From: Steven Barth Date: Mon, 21 Jul 2014 10:10:38 +0000 (+0200) Subject: Send router solicitations with source link-layer address X-Git-Url: http://git.cdn.openwrt.org/?a=commitdiff_plain;h=67b311ab81736b35858664219d345844ab08fcc7;p=project%2Fodhcp6c.git Send router solicitations with source link-layer address --- diff --git a/src/ra.c b/src/ra.c index 3e36f94..b700c9a 100644 --- a/src/ra.c +++ b/src/ra.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -132,9 +133,26 @@ int ra_init(const char *ifname, const struct in6_addr *ifid) static void ra_send_rs(int signal __attribute__((unused))) { - const struct icmp6_hdr rs = {ND_ROUTER_SOLICIT, 0, 0, {{0}}}; + struct { + struct icmp6_hdr hdr; + struct icmpv6_opt lladdr; + } rs = { + .hdr = {ND_ROUTER_SOLICIT, 0, 0, {{0}}}, + .lladdr = {ND_OPT_SOURCE_LINKADDR, 1, {0}}, + }; const struct sockaddr_in6 dest = {AF_INET6, 0, 0, ALL_IPV6_ROUTERS, if_index}; - sendto(sock, &rs, sizeof(rs), MSG_DONTWAIT, (struct sockaddr*)&dest, sizeof(dest)); + size_t len = sizeof(rs); + + struct ifreq ifr; + memset(&ifr, 0, sizeof(ifr)); + strncpy(ifr.ifr_name, if_name, sizeof(ifr.ifr_name)); + if (!ioctl(sock, SIOCGIFHWADDR, &ifr) + && memcmp(rs.lladdr.data, ifr.ifr_hwaddr.sa_data, 6)) + memcpy(rs.lladdr.data, ifr.ifr_hwaddr.sa_data, 6); + else + len = sizeof(struct icmp6_hdr); + + sendto(sock, &rs, len, MSG_DONTWAIT, (struct sockaddr*)&dest, sizeof(dest)); if (++rs_attempt <= 3) alarm(4);