networkd: Add support to configure IPv6 preferred lifetime (#3102)
Closes #2166. We only allow 0, infinity and forever. infinity and forever is same.
This commit is contained in:
parent
6e2d0795b3
commit
b5834a0b38
|
@ -652,6 +652,18 @@
|
||||||
<para>An address label.</para>
|
<para>An address label.</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
<varlistentry>
|
||||||
|
<term><varname>PreferredLifetime=</varname></term>
|
||||||
|
<listitem>
|
||||||
|
<para>Allows the default "preferred lifetime" of the address to be overridden.
|
||||||
|
Only three settings are accepted: <literal>forever</literal> or <literal>infinity</literal>
|
||||||
|
which is the default and means that the address never expires, and <literal>0</literal> which means
|
||||||
|
that the address is considered immediately "expired" and will not be used,
|
||||||
|
unless explicitly requested. A setting of PreferredLifetime=0 is useful for
|
||||||
|
addresses which are added to be used only by a specific application,
|
||||||
|
which is then configured to use them explicitly.</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
</variablelist>
|
</variablelist>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
|
||||||
|
|
|
@ -774,6 +774,54 @@ int config_parse_label(const char *unit,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int config_parse_lifetime(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) {
|
||||||
|
Network *network = userdata;
|
||||||
|
_cleanup_address_free_ Address *n = NULL;
|
||||||
|
unsigned k;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
assert(filename);
|
||||||
|
assert(section);
|
||||||
|
assert(lvalue);
|
||||||
|
assert(rvalue);
|
||||||
|
assert(data);
|
||||||
|
|
||||||
|
r = address_new_static(network, section_line, &n);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
if (STR_IN_SET(rvalue, "forever", "infinity")) {
|
||||||
|
n->cinfo.ifa_prefered = CACHE_INFO_INFINITY_LIFE_TIME;
|
||||||
|
n = NULL;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
r = safe_atou(rvalue, &k);
|
||||||
|
if (r < 0) {
|
||||||
|
log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse PreferredLifetime, ignoring: %s", rvalue);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (k != 0)
|
||||||
|
log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid PreferredLifetime value, ignoring: %d", k);
|
||||||
|
else {
|
||||||
|
n->cinfo.ifa_prefered = k;
|
||||||
|
n = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
bool address_is_ready(const Address *a) {
|
bool address_is_ready(const Address *a) {
|
||||||
assert(a);
|
assert(a);
|
||||||
|
|
||||||
|
|
|
@ -74,3 +74,4 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(Address*, address_free);
|
||||||
int config_parse_address(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);
|
int config_parse_address(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);
|
||||||
int config_parse_broadcast(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);
|
int config_parse_broadcast(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);
|
||||||
int config_parse_label(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);
|
int config_parse_label(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);
|
||||||
|
int config_parse_lifetime(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);
|
||||||
|
|
|
@ -65,6 +65,7 @@ Address.Address, config_parse_address,
|
||||||
Address.Peer, config_parse_address, 0, 0
|
Address.Peer, config_parse_address, 0, 0
|
||||||
Address.Broadcast, config_parse_broadcast, 0, 0
|
Address.Broadcast, config_parse_broadcast, 0, 0
|
||||||
Address.Label, config_parse_label, 0, 0
|
Address.Label, config_parse_label, 0, 0
|
||||||
|
Address.PreferredLifetime, config_parse_lifetime, 0, 0
|
||||||
Route.Gateway, config_parse_gateway, 0, 0
|
Route.Gateway, config_parse_gateway, 0, 0
|
||||||
Route.Destination, config_parse_destination, 0, 0
|
Route.Destination, config_parse_destination, 0, 0
|
||||||
Route.Source, config_parse_destination, 0, 0
|
Route.Source, config_parse_destination, 0, 0
|
||||||
|
|
Loading…
Reference in a new issue