diff --git a/man/systemd.network.xml b/man/systemd.network.xml
index 49814a05eb..199fcc0a58 100644
--- a/man/systemd.network.xml
+++ b/man/systemd.network.xml
@@ -2295,6 +2295,22 @@ Token=prefixstable:2002:da8:1::
+
+ UseGateway=
+
+ When true (the default), the router address will be configured as the default gateway.
+
+
+
+
+
+ UseRoutePrefix=
+
+ When true (the default), the routes corresponding to the route prefixes received in
+ the Router Advertisement will be configured.
+
+
+
UseAutonomousPrefix=
diff --git a/src/network/networkd-ndisc.c b/src/network/networkd-ndisc.c
index 21b5d0a0c0..470c969329 100644
--- a/src/network/networkd-ndisc.c
+++ b/src/network/networkd-ndisc.c
@@ -290,7 +290,6 @@ static int ndisc_request_address(Address *in, Link *link, sd_ndisc_router *rt) {
}
static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) {
- _cleanup_(route_freep) Route *route = NULL;
usec_t lifetime_usec, timestamp_usec;
struct in6_addr gateway;
uint16_t lifetime_sec;
@@ -299,8 +298,13 @@ static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) {
int r;
assert(link);
+ assert(link->network);
assert(rt);
+ if (!link->network->ipv6_accept_ra_use_gateway &&
+ hashmap_isempty(link->network->routes_by_section))
+ return 0;
+
r = sd_ndisc_router_get_lifetime(rt, &lifetime_sec);
if (r < 0)
return log_link_error_errno(link, r, "Failed to get gateway lifetime from RA: %m");
@@ -339,23 +343,29 @@ static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) {
return log_link_error_errno(link, r, "Failed to get default router MTU from RA: %m");
}
- r = route_new(&route);
- if (r < 0)
- return log_oom();
+ if (link->network->ipv6_accept_ra_use_gateway) {
+ _cleanup_(route_freep) Route *route = NULL;
- route->family = AF_INET6;
- route->pref = preference;
- route->gw_family = AF_INET6;
- route->gw.in6 = gateway;
- route->lifetime_usec = lifetime_usec;
- route->mtu = mtu;
+ r = route_new(&route);
+ if (r < 0)
+ return log_oom();
- r = ndisc_request_route(TAKE_PTR(route), link, rt);
- if (r < 0)
- return log_link_error_errno(link, r, "Could not request default route: %m");
+ route->family = AF_INET6;
+ route->pref = preference;
+ route->gw_family = AF_INET6;
+ route->gw.in6 = gateway;
+ route->lifetime_usec = lifetime_usec;
+ route->mtu = mtu;
+
+ r = ndisc_request_route(TAKE_PTR(route), link, rt);
+ if (r < 0)
+ return log_link_error_errno(link, r, "Could not request default route: %m");
+ }
Route *route_gw;
HASHMAP_FOREACH(route_gw, link->network->routes_by_section) {
+ _cleanup_(route_freep) Route *route = NULL;
+
if (!route_gw->gateway_from_dhcp_or_ra)
continue;
@@ -584,6 +594,9 @@ static int ndisc_router_process_route(Link *link, sd_ndisc_router *rt) {
assert(link);
+ if (!link->network->ipv6_accept_ra_use_route_prefix)
+ return 0;
+
r = sd_ndisc_router_route_get_lifetime(rt, &lifetime_sec);
if (r < 0)
return log_link_error_errno(link, r, "Failed to get route lifetime from RA: %m");
diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf
index 1f0a625183..bf58efc932 100644
--- a/src/network/networkd-network-gperf.gperf
+++ b/src/network/networkd-network-gperf.gperf
@@ -255,6 +255,8 @@ DHCPv6.IAID, config_parse_iaid,
DHCPv6.DUIDType, config_parse_duid_type, 0, offsetof(Network, dhcp6_duid)
DHCPv6.DUIDRawData, config_parse_duid_rawdata, 0, offsetof(Network, dhcp6_duid)
DHCPv6.RouteTable, config_parse_dhcp_or_ra_route_table, (RTPROT_DHCP<<16) | AF_INET6, 0
+IPv6AcceptRA.UseGateway, config_parse_bool, 0, offsetof(Network, ipv6_accept_ra_use_gateway)
+IPv6AcceptRA.UseRoutePrefix, config_parse_bool, 0, offsetof(Network, ipv6_accept_ra_use_route_prefix)
IPv6AcceptRA.UseAutonomousPrefix, config_parse_bool, 0, offsetof(Network, ipv6_accept_ra_use_autonomous_prefix)
IPv6AcceptRA.UseOnLinkPrefix, config_parse_bool, 0, offsetof(Network, ipv6_accept_ra_use_onlink_prefix)
IPv6AcceptRA.UseDNS, config_parse_bool, 0, offsetof(Network, ipv6_accept_ra_use_dns)
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index 1c00b98660..93621db03b 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -464,6 +464,8 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
.ipv6_accept_ra = -1,
.ipv6_accept_ra_use_dns = true,
+ .ipv6_accept_ra_use_gateway = true,
+ .ipv6_accept_ra_use_route_prefix = true,
.ipv6_accept_ra_use_autonomous_prefix = true,
.ipv6_accept_ra_use_onlink_prefix = true,
.ipv6_accept_ra_use_mtu = true,
diff --git a/src/network/networkd-network.h b/src/network/networkd-network.h
index f5258c9fcd..c86a492a17 100644
--- a/src/network/networkd-network.h
+++ b/src/network/networkd-network.h
@@ -301,6 +301,8 @@ struct Network {
/* IPv6 accept RA */
int ipv6_accept_ra;
bool ipv6_accept_ra_use_dns;
+ bool ipv6_accept_ra_use_gateway;
+ bool ipv6_accept_ra_use_route_prefix;
bool ipv6_accept_ra_use_autonomous_prefix;
bool ipv6_accept_ra_use_onlink_prefix;
bool ipv6_accept_ra_use_mtu;
diff --git a/test/fuzz/fuzz-network-parser/directives.network b/test/fuzz/fuzz-network-parser/directives.network
index 2ff20e0f08..66038a2378 100644
--- a/test/fuzz/fuzz-network-parser/directives.network
+++ b/test/fuzz/fuzz-network-parser/directives.network
@@ -352,6 +352,8 @@ RouteTable=
RouteMetric=
UseDNS=
DHCPv6Client=
+UseGateway=
+UseRoutePrefix=
UseAutonomousPrefix=
UseOnLinkPrefix=
RouterAllowList=