]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-ndisc: always send the link-layer address
authorTom Gundersen <teg@jklm.no>
Mon, 23 Nov 2015 14:49:10 +0000 (15:49 +0100)
committerTom Gundersen <teg@jklm.no>
Wed, 25 Nov 2015 17:30:31 +0000 (18:30 +0100)
We never send packets without first knowing the link-local L3 address,
so we should always include the L2 address in RS packets.

src/libsystemd-network/icmp6-util.c
src/libsystemd-network/sd-ndisc.c

index 91308bf6c33ccadf0e14e3346cd6a1ce9cef1295..03505fc47bf1ee69af4a08c745692b6d1077c047 100644 (file)
@@ -101,25 +101,25 @@ int icmp6_send_router_solicitation(int s, const struct ether_addr *ether_addr) {
                 struct ether_addr rs_opt_mac;
         } _packed_ rs = {
                 .rs.nd_rs_type = ND_ROUTER_SOLICIT,
+                .rs_opt.nd_opt_type = ND_OPT_SOURCE_LINKADDR,
+                .rs_opt.nd_opt_len = 1,
         };
-        struct iovec iov[1] = {
-                { &rs, },
+        struct iovec iov = {
+                .iov_base = &rs,
+                .iov_len = sizeof(rs),
         };
         struct msghdr msg = {
                 .msg_name = &dst,
                 .msg_namelen = sizeof(dst),
-                .msg_iov = iov,
+                .msg_iov = &iov,
                 .msg_iovlen = 1,
         };
         int r;
 
-        if (ether_addr) {
-                memcpy(&rs.rs_opt_mac, ether_addr, ETH_ALEN);
-                rs.rs_opt.nd_opt_type = ND_OPT_SOURCE_LINKADDR;
-                rs.rs_opt.nd_opt_len = 1;
-                iov[0].iov_len = sizeof(rs);
-        } else
-                iov[0].iov_len = sizeof(rs.rs);
+        assert(s >= 0);
+        assert(ether_addr);
+
+        rs.rs_opt_mac = *ether_addr;
 
         r = sendmsg(s, &msg, 0);
         if (r < 0)
index 5591bc78410f91755164044588b04ae2fc461651..249586f0485f2431f85269797fa09a92f0353c27 100644 (file)
@@ -572,8 +572,6 @@ static int ndisc_router_advertisment_recv(sd_event_source *s, int fd, uint32_t r
 static int ndisc_router_solicitation_timeout(sd_event_source *s, uint64_t usec, void *userdata) {
         sd_ndisc *nd = userdata;
         uint64_t time_now, next_timeout;
-        struct ether_addr unset = { };
-        struct ether_addr *addr = NULL;
         int r;
 
         assert(s);
@@ -587,10 +585,7 @@ static int ndisc_router_solicitation_timeout(sd_event_source *s, uint64_t usec,
                         nd->callback(nd, SD_NDISC_EVENT_TIMEOUT, nd->userdata);
                 nd->state = NDISC_STATE_ADVERTISMENT_LISTEN;
         } else {
-                if (memcmp(&nd->mac_addr, &unset, sizeof(struct ether_addr)))
-                        addr = &nd->mac_addr;
-
-                r = icmp6_send_router_solicitation(nd->fd, addr);
+                r = icmp6_send_router_solicitation(nd->fd, &nd->mac_addr);
                 if (r < 0)
                         log_ndisc(nd, "Error sending Router Solicitation");
                 else {