blob: f46a3ff788daa43a7c9c7f1a55361e04e9c2f12d [file] [log] [blame] [raw]
/* SPDX-License-Identifier: LGPL-2.1+ */
#include "alloc-util.h"
#include "fd-util.h"
#include "network-util.h"
#include "string-table.h"
#include "strv.h"
bool network_is_online(void) {
_cleanup_free_ char *state = NULL;
int r;
r = sd_network_get_operational_state(&state);
if (r < 0) /* if we don't know anything, we consider the system online */
return true;
if (STR_IN_SET(state, "routable", "degraded"))
return true;
return false;
}
static const char* const link_operstate_table[_LINK_OPERSTATE_MAX] = {
[LINK_OPERSTATE_OFF] = "off",
[LINK_OPERSTATE_NO_CARRIER] = "no-carrier",
[LINK_OPERSTATE_DORMANT] = "dormant",
[LINK_OPERSTATE_DEGRADED_CARRIER] = "degraded-carrier",
[LINK_OPERSTATE_CARRIER] = "carrier",
[LINK_OPERSTATE_DEGRADED] = "degraded",
[LINK_OPERSTATE_ENSLAVED] = "enslaved",
[LINK_OPERSTATE_ROUTABLE] = "routable",
};
DEFINE_STRING_TABLE_LOOKUP(link_operstate, LinkOperationalState);