summaryrefslogtreecommitdiff
path: root/src/network/networkd-fdb.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2018-12-21 22:06:22 +0100
committerMichael Biebl <biebl@debian.org>2018-12-21 22:06:22 +0100
commit6e866b331d7cd4a5e0759dd160dea6edabd3678e (patch)
tree4d24c1ffe4ae946f04d8910956090e8d13aecd9a /src/network/networkd-fdb.c
parentb012e92123bdc9fa10c2f079ec5bd9313b23e21a (diff)
downloadsystemd-6e866b331d7cd4a5e0759dd160dea6edabd3678e.tar.gz
New upstream version 240
Diffstat (limited to 'src/network/networkd-fdb.c')
-rw-r--r--src/network/networkd-fdb.c62
1 files changed, 38 insertions, 24 deletions
diff --git a/src/network/networkd-fdb.c b/src/network/networkd-fdb.c
index 11f70723a9..324f6a5a1a 100644
--- a/src/network/networkd-fdb.c
+++ b/src/network/networkd-fdb.c
@@ -20,18 +20,26 @@
/* create a new FDB entry or get an existing one. */
int fdb_entry_new_static(
Network *network,
- unsigned section,
+ const char *filename,
+ unsigned section_line,
FdbEntry **ret) {
+ _cleanup_(network_config_section_freep) NetworkConfigSection *n = NULL;
_cleanup_(fdb_entry_freep) FdbEntry *fdb_entry = NULL;
- struct ether_addr *mac_addr = NULL;
+ _cleanup_free_ struct ether_addr *mac_addr = NULL;
+ int r;
assert(network);
assert(ret);
+ assert(!!filename == (section_line > 0));
/* search entry in hashmap first. */
- if (section) {
- fdb_entry = hashmap_get(network->fdb_entries_by_section, UINT_TO_PTR(section));
+ if (filename) {
+ r = network_config_section_new(filename, section_line, &n);
+ if (r < 0)
+ return r;
+
+ fdb_entry = hashmap_get(network->fdb_entries_by_section, n);
if (fdb_entry) {
*ret = TAKE_PTR(fdb_entry);
@@ -48,24 +56,29 @@ int fdb_entry_new_static(
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);
+ fdb_entry = new(FdbEntry, 1);
+ if (!fdb_entry)
return -ENOMEM;
- }
/* init FDB structure. */
- fdb_entry->network = network;
- fdb_entry->mac_addr = mac_addr;
+ *fdb_entry = (FdbEntry) {
+ .network = network,
+ .mac_addr = TAKE_PTR(mac_addr),
+ };
LIST_PREPEND(static_fdb_entries, network->static_fdb_entries, fdb_entry);
network->n_static_fdb_entries++;
- if (section) {
- fdb_entry->section = section;
- hashmap_put(network->fdb_entries_by_section,
- UINT_TO_PTR(fdb_entry->section), fdb_entry);
+ if (filename) {
+ fdb_entry->section = TAKE_PTR(n);
+
+ r = hashmap_ensure_allocated(&network->fdb_entries_by_section, &network_config_hash_ops);
+ if (r < 0)
+ return r;
+
+ r = hashmap_put(network->fdb_entries_by_section, fdb_entry->section, fdb_entry);
+ if (r < 0)
+ return r;
}
/* return allocated FDB structure. */
@@ -74,8 +87,7 @@ int fdb_entry_new_static(
return 0;
}
-static int set_fdb_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
- Link *link = userdata;
+static int set_fdb_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r;
assert(link);
@@ -134,10 +146,13 @@ int fdb_entry_configure(Link *link, FdbEntry *fdb_entry) {
}
/* send message to the kernel to update its internal static MAC table. */
- r = sd_netlink_call_async(rtnl, req, set_fdb_handler, link, 0, NULL);
+ r = netlink_call_async(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");
+ link_ref(link);
+
return 0;
}
@@ -148,16 +163,15 @@ void fdb_entry_free(FdbEntry *fdb_entry) {
if (fdb_entry->network) {
LIST_REMOVE(static_fdb_entries, fdb_entry->network->static_fdb_entries, fdb_entry);
-
assert(fdb_entry->network->n_static_fdb_entries > 0);
fdb_entry->network->n_static_fdb_entries--;
if (fdb_entry->section)
- hashmap_remove(fdb_entry->network->fdb_entries_by_section, UINT_TO_PTR(fdb_entry->section));
+ hashmap_remove(fdb_entry->network->fdb_entries_by_section, fdb_entry->section);
}
+ network_config_section_free(fdb_entry->section);
free(fdb_entry->mac_addr);
-
free(fdb_entry);
}
@@ -184,7 +198,7 @@ int config_parse_fdb_hwaddr(
assert(rvalue);
assert(data);
- r = fdb_entry_new_static(network, section_line, &fdb_entry);
+ r = fdb_entry_new_static(network, filename, section_line, &fdb_entry);
if (r < 0)
return log_oom();
@@ -197,7 +211,7 @@ int config_parse_fdb_hwaddr(
&fdb_entry->mac_addr->ether_addr_octet[4],
&fdb_entry->mac_addr->ether_addr_octet[5]);
- if (ETHER_ADDR_LEN != r) {
+ if (r != ETHER_ADDR_LEN) {
log_syntax(unit, LOG_ERR, filename, line, 0, "Not a valid MAC address, ignoring assignment: %s", rvalue);
return 0;
}
@@ -230,7 +244,7 @@ int config_parse_fdb_vlan_id(
assert(rvalue);
assert(data);
- r = fdb_entry_new_static(network, section_line, &fdb_entry);
+ r = fdb_entry_new_static(network, filename, section_line, &fdb_entry);
if (r < 0)
return log_oom();