1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 #include "alloc-util.h"
5 #include "network-util.h"
6 #include "string-table.h"
9 bool network_is_online(void) {
10 _cleanup_free_
char *state
= NULL
;
13 r
= sd_network_get_operational_state(&state
);
14 if (r
< 0) /* if we don't know anything, we consider the system online */
17 if (STR_IN_SET(state
, "routable", "degraded"))
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",
34 DEFINE_STRING_TABLE_LOOKUP(link_operstate
, LinkOperationalState
);