]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
options: open an address socket to detect if inet6 is available
authorRoy Marples <roy@marples.name>
Sat, 25 Jul 2020 13:22:18 +0000 (14:22 +0100)
committerRoy Marples <roy@marples.name>
Sat, 1 Aug 2020 19:53:11 +0000 (20:53 +0100)
This should silence dhcpcd warnings if IPv6 is compiled out.
Do the same for IPv4, although that's highly unlikely as
it's kind of required for some interface ioctls.

src/if-options.c

index 917025d299449e410c3cd62f29e78f750747e908..4ba7cf775e9b7b5dde9eda9fd111cf64e522aef5 100644 (file)
@@ -59,6 +59,8 @@
 #define        SET_CONFIG_BLOCK(ifo)   ((ifo)->options |= DHCPCD_FORKED)
 #define        CLEAR_CONFIG_BLOCK(ifo) ((ifo)->options &= ~DHCPCD_FORKED)
 
+static unsigned long long default_options;
+
 const struct option cf_options[] = {
        {"background",      no_argument,       NULL, 'b'},
        {"script",          required_argument, NULL, 'c'},
@@ -2332,18 +2334,30 @@ read_config(struct dhcpcd_ctx *ctx,
        /* Seed our default options */
        if ((ifo = default_config(ctx)) == NULL)
                return NULL;
-       ifo->options |= DHCPCD_DAEMONISE | DHCPCD_GATEWAY;
-#ifdef PLUGIN_DEV
-       ifo->options |= DHCPCD_DEV;
-#endif
+       if (default_options == 0) {
+               default_options |= DHCPCD_DAEMONISE | DHCPCD_GATEWAY;
 #ifdef INET
-       ifo->options |= DHCPCD_IPV4 | DHCPCD_ARP | DHCPCD_DHCP | DHCPCD_IPV4LL;
+               skip = socket(PF_INET, SOCK_DGRAM, 0);
+               if (skip != -1) {
+                       close(skip);
+                       default_options |= DHCPCD_IPV4 | DHCPCD_ARP |
+                           DHCPCD_DHCP | DHCPCD_IPV4LL;
+               }
 #endif
 #ifdef INET6
-       ifo->options |= DHCPCD_IPV6 | DHCPCD_IPV6RS;
-       ifo->options |= DHCPCD_IPV6RA_AUTOCONF | DHCPCD_IPV6RA_REQRDNSS;
-       ifo->options |= DHCPCD_DHCP6;
+               skip = socket(PF_INET6, SOCK_DGRAM, 0);
+               if (skip != -1) {
+                       close(skip);
+                       default_options |= DHCPCD_IPV6 | DHCPCD_IPV6RS |
+                           DHCPCD_IPV6RA_AUTOCONF | DHCPCD_IPV6RA_REQRDNSS |
+                           DHCPCD_DHCP6;
+               }
+#endif
+#ifdef PLUGIN_DEV
+               default_options |= DHCPCD_DEV;
 #endif
+       }
+       ifo->options |= default_options;
 
        CLEAR_CONFIG_BLOCK(ifo);