/* * 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. */ /* Copyright (c) 2001, 2002, 2003 Eliot Dresselhaus Written by Fred Delley . 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. */ #ifdef CLIB_LINUX_KERNEL #include #endif #ifdef CLIB_UNIX #include #include #include #endif #include #include #include #include #include #include "test_vec.h" static int verbose; #define if_verbose(format,args...) \ if (verbose) { clib_warning(format, ## args); } #define MAX_CHANGE 100 typedef enum { /* Values have to be sequential and start with 0. */ OP_IS_VEC_RESIZE = 0, OP_IS_VEC_ADD1, OP_IS_VEC_ADD2, OP_IS_VEC_ADD, OP_IS_VEC_INSERT, OP_IS_VEC_INSERT_ELTS, OP_IS_VEC_DELETE, OP_IS_VEC_DUP, OP_IS_VEC_IS_EQUAL, OP_IS_VEC_ZERO, OP_IS_VEC_SET, OP_IS_VEC_VALIDATE, OP_IS_VEC_FREE, OP_IS_VEC_INIT, OP_IS_VEC_CLONE, OP_IS_VEC_APPEND, OP_IS_VEC_PREPEND, /* Operations on vectors with custom headers. */ OP_IS_VEC_INIT_H, OP_IS_VEC_RESIZE_H, OP_IS_VEC_FREE_H, OP_MAX, } op_t; #define FIRST_VEC_OP OP_IS_VEC_RESIZE #define LAST_VEC_OP OP_IS_VEC_PREPEND #define FIRST_VEC_HDR_OP OP_IS_VEC_INIT_H #define LAST_VEC_HDR_OP OP_IS_VEC_FREE_H uword g_prob_ratio[] = { [OP_IS_VEC_RESIZE] = 5, [OP_IS_VEC_ADD1] = 5, [OP_IS_VEC_ADD2] = 5, [OP_IS_VEC_ADD] = 5, [OP_IS_VEC_INSERT] = 5, [OP_IS_VEC_INSERT_ELTS] = 5, [OP_IS_VEC_DELETE] = 30, [OP_IS_VEC_DUP] = 5, [OP_IS_VEC_IS_EQUAL] = 5, [OP_IS_VEC_ZERO] = 2, [OP_IS_VEC_SET] = 3, [OP_IS_VEC_VALIDATE] = 5, [OP_IS_VEC_FREE] = 5, [OP_IS_VEC_INIT] = 5, [OP_IS_VEC_CLONE] = 5, [OP_IS_VEC_APPEND] = 5, [OP_IS_VEC_PREPEND] = 5, /* Operations on vectors with custom headers. */ [OP_IS_VEC_INIT_H] = 5, [OP_IS_VEC_RESIZE_H] = 5, [OP_IS_VEC_FREE_H] = 5, }; op_t *g_prob; op_t *g_prob_wh; uword g_call_stats[OP_MAX]; /* A structure for both vector headers and vector elements might be useful to uncover potential alignement issues. */ typedef struct { u8 field1[4]; CLIB_PACKED (u32 field2); } hdr_t; typedef struct { u8 field1[3]; CLIB_PACKED (u32 field2); } elt_t; #ifdef CLIB_UNIX u32 g_seed = 0xdeadbabe; uword g_verbose = 1; #endif op_t *g_op_prob; uword g_set_verbose_at = ~0; uword g_dump_period = ~0; static u8 * format_vec_op_type (u8 * s, va_list * args) { op_t op = va_arg (*args, int); switch (op) { #define _(n) \ case OP_IS_##n: \ s = format (s, "OP_IS_" #n); \ break; _(VEC_RESIZE); _(VEC_ADD1); _(VEC_ADD2); _(VEC_ADD); _(VEC_INSERT); _(VEC_INSERT_ELTS); _(VEC_DELETE); _(VEC_DUP); _(VEC_IS_EQUAL); _(VEC_ZERO); _(VEC_SET); _(VEC_VALIDATE); _(VEC_FREE); _(VEC_INIT); _(VEC_CLONE); _(VEC_APPEND); _(VEC_PREPEND); _(VEC_INIT_H); _(VEC_RESIZE_H); _(VEC_FREE_H); default: s = format (s, "Unknown vec op (%d)", op); break; } #undef _ return s; } static void dump_call_stats (uword * stats) { uword i; fformat (stdout, "Call Stats\n----------\n"); for (i = 0; i < OP_MAX; i++) fformat (stdout, "%-8d %U\n", stats[i], format_vec_op_type, i); } /* XXX - Purposely low value for debugging the validator. Will be set it to a more sensible value later. */ #define MAX_VEC_LEN 10 #define create_random_vec_wh(elt_type, len, hdr_bytes, seed) \ ({ \ elt_type * _v(v) = NULL; \ uword _v(l) = (len); \ uword _v(h) = (hdr_bytes); \ u8 * _v(hdr); \ \ if (_v(l) == 0) \ goto __done__; \ \ /* ~0 means select random length between 0 and MAX_VEC_LEN. */ \ if (_v(l) == ~0) \ _v(l) = bounded_random_u32 (&(seed), 0, MAX_VEC_LEN); \ \ _v(v) = _vec_resize (NULL, _v(l), _v(l) * sizeof (elt_type), _v(h), 0); \ fill_with_random_data (_v(v), vec_bytes (_v(v)), (seed)); \ \ /* Fill header with random data as well. */ \ if (_v(h) > 0) \ { \ _v(hdr) = vec_header (_v(v), _v(h)); \ fill_with_random_data (_v(hdr), _v(h), (seed)); \ } \ \ __done__: \ _v(v); \ }) #define create_random_vec(elt_type, len, seed) \ create_random_vec_wh (elt_type, len, 0, seed) #define compute_vec_hash(hash, vec) \ ({ \ u8 * _v(v) = (u8 *) (vec); \ uword _v(n) = vec_len (vec) * sizeof ((vec)[0]); \ u8 _v(hh) = (u8) (hash); \ \ compute_mem_hash (_v(hh), _v(v), _v(n)); \ }) static elt_t * validate_vec_free (elt_t * vec) { vec_free (vec); ASSERT (vec == NULL); return vec; } static elt_t * validate_vec_free_h (elt_t * vec, uword hdr_bytes) { vec_free_h (vec, hdr_bytes); ASSERT (vec == NULL); return vec; } static void validate_vec_hdr (elt_t * vec, uword hdr_bytes) { u8 *hdr; u8 *hdr_end; vec_header_t *vh; if (!vec) return; vh = _vec_find (vec); hdr = vec_header (vec, hdr_bytes); hdr_end = vec_header_end (hdr, hdr_bytes); ASSERT (hdr_end == (u8 *) vec); ASSERT ((u8 *) vh - (u8 *) hdr >= hdr_bytes); } static void validate_vec_len (elt_t * vec) { u8 *ptr; u8 *end; uword len; uword bytes; uword i; elt_t *elt; if (!vec) return; ptr = (u8 *) vec; end = (u8 *) vec_end (vec); len = vec_len (vec); bytes = sizeof (vec[0]) * len; ASSERT (bytes == vec_bytes (vec)); ASSERT ((ptr + bytes) == end); i = 0; /* XXX - TODO: confirm that auto-incrementing in vec_is_member() would not have the expected result. */ while (vec_is_member (vec, (__typeof__ (vec[0]) *) ptr)) { ptr++; i++; } ASSERT (ptr == end); ASSERT (i == bytes); i = 0; vec_foreach (elt, vec) i++; ASSERT (i == len); } static void validate_vec (elt_t * vec, uword hdr_bytes) { validate_vec_hdr (vec, hdr_bytes); validate_vec_len (vec); if (!vec || vec_len (vec) == 0) { VERBOSE3 ("Vector at %p has zero elements.\n\n", vec); } else { if (hdr_bytes > 0) VERBOSE3 ("Header: %U\n", format_hex_bytes, vec_header (vec, sizeof (vec[0])), sizeof (vec[0])); VERBOSE3 ("%U\n\n", format_hex_bytes, vec, vec_len (vec) * sizeof (vec[0])); } } static elt_t * validate_vec_resize (elt_t * vec, uword
/*
 * 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/ip6_error.h: ip6 fast path errors
 *
 * 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_ip_ip6_error_h
#define included_ip_ip6_error_h

#define foreach_ip6_error                                               \
  /* Must be first. */                                                  \
  _ (NONE, "valid ip6 packets")                                         \
                                                                        \
  /* Errors signalled by ip6-input */                                   \
  _ (TOO_SHORT, "ip6 length < 40 bytes")                                \
  _ (BAD_LENGTH, "ip6 length > l2 length")                              \
  _ (VERSION, "ip6 version != 6")                                       \
  _ (TIME_EXPIRED, "ip6 ttl <= 1")                                      \
                                                                        \
  /* Errors signalled by ip6-rewrite. */                                \
  _ (MTU_EXCEEDED, "ip6 MTU exceeded")                                  \
  _ (DST_LOOKUP_MISS, "ip6 destination lookup miss")                    \
  _ (SRC_LOOKUP_MISS, "ip6 source lookup miss")                         \
  _ (DROP, "ip6 drop")                                                  \
  _ (PUNT, "ip6 punt")                                                  \
                                                                        \
  /* Errors signalled by ip6-local. */                                  \
  _ (UNKNOWN_PROTOCOL, "unknown ip protocol")                           \
  _ (UDP_CHECKSUM, "bad udp checksum")                                  \
  _ (ICMP_CHECKSUM, "bad icmp checksum")                                \
  _ (UDP_LENGTH, "inconsistent udp/ip lengths")                         \
                                                                        \
  /* Errors signalled by udp6-lookup. */				\
  _ (UNKNOWN_UDP_PORT, "no listener for udp port")                      \
                                                                        \
  /* Spoofed packets in ip6-rewrite-local */                            \
  _(SPOOFED_LOCAL_PACKETS, "ip4 spoofed local-address packet drops")    \
                                                                        \
 /* Erros singalled by ip6-inacl */                                     \
  _ (INACL_TABLE_MISS, "input ACL table-miss drops")                    \
  _ (INACL_SESSION_DENY, "input ACL session deny drops")                \
 /* Erros singalled by ip6-outacl */                                    \
  _ (OUTACL_TABLE_MISS, "output ACL table-miss drops")                  \
  _ (OUTACL_SESSION_DENY, "output ACL session deny drops")              \
                                                                        \
  /* Errors signalled by ip6-reassembly */                              \
  _ (REASS_MISSING_UPPER, "missing-upper layer drops")                  \
  _ (REASS_DUPLICATE_FRAGMENT, "duplicate fragments")                   \
  _ (REASS_OVERLAPPING_FRAGMENT, "overlapping fragments")               \
  _ (REASS_LIMIT_REACHED, "drops due to concurrent reassemblies limit") \
  _ (REASS_TIMEOUT, "fragments dropped due to reassembly timeout")      \
  _ (REASS_INTERNAL_ERROR, "drops due to internal reassembly error")

typedef enum
{
#define _(sym,str) IP6_ERROR_##sym,
  foreach_ip6_error
#undef _
    IP6_N_ERROR,
} ip6_error_t;

#endif /* included_ip_ip6_error_h */

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */