]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Set hoplimit by IPV6_MULTICAST_HOPS intead of each time we send.
authorRoy Marples <roy@marples.name>
Wed, 12 Mar 2014 15:59:19 +0000 (15:59 +0000)
committerRoy Marples <roy@marples.name>
Wed, 12 Mar 2014 15:59:19 +0000 (15:59 +0000)
dhcp6.c
ipv6.c
ipv6.h
ipv6nd.c

diff --git a/dhcp6.c b/dhcp6.c
index b89cfd317d56bd6d04cfe4bfafc153ef90fb0566..9c1fbec13bd0f18ea3eb1736d0eb8dd7d7638ddb 100644 (file)
--- a/dhcp6.c
+++ b/dhcp6.c
@@ -833,7 +833,6 @@ logsend:
        ctx->sndhdr.msg_name = (caddr_t)&dst;
        ctx->sndhdr.msg_iov[0].iov_base = (caddr_t)state->send;
        ctx->sndhdr.msg_iov[0].iov_len = state->send_len;
-       ctx->sndhdr.msg_controllen = CMSG_SPACE(sizeof(struct in6_pktinfo));
 
        /* Set the outbound interface */
        cm = CMSG_FIRSTHDR(&ctx->sndhdr);
diff --git a/ipv6.c b/ipv6.c
index 1f321f5bed1587604a27394ad9f1dc05d7fd709f..1d13f64eb7df2719b69fcd8c378091c5b5bf015b 100644 (file)
--- a/ipv6.c
+++ b/ipv6.c
@@ -102,17 +102,17 @@ ipv6_init(struct dhcpcd_ctx *dhcpcd_ctx)
        }
        TAILQ_INIT(ctx->ra_routers);
 
-       // controllen is set at send/recieve
        ctx->sndhdr.msg_namelen = sizeof(struct sockaddr_in6);
        ctx->sndhdr.msg_iov = ctx->sndiov;
        ctx->sndhdr.msg_iovlen = 1;
        ctx->sndhdr.msg_control = ctx->sndbuf;
-       //ctx->sndhdr.msg_controllen = sizeof(ctx->sndbuf);
+       ctx->sndhdr.msg_controllen = sizeof(ctx->sndbuf);
        ctx->rcvhdr.msg_name = &ctx->from;
        ctx->rcvhdr.msg_namelen = sizeof(ctx->from);
        ctx->rcvhdr.msg_iov = ctx->rcviov;
        ctx->rcvhdr.msg_iovlen = 1;
        ctx->rcvhdr.msg_control = ctx->rcvbuf;
+       // controllen is set at recieve
        //ctx->rcvhdr.msg_controllen = sizeof(ctx->rcvbuf);
        ctx->rcviov[0].iov_base = ctx->ansbuf;
        ctx->rcviov[0].iov_len = sizeof(ctx->ansbuf);
diff --git a/ipv6.h b/ipv6.h
index 62c9573329d4cb7694949e659e0ba58955a7886a..4a89d85e36661d8402b3a09147c21ad9dd506af2 100644 (file)
--- a/ipv6.h
+++ b/ipv6.h
@@ -134,7 +134,7 @@ struct ipv6_ctx {
        struct sockaddr_in6 from;
        struct msghdr sndhdr;
        struct iovec sndiov[2];
-       unsigned char sndbuf[IP6BUFLEN];
+       unsigned char sndbuf[CMSG_SPACE(sizeof(struct in6_pktinfo))];
        struct msghdr rcvhdr;
        struct iovec rcviov[2];
        unsigned char rcvbuf[IP6BUFLEN];
index c03f9a0b5bcb8d4f5229ff7554dc022f8a7507fc..a755fe879c0d28978484fb986f9e1e86c263a432 100644 (file)
--- a/ipv6nd.c
+++ b/ipv6nd.c
@@ -184,6 +184,12 @@ ipv6nd_open(struct dhcpcd_ctx *dctx)
        }
 #endif
 
+       /* RFC4861 4.1 */
+       on = 255;
+       if (setsockopt(ctx->nd_fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
+           &on, sizeof(on)) == -1)
+               goto eexit;
+
        on = 1;
        if (setsockopt(ctx->nd_fd, IPPROTO_IPV6, IPV6_RECVPKTINFO,
            &on, sizeof(on)) == -1)
@@ -247,7 +253,6 @@ ipv6nd_sendrsprobe(void *arg)
        struct sockaddr_in6 dst;
        struct cmsghdr *cm;
        struct in6_pktinfo pi;
-       int hoplimit = 255; /* RFC4861 4.1 */
 
        if (ipv6_linklocal(ifp) == NULL) {
                syslog(LOG_DEBUG,
@@ -273,8 +278,6 @@ ipv6nd_sendrsprobe(void *arg)
        ctx->sndhdr.msg_name = (caddr_t)&dst;
        ctx->sndhdr.msg_iov[0].iov_base = state->rs;
        ctx->sndhdr.msg_iov[0].iov_len = state->rslen;
-       ctx->sndhdr.msg_controllen = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
-           CMSG_SPACE(sizeof(int));
 
        /* Set the outbound interface */
        cm = CMSG_FIRSTHDR(&ctx->sndhdr);
@@ -287,15 +290,6 @@ ipv6nd_sendrsprobe(void *arg)
        pi.ipi6_ifindex = ifp->index;
        memcpy(CMSG_DATA(cm), &pi, sizeof(pi));
 
-       /* Hop limit */
-       cm = CMSG_NXTHDR(&ctx->sndhdr, cm);
-       if (cm == NULL) /* unlikely */
-               return;
-       cm->cmsg_level = IPPROTO_IPV6;
-       cm->cmsg_type = IPV6_HOPLIMIT;
-       cm->cmsg_len = CMSG_LEN(sizeof(hoplimit));
-       memcpy(CMSG_DATA(cm), &hoplimit, sizeof(hoplimit));
-
        syslog(LOG_DEBUG, "%s: sending Router Solicitation", ifp->name);
        if (sendmsg(ctx->nd_fd, &ctx->sndhdr, 0) == -1) {
                syslog(LOG_ERR, "%s: %s: sendmsg: %m", ifp->name, __func__);
@@ -1247,7 +1241,6 @@ ipv6nd_proberouter(void *arg)
        struct sockaddr_in6 dst;
        struct cmsghdr *cm;
        struct in6_pktinfo pi;
-       int hoplimit = 255; /* RFC4861 4.1 */
        struct timeval tv, rtv;
        struct ipv6_ctx *ctx;
 
@@ -1287,8 +1280,6 @@ ipv6nd_proberouter(void *arg)
        ctx->sndhdr.msg_name = (caddr_t)&dst;
        ctx->sndhdr.msg_iov[0].iov_base = rap->ns;
        ctx->sndhdr.msg_iov[0].iov_len = rap->nslen;
-       ctx->sndhdr.msg_controllen = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
-           CMSG_SPACE(sizeof(int));
 
        /* Set the outbound interface */
        cm = CMSG_FIRSTHDR(&ctx->sndhdr);
@@ -1301,15 +1292,6 @@ ipv6nd_proberouter(void *arg)
        pi.ipi6_ifindex = rap->iface->index;
        memcpy(CMSG_DATA(cm), &pi, sizeof(pi));
 
-       /* Hop limit */
-       cm = CMSG_NXTHDR(&ctx->sndhdr, cm);
-       if (cm == NULL) /* unlikely */
-               return;
-       cm->cmsg_level = IPPROTO_IPV6;
-       cm->cmsg_type = IPV6_HOPLIMIT;
-       cm->cmsg_len = CMSG_LEN(sizeof(hoplimit));
-       memcpy(CMSG_DATA(cm), &hoplimit, sizeof(hoplimit));
-
 #ifdef DEBUG_NS
        syslog(LOG_INFO, "%s: sending IPv6 NS for %s",
            rap->iface->name, rap->sfrom);