From c5dd20250b74aa0d84b0280df034fc69b273709f Mon Sep 17 00:00:00 2001 From: Steven Luong Date: Mon, 5 Aug 2019 09:47:58 -0700 Subject: bonding lacp: deleting virtual interface which was enslaved may cause crash Virtual interfaces may be part of the bonding like physical interfaces. The difference is virtual interfaces may disappear dynamically. As an example, the following CLI sequence may crash the debug image create vhost-user socket /tmp/sock1 create bond mode lacp bond add BondEthernet0 VirtualEthernet0/0/0 delete vhost-user VirtualEhernet0/0/0 Notice the virtual interface is deleted without first doing bond delete. The proper order is to first remove the slave interface from the bond prior to deleting the virtual interface as shown below. But we should handle it anyway. create vhost-user socket /tmp/sock1 create bond mode lacp bond add BondEthernet0 VirtualEthernet0/0/0 bond del VirtualEthernet0/0/0 <----- delete vhost-user VirtualEhernet0/0/0 The fix is to register for VNET_SW_INTERFACE_ADD_DEL_FUNCTION and remove the slave interface from the bond if the to-be-deleted interface is part of the bond. We check the interface that it is actually up before we send the lacp pdu. Up means both hw and sw admin up. Type: fix Signed-off-by: Steven Luong Change-Id: If4d2da074338b16aab0df54e00d719e55c45221a (cherry picked from commit bac326cb7c5f8856786ca046df8cfa3be9f53926) --- src/plugins/lacp/cli.c | 7 ++++--- src/plugins/lacp/lacp.c | 40 +++++++++++++++++++++++----------------- 2 files changed, 27 insertions(+), 20 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/lacp/cli.c b/src/plugins/lacp/cli.c index b8ff199c2f4..92a890d2e37 100644 --- a/src/plugins/lacp/cli.c +++ b/src/plugins/lacp/cli.c @@ -30,7 +30,7 @@ lacp_dump_ifs (lacp_interface_details_t ** out_lacpifs) /* *INDENT-OFF* */ pool_foreach (sif, bm->neighbors, - if ((sif->port_enabled == 0) || (sif->lacp_enabled == 0)) + if (sif->lacp_enabled == 0) continue; vec_add2(r_lacpifs, lacpif, 1); clib_memset (lacpif, 0, sizeof (*lacpif)); @@ -88,7 +88,7 @@ show_lacp (vlib_main_t * vm, u32 * sw_if_indices) for (i = 0; i < vec_len (sw_if_indices); i++) { sif = bond_get_slave_by_sw_if_index (sw_if_indices[i]); - if (!sif || (sif->port_enabled == 0) || (sif->lacp_enabled == 0)) + if (!sif || (sif->lacp_enabled == 0)) continue; bif = bond_get_master_by_dev_instance (sif->bif_dev_instance); vlib_cli_output (vm, @@ -157,7 +157,7 @@ show_lacp_details (vlib_main_t * vm, u32 * sw_if_indices) for (i = 0; i < vec_len (sw_if_indices); i++) { sif = bond_get_slave_by_sw_if_index (sw_if_indices[i]); - if (!sif || (sif->port_enabled == 0) || (sif->lacp_enabled == 0)) + if (!sif || (sif->lacp_enabled == 0)) continue; vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name, vnet_get_main (), sif->sw_if_index); @@ -186,6 +186,7 @@ show_lacp_details (vlib_main_t * vm, u32 * sw_if_indices) now - sif->last_marker_pdu_sent_time); vlib_cli_output (vm, " debug: %d", sif->debug); vlib_cli_output (vm, " loopback port: %d", sif->loopback_port); + vlib_cli_output (vm, " port_enabled: %d", sif->port_enabled); vlib_cli_output (vm, " port moved: %d", sif->port_moved); vlib_cli_output (vm, " ready_n: %d", sif->ready_n); vlib_cli_output (vm, " ready: %d", sif->ready); diff --git a/src/plugins/lacp/lacp.c b/src/plugins/lacp/lacp.c index 57d8bb0edb3..dba6cb17f63 100644 --- a/src/plugins/lacp/lacp.c +++ b/src/plugins/lacp/lacp.c @@ -107,7 +107,7 @@ lacp_pick_packet_template (slave_if_t * sif) void lacp_send_lacp_pdu (vlib_main_t * vm, slave_if_t * sif) { - if (sif->mode != BOND_MODE_LACP) + if ((sif->mode != BOND_MODE_LACP) || (sif->port_enabled == 0)) { lacp_stop_timer (&sif->periodic_timer); return; @@ -374,16 +374,18 @@ lacp_sw_interface_up_down (vnet_main_t * vnm, u32 sw_if_index, u32 flags) sif = bond_get_slave_by_sw_if_index (sw_if_index); if (sif) { - sif->port_enabled = flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP; + if (sif->lacp_enabled == 0) + return 0; + + /* port_enabled is both admin up and hw link up */ + sif->port_enabled = ((flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) && + vnet_sw_interface_is_link_up (vnm, sw_if_index)); if (sif->port_enabled == 0) { - if (sif->lacp_enabled) - { - lacp_init_neighbor (sif, sif->actor_admin.system, - ntohs (sif->actor_admin.port_number), - ntohs (sif->actor_admin.key)); - lacp_init_state_machines (vm, sif); - } + lacp_init_neighbor (sif, sif->actor_admin.system, + ntohs (sif->actor_admin.port_number), + ntohs (sif->actor_admin.key)); + lacp_init_state_machines (vm, sif); } } @@ -404,15 +406,19 @@ lacp_hw_interface_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags) sif = bond_get_slave_by_sw_if_index (sw->sw_if_index); if (sif) { - if (!(flags & VNET_HW_INTERFACE_FLAG_LINK_UP)) + if (sif->lacp_enabled == 0) + return 0; + + /* port_enabled is both admin up and hw link up */ + sif->port_enabled = ((flags & VNET_HW_INTERFACE_FLAG_LINK_UP) && + vnet_sw_interface_is_admin_up (vnm, + sw->sw_if_index)); + if (sif->port_enabled == 0) { - if (sif->lacp_enabled) - { - lacp_init_neighbor (sif, sif->actor_admin.system, - ntohs (sif->actor_admin.port_number), - ntohs (sif->actor_admin.key)); - lacp_init_state_machines (vm, sif); - } + lacp_init_neighbor (sif, sif->actor_admin.system, + ntohs (sif->actor_admin.port_number), + ntohs (sif->actor_admin.key)); + lacp_init_state_machines (vm, sif); } } -- cgit 1.2.3-korg