summaryrefslogtreecommitdiffstats
path: root/src/shared/netif-util.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-01-20 21:02:42 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-01-20 21:02:42 +0100
commit61e964df713b5930a049053a0c4059521007b596 (patch)
tree96ed610edc1189ff6a033424f0f3dcc61736f228 /src/shared/netif-util.c
parentresolve: drop redundant call of link_allocate_scopes() and link_add_rrs() (diff)
downloadsystemd-61e964df713b5930a049053a0c4059521007b596.tar.xz
systemd-61e964df713b5930a049053a0c4059521007b596.zip
netif-util: introduce netif_has_carrier()
Diffstat (limited to 'src/shared/netif-util.c')
-rw-r--r--src/shared/netif-util.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/shared/netif-util.c b/src/shared/netif-util.c
index 603d4de109..69d7cc2b10 100644
--- a/src/shared/netif-util.c
+++ b/src/shared/netif-util.c
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#include <linux/if.h>
#include <linux/if_arp.h>
#include "arphrd-util.h"
@@ -11,6 +12,20 @@
#include "sparse-endian.h"
#include "strv.h"
+bool netif_has_carrier(uint8_t operstate, unsigned flags) {
+ /* see Documentation/networking/operstates.txt in the kernel sources */
+
+ if (operstate == IF_OPER_UP)
+ return true;
+
+ if (operstate != IF_OPER_UNKNOWN)
+ return false;
+
+ /* operstate may not be implemented, so fall back to flags */
+ return FLAGS_SET(flags, IFF_LOWER_UP | IFF_RUNNING) &&
+ !FLAGS_SET(flags, IFF_DORMANT);
+}
+
int net_get_type_string(sd_device *device, uint16_t iftype, char **ret) {
const char *t;
char *p;