diff options
author | Damjan Marion <damarion@cisco.com> | 2022-01-06 20:36:14 +0100 |
---|---|---|
committer | Ole Tr�an <otroan@employees.org> | 2022-01-07 12:49:47 +0000 |
commit | 5c954c4641c7894636aa0533634ef4f5a6bed615 (patch) | |
tree | ee3cbeb1e94fadda57aa8620eacfc30d16b7b1df /src/vnet/ethernet/interface.c | |
parent | c58b1747b34fe1987835f68268218779a81ae3db (diff) |
ethernet: new interface registration function
Prep for supporting multiple callbacks, optional args, etc.
Type: improvement
Change-Id: I96244c098712e8213374678623f12527b0e7f387
Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vnet/ethernet/interface.c')
-rw-r--r-- | src/vnet/ethernet/interface.c | 56 |
1 files changed, 17 insertions, 39 deletions
diff --git a/src/vnet/ethernet/interface.c b/src/vnet/ethernet/interface.c index 9b70ae5dce4..b1513a79774 100644 --- a/src/vnet/ethernet/interface.c +++ b/src/vnet/ethernet/interface.c @@ -345,28 +345,21 @@ unformat_ethernet_interface (unformat_input_t * input, va_list * args) return 0; } -clib_error_t * -ethernet_register_interface (vnet_main_t * vnm, - u32 dev_class_index, - u32 dev_instance, - const u8 * address, - u32 * hw_if_index_return, - ethernet_flag_change_function_t flag_change) +u32 +vnet_eth_register_interface (vnet_main_t *vnm, + vnet_eth_interface_registration_t *r) { ethernet_main_t *em = ðernet_main; ethernet_interface_t *ei; vnet_hw_interface_t *hi; - clib_error_t *error = 0; u32 hw_if_index; pool_get (em->interfaces, ei); - ei->flag_change = flag_change; + clib_memcpy (&ei->cb, &r->cb, sizeof (vnet_eth_if_callbacks_t)); - hw_if_index = vnet_register_interface - (vnm, - dev_class_index, dev_instance, - ethernet_hw_interface_class.index, ei - em->interfaces); - *hw_if_index_return = hw_if_index; + hw_if_index = vnet_register_interface ( + vnm, r->dev_class_index, r->dev_instance, + ethernet_hw_interface_class.index, ei - em->interfaces); hi = vnet_get_hw_interface (vnm, hw_if_index); @@ -380,14 +373,8 @@ ethernet_register_interface (vnet_main_t * vnm, /* Default ethernet MTU, 9000 unless set by ethernet_config see below */ vnet_sw_interface_set_mtu (vnm, hi->sw_if_index, em->default_mtu); - ethernet_set_mac (hi, ei, address); - - if (error) - { - pool_put (em->interfaces, ei); - return error; - } - return error; + ethernet_set_mac (hi, ei, r->address); + return hw_if_index; } void @@ -455,14 +442,14 @@ ethernet_set_flags (vnet_main_t * vnm, u32 hw_if_index, u32 flags) /* preserve status bits and update last set operation bits */ ei->flags = (ei->flags & ETHERNET_INTERFACE_FLAGS_STATUS_MASK) | opn_flags; - if (ei->flag_change) + if (ei->cb.flag_change) { switch (opn_flags) { case ETHERNET_INTERFACE_FLAG_DEFAULT_L3: if (hi->caps & VNET_HW_IF_CAP_MAC_FILTER) { - if (ei->flag_change (vnm, hi, opn_flags) != ~0) + if (ei->cb.flag_change (vnm, hi, opn_flags) != ~0) { ei->flags |= ETHERNET_INTERFACE_FLAG_STATUS_L3; return 0; @@ -475,7 +462,7 @@ ethernet_set_flags (vnet_main_t * vnm, u32 hw_if_index, u32 flags) ei->flags &= ~ETHERNET_INTERFACE_FLAG_STATUS_L3; /* fall through */ case ETHERNET_INTERFACE_FLAG_MTU: - return ei->flag_change (vnm, hi, opn_flags); + return ei->cb.flag_change (vnm, hi, opn_flags); default: return ~0; } @@ -834,13 +821,11 @@ vnet_create_loopback_interface (u32 * sw_if_indexp, u8 * mac_address, { vnet_main_t *vnm = vnet_get_main (); vlib_main_t *vm = vlib_get_main (); - clib_error_t *error; u32 instance; u8 address[6]; u32 hw_if_index; vnet_hw_interface_t *hw_if; u32 slot; - int rv = 0; ASSERT (sw_if_indexp); @@ -872,18 +857,11 @@ vnet_create_loopback_interface (u32 * sw_if_indexp, u8 * mac_address, address[5] = instance; } - error = ethernet_register_interface - (vnm, - ethernet_simulated_device_class.index, instance, address, &hw_if_index, - /* flag change */ 0); - - if (error) - { - rv = VNET_API_ERROR_INVALID_REGISTRATION; - clib_error_report (error); - return rv; - } - + vnet_eth_interface_registration_t eir = {}; + eir.dev_class_index = ethernet_simulated_device_class.index; + eir.dev_instance = instance; + eir.address = address; + hw_if_index = vnet_eth_register_interface (vnm, &eir); hw_if = vnet_get_hw_interface (vnm, hw_if_index); slot = vlib_node_add_named_next_with_slot (vm, hw_if->tx_node_index, |