summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2022-01-06 20:36:14 +0100
committerOle Tr�an <otroan@employees.org>2022-01-07 12:49:47 +0000
commit5c954c4641c7894636aa0533634ef4f5a6bed615 (patch)
treeee3cbeb1e94fadda57aa8620eacfc30d16b7b1df
parentc58b1747b34fe1987835f68268218779a81ae3db (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>
-rw-r--r--src/plugins/af_xdp/device.c15
-rw-r--r--src/plugins/avf/device.c12
-rw-r--r--src/plugins/dpdk/device/init.c12
-rw-r--r--src/plugins/geneve/geneve.c15
-rw-r--r--src/plugins/marvell/pp2/pp2.c16
-rw-r--r--src/plugins/memif/memif.c11
-rw-r--r--src/plugins/rdma/device.c12
-rw-r--r--src/plugins/unittest/bier_test.c45
-rw-r--r--src/plugins/unittest/fib_test.c26
-rw-r--r--src/plugins/unittest/mfib_test.c51
-rw-r--r--src/plugins/vmxnet3/vmxnet3.c17
-rw-r--r--src/vnet/bonding/cli.c16
-rw-r--r--src/vnet/devices/af_packet/af_packet.c21
-rw-r--r--src/vnet/devices/pipe/pipe.c14
-rw-r--r--src/vnet/devices/tap/tap.c16
-rw-r--r--src/vnet/devices/virtio/pci.c18
-rw-r--r--src/vnet/devices/virtio/vhost_user.c15
-rw-r--r--src/vnet/ethernet/ethernet.h25
-rw-r--r--src/vnet/ethernet/interface.c56
-rw-r--r--src/vnet/gre/interface.c16
-rw-r--r--src/vnet/l2/l2_bvi.c19
-rw-r--r--src/vnet/l2/l2_xcrw.c8
-rw-r--r--src/vnet/pg/stream.c8
-rw-r--r--src/vnet/unix/tuntap.c12
-rw-r--r--src/vnet/vxlan/vxlan.c14
25 files changed, 211 insertions, 279 deletions
diff --git a/src/plugins/af_xdp/device.c b/src/plugins/af_xdp/device.c
index c45e873f662..4aa36d95dd5 100644
--- a/src/plugins/af_xdp/device.c
+++ b/src/plugins/af_xdp/device.c
@@ -505,6 +505,7 @@ af_xdp_create_if (vlib_main_t * vm, af_xdp_create_if_args_t * args)
{
vnet_main_t *vnm = vnet_get_main ();
vlib_thread_main_t *tm = vlib_get_thread_main ();
+ vnet_eth_interface_registration_t eir = {};
af_xdp_main_t *am = &af_xdp_main;
af_xdp_device_t *ad;
vnet_sw_interface_t *sw;
@@ -646,15 +647,11 @@ af_xdp_create_if (vlib_main_t * vm, af_xdp_create_if_args_t * args)
ethernet_mac_address_generate (ad->hwaddr);
/* create interface */
- if (ethernet_register_interface (vnm, af_xdp_device_class.index,
- ad->dev_instance, ad->hwaddr,
- &ad->hw_if_index, af_xdp_flag_change))
- {
- args->rv = VNET_API_ERROR_INVALID_INTERFACE;
- args->error =
- clib_error_return (0, "ethernet_register_interface() failed");
- goto err2;
- }
+ eir.dev_class_index = af_xdp_device_class.index;
+ eir.dev_instance = ad->dev_instance;
+ eir.address = ad->hwaddr;
+ eir.cb.flag_change = af_xdp_flag_change;
+ ad->hw_if_index = vnet_eth_register_interface (vnm, &eir);
sw = vnet_get_hw_sw_interface (vnm, ad->hw_if_index);
args->sw_if_index = ad->sw_if_index = sw->sw_if_index;
diff --git a/src/plugins/avf/device.c b/src/plugins/avf/device.c
index 627ead6f4e5..df6d12881a5 100644
--- a/src/plugins/avf/device.c
+++ b/src/plugins/avf/device.c
@@ -1589,6 +1589,7 @@ void
avf_create_if (vlib_main_t * vm, avf_create_if_args_t * args)
{
vnet_main_t *vnm = vnet_get_main ();
+ vnet_eth_interface_registration_t eir = {};
avf_main_t *am = &avf_main;
avf_device_t *ad, **adp;
vlib_pci_dev_handle_t h;
@@ -1722,12 +1723,11 @@ avf_create_if (vlib_main_t * vm, avf_create_if_args_t * args)
goto error;
/* create interface */
- error = ethernet_register_interface (vnm, avf_device_class.index,
- ad->dev_instance, ad->hwaddr,
- &ad->hw_if_index, avf_flag_change);
-
- if (error)
- goto error;
+ eir.dev_class_index = avf_device_class.index;
+ eir.dev_instance = ad->dev_instance;
+ eir.address = ad->hwaddr;
+ eir.cb.flag_change = avf_flag_change;
+ ad->hw_if_index = vnet_eth_register_interface (vnm, &eir);
ethernet_set_flags (vnm, ad->hw_if_index,
ETHERNET_INTERFACE_FLAG_DEFAULT_L3);
diff --git a/src/plugins/dpdk/device/init.c b/src/plugins/dpdk/device/init.c
index d30c08c28fd..8a466a0169f 100644
--- a/src/plugins/dpdk/device/init.c
+++ b/src/plugins/dpdk/device/init.c
@@ -176,7 +176,6 @@ dpdk_lib_init (dpdk_main_t * dm)
vnet_main_t *vnm = vnet_get_main ();
u32 nports;
u16 port_id;
- clib_error_t *error;
vlib_main_t *vm = vlib_get_main ();
vlib_thread_main_t *tm = vlib_get_thread_main ();
vnet_device_main_t *vdm = &vnet_device_main;
@@ -226,6 +225,7 @@ dpdk_lib_init (dpdk_main_t * dm)
struct rte_vmbus_device *vmbus_dev;
dpdk_portid_t next_port_id;
dpdk_device_config_t *devconf = 0;
+ vnet_eth_interface_registration_t eir = {};
vlib_pci_addr_t pci_addr;
vlib_vmbus_addr_t vmbus_addr;
uword *p = 0;
@@ -650,11 +650,11 @@ dpdk_lib_init (dpdk_main_t * dm)
/* assign interface to input thread */
int q;
- error = ethernet_register_interface (
- vnm, dpdk_device_class.index, xd->device_index,
- /* ethernet address */ addr, &xd->hw_if_index, dpdk_flag_change);
- if (error)
- return error;
+ eir.dev_class_index = dpdk_device_class.index;
+ eir.dev_instance = xd->device_index;
+ eir.address = addr;
+ eir.cb.flag_change = dpdk_flag_change;
+ xd->hw_if_index = vnet_eth_register_interface (vnm, &eir);
sw = vnet_get_hw_sw_interface (vnm, xd->hw_if_index);
xd->sw_if_index = sw->sw_if_index;
diff --git a/src/plugins/geneve/geneve.c b/src/plugins/geneve/geneve.c
index 81c96c1c42e..bc0ad58672a 100644
--- a/src/plugins/geneve/geneve.c
+++ b/src/plugins/geneve/geneve.c
@@ -425,18 +425,15 @@ int vnet_geneve_add_del_tunnel
vnet_hw_interface_t *hi;
if (a->l3_mode)
{
+ vnet_eth_interface_registration_t eir = {};
u32 t_idx = t - vxm->tunnels;
u8 address[6] =
{ 0xd0, 0x0b, 0xee, 0xd0, (u8) (t_idx >> 8), (u8) t_idx };
- clib_error_t *error =
- ethernet_register_interface (vnm, geneve_device_class.index,
- t_idx,
- address, &hw_if_index, 0);
- if (error)
- {
- clib_error_report (error);
- return VNET_API_ERROR_INVALID_REGISTRATION;
- }
+
+ eir.dev_class_index = geneve_device_class.index;
+ eir.dev_instance = t_idx;
+ eir.address = address;
+ hw_if_index = vnet_eth_register_interface (vnm, &eir);
}
else
{
diff --git a/src/plugins/marvell/pp2/pp2.c b/src/plugins/marvell/pp2/pp2.c
index dfe5c157018..071fb5d9d66 100644
--- a/src/plugins/marvell/pp2/pp2.c
+++ b/src/plugins/marvell/pp2/pp2.c
@@ -178,6 +178,7 @@ mrvl_pp2_create_if (mrvl_pp2_create_if_args_t * args)
vlib_main_t *vm = vlib_get_main ();
vnet_main_t *vnm = vnet_get_main ();
vlib_thread_main_t *tm = vlib_get_thread_main ();
+ vnet_eth_interface_registration_t eir = {};
mrvl_pp2_main_t *ppm = &mrvl_pp2_main;
struct pp2_bpool_params bpool_params = { 0 };
struct pp2_ppio_params ppio_params = { 0 };
@@ -282,16 +283,11 @@ mrvl_pp2_create_if (mrvl_pp2_create_if_args_t * args)
goto error;
}
- args->error = ethernet_register_interface (vnm, mrvl_pp2_device_class.index,
- ppif->dev_instance,
- mac_addr,
- &ppif->hw_if_index,
- mrvl_pp2_eth_flag_change);
- if (args->error)
- {
- args->rv = VNET_API_ERROR_INVALID_REGISTRATION;
- goto error;
- }
+ eir.dev_class_index = mrvl_pp2_device_class.index;
+ eir.dev_instance = ppif->dev_instance;
+ eir.address = mac_addr;
+ eir.cb.flag_change = mrvl_pp2_eth_flag_change;
+ ppif->hw_if_index = vnet_eth_register_interface (vnm, &eir);
sw = vnet_get_hw_sw_interface (vnm, ppif->hw_if_index);
ppif->sw_if_index = sw->sw_if_index;
diff --git a/src/plugins/memif/memif.c b/src/plugins/memif/memif.c
index d7b82ceee5e..5da73621536 100644
--- a/src/plugins/memif/memif.c
+++ b/src/plugins/memif/memif.c
@@ -897,6 +897,7 @@ memif_create_if (vlib_main_t * vm, memif_create_if_args_t * args)
memif_main_t *mm = &memif_main;
vlib_thread_main_t *tm = vlib_get_thread_main ();
vnet_main_t *vnm = vnet_get_main ();
+ vnet_eth_interface_registration_t eir = {};
memif_if_t *mif = 0;
vnet_sw_interface_t *sw;
clib_error_t *error = 0;
@@ -1011,10 +1012,12 @@ memif_create_if (vlib_main_t * vm, memif_create_if_args_t * args)
args->hw_addr[0] = 2;
args->hw_addr[1] = 0xfe;
}
- error = ethernet_register_interface (vnm, memif_device_class.index,
- mif->dev_instance, args->hw_addr,
- &mif->hw_if_index,
- memif_eth_flag_change);
+
+ eir.dev_class_index = memif_device_class.index;
+ eir.dev_instance = mif->dev_instance;
+ eir.address = args->hw_addr;
+ eir.cb.flag_change = memif_eth_flag_change;
+ mif->hw_if_index = vnet_eth_register_interface (vnm, &eir);
}
else if (mif->mode == MEMIF_INTERFACE_MODE_IP)
{
diff --git a/src/plugins/rdma/device.c b/src/plugins/rdma/device.c
index 3ea8e44b3e7..cad5fdb541f 100644
--- a/src/plugins/rdma/device.c
+++ b/src/plugins/rdma/device.c
@@ -355,17 +355,19 @@ rdma_async_event_cleanup (rdma_device_t * rd)
static clib_error_t *
rdma_register_interface (vnet_main_t * vnm, rdma_device_t * rd)
{
- clib_error_t *err =
- ethernet_register_interface (vnm, rdma_device_class.index,
- rd->dev_instance, rd->hwaddr.bytes,
- &rd->hw_if_index, rdma_flag_change);
+ vnet_eth_interface_registration_t eir = {};
+ eir.dev_class_index = rdma_device_class.index;
+ eir.dev_instance = rd->dev_instance;
+ eir.address = rd->hwaddr.bytes;
+ eir.cb.flag_change = rdma_flag_change;
+ rd->hw_if_index = vnet_eth_register_interface (vnm, &eir);
/* Indicate ability to support L3 DMAC filtering and
* initialize interface to L3 non-promisc mode */
vnet_hw_if_set_caps (vnm, rd->hw_if_index, VNET_HW_IF_CAP_MAC_FILTER);
ethernet_set_flags (vnm, rd->hw_if_index,
ETHERNET_INTERFACE_FLAG_DEFAULT_L3);
- return err;
+ return 0;
}
static void
diff --git a/src/plugins/unittest/bier_test.c b/src/plugins/unittest/bier_test.c
index 7f7439d8590..924c9212929 100644
--- a/src/plugins/unittest/bier_test.c
+++ b/src/plugins/unittest/bier_test.c
@@ -118,28 +118,29 @@ bier_test_mk_intf (u32 ninterfaces)
for (i = 0; i < ninterfaces; i++)
{
- hw_address[5] = i;
-
- error = ethernet_register_interface(vnet_get_main(),
- test_interface_device_class.index,
- i /* instance */,
- hw_address,
- &tm->hw_if_indicies[i],
- /* flag change */ 0);
-
- error = vnet_hw_interface_set_flags(vnet_get_main(),
- tm->hw_if_indicies[i],
- VNET_HW_INTERFACE_FLAG_LINK_UP);
- BIER_TEST((NULL == error), "ADD interface %d", i);
-
- tm->hw[i] = vnet_get_hw_interface(vnet_get_main(),
- tm->hw_if_indicies[i]);
- ip4_main.fib_index_by_sw_if_index[tm->hw[i]->sw_if_index] = 0;
- ip6_main.fib_index_by_sw_if_index[tm->hw[i]->sw_if_index] = 0;
- error = vnet_sw_interface_set_flags(vnet_get_main(),
- tm->hw[i]->sw_if_index,
- VNET_SW_INTERFACE_FLAG_ADMIN_UP);
- BIER_TEST((NULL == error), "UP interface %d", i);
+ vnet_eth_interface_registration_t eir = {};
+ vnet_main_t *vnm = vnet_get_main ();
+
+ hw_address[5] = i;
+
+ eir.dev_class_index = test_interface_device_class.index;
+ eir.dev_instance = i;
+ eir.address = hw_address;
+ tm->hw_if_indicies[i] = vnet_eth_register_interface (vnm, &eir);
+
+ error =
+ vnet_hw_interface_set_flags (vnet_get_main (), tm->hw_if_indicies[i],
+ VNET_HW_INTERFACE_FLAG_LINK_UP);
+ BIER_TEST ((NULL == error), "ADD interface %d", i);
+
+ tm->hw[i] =
+ vnet_get_hw_interface (vnet_get_main (), tm->hw_if_indicies[i]);
+ ip4_main.fib_index_by_sw_if_index[tm->hw[i]->sw_if_index] = 0;
+ ip6_main.fib_index_by_sw_if_index[tm->hw[i]->sw_if_index] = 0;
+ error =
+ vnet_sw_interface_set_flags (vnet_get_main (), tm->hw[i]->sw_if_index,
+ VNET_SW_INTERFACE_FLAG_ADMIN_UP);
+ BIER_TEST ((NULL == error), "UP interface %d", i);
}
/*
* re-eval after the inevitable realloc
diff --git a/src/plugins/unittest/fib_test.c b/src/plugins/unittest/fib_test.c
index 3166e649bfe..2261a9d28d0 100644
--- a/src/plugins/unittest/fib_test.c
+++ b/src/plugins/unittest/fib_test.c
@@ -142,16 +142,15 @@ fib_test_mk_intf (u32 ninterfaces)
for (i = 0; i < ninterfaces; i++)
{
- hw_address[5] = i;
+ vnet_eth_interface_registration_t eir = {};
+ vnet_main_t *vnm = vnet_get_main();
- error = ethernet_register_interface(vnet_get_main(),
- test_interface_device_class.index,
- i /* instance */,
- hw_address,
- &tm->hw_if_indicies[i],
- /* flag change */ 0);
+ hw_address[5] = i;
- FIB_TEST((NULL == error), "ADD interface %d", i);
+ eir.dev_class_index = test_interface_device_class.index;
+ eir.dev_instance = i;
+ eir.address = hw_address;
+ tm->hw_if_indicies[i] = vnet_eth_register_interface (vnm, &eir);
error = vnet_hw_interface_set_flags(vnet_get_main(),
tm->hw_if_indicies[i],
@@ -5169,12 +5168,11 @@ fib_test_v6 (void)
/*
* Add the interface back. routes stay unresolved.
*/
- error = ethernet_register_interface(vnet_get_main(),
- test_interface_device_class.index,
- 0 /* instance */,
- hw_address,
- &tm->hw_if_indicies[0],
- /* flag change */ 0);
+ vnet_eth_interface_registration_t eir = {};
+ eir.dev_class_index = test_interface_device_class.index;
+ eir.dev_instance = 0;
+ eir.address = hw_address;
+ tm->hw_if_indicies[0] = vnet_eth_register_interface (vnet_get_main(), &eir);
fei = fib_table_lookup_exact_match(fib_index, &pfx_2001_b_s_64);
FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)),
diff --git a/src/plugins/unittest/mfib_test.c b/src/plugins/unittest/mfib_test.c
index 1fb4361e793..5cf821fb5f9 100644
--- a/src/plugins/unittest/mfib_test.c
+++ b/src/plugins/unittest/mfib_test.c
@@ -123,32 +123,31 @@ mfib_test_mk_intf (u32 ninterfaces)
for (i = 0; i < ninterfaces; i++)
{
- hw_address[5] = i;
-
- error = ethernet_register_interface(vnet_get_main(),
- test_interface_device_class.index,
- i /* instance */,
- hw_address,
- &tm->hw_if_indicies[i],
- /* flag change */ 0);
-
- MFIB_TEST((NULL == error), "ADD interface %d", i);
-
- error = vnet_hw_interface_set_flags(vnet_get_main(),
- tm->hw_if_indicies[i],
- VNET_HW_INTERFACE_FLAG_LINK_UP);
- tm->hw[i] = vnet_get_hw_interface(vnet_get_main(),
- tm->hw_if_indicies[i]);
- ip4_main.fib_index_by_sw_if_index[tm->hw[i]->sw_if_index] = 0;
- ip6_main.fib_index_by_sw_if_index[tm->hw[i]->sw_if_index] = 0;
-
- ip4_main.mfib_index_by_sw_if_index[tm->hw[i]->sw_if_index] = 0;
- ip6_main.mfib_index_by_sw_if_index[tm->hw[i]->sw_if_index] = 0;
-
- error = vnet_sw_interface_set_flags(vnet_get_main(),
- tm->hw[i]->sw_if_index,
- VNET_SW_INTERFACE_FLAG_ADMIN_UP);
- MFIB_TEST((NULL == error), "UP interface %d", i);
+ vnet_eth_interface_registration_t eir = {};
+ vnet_main_t *vnm = vnet_get_main ();
+
+ hw_address[5] = i;
+
+ eir.dev_class_index = test_interface_device_class.index;
+ eir.dev_instance = i;
+ eir.address = hw_address;
+ tm->hw_if_indicies[i] = vnet_eth_register_interface (vnm, &eir);
+
+ error =
+ vnet_hw_interface_set_flags (vnet_get_main (), tm->hw_if_indicies[i],
+ VNET_HW_INTERFACE_FLAG_LINK_UP);
+ tm->hw[i] =
+ vnet_get_hw_interface (vnet_get_main (), tm->hw_if_indicies[i]);
+ ip4_main.fib_index_by_sw_if_index[tm->hw[i]->sw_if_index] = 0;
+ ip6_main.fib_index_by_sw_if_index[tm->hw[i]->sw_if_index] = 0;
+
+ ip4_main.mfib_index_by_sw_if_index[tm->hw[i]->sw_if_index] = 0;
+ ip6_main.mfib_index_by_sw_if_index[tm->hw[i]->sw_if_index] = 0;
+
+ error =
+ vnet_sw_interface_set_flags (vnet_get_main (), tm->hw[i]->sw_if_index,
+ VNET_SW_INTERFACE_FLAG_ADMIN_UP);
+ MFIB_TEST ((NULL == error), "UP interface %d", i);
}
/*
* re-eval after the inevitable realloc
diff --git a/src/plugins/vmxnet3/vmxnet3.c b/src/plugins/vmxnet3/vmxnet3.c
index 8059d03c595..edd0b4f4f75 100644
--- a/src/plugins/vmxnet3/vmxnet3.c
+++ b/src/plugins/vmxnet3/vmxnet3.c
@@ -617,6 +617,8 @@ vmxnet3_create_if (vlib_main_t * vm, vmxnet3_create_if_args_t * args)
{
vnet_main_t *vnm = vnet_get_main ();
vmxnet3_main_t *vmxm = &vmxnet3_main;
+ vnet_eth_interface_registration_t eir = {};
+
vmxnet3_device_t *vd;
vlib_pci_dev_handle_t h;
clib_error_t *error = 0;
@@ -802,16 +804,11 @@ vmxnet3_create_if (vlib_main_t * vm, vmxnet3_create_if_args_t * args)
}
/* create interface */
- error = ethernet_register_interface (vnm, vmxnet3_device_class.index,
- vd->dev_instance, vd->mac_addr,
- &vd->hw_if_index, vmxnet3_flag_change);
-
- if (error)
- {
- vmxnet3_log_error (vd,
- "error encountered on ethernet register interface");
- goto error;
- }
+ eir.dev_class_index = vmxnet3_device_class.index;
+ eir.dev_instance = vd->dev_instance;
+ eir.address = vd->mac_addr;
+ eir.cb.flag_change = vmxnet3_flag_change;
+ vd->hw_if_index = vnet_eth_register_interface (vnm, &eir);
vnet_sw_interface_t *sw = vnet_get_hw_sw_interface (vnm, vd->hw_if_index);
vd->sw_if_index = sw->sw_if_index;
diff --git a/src/vnet/bonding/cli.c b/src/vnet/bonding/cli.c
index 2045ff43c53..62bbbdae75c 100644
--- a/src/vnet/bonding/cli.c
+++ b/src/vnet/bonding/cli.c
@@ -376,6 +376,7 @@ bond_delete_if (vlib_main_t * vm, u32 sw_if_index)
void
bond_create_if (vlib_main_t * vm, bond_create_if_args_t * args)
{
+ vnet_eth_interface_registration_t eir = {};
bond_main_t *bm = &bond_main;
vnet_main_t *vnm = vnet_get_main ();
vnet_sw_interface_t *sw;
@@ -439,18 +440,11 @@ bond_create_if (vlib_main_t * vm, bond_create_if_args_t * args)
args->hw_addr[1] = 0xfe;
}
memcpy (bif->hw_address, args->hw_addr, 6);
- args->error = ethernet_register_interface
- (vnm, bond_dev_class.index, bif->dev_instance /* device instance */ ,
- bif->hw_address /* ethernet address */ ,
- &bif->hw_if_index, 0 /* flag change */ );
- if (args->error)
- {
- args->rv = VNET_API_ERROR_INVALID_REGISTRATION;
- hash_unset (bm->id_used, bif->id);
- pool_put (bm->interfaces, bif);
- return;
- }
+ eir.dev_class_index = bond_dev_class.index;
+ eir.dev_instance = bif->dev_instance;
+ eir.address = bif->hw_address;
+ bif->hw_if_index = vnet_eth_register_interface (vnm, &eir);
sw = vnet_get_hw_sw_interface (vnm, bif->hw_if_index);
bif->sw_if_index = sw->sw_if_index;
diff --git a/src/vnet/devices/af_packet/af_packet.c b/src/vnet/devices/af_packet/af_packet.c
index 2e044472736..4c52cf1d5f4 100644
--- a/src/vnet/devices/af_packet/af_packet.c
+++ b/src/vnet/devices/af_packet/af_packet.c
@@ -252,7 +252,6 @@ af_packet_create_if (af_packet_create_if_arg_t *arg)
u8 *ring = 0;
af_packet_if_t *apif = 0;
u8 hw_addr[6];
- clib_error_t *error;
vnet_sw_interface_t *sw;
vnet_hw_interface_t *hw;
vlib_thread_main_t *tm = vlib_get_thread_main ();
@@ -386,6 +385,7 @@ af_packet_create_if (af_packet_create_if_arg_t *arg)
if (apif->mode != AF_PACKET_IF_MODE_IP)
{
+ vnet_eth_interface_registration_t eir = {};
/*use configured or generate random MAC address */
if (arg->hw_addr)
clib_memcpy (hw_addr, arg->hw_addr, 6);
@@ -401,20 +401,11 @@ af_packet_create_if (af_packet_create_if_arg_t *arg)
hw_addr[1] = 0xfe;
}
- error = ethernet_register_interface (
- vnm, af_packet_device_class.index, if_index, hw_addr,
- &apif->hw_if_index, af_packet_eth_flag_change);
-
- if (error)
- {
- clib_memset (apif, 0, sizeof (*apif));
- pool_put (apm->interfaces, apif);
- vlib_log_err (apm->log_class, "Unable to register interface: %U",
- format_clib_error, error);
- clib_error_free (error);
- ret = VNET_API_ERROR_SYSCALL_ERROR_1;
- goto error;
- }
+ eir.dev_class_index = af_packet_device_class.index;
+ eir.dev_instance = if_index;
+ eir.address = hw_addr;
+ eir.cb.flag_change = af_packet_eth_flag_change;
+ apif->hw_if_index = vnet_eth_register_interface (vnm, &eir);
}
else
{
diff --git a/src/vnet/devices/pipe/pipe.c b/src/vnet/devices/pipe/pipe.c
index 56e54defab7..26b01970b6c 100644
--- a/src/vnet/devices/pipe/pipe.c
+++ b/src/vnet/devices/pipe/pipe.c
@@ -533,6 +533,7 @@ vnet_create_pipe_interface (u8 is_specified,
{
vnet_main_t *vnm = vnet_get_main ();
vlib_main_t *vm = vlib_get_main ();
+ vnet_eth_interface_registration_t eir = {};
u8 address[6] = {
[0] = 0x22,
[1] = 0x22,
@@ -563,15 +564,10 @@ vnet_create_pipe_interface (u8 is_specified,
*/
address[5] = instance;
- error = ethernet_register_interface (vnm, pipe_device_class.index,
- instance, address, &hw_if_index,
- /* flag change */ 0);
-
- if (error)
- {
- rv = VNET_API_ERROR_INVALID_REGISTRATION;
- goto oops;
- }
+ eir.dev_class_index = pipe_device_class.index;
+ eir.dev_instance = instance;
+ eir.address = address;
+ hw_if_index = vnet_eth_register_interface (vnm, &eir);
hi = vnet_get_hw_interface (vnm, hw_if_index);
*parent_sw_if_index = hi->sw_if_index;
diff --git a/src/vnet/devices/tap/tap.c b/src/vnet/devices/tap/tap.c
index 93140ec0c3f..19333f0ab10 100644
--- a/src/vnet/devices/tap/tap.c
+++ b/src/vnet/devices/tap/tap.c
@@ -643,17 +643,13 @@ tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args)
if (vif->type != VIRTIO_IF_TYPE_TUN)
{
- args->error =
- ethernet_register_interface (vnm, virtio_device_class.index,
- vif->dev_instance, vif->mac_addr,
- &vif->hw_if_index,
- virtio_eth_flag_change);
- if (args->error)
- {
- args->rv = VNET_API_ERROR_INVALID_REGISTRATION;
- goto error;
- }
+ vnet_eth_interface_registration_t eir = {};
+ eir.dev_class_index = virtio_device_class.index;
+ eir.dev_instance = vif->dev_instance;
+ eir.address = vif->mac_addr;
+ eir.cb.flag_change = virtio_eth_flag_change;
+ vif->hw_if_index = vnet_eth_register_interface (vnm, &eir);
}
else
{
diff --git a/src/vnet/devices/virtio/pci.c b/src/vnet/devices/virtio/pci.c
index efa1b88a2b0..b32f72bc66b 100644
--- a/src/vnet/devices/virtio/pci.c
+++ b/src/vnet/devices/virtio/pci.c
@@ -1462,18 +1462,12 @@ virtio_pci_create_if (vlib_main_t * vm, virtio_pci_create_if_args_t * args)
}
/* create interface */
- error = ethernet_register_interface (vnm, virtio_device_class.index,
- vif->dev_instance, vif->mac_addr,
- &vif->hw_if_index,
- virtio_pci_flag_change);
-
- if (error)
- {
- args->rv = VNET_API_ERROR_INVALID_REGISTRATION;
- virtio_log_error (vif,
- "error encountered on ethernet register interface");
- goto error;
- }
+ vnet_eth_interface_registration_t eir = {};
+ eir.dev_class_index = virtio_device_class.index;
+ eir.dev_instance = vif->dev_instance;
+ eir.address = vif->mac_addr;
+ eir.cb.flag_change = virtio_pci_flag_change;
+ vif->hw_if_index = vnet_eth_register_interface (vnm, &eir);
vnet_sw_interface_t *sw = vnet_get_hw_sw_interface (vnm, vif->hw_if_index);
vif->sw_if_index = sw->sw_if_index;
diff --git a/src/vnet/devices/virtio/vhost_user.c b/src/vnet/devices/virtio/vhost_user.c
index 85c39b9de8b..2d8cad8da43 100644
--- a/src/vnet/devices/virtio/vhost_user.c
+++ b/src/vnet/devices/virtio/vhost_user.c
@@ -1563,8 +1563,8 @@ vhost_user_create_ethernet (vnet_main_t *vnm, vlib_main_t *vm,
vhost_user_create_if_args_t *args)
{
vhost_user_main_t *vum = &vhost_user_main;
+ vnet_eth_interface_registration_t eir = {};
u8 hwaddr[6];
- clib_error_t *error;
/* create hw and sw interface */
if (args->use_custom_mac)
@@ -1579,15 +1579,10 @@ vhost_user_create_ethernet (vnet_main_t *vnm, vlib_main_t *vm,
hwaddr[1] = 0xfe;
}
- error = ethernet_register_interface
- (vnm,
- vhost_user_device_class.index,
- vui - vum->vhost_user_interfaces /* device instance */ ,
- hwaddr /* ethernet address */ ,
- &vui->hw_if_index, 0 /* flag change */ );
-
- if (error)
- clib_error_report (error);
+ eir.dev_class_index = vhost_user_device_class.index;
+ eir.dev_instance = vui - vum->vhost_user_interfaces /* device instance */,
+ eir.address = hwaddr;
+ vui->hw_if_index = vnet_eth_register_interface (vnm, &eir);
}
/*
diff --git a/src/vnet/ethernet/ethernet.h b/src/vnet/ethernet/ethernet.h
index f3dd1a24a4f..9621429e4ee 100644
--- a/src/vnet/ethernet/ethernet.h
+++ b/src/vnet/ethernet/ethernet.h
@@ -128,6 +128,11 @@ struct vnet_hw_interface_t;
typedef u32 (ethernet_flag_change_function_t)
(vnet_main_t * vnm, struct vnet_hw_interface_t * hi, u32 flags);
+typedef struct
+{
+ ethernet_flag_change_function_t *flag_change;
+} vnet_eth_if_callbacks_t;
+
#define ETHERNET_MIN_PACKET_BYTES 64
#define ETHERNET_MAX_PACKET_BYTES 9216
@@ -165,7 +170,7 @@ typedef struct ethernet_interface
#define ETHERNET_INTERFACE_FLAG_MTU 2
/* Callback, e.g. to turn on/off promiscuous mode */
- ethernet_flag_change_function_t *flag_change;
+ vnet_eth_if_callbacks_t cb;
u32 driver_instance;
@@ -353,14 +358,6 @@ mac_address_t *ethernet_interface_add_del_address (ethernet_main_t * em,
const u8 * address,
u8 is_add);
-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);
-
void ethernet_delete_interface (vnet_main_t * vnm, u32 hw_if_index);
/* Register given node index to take input for given ethernet type. */
@@ -574,6 +571,16 @@ vnet_get_ethernet_main (void)
return &ethernet_main;
}
+typedef struct
+{
+ u32 dev_class_index;
+ u32 dev_instance;
+ vnet_eth_if_callbacks_t cb;
+ const u8 *address;
+} vnet_eth_interface_registration_t;
+
+u32 vnet_eth_register_interface (vnet_main_t *vnm,
+ vnet_eth_interface_registration_t *r);
void ethernet_update_adjacency (vnet_main_t * vnm, u32 sw_if_index, u32 ai);
u8 *ethernet_build_rewrite (vnet_main_t * vnm,
u32 sw_if_index,
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 = &ethernet_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,
diff --git a/src/vnet/gre/interface.c b/src/vnet/gre/interface.c
index 3b566b6ea81..4a02aa77292 100644
--- a/src/vnet/gre/interface.c
+++ b/src/vnet/gre/interface.c
@@ -370,7 +370,6 @@ vnet_gre_tunnel_add (vnet_gre_tunnel_add_del_args_t * a,
gre_tunnel_t *t;
vnet_hw_interface_t *hi;
u32 hw_if_index, sw_if_index;
- clib_error_t *error;
u8 is_ipv6 = a->is_ipv6;
gre_tunnel_key_t key;
@@ -415,17 +414,16 @@ vnet_gre_tunnel_add (vnet_gre_tunnel_add_del_args_t * a,
}
else
{
+ vnet_eth_interface_registration_t eir = {};
+
/* Default MAC address (d00b:eed0:0000 + sw_if_index) */
u8 address[6] =
{ 0xd0, 0x0b, 0xee, 0xd0, (u8) (t_idx >> 8), (u8) t_idx };
- error =
- ethernet_register_interface (vnm, gre_device_class.index, t_idx,
- address, &hw_if_index, 0);
- if (error)
- {
- clib_error_report (error);
- return VNET_API_ERROR_INVALID_REGISTRATION;
- }
+
+ eir.dev_class_index = gre_device_class.index;
+ eir.dev_instance = t_idx;
+ eir.address = address;
+ hw_if_index = vnet_eth_register_interface (vnm, &eir);
}
/* Set GRE tunnel interface output node (not used for L3 payload) */
diff --git a/src/vnet/l2/l2_bvi.c b/src/vnet/l2/l2_bvi.c
index e5623682657..9cfff55fb45 100644
--- a/src/vnet/l2/l2_bvi.c
+++ b/src/vnet/l2/l2_bvi.c
@@ -138,13 +138,11 @@ l2_bvi_create (u32 user_instance,
{
vnet_main_t *vnm = vnet_get_main ();
vlib_main_t *vm = vlib_get_main ();
+ vnet_eth_interface_registration_t eir = {};
u32 instance, hw_if_index, slot;
vnet_hw_interface_t *hw_if;
- clib_error_t *error;
mac_address_t mac;
- int rv = 0;
-
ASSERT (sw_if_indexp);
*sw_if_indexp = (u32) ~ 0;
@@ -178,17 +176,10 @@ l2_bvi_create (u32 user_instance,
mac_address_copy (&mac, mac_in);
}
- error = ethernet_register_interface (vnm,
- bvi_device_class.index,
- instance, mac.bytes, &hw_if_index,
- /* flag change */ 0);
-
- if (error)
- {
- rv = VNET_API_ERROR_INVALID_REGISTRATION;
- clib_error_report (error);
- return rv;
- }
+ eir.dev_class_index = bvi_device_class.index;
+ eir.dev_instance = instance;
+ eir.address = mac.bytes;
+ hw_if_index = vnet_eth_register_interface (vnm, &eir);
hw_if = vnet_get_hw_interface (vnm, hw_if_index);
diff --git a/src/vnet/l2/l2_xcrw.c b/src/vnet/l2/l2_xcrw.c
index c2c325a796f..d848fac6b72 100644
--- a/src/vnet/l2/l2_xcrw.c
+++ b/src/vnet/l2/l2_xcrw.c
@@ -291,6 +291,7 @@ static u32
create_xcrw_interface (vlib_main_t * vm)
{
vnet_main_t *vnm = vnet_get_main ();
+ vnet_eth_interface_registration_t eir = {};
static u32 instance;
u8 address[6];
u32 hw_if_index;
@@ -301,10 +302,9 @@ create_xcrw_interface (vlib_main_t * vm)
clib_memset (address, 0, sizeof (address));
address[2] = 0x12;
- /* can returns error iff phy != 0 */
- (void) ethernet_register_interface
- (vnm, xcrw_device_class.index, instance++, address, &hw_if_index,
- /* flag change */ 0);
+ eir.dev_class_index = xcrw_device_class.index;
+ eir.dev_instance = instance++, eir.address = address;
+ hw_if_index = vnet_eth_register_interface (vnm, &eir);
hi = vnet_get_hw_interface (vnm, hw_if_index);
sw_if_index = hi->sw_if_index;
diff --git a/src/vnet/pg/stream.c b/src/vnet/pg/stream.c
index 5f34a43812a..112cc09ae97 100644
--- a/src/vnet/pg/stream.c
+++ b/src/vnet/pg/stream.c
@@ -268,6 +268,7 @@ pg_interface_add_or_get (pg_main_t *pg, uword if_id, u8 gso_enabled,
}
else
{
+ vnet_eth_interface_registration_t eir = {};
u8 hw_addr[6];
f64 now = vlib_time_now (vm);
u32 rnd;
@@ -287,8 +288,11 @@ pg_interface_add_or_get (pg_main_t *pg, uword if_id, u8 gso_enabled,
switch (pi->mode)
{
case PG_MODE_ETHERNET:
- ethernet_register_interface (vnm, pg_dev_class.index, i, hw_addr,
- &pi->hw_if_index, pg_eth_flag_change);
+ eir.dev_class_index = pg_dev_class.index;
+ eir.dev_instance = i;
+ eir.address = hw_addr;
+ eir.cb.flag_change = pg_eth_flag_change;
+ pi->hw_if_index = vnet_eth_register_interface (vnm, &eir);
break;
case PG_MODE_IP4:
case PG_MODE_IP6:
diff --git a/src/vnet/unix/tuntap.c b/src/vnet/unix/tuntap.c
index 4a848349ae1..c588cfd208c 100644
--- a/src/vnet/unix/tuntap.c
+++ b/src/vnet/unix/tuntap.c
@@ -624,12 +624,12 @@ tuntap_config (vlib_main_t * vm, unformat_input_t * input)
if (have_normal_interface)
{
vnet_main_t *vnm = vnet_get_main ();
- error = ethernet_register_interface
- (vnm, tuntap_dev_class.index, 0 /* device instance */ ,
- tm->ether_dst_mac /* ethernet address */ ,
- &tm->hw_if_index, 0 /* flag change */ );
- if (error)
- clib_error_report (error);
+ vnet_eth_interface_registration_t eir = {};
+
+ eir.dev_class_index = tuntap_dev_class.index;
+ eir.address = tm->ether_dst_mac;
+ tm->hw_if_index = vnet_eth_register_interface (vnm, &eir);
+
tm->sw_if_index = tm->hw_if_index;
vm->os_punt_frame = tuntap_nopunt_frame;
}
diff --git a/src/vnet/vxlan/vxlan.c b/src/vnet/vxlan/vxlan.c
index 484b7c2fa21..f394b6b7c89 100644
--- a/src/vnet/vxlan/vxlan.c
+++ b/src/vnet/vxlan/vxlan.c
@@ -457,6 +457,7 @@ int vnet_vxlan_add_del_tunnel
vxlan_hw_class.index, dev_instance);
else
{
+ vnet_eth_interface_registration_t eir = {};
f64 now = vlib_time_now (vm);
u32 rnd;
rnd = (u32) (now * 1e6);
@@ -464,15 +465,12 @@ int vnet_vxlan_add_del_tunnel
memcpy (hw_addr + 2, &rnd, sizeof (rnd));
hw_addr[0] = 2;
hw_addr[1] = 0xfe;
- if (ethernet_register_interface (
- vnm, vxlan_device_class.index, dev_instance, hw_addr,
- &t->hw_if_index, vxlan_eth_flag_change))
- {
- hash_unset (vxm->instance_used, t->user_instance);
- pool_put (vxm->tunnels, t);
- return VNET_API_ERROR_SYSCALL_ERROR_2;
- }
+ eir.dev_class_index = vxlan_device_class.index;
+ eir.dev_instance = dev_instance;
+ eir.address = hw_addr;
+ eir.cb.flag_change = vxlan_eth_flag_change;
+ t->hw_if_index = vnet_eth_register_interface (vnm, &eir);
}
vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, t->hw_if_index);