------------------------------------------------------------ revno: 5008 committer: Andrius Bentkus <andrius.bentkus@xxxxxxxxxxxxxx> branch nick: hipfw-modules timestamp: Tue 2010-11-09 14:04:44 +0100 message: Forward command line initialization to modules in order to allow registering command line options themselfs. modified: firewall/firewall.c hipd/hipd.c hipd/init.c lib/core/options.c lib/core/options.h process_modules.py -- lp:~toxedvirus/hipl/hipfw-modules https://code.launchpad.net/~toxedvirus/hipl/hipfw-modules Your team HIPL core team is subscribed to branch lp:~toxedvirus/hipl/hipfw-modules. To unsubscribe from this branch go to https://code.launchpad.net/~toxedvirus/hipl/hipfw-modules/+edit-subscription
=== modified file 'firewall/firewall.c' --- firewall/firewall.c 2010-10-20 16:11:23 +0000 +++ firewall/firewall.c 2010-11-09 13:04:44 +0000 @@ -2074,6 +2074,8 @@ hip_cmd_options_add_static(&option_list, midauth_option_list); #endif + hip_cmd_init(&option_list, firewall_modules, firewall_num_modules); + if (hip_cmd_options_parse(argc, argv, &option_list)) { print_usage(); === modified file 'hipd/hipd.c' --- hipd/hipd.c 2010-10-20 16:11:23 +0000 +++ hipd/hipd.c 2010-11-09 13:04:44 +0000 @@ -61,6 +61,7 @@ #include "lib/core/protodefs.h" #include "lib/core/straddr.h" #include "lib/core/util.h" +#include "modules/hipd_modules.h" #include "config.h" #include "accessor.h" #include "hip_socket.h" @@ -221,7 +222,7 @@ sflags &= ~HIPD_START_LOWCAP; break; case 'm': - // do _not_ load/unload kernel modules/drivers + // do _not_ load/unload kernel modules/drivers sflags &= ~HIPD_START_LOAD_KMOD; break; case 'V': @@ -467,6 +468,8 @@ hip_cmd_options_add_static(&option_list, hipd_option_list); + hip_cmd_init(&option_list, hipd_modules, hipd_num_modules); + if (hip_cmd_options_parse(argc, argv, &option_list)) { // though we are leaving, we still have to free stuff usage(); === modified file 'hipd/init.c' --- hipd/init.c 2010-10-20 16:11:23 +0000 +++ hipd/init.c 2010-11-09 13:04:44 +0000 @@ -1196,7 +1196,7 @@ nsupdate(1); } - HIP_IFEL(hip_lmod_load_modules(hipd_modules, hipd_num_modules), + HIP_IFEL(hip_lmod_load_modules(hipd_modules, hipd_num_modules), -1, "Module initialization failed.\n"); === modified file 'lib/core/options.c' --- lib/core/options.c 2010-10-20 15:56:24 +0000 +++ lib/core/options.c 2010-11-09 13:04:44 +0000 @@ -54,7 +54,10 @@ #include <stdlib.h> #include <string.h> +#include "lmod.h" +#include "common.h" #include "options.h" +#include "modules/modules.h" #include "lib/core/linkedlist.h" /** @@ -343,3 +346,31 @@ free(opts); return 0; } + +/** + * Load module command line option definitions. + * + * @param option_list target option list to be used in adding process + * @param modules an array containing module information + * @param size number of the module entries in the array + * @return 1 if one of the paramteres where not set, + * 0 on success. + */ +int hip_cmd_init(struct hip_cmd_option_list *option_list, + const struct module_info *const modules, + const unsigned int size) +{ + unsigned int i; + + // check for bad paramters + if (!option_list) return 1; + if (!modules) return 1; + if (!size) return 1; + + for (i = 0; i < size; i++) { + if (modules[i].cmd_function && !lmod_module_disabled(modules[i].name)) { + modules[i].cmd_function(option_list); + } + } + return 0; // Success +} === modified file 'lib/core/options.h' --- lib/core/options.h 2010-10-20 14:42:29 +0000 +++ lib/core/options.h 2010-11-09 13:04:44 +0000 @@ -32,6 +32,7 @@ #define HIP_LIB_CORE_OPTIONS_H #include "lib/core/linkedlist.h" +#include "modules/modules.h" #define OPTION_DESCRIPTION_SIZE 512 @@ -89,4 +90,7 @@ char **argv, const struct hip_cmd_option_list *list); +int hip_cmd_init(struct hip_cmd_option_list *option_list, + const struct module_info *const modules, + const unsigned int size); #endif /* HIP_LIB_CORE_OPTIONS_H */ === modified file 'process_modules.py' --- process_modules.py 2010-10-20 15:04:46 +0000 +++ process_modules.py 2010-11-09 13:04:44 +0000 @@ -161,7 +161,7 @@ hdr_file.write('#define ' + app_string + '\n') hdr_file.write('\n#include "modules.h"\n') - info_string = 'struct module_info ' + current_app + info_string = 'static struct module_info ' + current_app info_string += '_modules[] = {' first_loop = True num_spaces = len(info_string) @@ -192,12 +192,18 @@ info_string += '"' + required_module['name'] + '"' first_loop_1 = False info_string += '}' + + if app_info.has_key('cmd_function'): + info_string += ', &' + app_info['cmd_function'] + else: + info_string += ', NULL' + info_string += ', &' + app_info['init_function'] + '}' first_loop = False info_string += '};' - hdr_file.write('\nconst unsigned int ' + current_app + '_num_modules') + hdr_file.write('\nstatic const unsigned int ' + current_app + '_num_modules') hdr_file.write(' = ' + str(num_modules) + ';\n\n') hdr_file.write(info_string) @@ -228,6 +234,7 @@ info_struct += ' const unsigned int num_required_modules;\n' info_struct += ' const char *required_modules[' info_struct += 'MAX_REQUIRED_MODULES];\n' + info_struct += ' void (*cmd_function)(void *);\n' info_struct += ' int (*init_function)(void);\n' info_struct += '};\n' hdr_file.write(info_struct)