1
0
mirror of https://github.com/systemd/systemd.git synced 2025-02-27 01:57:35 +03:00

save link activation policy to state file and display in networkctl

This commit is contained in:
Dan Streetman 2020-08-13 11:52:53 -04:00
parent 2236d75df9
commit a853652ae9
5 changed files with 41 additions and 1 deletions

View File

@ -212,6 +212,27 @@ _public_ int sd_network_link_get_required_operstate_for_online(int ifindex, char
return 0;
}
_public_ int sd_network_link_get_activation_policy(int ifindex, char **policy) {
_cleanup_free_ char *s = NULL;
int r;
assert_return(policy, -EINVAL);
r = network_link_get_string(ifindex, "ACTIVATION_POLICY", &s);
if (r < 0) {
if (r != -ENODATA)
return r;
/* For compatibility, assuming up. */
s = strdup("up");
if (!s)
return -ENOMEM;
}
*policy = TAKE_PTR(s);
return 0;
}
_public_ int sd_network_link_get_llmnr(int ifindex, char **llmnr) {
return network_link_get_string(ifindex, "LLMNR", llmnr);
}

View File

@ -1387,7 +1387,7 @@ static int link_status_one(
_cleanup_strv_free_ char **dns = NULL, **ntp = NULL, **sip = NULL, **search_domains = NULL, **route_domains = NULL;
_cleanup_free_ char *t = NULL, *network = NULL, *iaid = NULL, *duid = NULL,
*setup_state = NULL, *operational_state = NULL, *lease_file = NULL;
*setup_state = NULL, *operational_state = NULL, *lease_file = NULL, *activation_policy = NULL;
const char *driver = NULL, *path = NULL, *vendor = NULL, *model = NULL, *link = NULL,
*on_color_operational, *off_color_operational, *on_color_setup, *off_color_setup;
_cleanup_free_ int *carrier_bound_to = NULL, *carrier_bound_by = NULL;
@ -2062,6 +2062,16 @@ static int link_status_one(
if (r < 0)
return r;
r = sd_network_link_get_activation_policy(info->ifindex, &activation_policy);
if (r >= 0) {
r = table_add_many(table,
TABLE_EMPTY,
TABLE_STRING, "Activation Policy:",
TABLE_STRING, activation_policy);
if (r < 0)
return table_log_add_error(r);
}
if (lease) {
const void *client_id;
size_t client_id_len;

View File

@ -3011,6 +3011,9 @@ int link_save(Link *link) {
st.max != LINK_OPERSTATE_RANGE_DEFAULT.max ? ":" : "",
st.max != LINK_OPERSTATE_RANGE_DEFAULT.max ? strempty(link_operstate_to_string(st.max)) : "");
fprintf(f, "ACTIVATION_POLICY=%s\n",
activation_policy_to_string(link->network->activation_policy));
fprintf(f, "NETWORK_FILE=%s\n", link->network->filename);
/************************************************************/

View File

@ -103,6 +103,11 @@ int sd_network_link_get_address_state(int ifindex, char **state);
*/
int sd_network_link_get_required_for_online(int ifindex);
/* Get activation policy for ifindex.
* Possible values are as specified for ActivationPolicy=
*/
int sd_network_link_get_activation_policy(int ifindex, char **policy);
/* Get path to .network file applied to link */
int sd_network_link_get_network_file(int ifindex, char **filename);

View File

@ -3033,6 +3033,7 @@ class NetworkdStateFileTests(unittest.TestCase, Utilities):
self.assertRegex(data, r'OPER_STATE=routable')
self.assertRegex(data, r'REQUIRED_FOR_ONLINE=yes')
self.assertRegex(data, r'REQUIRED_OPER_STATE_FOR_ONLINE=routable')
self.assertRegex(data, r'ACTIVATION_POLICY=up')
self.assertRegex(data, r'NETWORK_FILE=/run/systemd/network/state-file-tests.network')
self.assertRegex(data, r'DNS=10.10.10.10#aaa.com 10.10.10.11:1111#bbb.com \[1111:2222::3333\]:1234#ccc.com')
self.assertRegex(data, r'NTP=0.fedora.pool.ntp.org 1.fedora.pool.ntp.org')