/* *------------------------------------------------------------------ * ip_api.c - vnet ip api * * Copyright (c) 2016 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *------------------------------------------------------------------ */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define vl_typedefs /* define message structures */ #include #undef vl_typedefs #define vl_endianfun /* define message structures */ #include #undef vl_endianfun /* instantiate all the print functions we know about */ #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) #define vl_printfun #include #undef vl_printfun #include #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) \ _ (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) static void vl_api_sw_interface_ip6_enable_disable_t_handler (vl_api_sw_interface_ip6_enable_disable_t * mp) { vl_api_sw_interface_ip6_enable_disable_reply_t *rmp; int rv = 0; VALIDATE_SW_IF_INDEX (mp); rv = ((mp->enable == 1) ? ip6_link_enable (ntohl (mp->sw_if_index), NULL) : ip6_link_disable (ntohl (mp->sw_if_index))); BAD_SW_IF_INDEX_LABEL; REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY); } static void send_ip_table_details (vpe_api_main_t * am, vl_api_registration_t * reg, u32 context, const fib_table_t * table) { vl_api_ip_table_details_t *mp; mp = vl_msg_api_alloc (sizeof (*mp)); if (!mp) return; clib_memset (mp, 0, sizeof (*mp)); mp->_vl_msg_id = ntohs (VL_API_IP_TABLE_DETAILS); mp->context = context; mp->table.is_ip6 = (table->ft_proto == FIB_PROTOCOL_IP6); mp->table.table_id = htonl (table->ft_table_id); memcpy (mp->table.name, table->ft_desc, clib_min (vec_len (table->ft_desc), sizeof (mp->table.name))); vl_api_send_msg (reg, (u8 *) mp); } static void vl_api_ip_table_dump_t_handler (vl_api_ip_table_dump_t * mp) { vpe_api_main_t *am = &vpe_api_main; vl_api_registration_t *reg; fib_table_t *fib_table; reg = vl_api_client_index_to_registration (mp->client_index); if (!reg) return; /* *INDENT-OFF* */ pool_foreach (fib_table, ip4_main.fibs) { send_ip_table_details(am, reg, mp->context, fib_table); } 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* */ } typedef struct vl_api_ip_fib_dump_walk_ctx_t_ { fib_node_index_t *feis; } vl_api_ip_fib_dump_walk_ctx_t; static fib_table_walk_rc_t vl_api_ip_fib_dump_walk (fib_node_index_t fei, void *arg) { vl_api_ip_fib_dump_walk_ctx_t *ctx = arg; vec_add1 (ctx->feis, fei); return (FIB_TABLE_WALK_CONTINUE); } static void send_ip_route_details (vpe_api_main_t * am, vl_api_registration_t * reg, u32 context, fib_node_index_t fib_entry_index) { fib_route_path_t *rpaths, *rpath; vl_api_ip_route_details_t *mp; const fib_prefix_t *pfx; vl_api_fib_path_t *fp; int path_count; rpaths = NULL; pfx = fib_entry_get_prefix (fib_entry_index); rpaths = fib_entry_encode (fib_entry_index); path_count = vec_len (rpaths); mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp)); if (!mp) return; clib_memset (mp, 0, sizeof (*mp)); mp->_vl_msg_id = ntohs (VL_API_IP_ROUTE_DETAILS); mp->context = context; ip_prefix_encode (pfx, &mp->route.prefix); mp->route.table_id = htonl (fib_table_get_table_id (fib_entry_get_fib_index (fib_entry_index), pfx->fp_proto)); mp->route.n_paths = path_count; mp->route.stats_index = htonl (fib_table_entry_get_stats_index (fib_entry_get_fib_index (fib_entry_index), pfx)); fp = mp->route.paths; vec_foreach (rpath, rpaths) { fib_api_path_encode (rpath, fp); fp++; } vl_api_send_msg (reg, (u8 *) mp); vec_free (rpaths); } typedef struct apt_ip6_fib_show_ctx_t_ { fib_node_index_t *entries; } api_ip6_fib_show_ctx_t; static void vl_api_ip_route_dump_t_handler (vl_api_ip_route_dump_t * mp) { vpe_api_main_t *am = &vpe_api_main; fib_node_index_t *fib_entry_index; vl_api_registration_t *reg; fib_protocol_t fproto; u32 fib_index; reg = vl_api_client_index_to_registration (mp->client_index); if (!reg) return; vl_api_ip_fib_dump_walk_ctx_t ctx = { .feis = NULL, }; fproto = (mp->table.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4); fib_index = fib_table_find (fproto, ntohl (mp->table.table_id)); if (INDEX_INVALID == fib_index) return; fib_table_walk (fib_index, fproto, vl_api_ip_fib_dump_walk, &ctx); vec_foreach (fib_entry_index, ctx.feis) { send_ip_route_details (am, reg, mp->context, *fib_entry_index); } vec_free (ctx.feis); } static void send_ip_mtable_details (vl_api_registration_t * reg, u32 context, const mfib_table_t * mfib_table) { vl_api_ip_mtable_details_t *mp; mp = vl_msg_api_alloc (sizeof (*mp)); if (!mp) return; memset (mp, 0, sizeof (*mp)); mp->_vl_msg_id = ntohs (VL_API_IP_MTABLE_DETAILS); mp->context = context; mp->table.table_id = htonl (mfib_table->mft_table_id); mp->table.is_ip6 = (FIB_PROTOCOL_IP6 == mfib_table->mft_proto); vl_api_send_msg (reg, (u8 *) mp); } static void vl_api_ip_mtable_dump_t_handler (vl_api_ip_mtable_dump_t * mp) { vl_api_registration_t *reg; mfib_table_t *mfib_table; reg = vl_api_client_index_to_registration (mp->client_index); if (!reg) return; /* *INDENT-OFF* */ pool_foreach (mfib_table, ip4_main.mfibs) { send_ip_mtable_details (reg, mp->context, mfib_table); } pool_foreach (mfib_table, ip6_main.mfibs) { send_ip_mtable_details (reg, mp->c
/*
 * Copyright (c) 2015 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 * osi.h: OSI definitions
 *
 * Copyright (c) 2008 Eliot Dresselhaus
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#ifndef included_osi_h
#define included_osi_h

#include <vnet/vnet.h>
#include <vnet/pg/pg.h>

#define foreach_osi_protocol			\
  _ (null, 0x0)					\
  _ (x_29, 0x01)				\
  _ (x_633, 0x03)				\
  _ (q_931, 0x08)				\
  _ (q_933, 0x08)				\
  _ (q_2931, 0x09)				\
  _ (q_2119, 0x0c)				\
  _ (snap, 0x80)				\
  _ (clnp, 0x81)				\
  _ (esis, 0x82)				\
  _ (isis, 0x83)				\
  _ (idrp, 0x85)				\
  _ (x25_esis, 0x8a)				\
  _ (iso10030, 0x8c)				\
  _ (iso11577, 0x8d)				\
  _ (ip6, 0x8e)					\
  _ (compressed, 0xb0)				\
  _ (sndcf, 0xc1)				\
  _ (ip4, 0xcc)					\
  _ (ppp, 0xcf)

typedef enum
{
#define _(f,n) OSI_PROTOCOL_##f = n,
  foreach_osi_protocol
#undef _
} osi_protocol_t;

typedef struct
{
  u8 protocol;

  u8 payload[0];
} osi_header_t;

typedef struct
{
  /* Name (a c string). */
  char *name;

  /* OSI protocol (SAP type). */
  osi_protocol_t protocol;

  /* Node which handles this type. */
  u32 node_index;

  /* Next index for this type. */
  u32 next_index;
} osi_protocol_info_t;

#define foreach_osi_error			\
  _ (NONE, "no error")				\
  _ (UNKNOWN_PROTOCOL, "unknown osi protocol")

typedef enum
{
#define _(f,s) OSI_ERROR_##f,
  foreach_osi_error
#undef _
    OSI_N_ERROR,
} osi_error_t;

typedef struct
{
  vlib_main_t *vlib_main;

  osi_protocol_info_t *protocol_infos;

  /* Hash tables mapping name/protocol to protocol info index. */
  uword *protocol_info_by_name, *protocol_info_by_protocol;

  /* osi-input next index indexed by protocol. */
  u8 input_next_by_protocol[256];
} osi_main_t;

always_inline osi_protocol_info_t *
osi_get_protocol_info (osi_main_t * m, osi_protocol_t protocol)
{
  uword *p = hash_get (m->protocol_info_by_protocol, protocol);
  return p ? vec_elt_at_index (m->protocol_infos, p[0]) : 0;
}

extern osi_main_t osi_main;

/* Register given node index to take input for given osi type. */
void osi_register_input_protocol (osi_protocol_t protocol, u32 node_index);

format_function_t format_osi_protocol;
format_function_t format_osi_header;
format_function_t format_osi_header_with_length;

/* Parse osi protocol as 0xXXXX or protocol name. */
unformat_function_t unformat_osi_protocol;

/* Parse osi header. */
unformat_function_t unformat_osi_header;
unformat_function_t unformat_pg_osi_header;

always_inline void
osi_setup_node (vlib_main_t * vm, u32 node_index)
{
  vlib_node_t *n = vlib_get_node (vm, node_index);
  pg_node_t *pn = pg_get_node (node_index);

  n->format_buffer = format_osi_header_with_length;
  n->unformat_buffer = unformat_osi_header;
  pn->unformat_edit = unformat_pg_osi_header;
}

void osi_register_input_protocol (osi_protocol_t protocol, u32 node_index);

format_function_t format_osi_header;

#endif /* included_osi_h */

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */
ble_reply_t *rmp; clib_error_t *error; /* Ignoring the profile id as currently a single profile * is supported */ error = ip6_ioam_enable (mp->trace_enable, mp->pot_enable, mp->seqno, mp->analyse); if (error) { clib_error_report (error); rv = clib_error_get_code (error); } REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY); } static void vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp) { int rv = 0; vl_api_ioam_disable_reply_t *rmp; clib_error_t *error; error = clear_ioam_rewrite_fn (); if (error) { clib_error_report (error); rv = clib_error_get_code (error); } REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY); } static void vl_api_ip_source_and_port_range_check_add_del_t_handler (vl_api_ip_source_and_port_range_check_add_del_t * mp) { vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp; int rv = 0; u8 is_add = mp->is_add; fib_prefix_t pfx; u16 *low_ports = 0; u16 *high_ports = 0; u32 vrf_id; u16 tmp_low, tmp_high; u8 num_ranges; int i; ip_prefix_decode (&mp->prefix, &pfx); // Validate port range num_ranges = mp->number_of_ranges; if (num_ranges > 32) { // This is size of array in VPE.API rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY; goto reply; } vec_reset_length (low_ports); vec_reset_length (high_ports); for (i = 0; i < num_ranges; i++) { tmp_low = mp->low_ports[i]; tmp_high = mp->high_ports[i]; // If tmp_low <= tmp_high then only need to check tmp_low = 0 // If tmp_low <= tmp_high then only need to check tmp_high > 65535 if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535) { rv = VNET_API_ERROR_INVALID_VALUE; goto reply; } vec_add1 (low_ports, tmp_low); vec_add1 (high_ports, tmp_high + 1); } vrf_id = ntohl (mp->vrf_id); if (vrf_id < 1) { rv = VNET_API_ERROR_INVALID_VALUE; goto reply; } if (FIB_PROTOCOL_IP6 == pfx.fp_proto) { rv = ip6_source_and_port_range_check_add_del (&pfx.fp_addr.ip6, pfx.fp_len, vrf_id, low_ports, high_ports, is_add); } else { rv = ip4_source_and_port_range_check_add_del (&pfx.fp_addr.ip4, pfx.fp_len, vrf_id, low_ports, high_ports, is_add); } reply: vec_free (low_ports); vec_free (high_ports); REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY); } static void vl_api_ip_source_and_port_range_check_interface_add_del_t_handler (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp) { vlib_main_t *vm = vlib_get_main (); vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp; ip4_main_t *im = &ip4_main; int rv; u32 sw_if_index; u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS]; u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS]; uword *p = 0; int i; vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] = ntohl (mp->tcp_out_vrf_id); vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] = ntohl (mp->udp_out_vrf_id); vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] = ntohl (mp->tcp_in_vrf_id); vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] = ntohl (mp->udp_in_vrf_id); for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++) { if (vrf_id[i] != 0 && vrf_id[i] != ~0) { p = hash_get (im->fib_index_by_table_id, vrf_id[i]); if (p == 0) { rv = VNET_API_ERROR_INVALID_VALUE; goto reply; } fib_index[i] = p[0]; } else fib_index[i] = ~0; } sw_if_index = ntohl (mp->sw_if_index); VALIDATE_SW_IF_INDEX (mp); rv = set_ip_source_and_port_range_check (vm, fib_index, sw_if_index, mp->is_add); BAD_SW_IF_INDEX_LABEL; reply: REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY); } static void vl_api_sw_interface_ip6_set_link_local_address_t_handler (vl_api_sw_interface_ip6_set_link_local_address_t * mp) { vl_api_sw_interface_ip6_set_link_local_address_reply_t *rmp; ip6_address_t ip; int rv; VALIDATE_SW_IF_INDEX (mp); ip6_address_decode (mp->ip, &ip); rv = ip6_link_set_local_address (ntohl (mp->sw_if_index), &ip); BAD_SW_IF_INDEX_LABEL; 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) { vl_api_ip_table_replace_begin_reply_t *rmp; fib_protocol_t fproto; u32 fib_index; int rv = 0; fproto = (mp->table.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4); fib_index = fib_table_find (fproto, ntohl (mp->table.table_id)); if (INDEX_INVALID == fib_index) rv = VNET_API_ERROR_NO_SUCH_FIB; else { 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); } REPLY_MACRO (VL_API_IP_TABLE_REPLACE_BEGIN_REPLY); } static void vl_api_ip_table_replace_end_t_handler (vl_api_ip_table_replace_end_t * mp) { vl_api_ip_table_replace_end_reply_t *rmp; fib_protocol_t fproto; u32 fib_index; int rv = 0; fproto = (mp->table.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4); fib_index = fib_table_find (fproto, ntohl (mp->table.table_id)); if (INDEX_INVALID == fib_index) rv = VNET_API_ERROR_NO_SUCH_FIB; else { 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); } REPLY_MACRO (VL_API_IP_TABLE_REPLACE_END_REPLY); } static void vl_api_ip_table_flush_t_handler (vl_api_ip_table_flush_t * mp) { vl_api_ip_table_flush_reply_t *rmp; fib_protocol_t fproto; u32 fib_index; int rv = 0; fproto = (mp->table.is_ip6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4); fib_index = fib_table_find (fproto, ntohl (mp->table.table_id)); if (INDEX_INVALID == fib_index) rv = VNET_API_ERROR_NO_SUCH_FIB; else { vnet_main_t *vnm = vnet_get_main (); vnet_interface_main_t *im = &vnm->interface_main; vnet_sw_interface_t *si; /* Shut down interfaces in this FIB / clean out intfc routes */ /* *INDENT-OFF* */ pool_foreach (si, im->sw_interfaces) { if (fib_index == fib_table_get_index_for_sw_if_index (fproto, si->sw_if_index)) { u32 flags = si->flags; 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); mfib_table_flush (mfib_table_find (fproto, ntohl (mp->table.table_id)), fproto, MFIB_SOURCE_API); } REPLY_MACRO (VL_API_IP_TABLE_FLUSH_REPLY); } void vl_api_ip_reassembly_set_t_handler (vl_api_ip_reassembly_set_t * mp) { vl_api_ip_reassembly_set_reply_t *rmp; int rv = 0; switch ((vl_api_ip_reass_type_t) clib_net_to_host_u32 (mp->type)) { case IP_REASS_TYPE_FULL: if (mp->is_ip6) { rv = ip6_full_reass_set (clib_net_to_host_u32 (mp->timeout_ms), clib_net_to_host_u32 (mp->max_reassemblies), clib_net_to_host_u32 (mp->max_reassembly_length), clib_net_to_host_u32 (mp->expire_walk_interval_ms)); } else { rv = ip4_full_reass_set (clib_net_to_host_u32 (mp->timeout_ms), clib_net_to_host_u32 (mp->max_reassemblies), clib_net_to_host_u32 (mp->max_reassembly_length), clib_net_to_host_u32 (mp->expire_walk_interval_ms)); } break; case IP_REASS_TYPE_SHALLOW_VIRTUAL: if (mp->is_ip6) { rv = ip6_sv_reass_set (clib_net_to_host_u32 (mp->timeout_ms), clib_net_to_host_u32 (mp->max_reassemblies), clib_net_to_host_u32 (mp->max_reassembly_length), clib_net_to_host_u32 (mp->expire_walk_interval_ms)); } else { rv = ip4_sv_reass_set (clib_net_to_host_u32 (mp->timeout_ms), clib_net_to_host_u32 (mp->max_reassemblies), clib_net_to_host_u32 (mp->max_reassembly_length), clib_net_to_host_u32 (mp->expire_walk_interval_ms)); } break; } REPLY_MACRO (VL_API_IP_REASSEMBLY_SET_REPLY); } void vl_api_ip_reassembly_get_t_handler (vl_api_ip_reassembly_get_t * mp) { vl_api_registration_t *rp; rp = vl_api_client_index_to_registration (mp->client_index); if (rp == 0) return; vl_api_ip_reassembly_get_reply_t *rmp = vl_msg_api_alloc (sizeof (*rmp)); clib_memset (rmp, 0, sizeof (*rmp)); rmp->_vl_msg_id = ntohs (VL_API_IP_REASSEMBLY_GET_REPLY); rmp->context = mp->context; rmp->retval = 0; u32 timeout_ms; u32 max_reassemblies; u32 max_reassembly_length; u32 expire_walk_interval_ms; switch ((vl_api_ip_reass_type_t) clib_net_to_host_u32 (mp->type)) { case IP_REASS_TYPE_FULL: if (mp->is_ip6) { rmp->is_ip6 = 1; ip6_full_reass_get (&timeout_ms, &max_reassemblies, &max_reassembly_length, &expire_walk_interval_ms); } else { rmp->is_ip6 = 0; ip4_full_reass_get (&timeout_ms, &max_reassemblies, &max_reassembly_length, &expire_walk_interval_ms); } break; case IP_REASS_TYPE_SHALLOW_VIRTUAL: if (mp->is_ip6) { rmp->is_ip6 = 1; ip6_sv_reass_get (&timeout_ms, &max_reassemblies, &max_reassembly_length, &expire_walk_interval_ms); } else { rmp->is_ip6 = 0; ip4_sv_reass_get (&timeout_ms, &max_reassemblies, &max_reassembly_length, &expire_walk_interval_ms); } break; } rmp->timeout_ms = clib_host_to_net_u32 (timeout_ms); rmp->max_reassemblies = clib_host_to_net_u32 (max_reassemblies); rmp->max_reassembly_length = clib_host_to_net_u32 (max_reassembly_length); rmp->expire_walk_interval_ms = clib_host_to_net_u32 (expire_walk_interval_ms); vl_api_send_msg (rp, (u8 *) rmp); } void vl_api_ip_reassembly_enable_disable_t_handler (vl_api_ip_reassembly_enable_disable_t * mp) { vl_api_ip_reassembly_enable_disable_reply_t *rmp; int rv = 0; switch ((vl_api_ip_reass_type_t) clib_net_to_host_u32 (mp->type)) { case IP_REASS_TYPE_FULL: rv = ip4_full_reass_enable_disable (clib_net_to_host_u32 (mp->sw_if_index), mp->enable_ip4); if (0 == rv) rv = ip6_full_reass_enable_disable (clib_net_to_host_u32 (mp->sw_if_index), mp->enable_ip6); break; case IP_REASS_TYPE_SHALLOW_VIRTUAL: rv = ip4_sv_reass_enable_disable (clib_net_to_host_u32 (mp->sw_if_index), mp->enable_ip4); if (0 == rv) { rv = ip6_sv_reass_enable_disable (clib_net_to_host_u32 (mp->sw_if_index), mp->enable_ip6); } break; } 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, }; mp = vl_msg_api_alloc (sizeof (*mp)); if (!mp) return (WALK_STOP);; clib_memset (mp, 0, sizeof (*mp)); mp->_vl_msg_id = ntohs (VL_API_IP_PUNT_REDIRECT_DETAILS); mp->context = ctx->context; fib_path_list_walk_w_ext (ipr->pl, NULL, fib_path_encode, &path_ctx); mp->punt.rx_sw_if_index = htonl (rx_sw_if_index); mp->punt.tx_sw_if_index = htonl (path_ctx.rpaths[0].frp_sw_if_index); ip_address_encode (&path_ctx.rpaths[0].frp_addr, fib_proto_to_ip46 (ipr->fproto), &mp->punt.nh); vl_api_send_msg (ctx->reg, (u8 *) mp); vec_free (path_ctx.rpaths); return (WALK_CONTINUE); } static void vl_api_ip_punt_redirect_dump_t_handler (vl_api_ip_punt_redirect_dump_t * mp) { vl_api_registration_t *reg; fib_protocol_t fproto = FIB_PROTOCOL_IP4; reg = vl_api_client_index_to_registration (mp->client_index); if (!reg) return; if (mp->is_ipv6 == 1) fproto = FIB_PROTOCOL_IP6; ip_punt_redirect_walk_ctx_t ctx = { .reg = reg, .context = mp->context, }; if (~0 != mp->sw_if_index) { u32 rx_sw_if_index; index_t pri; rx_sw_if_index = ntohl (mp->sw_if_index); pri = ip_punt_redirect_find (fproto, rx_sw_if_index); if (INDEX_INVALID == pri) return; send_ip_punt_redirect_details (rx_sw_if_index, ip_punt_redirect_get (pri), &ctx); } else ip_punt_redirect_walk (fproto, send_ip_punt_redirect_details, &ctx); } #define vl_msg_name_crc_list #include #undef vl_msg_name_crc_list static void setup_message_id_table (api_main_t * am) { #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); foreach_vl_msg_name_crc_ip; #undef _ } static clib_error_t * ip_api_hookup (vlib_main_t * vm) { api_main_t *am = vlibapi_get_main (); #define _(N,n) \ vl_msg_api_set_handlers(VL_API_##N, #n, \ vl_api_##n##_t_handler, \ vl_noop_handler, \ vl_api_##n##_t_endian, \ vl_api_##n##_t_print, \ sizeof(vl_api_##n##_t), 1); foreach_ip_api_msg; #undef _ /* * Mark the route add/del API as MP safe */ am->is_mp_safe[VL_API_IP_ROUTE_ADD_DEL] = 1; am->is_mp_safe[VL_API_IP_ROUTE_ADD_DEL_REPLY] = 1; /* * Set up the (msg_name, crc, message-id) table */ setup_message_id_table (am); return 0; } VLIB_API_INIT_FUNCTION (ip_api_hookup); /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */