X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fip%2Fip_api.c;h=5b87f7cc86a8f83934b4d3ce46d5a76126505a33;hb=8f5fef2c7;hp=448b36c6acc35fe45c5f50491ebb37bd79bdd5ea;hpb=990f69450781f1110056738707e3fed565262554;p=vpp.git diff --git a/src/vnet/ip/ip_api.c b/src/vnet/ip/ip_api.c index 448b36c6acc..5b87f7cc86a 100644 --- a/src/vnet/ip/ip_api.c +++ b/src/vnet/ip/ip_api.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -45,6 +46,7 @@ #include #include #include +#include #include @@ -66,40 +68,48 @@ #include -#define foreach_ip_api_msg \ -_(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable) \ -_(IP_TABLE_DUMP, ip_table_dump) \ -_(IP_ROUTE_DUMP, ip_route_dump) \ -_(IP_MTABLE_DUMP, ip_mtable_dump) \ -_(IP_MROUTE_DUMP, ip_mroute_dump) \ -_(IP_MROUTE_ADD_DEL, ip_mroute_add_del) \ -_(MFIB_SIGNAL_DUMP, mfib_signal_dump) \ -_(IP_ADDRESS_DUMP, ip_address_dump) \ -_(IP_UNNUMBERED_DUMP, ip_unnumbered_dump) \ -_(IP_DUMP, ip_dump) \ -_(IP_TABLE_REPLACE_BEGIN, ip_table_replace_begin) \ -_(IP_TABLE_REPLACE_END, ip_table_replace_end) \ -_(IP_TABLE_FLUSH, ip_table_flush) \ -_(IP_ROUTE_ADD_DEL, ip_route_add_del) \ -_(IP_ROUTE_LOOKUP, ip_route_lookup) \ -_(IP_TABLE_ADD_DEL, ip_table_add_del) \ -_(IP_PUNT_POLICE, ip_punt_police) \ -_(IP_PUNT_REDIRECT, ip_punt_redirect) \ -_(SET_IP_FLOW_HASH,set_ip_flow_hash) \ -_(IP_CONTAINER_PROXY_ADD_DEL, ip_container_proxy_add_del) \ -_(IP_CONTAINER_PROXY_DUMP, ip_container_proxy_dump) \ -_(IOAM_ENABLE, ioam_enable) \ -_(IOAM_DISABLE, ioam_disable) \ -_(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \ - ip_source_and_port_range_check_add_del) \ -_(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \ - ip_source_and_port_range_check_interface_add_del) \ - _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \ - sw_interface_ip6_set_link_local_address) \ -_(IP_REASSEMBLY_SET, ip_reassembly_set) \ -_(IP_REASSEMBLY_GET, ip_reassembly_get) \ -_(IP_REASSEMBLY_ENABLE_DISABLE, ip_reassembly_enable_disable) \ -_(IP_PUNT_REDIRECT_DUMP, ip_punt_redirect_dump) +#define foreach_ip_api_msg \ + _ (SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable) \ + _ (IP_TABLE_DUMP, ip_table_dump) \ + _ (IP_ROUTE_DUMP, ip_route_dump) \ + _ (IP_MTABLE_DUMP, ip_mtable_dump) \ + _ (IP_MROUTE_DUMP, ip_mroute_dump) \ + _ (IP_MROUTE_ADD_DEL, ip_mroute_add_del) \ + _ (MFIB_SIGNAL_DUMP, mfib_signal_dump) \ + _ (IP_ADDRESS_DUMP, ip_address_dump) \ + _ (IP_UNNUMBERED_DUMP, ip_unnumbered_dump) \ + _ (IP_DUMP, ip_dump) \ + _ (IP_TABLE_REPLACE_BEGIN, ip_table_replace_begin) \ + _ (IP_TABLE_REPLACE_END, ip_table_replace_end) \ + _ (IP_TABLE_FLUSH, ip_table_flush) \ + _ (IP_ROUTE_ADD_DEL, ip_route_add_del) \ + _ (IP_ROUTE_LOOKUP, ip_route_lookup) \ + _ (IP_TABLE_ADD_DEL, ip_table_add_del) \ + _ (IP_PUNT_POLICE, ip_punt_police) \ + _ (IP_PUNT_REDIRECT, ip_punt_redirect) \ + _ (SET_IP_FLOW_HASH, set_ip_flow_hash) \ + _ (SET_IP_FLOW_HASH_V2, set_ip_flow_hash_v2) \ + _ (SET_IP_FLOW_HASH_ROUTER_ID, set_ip_flow_hash_router_id) \ + _ (IP_CONTAINER_PROXY_ADD_DEL, ip_container_proxy_add_del) \ + _ (IP_CONTAINER_PROXY_DUMP, ip_container_proxy_dump) \ + _ (IOAM_ENABLE, ioam_enable) \ + _ (IOAM_DISABLE, ioam_disable) \ + _ (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \ + ip_source_and_port_range_check_add_del) \ + _ (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \ + ip_source_and_port_range_check_interface_add_del) \ + _ (SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \ + sw_interface_ip6_set_link_local_address) \ + _ (SW_INTERFACE_IP6_GET_LINK_LOCAL_ADDRESS, \ + sw_interface_ip6_get_link_local_address) \ + _ (IP_REASSEMBLY_SET, ip_reassembly_set) \ + _ (IP_REASSEMBLY_GET, ip_reassembly_get) \ + _ (IP_REASSEMBLY_ENABLE_DISABLE, ip_reassembly_enable_disable) \ + _ (IP_PUNT_REDIRECT_DUMP, ip_punt_redirect_dump) \ + _ (IP_PATH_MTU_UPDATE, ip_path_mtu_update) \ + _ (IP_PATH_MTU_REPLACE_BEGIN, ip_path_mtu_replace_begin) \ + _ (IP_PATH_MTU_REPLACE_END, ip_path_mtu_replace_end) \ + _ (IP_PATH_MTU_GET, ip_path_mtu_get) static void vl_api_sw_interface_ip6_enable_disable_t_handler @@ -153,17 +163,17 @@ vl_api_ip_table_dump_t_handler (vl_api_ip_table_dump_t * mp) return; /* *INDENT-OFF* */ - pool_foreach (fib_table, ip4_main.fibs, - ({ + pool_foreach (fib_table, ip4_main.fibs) + { send_ip_table_details(am, reg, mp->context, fib_table); - })); - pool_foreach (fib_table, ip6_main.fibs, - ({ + } + pool_foreach (fib_table, ip6_main.fibs) + { /* don't send link locals */ if (fib_table->ft_flags & FIB_TABLE_FLAG_IP6_LL) continue; send_ip_table_details(am, reg, mp->context, fib_table); - })); + } /* *INDENT-ON* */ } @@ -293,14 +303,14 @@ vl_api_ip_mtable_dump_t_handler (vl_api_ip_mtable_dump_t * mp) return; /* *INDENT-OFF* */ - pool_foreach (mfib_table, ip4_main.mfibs, - ({ + pool_foreach (mfib_table, ip4_main.mfibs) + { send_ip_mtable_details (reg, mp->context, mfib_table); - })); - pool_foreach (mfib_table, ip6_main.mfibs, - ({ + } + pool_foreach (mfib_table, ip6_main.mfibs) + { send_ip_mtable_details (reg, mp->context, mfib_table); - })); + } /* *INDENT-ON* */ } @@ -949,8 +959,8 @@ vl_api_ip_unnumbered_dump_t_handler (vl_api_ip_unnumbered_dump_t * mp) else { /* *INDENT-OFF* */ - pool_foreach (si, im->sw_interfaces, - ({ + pool_foreach (si, im->sw_interfaces) + { if ((si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) { send_ip_unnumbered_details(am, reg, @@ -958,7 +968,7 @@ vl_api_ip_unnumbered_dump_t_handler (vl_api_ip_unnumbered_dump_t * mp) si->unnumbered_sw_if_index, mp->context); } - })); + } /* *INDENT-ON* */ } @@ -984,10 +994,10 @@ vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp) sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces)); _vec_len (sorted_sis) = 0; /* *INDENT-OFF* */ - pool_foreach (si, im->sw_interfaces, - ({ + pool_foreach (si, im->sw_interfaces) + { vec_add1 (sorted_sis, si[0]); - })); + } /* *INDENT-ON* */ vec_foreach (si, sorted_sis) @@ -1007,7 +1017,7 @@ vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp) } static void -set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp) +vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t *mp) { vl_api_set_ip_flow_hash_reply_t *rmp; int rv; @@ -1017,41 +1027,41 @@ set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp) table_id = ntohl (mp->vrf_id); #define _(a,b) if (mp->a) flow_hash_config |= b; - foreach_flow_hash_bit; + foreach_flow_hash_bit_v1; #undef _ - rv = vnet_set_ip6_flow_hash (table_id, flow_hash_config); + rv = ip_flow_hash_set ((mp->is_ipv6 ? AF_IP6 : AF_IP4), table_id, + flow_hash_config); REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY); } static void -set_ip4_flow_hash (vl_api_set_ip_flow_hash_t * mp) +vl_api_set_ip_flow_hash_v2_t_handler (vl_api_set_ip_flow_hash_v2_t *mp) { - vl_api_set_ip_flow_hash_reply_t *rmp; + vl_api_set_ip_flow_hash_v2_reply_t *rmp; + ip_address_family_t af; int rv; - u32 table_id; - flow_hash_config_t flow_hash_config = 0; - table_id = ntohl (mp->vrf_id); + rv = ip_address_family_decode (mp->af, &af); -#define _(a,b) if (mp->a) flow_hash_config |= b; - foreach_flow_hash_bit; -#undef _ + if (!rv) + rv = ip_flow_hash_set (af, htonl (mp->table_id), + htonl (mp->flow_hash_config)); - rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config); - - REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY); + REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_V2_REPLY); } - static void -vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t * mp) +vl_api_set_ip_flow_hash_router_id_t_handler ( + vl_api_set_ip_flow_hash_router_id_t *mp) { - if (mp->is_ipv6 == 0) - set_ip4_flow_hash (mp); - else - set_ip6_flow_hash (mp); + vl_api_set_ip_flow_hash_router_id_reply_t *rmp; + int rv = 0; + + ip_flow_hash_router_id_set (ntohl (mp->router_id)); + + REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_ROUTER_ID_REPLY); } void @@ -1129,18 +1139,18 @@ static void REPLY_MACRO (VL_API_IP_CONTAINER_PROXY_ADD_DEL_REPLY); } -typedef struct ip_container_proxy_walk_ctx_t_ +typedef struct ip_walk_ctx_t_ { vl_api_registration_t *reg; u32 context; -} ip_container_proxy_walk_ctx_t; +} ip_walk_ctx_t; static int ip_container_proxy_send_details (const fib_prefix_t * pfx, u32 sw_if_index, void *args) { vl_api_ip_container_proxy_details_t *mp; - ip_container_proxy_walk_ctx_t *ctx = args; + ip_walk_ctx_t *ctx = args; mp = vl_msg_api_alloc (sizeof (*mp)); if (!mp) @@ -1168,7 +1178,7 @@ vl_api_ip_container_proxy_dump_t_handler (vl_api_ip_container_proxy_dump_t * if (!reg) return; - ip_container_proxy_walk_ctx_t ctx = { + ip_walk_ctx_t ctx = { .context = mp->context, .reg = reg, }; @@ -1362,6 +1372,30 @@ static void REPLY_MACRO (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY); } +static void +vl_api_sw_interface_ip6_get_link_local_address_t_handler ( + vl_api_sw_interface_ip6_get_link_local_address_t *mp) +{ + vl_api_sw_interface_ip6_get_link_local_address_reply_t *rmp; + const ip6_address_t *ip = NULL; + int rv = 0; + + VALIDATE_SW_IF_INDEX (mp); + + ip = ip6_get_link_local_address (ntohl (mp->sw_if_index)); + if (NULL == ip) + rv = VNET_API_ERROR_IP6_NOT_ENABLED; + + BAD_SW_IF_INDEX_LABEL; + /* clang-format off */ + REPLY_MACRO2 (VL_API_SW_INTERFACE_IP6_GET_LINK_LOCAL_ADDRESS_REPLY, + ({ + if (!rv) + ip6_address_encode (ip, rmp->ip); + })) + /* clang-format on */ +} + static void vl_api_ip_table_replace_begin_t_handler (vl_api_ip_table_replace_begin_t * mp) { @@ -1428,8 +1462,8 @@ vl_api_ip_table_flush_t_handler (vl_api_ip_table_flush_t * mp) /* Shut down interfaces in this FIB / clean out intfc routes */ /* *INDENT-OFF* */ - pool_foreach (si, im->sw_interfaces, - ({ + pool_foreach (si, im->sw_interfaces) + { if (fib_index == fib_table_get_index_for_sw_if_index (fproto, si->sw_if_index)) { @@ -1437,7 +1471,7 @@ vl_api_ip_table_flush_t_handler (vl_api_ip_table_flush_t * mp) flags &= ~VNET_SW_INTERFACE_FLAG_ADMIN_UP; vnet_sw_interface_set_flags (vnm, si->sw_if_index, flags); } - })); + } /* *INDENT-ON* */ fib_table_flush (fib_index, fproto, FIB_SOURCE_API); @@ -1595,21 +1629,15 @@ void REPLY_MACRO (VL_API_IP_REASSEMBLY_ENABLE_DISABLE_REPLY); } -typedef struct ip_punt_redirect_walk_ctx_t_ -{ - vl_api_registration_t *reg; - u32 context; -} ip_punt_redirect_walk_ctx_t; - static walk_rc_t send_ip_punt_redirect_details (u32 rx_sw_if_index, const ip_punt_redirect_rx_t * ipr, void *arg) { - ip_punt_redirect_walk_ctx_t *ctx = arg; vl_api_ip_punt_redirect_details_t *mp; fib_path_encode_ctx_t path_ctx = { .rpaths = NULL, }; + ip_walk_ctx_t *ctx = arg; mp = vl_msg_api_alloc (sizeof (*mp)); if (!mp) @@ -1647,7 +1675,7 @@ vl_api_ip_punt_redirect_dump_t_handler (vl_api_ip_punt_redirect_dump_t * mp) if (mp->is_ipv6 == 1) fproto = FIB_PROTOCOL_IP6; - ip_punt_redirect_walk_ctx_t ctx = { + ip_walk_ctx_t ctx = { .reg = reg, .context = mp->context, }; @@ -1670,6 +1698,73 @@ vl_api_ip_punt_redirect_dump_t_handler (vl_api_ip_punt_redirect_dump_t * mp) ip_punt_redirect_walk (fproto, send_ip_punt_redirect_details, &ctx); } +void +vl_api_ip_path_mtu_update_t_handler (vl_api_ip_path_mtu_update_t *mp) +{ + vl_api_ip_path_mtu_update_reply_t *rmp; + ip_address_t nh; + int rv = 0; + + ip_address_decode2 (&mp->pmtu.nh, &nh); + + rv = ip_path_mtu_update (&nh, ntohl (mp->pmtu.table_id), + ntohs (mp->pmtu.path_mtu)); + + REPLY_MACRO (VL_API_IP_PATH_MTU_UPDATE_REPLY); +} + +void +vl_api_ip_path_mtu_replace_begin_t_handler ( + vl_api_ip_path_mtu_replace_begin_t *mp) +{ + vl_api_ip_path_mtu_replace_begin_reply_t *rmp; + int rv; + + rv = ip_path_mtu_replace_begin (); + + REPLY_MACRO (VL_API_IP_PATH_MTU_REPLACE_BEGIN_REPLY); +} + +void +vl_api_ip_path_mtu_replace_end_t_handler (vl_api_ip_path_mtu_replace_end_t *mp) +{ + vl_api_ip_path_mtu_replace_end_reply_t *rmp; + int rv; + + rv = ip_path_mtu_replace_end (); + + REPLY_MACRO (VL_API_IP_PATH_MTU_REPLACE_END_REPLY); +} + +static void +send_ip_path_mtu_details (index_t ipti, vl_api_registration_t *rp, u32 context) +{ + vl_api_ip_path_mtu_details_t *rmp; + ip_address_t ip; + ip_pmtu_t *ipt; + + ipt = ip_path_mtu_get (ipti); + + REPLY_MACRO_DETAILS4 (VL_API_IP_PATH_MTU_DETAILS, rp, context, ({ + ip_pmtu_get_ip (ipt, &ip); + ip_address_encode2 (&ip, &rmp->pmtu.nh); + rmp->pmtu.table_id = + htonl (ip_pmtu_get_table_id (ipt)); + rmp->pmtu.path_mtu = htons (ipt->ipt_cfg_pmtu); + })); +} + +static void +vl_api_ip_path_mtu_get_t_handler (vl_api_ip_path_mtu_get_t *mp) +{ + vl_api_ip_path_mtu_get_reply_t *rmp; + i32 rv = 0; + + REPLY_AND_DETAILS_MACRO ( + VL_API_IP_PATH_MTU_GET_REPLY, ip_pmtu_pool, + ({ send_ip_path_mtu_details (cursor, rp, mp->context); })); +} + #define vl_msg_name_crc_list #include #undef vl_msg_name_crc_list