From bcfaccb71e045a04f4915201c1b9d0cd68c7453e Mon Sep 17 00:00:00 2001 From: gamemann Date: Fri, 12 Nov 2021 17:30:35 +0000 Subject: [PATCH] Add comments to functions. --- src/cmdline.c | 7 +++++++ src/config.c | 21 +++++++++++++++++++++ src/xdpfw.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/src/cmdline.c b/src/cmdline.c index c347801..9f3f3d4 100644 --- a/src/cmdline.c +++ b/src/cmdline.c @@ -13,6 +13,13 @@ const struct option opts[] = {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[]) { int c; diff --git a/src/config.c b/src/config.c index f13b727..2cacbdc 100644 --- a/src/config.c +++ b/src/config.c @@ -11,6 +11,13 @@ FILE *file; +/** + * Sets the config structure's default values. + * + * @param cfg A pointer to the config structure. + * + * @return Void +*/ void setcfgdefaults(struct config *cfg) { 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) { // Close any existing files. @@ -94,6 +108,13 @@ int opencfg(const char *filename) 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) { // Not sure why this would be set to NULL after checking for it in OpenConfig(), but just for safety. diff --git a/src/xdpfw.c b/src/xdpfw.c index 4220c91..2be4d2f 100644 --- a/src/xdpfw.c +++ b/src/xdpfw.c @@ -31,6 +31,13 @@ void signalHndl(int tmp) cont = 0; } +/** + * Updates the filter's BPF map. + * + * @param cfg A pointer to the config structure. + * + * @return Void +*/ void updatefilters(struct config *cfg) { // 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) { // Open config file. @@ -86,6 +101,14 @@ int updateconfig(struct config *cfg, char *cfgfile) 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) { struct bpf_map *map; @@ -106,6 +129,13 @@ int findmapfd(struct bpf_object *bpf_obj, const char *mapname) 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 first_prog_fd = -1;