Add typedefs and organize code.
This commit is contained in:
@@ -43,7 +43,7 @@ void SignalHndl(int tmp)
|
||||
*
|
||||
* @return Void
|
||||
*/
|
||||
void UpdateFilters(struct config *cfg)
|
||||
void UpdateFilters(config__t *cfg)
|
||||
{
|
||||
// Loop through all filters and delete the map. We do this in the case rules were edited and were put out of order since the key doesn't uniquely map to a specific rule.
|
||||
for (u8 i = 0; i < MAX_FILTERS; i++)
|
||||
@@ -63,7 +63,7 @@ void UpdateFilters(struct config *cfg)
|
||||
}
|
||||
|
||||
// Create value array (max CPUs in size) since we're using a per CPU map.
|
||||
struct filter filter[MAX_CPUS];
|
||||
filter_t filter[MAX_CPUS];
|
||||
|
||||
for (int j = 0; j < MAX_CPUS; j++)
|
||||
{
|
||||
@@ -86,7 +86,7 @@ void UpdateFilters(struct config *cfg)
|
||||
*
|
||||
* @return 0 on success or -1 on error.
|
||||
*/
|
||||
int UpdateConfig(struct config *cfg, char *cfgfile)
|
||||
int UpdateConfig(config__t *cfg, char *cfgfile)
|
||||
{
|
||||
// Open config file.
|
||||
if (OpenCfg(cfgfile) != 0)
|
||||
@@ -180,7 +180,7 @@ struct xdp_program *LoadBpfObj(const char *filename)
|
||||
*
|
||||
* @return 0 on success and 1 on error.
|
||||
*/
|
||||
int AttachXdp(struct xdp_program *prog, int ifidx, u8 detach, struct cmdline *cmd)
|
||||
int AttachXdp(struct xdp_program *prog, int ifidx, u8 detach, cmdline_t *cmd)
|
||||
{
|
||||
int err;
|
||||
|
||||
@@ -273,7 +273,7 @@ struct stat conf_stat;
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// Parse the command line.
|
||||
struct cmdline cmd =
|
||||
cmdline_t cmd =
|
||||
{
|
||||
.cfgfile = "/etc/xdpfw/xdpfw.conf",
|
||||
.help = 0,
|
||||
@@ -315,7 +315,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
// Initialize config.
|
||||
struct config cfg = {0};
|
||||
config__t cfg = {0};
|
||||
|
||||
SetCfgDefaults(&cfg);
|
||||
|
||||
@@ -332,7 +332,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
for (uint16_t i = 0; i < MAX_FILTERS; i++)
|
||||
{
|
||||
struct filter *filter = &cfg.filters[i];
|
||||
filter_t *filter = &cfg.filters[i];
|
||||
|
||||
if (filter->id < 1)
|
||||
{
|
||||
@@ -521,12 +521,12 @@ int main(int argc, char *argv[])
|
||||
if (!cfg.nostats)
|
||||
{
|
||||
u32 key = 0;
|
||||
struct stats stats[MAX_CPUS];
|
||||
stats_t stats[MAX_CPUS];
|
||||
//memset(stats, 0, sizeof(struct stats) * MAX_CPUS);
|
||||
|
||||
__u64 allowed = 0;
|
||||
__u64 dropped = 0;
|
||||
__u64 passed = 0;
|
||||
u64 allowed = 0;
|
||||
u64 dropped = 0;
|
||||
u64 passed = 0;
|
||||
|
||||
if (bpf_map_lookup_elem(statsmap, &key, stats) != 0)
|
||||
{
|
||||
|
||||
@@ -22,7 +22,7 @@ const struct option opts[] =
|
||||
*
|
||||
* @return Void
|
||||
*/
|
||||
void ParseCommandLine(struct cmdline *cmd, int argc, char *argv[])
|
||||
void ParseCommandLine(cmdline_t *cmd, int argc, char *argv[])
|
||||
{
|
||||
int c;
|
||||
|
||||
|
||||
@@ -8,6 +8,6 @@ struct cmdline
|
||||
unsigned int time;
|
||||
unsigned int list : 1;
|
||||
unsigned int help : 1;
|
||||
};
|
||||
} typedef cmdline_t;
|
||||
|
||||
void ParseCommandLine(struct cmdline *cmd, int argc, char *argv[]);
|
||||
void ParseCommandLine(cmdline_t *cmd, int argc, char *argv[]);
|
||||
@@ -11,7 +11,7 @@ FILE *file;
|
||||
*
|
||||
* @return Void
|
||||
*/
|
||||
void SetCfgDefaults(struct config *cfg)
|
||||
void SetCfgDefaults(config__t *cfg)
|
||||
{
|
||||
cfg->updatetime = 0;
|
||||
cfg->interface = NULL;
|
||||
@@ -111,7 +111,7 @@ int OpenCfg(const char *filename)
|
||||
*
|
||||
* @return 0 on success or 1/-1 on error.
|
||||
*/
|
||||
int ReadCfg(struct config *cfg)
|
||||
int ReadCfg(config__t *cfg)
|
||||
{
|
||||
// Not sure why this would be set to NULL after checking for it in OpenConfig(), but just for safety.
|
||||
if (file == NULL)
|
||||
@@ -225,7 +225,7 @@ int ReadCfg(struct config *cfg)
|
||||
|
||||
if (config_setting_lookup_string(filter, "src_ip", &sip))
|
||||
{
|
||||
struct ip ip = ParseIp(sip);
|
||||
ip_range_t ip = ParseIpCidr(sip);
|
||||
|
||||
cfg->filters[i].src_ip = ip.ip;
|
||||
cfg->filters[i].src_cidr = ip.cidr;
|
||||
@@ -236,7 +236,7 @@ int ReadCfg(struct config *cfg)
|
||||
|
||||
if (config_setting_lookup_string(filter, "dst_ip", &dip))
|
||||
{
|
||||
struct ip ip = ParseIp(dip);
|
||||
ip_range_t ip = ParseIpCidr(dip);
|
||||
|
||||
cfg->filters[i].dst_ip = ip.ip;
|
||||
cfg->filters[i].dst_cidr = ip.cidr;
|
||||
|
||||
@@ -16,9 +16,9 @@ struct config
|
||||
u16 updatetime;
|
||||
unsigned int nostats : 1;
|
||||
int stdout_update_time;
|
||||
struct filter filters[MAX_FILTERS];
|
||||
};
|
||||
filter_t filters[MAX_FILTERS];
|
||||
} typedef config__t; // config_t is taken by libconfig -.-
|
||||
|
||||
void SetCfgDefaults(struct config *cfg);
|
||||
void SetCfgDefaults(config__t *cfg);
|
||||
int OpenCfg(const char *filename);
|
||||
int ReadCfg(struct config *cfg);
|
||||
int ReadCfg(config__t *cfg);
|
||||
@@ -7,9 +7,9 @@
|
||||
*
|
||||
* @return Returns an IP structure with IP and CIDR.
|
||||
*/
|
||||
struct ip ParseIp(const char *ip)
|
||||
ip_range_t ParseIpCidr(const char *ip)
|
||||
{
|
||||
struct ip ret = {0};
|
||||
ip_range_t ret = {0};
|
||||
ret.cidr = 32;
|
||||
|
||||
char *token = strtok((char *) ip, "/");
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct ip
|
||||
struct ip_range
|
||||
{
|
||||
u32 ip;
|
||||
u32 cidr;
|
||||
};
|
||||
} typedef ip_range_t;
|
||||
|
||||
struct ip ParseIp(const char *ip);
|
||||
ip_range_t ParseIpCidr(const char *ip);
|
||||
Reference in New Issue
Block a user