ndp: remove bindtodevice workaround
[project/odhcpd.git] / src / ndp.c
index 027e9ab..b5bab27 100644 (file)
--- a/src/ndp.c
+++ b/src/ndp.c
@@ -215,10 +215,6 @@ static ssize_t ping6(struct in6_addr *addr,
        struct sockaddr_in6 dest = {AF_INET6, 0, 0, *addr, iface->ifindex};
        struct icmp6_hdr echo = {.icmp6_type = ICMP6_ECHO_REQUEST};
        struct iovec iov = {&echo, sizeof(echo)};
-
-       // Linux seems to not honor IPV6_PKTINFO on raw-sockets, so work around
-       setsockopt(ping_socket, SOL_SOCKET, SO_BINDTODEVICE,
-                       iface->ifname, sizeof(iface->ifname));
        return odhcpd_send(ping_socket, &dest, &iov, 1, iface);
 }
 
@@ -356,11 +352,12 @@ static void handle_rtnetlink(_unused void *addr, void *data, size_t len,
 
                // Data to retrieve
                size_t rta_offset = (is_route) ? sizeof(*rtm) : (is_addr) ?
-                               sizeof(*ifa) : sizeof(*ndm);
+                               sizeof(struct ifaddrmsg) : sizeof(*ndm);
                uint16_t atype = (is_route) ? RTA_DST : (is_addr) ? IFA_ADDRESS : NDA_DST;
                ssize_t alen = NLMSG_PAYLOAD(nh, rta_offset);
                struct in6_addr *addr = NULL;
                int *ifindex = (!is_route) ? &ndm->ndm_ifindex : NULL;
+               int *metric = NULL;
 
                for (struct rtattr *rta = (void*)(((uint8_t*)ndm) + rta_offset);
                                RTA_OK(rta, alen); rta = RTA_NEXT(rta, alen)) {
@@ -373,6 +370,8 @@ static void handle_rtnetlink(_unused void *addr, void *data, size_t len,
                        } else if (is_route && rta->rta_type == RTA_GATEWAY) {
                                ifindex = NULL;
                                break;
+                       } else if (is_route && rta->rta_type == RTA_PRIORITY) {
+                               metric = (int*)RTA_DATA(rta);
                        }
                }
 
@@ -491,6 +490,7 @@ static void handle_rtnetlink(_unused void *addr, void *data, size_t len,
                                list_for_each_entry(c, &interfaces, head) {
                                        if (c->ndp == RELAYD_RELAY && !c->master) {
                                                *ifindex = c->ifindex;
+                                               *metric = (*metric & 0xffff) | (c->ifindex << 16);
                                                send(rtnl_event.uloop.fd, nh, nh->nlmsg_len, MSG_DONTWAIT);
                                        }
                                }