]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkd: bridge FDB support more NTF_* flags
authorSusant Sahani <ssahani@gmail.com>
Wed, 8 May 2019 14:13:21 +0000 (19:43 +0530)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 14 May 2019 00:24:51 +0000 (02:24 +0200)
Add support to configure NTF_ROUTER and NTF_USE

man/systemd.network.xml
src/network/networkd-fdb.c
src/network/networkd-fdb.h
src/network/networkd-network-gperf.gperf
test/fuzz/fuzz-network-parser/directives.network

index 3ff1a036ff5ebbbd7aa5cae6c8a18e1e3700104e..ca82f33bb4b98ef25f2978dbbcbc8479e3d6e08c 100644 (file)
             Defaults to unset.</para>
           </listitem>
         </varlistentry>
+        <varlistentry>
+          <term><varname>AssociatedWith=</varname></term>
+          <listitem>
+            <para>Specifies where the address is associated with. Takes one of <literal>use</literal>,
+            <literal>self</literal>, <literal>master</literal> or <literal>router</literal>.
+            <literal>use</literal> means the address is in use. User space can use this option to
+            indicate to the kernel that the fdb entry is in use. <literal>self</literal> means
+            the address is associated with the port drivers fdb. Usually hardware. <literal>master</literal>
+            means the address is associated with master devices fdb. <literal>router</literal> means
+            the destination address is associated with a router. Note that it's valid if the referenced
+            device is a VXLAN type device and has route shortcircuit enabled. Defaults to <literal>self</literal>.</para>
+          </listitem>
+        </varlistentry>
       </variablelist>
   </refsect1>
 
index fdac574d74fce76abbb247f49776b35610ed51ce..4ae511fc7aeb3f9a3f4bfe5148d0af5d69f1c512 100644 (file)
 #include "networkd-manager.h"
 #include "parse-util.h"
 #include "string-util.h"
+#include "string-table.h"
 #include "util.h"
 #include "vlan-util.h"
 
 #define STATIC_FDB_ENTRIES_PER_NETWORK_MAX 1024U
 
+static const char* const fdb_ntf_flags_table[_NEIGHBOR_CACHE_ENTRY_FLAGS_MAX] = {
+        [NEIGHBOR_CACHE_ENTRY_FLAGS_USE] = "use",
+        [NEIGHBOR_CACHE_ENTRY_FLAGS_SELF] = "self",
+        [NEIGHBOR_CACHE_ENTRY_FLAGS_MASTER] = "master",
+        [NEIGHBOR_CACHE_ENTRY_FLAGS_ROUTER] = "router",
+};
+
+DEFINE_STRING_TABLE_LOOKUP(fdb_ntf_flags, NeighborCacheEntryFlags);
+
 /* create a new FDB entry or get an existing one. */
 static int fdb_entry_new_static(
                 Network *network,
@@ -68,6 +78,7 @@ static int fdb_entry_new_static(
                 .network = network,
                 .mac_addr = TAKE_PTR(mac_addr),
                 .vni = VXLAN_VID_MAX + 1,
+                .fdb_ntf_flags = NEIGHBOR_CACHE_ENTRY_FLAGS_SELF,
         };
 
         LIST_PREPEND(static_fdb_entries, network->static_fdb_entries, fdb_entry);
@@ -106,9 +117,6 @@ static int set_fdb_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link)
 /* send a request to the kernel to add a FDB entry in its static MAC table. */
 int fdb_entry_configure(Link *link, FdbEntry *fdb_entry) {
         _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
-        sd_netlink *rtnl;
-        Bridge *bridge;
-        uint8_t flags;
         int r;
 
         assert(link);
@@ -116,20 +124,12 @@ int fdb_entry_configure(Link *link, FdbEntry *fdb_entry) {
         assert(link->manager);
         assert(fdb_entry);
 
-        rtnl = link->manager->rtnl;
-        bridge = BRIDGE(link->network->bridge);
-
         /* create new RTM message */
-        r = sd_rtnl_message_new_neigh(rtnl, &req, RTM_NEWNEIGH, link->ifindex, PF_BRIDGE);
+        r = sd_rtnl_message_new_neigh(link->manager->rtnl, &req, RTM_NEWNEIGH, link->ifindex, PF_BRIDGE);
         if (r < 0)
                 return rtnl_log_create_error(r);
 
-        if (bridge)
-                flags = NTF_MASTER;
-        else
-                flags = NTF_SELF;
-
-        r = sd_rtnl_message_neigh_set_flags(req, flags);
+        r = sd_rtnl_message_neigh_set_flags(req, fdb_entry->fdb_ntf_flags);
         if (r < 0)
                 return rtnl_log_create_error(r);
 
@@ -162,7 +162,7 @@ int fdb_entry_configure(Link *link, FdbEntry *fdb_entry) {
         }
 
         /* send message to the kernel to update its internal static MAC table. */
-        r = netlink_call_async(rtnl, NULL, req, set_fdb_handler,
+        r = netlink_call_async(link->manager->rtnl, NULL, req, set_fdb_handler,
                                link_netlink_destroy_callback, link);
         if (r < 0)
                 return log_link_error_errno(link, r, "Could not send rtnetlink message: %m");
@@ -359,3 +359,45 @@ int config_parse_fdb_vxlan_vni(
 
         return 0;
 }
+
+
+int config_parse_fdb_ntf_flags(
+                const char *unit,
+                const char *filename,
+                unsigned line,
+                const char *section,
+                unsigned section_line,
+                const char *lvalue,
+                int ltype,
+                const char *rvalue,
+                void *data,
+                void *userdata) {
+
+        _cleanup_(fdb_entry_free_or_set_invalidp) FdbEntry *fdb_entry = NULL;
+        Network *network = userdata;
+        NeighborCacheEntryFlags f;
+        int r;
+
+        assert(filename);
+        assert(section);
+        assert(lvalue);
+        assert(rvalue);
+        assert(data);
+
+        r = fdb_entry_new_static(network, filename, section_line, &fdb_entry);
+        if (r < 0)
+                return log_oom();
+
+        f = fdb_ntf_flags_from_string(rvalue);
+        if (f < 0) {
+                log_syntax(unit, LOG_ERR, filename, line, 0,
+                           "FDB failed to parse AssociatedWith=, ignoring assignment: %s",
+                           rvalue);
+                return 0;
+        }
+
+        fdb_entry->fdb_ntf_flags = f;
+        fdb_entry = NULL;
+
+        return 0;
+}
index 6954e555fa413186d4cfc24b1244e3a280e6c252..bcdd8ce3cb241ab21ed262352c5e31f002c4d9a3 100644 (file)
@@ -5,6 +5,8 @@
   Copyright © 2014 Intel Corporation. All rights reserved.
 ***/
 
+#include <linux/neighbour.h>
+
 #include "conf-parser.h"
 #include "list.h"
 #include "macro.h"
@@ -15,6 +17,15 @@ typedef struct FdbEntry FdbEntry;
 typedef struct Link Link;
 typedef struct NetworkConfigSection NetworkConfigSection;
 
+typedef enum NeighborCacheEntryFlags {
+        NEIGHBOR_CACHE_ENTRY_FLAGS_USE = NTF_USE,
+        NEIGHBOR_CACHE_ENTRY_FLAGS_SELF = NTF_SELF,
+        NEIGHBOR_CACHE_ENTRY_FLAGS_MASTER = NTF_MASTER,
+        NEIGHBOR_CACHE_ENTRY_FLAGS_ROUTER = NTF_ROUTER,
+        _NEIGHBOR_CACHE_ENTRY_FLAGS_MAX,
+        _NEIGHBOR_CACHE_ENTRY_FLAGS_INVALID = -1,
+} NeighborCacheEntryFlags;
+
 struct FdbEntry {
         Network *network;
         NetworkConfigSection *section;
@@ -26,6 +37,7 @@ struct FdbEntry {
 
         struct ether_addr *mac_addr;
         union in_addr_union destination_addr;
+        NeighborCacheEntryFlags fdb_ntf_flags;
 
         LIST_FIELDS(FdbEntry, static_fdb_entries);
 };
@@ -35,7 +47,11 @@ int fdb_entry_configure(Link *link, FdbEntry *fdb_entry);
 
 DEFINE_NETWORK_SECTION_FUNCTIONS(FdbEntry, fdb_entry_free);
 
+const char* fdb_ntf_flags_to_string(NeighborCacheEntryFlags i) _const_;
+NeighborCacheEntryFlags fdb_ntf_flags_from_string(const char *s) _pure_;
+
 CONFIG_PARSER_PROTOTYPE(config_parse_fdb_hwaddr);
 CONFIG_PARSER_PROTOTYPE(config_parse_fdb_vlan_id);
 CONFIG_PARSER_PROTOTYPE(config_parse_fdb_destination);
 CONFIG_PARSER_PROTOTYPE(config_parse_fdb_vxlan_vni);
+CONFIG_PARSER_PROTOTYPE(config_parse_fdb_ntf_flags);
index c6036e29faf6819f1912889a7c972656ae3593ac..a57d9395f63c7382ada8f5698551c25509dd84e4 100644 (file)
@@ -186,6 +186,7 @@ BridgeFDB.MACAddress,                   config_parse_fdb_hwaddr,
 BridgeFDB.VLANId,                       config_parse_fdb_vlan_id,                        0,                             0
 BridgeFDB.Destination,                  config_parse_fdb_destination,                    0,                             0
 BridgeFDB.VNI,                          config_parse_fdb_vxlan_vni,                      0,                             0
+BridgeFDB.AssociatedWith,               config_parse_fdb_ntf_flags,                      0,                             0
 BridgeVLAN.PVID,                        config_parse_brvlan_pvid,                        0,                             0
 BridgeVLAN.VLAN,                        config_parse_brvlan_vlan,                        0,                             0
 BridgeVLAN.EgressUntagged,              config_parse_brvlan_untagged,                    0,                             0
index 97e8e4a58026dcad1fbd90fbb2f022ae09b27f7f..5d48f0825b8c596ed64cae6da22a480072581350 100644 (file)
@@ -37,6 +37,7 @@ VLANId=
 MACAddress=
 Destination=
 VNI=
+AssociatedWith=
 [DHCP]
 UseDomains=
 UseRoutes=