diff options
Diffstat (limited to 'src/network/networkd-bridge-fdb.c')
-rw-r--r-- | src/network/networkd-bridge-fdb.c | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/src/network/networkd-bridge-fdb.c b/src/network/networkd-bridge-fdb.c index 1298727a72..a0024f62d4 100644 --- a/src/network/networkd-bridge-fdb.c +++ b/src/network/networkd-bridge-fdb.c @@ -121,68 +121,51 @@ static int bridge_fdb_configure_handler(sd_netlink *rtnl, sd_netlink_message *m, } /* send a request to the kernel to add a FDB entry in its static MAC table. */ -static int bridge_fdb_configure(const BridgeFDB *fdb, Link *link, link_netlink_message_handler_t callback) { - _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL; +static int bridge_fdb_configure_message(const BridgeFDB *fdb, Link *link, sd_netlink_message *req) { int r; assert(fdb); assert(link); - assert(link->manager); - assert(link->manager->rtnl); - assert(callback); - - /* create new RTM message */ - r = sd_rtnl_message_new_neigh(link->manager->rtnl, &req, RTM_NEWNEIGH, link->ifindex, AF_BRIDGE); - if (r < 0) - return log_link_error_errno(link, r, "Could not create RTM_NEWNEIGH message: %m"); r = sd_rtnl_message_neigh_set_flags(req, fdb->ntf_flags); if (r < 0) - return log_link_error_errno(link, r, "Could not set neighbor flags: %m"); + return r; /* only NUD_PERMANENT state supported. */ r = sd_rtnl_message_neigh_set_state(req, NUD_NOARP | NUD_PERMANENT); if (r < 0) - return log_link_error_errno(link, r, "Could not set neighbor state: %m"); + return r; r = sd_netlink_message_append_data(req, NDA_LLADDR, &fdb->mac_addr, sizeof(fdb->mac_addr)); if (r < 0) - return log_link_error_errno(link, r, "Could not append NDA_LLADDR attribute: %m"); + return r; /* VLAN Id is optional. We'll add VLAN Id only if it's specified. */ if (fdb->vlan_id > 0) { r = sd_netlink_message_append_u16(req, NDA_VLAN, fdb->vlan_id); if (r < 0) - return log_link_error_errno(link, r, "Could not append NDA_VLAN attribute: %m"); + return r; } if (fdb->outgoing_ifindex > 0) { r = sd_netlink_message_append_u32(req, NDA_IFINDEX, fdb->outgoing_ifindex); if (r < 0) - return log_link_error_errno(link, r, "Could not append NDA_IFINDEX attribute: %m"); + return r; } if (in_addr_is_set(fdb->family, &fdb->destination_addr)) { r = netlink_message_append_in_addr_union(req, NDA_DST, fdb->family, &fdb->destination_addr); if (r < 0) - return log_link_error_errno(link, r, "Could not append NDA_DST attribute: %m"); + return r; } if (fdb->vni <= VXLAN_VID_MAX) { r = sd_netlink_message_append_u32(req, NDA_VNI, fdb->vni); if (r < 0) - return log_link_error_errno(link, r, "Could not append NDA_VNI attribute: %m"); + return r; } - /* send message to the kernel to update its internal static MAC table. */ - r = netlink_call_async(link->manager->rtnl, NULL, req, callback, - 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 1; + return 0; } int link_request_static_bridge_fdb(Link *link) { @@ -238,15 +221,36 @@ static bool bridge_fdb_is_ready_to_configure(BridgeFDB *fdb, Link *link) { } int request_process_bridge_fdb(Request *req) { + Link *link; + int r; + assert(req); - assert(req->link); assert(req->fdb); assert(req->type == REQUEST_TYPE_BRIDGE_FDB); + assert_se(link = req->link); - if (!bridge_fdb_is_ready_to_configure(req->fdb, req->link)) + if (!bridge_fdb_is_ready_to_configure(req->fdb, link)) return 0; - return bridge_fdb_configure(req->fdb, req->link, req->netlink_handler); + /* create new RTM message */ + _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL; + r = sd_rtnl_message_new_neigh(link->manager->rtnl, &m, RTM_NEWNEIGH, link->ifindex, AF_BRIDGE); + if (r < 0) + return log_link_error_errno(link, r, "Could not allocate netlink message: %m"); + + r = bridge_fdb_configure_message(req->fdb, link, m); + if (r < 0) + return log_link_error_errno(link, r, "Could not create netlink message: %m"); + + /* send message to the kernel to update its internal static MAC table. */ + r = netlink_call_async(link->manager->rtnl, NULL, m, req->netlink_handler, + link_netlink_destroy_callback, link); + if (r < 0) + return log_link_error_errno(link, r, "Could not send netlink message: %m"); + + link_ref(link); + + return 1; } void network_drop_invalid_bridge_fdb_entries(Network *network) { |