From: Roy Marples Date: Thu, 14 Mar 2019 00:17:26 +0000 (+0000) Subject: options: add link_rcvbuf variable X-Git-Tag: v8.0.0~56 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=281818ae04591a3c219623ebb91f22179ba89860;p=thirdparty%2Fdhcpcd.git options: add link_rcvbuf variable Sets SO_RCVBUF on the link socket to the designated size. On a busy system this can be inflated to avoid buffer overflow. However, dhcpcd *will* cope fine with overflow on NetBSD, OpenBSD and Linux with a call to getifaddrs(3), but that might be too heavy weight depending on the libc implementation as most don't report address flags via this method. --- diff --git a/src/dhcpcd.c b/src/dhcpcd.c index f7927140..8986a9b4 100644 --- a/src/dhcpcd.c +++ b/src/dhcpcd.c @@ -1128,6 +1128,22 @@ dhcpcd_checkcarrier(void *arg) dhcpcd_handlecarrier(ifp->ctx, LINK_UNKNOWN, ifp->flags, ifp->name); } +#ifndef SMALL +static void +dhcpcd_setlinkrcvbuf(struct dhcpcd_ctx *ctx) +{ + socklen_t socklen; + + if (ctx->link_rcvbuf == 0) + return; + + socklen = sizeof(ctx->link_rcvbuf); + if (setsockopt(ctx->link_fd, SOL_SOCKET, + SO_RCVBUF, &ctx->link_rcvbuf, socklen) == -1) + logerr(__func__); +} +#endif + void dhcpcd_linkoverflow(struct dhcpcd_ctx *ctx) { @@ -1148,6 +1164,9 @@ dhcpcd_linkoverflow(struct dhcpcd_ctx *ctx) eloop_exit(ctx->eloop, EXIT_FAILURE); return; } +#ifndef SMALL + dhcpcd_setlinkrcvbuf(ctx); +#endif eloop_event_add(ctx->eloop, ctx->link_fd, dhcpcd_handlelink, ctx); /* Work out the current interfaces. */ @@ -1993,6 +2012,9 @@ printpidfile: logerr("%s: if_opensockets", __func__); goto exit_failure; } +#ifndef SMALL + dhcpcd_setlinkrcvbuf(&ctx); +#endif /* When running dhcpcd against a single interface, we need to retain * the old behaviour of waiting for an IP address */ diff --git a/src/dhcpcd.conf.5.in b/src/dhcpcd.conf.5.in index f792b15f..70b38ae5 100644 --- a/src/dhcpcd.conf.5.in +++ b/src/dhcpcd.conf.5.in @@ -22,7 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd September 15, 2018 +.Dd March 8, 2019 .Dt DHCPCD.CONF 5 .Os .Sh NAME @@ -429,6 +429,12 @@ globally but needs to be enabled for one interface. .It Ic leasetime Ar seconds Request a leasetime of .Ar seconds . +.It Ic link_rcvbuf Ar size +Override the size of the link receive buffer from the kernel default. +While +.Nm dhcpcd +will recover from link buffer overflows, +this may not be desirable on heavily loaded systems. .It Ic logfile Ar logfile Writes to the specified .Ar logfile diff --git a/src/dhcpcd.h b/src/dhcpcd.h index df229fd3..4df57a88 100644 --- a/src/dhcpcd.h +++ b/src/dhcpcd.h @@ -145,6 +145,9 @@ struct dhcpcd_ctx { int pf_inet_fd; void *priv; int link_fd; +#ifndef SMALL + int link_rcvbuf; +#endif int seq; /* route message sequence no */ int sseq; /* successful seq no sent */ diff --git a/src/if-options.c b/src/if-options.c index 27354629..8f6c0372 100644 --- a/src/if-options.c +++ b/src/if-options.c @@ -64,7 +64,7 @@ #define O_IPV6RS O_BASE + 4 #define O_NOIPV6RS O_BASE + 5 #define O_IPV6RA_FORK O_BASE + 6 -// unused O_BASE + 7 +#define O_LINK_RCVBUF O_BASE + 7 // unused O_BASE + 8 #define O_NOALIAS O_BASE + 9 #define O_IA_NA O_BASE + 10 @@ -204,6 +204,7 @@ const struct option cf_options[] = { {"lastleaseextend", no_argument, NULL, O_LASTLEASE_EXTEND}, {"inactive", no_argument, NULL, O_INACTIVE}, {"mudurl", required_argument, NULL, O_MUDURL}, + {"link_rcvbuf", required_argument, NULL, O_LINK_RCVBUF}, {NULL, 0, NULL, '\0'} }; @@ -2173,6 +2174,16 @@ err_sla: } *ifo->mudurl = (uint8_t)s; break; + case O_LINK_RCVBUF: +#ifndef SMALL + ARG_REQUIRED; + ctx->link_rcvbuf = (int)strtoi(arg, NULL, 0, 0, INT32_MAX, &e); + if (e) { + logerrx("failed to convert link_rcvbuf %s", arg); + return -1; + } +#endif + break; default: return 0; }