Compare commits

...

5 Commits

Author SHA1 Message Date
Yu Watanabe 4e8b5f0f2c
Merge ec6a9b2e03 into b7eefa1996 2024-11-21 17:04:30 +00:00
Luca Boccassi b7eefa1996 cgroup-util: fix memory leak on error
CID#1565824

Follow-up for f6793bbcf0
2024-11-21 14:02:34 +09:00
Yu Watanabe ec6a9b2e03 test-network: add test case for [IPv6RoutePrefix] Preference= 2024-11-20 18:50:53 +09:00
Yu Watanabe 087e46cc55 network/radv: add [IPv6RoutePrefix] Preference= setting 2024-11-20 18:50:53 +09:00
Yu Watanabe 4527f71040 network/radv: modernize config_parse_router_preference() 2024-11-20 18:50:53 +09:00
6 changed files with 69 additions and 18 deletions

View File

@ -4397,6 +4397,15 @@ ServerAddress=192.168.0.1/24</programlisting>
<xi:include href="version-info.xml" xpointer="v244"/></listitem>
</varlistentry>
<varlistentry>
<term><varname>Preference=</varname></term>
<listitem><para>Specifies the preference of the route option. Takes one of <literal>high</literal>,
<literal>medium</literal>, or <literal>low</literal>. Defaults to <literal>medium</literal>.</para>
<xi:include href="version-info.xml" xpointer="v258"/></listitem>
</varlistentry>
</variablelist>
</refsect1>

View File

@ -799,7 +799,7 @@ int cg_pid_get_path(const char *controller, pid_t pid, char **ret_path) {
continue;
}
char *path = strdup(e + 1);
_cleanup_free_ char *path = strdup(e + 1);
if (!path)
return -ENOMEM;
@ -812,7 +812,7 @@ int cg_pid_get_path(const char *controller, pid_t pid, char **ret_path) {
if (e)
*e = 0;
*ret_path = path;
*ret_path = TAKE_PTR(path);
return 0;
}
}

View File

@ -406,7 +406,7 @@ IPv6SendRA.ReachableTimeSec, config_parse_router_uint32_msec_use
IPv6SendRA.RetransmitSec, config_parse_router_uint32_msec_usec, 0, offsetof(Network, router_retransmit_usec)
IPv6SendRA.Managed, config_parse_bool, 0, offsetof(Network, router_managed)
IPv6SendRA.OtherInformation, config_parse_bool, 0, offsetof(Network, router_other_information)
IPv6SendRA.RouterPreference, config_parse_router_preference, 0, 0
IPv6SendRA.RouterPreference, config_parse_router_preference, 0, offsetof(Network, router_preference)
IPv6SendRA.HopLimit, config_parse_uint8, 0, offsetof(Network, router_hop_limit)
IPv6SendRA.EmitDNS, config_parse_bool, 0, offsetof(Network, router_emit_dns)
IPv6SendRA.DNS, config_parse_radv_dns, 0, 0
@ -427,6 +427,7 @@ IPv6Prefix.RouteMetric, config_parse_prefix_metric,
IPv6Prefix.Token, config_parse_prefix_token, 0, 0
IPv6RoutePrefix.Route, config_parse_route_prefix, 0, 0
IPv6RoutePrefix.LifetimeSec, config_parse_route_prefix_lifetime, 0, 0
IPv6RoutePrefix.Preference, config_parse_route_prefix_preference, 0, 0
IPv6PREF64Prefix.Prefix, config_parse_pref64_prefix, 0, 0
IPv6PREF64Prefix.LifetimeSec, config_parse_pref64_prefix_lifetime, 0, 0
LLDP.MUDURL, config_parse_mud_url, 0, offsetof(Network, lldp_mudurl)

View File

@ -1134,6 +1134,37 @@ int config_parse_route_prefix_lifetime(
return 0;
}
int config_parse_route_prefix_preference(
const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
_cleanup_(route_prefix_free_or_set_invalidp) RoutePrefix *p = NULL;
Network *network = ASSERT_PTR(userdata);
int r;
assert(filename);
r = route_prefix_new_static(network, filename, section_line, &p);
if (r < 0)
return log_oom();
r = config_parse_router_preference(unit, filename, line, section, section_line,
lvalue, ltype, rvalue, &p->route.preference, NULL);
if (r <= 0)
return r;
TAKE_PTR(p);
return 0;
}
int config_parse_pref64_prefix(
const char *unit,
const char *filename,
@ -1511,25 +1542,18 @@ int config_parse_router_preference(
void *data,
void *userdata) {
Network *network = userdata;
uint8_t *preference = ASSERT_PTR(data);
assert(filename);
assert(section);
assert(lvalue);
assert(rvalue);
assert(data);
if (streq(rvalue, "high"))
network->router_preference = SD_NDISC_PREFERENCE_HIGH;
else if (STR_IN_SET(rvalue, "medium", "normal", "default"))
network->router_preference = SD_NDISC_PREFERENCE_MEDIUM;
if (isempty(rvalue) || STR_IN_SET(rvalue, "medium", "normal", "default"))
*preference = SD_NDISC_PREFERENCE_MEDIUM;
else if (streq(rvalue, "high"))
*preference = SD_NDISC_PREFERENCE_HIGH;
else if (streq(rvalue, "low"))
network->router_preference = SD_NDISC_PREFERENCE_LOW;
*preference = SD_NDISC_PREFERENCE_LOW;
else
log_syntax(unit, LOG_WARNING, filename, line, 0,
"Invalid router preference, ignoring assignment: %s", rvalue);
return log_syntax_parse_error(unit, filename, line, 0, lvalue, rvalue);
return 0;
return 1;
}
int config_parse_router_home_agent_lifetime(

View File

@ -86,6 +86,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_radv_dns);
CONFIG_PARSER_PROTOTYPE(config_parse_radv_search_domains);
CONFIG_PARSER_PROTOTYPE(config_parse_route_prefix);
CONFIG_PARSER_PROTOTYPE(config_parse_route_prefix_lifetime);
CONFIG_PARSER_PROTOTYPE(config_parse_route_prefix_preference);
CONFIG_PARSER_PROTOTYPE(config_parse_pref64_prefix);
CONFIG_PARSER_PROTOTYPE(config_parse_pref64_prefix_lifetime);
CONFIG_PARSER_PROTOTYPE(config_parse_router_home_agent_lifetime);

View File

@ -6472,6 +6472,22 @@ class NetworkdRATests(unittest.TestCase, Utilities):
networkctl_reload()
self.check_router_preference('01', 100, 'high', 300, 'low')
# Use route options with preference to configure default routes.
with open(os.path.join(network_unit_dir, '25-veth-router-high.network'), mode='a', encoding='utf-8') as f:
f.write('LifetimeSec=1200\nPreference=low\n')
with open(os.path.join(network_unit_dir, '25-veth-router-low.network'), mode='a', encoding='utf-8') as f:
f.write('LifetimeSec=1200\nPreference=high\n')
networkctl_reload()
self.check_router_preference('01', 300, 'low', 100, 'high')
# Set zero lifetime again to the route options.
with open(os.path.join(network_unit_dir, '25-veth-router-high.network'), mode='a', encoding='utf-8') as f:
f.write('LifetimeSec=0\n')
with open(os.path.join(network_unit_dir, '25-veth-router-low.network'), mode='a', encoding='utf-8') as f:
f.write('LifetimeSec=0\n')
networkctl_reload()
self.check_router_preference('01', 100, 'high', 300, 'low')
def _test_ndisc_vs_static_route(self, manage_foreign_nexthops):
if not manage_foreign_nexthops:
copy_networkd_conf_dropin('networkd-manage-foreign-nexthops-no.conf')