Regardless if we are a router or not.
BSD IPv6 source address selection does really matter for this.
This fixes FreeBSD systes where the forwarding sysctl is set
by the routing script which starts late in the day where
dhcpcd is already running and won't get the default route applied
until another RA comes in which could be a while.
}
#ifdef INET6
-#if (defined(IPV6CTL_ACCEPT_RTADV) && !defined(ND6_IFF_ACCEPT_RTADV)) || \
- defined(IPV6CTL_FORWARDING)
+#if (defined(IPV6CTL_ACCEPT_RTADV) && !defined(ND6_IFF_ACCEPT_RTADV))
#define get_inet6_sysctl(code) inet6_sysctl(code, 0, 0)
#define set_inet6_sysctl(code, val) inet6_sysctl(code, val, 1)
static int
#endif
}
-#ifndef IPV6CTL_FORWARDING
-#define get_inet6_sysctlbyname(code) inet6_sysctlbyname(code, 0, 0)
-#define set_inet6_sysctlbyname(code, val) inet6_sysctlbyname(code, val, 1)
-static int
-inet6_sysctlbyname(const char *name, int val, int action)
-{
- size_t size;
-
- size = sizeof(val);
- if (action) {
- if (sysctlbyname(name, NULL, 0, &val, size) == -1)
- return -1;
- return 0;
- }
- if (sysctlbyname(name, &val, &size, NULL, 0) == -1)
- return -1;
- return val;
-}
-#endif
-
-int
-ip6_forwarding(__unused const char *ifname)
-{
-
-#ifdef IPV6CTL_FORWARDING
- return get_inet6_sysctl(IPV6CTL_FORWARDING);
-#else
- return get_inet6_sysctlbyname("net.inet6.ip6.forwarding");
-#endif
-}
-
#ifdef SIOCIFAFATTACH
static int
if_af_attach(const struct interface *ifp, int af)
return error;
}
-int
-ip6_forwarding(const char *ifname)
-{
- char path[256], buf[64];
- int error, i;
-
- if (ifname == NULL)
- ifname = "all";
- snprintf(path, sizeof(path), "%s/%s/forwarding", p_conf, ifname);
- if (readfile(path, buf, sizeof(buf)) == -1)
- return -1;
- i = (int)strtoi(buf, NULL, 0, INT_MIN, INT_MAX, &error);
- if (error != 0 && error != ENOTSUP)
- return -1;
- return i;
-}
-
#endif /* INET6 */
{
}
-
-int
-ip6_forwarding(__unused const char *ifname)
-{
-
- return 1;
-}
#endif
{
struct ipv6_addr *ia;
struct interface *ifp;
- bool forwarding;
-
- ia = ipv6_ifanyglobal(sifp);
- if (ia != NULL)
- return ia;
-
- /* BSD forwarding is either on or off.
- * Linux forwarding is technically the same as it's
- * configured by the "all" interface.
- * Per interface only affects IsRouter of NA messages. */
-#ifdef PRIVSEP_SYSCTL
- if (IN_PRIVSEP(sifp->ctx))
- forwarding = ps_root_ip6forwarding(sifp->ctx, NULL) > 0;
- else
-#endif
- forwarding = ip6_forwarding(NULL) > 0;
-
- if (!forwarding)
- return NULL;
+ /* IP6 source address selection does not care if we are a router
+ * or not, so just find a global address on any interface. */
TAILQ_FOREACH(ifp, sifp->ctx->ifaces, next) {
- if (ifp == sifp)
- continue;
ia = ipv6_ifanyglobal(ifp);
if (ia != NULL)
return ia;
/* add default route */
if (rap->lifetime == 0)
continue;
+ /* We only want to install a default route if we have
+ * an address that we can use other it.
+ * If we don't have any global addresses any request
+ * over the interface just times out.
+ * This avoids a badly setup IPv6 enabled router. */
if (ipv6_anyglobal(rap->iface) == NULL)
continue;
rt = inet6_makerouter(rap);
free_rdata = true;
break;
#endif
-#if defined(INET6) && defined(PRIVSEP_SYSCTL)
- case PS_IP6FORWARDING:
- err = ip6_forwarding(data);
- break;
-#endif
#ifdef PLUGIN_DEV
case PS_DEV_INITTED:
err = dev_initialised(ctx, data);
}
#endif
-#ifdef PRIVSEP_SYSCTL
-ssize_t
-ps_root_ip6forwarding(struct dhcpcd_ctx *ctx, const char *ifname)
-{
-
- if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_IP6FORWARDING, 0,
- ifname, ifname != NULL ? strlen(ifname) + 1 : 0) == -1)
- return -1;
- return ps_root_readerror(ctx, NULL, 0);
-}
-#endif
-
#ifdef AUTH
int
ps_root_getauthrdm(struct dhcpcd_ctx *ctx, uint64_t *rdm)
ssize_t ps_root_readerror(struct dhcpcd_ctx *, void *, size_t);
ssize_t ps_root_mreaderror(struct dhcpcd_ctx *, void **, size_t *);
ssize_t ps_root_ioctl(struct dhcpcd_ctx *, ioctl_request_t, void *, size_t);
-ssize_t ps_root_ip6forwarding(struct dhcpcd_ctx *, const char *);
ssize_t ps_root_unlink(struct dhcpcd_ctx *, const char *);
ssize_t ps_root_filemtime(struct dhcpcd_ctx *, const char *, time_t *);
ssize_t ps_root_readfile(struct dhcpcd_ctx *, const char *, void *, size_t);