int starter_ifaces_load (char **ifaces, unsigned int omtu, int nat_t) { char *tmp_phys, *phys; unsigned int n; char **i; int sock; int j, found; int ret = 0; starter_log(LOG_LEVEL_DEBUG, "starter_ifaces_load()"); sock = safe_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 = starter_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 */ }
int starter_iface_find(char *iface, int af, ip_address *dst, ip_address *nh) { char *phys; struct ifreq req; struct sockaddr_in *sa = (struct sockaddr_in *)(&req.ifr_addr); int sock; if (!iface) return -1; sock = safe_socket(af, SOCK_DGRAM, 0); if (sock < 0) return -1; phys = starter_find_physical_iface(sock, iface); if (!phys) goto failed; strncpy(req.ifr_name, phys, IFNAMSIZ); if (ioctl(sock, SIOCGIFFLAGS, &req)!=0) goto failed; if (!(req.ifr_flags & IFF_UP)) goto failed; if ((req.ifr_flags & IFF_POINTOPOINT) && (nh) && (ioctl(sock, SIOCGIFDSTADDR, &req)==0)) { if (sa->sin_family == af) { initaddr((const void *)&sa->sin_addr, sizeof(struct in_addr), af, nh); } } if ((dst) && (ioctl(sock, SIOCGIFADDR, &req)==0)) { if (sa->sin_family == af) { initaddr((const void *)&sa->sin_addr, sizeof(struct in_addr), af, dst); } } close(sock); return 0; failed: close(sock); return -1; }