network: introduce AddPrefixRoute= and deprecate PrefixRoute=

PrefixRoute= was added by e63be0847c,
but unfortunately, the meaning of PrefixRoute= is inverted; when true
IFA_F_NOPREFIXROUTE flag is added. This introduces AddPrefixRoute=
setting.
This commit is contained in:
Yu Watanabe 2019-12-08 00:32:36 +09:00 committed by Zbigniew Jędrzejewski-Szmek
parent 0c8e33b6e9
commit de697db05b
5 changed files with 17 additions and 14 deletions

View File

@ -1007,12 +1007,10 @@
</listitem>
</varlistentry>
<varlistentry>
<term><varname>PrefixRoute=</varname></term>
<term><varname>AddPrefixRoute=</varname></term>
<listitem>
<para>Takes a boolean. When adding or modifying an IPv6 address, the userspace
application needs a way to suppress adding a prefix route. This is for example relevant
together with IFA_F_MANAGERTEMPADDR, where userspace creates autoconf generated addresses,
but depending on on-link, no route for the prefix should be added. Defaults to false.</para>
<para>Takes a boolean. When true, the prefix route for the address is automatically added.
Defaults to true.</para>
</listitem>
</varlistentry>
<varlistentry>

View File

@ -33,6 +33,7 @@ int address_new(Address **ret) {
.cinfo.ifa_prefered = CACHE_INFO_INFINITY_LIFE_TIME,
.cinfo.ifa_valid = CACHE_INFO_INFINITY_LIFE_TIME,
.duplicate_address_detection = ADDRESS_FAMILY_IPV6,
.prefix_route = true,
};
*ret = TAKE_PTR(address);
@ -596,7 +597,7 @@ int address_configure(
if (address->manage_temporary_address)
address->flags |= IFA_F_MANAGETEMPADDR;
if (address->prefix_route)
if (!address->prefix_route)
address->flags |= IFA_F_NOPREFIXROUTE;
if (address->autojoin)
@ -1001,6 +1002,8 @@ int config_parse_address_flags(const char *unit,
else if (streq(lvalue, "ManageTemporaryAddress"))
n->manage_temporary_address = r;
else if (streq(lvalue, "PrefixRoute"))
n->prefix_route = !r;
else if (streq(lvalue, "AddPrefixRoute"))
n->prefix_route = r;
else if (streq(lvalue, "AutoJoin"))
n->autojoin = r;

View File

@ -111,10 +111,10 @@ static int route_scope_from_address(const Route *route, const struct in_addr *se
return RT_SCOPE_UNIVERSE;
}
static bool link_noprefixroute(Link *link) {
return link->network->dhcp_route_table_set &&
link->network->dhcp_route_table != RT_TABLE_MAIN &&
!link->manager->dhcp4_prefix_root_cannot_set_table;
static bool link_prefixroute(Link *link) {
return !link->network->dhcp_route_table_set ||
link->network->dhcp_route_table == RT_TABLE_MAIN ||
link->manager->dhcp4_prefix_root_cannot_set_table;
}
static int dhcp_route_configure(Route **route, Link *link) {
@ -254,7 +254,7 @@ static int link_set_dhcp_routes(Link *link) {
if (r < 0)
return log_link_warning_errno(link, r, "DHCP error: could not get address: %m");
if (link_noprefixroute(link)) {
if (!link_prefixroute(link)) {
_cleanup_(route_freep) Route *prefix_route = NULL;
r = dhcp_prefix_route_from_lease(link->dhcp_lease, table, &address, &prefix_route);
@ -516,7 +516,7 @@ static int dhcp_remove_dns_routes(Link *link, sd_dhcp_lease *lease, const struct
(void) route_remove(route, link, NULL);
}
if (link_noprefixroute(link)) {
if (!link_prefixroute(link)) {
_cleanup_(route_freep) Route *prefix_route = NULL;
r = dhcp_prefix_route_from_lease(lease, table, address, &prefix_route);
@ -719,7 +719,7 @@ static int dhcp4_update_address(Link *link,
addr->cinfo.ifa_valid = lifetime;
addr->prefixlen = prefixlen;
addr->broadcast.s_addr = address->s_addr | ~netmask->s_addr;
addr->prefix_route = link_noprefixroute(link);
addr->prefix_route = link_prefixroute(link);
/* allow reusing an existing address and simply update its lifetime
* in case it already exists */

View File

@ -106,7 +106,8 @@ Address.Label, config_parse_label,
Address.PreferredLifetime, config_parse_lifetime, 0, 0
Address.HomeAddress, config_parse_address_flags, 0, 0
Address.ManageTemporaryAddress, config_parse_address_flags, 0, 0
Address.PrefixRoute, config_parse_address_flags, 0, 0
Address.PrefixRoute, config_parse_address_flags, 0, 0 /* deprecated */
Address.AddPrefixRoute, config_parse_address_flags, 0, 0
Address.AutoJoin, config_parse_address_flags, 0, 0
Address.DuplicateAddressDetection, config_parse_duplicate_address_detection, 0, 0
Address.Scope, config_parse_address_scope, 0, 0

View File

@ -202,6 +202,7 @@ Address=
Scope=
HomeAddress=
PrefixRoute=
AddPrefixRoute=
ManageTemporaryAddress=
Broadcast=
Peer=