Add comments to functions.

This commit is contained in:
gamemann
2021-11-12 17:30:35 +00:00
parent becaeb4b34
commit bcfaccb71e
3 changed files with 58 additions and 0 deletions

View File

@@ -13,6 +13,13 @@ const struct option opts[] =
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
}; };
/**
* Parses the command line and stores values in the cmdline structure.
*
* @param cmd A pointer to the cmdline structure.
*
* @return Void
*/
void parsecommandline(struct cmdline *cmd, int argc, char *argv[]) void parsecommandline(struct cmdline *cmd, int argc, char *argv[])
{ {
int c; int c;

View File

@@ -11,6 +11,13 @@
FILE *file; FILE *file;
/**
* Sets the config structure's default values.
*
* @param cfg A pointer to the config structure.
*
* @return Void
*/
void setcfgdefaults(struct config *cfg) void setcfgdefaults(struct config *cfg)
{ {
cfg->updatetime = 0; cfg->updatetime = 0;
@@ -74,6 +81,13 @@ void setcfgdefaults(struct config *cfg)
} }
} }
/**
* Opens the config file.
*
* @param filename Path to config file.
*
* @return 0 on success or 1 on error.
*/
int opencfg(const char *filename) int opencfg(const char *filename)
{ {
// Close any existing files. // Close any existing files.
@@ -94,6 +108,13 @@ int opencfg(const char *filename)
return 0; return 0;
} }
/**
* Read the config file and stores values in config structure.
*
* @param cfg A pointer to the config structure.
*
* @return 0 on success or 1/-1 on error.
*/
int readcfg(struct config *cfg) int readcfg(struct config *cfg)
{ {
// Not sure why this would be set to NULL after checking for it in OpenConfig(), but just for safety. // Not sure why this would be set to NULL after checking for it in OpenConfig(), but just for safety.

View File

@@ -31,6 +31,13 @@ void signalHndl(int tmp)
cont = 0; cont = 0;
} }
/**
* Updates the filter's BPF map.
*
* @param cfg A pointer to the config structure.
*
* @return Void
*/
void updatefilters(struct config *cfg) void updatefilters(struct config *cfg)
{ {
// Loop through all filters and delete the map. // Loop through all filters and delete the map.
@@ -58,6 +65,14 @@ void updatefilters(struct config *cfg)
} }
} }
/**
* Retrieves an update from the config.
*
* @param cfg A pointer to the config structure.
* @param cfgfile The path to the config file.
*
* @return 0 on success or -1 on error.
*/
int updateconfig(struct config *cfg, char *cfgfile) int updateconfig(struct config *cfg, char *cfgfile)
{ {
// Open config file. // Open config file.
@@ -86,6 +101,14 @@ int updateconfig(struct config *cfg, char *cfgfile)
return 0; return 0;
} }
/**
* Finds a BPF map's FD.
*
* @param bpf_obj A pointer to the BPF object.
* @param mapname The name of the map to retrieve.
*
* @return The map's FD.
*/
int findmapfd(struct bpf_object *bpf_obj, const char *mapname) int findmapfd(struct bpf_object *bpf_obj, const char *mapname)
{ {
struct bpf_map *map; struct bpf_map *map;
@@ -106,6 +129,13 @@ int findmapfd(struct bpf_object *bpf_obj, const char *mapname)
return fd; return fd;
} }
/**
* Loads a BPF object file.
*
* @param filename The path to the BPF object file.
*
* @return BPF's program FD.
*/
int loadbpfobj(const char *filename) int loadbpfobj(const char *filename)
{ {
int first_prog_fd = -1; int first_prog_fd = -1;