From 778e3da95ef16302956087e6f10ccf7d42499aec Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 24 Sep 2022 09:22:03 +0900 Subject: sd-network: drop fallback values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This drops spurious lines in `networkctl status` for unmanaged interfaces. Before: ``` $ networkctl status --lines 0 lo ● 1: lo Link File: n/a Network File: n/a Type: loopback State: carrier (unmanaged) Online state: unknown HW Address: 00:00:00:00:00:00 MTU: 65536 QDisc: noqueue IPv6 Address Generation Mode: eui64 Queue Length (Tx/Rx): 1/1 Address: 127.0.0.1 ::1 Activation Policy: up Required For Online: yes ``` After: ``` $ networkctl status --lines 0 lo ● 1: lo Link File: n/a Network File: n/a State: carrier (unmanaged) Online state: unknown Type: loopback Hardware Address: 00:00:00:00:00:00 MTU: 65536 QDisc: noqueue IPv6 Address Generation Mode: eui64 Number of Queues (Tx/Rx): 1/1 Address: 127.0.0.1 ::1 ``` That is, the lines for Activation Policy and Required For Online are dropped. --- src/libsystemd/sd-network/sd-network.c | 69 ++-------------------------------- 1 file changed, 4 insertions(+), 65 deletions(-) (limited to 'src/libsystemd/sd-network') diff --git a/src/libsystemd/sd-network/sd-network.c b/src/libsystemd/sd-network/sd-network.c index 9d00470fe1..4fd4c2502b 100644 --- a/src/libsystemd/sd-network/sd-network.c +++ b/src/libsystemd/sd-network/sd-network.c @@ -173,23 +173,7 @@ int sd_network_link_get_operational_state(int ifindex, char **ret) { } int sd_network_link_get_required_family_for_online(int ifindex, char **ret) { - _cleanup_free_ char *s = NULL; - int r; - - assert_return(ret, -EINVAL); - - r = network_link_get_string(ifindex, "REQUIRED_FAMILY_FOR_ONLINE", &s); - if (r < 0) { - if (r != -ENODATA) - return r; - - s = strdup("any"); - if (!s) - return -ENOMEM; - } - - *ret = TAKE_PTR(s); - return 0; + return network_link_get_string(ifindex, "REQUIRED_FAMILY_FOR_ONLINE", ret); } int sd_network_link_get_carrier_state(int ifindex, char **ret) { @@ -221,60 +205,15 @@ int sd_network_link_get_dhcp6_client_duid_string(int ifindex, char **ret) { } int sd_network_link_get_required_for_online(int ifindex) { - _cleanup_free_ char *s = NULL; - int r; - - r = network_link_get_string(ifindex, "REQUIRED_FOR_ONLINE", &s); - if (r < 0) { - /* Handle -ENODATA as RequiredForOnline=yes, for compatibility */ - if (r == -ENODATA) - return true; - return r; - } - - return parse_boolean(s); + return network_link_get_boolean(ifindex, "REQUIRED_FOR_ONLINE"); } int sd_network_link_get_required_operstate_for_online(int ifindex, char **ret) { - _cleanup_free_ char *s = NULL; - int r; - - assert_return(ret, -EINVAL); - - r = network_link_get_string(ifindex, "REQUIRED_OPER_STATE_FOR_ONLINE", &s); - if (r < 0) { - if (r != -ENODATA) - return r; - - /* For compatibility, assuming degraded. */ - s = strdup("degraded"); - if (!s) - return -ENOMEM; - } - - *ret = TAKE_PTR(s); - return 0; + return network_link_get_string(ifindex, "REQUIRED_OPER_STATE_FOR_ONLINE", ret); } int sd_network_link_get_activation_policy(int ifindex, char **ret) { - _cleanup_free_ char *s = NULL; - int r; - - assert_return(ret, -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; - } - - *ret = TAKE_PTR(s); - return 0; + return network_link_get_string(ifindex, "ACTIVATION_POLICY", ret); } int sd_network_link_get_llmnr(int ifindex, char **ret) { -- cgit v1.2.3