X Tutup
Skip to content

Commit a853652

Browse files
author
Dan Streetman
committed
save link activation policy to state file and display in networkctl
1 parent 2236d75 commit a853652

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

src/libsystemd/sd-network/sd-network.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,27 @@ _public_ int sd_network_link_get_required_operstate_for_online(int ifindex, char
212212
return 0;
213213
}
214214

215+
_public_ int sd_network_link_get_activation_policy(int ifindex, char **policy) {
216+
_cleanup_free_ char *s = NULL;
217+
int r;
218+
219+
assert_return(policy, -EINVAL);
220+
221+
r = network_link_get_string(ifindex, "ACTIVATION_POLICY", &s);
222+
if (r < 0) {
223+
if (r != -ENODATA)
224+
return r;
225+
226+
/* For compatibility, assuming up. */
227+
s = strdup("up");
228+
if (!s)
229+
return -ENOMEM;
230+
}
231+
232+
*policy = TAKE_PTR(s);
233+
return 0;
234+
}
235+
215236
_public_ int sd_network_link_get_llmnr(int ifindex, char **llmnr) {
216237
return network_link_get_string(ifindex, "LLMNR", llmnr);
217238
}

src/network/networkctl.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1387,7 +1387,7 @@ static int link_status_one(
13871387

13881388
_cleanup_strv_free_ char **dns = NULL, **ntp = NULL, **sip = NULL, **search_domains = NULL, **route_domains = NULL;
13891389
_cleanup_free_ char *t = NULL, *network = NULL, *iaid = NULL, *duid = NULL,
1390-
*setup_state = NULL, *operational_state = NULL, *lease_file = NULL;
1390+
*setup_state = NULL, *operational_state = NULL, *lease_file = NULL, *activation_policy = NULL;
13911391
const char *driver = NULL, *path = NULL, *vendor = NULL, *model = NULL, *link = NULL,
13921392
*on_color_operational, *off_color_operational, *on_color_setup, *off_color_setup;
13931393
_cleanup_free_ int *carrier_bound_to = NULL, *carrier_bound_by = NULL;
@@ -2062,6 +2062,16 @@ static int link_status_one(
20622062
if (r < 0)
20632063
return r;
20642064

2065+
r = sd_network_link_get_activation_policy(info->ifindex, &activation_policy);
2066+
if (r >= 0) {
2067+
r = table_add_many(table,
2068+
TABLE_EMPTY,
2069+
TABLE_STRING, "Activation Policy:",
2070+
TABLE_STRING, activation_policy);
2071+
if (r < 0)
2072+
return table_log_add_error(r);
2073+
}
2074+
20652075
if (lease) {
20662076
const void *client_id;
20672077
size_t client_id_len;

src/network/networkd-link.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3011,6 +3011,9 @@ int link_save(Link *link) {
30113011
st.max != LINK_OPERSTATE_RANGE_DEFAULT.max ? ":" : "",
30123012
st.max != LINK_OPERSTATE_RANGE_DEFAULT.max ? strempty(link_operstate_to_string(st.max)) : "");
30133013

3014+
fprintf(f, "ACTIVATION_POLICY=%s\n",
3015+
activation_policy_to_string(link->network->activation_policy));
3016+
30143017
fprintf(f, "NETWORK_FILE=%s\n", link->network->filename);
30153018

30163019
/************************************************************/

src/systemd/sd-network.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ int sd_network_link_get_address_state(int ifindex, char **state);
103103
*/
104104
int sd_network_link_get_required_for_online(int ifindex);
105105

106+
/* Get activation policy for ifindex.
107+
* Possible values are as specified for ActivationPolicy=
108+
*/
109+
int sd_network_link_get_activation_policy(int ifindex, char **policy);
110+
106111
/* Get path to .network file applied to link */
107112
int sd_network_link_get_network_file(int ifindex, char **filename);
108113

test/test-network/systemd-networkd-tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3033,6 +3033,7 @@ def test_state_file(self):
30333033
self.assertRegex(data, r'OPER_STATE=routable')
30343034
self.assertRegex(data, r'REQUIRED_FOR_ONLINE=yes')
30353035
self.assertRegex(data, r'REQUIRED_OPER_STATE_FOR_ONLINE=routable')
3036+
self.assertRegex(data, r'ACTIVATION_POLICY=up')
30363037
self.assertRegex(data, r'NETWORK_FILE=/run/systemd/network/state-file-tests.network')
30373038
self.assertRegex(data, r'DNS=10.10.10.10#aaa.com 10.10.10.11:1111#bbb.com \[1111:2222::3333\]:1234#ccc.com')
30383039
self.assertRegex(data, r'NTP=0.fedora.pool.ntp.org 1.fedora.pool.ntp.org')

0 commit comments

Comments
 (0)
X Tutup