]> git.proxmox.com Git - systemd.git/blob - src/libsystemd/sd-network/network-util.c
New upstream version 242
[systemd.git] / src / libsystemd / sd-network / network-util.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include "alloc-util.h"
4 #include "fd-util.h"
5 #include "network-util.h"
6 #include "string-table.h"
7 #include "strv.h"
8
9 bool network_is_online(void) {
10 _cleanup_free_ char *state = NULL;
11 int r;
12
13 r = sd_network_get_operational_state(&state);
14 if (r < 0) /* if we don't know anything, we consider the system online */
15 return true;
16
17 if (STR_IN_SET(state, "routable", "degraded"))
18 return true;
19
20 return false;
21 }
22
23 static const char* const link_operstate_table[_LINK_OPERSTATE_MAX] = {
24 [LINK_OPERSTATE_OFF] = "off",
25 [LINK_OPERSTATE_NO_CARRIER] = "no-carrier",
26 [LINK_OPERSTATE_DORMANT] = "dormant",
27 [LINK_OPERSTATE_DEGRADED_CARRIER] = "degraded-carrier",
28 [LINK_OPERSTATE_CARRIER] = "carrier",
29 [LINK_OPERSTATE_DEGRADED] = "degraded",
30 [LINK_OPERSTATE_ENSLAVED] = "enslaved",
31 [LINK_OPERSTATE_ROUTABLE] = "routable",
32 };
33
34 DEFINE_STRING_TABLE_LOOKUP(link_operstate, LinkOperationalState);