X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Finterface_api.c;h=a765c0bbc3d518301a353ec672b9db4c8cb9d793;hb=2010a214ea07e1a4d17393ec93f5c4049a517a93;hp=80a3058303c1919d2ab4716670429d9c01a6e6c7;hpb=7854b46f7789aae662f01fc29f4dd222a67bfe3d;p=vpp.git diff --git a/src/vnet/interface_api.c b/src/vnet/interface_api.c index 80a3058303c..a765c0bbc3d 100644 --- a/src/vnet/interface_api.c +++ b/src/vnet/interface_api.c @@ -461,63 +461,25 @@ vl_api_sw_interface_set_table_t_handler (vl_api_sw_interface_set_table_t * mp) VALIDATE_SW_IF_INDEX (mp); if (mp->is_ipv6) - rv = ip_table_bind (FIB_PROTOCOL_IP6, sw_if_index, table_id, 1); + rv = ip_table_bind (FIB_PROTOCOL_IP6, sw_if_index, table_id); else - rv = ip_table_bind (FIB_PROTOCOL_IP4, sw_if_index, table_id, 1); + rv = ip_table_bind (FIB_PROTOCOL_IP4, sw_if_index, table_id); BAD_SW_IF_INDEX_LABEL; REPLY_MACRO (VL_API_SW_INTERFACE_SET_TABLE_REPLY); } -int -ip_table_bind (fib_protocol_t fproto, - u32 sw_if_index, u32 table_id, u8 is_api) +void +fib_table_bind (fib_protocol_t fproto, u32 sw_if_index, u32 fib_index) { - CLIB_UNUSED (ip_interface_address_t * ia); - u32 fib_index, mfib_index; - fib_source_t src; - mfib_source_t msrc; - - if (is_api) - { - src = FIB_SOURCE_API; - msrc = MFIB_SOURCE_API; - } - else - { - src = FIB_SOURCE_CLI; - msrc = MFIB_SOURCE_CLI; - } - - /* - * This if table does not exist = error is what we want in the end. - */ - fib_index = fib_table_find (fproto, table_id); - mfib_index = mfib_table_find (fproto, table_id); + u32 table_id; - if (~0 == fib_index || ~0 == mfib_index) - { - return (VNET_API_ERROR_NO_SUCH_FIB); - } + table_id = fib_table_get_table_id (fib_index, fproto); + ASSERT (table_id != ~0); if (FIB_PROTOCOL_IP6 == fproto) { - /* - * If the interface already has in IP address, then a change int - * VRF is not allowed. The IP address applied must first be removed. - * We do not do that automatically here, since VPP has no knowledge - * of whether those subnets are valid in the destination VRF. - */ - /* *INDENT-OFF* */ - foreach_ip_interface_address (&ip6_main.lookup_main, - ia, sw_if_index, - 1 /* honor unnumbered */ , - ({ - return (VNET_API_ERROR_ADDRESS_FOUND_FOR_INTERFACE); - })); - /* *INDENT-ON* */ - /* * tell those that are interested that the binding is changing. */ @@ -531,38 +493,18 @@ ip_table_bind (fib_protocol_t fproto, /* unlock currently assigned tables */ if (0 != ip6_main.fib_index_by_sw_if_index[sw_if_index]) fib_table_unlock (ip6_main.fib_index_by_sw_if_index[sw_if_index], - FIB_PROTOCOL_IP6, src); - if (0 != ip6_main.mfib_index_by_sw_if_index[sw_if_index]) - mfib_table_unlock (ip6_main.mfib_index_by_sw_if_index[sw_if_index], - FIB_PROTOCOL_IP6, msrc); + FIB_PROTOCOL_IP6, FIB_SOURCE_INTERFACE); if (0 != table_id) { /* we need to lock the table now it's inuse */ - fib_table_lock (fib_index, FIB_PROTOCOL_IP6, src); - mfib_table_lock (mfib_index, FIB_PROTOCOL_IP6, msrc); + fib_table_lock (fib_index, FIB_PROTOCOL_IP6, FIB_SOURCE_INTERFACE); } ip6_main.fib_index_by_sw_if_index[sw_if_index] = fib_index; - ip6_main.mfib_index_by_sw_if_index[sw_if_index] = mfib_index; } else { - /* - * If the interface already has in IP address, then a change int - * VRF is not allowed. The IP address applied must first be removed. - * We do not do that automatically here, since VPP has no knowledge - * of whether those subnets are valid in the destination VRF. - */ - /* *INDENT-OFF* */ - foreach_ip_interface_address (&ip4_main.lookup_main, - ia, sw_if_index, - 1 /* honor unnumbered */ , - ({ - return (VNET_API_ERROR_ADDRESS_FOUND_FOR_INTERFACE); - })); - /* *INDENT-ON* */ - /* * tell those that are interested that the binding is changing. */ @@ -576,24 +518,94 @@ ip_table_bind (fib_protocol_t fproto, /* unlock currently assigned tables */ if (0 != ip4_main.fib_index_by_sw_if_index[sw_if_index]) fib_table_unlock (ip4_main.fib_index_by_sw_if_index[sw_if_index], - FIB_PROTOCOL_IP4, src); + FIB_PROTOCOL_IP4, FIB_SOURCE_INTERFACE); + + if (0 != table_id) + { + /* we need to lock the table now it's inuse */ + fib_index = fib_table_find_or_create_and_lock ( + FIB_PROTOCOL_IP4, table_id, FIB_SOURCE_INTERFACE); + } + + ip4_main.fib_index_by_sw_if_index[sw_if_index] = fib_index; + } +} + +void +mfib_table_bind (fib_protocol_t fproto, u32 sw_if_index, u32 mfib_index) +{ + u32 table_id; + + table_id = mfib_table_get_table_id (mfib_index, fproto); + ASSERT (table_id != ~0); + + if (FIB_PROTOCOL_IP6 == fproto) + { + if (0 != ip6_main.mfib_index_by_sw_if_index[sw_if_index]) + mfib_table_unlock (ip6_main.mfib_index_by_sw_if_index[sw_if_index], + FIB_PROTOCOL_IP6, MFIB_SOURCE_INTERFACE); + + if (0 != table_id) + { + /* we need to lock the table now it's inuse */ + mfib_table_lock (mfib_index, FIB_PROTOCOL_IP6, + MFIB_SOURCE_INTERFACE); + } + + ip6_main.mfib_index_by_sw_if_index[sw_if_index] = mfib_index; + } + else + { if (0 != ip4_main.mfib_index_by_sw_if_index[sw_if_index]) mfib_table_unlock (ip4_main.mfib_index_by_sw_if_index[sw_if_index], - FIB_PROTOCOL_IP4, msrc); + FIB_PROTOCOL_IP4, MFIB_SOURCE_INTERFACE); if (0 != table_id) { /* we need to lock the table now it's inuse */ - fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP4, - table_id, src); - - mfib_index = mfib_table_find_or_create_and_lock (FIB_PROTOCOL_IP4, - table_id, msrc); + mfib_index = mfib_table_find_or_create_and_lock ( + FIB_PROTOCOL_IP4, table_id, MFIB_SOURCE_INTERFACE); } - ip4_main.fib_index_by_sw_if_index[sw_if_index] = fib_index; ip4_main.mfib_index_by_sw_if_index[sw_if_index] = mfib_index; } +} + +int +ip_table_bind (fib_protocol_t fproto, u32 sw_if_index, u32 table_id) +{ + CLIB_UNUSED (ip_interface_address_t * ia); + u32 fib_index, mfib_index; + + /* + * This if table does not exist = error is what we want in the end. + */ + fib_index = fib_table_find (fproto, table_id); + mfib_index = mfib_table_find (fproto, table_id); + + if (~0 == fib_index || ~0 == mfib_index) + { + return (VNET_API_ERROR_NO_SUCH_FIB); + } + + /* + * If the interface already has in IP address, then a change int + * VRF is not allowed. The IP address applied must first be removed. + * We do not do that automatically here, since VPP has no knowledge + * of whether those subnets are valid in the destination VRF. + */ + /* clang-format off */ + foreach_ip_interface_address (FIB_PROTOCOL_IP6 == fproto ? + &ip6_main.lookup_main : &ip4_main.lookup_main, + ia, sw_if_index, + 1 /* honor unnumbered */ , + ({ + return (VNET_API_ERROR_ADDRESS_FOUND_FOR_INTERFACE); + })); + /* clang-format on */ + + fib_table_bind (fproto, sw_if_index, fib_index); + mfib_table_bind (fproto, sw_if_index, mfib_index); return (0); }