1 /* SPDX-License-Identifier: LGPL-2.1-or-later */ 2 #pragma once 3 4 #include <errno.h> 5 #include <stdbool.h> 6 7 #include "macro.h" 8 9 bool network_is_online(void); 10 11 typedef enum AddressFamily { 12 /* This is a bitmask, though it usually doesn't feel that way! */ 13 ADDRESS_FAMILY_NO = 0, 14 ADDRESS_FAMILY_IPV4 = 1 << 0, 15 ADDRESS_FAMILY_IPV6 = 1 << 1, 16 ADDRESS_FAMILY_YES = ADDRESS_FAMILY_IPV4 | ADDRESS_FAMILY_IPV6, 17 _ADDRESS_FAMILY_MAX, 18 _ADDRESS_FAMILY_INVALID = -EINVAL, 19 } AddressFamily; 20 21 typedef enum LinkOperationalState { 22 LINK_OPERSTATE_MISSING, 23 LINK_OPERSTATE_OFF, 24 LINK_OPERSTATE_NO_CARRIER, 25 LINK_OPERSTATE_DORMANT, 26 LINK_OPERSTATE_DEGRADED_CARRIER, 27 LINK_OPERSTATE_CARRIER, 28 LINK_OPERSTATE_DEGRADED, 29 LINK_OPERSTATE_ENSLAVED, 30 LINK_OPERSTATE_ROUTABLE, 31 _LINK_OPERSTATE_MAX, 32 _LINK_OPERSTATE_INVALID = -EINVAL, 33 } LinkOperationalState; 34 35 typedef enum LinkCarrierState { 36 LINK_CARRIER_STATE_OFF = LINK_OPERSTATE_OFF, 37 LINK_CARRIER_STATE_NO_CARRIER = LINK_OPERSTATE_NO_CARRIER, 38 LINK_CARRIER_STATE_DORMANT = LINK_OPERSTATE_DORMANT, 39 LINK_CARRIER_STATE_DEGRADED_CARRIER = LINK_OPERSTATE_DEGRADED_CARRIER, 40 LINK_CARRIER_STATE_CARRIER = LINK_OPERSTATE_CARRIER, 41 LINK_CARRIER_STATE_ENSLAVED = LINK_OPERSTATE_ENSLAVED, 42 _LINK_CARRIER_STATE_MAX, 43 _LINK_CARRIER_STATE_INVALID = -EINVAL, 44 } LinkCarrierState; 45 46 typedef enum LinkAddressState { 47 LINK_ADDRESS_STATE_OFF, 48 LINK_ADDRESS_STATE_DEGRADED, 49 LINK_ADDRESS_STATE_ROUTABLE, 50 _LINK_ADDRESS_STATE_MAX, 51 _LINK_ADDRESS_STATE_INVALID = -EINVAL, 52 } LinkAddressState; 53 54 typedef enum LinkOnlineState { 55 LINK_ONLINE_STATE_OFFLINE, 56 LINK_ONLINE_STATE_PARTIAL, 57 LINK_ONLINE_STATE_ONLINE, 58 _LINK_ONLINE_STATE_MAX, 59 _LINK_ONLINE_STATE_INVALID = -EINVAL, 60 } LinkOnlineState; 61 62 const char* link_operstate_to_string(LinkOperationalState s) _const_; 63 LinkOperationalState link_operstate_from_string(const char *s) _pure_; 64 65 const char* link_carrier_state_to_string(LinkCarrierState s) _const_; 66 LinkCarrierState link_carrier_state_from_string(const char *s) _pure_; 67 68 const char* link_required_address_family_to_string(AddressFamily s) _const_; 69 AddressFamily link_required_address_family_from_string(const char *s) _pure_; 70 71 const char* link_address_state_to_string(LinkAddressState s) _const_; 72 LinkAddressState link_address_state_from_string(const char *s) _pure_; 73 74 const char* link_online_state_to_string(LinkOnlineState s) _const_; 75 LinkOnlineState link_online_state_from_string(const char *s) _pure_; 76 77 typedef struct LinkOperationalStateRange { 78 LinkOperationalState min; 79 LinkOperationalState max; 80 } LinkOperationalStateRange; 81 82 #define LINK_OPERSTATE_RANGE_DEFAULT (LinkOperationalStateRange) { LINK_OPERSTATE_DEGRADED, \ 83 LINK_OPERSTATE_ROUTABLE } 84 85 int parse_operational_state_range(const char *str, LinkOperationalStateRange *out); 86 int network_link_get_operational_state(int ifindex, LinkOperationalState *ret); 87