Module Name:    src
Committed By:   roy
Date:           Wed May 10 11:03:44 UTC 2017

Modified Files:
        src/external/bsd/dhcpcd/dist/src: dhcpcd.c if-options.c

Log Message:
Sync


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/external/bsd/dhcpcd/dist/src/dhcpcd.c \
    src/external/bsd/dhcpcd/dist/src/if-options.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/bsd/dhcpcd/dist/src/dhcpcd.c
diff -u src/external/bsd/dhcpcd/dist/src/dhcpcd.c:1.3 src/external/bsd/dhcpcd/dist/src/dhcpcd.c:1.4
--- src/external/bsd/dhcpcd/dist/src/dhcpcd.c:1.3	Fri Apr 14 09:56:32 2017
+++ src/external/bsd/dhcpcd/dist/src/dhcpcd.c	Wed May 10 11:03:44 2017
@@ -477,6 +477,10 @@ configure_interface1(struct interface *i
 		 * between reboots without persitent storage,
 		 * generating the IAID from the MAC address is the only
 		 * logical default.
+		 * Saying that, if a VLANID has been specified then we
+		 * can use that. It's possible that different interfaces
+		 * can have the same VLANID, but this is no worse than
+		 * generating the IAID from the duplicate MAC address.
 		 *
 		 * dhclient uses the last 4 bytes of the MAC address.
 		 * dibbler uses an increamenting counter.
@@ -487,11 +491,18 @@ configure_interface1(struct interface *i
 		 * dhcpcd-6.1.0 and earlier used the interface name,
 		 * falling back to interface index if name > 4.
 		 */
-		if (ifp->hwlen >= sizeof(ifo->iaid))
+		if (ifp->vlanid != 0) {
+			uint32_t vlanid;
+
+			/* Maximal VLANID is 4095, so prefix with 0xff
+			 * so we don't conflict with an interface index. */
+			vlanid = htonl(ifp->vlanid | 0xff000000);
+			memcpy(ifo->iaid, &vlanid, sizeof(vlanid));
+		} else if (ifp->hwlen >= sizeof(ifo->iaid)) {
 			memcpy(ifo->iaid,
 			    ifp->hwaddr + ifp->hwlen - sizeof(ifo->iaid),
 			    sizeof(ifo->iaid));
-		else {
+		} else {
 			uint32_t len;
 
 			len = (uint32_t)strlen(ifp->name);
@@ -503,7 +514,7 @@ configure_interface1(struct interface *i
 			} else {
 				/* IAID is the same size as a uint32_t */
 				len = htonl(ifp->index);
-				memcpy(ifo->iaid, &len, sizeof(len));
+				memcpy(ifo->iaid, &len, sizeof(ifo->iaid));
 			}
 		}
 		ifo->options |= DHCPCD_IAID;
@@ -775,7 +786,7 @@ warn_iaid_conflict(struct interface *ifp
 
 	/* This is only a problem if the interfaces are on the same network. */
 	if (ifn)
-		logerr("%s: IAID conflicts with one assigned to %s",
+		logerrx("%s: IAID conflicts with one assigned to %s",
 		    ifp->name, ifn->name);
 }
 
@@ -1510,6 +1521,7 @@ main(int argc, char **argv)
 #endif
 		case 'P':
 			ctx.options |= DHCPCD_PRINT_PIDFILE;
+			logopts &= ~(LOGERR_LOG | LOGERR_ERR);
 			break;
 		case 'T':
 			i = 1;
@@ -1603,10 +1615,12 @@ printpidfile:
 		 *  instance for that interface. */
 		if (optind == argc - 1 && !(ctx.options & DHCPCD_MASTER)) {
 			const char *per;
+			const char *ifname;
 
-			if (strlen(argv[optind]) > IF_NAMESIZE) {
-				logerrx("%s: interface name too long",
-				    argv[optind]);
+			ifname = *ctx.ifv;
+			if (ifname == NULL || strlen(ifname) > IF_NAMESIZE) {
+				errno = ifname == NULL ? EINVAL : E2BIG;
+				logerr("%s: ", ifname);
 				goto exit_failure;
 			}
 			/* Allow a dhcpcd interface per address family */
@@ -1621,7 +1635,7 @@ printpidfile:
 				per = "";
 			}
 			snprintf(ctx.pidfile, sizeof(ctx.pidfile),
-			    PIDFILE, "-", argv[optind], per);
+			    PIDFILE, "-", ifname, per);
 		} else {
 			snprintf(ctx.pidfile, sizeof(ctx.pidfile),
 			    PIDFILE, "", "", "");
@@ -1643,20 +1657,13 @@ printpidfile:
 		goto exit_failure;
 	}
 
-	/* Open our persistent sockets.
-	 * This is needed early for dumping leases on valid interfaces. */
-#ifdef USE_SIGNALS
-	if (sig == 0) {
-#endif
+	if (ctx.options & DHCPCD_DUMPLEASE) {
+		/* Open sockets so we can dump something about
+		 * valid interfaces. */
 		if (if_opensockets(&ctx) == -1) {
 			logerr("%s: if_opensockets", __func__);
 			goto exit_failure;
 		}
-#ifdef USE_SIGNALS
-	}
-#endif
-
-	if (ctx.options & DHCPCD_DUMPLEASE) {
 		if (optind != argc) {
 			/* We need to try and find the interface so we can load
 			 * the hardware address to compare automated IAID */
@@ -1803,6 +1810,12 @@ printpidfile:
 
 	logdebugx(PACKAGE "-" VERSION " starting");
 	ctx.options |= DHCPCD_STARTED;
+
+	if (if_opensockets(&ctx) == -1) {
+		logerr("%s: if_opensockets", __func__);
+		goto exit_failure;
+	}
+
 #ifdef USE_SIGNALS
 	if (eloop_signal_set_cb(ctx.eloop,
 	    dhcpcd_signals, dhcpcd_signals_len,
Index: src/external/bsd/dhcpcd/dist/src/if-options.c
diff -u src/external/bsd/dhcpcd/dist/src/if-options.c:1.3 src/external/bsd/dhcpcd/dist/src/if-options.c:1.4
--- src/external/bsd/dhcpcd/dist/src/if-options.c:1.3	Fri Apr 14 09:56:32 2017
+++ src/external/bsd/dhcpcd/dist/src/if-options.c	Wed May 10 11:03:44 2017
@@ -93,7 +93,7 @@
 #define O_IPV6			O_BASE + 33
 #define O_CONTROLGRP		O_BASE + 34
 #define O_SLAAC			O_BASE + 35
-// unused			O_BASE + 36
+#define O_GATEWAY		O_BASE + 36
 #define O_NOUP			O_BASE + 37
 #define O_IPV6RA_AUTOCONF	O_BASE + 38
 #define O_IPV6RA_NOAUTOCONF	O_BASE + 39
@@ -196,6 +196,7 @@ const struct option cf_options[] = {
 	{"nodhcp6",         no_argument,       NULL, O_NODHCP6},
 	{"controlgroup",    required_argument, NULL, O_CONTROLGRP},
 	{"slaac",           required_argument, NULL, O_SLAAC},
+	{"gateway",         no_argument,       NULL, O_GATEWAY},
 	{"reject",          required_argument, NULL, O_REJECT},
 	{"bootp",           no_argument,       NULL, O_BOOTP},
 	{"nodelay",         no_argument,       NULL, O_NODELAY},
@@ -978,6 +979,9 @@ parse_option(struct dhcpcd_ctx *ctx, con
 			return -1;
 		}
 		break;
+	case 'G':
+		ifo->options &= ~DHCPCD_GATEWAY;
+		break;
 	case 'H':
 		ifo->options |= DHCPCD_XID_HWADDR;
 		break;
@@ -1062,8 +1066,14 @@ parse_option(struct dhcpcd_ctx *ctx, con
 		    strncmp(arg, "ms_classless_static_routes=",
 		        strlen("ms_classless_static_routes=")) == 0)
 		{
+			struct interface *ifp;
 			struct in_addr addr3;
 
+			ifp = if_find(ctx->ifaces, ifname);
+			if (ifp == NULL) {
+				logerrx("static routes require an interface");
+				return -1;
+			}
 			fp = np = strwhite(p);
 			if (np == NULL) {
 				logerrx("all routes need a gateway");
@@ -1077,7 +1087,7 @@ parse_option(struct dhcpcd_ctx *ctx, con
 				*fp = ' ';
 				return -1;
 			}
-			if ((rt = rt_new(if_find(ctx->ifaces, ifname))) == NULL) {
+			if ((rt = rt_new(ifp)) == NULL) {
 				*fp = ' ';
 				return -1;
 			}
@@ -1087,9 +1097,16 @@ parse_option(struct dhcpcd_ctx *ctx, con
 			TAILQ_INSERT_TAIL(&ifo->routes, rt, rt_next);
 			*fp = ' ';
 		} else if (strncmp(arg, "routers=", strlen("routers=")) == 0) {
+			struct interface *ifp;
+
+			ifp = if_find(ctx->ifaces, ifname);
+			if (ifp == NULL) {
+				logerrx("static routes require an interface");
+				return -1;
+			}
 			if (parse_addr(&addr, NULL, p) == -1)
 				return -1;
-			if ((rt = rt_new(if_find(ctx->ifaces, ifname))) == NULL)
+			if ((rt = rt_new(ifp)) == NULL)
 				return -1;
 			addr2.s_addr = INADDR_ANY;
 			sa_in_init(&rt->rt_dest, &addr2);
@@ -2078,6 +2095,9 @@ err_sla:
 		ctx->control_group = grp->gr_gid;
 #endif
 		break;
+	case O_GATEWAY:
+		ifo->options |= DHCPCD_GATEWAY;
+		break;
 	case O_NOUP:
 		ifo->options &= ~DHCPCD_IF_UP;
 		break;
@@ -2257,7 +2277,7 @@ read_config(struct dhcpcd_ctx *ctx,
 	/* Seed our default options */
 	if ((ifo = default_config(ctx)) == NULL)
 		return NULL;
-	ifo->options |= DHCPCD_DAEMONISE;
+	ifo->options |= DHCPCD_DAEMONISE | DHCPCD_GATEWAY;
 #ifdef PLUGIN_DEV
 	ifo->options |= DHCPCD_DEV;
 #endif

Reply via email to