Committer: Tim Just <tim.just@xxxxxxxxxxxxxx> Date: Mon Mar 15 14:30:46 2010 +0100 Revision: 3676 Revision-id: tim.just@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Branch nick: tiny Log: Moved maintenance related code to hipd/maintenance.c First step on removing of hipd/modularization.{h,c} Modified: M hipd/maintenance.c M hipd/maintenance.h M hipd/modularization.c M hipd/modularization.h === modified file 'hipd/maintenance.c' --- hipd/maintenance.c 2010-03-13 13:46:21 +0000 +++ hipd/maintenance.c 2010-03-15 13:30:46 +0000 @@ -15,12 +15,17 @@ #include "config.h" #include "maintenance.h" -#include "modularization.h" #include "hipd.h" #include "lib/core/hip_udp.h" +#include "lib/modularization/lmod.h" #define FORCE_EXIT_COUNTER_START 5 +struct maint_function { + uint16_t priority; + int (*func_ptr)(void); +}; + int hip_firewall_sock_lsi_fd = -1; float retrans_counter = HIP_RETRANSMIT_INIT; @@ -33,10 +38,10 @@ int hip_firewall_status = -1; int fall, retr; - - -static int hip_handle_retransmission(hip_ha_t *entry, void *current_time); -static int hip_scan_retransmissions(void); +/** + * List containing all maintenance functions. + */ +static hip_ll_t *hip_maintenance_functions; /** * Handle packet retransmissions. @@ -137,6 +142,98 @@ } /** + * hip_register_maint_function + * + * Register a maintenance function. All maintenance functions are called during + * the periodic maintenance cycle. + * + * @param *maint_function Pointer to the maintenance function. + * @param priority Priority of the maintenance function. + * + * @return Success = 0 + * Error = -1 + * + */ +int hip_register_maint_function(int (*maint_function)(void), + const uint16_t priority) +{ + int err = 0; + struct maint_function *new_entry = NULL; + + HIP_IFEL(!(new_entry = malloc(sizeof(struct maint_function))), + -1, + "Error on allocating memory for a maintenance function entry.\n"); + + new_entry->priority = priority; + new_entry->func_ptr = maint_function; + + hip_maintenance_functions = lmod_register_function(hip_maintenance_functions, + new_entry, + priority); + if (!hip_maintenance_functions) { + HIP_ERROR("Error on registering a maintenance function.\n"); + err = -1; + } + +out_err: + return err; +} + +/** + * hip_unregister_maint_function + * + * Remove a maintenance function from the list. + * + * @param *maint_function Pointer to the function which should be unregistered. + * + * @return Success = 0 + * Error = -1 + */ +int hip_unregister_maint_function(int (*maint_function)(void)) +{ + return lmod_unregister_function(hip_maintenance_functions, + maint_function); +} + +/** + * hip_run_maint_functions + * + * Run all maintenance functions. + * + * @return Success = 0 + * Error = -1 + */ +static int hip_run_maint_functions(void) +{ + int err = 0; + hip_ll_node_t *iter = NULL; + + if (hip_maintenance_functions) { + while ((iter = hip_ll_iterate(hip_maintenance_functions, iter))) { + ((struct maint_function*) iter->ptr)->func_ptr(); + } + } else { + HIP_DEBUG("No maintenance function registered.\n"); + } + + return err; +} + +/** + * hip_uninit_maint_functions + * + * Free the memory used for storage of maintenance functions. + * + */ +void hip_uninit_maint_functions(void) +{ + if (hip_maintenance_functions) { + hip_ll_uninit(hip_maintenance_functions, free); + free(hip_maintenance_functions); + } +} + +/** * Periodic maintenance. * * @return ... === modified file 'hipd/maintenance.h' --- hipd/maintenance.h 2010-03-10 17:48:17 +0000 +++ hipd/maintenance.h 2010-03-15 13:30:46 +0000 @@ -9,6 +9,10 @@ #include "lib/core/hip_statistics.h" #include "nat.h" +int hip_register_maint_function(int (*maint_function)(void), + const uint16_t priority); +int hip_unregister_maint_function(int (*maint_function)(void)); +void hip_uninit_maint_functions(void); int hip_periodic_maintenance(void); void hip_set_firewall_status(void); int hip_get_firewall_status(void); === modified file 'hipd/modularization.c' --- hipd/modularization.c 2010-03-13 10:59:53 +0000 +++ hipd/modularization.c 2010-03-15 13:30:46 +0000 @@ -19,22 +19,12 @@ struct hip_packet_context *ctx); }; -struct maint_function { - uint16_t priority; - int (*func_ptr)(void); -}; - /** * @todo add description */ static hip_ll_t *hip_handle_functions[HIP_MAX_PACKET_TYPE][HIP_MAX_HA_STATE]; /** - * @todo add description - */ -static hip_ll_t *hip_maintenance_functions; - -/** * hip_register_handle_function * * Register a function for handling of the specified combination from packet @@ -186,86 +176,3 @@ } } } - -/** - * hip_register_maint_function - * - */ -int hip_register_maint_function(int (*maint_function)(void), - const uint16_t priority) -{ - int err = 0; - struct maint_function *new_entry = NULL; - - HIP_IFEL(!(new_entry = malloc(sizeof(struct maint_function))), - -1, - "Error on allocating memory for a maintenance function entry.\n"); - - new_entry->priority = priority; - new_entry->func_ptr = maint_function; - - hip_maintenance_functions = lmod_register_function(hip_maintenance_functions, - new_entry, - priority); - if (!hip_maintenance_functions) { - HIP_ERROR("Error on registering a maintenance function.\n"); - err = -1; - } - -out_err: - return err; -} - -/** - * hip_unregister_maint_function - * - * Remove a maintenance function from the list. - * - * @param *maint_function Pointer to the function which should be unregistered. - * - * @return Success = 0 - * Error = -1 - */ -int hip_unregister_maint_function(int (*maint_function)(void)) -{ - return lmod_unregister_function(hip_maintenance_functions, - maint_function); -} - -/** - * hip_run_maint_functions - * - * Run all maintenance functions. - * - * @return Success = 0 - * Error = -1 - */ -int hip_run_maint_functions(void) -{ - int err = 0; - hip_ll_node_t *iter = NULL; - - if (hip_maintenance_functions) { - while ((iter = hip_ll_iterate(hip_maintenance_functions, iter))) { - ((struct maint_function*) iter->ptr)->func_ptr(); - } - } else { - HIP_DEBUG("No maintenance function registered.\n"); - } - - return err; -} - -/** - * hip_uninit_maint_functions - * - * Free the memory used for storage of maintenance functions. - * - */ -void hip_uninit_maint_functions(void) -{ - if (hip_maintenance_functions) { - hip_ll_uninit(hip_maintenance_functions, free); - free(hip_maintenance_functions); - } -} === modified file 'hipd/modularization.h' --- hipd/modularization.h 2010-03-13 10:59:53 +0000 +++ hipd/modularization.h 2010-03-15 13:30:46 +0000 @@ -27,13 +27,4 @@ void hip_uninit_handle_functions(void); -int hip_register_maint_function(int (*maint_function)(void), - const uint16_t priority); - -int hip_unregister_maint_function(int (*maint_function)(void)); - -int hip_run_maint_functions(void); - -void hip_uninit_maint_functions(void); - #endif /* HIP_HIPD_MODULARIZATION_H */