From: Roy Marples Date: Mon, 4 Nov 2019 17:21:33 +0000 (+0000) Subject: BSD: Disable kernel RTADV sysctl earlier X-Git-Tag: v8.1.2~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c638eac8065e21fbef84db75a04f6a4a5a11e2b5;p=thirdparty%2Fdhcpcd.git BSD: Disable kernel RTADV sysctl earlier Just makes life a bit easier. --- diff --git a/src/dhcpcd.c b/src/dhcpcd.c index 2b04bb3e..474b6abe 100644 --- a/src/dhcpcd.c +++ b/src/dhcpcd.c @@ -1995,6 +1995,12 @@ printpidfile: ctx.options & DHCPCD_IPV4 ? " [ip4]" : "", ctx.options & DHCPCD_IPV6 ? " [ip6]" : ""); +#ifdef BSD + /* Disable the kernel RTADV sysctl as early as possible. */ + if (ctx.options & DHCPCD_IPV6 && ctx.options & DHCPCD_IPV6RS) + if_disable_rtadv(); +#endif + if (if_opensockets(&ctx) == -1) { logerr("%s: if_opensockets", __func__); goto exit_failure; diff --git a/src/if-bsd.c b/src/if-bsd.c index a2c613ed..d2e910ef 100644 --- a/src/if-bsd.c +++ b/src/if-bsd.c @@ -1619,6 +1619,22 @@ set_ifxflags(int s, const struct interface *ifp) #define ND6_NDI_FLAGS #endif +void +if_disable_rtadv(void) +{ +#if defined(IPV6CTL_ACCEPT_RTADV) && !defined(ND6_IFF_ACCEPT_RTADV) + int ra = get_inet6_sysctl(IPV6CTL_ACCEPT_RTADV); + + if (ra == -1) { + if (errno != ENOENT) + logerr("IPV6CTL_ACCEPT_RTADV"); + else if (ra != 0) + if (set_inet6_sysctl(IPV6CTL_ACCEPT_RTADV, 0) == -1) + logerr("IPV6CTL_ACCEPT_RTADV"); + } +#endif +} + void if_setup_inet6(const struct interface *ifp) { @@ -1690,21 +1706,6 @@ if_setup_inet6(const struct interface *ifp) logerr("%s: set_ifxflags", ifp->name); #endif -#if defined(IPV6CTL_ACCEPT_RTADV) && !defined(ND6_IFF_ACCEPT_RTADV) - /* If we cannot control ra per interface, disable it globally. */ - if (ifp->options->options & DHCPCD_IPV6RS) { - int ra = get_inet6_sysctl(IPV6CTL_ACCEPT_RTADV); - - if (ra == -1) { - if (errno != ENOENT) - logerr("IPV6CTL_ACCEPT_RTADV"); - else if (ra != 0) - if (set_inet6_sysctl(IPV6CTL_ACCEPT_RTADV, 0) == -1) - logerr("IPV6CTL_ACCEPT_RTADV"); - } - } -#endif - #if defined(IPV6CTL_ACCEPT_RTADV) || defined(ND6_IFF_ACCEPT_RTADV) /* Flush the kernel knowledge of advertised routers * and prefixes so the kernel does not expire prefixes diff --git a/src/if.h b/src/if.h index 19b6b2fe..ecfdb102 100644 --- a/src/if.h +++ b/src/if.h @@ -195,6 +195,7 @@ int if_addrflags(const struct interface *, const struct in_addr *, #endif #ifdef INET6 +void if_disable_rtadv(void); void if_setup_inet6(const struct interface *); #ifdef IPV6_MANAGETEMPADDR int ip6_use_tempaddr(const char *ifname);