Skip to content

Commit b70129f

Browse files
committed
Fix #785: disable global IPv6 fwd by default
Enabled by user enabling IPv6 forwarding on any interface. This change also enables net.ipv6.conf.all.accept_ra (=2) to accept any IPv6 route advertisements even when acting as a router. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
1 parent 888f0c4 commit b70129f

File tree

3 files changed

+64
-19
lines changed

3 files changed

+64
-19
lines changed

board/common/rootfs/etc/sysctl.d/ipv6.conf

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22
net.ipv6.route.max_size=131072
33
net.ipv6.conf.all.ignore_routes_with_linkdown=1
44

5-
# IP Routing
6-
net.ipv6.conf.all.forwarding=1
5+
# IP Routing is disabled by default, enabled globally, and per
6+
# interface, for each interface in confd. See also accept_ra.
7+
net.ipv6.conf.all.forwarding=0
78
net.ipv6.conf.default.forwarding=0
89

10+
# Accept router advertisements even when forwarding is enabled
11+
net.ipv6.conf.all.accept_ra=2
12+
net.ipv6.conf.default.accept_ra=2
13+
914
# IPv6 SLAAC
1015
net.ipv6.conf.all.autoconf=0
1116
net.ipv6.conf.default.autoconf=0

doc/networking.md

+19-15
Original file line numberDiff line numberDiff line change
@@ -1183,23 +1183,27 @@ received on this interface can be forwarded.
11831183

11841184
### IPv6 forwarding
11851185

1186-
This flag behaves totally different than for IPv4. For IPv6 the
1187-
ability to route between interfaces is always enabled, instead this
1188-
flag controls if the interface will be in host/router mode.
1186+
Due to how the Linux kernel manages IPv6 forwarding, we can not fully
1187+
control it per interface via this setting like how IPv4 works. Instead,
1188+
IPv6 forwarding is globally enabled when at least one interface enable
1189+
forwarding, otherwise it is disabled.
11891190

1190-
| **Feature** | **Forward enabled** | **Forward disabled** |
1191-
|:-----------------------------------------|:--------------------|:---------------------|
1192-
| IsRouter set in Neighbour Advertisements | Yes | No |
1193-
| Transmit Router Solicitations | No | Yes |
1194-
| Router Advertisements are ignored | No | Yes |
1195-
| Accept Redirects | No | Yes |
1191+
The following table shows the system IPv6 features that the `forwarding`
1192+
setting control when it is *Enabled* or *Disabled:
11961193

1197-
```
1198-
admin@example:/config/> edit interface eth0
1199-
admin@example:/config/interface/eth0/> set ipv6 forwarding
1200-
admin@example:/config/interface/eth0/> leave
1201-
admin@example:/>
1202-
```
1194+
| **IPv6 Feature** | **Enabled** | **Disabled** |
1195+
|:-----------------------------------------|:------------|:-------------|
1196+
| IsRouter set in Neighbour Advertisements | Yes | No |
1197+
| Transmit Router Solicitations | No | Yes |
1198+
| Router Advertisements are ignored | Yes | Yes |
1199+
| Accept Redirects | No | Yes |
1200+
1201+
```
1202+
admin@example:/config/> edit interface eth0
1203+
admin@example:/config/interface/eth0/> set ipv6 forwarding
1204+
admin@example:/config/interface/eth0/> leave
1205+
admin@example:/>
1206+
```
12031207

12041208

12051209
## Routing support

src/confd/src/ietf-interfaces.c

+38-2
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,39 @@ static int netdag_gen_sysctl(struct dagger *net,
350350
return err;
351351
}
352352

353+
/*
354+
* The global IPv6 forwarding lever is off by default, enabled when any
355+
* interface has IPv6 forwarding enabled.
356+
*/
357+
static int netdag_ipv6_forwarding(struct lyd_node *cifs, struct dagger *net)
358+
{
359+
struct lyd_node *cif;
360+
FILE *sysctl = NULL;
361+
int ena = 0;
362+
363+
LYX_LIST_FOR_EACH(cifs, cif, "interface")
364+
ena |= lydx_is_enabled(lydx_get_child(cif, "ipv6"), "forwarding");
365+
366+
if (ena)
367+
sysctl = dagger_fopen_next(net, "init", "@post", NETDAG_INIT_POST, "ipv6.sysctl");
368+
else
369+
sysctl = dagger_fopen_current(net, "exit", "@pre", NETDAG_EXIT_PRE, "ipv6.sysctl");
370+
if (!sysctl) {
371+
/*
372+
* Cannot create exit code in gen: -1. Safe to ignore
373+
* since ipv6 forwarding is disabled by default.
374+
*/
375+
if (dagger_is_bootstrap(net) && !ena)
376+
return 0;
377+
return -EIO;
378+
}
379+
380+
fprintf(sysctl, "net.ipv6.conf.all.forwarding = %d\n", ena);
381+
fclose(sysctl);
382+
383+
return 0;
384+
}
385+
353386
static int dummy_gen(struct lyd_node *dif, struct lyd_node *cif, FILE *ip)
354387
{
355388
const char *ifname = lydx_get_cattr(cif, "name");
@@ -707,7 +740,10 @@ static sr_error_t netdag_init(sr_session_ctx_t *session, struct dagger *net,
707740
static sr_error_t ifchange_post(sr_session_ctx_t *session, struct dagger *net,
708741
struct lyd_node *cifs, struct lyd_node *difs)
709742
{
710-
int err;
743+
int err = 0;
744+
745+
/* Figure out value of global IPv6 forwarding flag. Issue #785 */
746+
err |= netdag_ipv6_forwarding(cifs, net);
711747

712748
/* For each configured bridge, the corresponding multicast
713749
* querier settings depend on both the bridge config and on
@@ -717,7 +753,7 @@ static sr_error_t ifchange_post(sr_session_ctx_t *session, struct dagger *net,
717753
* regenerate the full config for mcd every time by walking
718754
* the full configuration.
719755
*/
720-
err = bridge_mcd_gen(cifs);
756+
err |= bridge_mcd_gen(cifs);
721757

722758
/* Whenever at least one bridge has spanning tree enabled,
723759
* start mstpd; otherwise, stop it.

0 commit comments

Comments
 (0)