[systemd-devel] [PATCH] Add FDB support
Alin Rauta
alin.rauta at intel.com
Thu Dec 11 08:07:57 PST 2014
Signed-off-by: Alin Rauta <alin.rauta at intel.com>
---
Makefile.am | 1 +
man/systemd.network.xml | 31 +++
src/libsystemd/sd-rtnl/rtnl-message.c | 56 ++++-
src/libsystemd/sd-rtnl/rtnl-types.c | 15 +-
src/network/networkd-fdb.c | 357 +++++++++++++++++++++++++++++++
src/network/networkd-link.c | 37 ++++
src/network/networkd-network-gperf.gperf | 3 +
src/network/networkd-network.c | 13 ++
src/network/networkd.h | 32 +++
src/systemd/sd-rtnl.h | 4 +
10 files changed, 539 insertions(+), 10 deletions(-)
create mode 100644 src/network/networkd-fdb.c
diff --git a/Makefile.am b/Makefile.am
index 6f02c74..02dd273 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -5252,6 +5252,7 @@ libsystemd_networkd_core_la_SOURCES = \
src/network/networkd-address.c \
src/network/networkd-route.c \
src/network/networkd-manager.c \
+ src/network/networkd-fdb.c \
src/network/networkd-address-pool.c
nodist_libsystemd_networkd_core_la_SOURCES = \
diff --git a/man/systemd.network.xml b/man/systemd.network.xml
index 1edaa0b..9d44641 100644
--- a/man/systemd.network.xml
+++ b/man/systemd.network.xml
@@ -249,6 +249,15 @@
</listitem>
</varlistentry>
<varlistentry>
+ <term><varname>FDBControlled=</varname></term>
+ <listitem>
+ <para>A boolean. When true, deletes existing FDB entries
+ and configures those specified in [FDBEntry] section. Defaults
+ to false.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
<term><varname>LLMNR=</varname></term>
<listitem>
<para>A boolean or <literal>resolve</literal>. When true, enables
@@ -549,6 +558,28 @@
</refsect1>
<refsect1>
+ <title>[FDBEntry] Section Options</title>
+ <para>The <literal>[FDBEntry]</literal> section accepts the following keys. Specify
+ several <literal>[FDBEntry]</literal> sections to configure several static MAC table entries.</para>
+
+ <variablelist class='network-directives'>
+ <varlistentry>
+ <term><varname>MACAddress=</varname></term>
+ <listitem>
+ <para>As in the <literal>[Network]</literal> section. This key is mandatory.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><varname>VLAN=</varname></term>
+ <listitem>
+ <para>The VLAN for the new static MAC table entry.
+ If omitted, no VLAN info is appended to the new static MAC table entry.</para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect1>
+
+ <refsect1>
<title>Example</title>
<example>
<title>/etc/systemd/network/50-static.network</title>
diff --git a/src/libsystemd/sd-rtnl/rtnl-message.c b/src/libsystemd/sd-rtnl/rtnl-message.c
index 165e84d..9099440 100644
--- a/src/libsystemd/sd-rtnl/rtnl-message.c
+++ b/src/libsystemd/sd-rtnl/rtnl-message.c
@@ -220,6 +220,58 @@ int sd_rtnl_message_new_route(sd_rtnl *rtnl, sd_rtnl_message **ret,
return 0;
}
+int sd_rtnl_message_neigh_set_flags(sd_rtnl_message *m, uint8_t flags) {
+ struct ndmsg *ndm;
+
+ assert_return(m, -EINVAL);
+ assert_return(m->hdr, -EINVAL);
+ assert_return(rtnl_message_type_is_neigh(m->hdr->nlmsg_type), -EINVAL);
+
+ ndm = NLMSG_DATA(m->hdr);
+ ndm->ndm_flags |= flags;
+
+ return 0;
+}
+
+int sd_rtnl_message_neigh_set_state(sd_rtnl_message *m, uint16_t state) {
+ struct ndmsg *ndm;
+
+ assert_return(m, -EINVAL);
+ assert_return(m->hdr, -EINVAL);
+ assert_return(rtnl_message_type_is_neigh(m->hdr->nlmsg_type), -EINVAL);
+
+ ndm = NLMSG_DATA(m->hdr);
+ ndm->ndm_state |= state;
+
+ return 0;
+}
+
+int sd_rtnl_message_neigh_get_flags(sd_rtnl_message *m, uint8_t *flags) {
+ struct ndmsg *ndm;
+
+ assert_return(m, -EINVAL);
+ assert_return(m->hdr, -EINVAL);
+ assert_return(rtnl_message_type_is_neigh(m->hdr->nlmsg_type), -EINVAL);
+
+ ndm = NLMSG_DATA(m->hdr);
+ *flags = ndm->ndm_flags;
+
+ return 0;
+}
+
+int sd_rtnl_message_neigh_get_state(sd_rtnl_message *m, uint16_t *state) {
+ struct ndmsg *ndm;
+
+ assert_return(m, -EINVAL);
+ assert_return(m->hdr, -EINVAL);
+ assert_return(rtnl_message_type_is_neigh(m->hdr->nlmsg_type), -EINVAL);
+
+ ndm = NLMSG_DATA(m->hdr);
+ *state = ndm->ndm_state;
+
+ return 0;
+}
+
int sd_rtnl_message_neigh_get_family(sd_rtnl_message *m, int *family) {
struct ndmsg *ndm;
@@ -255,7 +307,9 @@ int sd_rtnl_message_new_neigh(sd_rtnl *rtnl, sd_rtnl_message **ret, uint16_t nlm
int r;
assert_return(rtnl_message_type_is_neigh(nlmsg_type), -EINVAL);
- assert_return(ndm_family == AF_INET || ndm_family == AF_INET6, -EINVAL);
+ assert_return(ndm_family == AF_INET ||
+ ndm_family == AF_INET6 ||
+ ndm_family == PF_BRIDGE, -EINVAL);
assert_return(ret, -EINVAL);
r = message_new(rtnl, ret, nlmsg_type);
diff --git a/src/libsystemd/sd-rtnl/rtnl-types.c b/src/libsystemd/sd-rtnl/rtnl-types.c
index a1db2ab..735ad75 100644
--- a/src/libsystemd/sd-rtnl/rtnl-types.c
+++ b/src/libsystemd/sd-rtnl/rtnl-types.c
@@ -332,15 +332,12 @@ static const NLTypeSystem rtnl_route_type_system = {
static const NLType rtnl_neigh_types[NDA_MAX + 1] = {
[NDA_DST] = { .type = NLA_IN_ADDR },
[NDA_LLADDR] = { .type = NLA_ETHER_ADDR },
-/*
- NDA_CACHEINFO,
- NDA_PROBES,
- NDA_VLAN,
- NDA_PORT
- NDA_VNI
- NDA_IFINDEX
- NDA_MASTER
-*/
+ [NDA_CACHEINFO] = { .type = NLA_CACHE_INFO, .size = sizeof(struct nda_cacheinfo) },
+ [NDA_PROBES] = { .type = NLA_U32 },
+ [NDA_VLAN] = { .type = NLA_U16 },
+ [NDA_PORT] = { .type = NLA_U16 },
+ [NDA_VNI] = { .type = NLA_U32 },
+ [NDA_IFINDEX] = { .type = NLA_U32 },
};
static const NLTypeSystem rtnl_neigh_type_system = {
diff --git a/src/network/networkd-fdb.c b/src/network/networkd-fdb.c
new file mode 100644
index 0000000..410de6f
--- /dev/null
+++ b/src/network/networkd-fdb.c
@@ -0,0 +1,357 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright (C) 2014 Intel Corporation. All rights reserved.
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <ctype.h>
+#include <net/if.h>
+#include <net/ethernet.h>
+
+#include "networkd.h"
+#include "networkd-netdev.h"
+#include "networkd-link.h"
+#include "network-internal.h"
+#include "path-util.h"
+#include "conf-files.h"
+#include "conf-parser.h"
+#include "util.h"
+
+/* create a new FDB entry or get an existing one. */
+int fdb_entry_new_static(Network *const network,
+ const unsigned section,
+ FdbEntry **ret) {
+ _cleanup_fdbentry_free_ FdbEntry *fdb_entry = NULL;
+ struct ether_addr *mac_addr = NULL;
+
+ assert(network);
+
+ /* search entry in hashmap first. */
+ if(section) {
+ fdb_entry = hashmap_get(network->fdb_entries_by_section, UINT_TO_PTR(section));
+ if (fdb_entry) {
+ *ret = fdb_entry;
+ fdb_entry = NULL;
+
+ return 0;
+ }
+ }
+
+ /* allocate space for MAC address. */
+ mac_addr = new0(struct ether_addr, 1);
+ if (!mac_addr)
+ return -ENOMEM;
+
+ /* allocate space for and FDB entry. */
+ fdb_entry = new0(FdbEntry, 1);
+
+ if (!fdb_entry) {
+ /* free previously allocated space for mac_addr. */
+ free(mac_addr);
+ return -ENOMEM;
+ }
+
+ /* init FDB structure. */
+ fdb_entry->network = network;
+ fdb_entry->mac_addr = mac_addr;
+
+ LIST_PREPEND(static_fdb_entries, network->static_fdb_entries, fdb_entry);
+
+ if (section) {
+ fdb_entry->section = section;
+ hashmap_put(network->fdb_entries_by_section,
+ UINT_TO_PTR(fdb_entry->section), fdb_entry);
+ }
+
+ /* return allocated FDB structure. */
+ *ret = fdb_entry;
+ fdb_entry = NULL;
+
+ return 0;
+}
+
+static int fdb_delete_existing(sd_rtnl *const rtnl,
+ sd_rtnl_message *const fdb,
+ const int ifindex) {
+ _cleanup_rtnl_message_unref_ sd_rtnl_message *del_req = NULL;
+ bool got_vlan_info = false; /* suppose we don't have VLAN info by default. */
+ struct ether_addr mac;
+ uint16_t vlan;
+ uint8_t flags;
+ uint16_t state;
+ int r;
+
+ r = sd_rtnl_message_read_ether_addr(fdb, NDA_LLADDR, &mac);
+ if (r < 0)
+ return rtnl_log_parse_error(r);
+
+ /* check if we have VLAN info available. */
+ r = sd_rtnl_message_read_u16(fdb, NDA_VLAN, &vlan);
+ if (r >= 0)
+ got_vlan_info = true;
+
+ r = sd_rtnl_message_neigh_get_flags(fdb, &flags);
+ if (r < 0)
+ return rtnl_log_parse_error(r);
+
+ r = sd_rtnl_message_neigh_get_state(fdb, &state);
+ if(r < 0)
+ return rtnl_log_parse_error(r);
+
+ /* delete current entry. */
+ r = sd_rtnl_message_new_neigh(rtnl, &del_req, RTM_DELNEIGH, ifindex, PF_BRIDGE);
+ if (r < 0)
+ return rtnl_log_create_error(r);
+
+ r = sd_rtnl_message_append_ether_addr(del_req, NDA_LLADDR, &mac);
+ if (r < 0)
+ return rtnl_log_create_error(r);
+
+ if (false != got_vlan_info) {
+ r = sd_rtnl_message_append_u16(del_req, NDA_VLAN, vlan);
+ if (r < 0)
+ return rtnl_log_create_error(r);
+ }
+
+ r = sd_rtnl_message_neigh_set_flags(del_req, flags);
+ if (r < 0)
+ return rtnl_log_create_error(r);
+
+ r = sd_rtnl_message_neigh_set_state(del_req, state);
+ if (r < 0)
+ return rtnl_log_create_error(r);
+
+ /* send delete request to kernel. */
+ r = sd_rtnl_call(rtnl, del_req, 0, NULL);
+ if (r < 0)
+ return r;
+
+ return 0;
+}
+
+
+/* clear FDB entries for current port. */
+int fdb_entries_clear(sd_rtnl *const rtnl,
+ const int ifindex) {
+ _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL, *reply = NULL, *fdb = NULL;
+ int r;
+
+ assert(rtnl);
+
+ /* create new RTM message for getting the FDB table for this port. */
+ r = sd_rtnl_message_new_neigh(rtnl, &req, RTM_GETNEIGH, ifindex, PF_BRIDGE);
+ if (r < 0)
+ return rtnl_log_create_error(r);
+
+ r = sd_rtnl_message_request_dump(req, true);
+ if (r < 0)
+ return rtnl_log_create_error(r);
+
+ /* send GET request to the kernel. */
+ r = sd_rtnl_call(rtnl, req, 0, &reply);
+ if (r < 0) {
+ log_error("Could not send rtnetlink message: %s", strerror(-r));
+ return r;
+ }
+
+ /* look through the returned table and find the entries that match this interface name. */
+ for(fdb = reply; fdb; fdb = sd_rtnl_message_next(fdb)) {
+ int fdb_ifindex;
+
+ /* get ifindex for current entry. */
+ r = sd_rtnl_message_neigh_get_ifindex(fdb, &fdb_ifindex);
+ if (r < 0)
+ return rtnl_log_parse_error(r);
+
+ /* check if the entry is for current interface. If yes, delete it. */
+ if (fdb_ifindex == ifindex) {
+ r = fdb_delete_existing(rtnl, fdb, ifindex);
+ if (r < 0)
+ return r;
+ }
+ }
+
+ /* the FDB entries were succesfully configured for this port. */
+ return 0;
+}
+
+static int set_fdb_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
+ _cleanup_fdbentry_free_ FdbEntry *fdb_entry = userdata;
+ int r;
+
+ assert(fdb_entry);
+
+ r = sd_rtnl_message_get_errno(m);
+ if (r < 0)
+ log_error("Could not add FDB entry for interface: %s error: %s",
+ fdb_entry->network->match_name, strerror(-r));
+
+ return 1;
+}
+
+/* send a request to the kernel to add a FDB entry in its static MAC table. */
+int fdb_entry_configure(sd_rtnl *const rtnl,
+ FdbEntry *const fdb_entry,
+ const int ifindex) {
+ _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL;
+ int r;
+
+ assert(fdb_entry);
+ assert(rtnl);
+
+ /* create new RTM message */
+ r = sd_rtnl_message_new_neigh(rtnl, &req, RTM_NEWNEIGH, ifindex, PF_BRIDGE);
+ if (r < 0)
+ return rtnl_log_create_error(r);
+
+ /* only NTF_SELF flag supported. */
+ r = sd_rtnl_message_neigh_set_flags(req, NTF_SELF);
+ if (r < 0)
+ return rtnl_log_create_error(r);
+
+ /* only NUD_PERMANENT state supported. */
+ r = sd_rtnl_message_neigh_set_state(req, NUD_NOARP | NUD_PERMANENT);
+ if (r < 0)
+ return rtnl_log_create_error(r);
+
+ r = sd_rtnl_message_append_ether_addr(req, NDA_LLADDR, fdb_entry->mac_addr);
+ if (r < 0)
+ return rtnl_log_create_error(r);
+
+ /* VLAN is optional. We'll add VLAN info only if it's specified. */
+ if (0 != fdb_entry->vlan) {
+ r = sd_rtnl_message_append_u16(req, NDA_VLAN, fdb_entry->vlan);
+ if (r < 0)
+ return rtnl_log_create_error(r);
+ }
+
+ /* send message to the kernel to update its internal static MAC table. */
+ r = sd_rtnl_call_async(rtnl, req, set_fdb_handler, fdb_entry, 0, NULL);
+ if (r < 0) {
+ log_error("Could not send rtnetlink message: %s", strerror(-r));
+ return r;
+ }
+
+ return 0;
+}
+
+/* remove and FDB entry. */
+void fdb_entry_free(FdbEntry *fdb_entry) {
+ if(!fdb_entry)
+ return;
+
+ if(fdb_entry->network) {
+ LIST_REMOVE(static_fdb_entries, fdb_entry->network->static_fdb_entries,
+ fdb_entry);
+
+ if(fdb_entry->section)
+ hashmap_remove(fdb_entry->network->fdb_entries_by_section,
+ UINT_TO_PTR(fdb_entry->section));
+ }
+
+ free(fdb_entry->mac_addr);
+
+ free(fdb_entry);
+}
+
+/* parse the HW address from config files. */
+int config_parse_fdb_hwaddr(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) {
+ Network *network = userdata;
+ _cleanup_fdbentry_free_ FdbEntry *fdb_entry = NULL;
+ int r;
+
+ assert(filename);
+ assert(section);
+ assert(lvalue);
+ assert(rvalue);
+ assert(data);
+
+ r = fdb_entry_new_static(network, section_line, &fdb_entry);
+ if (r < 0) {
+ log_error("Failed to allocate a new FDB entry: %s", strerror(-r));
+ return r;
+ }
+
+ /* read in the MAC address for the FDB table. */
+ r = sscanf(rvalue, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
+ &fdb_entry->mac_addr->ether_addr_octet[0],
+ &fdb_entry->mac_addr->ether_addr_octet[1],
+ &fdb_entry->mac_addr->ether_addr_octet[2],
+ &fdb_entry->mac_addr->ether_addr_octet[3],
+ &fdb_entry->mac_addr->ether_addr_octet[4],
+ &fdb_entry->mac_addr->ether_addr_octet[5]);
+
+ if (ETHER_ADDR_LEN != r) {
+ log_syntax(unit, LOG_ERR, filename, line, EINVAL,
+ "Not a valid MAC address, ignoring assignment: %s", rvalue);
+ return 0;
+ }
+
+ fdb_entry = NULL;
+
+ return 0;
+}
+
+/* parse the VLAN from config files. */
+int config_parse_fdb_vlan(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) {
+ Network *network = userdata;
+ _cleanup_fdbentry_free_ FdbEntry *fdb_entry = NULL;
+ int r;
+
+ assert(filename);
+ assert(section);
+ assert(lvalue);
+ assert(rvalue);
+ assert(data);
+
+ r = fdb_entry_new_static(network, section_line, &fdb_entry);
+ if (r < 0) {
+ log_error("Failed to allocate a new FDB entry: %s", strerror(-r));
+ return r;
+ }
+
+ r = config_parse_unsigned(unit, filename, line, section,
+ section_line, lvalue, ltype,
+ rvalue, &fdb_entry->vlan, userdata);
+ if (r < 0) {
+ log_error("Failed to parse the unsigned integer: %s", strerror(-r));
+ return r;
+ }
+
+ fdb_entry = NULL;
+
+ return 0;
+}
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 08f724e..f15d726 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -75,6 +75,16 @@ static bool link_ipv4ll_enabled(Link *link) {
return link->network->ipv4ll;
}
+static bool link_fdb_controlled(Link *link) {
+ if (link->flags & IFF_LOOPBACK)
+ return false;
+
+ if (!link->network)
+ return false;
+
+ return link->network->fdb_controlled;
+}
+
#define FLAG_STRING(string, flag, old, new) \
(((old ^ new) & flag) \
? ((old & flag) ? (" -" string) : (" +" string)) \
@@ -656,6 +666,27 @@ int link_address_drop_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata)
return 1;
}
+static int link_set_fdb_entries(const Link *const link) {
+ FdbEntry *fdb_entry;
+ int r = 0;
+
+ r = fdb_entries_clear(link->manager->rtnl, link->ifindex);
+ if(r < 0) {
+ log_link_error(link, "Failed to clear existing entries: %s", strerror(-r));
+ return r;
+ }
+
+ LIST_FOREACH(static_fdb_entries, fdb_entry, link->network->static_fdb_entries) {
+ r = fdb_entry_configure(link->manager->rtnl, fdb_entry, link->ifindex);
+ if(r < 0) {
+ log_link_error(link, "Failed to add MAC entry to static MAC table: %s", strerror(-r));
+ break;
+ }
+ }
+
+ return r;
+}
+
static int link_set_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
_cleanup_link_unref_ Link *link = userdata;
int r;
@@ -1147,6 +1178,12 @@ static int link_configure(Link *link) {
assert(link->network);
assert(link->state == LINK_STATE_PENDING);
+ if (link_fdb_controlled(link)) {
+ r = link_set_fdb_entries(link);
+ if (r < 0)
+ return r;
+ }
+
if (link_ipv4ll_enabled(link)) {
r = ipv4ll_configure(link);
if (r < 0)
diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf
index bd422e3..ec9b935 100644
--- a/src/network/networkd-network-gperf.gperf
+++ b/src/network/networkd-network-gperf.gperf
@@ -43,6 +43,7 @@ Network.Domains, config_parse_domains, 0,
Network.DNS, config_parse_strv, 0, offsetof(Network, dns)
Network.LLMNR, config_parse_llmnr, 0, offsetof(Network, llmnr)
Network.NTP, config_parse_strv, 0, offsetof(Network, ntp)
+Network.FDBControlled, config_parse_bool, 0, offsetof(Network, fdb_controlled)
Address.Address, config_parse_address, 0, 0
Address.Peer, config_parse_address, 0, 0
Address.Broadcast, config_parse_broadcast, 0, 0
@@ -69,3 +70,5 @@ DHCPv4.UseHostname, config_parse_bool, 0,
DHCP.UseDomainName, config_parse_bool, 0, offsetof(Network, dhcp_domains)
DHCPv4.UseDomainName, config_parse_bool, 0, offsetof(Network, dhcp_domains)
DHCPv4.CriticalConnection, config_parse_bool, 0, offsetof(Network, dhcp_critical)
+FDBEntry.MACAddress, config_parse_fdb_hwaddr, 0, 0
+FDBEntry.VLAN, config_parse_fdb_vlan, 0, 0
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index 075596a..a786639 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -62,6 +62,7 @@ static int network_load_one(Manager *manager, const char *filename) {
LIST_HEAD_INIT(network->static_addresses);
LIST_HEAD_INIT(network->static_routes);
+ LIST_HEAD_INIT(network->static_fdb_entries);
network->stacked_netdevs = hashmap_new(&string_hash_ops);
if (!network->stacked_netdevs)
@@ -75,6 +76,10 @@ static int network_load_one(Manager *manager, const char *filename) {
if (!network->routes_by_section)
return log_oom();
+ network->fdb_entries_by_section = hashmap_new(NULL);
+ if (!network->fdb_entries_by_section)
+ return log_oom();
+
network->filename = strdup(filename);
if (!network->filename)
return log_oom();
@@ -89,6 +94,8 @@ static int network_load_one(Manager *manager, const char *filename) {
network->llmnr = LLMNR_SUPPORT_YES;
+ network->fdb_controlled = false;
+
r = config_parse(NULL, filename, file,
"Match\0"
"Link\0"
@@ -97,6 +104,7 @@ static int network_load_one(Manager *manager, const char *filename) {
"Route\0"
"DHCP\0"
"DHCPv4\0"
+ "FDBEntry\0"
"BridgePort\0",
config_item_perf_lookup, network_network_gperf_lookup,
false, false, true, network);
@@ -154,6 +162,7 @@ void network_free(Network *network) {
NetDev *netdev;
Route *route;
Address *address;
+ FdbEntry *fdb_entry;
Iterator i;
if (!network)
@@ -192,8 +201,12 @@ void network_free(Network *network) {
while ((address = network->static_addresses))
address_free(address);
+ while ((fdb_entry = network->static_fdb_entries))
+ fdb_entry_free(fdb_entry);
+
hashmap_free(network->addresses_by_section);
hashmap_free(network->routes_by_section);
+ hashmap_free(network->fdb_entries_by_section);
if (network->manager && network->manager->networks)
LIST_REMOVE(networks, network->manager->networks, network);
diff --git a/src/network/networkd.h b/src/network/networkd.h
index 4cdcd73..0eddf83 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -51,6 +51,7 @@ typedef struct Address Address;
typedef struct Route Route;
typedef struct Manager Manager;
typedef struct AddressPool AddressPool;
+typedef struct FdbEntry FdbEntry;
typedef enum DHCPSupport {
DHCP_SUPPORT_NONE,
@@ -69,6 +70,16 @@ typedef enum LLMNRSupport {
_LLMNR_SUPPORT_INVALID = -1,
} LLMNRSupport;
+struct FdbEntry {
+ Network *network;
+ unsigned section;
+
+ struct ether_addr *mac_addr;
+ uint16_t vlan;
+
+ LIST_FIELDS(FdbEntry, static_fdb_entries);
+};
+
struct Network {
Manager *manager;
@@ -106,6 +117,8 @@ struct Network {
bool dhcp_server;
+ bool fdb_controlled;
+
unsigned cost;
struct ether_addr *mac;
@@ -113,9 +126,11 @@ struct Network {
LIST_HEAD(Address, static_addresses);
LIST_HEAD(Route, static_routes);
+ LIST_HEAD(FdbEntry, static_fdb_entries);
Hashmap *addresses_by_section;
Hashmap *routes_by_section;
+ Hashmap *fdb_entries_by_section;
bool wildcard_domain;
char **domains, **dns, **ntp;
@@ -327,6 +342,23 @@ int config_parse_label(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);
+/* Forwarding database table. */
+int fdb_entry_configure(sd_rtnl *const rtnl, FdbEntry *const fdb_entry, const int ifindex);
+void fdb_entry_free(FdbEntry *fdb_entry);
+int fdb_entry_new_static(Network *const network, const unsigned section, FdbEntry **ret);
+int fdb_entries_clear(sd_rtnl *const rtnl, const int ifindex);
+
+DEFINE_TRIVIAL_CLEANUP_FUNC(FdbEntry*, fdb_entry_free);
+#define _cleanup_fdbentry_free_ _cleanup_(fdb_entry_freep)
+
+int config_parse_fdb_hwaddr(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);
+
+int config_parse_fdb_vlan(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);
+
/* DHCP support */
const char* dhcp_support_to_string(DHCPSupport i) _const_;
diff --git a/src/systemd/sd-rtnl.h b/src/systemd/sd-rtnl.h
index b05f83c..b8836e2 100644
--- a/src/systemd/sd-rtnl.h
+++ b/src/systemd/sd-rtnl.h
@@ -109,8 +109,12 @@ int sd_rtnl_message_route_get_family(sd_rtnl_message *m, int *family);
int sd_rtnl_message_route_get_dst_prefixlen(sd_rtnl_message *m, unsigned char *dst_len);
int sd_rtnl_message_route_get_src_prefixlen(sd_rtnl_message *m, unsigned char *src_len);
+int sd_rtnl_message_neigh_set_flags(sd_rtnl_message *m, uint8_t flags);
+int sd_rtnl_message_neigh_set_state(sd_rtnl_message *m, uint16_t state);
int sd_rtnl_message_neigh_get_family(sd_rtnl_message *m, int *family);
int sd_rtnl_message_neigh_get_ifindex(sd_rtnl_message *m, int *family);
+int sd_rtnl_message_neigh_get_state(sd_rtnl_message *m, uint16_t *state);
+int sd_rtnl_message_neigh_get_flags(sd_rtnl_message *m, uint8_t *flags);
int sd_rtnl_message_append_string(sd_rtnl_message *m, unsigned short type, const char *data);
int sd_rtnl_message_append_u8(sd_rtnl_message *m, unsigned short type, uint8_t data);
--
1.9.3
More information about the systemd-devel
mailing list