From 61b824c5619a3f5f4fa1c02a3258c36deeb689ca Mon Sep 17 00:00:00 2001 From: Susant Sahani Date: Mon, 6 May 2019 19:58:52 +0530 Subject: [PATCH] networkd: bridge fdb add support to configure VXLAN VNI --- man/systemd.network.xml | 8 +++ src/network/networkd-fdb.c | 62 ++++++++++++++++++- src/network/networkd-fdb.h | 3 + src/network/networkd-network-gperf.gperf | 1 + .../fuzz-network-parser/directives.network | 1 + 5 files changed, 73 insertions(+), 2 deletions(-) diff --git a/man/systemd.network.xml b/man/systemd.network.xml index 7353b57419c..f24bf401595 100644 --- a/man/systemd.network.xml +++ b/man/systemd.network.xml @@ -1944,6 +1944,14 @@ table entry. + + VNI= + + The VXLAN Network Identifier (or VXLAN Segment ID) to use to connect to + the remote VXLAN tunnel endpoint. Takes a number in the range 1-16777215. + Defaults to unset. + + diff --git a/src/network/networkd-fdb.c b/src/network/networkd-fdb.c index 6ebc45267fc..fdac574d74f 100644 --- a/src/network/networkd-fdb.c +++ b/src/network/networkd-fdb.c @@ -9,9 +9,12 @@ #include "alloc-util.h" #include "conf-parser.h" #include "netdev/bridge.h" +#include "netdev/vxlan.h" #include "netlink-util.h" #include "networkd-fdb.h" #include "networkd-manager.h" +#include "parse-util.h" +#include "string-util.h" #include "util.h" #include "vlan-util.h" @@ -64,6 +67,7 @@ static int fdb_entry_new_static( *fdb_entry = (FdbEntry) { .network = network, .mac_addr = TAKE_PTR(mac_addr), + .vni = VXLAN_VID_MAX + 1, }; LIST_PREPEND(static_fdb_entries, network->static_fdb_entries, fdb_entry); @@ -103,9 +107,9 @@ static int set_fdb_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) int fdb_entry_configure(Link *link, FdbEntry *fdb_entry) { _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL; sd_netlink *rtnl; - int r; - uint8_t flags; Bridge *bridge; + uint8_t flags; + int r; assert(link); assert(link->network); @@ -151,6 +155,12 @@ int fdb_entry_configure(Link *link, FdbEntry *fdb_entry) { return log_link_error_errno(link, r, "Could not append NDA_DST attribute: %m"); } + if (fdb_entry->vni <= VXLAN_VID_MAX) { + r = sd_netlink_message_append_u32(req, NDA_VNI, fdb_entry->vni); + if (r < 0) + return log_link_error_errno(link, r, "Could not append NDA_VNI attribute: %m"); + } + /* send message to the kernel to update its internal static MAC table. */ r = netlink_call_async(rtnl, NULL, req, set_fdb_handler, link_netlink_destroy_callback, link); @@ -301,3 +311,51 @@ int config_parse_fdb_destination( return 0; } + +int config_parse_fdb_vxlan_vni( + 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; + uint32_t vni; + 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(); + + r = safe_atou32(rvalue, &vni); + if (r < 0) { + log_syntax(unit, LOG_ERR, filename, line, r, + "Failed to parse VXLAN Network Identifier (VNI), ignoring assignment: %s", + rvalue); + return 0; + } + + if (vni > VXLAN_VID_MAX) { + log_syntax(unit, LOG_ERR, filename, line, 0, + "FDB invalid VXLAN Network Identifier (VNI), ignoring assignment: %s", + rvalue); + return 0; + } + + fdb_entry->vni = vni; + fdb_entry = NULL; + + return 0; +} diff --git a/src/network/networkd-fdb.h b/src/network/networkd-fdb.h index e3c45acd72d..6954e555fa4 100644 --- a/src/network/networkd-fdb.h +++ b/src/network/networkd-fdb.h @@ -19,6 +19,8 @@ struct FdbEntry { Network *network; NetworkConfigSection *section; + uint32_t vni; + int family; uint16_t vlan_id; @@ -36,3 +38,4 @@ DEFINE_NETWORK_SECTION_FUNCTIONS(FdbEntry, fdb_entry_free); 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); diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf index 646cd91e938..98c2241fca2 100644 --- a/src/network/networkd-network-gperf.gperf +++ b/src/network/networkd-network-gperf.gperf @@ -181,6 +181,7 @@ Bridge.Priority, config_parse_bridge_port_priority, BridgeFDB.MACAddress, config_parse_fdb_hwaddr, 0, 0 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 BridgeVLAN.PVID, config_parse_brvlan_pvid, 0, 0 BridgeVLAN.VLAN, config_parse_brvlan_vlan, 0, 0 BridgeVLAN.EgressUntagged, config_parse_brvlan_untagged, 0, 0 diff --git a/test/fuzz/fuzz-network-parser/directives.network b/test/fuzz/fuzz-network-parser/directives.network index 8149a35d1eb..17f21b42587 100644 --- a/test/fuzz/fuzz-network-parser/directives.network +++ b/test/fuzz/fuzz-network-parser/directives.network @@ -33,6 +33,7 @@ MACAddress= VLANId= MACAddress= Destination= +VNI= [DHCP] UseDomains= UseRoutes= -- 2.39.5