From: Roy Marples Date: Fri, 2 Sep 2016 11:34:09 +0000 (+0000) Subject: Remove the need for statically sized receive buffers for IPv6 ND and DHCPv6 X-Git-Tag: v6.11.4~59 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2629170f018b01ab126451c89cfbf9a37b9b8fc7;p=thirdparty%2Fdhcpcd.git Remove the need for statically sized receive buffers for IPv6 ND and DHCPv6 messages. --- diff --git a/dhcp6.c b/dhcp6.c index 7b3935cc..5f183e56 100644 --- a/dhcp6.c +++ b/dhcp6.c @@ -2647,7 +2647,7 @@ dhcp6_handledata(void *arg) dctx = arg; ctx = dctx->ipv6; ctx->rcvhdr.msg_controllen = CMSG_SPACE(sizeof(struct in6_pktinfo)); - bytes = recvmsg(ctx->dhcp_fd, &ctx->rcvhdr, 0); + bytes = recvmsg_realloc(ctx->dhcp_fd, &ctx->rcvhdr, 0); if (bytes == -1) { logger(dctx, LOG_ERR, "%s: recvmsg: %m", __func__); close(ctx->dhcp_fd); diff --git a/ipv6.c b/ipv6.c index 2cd45be4..35ff4f79 100644 --- a/ipv6.c +++ b/ipv6.c @@ -154,19 +154,17 @@ ipv6_init(struct dhcpcd_ctx *dhcpcd_ctx) TAILQ_INIT(&ctx->kroutes); ctx->sndhdr.msg_namelen = sizeof(struct sockaddr_in6); - ctx->sndhdr.msg_iov = ctx->sndiov; + 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->rcvhdr.msg_name = &ctx->from; ctx->rcvhdr.msg_namelen = sizeof(ctx->from); - ctx->rcvhdr.msg_iov = ctx->rcviov; + ctx->rcvhdr.msg_iov = &dhcpcd_ctx->iov; ctx->rcvhdr.msg_iovlen = 1; - ctx->rcvhdr.msg_control = ctx->rcvbuf; + ctx->rcvhdr.msg_control = ctx->ctlbuf; // 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); ctx->nd_fd = -1; ctx->dhcp_fd = -1; diff --git a/ipv6.h b/ipv6.h index b433c016..4a1248b9 100644 --- a/ipv6.h +++ b/ipv6.h @@ -260,17 +260,14 @@ struct ipv6_state { #define IP6BUFLEN (CMSG_SPACE(sizeof(struct in6_pktinfo)) + \ CMSG_SPACE(sizeof(int))) - #ifdef INET6 struct ipv6_ctx { + unsigned char ctlbuf[IP6BUFLEN]; struct sockaddr_in6 from; struct msghdr sndhdr; - struct iovec sndiov[2]; + struct iovec sndiov; unsigned char sndbuf[CMSG_SPACE(sizeof(struct in6_pktinfo))]; struct msghdr rcvhdr; - struct iovec rcviov[2]; - unsigned char rcvbuf[IP6BUFLEN]; - unsigned char ansbuf[1500]; char ntopbuf[INET6_ADDRSTRLEN]; const char *sfrom; diff --git a/ipv6nd.c b/ipv6nd.c index 71075002..11415c1f 100644 --- a/ipv6nd.c +++ b/ipv6nd.c @@ -1551,7 +1551,7 @@ ipv6nd_handledata(void *arg) ctx = dctx->ipv6; ctx->rcvhdr.msg_controllen = CMSG_SPACE(sizeof(struct in6_pktinfo)) + CMSG_SPACE(sizeof(int)); - len = recvmsg(ctx->nd_fd, &ctx->rcvhdr, 0); + len = recvmsg_realloc(ctx->nd_fd, &ctx->rcvhdr, 0); if (len == -1) { logger(dctx, LOG_ERR, "recvmsg: %m"); eloop_event_delete(dctx->eloop, ctx->nd_fd);