diff options
author | Benoît Ganne <bganne@cisco.com> | 2024-04-16 09:36:05 +0200 |
---|---|---|
committer | Neale Ranns <neale@graphiant.com> | 2024-07-12 03:09:22 +0000 |
commit | ff570d3d07ebe07a5107b44d50c54fc4a57359dc (patch) | |
tree | e09554d6adf9e79b5d9abc7b9357509db20d8641 /src/vnet/ip/ip_api.c | |
parent | caaa63322307b28bc8cf9796f642d9a068722ba5 (diff) |
fib: make mfib optional
In some cases we do not need multicast support. Making it optional helps
scaling to high number of VRFs, by reducing the control plane operations
and memory consumption.
Type: improvement
Change-Id: Ib34ed3fe2806e2f4624981da4e4a3c49c69f70be
Signed-off-by: Benoît Ganne <bganne@cisco.com>
Diffstat (limited to 'src/vnet/ip/ip_api.c')
-rw-r--r-- | src/vnet/ip/ip_api.c | 65 |
1 files changed, 50 insertions, 15 deletions
diff --git a/src/vnet/ip/ip_api.c b/src/vnet/ip/ip_api.c index 6dd95140f4b..5ced88fec2e 100644 --- a/src/vnet/ip/ip_api.c +++ b/src/vnet/ip/ip_api.c @@ -636,7 +636,8 @@ vl_api_ip_table_add_del_t_handler (vl_api_ip_table_add_del_t * mp) if (mp->is_add) { - ip_table_create (fproto, table_id, 1, mp->table.name); + ip_table_create (fproto, table_id, 1 /* is_api */, 1 /* create_mfib */, + mp->table.name); } else { @@ -647,6 +648,28 @@ vl_api_ip_table_add_del_t_handler (vl_api_ip_table_add_del_t * mp) } void +vl_api_ip_table_add_del_v2_t_handler (vl_api_ip_table_add_del_v2_t *mp) +{ + vl_api_ip_table_add_del_v2_reply_t *rmp; + fib_protocol_t fproto = + (mp->table.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4); + u32 table_id = ntohl (mp->table.table_id); + int rv = 0; + + if (mp->is_add) + { + ip_table_create (fproto, table_id, 1 /* is_api */, mp->create_mfib, + mp->table.name); + } + else + { + ip_table_delete (fproto, table_id, 1); + } + + REPLY_MACRO (VL_API_IP_TABLE_ADD_DEL_V2_REPLY); +} + +void vl_api_ip_table_allocate_t_handler (vl_api_ip_table_allocate_t *mp) { vl_api_ip_table_allocate_reply_t *rmp; @@ -661,7 +684,8 @@ vl_api_ip_table_allocate_t_handler (vl_api_ip_table_allocate_t *mp) if (~0 == table_id) rv = VNET_API_ERROR_EAGAIN; else - ip_table_create (fproto, table_id, 1, mp->table.name); + ip_table_create (fproto, table_id, 1 /* is_api */, 1 /* create_mfib */, + mp->table.name); REPLY_MACRO2 (VL_API_IP_TABLE_ALLOCATE_REPLY, { clib_memcpy_fast (&rmp->table, &mp->table, sizeof (mp->table)); @@ -915,8 +939,8 @@ vl_api_ip_route_lookup_v2_t_handler (vl_api_ip_route_lookup_v2_t *mp) } void -ip_table_create (fib_protocol_t fproto, - u32 table_id, u8 is_api, const u8 * name) +ip_table_create (fib_protocol_t fproto, u32 table_id, u8 is_api, + u8 create_mfib, const u8 *name) { u32 fib_index, mfib_index; vnet_main_t *vnm = vnet_get_main (); @@ -936,16 +960,23 @@ ip_table_create (fib_protocol_t fproto, * their own unicast tables. */ fib_index = fib_table_find (fproto, table_id); - mfib_index = mfib_table_find (fproto, table_id); - /* * Always try to re-lock in case the fib was deleted by an API call * but was not yet freed because some other locks were held */ fib_table_find_or_create_and_lock_w_name ( fproto, table_id, (is_api ? FIB_SOURCE_API : FIB_SOURCE_CLI), name); - mfib_table_find_or_create_and_lock_w_name ( - fproto, table_id, (is_api ? MFIB_SOURCE_API : MFIB_SOURCE_CLI), name); + + if (create_mfib) + { + /* same for mfib, if needs be */ + mfib_index = mfib_table_find (fproto, table_id); + mfib_table_find_or_create_and_lock_w_name ( + fproto, table_id, (is_api ? MFIB_SOURCE_API : MFIB_SOURCE_CLI), + name); + } + else + mfib_index = 0; if ((~0 == fib_index) || (~0 == mfib_index)) call_elf_section_ip_table_callbacks (vnm, table_id, 1 /* is_add */ , @@ -1655,9 +1686,10 @@ vl_api_ip_table_replace_begin_t_handler (vl_api_ip_table_replace_begin_t * mp) rv = VNET_API_ERROR_NO_SUCH_FIB; else { + u32 mfib_index = mfib_table_find (fproto, ntohl (mp->table.table_id)); fib_table_mark (fib_index, fproto, FIB_SOURCE_API); - mfib_table_mark (mfib_table_find (fproto, ntohl (mp->table.table_id)), - fproto, MFIB_SOURCE_API); + if (mfib_index != INDEX_INVALID) + mfib_table_mark (mfib_index, fproto, MFIB_SOURCE_API); } REPLY_MACRO (VL_API_IP_TABLE_REPLACE_BEGIN_REPLY); } @@ -1677,10 +1709,10 @@ vl_api_ip_table_replace_end_t_handler (vl_api_ip_table_replace_end_t * mp) rv = VNET_API_ERROR_NO_SUCH_FIB; else { + u32 mfib_index = mfib_table_find (fproto, ntohl (mp->table.table_id)); fib_table_sweep (fib_index, fproto, FIB_SOURCE_API); - mfib_table_sweep (mfib_table_find - (fproto, ntohl (mp->table.table_id)), fproto, - MFIB_SOURCE_API); + if (mfib_index != INDEX_INVALID) + mfib_table_sweep (mfib_index, fproto, MFIB_SOURCE_API); } REPLY_MACRO (VL_API_IP_TABLE_REPLACE_END_REPLY); } @@ -1703,6 +1735,7 @@ vl_api_ip_table_flush_t_handler (vl_api_ip_table_flush_t * mp) vnet_main_t *vnm = vnet_get_main (); vnet_interface_main_t *im = &vnm->interface_main; vnet_sw_interface_t *si; + u32 mfib_index; /* Shut down interfaces in this FIB / clean out intfc routes */ pool_foreach (si, im->sw_interfaces) @@ -1717,8 +1750,10 @@ vl_api_ip_table_flush_t_handler (vl_api_ip_table_flush_t * mp) } fib_table_flush (fib_index, fproto, FIB_SOURCE_API); - mfib_table_flush (mfib_table_find (fproto, ntohl (mp->table.table_id)), - fproto, MFIB_SOURCE_API); + + mfib_index = mfib_table_find (fproto, ntohl (mp->table.table_id)); + if (mfib_index != INDEX_INVALID) + mfib_table_flush (mfib_index, fproto, MFIB_SOURCE_API); } REPLY_MACRO (VL_API_IP_TABLE_FLUSH_REPLY); |