diff options
author | Damjan Marion <damarion@cisco.com> | 2023-07-28 13:02:00 +0200 |
---|---|---|
committer | Florin Coras <florin.coras@gmail.com> | 2023-07-28 15:52:35 +0000 |
commit | 8797956bac13dba878250a2528794fdf6a8192bf (patch) | |
tree | a3474a0522a5fef060e17f10e8579ef1937223cc /src/vnet | |
parent | 00ea98ad6050e7784da1153c4d8a9145bc481308 (diff) |
vnet: add vnet_register_device_class function
To allow dynamic registration of device classes..."
Change-Id: Ie8435e8c55b7e300be06abe97b653c0c3ce7f732
Type: improvement
Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vnet')
-rw-r--r-- | src/vnet/interface.c | 44 | ||||
-rw-r--r-- | src/vnet/interface.h | 2 |
2 files changed, 25 insertions, 21 deletions
diff --git a/src/vnet/interface.c b/src/vnet/interface.c index 18ce6b6bc4b..b21170f9c3a 100644 --- a/src/vnet/interface.c +++ b/src/vnet/interface.c @@ -1404,6 +1404,26 @@ vnet_sw_interface_supports_addressing (vnet_main_t *vnm, u32 sw_if_index) return NULL; } +u32 +vnet_register_device_class (vlib_main_t *vm, vnet_device_class_t *c) +{ + vnet_main_t *vnm = vnet_get_main (); + vnet_interface_main_t *im = &vnm->interface_main; + c->index = vec_len (im->device_classes); + hash_set_mem (im->device_class_by_name, c->name, c->index); + + /* to avoid confusion, please remove ".tx_function" statement + from VNET_DEVICE_CLASS() if using function candidates */ + ASSERT (c->tx_fn_registrations == 0 || c->tx_function == 0); + + if (c->tx_fn_registrations) + c->tx_function = + vlib_node_get_preferred_node_fn_variant (vm, c->tx_fn_registrations); + + vec_add1 (im->device_classes, c[0]); + return c->index; +} + clib_error_t * vnet_interface_init (vlib_main_t * vm) { @@ -1450,28 +1470,10 @@ vnet_interface_init (vlib_main_t * vm) im->device_class_by_name = hash_create_string ( /* size */ 0, sizeof (uword)); - { - vnet_device_class_t *c; - c = vnm->device_class_registrations; - - while (c) - { - c->index = vec_len (im->device_classes); - hash_set_mem (im->device_class_by_name, c->name, c->index); - - /* to avoid confusion, please remove ".tx_function" statement - from VNET_DEVICE_CLASS() if using function candidates */ - ASSERT (c->tx_fn_registrations == 0 || c->tx_function == 0); - - if (c->tx_fn_registrations) - c->tx_function = vlib_node_get_preferred_node_fn_variant ( - vm, c->tx_fn_registrations); - - vec_add1 (im->device_classes, c[0]); - c = c->next_class_registration; - } - } + for (vnet_device_class_t *c = vnm->device_class_registrations; c; + c = c->next_class_registration) + vnet_register_device_class (vm, c); im->hw_interface_class_by_name = hash_create_string ( /* size */ 0, sizeof (uword)); diff --git a/src/vnet/interface.h b/src/vnet/interface.h index 8ba5c996e0d..f0cb540f979 100644 --- a/src/vnet/interface.h +++ b/src/vnet/interface.h @@ -292,6 +292,8 @@ typedef struct _vnet_device_class } vnet_device_class_t; +u32 vnet_register_device_class (vlib_main_t *, vnet_device_class_t *); + #ifndef CLIB_MARCH_VARIANT #define VNET_DEVICE_CLASS(x,...) \ __VA_ARGS__ vnet_device_class_t x; \ |