Branch data Line data Source code
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 : 0 : bool network_is_online(void) { 10 : 0 : _cleanup_free_ char *carrier_state = NULL, *addr_state = NULL; 11 : : int r; 12 : : 13 : 0 : r = sd_network_get_carrier_state(&carrier_state); 14 [ # # ]: 0 : if (r < 0) /* if we don't know anything, we consider the system online */ 15 : 0 : return true; 16 : : 17 : 0 : r = sd_network_get_address_state(&addr_state); 18 [ # # ]: 0 : if (r < 0) /* if we don't know anything, we consider the system online */ 19 : 0 : return true; 20 : : 21 [ # # ]: 0 : if (STR_IN_SET(carrier_state, "degraded-carrier", "carrier") && 22 [ # # ]: 0 : STR_IN_SET(addr_state, "routable", "degraded")) 23 : 0 : return true; 24 : : 25 : 0 : return false; 26 : : } 27 : : 28 : : static const char* const link_operstate_table[_LINK_OPERSTATE_MAX] = { 29 : : [LINK_OPERSTATE_OFF] = "off", 30 : : [LINK_OPERSTATE_NO_CARRIER] = "no-carrier", 31 : : [LINK_OPERSTATE_DORMANT] = "dormant", 32 : : [LINK_OPERSTATE_DEGRADED_CARRIER] = "degraded-carrier", 33 : : [LINK_OPERSTATE_CARRIER] = "carrier", 34 : : [LINK_OPERSTATE_DEGRADED] = "degraded", 35 : : [LINK_OPERSTATE_ENSLAVED] = "enslaved", 36 : : [LINK_OPERSTATE_ROUTABLE] = "routable", 37 : : }; 38 : : 39 [ + + + + ]: 80 : DEFINE_STRING_TABLE_LOOKUP(link_operstate, LinkOperationalState); 40 : : 41 : : static const char* const link_carrier_state_table[_LINK_CARRIER_STATE_MAX] = { 42 : : [LINK_CARRIER_STATE_OFF] = "off", 43 : : [LINK_CARRIER_STATE_NO_CARRIER] = "no-carrier", 44 : : [LINK_CARRIER_STATE_DORMANT] = "dormant", 45 : : [LINK_CARRIER_STATE_DEGRADED_CARRIER] = "degraded-carrier", 46 : : [LINK_CARRIER_STATE_CARRIER] = "carrier", 47 : : [LINK_CARRIER_STATE_ENSLAVED] = "enslaved", 48 : : }; 49 : : 50 [ # # # # ]: 0 : DEFINE_STRING_TABLE_LOOKUP(link_carrier_state, LinkCarrierState); 51 : : 52 : : static const char* const link_address_state_table[_LINK_ADDRESS_STATE_MAX] = { 53 : : [LINK_ADDRESS_STATE_OFF] = "off", 54 : : [LINK_ADDRESS_STATE_DEGRADED] = "degraded", 55 : : [LINK_ADDRESS_STATE_ROUTABLE] = "routable", 56 : : }; 57 : : 58 [ # # # # ]: 0 : DEFINE_STRING_TABLE_LOOKUP(link_address_state, LinkAddressState);