]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
netif-util: introduce netif_has_carrier()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 20 Jan 2022 20:02:42 +0000 (05:02 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 20 Jan 2022 20:02:42 +0000 (05:02 +0900)
src/network/networkd-link.c
src/network/networkd-link.h
src/shared/netif-util.c
src/shared/netif-util.h

index 89ee8c83670d59e57a65ccb1d8e8ff995ed0121b..1f5f4bd41a154823d5b8a819d5516f8148c4b360 100644 (file)
@@ -1802,21 +1802,6 @@ static int link_admin_state_down(Link *link) {
         return 0;
 }
 
-bool link_has_carrier(Link *link) {
-        /* see Documentation/networking/operstates.txt in the kernel sources */
-
-        if (link->kernel_operstate == IF_OPER_UP)
-                return true;
-
-        if (link->kernel_operstate == IF_OPER_UNKNOWN)
-                /* operstate may not be implemented, so fall back to flags */
-                if (FLAGS_SET(link->flags, IFF_LOWER_UP | IFF_RUNNING) &&
-                    !FLAGS_SET(link->flags, IFF_DORMANT))
-                        return true;
-
-        return false;
-}
-
 static bool link_is_enslaved(Link *link) {
         if (link->flags & IFF_SLAVE)
                 return true;
index 8bf1cc67f7188a1195432db0fbfb493408ec3bab..7ccb31df79199250c7d153b5432bb29ae16c6032 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "ether-addr-util.h"
 #include "log-link.h"
+#include "netif-util.h"
 #include "network-util.h"
 #include "networkd-util.h"
 #include "ordered-set.h"
@@ -212,7 +213,10 @@ void link_check_ready(Link *link);
 
 void link_update_operstate(Link *link, bool also_update_bond_master);
 
-bool link_has_carrier(Link *link);
+static inline bool link_has_carrier(Link *link) {
+        assert(link);
+        return netif_has_carrier(link->kernel_operstate, link->flags);
+}
 
 bool link_ipv6_enabled(Link *link);
 bool link_ipv6ll_enabled(Link *link);
index 603d4de109ff7fb8d558f8b81205cd93d9dd6468..69d7cc2b10dd38bc5fee9382900c3c6f22004573 100644 (file)
@@ -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"
 #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;
index c26dab63cf3018cc64068d7896f8c596728ad209..fb6a27cce151783f0244dc276a67294fbd56ae34 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "ether-addr-util.h"
 
+bool netif_has_carrier(uint8_t operstate, unsigned flags);
 int net_get_type_string(sd_device *device, uint16_t iftype, char **ret);
 const char *net_get_persistent_name(sd_device *device);
 int net_get_unique_predictable_data(sd_device *device, bool use_sysname, uint64_t *ret);