diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-09-24 02:22:03 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-09-27 03:42:31 +0200 |
commit | 778e3da95ef16302956087e6f10ccf7d42499aec (patch) | |
tree | d07853a1719668af1aa2e8585f956ada26b8b453 /src/libsystemd/sd-network | |
parent | sd-network: introduce network_link_get_boolean() helper function (diff) | |
download | systemd-778e3da95ef16302956087e6f10ccf7d42499aec.tar.xz systemd-778e3da95ef16302956087e6f10ccf7d42499aec.zip |
sd-network: drop fallback values
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.
Diffstat (limited to 'src/libsystemd/sd-network')
-rw-r--r-- | src/libsystemd/sd-network/sd-network.c | 69 |
1 files changed, 4 insertions, 65 deletions
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) { |