X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fodhcpd.git;a=blobdiff_plain;f=src%2Fndp.c;h=50529b536f6fa4949d377ea819820e5b48266feb;hp=6d18bb5bae5e9e135dce833c6e8770c3268fc88b;hb=df3dac62087211a1d4b2827897d80270ba51e413;hpb=e9a21fdb43c9f94762a724db1a043b376f745ae3 diff --git a/src/ndp.c b/src/ndp.c index 6d18bb5..50529b5 100644 --- a/src/ndp.c +++ b/src/ndp.c @@ -32,9 +32,9 @@ static void handle_solicit(void *addr, void *data, size_t len, - struct interface *iface); + struct interface *iface, void *dest); static void handle_rtnetlink(void *addr, void *data, size_t len, - struct interface *iface); + struct interface *iface, void *dest); static struct ndp_neighbor* find_neighbor(struct in6_addr *addr, bool strict); static void modify_neighbor(struct in6_addr *addr, struct interface *iface, bool add); @@ -111,6 +111,10 @@ int init_ndp(void) // Open ICMPv6 socket ping_socket = socket(AF_INET6, SOCK_RAW | SOCK_CLOEXEC, IPPROTO_ICMPV6); + if (ping_socket < 0) { + syslog(LOG_ERR, "Unable to open raw socket: %s", strerror(errno)); + return -1; + } int val = 2; setsockopt(ping_socket, IPPROTO_RAW, IPV6_CHECKSUM, &val, sizeof(val)); @@ -167,6 +171,7 @@ int setup_ndp_interface(struct interface *iface, bool enable) memcpy(entry, iface->static_ndp, iface->static_ndp_len); for (entry = strtok_r(entry, " ", &saveptr); entry; entry = strtok_r(NULL, " ", &saveptr)) { + char *sep; struct ndp_neighbor *n = malloc(sizeof(*n)); if (!n) { syslog(LOG_ERR, "Malloc failed for static NDP-prefix %s", entry); @@ -176,12 +181,20 @@ int setup_ndp_interface(struct interface *iface, bool enable) n->iface = iface; n->timeout = 0; - char ipbuf[INET6_ADDRSTRLEN]; - if (sscanf(entry, "%45s/%hhu", ipbuf, &n->len) < 2 - || n->len > 128 || inet_pton(AF_INET6, ipbuf, &n->addr) != 1) { + sep = strchr(entry, '/'); + if (!sep) { + free(n); syslog(LOG_ERR, "Invalid static NDP-prefix %s", entry); return -1; } + + *sep = 0; + n->len = atoi(sep + 1); + if (inet_pton(AF_INET6, entry, &n->addr) != 1 || n->len > 128) { + free(n); + syslog(LOG_ERR, "Invalid static NDP-prefix %s/%s", entry, sep + 1); + return -1; + } list_add(&n->head, &neighbors); } @@ -210,7 +223,7 @@ static ssize_t ping6(struct in6_addr *addr, // Handle solicitations static void handle_solicit(void *addr, void *data, size_t len, - struct interface *iface) + struct interface *iface, _unused void *dest) { struct ip6_hdr *ip6 = data; struct nd_neighbor_solicit *req = (struct nd_neighbor_solicit*)&ip6[1]; @@ -422,7 +435,7 @@ static void modify_neighbor(struct in6_addr *addr, // Handler for neighbor cache entries from the kernel. This is our source // to learn and unlearn hosts on interfaces. static void handle_rtnetlink(_unused void *addr, void *data, size_t len, - _unused struct interface *iface) + _unused struct interface *iface, _unused void *dest) { for (struct nlmsghdr *nh = data; NLMSG_OK(nh, len); nh = NLMSG_NEXT(nh, len)) {