]> git.decadent.org.uk Git - odhcp6c.git/commitdiff
Send router solicitations with source link-layer address
authorSteven Barth <steven@midlink.org>
Mon, 21 Jul 2014 10:10:38 +0000 (12:10 +0200)
committerSteven Barth <steven@midlink.org>
Mon, 21 Jul 2014 10:10:38 +0000 (12:10 +0200)
src/ra.c

index 3e36f94692e14921cb9aa94132d032181cf654e1..b700c9a8270a10aba5a162f10d0c4c061e785e27 100644 (file)
--- a/src/ra.c
+++ b/src/ra.c
@@ -26,6 +26,7 @@
 #include <arpa/inet.h>
 #include <sys/socket.h>
 #include <sys/types.h>
+#include <sys/ioctl.h>
 #include <netinet/in.h>
 #include <netinet/icmp6.h>
 
@@ -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);