From: Roy Marples Date: Sat, 25 Jul 2020 13:22:18 +0000 (+0100) Subject: options: open an address socket to detect if inet6 is available X-Git-Tag: v9.2.0~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=465198ad6453f68eb1223615d4ab5deefc0294cf;p=thirdparty%2Fdhcpcd.git options: open an address socket to detect if inet6 is available 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. --- diff --git a/src/if-options.c b/src/if-options.c index 917025d2..4ba7cf77 100644 --- a/src/if-options.c +++ b/src/if-options.c @@ -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);