]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: add nlmon support
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 23 May 2019 02:36:25 +0000 (11:36 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 28 May 2019 13:47:15 +0000 (22:47 +0900)
nlmon is a Netlink monitor device.

man/systemd.netdev.xml
src/libsystemd/sd-netlink/netlink-types.c
src/libsystemd/sd-netlink/netlink-types.h
src/network/meson.build
src/network/netdev/netdev.c
src/network/netdev/netdev.h
src/network/netdev/nlmon.c [new file with mode: 0644]
src/network/netdev/nlmon.h [new file with mode: 0644]
src/network/networkd-link.c

index 26a5dbbd1e1d437f2c09879bf9bb0b703592b48e..066793c6e64eee17cbadf11c3af9dc10b906f565 100644 (file)
           <entry>WireGuard Secure Network Tunnel.</entry></row>
 
           <row><entry><varname>netdevsim</varname></entry>
-          <entry> A simulator. This simulated networking device is used for testing various networking APIs and at this time is particularly focused on testing hardware offloading related interfaces.</entry></row>
+          <entry>A simulator. This simulated networking device is used for testing various networking APIs and at this time is particularly focused on testing hardware offloading related interfaces.</entry></row>
+
+          <row><entry><varname>nlmon</varname></entry>
+          <entry>A Netlink monitor device. Use an nlmon device when you want to monitor system Netlink messages.</entry></row>
 
           <row><entry><varname>fou</varname></entry>
           <entry>Foo-over-UDP tunneling.</entry></row>
index 7fd3efbd35723a44b7b7d745d7d5191043937774..35ca843569d1a14f4f50b13dd66169596a8520d7 100644 (file)
@@ -357,6 +357,7 @@ static const char* const nl_union_link_info_data_table[] = {
         [NL_UNION_LINK_INFO_DATA_NETDEVSIM] = "netdevsim",
         [NL_UNION_LINK_INFO_DATA_CAN] = "can",
         [NL_UNION_LINK_INFO_DATA_MACSEC] = "macsec",
+        [NL_UNION_LINK_INFO_DATA_NLMON] = "nlmon",
 };
 
 DEFINE_STRING_TABLE_LOOKUP(nl_union_link_info_data, NLUnionLinkInfoData);
index 8585280463a647bf22d3beca634d92a945c0adb0..fed43ae43c09640a23f54f033c497fcc82986908 100644 (file)
@@ -82,6 +82,7 @@ typedef enum NLUnionLinkInfoData {
         NL_UNION_LINK_INFO_DATA_NETDEVSIM,
         NL_UNION_LINK_INFO_DATA_CAN,
         NL_UNION_LINK_INFO_DATA_MACSEC,
+        NL_UNION_LINK_INFO_DATA_NLMON,
         _NL_UNION_LINK_INFO_DATA_MAX,
         _NL_UNION_LINK_INFO_DATA_INVALID = -1
 } NLUnionLinkInfoData;
index 0bcf7f4a815d193f510c909931e67d33a34e963e..feeb98cb07424ed87dcffd89d2000fa556d754d8 100644 (file)
@@ -13,6 +13,8 @@ sources = files('''
         netdev/macvlan.h
         netdev/netdev.c
         netdev/netdev.h
+        netdev/nlmon.c
+        netdev/nlmon.h
         netdev/tunnel.c
         netdev/tunnel.h
         netdev/tuntap.c
index 1c307a3125d5c52d7eecacb312c2666fffeb4ea1..542923760355d4cf7764c52f89395b7161cc302b 100644 (file)
@@ -19,6 +19,7 @@
 #include "netdev/macvlan.h"
 #include "netdev/netdev.h"
 #include "netdev/netdevsim.h"
+#include "netdev/nlmon.h"
 #include "netdev/tunnel.h"
 #include "netdev/tuntap.h"
 #include "netdev/vcan.h"
@@ -70,6 +71,7 @@ const NetDevVTable * const netdev_vtable[_NETDEV_KIND_MAX] = {
         [NETDEV_KIND_ERSPAN] = &erspan_vtable,
         [NETDEV_KIND_L2TP] = &l2tptnl_vtable,
         [NETDEV_KIND_MACSEC] = &macsec_vtable,
+        [NETDEV_KIND_NLMON] = &nlmon_vtable,
 };
 
 static const char* const netdev_kind_table[_NETDEV_KIND_MAX] = {
@@ -104,6 +106,7 @@ static const char* const netdev_kind_table[_NETDEV_KIND_MAX] = {
         [NETDEV_KIND_ERSPAN] = "erspan",
         [NETDEV_KIND_L2TP] = "l2tp",
         [NETDEV_KIND_MACSEC] = "macsec",
+        [NETDEV_KIND_NLMON] = "nlmon",
 };
 
 DEFINE_STRING_TABLE_LOOKUP(netdev_kind, NetDevKind);
index 8295ba1966da2305adabc22d8fb2bcb749e71060..57fabbef40ddfc36bfb63a991a3c90294a6a560a 100644 (file)
@@ -49,6 +49,7 @@ typedef enum NetDevKind {
         NETDEV_KIND_ERSPAN,
         NETDEV_KIND_L2TP,
         NETDEV_KIND_MACSEC,
+        NETDEV_KIND_NLMON,
         _NETDEV_KIND_MAX,
         _NETDEV_KIND_TUNNEL, /* Used by config_parse_stacked_netdev() */
         _NETDEV_KIND_INVALID = -1
diff --git a/src/network/netdev/nlmon.c b/src/network/netdev/nlmon.c
new file mode 100644 (file)
index 0000000..c58a6b5
--- /dev/null
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
+#include "netdev/nlmon.h"
+
+static int netdev_nlmon_verify(NetDev *netdev, const char *filename) {
+        assert(netdev);
+        assert(filename);
+
+        if (netdev->mac) {
+                log_netdev_warning(netdev, "%s: MACAddress= is not supported. Ignoring", filename);
+                netdev->mac = mfree(netdev->mac);
+        }
+
+        return 0;
+}
+
+const NetDevVTable nlmon_vtable = {
+        .object_size = sizeof(NLMon),
+        .sections = "Match\0NetDev\0",
+        .create_type = NETDEV_CREATE_INDEPENDENT,
+        .config_verify = netdev_nlmon_verify,
+};
diff --git a/src/network/netdev/nlmon.h b/src/network/netdev/nlmon.h
new file mode 100644 (file)
index 0000000..590b62d
--- /dev/null
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+#pragma once
+
+typedef struct NLMon NLMon;
+
+#include "netdev/netdev.h"
+
+struct NLMon {
+        NetDev meta;
+};
+
+DEFINE_NETDEV_CAST(NLMON, NLMon);
+
+extern const NetDevVTable nlmon_vtable;
index 924cc8ce6af25b32f1eea102debb813b4551ee07..9486329b9a9191c24828640406ee66a09a0dddc2 100644 (file)
@@ -132,7 +132,7 @@ bool link_ipv4ll_enabled(Link *link, AddressFamilyBoolean mask) {
         if (!link->network)
                 return false;
 
-        if (STRPTR_IN_SET(link->kind, "vrf", "wireguard", "ipip", "gre", "ip6gre", "ip6tnl", "sit", "vti", "vti6", "can", "vcan", "vxcan"))
+        if (STRPTR_IN_SET(link->kind, "vrf", "wireguard", "ipip", "gre", "ip6gre", "ip6tnl", "sit", "vti", "vti6", "can", "vcan", "vxcan", "nlmon"))
                 return false;
 
         /* L3 or L3S mode do not support ARP. */
@@ -142,6 +142,9 @@ bool link_ipv4ll_enabled(Link *link, AddressFamilyBoolean mask) {
         if (link->network->bond)
                 return false;
 
+        if (link->network->bond)
+                return false;
+
         return link->network->link_local & mask;
 }
 
@@ -157,7 +160,7 @@ static bool link_ipv6ll_enabled(Link *link) {
         if (!link->network)
                 return false;
 
-        if (STRPTR_IN_SET(link->kind, "vrf", "wireguard", "ipip", "gre", "sit", "vti", "can", "vcan", "vxcan"))
+        if (STRPTR_IN_SET(link->kind, "vrf", "wireguard", "ipip", "gre", "sit", "vti", "can", "vcan", "vxcan", "nlmon"))
                 return false;
 
         if (link->network->bond)