int starter_ifaces_load (char **ifaces, unsigned int omtu, int nat_t) { char *tmp_phys, *phys; int n; char **i; int sock; int j, found; int ret = 0; starter_log(LOG_LEVEL_DEBUG, "starter_ifaces_load()"); sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) return -1; for (j=0; j<N_IPSEC_IF; j++) { found = 0; for (i=ifaces; i && *i; i++) { if ((valid_str(*i, &n, &tmp_phys)) && (tmp_phys) && (n>=0) && (n<N_IPSEC_IF)) { if (n==j) { if (found) { starter_log(LOG_LEVEL_ERR, "ignoring duplicate entry for interface ipsec%d", j); } else { found++; phys = _find_physical_iface(sock, tmp_phys); if (phys) { ret += _iface_up (sock, &(_ipsec_if[n]), phys, omtu, nat_t); } else { ret += _iface_down (sock, &(_ipsec_if[n])); } } } } else if (j==0) { /** * Only log in the first loop */ starter_log(LOG_LEVEL_ERR, "ignoring invalid interface '%s'", *i); } } if (!found) ret += _iface_down (sock, &(_ipsec_if[j])); } close(sock); return ret; /* = number of changes - 'whack --listen' if > 0 */ }
void starter_ifaces_clear (void) { int sock; unsigned int i; sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) return; for (i=0; i<N_IPSEC_IF; i++) { _iface_down (sock, &(_ipsec_if[i])); } }
int starter_ifaces_load(char **ifaces, unsigned int omtu, bool nat_t , defaultroute_t *defaultroute) { char *tmp_phys, *phys; int n; char **i; int sock; int j, found; int ret = 0; struct ifreq physreq, ipsecreq; // re-attach interface struct sockaddr_in *inp1, *inp2; // re-attach interface DBG(DBG_CONTROL, DBG_log("starter_ifaces_load()") ) sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) return -1; for (j = 0; j < N_IPSEC_IF; j++) { found = 0; for (i = ifaces; i && *i; i++) { if (valid_str(*i, &n, &tmp_phys, defaultroute) && tmp_phys && n >= 0 && n < N_IPSEC_IF) { if (n==j) { if (found) { plog( "ignoring duplicate entry for interface ipsec%d", j); } else { found++; phys = _find_physical_iface(sock, tmp_phys); /* Re-attach ipsec interface if IP address changes * [email protected] */ if (phys) { memset ((void*)&physreq, 0, sizeof(physreq)); memset ((void*)&ipsecreq, 0, sizeof(ipsecreq)); strncpy(physreq.ifr_name, phys, IFNAMSIZ); sprintf(ipsecreq.ifr_name, "ipsec%d", j); ioctl(sock, SIOCGIFADDR, &physreq); ioctl(sock, SIOCGIFADDR, &ipsecreq); inp1 = (struct sockaddr_in *)&physreq.ifr_addr; inp2 = (struct sockaddr_in *)&ipsecreq.ifr_addr; if (inp1->sin_addr.s_addr != inp2->sin_addr.s_addr) { plog("IP address of physical interface changed " "-> reinit of ipsec interface"); _iface_down (sock, &(_ipsec_if[n])); } ret += _iface_up (sock, &(_ipsec_if[n]), phys, omtu, nat_t); } else { ret += _iface_down (sock, &(_ipsec_if[n])); } } } } else if (j == 0) { /* Only log in the first loop */ plog("ignoring invalid interface '%s'", *i); } } if (!found) ret += _iface_down (sock, &(_ipsec_if[j])); } close(sock); return ret; /* = number of changes - 'whack --listen' if > 0 */ }