From 67b311ab81736b35858664219d345844ab08fcc7 Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Mon, 21 Jul 2014 12:10:38 +0200 Subject: [PATCH] Send router solicitations with source link-layer address --- src/ra.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) 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); -- 2.25.1