Committer: Tim Just <tim.just@xxxxxxxxxxxxxx> Date: 19/03/2010 at 12:40:12 Revision: 3702 Revision-id: tim.just@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Branch nick: tiny Log: Added command line option '-d'. It can be used to disable modules. Now the compiled and linked modules can be disabled per runtime decision. You can pass -d <module name> to the hipd and the corresponding module will not be initialized. You can disable additional modules using an additional -d parameter. Dependencies between modules are not check, for now. Changed debug output regarding module initialization. For each configured module there is a debug statement. It says whether the module is enabled or disabled. The registration of module names is now done by the build system (i.e. process_modules.py). The python script creates a list with all configured modules. Therefore it is not necessary to register modules. Modified: M hipd/hipd.c M hipd/init.c M lib/modularization/lmod.c M lib/modularization/lmod.h M modules/heartbeat/hipd/heartbeat.c M modules/update/hipd/update.c M process_modules.py === modified file 'hipd/hipd.c' --- hipd/hipd.c 2010-03-17 15:05:58 +0000 +++ hipd/hipd.c 2010-03-19 10:38:17 +0000 @@ -122,11 +122,14 @@ { fprintf(stderr, "Usage: hipd [options]\n\n"); fprintf(stderr, " -b run in background\n"); - fprintf(stderr, " -i <device name> add interface to the white list. Use additional -i for additional devices.\n"); + fprintf(stderr, " -i <device name> add interface to the white list. " \ + "Use additional -i for additional devices.\n"); fprintf(stderr, " -k kill existing hipd\n"); fprintf(stderr, " -N do not flush ipsec rules on exit\n"); fprintf(stderr, " -a fix alignment issues automatically(ARM)\n"); fprintf(stderr, " -f set debug type format to short\n"); + fprintf(stderr, " -d <module name> disable this module. " \ + "Use additional -d for additional modules.\n"); fprintf(stderr, "\n"); } @@ -225,7 +228,7 @@ hip_set_logfmt(LOGFMT_LONG); /* Parse command-line options */ - while ((ch = getopt(argc, argv, ":bi:kNchaf")) != -1) { + while ((ch = getopt(argc, argv, ":bi:kNchafd:")) != -1) { switch (ch) { case 'b': foreground = 0; @@ -253,6 +256,13 @@ HIP_INFO("Setting output format to short\n"); hip_set_logfmt(LOGFMT_SHORT); break; + case 'd': + if (!lmod_disable_module(optarg)) { + HIP_DEBUG("Module '%s' disabled.\n", optarg); + } else { + HIP_ERROR("Error while disabling module '%s'.\n", optarg); + } + break; case '?': case 'h': default: === modified file 'hipd/init.c' --- hipd/init.c 2010-03-19 09:03:41 +0000 +++ hipd/init.c 2010-03-19 10:38:17 +0000 @@ -939,17 +939,20 @@ } /* Initialize modules */ - HIP_INFO("Initializing modules.\n"); + HIP_INFO("Initializing modules.\n\n"); for (i = 0; i < num_modules_hipd; i++) { + HIP_DEBUG("module: %s\n", modules_hipd[i]); + if (lmod_module_disabled(modules_hipd[i])) { + HIP_DEBUG("state: DISABLED\n\n"); + continue; + } else { + HIP_DEBUG("state: ENABLED\n\n"); HIP_IFEL(hipd_init_functions[i](), -1, "Module initialization failed.\n"); + } } - printf("\nThe following modules were loaded:\n\n"); - lmod_print_registered_modules(); - printf("\n"); - hip_init_sockets(); out_err: @@ -1194,7 +1197,7 @@ hip_dh_uninit(); - lmod_uninit_module_list(); + lmod_uninit_disabled_modules(); return; } === modified file 'lib/modularization/lmod.c' --- lib/modularization/lmod.c 2010-03-19 09:03:41 +0000 +++ lib/modularization/lmod.c 2010-03-19 10:38:17 +0000 @@ -43,7 +43,7 @@ * Used to check, whether a certain module is loaded. * */ -static char **module_list; +static char **disabled_modules; /** * List of packet types. @@ -59,7 +59,7 @@ /** * Number of enabled modules. */ -static uint16_t num_modules = 0; +static uint16_t num_disabled_modules = 0; /** * lmod_init_state @@ -333,51 +333,52 @@ } /** - * lmod_register_module - * - * Add an identifier to the module list. All modules should register an id. - * So everyone else can check, if a certain module is loaded. - * - * @note Call lmod_uninit_module_list() to free the allocated memory! - * - * @param *module_id String identifier for the module to register. + * lmod_disable_module + * + * Disable the module with the provide name. The initialization functions of + * disabled modules will not be executed. Therefore the functionality of these + * modules should be completely disabled. + * + * @note Call lmod_uninit_disabled_modules() to free the allocated memory! + * + * @param *module_name String identifier for the module to disable. * * @return Success = 0 - * Error = -1 (if the identifier already exists) + * Error = -1 (if the module was already disabled) */ -int lmod_register_module(const char *module_id) +int lmod_disable_module(const char *module_name) { - if (lmod_module_exists(module_id)) { + if (lmod_module_disabled(module_name)) { return -1; } - module_list = (char **)realloc(module_list, - (num_modules + 1) * sizeof(char *)); + disabled_modules = (char **)realloc(disabled_modules, + (num_disabled_modules + 1) * sizeof(char *)); - module_list[num_modules++] = strdup(module_id); + disabled_modules[num_disabled_modules++] = strdup(module_name); return 0; } /** - * lmod_module_exists + * lmod_module_disabled * - * Check whether a certain module is enabled. + * Check whether a certain module is disabled. * * @note This function uses string compares. Therefore you should call this * function only once and cache the result to improve performance. * - * @param *module_id String identifier for the module to check. + * @param *module_name String identifier for the module to check. * - * @return 0, if module with this id is NOT registered - * 1, if module with this id is registered + * @return 0, if module with this name is ENABLED + * 1, if module with this name is DISABLED */ -int lmod_module_exists(const char *module_id) +int lmod_module_disabled(const char *module_name) { unsigned int i; - for (i = 0; i < num_modules; i++) { - if (0 == strcmp(module_id, module_list[i])) { + for (i = 0; i < num_disabled_modules; i++) { + if (0 == strcmp(module_name, disabled_modules[i])) { return 1; } } @@ -386,38 +387,22 @@ } /** - * lmod_print_registered_modules - * - * Print all registered modules to stdout. - */ -void lmod_print_registered_modules(void) -{ - unsigned int i; - - for (i = 0; i < num_modules; i++) { - printf("%s\n", module_list[i]); - } -} - -/** - * lmod_uninit_module_list - * - * Free all allocated memory for storage of the module list. - * - * @note Call this function, if you have added module id's. - * - */ -void lmod_uninit_module_list(void) + * lmod_uninit_disabled_modules + * + * Free all allocated memory for storage of disabled modules. + * + */ +void lmod_uninit_disabled_modules(void) { int i; - if (module_list) { - for (i = 0; i < num_modules; i++) { - if (module_list[i]) { - free(module_list[i]); + if (disabled_modules) { + for (i = 0; i < num_disabled_modules; i++) { + if (disabled_modules[i]) { + free(disabled_modules[i]); } } - free(module_list); + free(disabled_modules); } } === modified file 'lib/modularization/lmod.h' --- lib/modularization/lmod.h 2010-03-19 08:45:27 +0000 +++ lib/modularization/lmod.h 2010-03-19 10:38:17 +0000 @@ -48,13 +48,11 @@ void lmod_uninit_state(struct modular_state *state); -int lmod_register_module(const char *module_id); - -int lmod_module_exists(const char *module_id); - -void lmod_print_registered_modules(void); - -void lmod_uninit_module_list(void); +int lmod_disable_module(const char *module_id); + +int lmod_module_disabled(const char *module_id); + +void lmod_uninit_disabled_modules(void); int lmod_register_packet_type(const uint16_t packet_type, const char *identifier); === modified file 'modules/heartbeat/hipd/heartbeat.c' --- modules/heartbeat/hipd/heartbeat.c 2010-03-13 13:46:21 +0000 +++ modules/heartbeat/hipd/heartbeat.c 2010-03-19 10:38:17 +0000 @@ -388,10 +388,6 @@ err = setsockopt(*icmpsockfd, IPPROTO_IPV6, IPV6_2292PKTINFO, &on, sizeof(on)); HIP_IFEL(err, -1, "setsockopt icmp IPV6_RECVPKTINFO failed\n"); - HIP_IFEL(lmod_register_module("heartbeat"), - -1, - "Error on registration of HEARTBEAT module.\n"); - HIP_IFEL(hip_register_socket(hip_icmp_sock, &hip_heartbeat_handle_icmp_sock, 30000), === modified file 'modules/update/hipd/update.c' --- modules/update/hipd/update.c 2010-03-18 17:03:04 +0000 +++ modules/update/hipd/update.c 2010-03-19 10:38:17 +0000 @@ -994,10 +994,6 @@ { int err = 0; - HIP_IFEL(lmod_register_module("update"), - -1, - "Error on registering UPDATE module.\n"); - lmod_register_packet_type(HIP_UPDATE, "HIP_UPDATE"); HIP_IFEL(lmod_register_state_init_function(&hip_update_init_state), === modified file 'process_modules.py' --- process_modules.py 2010-03-18 14:07:15 +0000 +++ process_modules.py 2010-03-19 10:38:17 +0000 @@ -210,7 +210,7 @@ # Creates a C header file with the given filename an the needed includes, # the number of init functions per application and an array of function # pointers for each application -def create_header_files(output_dir, suffix, applications, includes, init_functions): +def create_header_files(output_dir, suffix, applications, includes, init_functions, enabled_modules): if False == os.path.isdir(output_dir): os.mkdir(output_dir) @@ -234,7 +234,17 @@ hdr_file.write('\n\ntypedef int (*pt2Function)(void);\n') hdr_file.write('\nconst int num_modules_' + current_app + ' = ') - hdr_file.write(num_modules + ';') + hdr_file.write(num_modules + ';\n') + hdr_file.write('\nconst char *modules_' + current_app + '[') + hdr_file.write(num_modules + '] = {') + first_loop = True + for module in enabled_modules: + if first_loop != True: + hdr_file.write(', ') + hdr_file.write('"' + module + '"') + first_loop = False + hdr_file.write('};') + hdr_file.write('\n\nstatic const pt2Function ' + current_app) hdr_file.write('_init_functions[' + num_modules + '] = {') @@ -337,7 +347,8 @@ HEADER_FILE_SUFFIX, applications, includes, - init_functions) + init_functions, + module_info.keys()) create_makefile_modules('Makefile.modules', module_info,