network: introduce ManageForeignRoutingPolicyRules= boolean setting in networkd.conf

The commit 0b81225e57 makes that networkd
remove all foreign rules except those with "proto kernel".

But, in some situation, people may want to manage routing policy rules
with other tools, e.g. 'ip' command. To support such the situation,
this introduce ManageForeignRoutingPolicyRules= boolean setting.

Closes #19106.
This commit is contained in:
Yu Watanabe 2021-04-11 21:33:51 +09:00
parent 6bfadad9bb
commit d94dfe7053
6 changed files with 24 additions and 6 deletions

View file

@ -62,6 +62,15 @@
If <varname>SpeedMeter=no</varname>, the value is ignored. Defaults to 10sec.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>ManageForeignRoutingPolicyRules=</varname></term>
<listitem><para>A boolean. When true, <command>systemd-networkd</command> will remove rules
that are not configured in .network files (except for rules with protocol
<literal>kernel</literal>). When false, it will not remove any foreign rules, keeping them even
if they are not configured in a .network file. Defaults to yes.
</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>ManageForeignRoutes=</varname></term>
<listitem><para>A boolean. When true, <command>systemd-networkd</command> will store any routes

View file

@ -20,9 +20,10 @@ struct ConfigPerfItem;
%struct-type
%includes
%%
Network.SpeedMeter, config_parse_bool, 0, offsetof(Manager, use_speed_meter)
Network.SpeedMeterIntervalSec, config_parse_sec, 0, offsetof(Manager, speed_meter_interval_usec)
Network.ManageForeignRoutes, config_parse_bool, 0, offsetof(Manager, manage_foreign_routes)
Network.RouteTable, config_parse_route_table_names, 0, 0
DHCP.DUIDType, config_parse_duid_type, 0, offsetof(Manager, duid)
DHCP.DUIDRawData, config_parse_duid_rawdata, 0, offsetof(Manager, duid)
Network.SpeedMeter, config_parse_bool, 0, offsetof(Manager, use_speed_meter)
Network.SpeedMeterIntervalSec, config_parse_sec, 0, offsetof(Manager, speed_meter_interval_usec)
Network.ManageForeignRoutingPolicyRules, config_parse_bool, 0, offsetof(Manager, manage_foreign_rules)
Network.ManageForeignRoutes, config_parse_bool, 0, offsetof(Manager, manage_foreign_routes)
Network.RouteTable, config_parse_route_table_names, 0, 0
DHCP.DUIDType, config_parse_duid_type, 0, offsetof(Manager, duid)
DHCP.DUIDRawData, config_parse_duid_rawdata, 0, offsetof(Manager, duid)

View file

@ -380,6 +380,7 @@ int manager_new(Manager **ret) {
*m = (Manager) {
.speed_meter_interval_usec = SPEED_METER_DEFAULT_TIME_INTERVAL,
.manage_foreign_routes = true,
.manage_foreign_rules = true,
.ethtool_fd = -1,
};
@ -655,6 +656,9 @@ static int manager_enumerate_rules(Manager *m) {
assert(m);
assert(m->rtnl);
if (!m->manage_foreign_rules)
return 0;
r = sd_rtnl_message_new_routing_policy_rule(m->rtnl, &req, RTM_GETRULE, 0);
if (r < 0)
return r;

View file

@ -32,6 +32,7 @@ struct Manager {
bool dirty;
bool restarting;
bool manage_foreign_routes;
bool manage_foreign_rules;
Set *dirty_links;

View file

@ -977,6 +977,8 @@ int manager_rtnl_process_rule(sd_netlink *rtnl, sd_netlink_message *message, Man
case RTM_NEWRULE:
if (rule)
log_routing_policy_rule_debug(tmp, tmp->family, "Received remembered", NULL, m);
else if (!m->manage_foreign_routes)
log_routing_policy_rule_debug(tmp, tmp->family, "Ignoring received foreign", NULL, m);
else {
log_routing_policy_rule_debug(tmp, tmp->family, "Remembering foreign", NULL, m);
r = routing_policy_rule_consume_foreign(m, TAKE_PTR(tmp));

View file

@ -15,6 +15,7 @@
[Network]
#SpeedMeter=no
#SpeedMeterIntervalSec=10sec
#ManageForeignRoutingPolicyRules=yes
#ManageForeignRoutes=yes
#RouteTable=