/* * leave pluto, with status. * Once child is launched, parent must not exit this way because * the lock would be released. * * 0 OK * 1 general discomfort * 10 lock file exists */ void exit_pluto(int status) { /* needed because we may be called in odd state */ reset_globals(); #ifdef USE_SYSTEMD_WATCHDOG pluto_sd(PLUTO_SD_STOPPING, status); #endif free_preshared_secrets(); free_remembered_public_keys(); delete_every_connection(); /* * free memory allocated by initialization routines. Please don't * forget to do this. */ #if defined(LIBCURL) || defined(LDAP_VER) free_crl_fetch(); /* free chain of crl fetch requests */ #endif lsw_conf_free_oco(); /* free global_oco containing path names */ free_myFQDN(); /* free myid FQDN */ free_ifaces(); /* free interface list from memory */ free_md_pool(); /* free the md pool */ lsw_nss_shutdown(); delete_lock(); /* delete any lock files */ free_virtual_ip(); /* virtual_private= */ free_kernelfd(); /* stop listening to kernel FD, remove event */ free_pluto_main(); /* our static chars */ /* report memory leaks now, after all free_* calls */ if (leak_detective) report_leaks(); close_log(); /* close the logfiles */ #ifdef USE_SYSTEMD_WATCHDOG pluto_sd(PLUTO_SD_EXIT,status); #endif exit(status); /* exit, with our error code */ }
/* * Initialize Virtual IP Support * * @param private_list String (contents of virtual-private= from ipsec.conf) */ void init_virtual_ip(const char *private_list) { const char *str; int ign = 0, i_incl, i_excl; free_virtual_ip(); /** Count **/ str = private_list; while (str != NULL) { const char *next = strchr(str, ','); bool incl; ip_subnet sub; /* sink: value never used */ if (next == NULL) next = str + strlen(str); if (read_subnet(str, next - str, &sub, &sub, &incl)) { if (incl) private_net_incl_len++; else private_net_excl_len++; } else { ign++; } str = *next != '\0' ? next + 1 : NULL; } if (ign == 0) { /** Allocate **/ if (private_net_incl_len != 0) { private_net_incl = (ip_subnet *)alloc_bytes( (private_net_incl_len * sizeof(ip_subnet)), "private_net_incl subnets"); } if (private_net_excl_len != 0) { private_net_excl = (ip_subnet *)alloc_bytes( (private_net_excl_len * sizeof(ip_subnet)), "private_net_excl subnets"); } /** Fill **/ str = private_list; i_incl = 0; i_excl = 0; while (str != NULL) { const char *next = strchr(str, ','); bool incl; if (next == NULL) next = str + strlen(str); if (read_subnet(str, next - str, &(private_net_incl[i_incl]), &(private_net_excl[i_excl]), &incl)) { if (incl) i_incl++; else i_excl++; } str = *next != '\0' ? next + 1 : NULL; } } else { loglog(RC_LOG_SERIOUS, "%d bad entries in virtual-private - none loaded", ign); } }