X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=src%2Fvnet%2Fmfib%2Fip4_mfib.c;h=2ad873f82bfe4b7a4e6f4de29c34a2a8b52e446d;hb=16581f5dcb069fc7094f615e4f25c4d8ca34c357;hp=1d872f974fd799a7a24cb1e75e10501ded3d5fb9;hpb=05cac30a9228ddc543b3327cb8a494d79eb5b90d;p=vpp.git diff --git a/src/vnet/mfib/ip4_mfib.c b/src/vnet/mfib/ip4_mfib.c index 1d872f974fd..2ad873f82bf 100644 --- a/src/vnet/mfib/ip4_mfib.c +++ b/src/vnet/mfib/ip4_mfib.c @@ -18,19 +18,42 @@ #include #include -static const mfib_prefix_t ip4_specials[] = { +static const mfib_prefix_t all_zeros = +{ + .fp_proto = FIB_PROTOCOL_IP4, +}; +static const mfib_prefix_t ip4_specials[] = +{ + /* ALL prefixes are in network order */ { - /* (*,*)/0 */ - .fp_src_addr = { - .ip4.data_u32 = 0, + /* (*,224.0.0.1)/32 - all hosts */ + .fp_grp_addr = { + .ip4.data_u32 = 0x010000e0, }, + .fp_len = 32, + .fp_proto = FIB_PROTOCOL_IP4, + }, + { + /* (*,224.0.0.2)/32 - all routers */ .fp_grp_addr = { - .ip4.data_u32 = 0, + .ip4.data_u32 = 0x020000e0, }, - .fp_len = 0, + .fp_len = 32, .fp_proto = FIB_PROTOCOL_IP4, }, }; +static const fib_route_path_t ip4_special_path = + { + .frp_proto = DPO_PROTO_IP4, + .frp_addr = { + .ip4.data_u32 = 0x0, + }, + .frp_sw_if_index = ~0, + .frp_fib_index = ~0, + .frp_weight = 1, + .frp_flags = FIB_ROUTE_PATH_LOCAL, + .frp_mitf_flags = MFIB_ITF_FLAG_FORWARD, + }; static u32 ip4_create_mfib_with_table_id (u32 table_id, @@ -57,24 +80,23 @@ ip4_create_mfib_with_table_id (u32 table_id, mfib_table_lock(mfib_table->mft_index, FIB_PROTOCOL_IP4, src); /* - * add the special entries into the new FIB + * add the default route into the new FIB */ + mfib_table_entry_update(mfib_table->mft_index, + &all_zeros, + MFIB_SOURCE_DEFAULT_ROUTE, + MFIB_RPF_ID_NONE, + MFIB_ENTRY_FLAG_DROP); + int ii; for (ii = 0; ii < ARRAY_LEN(ip4_specials); ii++) { - mfib_prefix_t prefix = ip4_specials[ii]; - - prefix.fp_src_addr.ip4.data_u32 = - clib_host_to_net_u32(prefix.fp_src_addr.ip4.data_u32); - prefix.fp_grp_addr.ip4.data_u32 = - clib_host_to_net_u32(prefix.fp_grp_addr.ip4.data_u32); - - mfib_table_entry_update(mfib_table->mft_index, - &prefix, - MFIB_SOURCE_DEFAULT_ROUTE, - MFIB_RPF_ID_NONE, - MFIB_ENTRY_FLAG_DROP); + mfib_table_entry_path_update(mfib_table->mft_index, + &ip4_specials[ii], + MFIB_SOURCE_SPECIAL, + MFIB_ENTRY_FLAG_NONE, + &ip4_special_path); } return (mfib_table->mft_index); @@ -89,19 +111,17 @@ ip4_mfib_table_destroy (ip4_mfib_t *mfib) /* * remove all the specials we added when the table was created. */ - for (ii = 0; ii < ARRAY_LEN(ip4_specials); ii++) - { - fib_node_index_t mfei; - mfib_prefix_t prefix = ip4_specials[ii]; + mfib_table_entry_delete(mfib_table->mft_index, + &all_zeros, + MFIB_SOURCE_DEFAULT_ROUTE); - prefix.fp_src_addr.ip4.data_u32 = - clib_host_to_net_u32(prefix.fp_src_addr.ip4.data_u32); - prefix.fp_grp_addr.ip4.data_u32 = - clib_host_to_net_u32(prefix.fp_grp_addr.ip4.data_u32); - - mfei = mfib_table_lookup(mfib_table->mft_index, &prefix); - mfib_table_entry_delete_index(mfei, MFIB_SOURCE_DEFAULT_ROUTE); - } + for (ii = 0; ii < ARRAY_LEN(ip4_specials); ii++) + { + mfib_table_entry_path_remove(mfib_table->mft_index, + &ip4_specials[ii], + MFIB_SOURCE_SPECIAL, + &ip4_special_path); + } /* * validate no more routes. @@ -109,10 +129,48 @@ ip4_mfib_table_destroy (ip4_mfib_t *mfib) ASSERT(0 == mfib_table->mft_total_route_counts); ASSERT(~0 != mfib_table->mft_table_id); + for (u32 i = 0; i < ARRAY_LEN (mfib->fib_entry_by_dst_address); i++) + hash_free (mfib->fib_entry_by_dst_address[i]); hash_unset (ip4_main.mfib_index_by_table_id, mfib_table->mft_table_id); pool_put(ip4_main.mfibs, mfib_table); } +void +ip4_mfib_interface_enable_disable (u32 sw_if_index, int is_enable) +{ + const fib_route_path_t path = { + .frp_proto = DPO_PROTO_IP4, + .frp_addr = zero_addr, + .frp_sw_if_index = sw_if_index, + .frp_fib_index = ~0, + .frp_weight = 1, + .frp_mitf_flags = MFIB_ITF_FLAG_ACCEPT, + }; + u32 mfib_index; + int ii; + + mfib_index = ip4_mfib_table_get_index_for_sw_if_index(sw_if_index); + + for (ii = 0; ii < ARRAY_LEN(ip4_specials); ii++) + { + if (is_enable) + { + mfib_table_entry_path_update(mfib_index, + &ip4_specials[ii], + MFIB_SOURCE_SPECIAL, + MFIB_ENTRY_FLAG_NONE, + &path); + } + else + { + mfib_table_entry_path_remove(mfib_index, + &ip4_specials[ii], + MFIB_SOURCE_SPECIAL, + &path); + } + } +} + u32 ip4_mfib_table_find_or_create_and_lock (u32 table_id, mfib_source_t src) @@ -345,8 +403,8 @@ format_ip4_mfib_table_memory (u8 * s, va_list * args) total_memory = 0; - pool_foreach (mfib_table, ip4_main.mfibs, - ({ + pool_foreach (mfib_table, ip4_main.mfibs) + { ip4_mfib_t *mfib = &mfib_table->v4; uword mfib_size; int i; @@ -364,7 +422,7 @@ format_ip4_mfib_table_memory (u8 * s, va_list * args) } total_memory += mfib_size; - })); + } s = format(s, "%=30s %=6d %=12ld\n", "IPv4 multicast", @@ -474,8 +532,8 @@ ip4_show_mfib (vlib_main_t * vm, break; } - pool_foreach (mfib_table, im4->mfibs, - ({ + pool_foreach (mfib_table, im4->mfibs) + { ip4_mfib_t *mfib = &mfib_table->v4; if (table_id >= 0 && table_id != (int)mfib->table_id) @@ -506,9 +564,10 @@ ip4_show_mfib (vlib_main_t * vm, continue; } - vlib_cli_output (vm, "%U, fib_index %d", + vlib_cli_output (vm, "%U, fib_index:%d flags:%U", format_mfib_table_name, mfib->index, FIB_PROTOCOL_IP4, - mfib->index); + mfib->index, + format_mfib_table_flags, mfib_table->mft_flags); /* Show summary? */ if (! verbose) @@ -532,19 +591,20 @@ ip4_show_mfib (vlib_main_t * vm, { ip4_mfib_table_show_one(mfib, vm, &src, &grp, mask); } - })); + } if (memory) vlib_cli_output (vm, "totals: hash:%ld", total_hash_memory); return 0; } +/* clang-format off */ /*? * This command displays the IPv4 MulticasrFIB Tables (VRF Tables) and * the route entries for each table. * * @note This command will run for a long time when the FIB tables are - * comprised of millions of entries. For those senarios, consider displaying + * comprised of millions of entries. For those scenarios, consider displaying * a single table or summary mode. * * @cliexpar @@ -581,10 +641,9 @@ ip4_show_mfib (vlib_main_t * vm, * 32 4 * @cliexend ?*/ -/* *INDENT-OFF* */ +/* clang-format on */ VLIB_CLI_COMMAND (ip4_show_mfib_command, static) = { .path = "show ip mfib", .short_help = "show ip mfib [summary] [table ] [index ] [[/]] [] [ ]", .function = ip4_show_mfib, }; -/* *INDENT-ON* */