Author: tjansen Date: Thu Oct 29 14:48:43 2009 New Revision: 1405 Log: There is only one globally available cd_cfg, no need to pass pointers around. Modified: trunk/pisacd/cdconf.c trunk/pisacd/cdconf.h trunk/pisacd/cdmain.c Modified: trunk/pisacd/cdconf.c ============================================================================== --- trunk/pisacd/cdconf.c Thu Oct 29 14:37:26 2009 (r1404) +++ trunk/pisacd/cdconf.c Thu Oct 29 14:48:43 2009 (r1405) @@ -4,7 +4,7 @@ */ /** - * @file cdconf.c + * @file cd_cfg.c * @brief Implementation of the configuration manager for the PISA neighbor daemon. * @author Dongsu Park <dpark1978@xxxxxxxxx> * @date Jan. 2009 @@ -26,65 +26,57 @@ cd_conf cd_cfg; /** - * Initialize general configuration of neighbor daemon. - * - * @param cdconf cd_conf structure to be initialized + * Initialize general configuration. */ -void cdconf_init(cd_conf *cdconf) +void cdconf_init(void) { - memset(cdconf->conffile, 0, sizeof(cdconf->conffile)); - memset(cdconf->debuglevel, 0, sizeof(cdconf->debuglevel)); - memset(&cdconf->ipaddr, 0, sizeof(cdconf->ipaddr)); - memset(&cdconf->local_ipv4, 0, sizeof(cdconf->local_ipv4)); - memset(&cdconf->local_netmask, 0, sizeof(cdconf->local_netmask)); - cdconf->port_control = 0; - cdconf->port_data = 0; - cdconf->idle_disconnect_delay = PISACD_DEFAULT_IDLE_DISCONNECT_DELAY; + memset(cd_cfg.conffile, 0, sizeof(cd_cfg.conffile)); + memset(cd_cfg.debuglevel, 0, sizeof(cd_cfg.debuglevel)); + memset(&cd_cfg.ipaddr, 0, sizeof(cd_cfg.ipaddr)); + memset(&cd_cfg.local_ipv4, 0, sizeof(cd_cfg.local_ipv4)); + memset(&cd_cfg.local_netmask, 0, sizeof(cd_cfg.local_netmask)); + cd_cfg.port_control = 0; + cd_cfg.port_data = 0; + cd_cfg.idle_disconnect_delay = PISACD_DEFAULT_IDLE_DISCONNECT_DELAY; } /** - * Destroy general configurations of neighbor daemon. - * - * @param cdconf cd_conf structure to be destroyed + * Destroy general configuration. */ -void cdconf_destroy(cd_conf *cdconf) +void cdconf_destroy(void) { pisa_cfg_cleanup(); } /** * Setup the configuration file before doing any read/write operations. - * - * @param cdconf cd_conf structure to be set up */ -void cdconf_setup_conffile(cd_conf *cdconf) +void cdconf_setup_conffile(void) { /* Use default path if no config file was given via commandline argument */ - if (cdconf->conffile[0] == '\0') { + if (cd_cfg.conffile[0] == '\0') { pisa_check_and_create_dir(PISA_CONFDIR_PATH, DEFAULT_CONFIG_DIR_MODE); - strncpy(cdconf->conffile, PISACD_CONFFILE_FULLPATH, sizeof(cdconf->conffile)); + strncpy(cd_cfg.conffile, PISACD_CONFFILE_FULLPATH, sizeof(cd_cfg.conffile)); } - if (pisa_cfg_setup_file(cdconf->conffile) <= 0) { - PISA_ERROR("Cannot read the config file %s\n", cdconf->conffile); + if (pisa_cfg_setup_file(cd_cfg.conffile) <= 0) { + PISA_ERROR("Cannot read the config file %s\n", cd_cfg.conffile); exit(EXIT_FAILURE); } - PISA_INFO("Using configuration file %s\n", cdconf->conffile); + PISA_INFO("Using configuration file %s\n", cd_cfg.conffile); } /** * Read the debug level from the configuration file. - * - * @param cdconf cd_conf structure where conf settings are stored */ -static void cdconf_read_debuglevel(cd_conf *cdconf) +static void cdconf_read_debuglevel(void) { /* Determine the appropriate debuglevel name for listening connections */ - if (*cdconf->debuglevel == '\0') { - if (!pisa_cfg_get_string_value("debuglevel", cdconf->debuglevel, sizeof(cdconf->debuglevel))) { + if (*cd_cfg.debuglevel == '\0') { + if (!pisa_cfg_get_string_value("debuglevel", cd_cfg.debuglevel, sizeof(cd_cfg.debuglevel))) { PISA_DEBUG(PL_CONFIG, "Using the default debuglevel %s\n", PISACD_DEFAULT_DEBUGLEVEL); - strncpy(cdconf->debuglevel, PISACD_DEFAULT_DEBUGLEVEL, sizeof(cdconf->debuglevel)); + strncpy(cd_cfg.debuglevel, PISACD_DEFAULT_DEBUGLEVEL, sizeof(cd_cfg.debuglevel)); } } } @@ -92,7 +84,7 @@ /** * Read the debug type mask from the configuration file. */ -static void cdconf_read_debugtypemask() +static void cdconf_read_debugtypemask(void) { int mask = 0x7fffffff; @@ -102,42 +94,38 @@ /** * Read the listening control port number from the configuration file. - * - * @param cdconf cd_conf structure where conf settings are stored */ -static void cdconf_read_port_control(cd_conf *cdconf) +static void cdconf_read_port_control(void) { /* Determine the appropriate port number for listening connections */ - if (cdconf->port_control > MAX_PORTNUM) { + if (cd_cfg.port_control > MAX_PORTNUM) { PISA_ERROR("Error: Port number must be %d at most!\n" "Run with -h to see usage\n", MAX_PORTNUM); exit(EXIT_FAILURE); - } else if (cdconf->port_control == 0) { - if (!pisa_cfg_get_int_value("port_control", &cdconf->port_control)) { + } else if (cd_cfg.port_control == 0) { + if (!pisa_cfg_get_int_value("port_control", &cd_cfg.port_control)) { PISA_DEBUG(PL_CONFIG, "Using the default control port number %d\n", PISACD_DEFAULT_PORTNUM_CONTROL); - cdconf->port_control = PISACD_DEFAULT_PORTNUM_CONTROL; + cd_cfg.port_control = PISACD_DEFAULT_PORTNUM_CONTROL; } } } /** * Read the listening data port number from the configuration file. - * - * @param cdconf cd_conf structure where conf settings are stored */ -static void cdconf_read_port_data(cd_conf *cdconf) +static void cdconf_read_port_data(void) { /* Determine the appropriate port number for listening connections */ - if (cdconf->port_data > MAX_PORTNUM) { + if (cd_cfg.port_data > MAX_PORTNUM) { PISA_ERROR("Error: Port number must be %d at most!\n" "Run with -h to see usage\n", MAX_PORTNUM); exit(EXIT_FAILURE); - } else if (cdconf->port_data == 0) { - if (!pisa_cfg_get_int_value("port_data", &cdconf->port_data)) { + } else if (cd_cfg.port_data == 0) { + if (!pisa_cfg_get_int_value("port_data", &cd_cfg.port_data)) { PISA_DEBUG(PL_CONFIG, "Using the default data port number %d\n", PISACD_DEFAULT_PORTNUM_DATA); - cdconf->port_data = PISACD_DEFAULT_PORTNUM_DATA; + cd_cfg.port_data = PISACD_DEFAULT_PORTNUM_DATA; } } } @@ -145,23 +133,20 @@ /** * Read the delay before idle connections are deregistered from the * configuration file. - * - * @param cdconf cd_conf structure where conf settings are stored */ -static void cdconf_read_idle_disconnect_delay(cd_conf *cdconf) +static void cdconf_read_idle_disconnect_delay(void) { - if (!pisa_cfg_get_int_value("idle_disconnect_delay", &cdconf->idle_disconnect_delay)) { + if (!pisa_cfg_get_int_value("idle_disconnect_delay", &cd_cfg.idle_disconnect_delay)) { PISA_DEBUG(PL_CONFIG, "Using the default idle disconnect delay %d\n", PISACD_DEFAULT_IDLE_DISCONNECT_DELAY); - cdconf->idle_disconnect_delay = PISACD_DEFAULT_IDLE_DISCONNECT_DELAY; + cd_cfg.idle_disconnect_delay = PISACD_DEFAULT_IDLE_DISCONNECT_DELAY; } } /** * Reads the netmask for the local ip range from the pisacd.conf file - * @param cdconf cd_conf structure where conf settings are stored */ -static void cdconf_read_local_ipv4(cd_conf *cdconf) +static void cdconf_read_local_ipv4(void) { char ip_tmp[INET_ADDRSTRLEN]; @@ -171,16 +156,15 @@ } else { - if(inet_pton(AF_INET, ip_tmp, &cdconf->local_ipv4) != 1) + if(inet_pton(AF_INET, ip_tmp, &cd_cfg.local_ipv4) != 1) PISA_ERROR("Error: Not a valid netmask.\n"); } } /** * Reads the netmask for the local ip range from the pisacd.conf file - * @param cdconf cd_conf structure where conf settings are stored */ -static void cdconf_read_local_netmask(cd_conf *cdconf) +static void cdconf_read_local_netmask(void) { char ip_tmp[INET_ADDRSTRLEN]; @@ -190,19 +174,17 @@ } else { - if(inet_pton(AF_INET, ip_tmp, &cdconf->local_netmask) != 1) + if(inet_pton(AF_INET, ip_tmp, &cd_cfg.local_netmask) != 1) PISA_ERROR("Error: Not a valid netmask.\n"); } } /** * Set the global debug level variable - * - * @param cdconf cd_conf structure where conf settings are stored */ -void cdconf_set_debuglevel(cd_conf *cdconf) +void cdconf_set_debuglevel(void) { - char *dlstr = cdconf->debuglevel; + char *dlstr = cd_cfg.debuglevel; int debuglevel = PISA_LOGDEBUG_MEDIUM; if (strncasecmp(dlstr, "all", MAX_DEBUGLEVEL_STR) == 0) { @@ -223,14 +205,14 @@ /** * Read basic settings from the configuration file */ -void cdconf_read_basic_confs(cd_conf *cdconf) +void cdconf_read_basic_confs(void) { /* Read several configuration from pisacd.conf. */ - cdconf_read_debuglevel(cdconf); + cdconf_read_debuglevel(); cdconf_read_debugtypemask(); - cdconf_read_port_control(cdconf); - cdconf_read_port_data(cdconf); - cdconf_read_idle_disconnect_delay(cdconf); - cdconf_read_local_ipv4(cdconf); - cdconf_read_local_netmask(cdconf); + cdconf_read_port_control(); + cdconf_read_port_data(); + cdconf_read_idle_disconnect_delay(); + cdconf_read_local_ipv4(); + cdconf_read_local_netmask(); } Modified: trunk/pisacd/cdconf.h ============================================================================== --- trunk/pisacd/cdconf.h Thu Oct 29 14:37:26 2009 (r1404) +++ trunk/pisacd/cdconf.h Thu Oct 29 14:48:43 2009 (r1405) @@ -39,11 +39,11 @@ /** * This must be called before any other call to the cdconf module. */ -void cdconf_init(cd_conf *cdconf); -void cdconf_destroy(cd_conf *cdconf); -void cdconf_set_debuglevel(cd_conf *cdconf); +void cdconf_init(void); +void cdconf_destroy(void); +void cdconf_set_debuglevel(void); -void cdconf_read_basic_confs(cd_conf *cdconf); -void cdconf_setup_conffile(cd_conf *cdconf); +void cdconf_read_basic_confs(void); +void cdconf_setup_conffile(void); #endif /* PISA_CDCONF_H */ Modified: trunk/pisacd/cdmain.c ============================================================================== --- trunk/pisacd/cdmain.c Thu Oct 29 14:37:26 2009 (r1404) +++ trunk/pisacd/cdmain.c Thu Oct 29 14:48:43 2009 (r1405) @@ -309,7 +309,7 @@ { PISA_DEBUG(PL_GENERIC, "Received a HUP signal, reloading basic configurations...\n"); - cdconf_read_basic_confs(&cd_cfg); + cdconf_read_basic_confs(); } #ifdef CONFIG_PISA_PERFORMANCE @@ -356,7 +356,7 @@ /* Set default values in context and config */ cdctx_init(&cd_ctx); - cdconf_init(&cd_cfg); + cdconf_init(); /* Receive and parse command line arguments. * Note that command line args must be obtained before calling any @@ -374,7 +374,7 @@ #endif /* set the default or command line specified debug level */ - cdconf_set_debuglevel(&cd_cfg); + cdconf_set_debuglevel(); /* daemonize pisacd when running background mode */ if (cd_ctx.flag_background) @@ -385,12 +385,12 @@ /* Setup configuration file. * This is needed before any cdconf_read_*() operations. */ - cdconf_setup_conffile(&cd_cfg); + cdconf_setup_conffile(); /* Read several configuration from pisacd.conf. */ - cdconf_read_basic_confs(&cd_cfg); + cdconf_read_basic_confs(); - cdconf_set_debuglevel(&cd_cfg); + cdconf_set_debuglevel(); /* Make default sockets */ cd_ctx.fd_tunnel = pisa_tunnel_open_tundev(cd_ctx.ifname_tunnel, IFNAMSIZ); @@ -435,7 +435,7 @@ pisa_tunnel_remove_firewall_rules(cd_ctx.ifname_tunnel); pisa_nat_destroy(cd_ctx.natlist); cdctx_destroy(&cd_ctx); - cdconf_destroy(&cd_cfg); + cdconf_destroy(); pisa_arp_cleanup(); pisa_sched_cleanup(&cd_ctx.scheduler);