]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: introduce link_flags_to_string_alloc() and kernel_operstate_to_string()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 14 Nov 2021 09:36:42 +0000 (18:36 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 25 Nov 2021 13:35:35 +0000 (22:35 +0900)
src/network/networkd-link.c
src/network/networkd-link.h

index a63b1704c1ae4f41e2108dd6cdef65897effd4cd..36ef6a0b5df5b02ef961642521afb0425de95a11 100644 (file)
@@ -2670,3 +2670,53 @@ static const char* const link_state_table[_LINK_STATE_MAX] = {
 };
 
 DEFINE_STRING_TABLE_LOOKUP(link_state, LinkState);
+
+int link_flags_to_string_alloc(uint32_t flags, char **ret) {
+        _cleanup_free_ char *str = NULL;
+        static const struct {
+                uint32_t flag;
+                const char *name;
+        } map[] = {
+                { IFF_UP,          "up"             }, /* interface is up. */
+                { IFF_BROADCAST,   "broadcast"      }, /* broadcast address valid.*/
+                { IFF_DEBUG,       "debug"          }, /* turn on debugging. */
+                { IFF_LOOPBACK,    "loopback"       }, /* interface is a loopback net. */
+                { IFF_POINTOPOINT, "point-to-point" }, /* interface has p-p link. */
+                { IFF_NOTRAILERS,  "no-trailers"    }, /* avoid use of trailers. */
+                { IFF_RUNNING,     "running"        }, /* interface RFC2863 OPER_UP. */
+                { IFF_NOARP,       "no-arp"         }, /* no ARP protocol. */
+                { IFF_PROMISC,     "promiscuous"    }, /* receive all packets. */
+                { IFF_ALLMULTI,    "all-multicast"  }, /* receive all multicast packets. */
+                { IFF_MASTER,      "master"         }, /* master of a load balancer. */
+                { IFF_SLAVE,       "slave"          }, /* slave of a load balancer. */
+                { IFF_MULTICAST,   "multicast"      }, /* supports multicast.*/
+                { IFF_PORTSEL,     "portsel"        }, /* can set media type. */
+                { IFF_AUTOMEDIA,   "auto-media"     }, /* auto media select active. */
+                { IFF_DYNAMIC,     "dynamic"        }, /* dialup device with changing addresses. */
+                { IFF_LOWER_UP,    "lower-up"       }, /* driver signals L1 up. */
+                { IFF_DORMANT,     "dormant"        }, /* driver signals dormant. */
+                { IFF_ECHO,        "echo"           }, /* echo sent packets. */
+        };
+
+        assert(ret);
+
+        for (size_t i = 0; i < ELEMENTSOF(map); i++)
+                if (flags & map[i].flag &&
+                    !strextend_with_separator(&str, ",", map[i].name))
+                        return -ENOMEM;
+
+        *ret = TAKE_PTR(str);
+        return 0;
+}
+
+static const char * const kernel_operstate_table[] = {
+        [IF_OPER_UNKNOWN]        = "unknown",
+        [IF_OPER_NOTPRESENT]     = "not-present",
+        [IF_OPER_DOWN]           = "down",
+        [IF_OPER_LOWERLAYERDOWN] = "lower-layer-down",
+        [IF_OPER_TESTING]        = "testing",
+        [IF_OPER_DORMANT]        = "dormant",
+        [IF_OPER_UP]             = "up",
+};
+
+DEFINE_STRING_TABLE_LOOKUP_TO_STRING(kernel_operstate, int);
index edf93d720ef2694a4aca00c9d826053c7b5849e1..cba911f02d91c52ebec3426e008bbc08ee54f8a0 100644 (file)
@@ -226,3 +226,6 @@ int link_reconfigure_after_sleep(Link *link);
 
 int manager_udev_process_link(sd_device_monitor *monitor, sd_device *device, void *userdata);
 int manager_rtnl_process_link(sd_netlink *rtnl, sd_netlink_message *message, Manager *m);
+
+int link_flags_to_string_alloc(uint32_t flags, char **ret);
+const char *kernel_operstate_to_string(int t) _const_;