]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
If not running in master mode, allow dhcpcd to bind directly to the interface
authorRoy Marples <roy@marples.name>
Sun, 14 Aug 2016 08:30:13 +0000 (08:30 +0000)
committerRoy Marples <roy@marples.name>
Sun, 14 Aug 2016 08:30:13 +0000 (08:30 +0000)
for DHCPv6. This allows more than once dhcpcd instance to work with DHCPv6.

dhcp6.c

diff --git a/dhcp6.c b/dhcp6.c
index 7863a30a9676513d03209820b8b605f044886aa1..45fd5e3fc94de20f46a2ddba063c80481858ed61 100644 (file)
--- a/dhcp6.c
+++ b/dhcp6.c
@@ -3174,6 +3174,29 @@ dhcp6_open(struct dhcpcd_ctx *dctx)
                logger(dctx, LOG_WARNING, "setsockopt: SO_REUSEPORT: %m");
 #endif
 
+#ifdef SO_BINDTODEVICE
+       /* If we're not running in master mode, we can bind directly to the
+        * interface. This allows separate daemons to work on separate
+        * interfaces. */
+       if (!(dctx->options & DHCPCD_MASTER)) {
+               const struct interface *ifp;
+               struct ifreq ifr;
+
+               TAILQ_FOREACH(ifp, dctx->ifaces, next) {
+                       if (ifp->active)
+                               break;
+               }
+               if (ifp != NULL) {
+                       memset(&ifr, 0, sizeof(ifr));
+                       strlcpy(ifr.ifr_name, ifp->name, sizeof(ifr.ifr_name));
+                       if (setsockopt(ctx->dhcp_fd, SOL_SOCKET, SO_BINDTODEVICE, &ifr,
+                           sizeof(ifr)) == -1)
+                               logger(dctx, LOG_WARNING,
+                                   "setsockopt: SO_BINDTODEVICE: %m");
+               }
+       }
+#endif
+
        if (bind(ctx->dhcp_fd, (struct sockaddr *)&sa, sizeof(sa)) == -1)
                goto errexit;