1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-31 16:21:26 +03:00

network: rename MdbEntry -> BridgeMDB

This commit is contained in:
Yu Watanabe 2021-05-18 05:09:59 +09:00
parent 9373f5a812
commit ff9e07838d
8 changed files with 89 additions and 89 deletions

View File

@ -59,6 +59,8 @@ sources = files('''
networkd-address.h
networkd-bridge-fdb.c
networkd-bridge-fdb.h
networkd-bridge-mdb.c
networkd-bridge-mdb.h
networkd-brvlan.c
networkd-brvlan.h
networkd-can.c
@ -95,8 +97,6 @@ sources = files('''
networkd-manager-bus.h
networkd-manager.c
networkd-manager.h
networkd-mdb.c
networkd-mdb.h
networkd-ndisc.c
networkd-ndisc.h
networkd-neighbor.c

View File

@ -3,41 +3,41 @@
#include <net/if.h>
#include "netlink-util.h"
#include "networkd-bridge-mdb.h"
#include "networkd-link.h"
#include "networkd-manager.h"
#include "networkd-mdb.h"
#include "networkd-network.h"
#include "string-util.h"
#include "vlan-util.h"
#define STATIC_MDB_ENTRIES_PER_NETWORK_MAX 1024U
#define STATIC_BRIDGE_MDB_ENTRIES_PER_NETWORK_MAX 1024U
/* remove MDB entry. */
MdbEntry *mdb_entry_free(MdbEntry *mdb_entry) {
if (!mdb_entry)
BridgeMDB *bridge_mdb_free(BridgeMDB *mdb) {
if (!mdb)
return NULL;
if (mdb_entry->network) {
assert(mdb_entry->section);
hashmap_remove(mdb_entry->network->mdb_entries_by_section, mdb_entry->section);
if (mdb->network) {
assert(mdb->section);
hashmap_remove(mdb->network->bridge_mdb_entries_by_section, mdb->section);
}
network_config_section_free(mdb_entry->section);
network_config_section_free(mdb->section);
return mfree(mdb_entry);
return mfree(mdb);
}
DEFINE_NETWORK_SECTION_FUNCTIONS(MdbEntry, mdb_entry_free);
DEFINE_NETWORK_SECTION_FUNCTIONS(BridgeMDB, bridge_mdb_free);
/* create a new MDB entry or get an existing one. */
static int mdb_entry_new_static(
static int bridge_mdb_new_static(
Network *network,
const char *filename,
unsigned section_line,
MdbEntry **ret) {
BridgeMDB **ret) {
_cleanup_(network_config_section_freep) NetworkConfigSection *n = NULL;
_cleanup_(mdb_entry_freep) MdbEntry *mdb_entry = NULL;
_cleanup_(bridge_mdb_freep) BridgeMDB *mdb = NULL;
int r;
assert(network);
@ -50,32 +50,32 @@ static int mdb_entry_new_static(
return r;
/* search entry in hashmap first. */
mdb_entry = hashmap_get(network->mdb_entries_by_section, n);
if (mdb_entry) {
*ret = TAKE_PTR(mdb_entry);
mdb = hashmap_get(network->bridge_mdb_entries_by_section, n);
if (mdb) {
*ret = TAKE_PTR(mdb);
return 0;
}
if (hashmap_size(network->mdb_entries_by_section) >= STATIC_MDB_ENTRIES_PER_NETWORK_MAX)
if (hashmap_size(network->bridge_mdb_entries_by_section) >= STATIC_BRIDGE_MDB_ENTRIES_PER_NETWORK_MAX)
return -E2BIG;
/* allocate space for an MDB entry. */
mdb_entry = new(MdbEntry, 1);
if (!mdb_entry)
mdb = new(BridgeMDB, 1);
if (!mdb)
return -ENOMEM;
/* init MDB structure. */
*mdb_entry = (MdbEntry) {
*mdb = (BridgeMDB) {
.network = network,
.section = TAKE_PTR(n),
};
r = hashmap_ensure_put(&network->mdb_entries_by_section, &network_config_hash_ops, mdb_entry->section, mdb_entry);
r = hashmap_ensure_put(&network->bridge_mdb_entries_by_section, &network_config_hash_ops, mdb->section, mdb);
if (r < 0)
return r;
/* return allocated MDB structure. */
*ret = TAKE_PTR(mdb_entry);
*ret = TAKE_PTR(mdb);
return 0;
}
@ -83,9 +83,9 @@ static int set_mdb_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link)
int r;
assert(link);
assert(link->bridge_mdb_messages > 0);
assert(link->static_bridge_mdb_messages > 0);
link->bridge_mdb_messages--;
link->static_bridge_mdb_messages--;
if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
return 1;
@ -103,8 +103,8 @@ static int set_mdb_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link)
return 1;
}
if (link->bridge_mdb_messages == 0) {
link->bridge_mdb_configured = true;
if (link->static_bridge_mdb_messages == 0) {
link->static_bridge_mdb_configured = true;
link_check_ready(link);
}
@ -124,7 +124,7 @@ static int link_get_bridge_master_ifindex(Link *link) {
}
/* send a request to the kernel to add an MDB entry */
static int mdb_entry_configure(Link *link, MdbEntry *mdb_entry) {
static int bridge_mdb_configure(Link *link, BridgeMDB *mdb) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
struct br_mdb_entry entry;
int master, r;
@ -132,14 +132,14 @@ static int mdb_entry_configure(Link *link, MdbEntry *mdb_entry) {
assert(link);
assert(link->network);
assert(link->manager);
assert(mdb_entry);
assert(mdb);
if (DEBUG_LOGGING) {
_cleanup_free_ char *a = NULL;
(void) in_addr_to_string(mdb_entry->family, &mdb_entry->group_addr, &a);
(void) in_addr_to_string(mdb->family, &mdb->group_addr, &a);
log_link_debug(link, "Configuring bridge MDB entry: MulticastGroupAddress=%s, VLANId=%u",
strna(a), mdb_entry->vlan_id);
strna(a), mdb->vlan_id);
}
master = link_get_bridge_master_ifindex(link);
@ -151,7 +151,7 @@ static int mdb_entry_configure(Link *link, MdbEntry *mdb_entry) {
* See br_mdb_add_group() in net/bridge/br_mdb.c of kernel. */
.state = master == link->ifindex ? MDB_TEMPORARY : MDB_PERMANENT,
.ifindex = link->ifindex,
.vid = mdb_entry->vlan_id,
.vid = mdb->vlan_id,
};
/* create new RTM message */
@ -159,14 +159,14 @@ static int mdb_entry_configure(Link *link, MdbEntry *mdb_entry) {
if (r < 0)
return log_link_error_errno(link, r, "Could not create RTM_NEWMDB message: %m");
switch (mdb_entry->family) {
switch (mdb->family) {
case AF_INET:
entry.addr.u.ip4 = mdb_entry->group_addr.in.s_addr;
entry.addr.u.ip4 = mdb->group_addr.in.s_addr;
entry.addr.proto = htobe16(ETH_P_IP);
break;
case AF_INET6:
entry.addr.u.ip6 = mdb_entry->group_addr.in6;
entry.addr.u.ip6 = mdb->group_addr.in6;
entry.addr.proto = htobe16(ETH_P_IPV6);
break;
@ -189,23 +189,23 @@ static int mdb_entry_configure(Link *link, MdbEntry *mdb_entry) {
}
int link_set_bridge_mdb(Link *link) {
MdbEntry *mdb_entry;
BridgeMDB *mdb;
int r;
assert(link);
assert(link->manager);
if (link->bridge_mdb_messages != 0) {
if (link->static_bridge_mdb_messages != 0) {
log_link_debug(link, "MDB entries are configuring.");
return 0;
}
link->bridge_mdb_configured = false;
link->static_bridge_mdb_configured = false;
if (!link->network)
return 0;
if (hashmap_isempty(link->network->mdb_entries_by_section))
if (hashmap_isempty(link->network->bridge_mdb_entries_by_section))
goto finish;
if (!link_has_carrier(link)) {
@ -233,64 +233,64 @@ int link_set_bridge_mdb(Link *link) {
goto finish;
}
HASHMAP_FOREACH(mdb_entry, link->network->mdb_entries_by_section) {
r = mdb_entry_configure(link, mdb_entry);
HASHMAP_FOREACH(mdb, link->network->bridge_mdb_entries_by_section) {
r = bridge_mdb_configure(link, mdb);
if (r < 0)
return log_link_error_errno(link, r, "Failed to add MDB entry to multicast group database: %m");
link->bridge_mdb_messages++;
link->static_bridge_mdb_messages++;
}
finish:
if (link->bridge_mdb_messages == 0) {
link->bridge_mdb_configured = true;
if (link->static_bridge_mdb_messages == 0) {
link->static_bridge_mdb_configured = true;
link_check_ready(link);
}
return 0;
}
static int mdb_entry_verify(MdbEntry *mdb_entry) {
if (section_is_invalid(mdb_entry->section))
static int bridge_mdb_verify(BridgeMDB *mdb) {
if (section_is_invalid(mdb->section))
return -EINVAL;
if (mdb_entry->family == AF_UNSPEC)
if (mdb->family == AF_UNSPEC)
return log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
"%s: [BridgeMDB] section without MulticastGroupAddress= field configured. "
"Ignoring [BridgeMDB] section from line %u.",
mdb_entry->section->filename, mdb_entry->section->line);
mdb->section->filename, mdb->section->line);
if (!in_addr_is_multicast(mdb_entry->family, &mdb_entry->group_addr))
if (!in_addr_is_multicast(mdb->family, &mdb->group_addr))
return log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
"%s: MulticastGroupAddress= is not a multicast address. "
"Ignoring [BridgeMDB] section from line %u.",
mdb_entry->section->filename, mdb_entry->section->line);
mdb->section->filename, mdb->section->line);
if (mdb_entry->family == AF_INET) {
if (in4_addr_is_local_multicast(&mdb_entry->group_addr.in))
if (mdb->family == AF_INET) {
if (in4_addr_is_local_multicast(&mdb->group_addr.in))
return log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
"%s: MulticastGroupAddress= is a local multicast address. "
"Ignoring [BridgeMDB] section from line %u.",
mdb_entry->section->filename, mdb_entry->section->line);
mdb->section->filename, mdb->section->line);
} else {
if (in6_addr_is_link_local_all_nodes(&mdb_entry->group_addr.in6))
if (in6_addr_is_link_local_all_nodes(&mdb->group_addr.in6))
return log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
"%s: MulticastGroupAddress= is the multicast all nodes address. "
"Ignoring [BridgeMDB] section from line %u.",
mdb_entry->section->filename, mdb_entry->section->line);
mdb->section->filename, mdb->section->line);
}
return 0;
}
void network_drop_invalid_mdb_entries(Network *network) {
MdbEntry *mdb_entry;
void network_drop_invalid_bridge_mdb_entries(Network *network) {
BridgeMDB *mdb;
assert(network);
HASHMAP_FOREACH(mdb_entry, network->mdb_entries_by_section)
if (mdb_entry_verify(mdb_entry) < 0)
mdb_entry_free(mdb_entry);
HASHMAP_FOREACH(mdb, network->bridge_mdb_entries_by_section)
if (bridge_mdb_verify(mdb) < 0)
bridge_mdb_free(mdb);
}
/* parse the VLAN Id from config files. */
@ -306,7 +306,7 @@ int config_parse_mdb_vlan_id(
void *data,
void *userdata) {
_cleanup_(mdb_entry_free_or_set_invalidp) MdbEntry *mdb_entry = NULL;
_cleanup_(bridge_mdb_free_or_set_invalidp) BridgeMDB *mdb = NULL;
Network *network = userdata;
int r;
@ -316,17 +316,17 @@ int config_parse_mdb_vlan_id(
assert(rvalue);
assert(data);
r = mdb_entry_new_static(network, filename, section_line, &mdb_entry);
r = bridge_mdb_new_static(network, filename, section_line, &mdb);
if (r < 0)
return log_oom();
r = config_parse_vlanid(unit, filename, line, section,
section_line, lvalue, ltype,
rvalue, &mdb_entry->vlan_id, userdata);
rvalue, &mdb->vlan_id, userdata);
if (r < 0)
return r;
TAKE_PTR(mdb_entry);
TAKE_PTR(mdb);
return 0;
}
@ -343,7 +343,7 @@ int config_parse_mdb_group_address(
void *data,
void *userdata) {
_cleanup_(mdb_entry_free_or_set_invalidp) MdbEntry *mdb_entry = NULL;
_cleanup_(bridge_mdb_free_or_set_invalidp) BridgeMDB *mdb = NULL;
Network *network = userdata;
int r;
@ -353,16 +353,16 @@ int config_parse_mdb_group_address(
assert(rvalue);
assert(data);
r = mdb_entry_new_static(network, filename, section_line, &mdb_entry);
r = bridge_mdb_new_static(network, filename, section_line, &mdb);
if (r < 0)
return log_oom();
r = in_addr_from_string_auto(rvalue, &mdb_entry->family, &mdb_entry->group_addr);
r = in_addr_from_string_auto(rvalue, &mdb->family, &mdb->group_addr);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r, "Cannot parse multicast group address: %m");
return 0;
}
TAKE_PTR(mdb_entry);
TAKE_PTR(mdb);
return 0;
}

View File

@ -7,21 +7,21 @@
#include "in-addr-util.h"
#include "networkd-util.h"
typedef struct Network Network;
typedef struct Link Link;
typedef struct Network Network;
typedef struct MdbEntry {
typedef struct BridgeMDB {
Network *network;
NetworkConfigSection *section;
int family;
union in_addr_union group_addr;
uint16_t vlan_id;
} MdbEntry;
} BridgeMDB;
MdbEntry *mdb_entry_free(MdbEntry *mdb_entry);
BridgeMDB *bridge_mdb_free(BridgeMDB *mdb);
void network_drop_invalid_mdb_entries(Network *network);
void network_drop_invalid_bridge_mdb_entries(Network *network);
int link_set_bridge_mdb(Link *link);

View File

@ -28,6 +28,7 @@
#include "networkd-address-label.h"
#include "networkd-address.h"
#include "networkd-bridge-fdb.h"
#include "networkd-bridge-mdb.h"
#include "networkd-can.h"
#include "networkd-dhcp-server.h"
#include "networkd-dhcp4.h"
@ -38,7 +39,6 @@
#include "networkd-link.h"
#include "networkd-lldp-tx.h"
#include "networkd-manager.h"
#include "networkd-mdb.h"
#include "networkd-ndisc.h"
#include "networkd-neighbor.h"
#include "networkd-nexthop.h"
@ -753,6 +753,9 @@ void link_check_ready(Link *link) {
if (!link->static_bridge_fdb_configured)
return (void) log_link_debug(link, "%s(): static bridge MDB entries are not configured.", __func__);
if (!link->static_bridge_mdb_configured)
return (void) log_link_debug(link, "%s(): static bridge MDB entries are not configured.", __func__);
if (!link->static_neighbors_configured)
return (void) log_link_debug(link, "%s(): static neighbors are not configured.", __func__);
@ -771,9 +774,6 @@ void link_check_ready(Link *link) {
if (!link->sr_iov_configured)
return (void) log_link_debug(link, "%s(): SR-IOV is not configured.", __func__);
if (!link->bridge_mdb_configured)
return (void) log_link_debug(link, "%s(): Bridge MDB is not configured.", __func__);
if (link_has_carrier(link) || !link->network->configure_without_carrier) {
bool has_ndisc_address = false;
NDiscAddress *n;
@ -2806,7 +2806,7 @@ static int link_carrier_gained(Link *link) {
if (r < 0)
return r;
if (!link->bridge_mdb_configured) {
if (!link->static_bridge_mdb_configured) {
r = link_set_bridge_mdb(link);
if (r < 0)
return r;
@ -2816,7 +2816,7 @@ static int link_carrier_gained(Link *link) {
Link *slave;
SET_FOREACH(slave, link->slaves) {
if (slave->bridge_mdb_configured)
if (slave->static_bridge_mdb_configured)
continue;
r = link_set_bridge_mdb(slave);

View File

@ -82,6 +82,7 @@ typedef struct Link {
unsigned address_label_messages;
unsigned static_address_messages;
unsigned static_bridge_fdb_messages;
unsigned static_bridge_mdb_messages;
unsigned static_neighbor_messages;
unsigned static_nexthop_messages;
unsigned static_route_messages;
@ -93,7 +94,6 @@ typedef struct Link {
unsigned tc_messages;
unsigned sr_iov_messages;
unsigned enslaving;
unsigned bridge_mdb_messages;
Set *addresses;
Set *addresses_foreign;
@ -124,6 +124,7 @@ typedef struct Link {
bool static_addresses_configured:1;
bool static_bridge_fdb_configured:1;
bool static_bridge_mdb_configured:1;
bool static_neighbors_configured:1;
bool static_nexthops_configured:1;
bool static_routes_configured:1;
@ -133,7 +134,6 @@ typedef struct Link {
bool setting_mtu:1;
bool setting_genmode:1;
bool ipv6_mtu_set:1;
bool bridge_mdb_configured:1;
bool can_configured:1;
bool activated:1;

View File

@ -10,6 +10,7 @@ _Pragma("GCC diagnostic ignored \"-Wimplicit-fallthrough\"")
#include "networkd-address-label.h"
#include "networkd-address.h"
#include "networkd-bridge-fdb.h"
#include "networkd-bridge-mdb.h"
#include "networkd-can.h"
#include "networkd-dhcp-common.h"
#include "networkd-dhcp-server-static-lease.h"
@ -18,7 +19,6 @@ _Pragma("GCC diagnostic ignored \"-Wimplicit-fallthrough\"")
#include "networkd-dhcp6.h"
#include "networkd-ipv4ll.h"
#include "networkd-ipv6-proxy-ndp.h"
#include "networkd-mdb.h"
#include "networkd-ndisc.h"
#include "networkd-network.h"
#include "networkd-neighbor.h"

View File

@ -16,11 +16,11 @@
#include "networkd-address-label.h"
#include "networkd-address.h"
#include "networkd-bridge-fdb.h"
#include "networkd-bridge-mdb.h"
#include "networkd-dhcp-common.h"
#include "networkd-dhcp-server-static-lease.h"
#include "networkd-dhcp-server.h"
#include "networkd-manager.h"
#include "networkd-mdb.h"
#include "networkd-ndisc.h"
#include "networkd-neighbor.h"
#include "networkd-network.h"
@ -234,7 +234,7 @@ int network_verify(Network *network) {
network_drop_invalid_routes(network);
network_drop_invalid_nexthops(network);
network_drop_invalid_bridge_fdb_entries(network);
network_drop_invalid_mdb_entries(network);
network_drop_invalid_bridge_mdb_entries(network);
network_drop_invalid_neighbors(network);
network_drop_invalid_address_labels(network);
network_drop_invalid_prefixes(network);
@ -604,7 +604,7 @@ static Network *network_free(Network *network) {
hashmap_free_with_destructor(network->routes_by_section, route_free);
hashmap_free_with_destructor(network->nexthops_by_section, nexthop_free);
hashmap_free_with_destructor(network->bridge_fdb_entries_by_section, bridge_fdb_free);
hashmap_free_with_destructor(network->mdb_entries_by_section, mdb_entry_free);
hashmap_free_with_destructor(network->bridge_mdb_entries_by_section, bridge_mdb_free);
hashmap_free_with_destructor(network->neighbors_by_section, neighbor_free);
hashmap_free_with_destructor(network->address_labels_by_section, address_label_free);
hashmap_free_with_destructor(network->prefixes_by_section, prefix_free);
@ -659,7 +659,7 @@ bool network_has_static_ipv6_configurations(Network *network) {
Address *address;
Route *route;
BridgeFDB *fdb;
MdbEntry *mdb;
BridgeMDB *mdb;
Neighbor *neighbor;
assert(network);
@ -676,7 +676,7 @@ bool network_has_static_ipv6_configurations(Network *network) {
if (fdb->family == AF_INET6)
return true;
HASHMAP_FOREACH(mdb, network->mdb_entries_by_section)
HASHMAP_FOREACH(mdb, network->bridge_mdb_entries_by_section)
if (mdb->family == AF_INET6)
return true;

View File

@ -310,7 +310,7 @@ struct Network {
Hashmap *routes_by_section;
Hashmap *nexthops_by_section;
Hashmap *bridge_fdb_entries_by_section;
Hashmap *mdb_entries_by_section;
Hashmap *bridge_mdb_entries_by_section;
Hashmap *neighbors_by_section;
Hashmap *address_labels_by_section;
Hashmap *prefixes_by_section;