summaryrefslogtreecommitdiffstats
path: root/src/vnet
diff options
context:
space:
mode:
Diffstat (limited to 'src/vnet')
-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
14 files changed, 100 insertions, 158 deletions
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);