/* * 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. */ /* * ip/icmp6.c: ip6 icmp * * 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. */ #include #include #include #include #include /** ICMP throttling */ static throttle_t icmp_throttle; static u8 * format_ip6_icmp_type_and_code (u8 * s, va_list * args) { icmp6_type_t type = va_arg (*args, int); u8 code = va_arg (*args, int); char *t = 0; #define _(n,f) case n: t = #f; break; switch (type) { foreach_icmp6_type; default: break; } #undef _ if (!t) return format (s, "unknown 0x%x", type); s = format (s, "%s", t); t = 0; switch ((type << 8) | code) { #define _(a,n,f) case (ICMP6_##a << 8) | (n): t = #f; break; foreach_icmp6_code; #undef _ } if (t) s = format (s, " %s", t); return s; } static u8 * format_icmp6_header (u8 * s, va_list * args) { icmp46_header_t *icmp = va_arg (*args, icmp46_header_t *); u32 max_header_bytes = va_arg (*args, u32); /* Nothing to do. */ if (max_header_bytes < sizeof (icmp[0])) return format (s, "ICMP header truncated"); s = format (s, "ICMP %U checksum 0x%x", format_ip6_icmp_type_and_code, icmp->type, icmp->code, clib_net_to_host_u16 (icmp->checksum)); if (max_header_bytes >= sizeof (icmp6_neighbor_solicitation_or_advertisement_header_t) && (icmp->type == ICMP6_neighbor_solicitation || icmp->type == ICMP6_neighbor_advertisement)) { icmp6_neighbor_solicitation_or_advertisement_header_t *icmp6_nd = (icmp6_neighbor_solicitation_or_advertisement_header_t *) icmp; s = format (s, "\n target address %U", format_ip6_address, &icmp6_nd->target_address); } return s; } u8 * format_icmp6_input_trace (u8 * s, va_list * va) { CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *); CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *); icmp6_input_trace_t *t = va_arg (*va, icmp6_input_trace_t *); s = format (s, "%U", format_ip6_header, t->packet_data, sizeof (t->packet_data)); return s; } static char *icmp_error_strings[] = { #define _(f,s) s, foreach_icmp6_error #undef _ }; typedef enum { ICMP_INPUT_NEXT_PUNT, ICMP_INPUT_N_NEXT, } icmp_input_next_t; typedef struct { uword *type_and_code_by_name; uword *type_by_name; /* Vector dispatch table indexed by [icmp type]. */ u8 input_next_index_by_type[256]; /* Max valid code indexed by icmp type. */ u8 max_valid_code_by_type[256]; /* hop_limit must be >= this value for this icmp type. */ u8 min_valid_hop_limit_by_type[256]; u8 min_valid_length_by_type[256]; } icmp6_main_t; icmp6_main_t icmp6_main; static uword ip6_icmp_input (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) { icmp6_main_t *im = &icmp6_main; u32 *from, *to_next; u32 n_left_from, n_left_to_next, next_index; from = vlib_frame_vector_args (frame); n_left_from = frame->n_vectors; next_index = node->cached_next_index; if (node->flags & VLIB_NODE_FLAG_TRACE) vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors, /* stride */ 1, sizeo
Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
if (p->checksum.type == PG_EDIT_UNSPECIFIED) { pg_edit_group_t *g = pg_stream_get_group (s, group_index); g->edit_function = icmp6_pg_edit_function; g->edit_function_opaque = 0; } return 1; error: /* Free up any edits we may have added. */ pg_free_edit_group (s); return 0; } void icmp6_register_type (vlib_main_t * vm, icmp6_type_t type, u32 node_index) { icmp6_main_t *im = &icmp6_main; ASSERT ((int) type < ARRAY_LEN (im->input_next_index_by_type)); im->input_next_index_by_type[type] = vlib_node_add_next (vm, ip6_icmp_input_node.index, node_index); } static clib_error_t * icmp6_init (vlib_main_t * vm) { ip_main_t *im = &ip_main; ip_protocol_info_t *pi; icmp6_main_t *cm = &icmp6_main; clib_error_t *error; error = vlib_call_init_function (vm, ip_main_init); if (error) return error; pi = ip_get_protocol_info (im, IP_PROTOCOL_ICMP6); pi->format_header = format_icmp6_header; pi->unformat_pg_edit = unformat_pg_icmp_header; cm->type_by_name = hash_create_string (0, sizeof (uword)); #define _(n,t) hash_set_mem (cm->type_by_name, #t, (n)); foreach_icmp6_type; #undef _ cm->type_and_code_by_name = hash_create_string (0, sizeof (uword)); #define _(a,n,t) hash_set_mem (cm->type_by_name, #t, (n) | (ICMP6_##a << 8)); foreach_icmp6_code; #undef _ clib_memset (cm->input_next_index_by_type, ICMP_INPUT_NEXT_PUNT, sizeof (cm->input_next_index_by_type)); clib_memset (cm->max_valid_code_by_type, 0, sizeof (cm->max_valid_code_by_type)); #define _(a,n,t) cm->max_valid_code_by_type[ICMP6_##a] = clib_max (cm->max_valid_code_by_type[ICMP6_##a], n); foreach_icmp6_code; #undef _ clib_memset (cm->min_valid_hop_limit_by_type, 0, sizeof (cm->min_valid_hop_limit_by_type)); cm->min_valid_hop_limit_by_type[ICMP6_router_solicitation] = 255; cm->min_valid_hop_limit_by_type[ICMP6_router_advertisement] = 255; cm->min_valid_hop_limit_by_type[ICMP6_neighbor_solicitation] = 255; cm->min_valid_hop_limit_by_type[ICMP6_neighbor_advertisement] = 255; cm->min_valid_hop_limit_by_type[ICMP6_redirect] = 255; clib_memset (cm->min_valid_length_by_type, sizeof (icmp46_header_t), sizeof (cm->min_valid_length_by_type)); cm->min_valid_length_by_type[ICMP6_router_solicitation] = sizeof (icmp6_neighbor_discovery_header_t); cm->min_valid_length_by_type[ICMP6_router_advertisement] = sizeof (icmp6_router_advertisement_header_t); cm->min_valid_length_by_type[ICMP6_neighbor_solicitation] = sizeof (icmp6_neighbor_solicitation_or_advertisement_header_t); cm->min_valid_length_by_type[ICMP6_neighbor_advertisement] = sizeof (icmp6_neighbor_solicitation_or_advertisement_header_t); cm->min_valid_length_by_type[ICMP6_redirect] = sizeof (icmp6_redirect_header_t); vlib_thread_main_t *tm = &vlib_thread_main; u32 n_vlib_mains = tm->n_vlib_mains; throttle_init (&icmp_throttle, n_vlib_mains, 1e-3); return (NULL); } VLIB_INIT_FUNCTION (icmp6_init); /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */