Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * map.c : MAP support |
| 3 | * |
| 4 | * Copyright (c) 2015 Cisco and/or its affiliates. |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 18 | #include <vnet/fib/fib_table.h> |
| 19 | #include <vnet/fib/ip6_fib.h> |
| 20 | #include <vnet/adj/adj.h> |
| 21 | #include <vnet/map/map_dpo.h> |
Christophe Fontaine | b4bd28a | 2017-05-31 11:27:19 +0200 | [diff] [blame] | 22 | #include <vppinfra/crc32.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 23 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 24 | #include "map.h" |
| 25 | |
Dave Wallace | 71612d6 | 2017-10-24 01:32:41 -0400 | [diff] [blame] | 26 | map_main_t map_main; |
| 27 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 28 | /* |
| 29 | * This code supports the following MAP modes: |
Damjan Marion | 607de1a | 2016-08-16 22:53:54 +0200 | [diff] [blame] | 30 | * |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 31 | * Algorithmic Shared IPv4 address (ea_bits_len > 0): |
| 32 | * ea_bits_len + ip4_prefix > 32 |
| 33 | * psid_length > 0, ip6_prefix < 64, ip4_prefix <= 32 |
| 34 | * Algorithmic Full IPv4 address (ea_bits_len > 0): |
| 35 | * ea_bits_len + ip4_prefix = 32 |
| 36 | * psid_length = 0, ip6_prefix < 64, ip4_prefix <= 32 |
| 37 | * Algorithmic IPv4 prefix (ea_bits_len > 0): |
| 38 | * ea_bits_len + ip4_prefix < 32 |
| 39 | * psid_length = 0, ip6_prefix < 64, ip4_prefix <= 32 |
| 40 | * |
| 41 | * Independent Shared IPv4 address (ea_bits_len = 0): |
| 42 | * ip4_prefix = 32 |
| 43 | * psid_length > 0 |
| 44 | * Rule IPv6 address = 128, Rule PSID Set |
| 45 | * Independent Full IPv4 address (ea_bits_len = 0): |
| 46 | * ip4_prefix = 32 |
| 47 | * psid_length = 0, ip6_prefix = 128 |
| 48 | * Independent IPv4 prefix (ea_bits_len = 0): |
| 49 | * ip4_prefix < 32 |
| 50 | * psid_length = 0, ip6_prefix = 128 |
| 51 | * |
| 52 | */ |
| 53 | |
| 54 | /* |
| 55 | * This code supports MAP-T: |
| 56 | * |
| 57 | * With DMR prefix length equal to 96. |
| 58 | * |
| 59 | */ |
| 60 | |
| 61 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 62 | |
| 63 | int |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 64 | map_create_domain (ip4_address_t * ip4_prefix, |
| 65 | u8 ip4_prefix_len, |
| 66 | ip6_address_t * ip6_prefix, |
| 67 | u8 ip6_prefix_len, |
| 68 | ip6_address_t * ip6_src, |
| 69 | u8 ip6_src_len, |
| 70 | u8 ea_bits_len, |
| 71 | u8 psid_offset, |
| 72 | u8 psid_length, u32 * map_domain_index, u16 mtu, u8 flags) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 73 | { |
Ole Troan | 07e7eab | 2016-08-25 00:24:08 +0200 | [diff] [blame] | 74 | u8 suffix_len, suffix_shift; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 75 | map_main_t *mm = &map_main; |
Neale Ranns | 948e00f | 2016-10-20 13:39:34 +0100 | [diff] [blame] | 76 | dpo_id_t dpo_v4 = DPO_INVALID; |
| 77 | dpo_id_t dpo_v6 = DPO_INVALID; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 78 | map_domain_t *d; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 79 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 80 | /* Sanity check on the src prefix length */ |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 81 | if (flags & MAP_DOMAIN_TRANSLATION) |
| 82 | { |
| 83 | if (ip6_src_len != 96) |
| 84 | { |
| 85 | clib_warning ("MAP-T only supports ip6_src_len = 96 for now."); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 86 | return -1; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 87 | } |
| 88 | } |
| 89 | else |
| 90 | { |
| 91 | if (ip6_src_len != 128) |
| 92 | { |
| 93 | clib_warning |
Ole Troan | 07e7eab | 2016-08-25 00:24:08 +0200 | [diff] [blame] | 94 | ("MAP-E requires a BR address, not a prefix (ip6_src_len should " |
| 95 | "be 128)."); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 96 | return -1; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 97 | } |
| 98 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 99 | |
Ole Troan | 07e7eab | 2016-08-25 00:24:08 +0200 | [diff] [blame] | 100 | /* How many, and which bits to grab from the IPv4 DA */ |
| 101 | if (ip4_prefix_len + ea_bits_len < 32) |
| 102 | { |
| 103 | flags |= MAP_DOMAIN_PREFIX; |
Ole Troan | d575e69 | 2016-08-25 12:26:47 +0200 | [diff] [blame] | 104 | suffix_shift = 32 - ip4_prefix_len - ea_bits_len; |
| 105 | suffix_len = ea_bits_len; |
Ole Troan | 07e7eab | 2016-08-25 00:24:08 +0200 | [diff] [blame] | 106 | } |
| 107 | else |
| 108 | { |
| 109 | suffix_shift = 0; |
| 110 | suffix_len = 32 - ip4_prefix_len; |
| 111 | } |
| 112 | |
| 113 | /* EA bits must be within the first 64 bits */ |
| 114 | if (ea_bits_len > 0 && ((ip6_prefix_len + ea_bits_len) > 64 || |
| 115 | ip6_prefix_len + suffix_len + psid_length > 64)) |
| 116 | { |
| 117 | clib_warning |
| 118 | ("Embedded Address bits must be within the first 64 bits of " |
| 119 | "the IPv6 prefix"); |
| 120 | return -1; |
| 121 | } |
| 122 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 123 | /* Get domain index */ |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 124 | pool_get_aligned (mm->domains, d, CLIB_CACHE_LINE_BYTES); |
| 125 | memset (d, 0, sizeof (*d)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 126 | *map_domain_index = d - mm->domains; |
| 127 | |
| 128 | /* Init domain struct */ |
| 129 | d->ip4_prefix.as_u32 = ip4_prefix->as_u32; |
| 130 | d->ip4_prefix_len = ip4_prefix_len; |
| 131 | d->ip6_prefix = *ip6_prefix; |
| 132 | d->ip6_prefix_len = ip6_prefix_len; |
| 133 | d->ip6_src = *ip6_src; |
| 134 | d->ip6_src_len = ip6_src_len; |
| 135 | d->ea_bits_len = ea_bits_len; |
| 136 | d->psid_offset = psid_offset; |
| 137 | d->psid_length = psid_length; |
| 138 | d->mtu = mtu; |
| 139 | d->flags = flags; |
Ole Troan | 07e7eab | 2016-08-25 00:24:08 +0200 | [diff] [blame] | 140 | d->suffix_shift = suffix_shift; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 141 | d->suffix_mask = (1 << suffix_len) - 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 142 | |
| 143 | d->psid_shift = 16 - psid_length - psid_offset; |
| 144 | d->psid_mask = (1 << d->psid_length) - 1; |
| 145 | d->ea_shift = 64 - ip6_prefix_len - suffix_len - d->psid_length; |
| 146 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 147 | /* MAP data-plane object */ |
| 148 | if (d->flags & MAP_DOMAIN_TRANSLATION) |
| 149 | map_t_dpo_create (DPO_PROTO_IP4, *map_domain_index, &dpo_v4); |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 150 | else |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 151 | map_dpo_create (DPO_PROTO_IP4, *map_domain_index, &dpo_v4); |
| 152 | |
| 153 | /* Create ip4 route */ |
| 154 | fib_prefix_t pfx = { |
| 155 | .fp_proto = FIB_PROTOCOL_IP4, |
| 156 | .fp_len = d->ip4_prefix_len, |
| 157 | .fp_addr = { |
| 158 | .ip4 = d->ip4_prefix, |
| 159 | } |
| 160 | , |
| 161 | }; |
| 162 | fib_table_entry_special_dpo_add (0, &pfx, |
| 163 | FIB_SOURCE_MAP, |
| 164 | FIB_ENTRY_FLAG_EXCLUSIVE, &dpo_v4); |
| 165 | dpo_reset (&dpo_v4); |
| 166 | |
| 167 | /* |
Neale Ranns | 9705c38 | 2017-02-20 20:29:41 -0800 | [diff] [blame] | 168 | * construct a DPO to use the v6 domain |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 169 | */ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 170 | if (d->flags & MAP_DOMAIN_TRANSLATION) |
| 171 | map_t_dpo_create (DPO_PROTO_IP6, *map_domain_index, &dpo_v6); |
| 172 | else |
| 173 | map_dpo_create (DPO_PROTO_IP6, *map_domain_index, &dpo_v6); |
| 174 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 175 | /* |
Neale Ranns | 9705c38 | 2017-02-20 20:29:41 -0800 | [diff] [blame] | 176 | * Multiple MAP domains may share same source IPv6 TEP. Which is just dandy. |
| 177 | * We are not tracking the sharing. So a v4 lookup to find the correct |
| 178 | * domain post decap/trnaslate is always done |
| 179 | * |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 180 | * Create ip6 route. This is a reference counted add. If the prefix |
| 181 | * already exists and is MAP sourced, it is now MAP source n+1 times |
| 182 | * and will need to be removed n+1 times. |
| 183 | */ |
Neale Ranns | 9705c38 | 2017-02-20 20:29:41 -0800 | [diff] [blame] | 184 | fib_prefix_t pfx6 = { |
| 185 | .fp_proto = FIB_PROTOCOL_IP6, |
| 186 | .fp_len = d->ip6_src_len, |
| 187 | .fp_addr.ip6 = d->ip6_src, |
| 188 | }; |
| 189 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 190 | fib_table_entry_special_dpo_add (0, &pfx6, |
| 191 | FIB_SOURCE_MAP, |
| 192 | FIB_ENTRY_FLAG_EXCLUSIVE, &dpo_v6); |
| 193 | dpo_reset (&dpo_v6); |
| 194 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 195 | /* Validate packet/byte counters */ |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 196 | map_domain_counter_lock (mm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 197 | int i; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 198 | for (i = 0; i < vec_len (mm->simple_domain_counters); i++) |
| 199 | { |
| 200 | vlib_validate_simple_counter (&mm->simple_domain_counters[i], |
| 201 | *map_domain_index); |
| 202 | vlib_zero_simple_counter (&mm->simple_domain_counters[i], |
| 203 | *map_domain_index); |
| 204 | } |
| 205 | for (i = 0; i < vec_len (mm->domain_counters); i++) |
| 206 | { |
| 207 | vlib_validate_combined_counter (&mm->domain_counters[i], |
| 208 | *map_domain_index); |
| 209 | vlib_zero_combined_counter (&mm->domain_counters[i], *map_domain_index); |
| 210 | } |
| 211 | map_domain_counter_unlock (mm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 212 | |
| 213 | return 0; |
| 214 | } |
| 215 | |
| 216 | /* |
| 217 | * map_delete_domain |
| 218 | */ |
| 219 | int |
| 220 | map_delete_domain (u32 map_domain_index) |
| 221 | { |
| 222 | map_main_t *mm = &map_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 223 | map_domain_t *d; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 224 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 225 | if (pool_is_free_index (mm->domains, map_domain_index)) |
| 226 | { |
| 227 | clib_warning ("MAP domain delete: domain does not exist: %d", |
| 228 | map_domain_index); |
| 229 | return -1; |
| 230 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 231 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 232 | d = pool_elt_at_index (mm->domains, map_domain_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 233 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 234 | fib_prefix_t pfx = { |
| 235 | .fp_proto = FIB_PROTOCOL_IP4, |
| 236 | .fp_len = d->ip4_prefix_len, |
| 237 | .fp_addr = { |
| 238 | .ip4 = d->ip4_prefix, |
| 239 | } |
| 240 | , |
| 241 | }; |
| 242 | fib_table_entry_special_remove (0, &pfx, FIB_SOURCE_MAP); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 243 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 244 | fib_prefix_t pfx6 = { |
| 245 | .fp_proto = FIB_PROTOCOL_IP6, |
| 246 | .fp_len = d->ip6_src_len, |
| 247 | .fp_addr = { |
| 248 | .ip6 = d->ip6_src, |
| 249 | } |
| 250 | , |
| 251 | }; |
| 252 | fib_table_entry_special_remove (0, &pfx6, FIB_SOURCE_MAP); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 253 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 254 | /* Deleting rules */ |
| 255 | if (d->rules) |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 256 | clib_mem_free (d->rules); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 257 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 258 | pool_put (mm->domains, d); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 259 | |
| 260 | return 0; |
| 261 | } |
| 262 | |
| 263 | int |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 264 | map_add_del_psid (u32 map_domain_index, u16 psid, ip6_address_t * tep, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 265 | u8 is_add) |
| 266 | { |
| 267 | map_domain_t *d; |
| 268 | map_main_t *mm = &map_main; |
| 269 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 270 | if (pool_is_free_index (mm->domains, map_domain_index)) |
| 271 | { |
| 272 | clib_warning ("MAP rule: domain does not exist: %d", map_domain_index); |
| 273 | return -1; |
| 274 | } |
| 275 | d = pool_elt_at_index (mm->domains, map_domain_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 276 | |
| 277 | /* Rules are only used in 1:1 independent case */ |
| 278 | if (d->ea_bits_len > 0) |
| 279 | return (-1); |
| 280 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 281 | if (!d->rules) |
| 282 | { |
| 283 | u32 l = (0x1 << d->psid_length) * sizeof (ip6_address_t); |
| 284 | d->rules = clib_mem_alloc_aligned (l, CLIB_CACHE_LINE_BYTES); |
| 285 | if (!d->rules) |
| 286 | return -1; |
| 287 | memset (d->rules, 0, l); |
| 288 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 289 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 290 | if (psid >= (0x1 << d->psid_length)) |
| 291 | { |
| 292 | clib_warning ("MAP rule: PSID outside bounds: %d [%d]", psid, |
| 293 | 0x1 << d->psid_length); |
| 294 | return -1; |
| 295 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 296 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 297 | if (is_add) |
| 298 | { |
| 299 | d->rules[psid] = *tep; |
| 300 | } |
| 301 | else |
| 302 | { |
| 303 | memset (&d->rules[psid], 0, sizeof (ip6_address_t)); |
| 304 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 305 | return 0; |
| 306 | } |
| 307 | |
| 308 | #ifdef MAP_SKIP_IP6_LOOKUP |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 309 | /** |
| 310 | * Pre-resolvd per-protocol global next-hops |
| 311 | */ |
| 312 | map_main_pre_resolved_t pre_resolved[FIB_PROTOCOL_MAX]; |
| 313 | |
| 314 | static void |
| 315 | map_pre_resolve_init (map_main_pre_resolved_t * pr) |
| 316 | { |
| 317 | pr->fei = FIB_NODE_INDEX_INVALID; |
| 318 | fib_node_init (&pr->node, FIB_NODE_TYPE_MAP_E); |
| 319 | } |
| 320 | |
| 321 | static u8 * |
Christophe Fontaine | d3c008d | 2017-10-02 18:10:54 +0200 | [diff] [blame] | 322 | format_map_pre_resolve (u8 * s, va_list * ap) |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 323 | { |
Christophe Fontaine | d3c008d | 2017-10-02 18:10:54 +0200 | [diff] [blame] | 324 | map_main_pre_resolved_t *pr = va_arg (*ap, map_main_pre_resolved_t *); |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 325 | |
| 326 | if (FIB_NODE_INDEX_INVALID != pr->fei) |
| 327 | { |
| 328 | fib_prefix_t pfx; |
| 329 | |
| 330 | fib_entry_get_prefix (pr->fei, &pfx); |
| 331 | |
| 332 | return (format (s, "%U (%u)", |
| 333 | format_ip46_address, &pfx.fp_addr, IP46_TYPE_ANY, |
| 334 | pr->dpo.dpoi_index)); |
| 335 | } |
| 336 | else |
| 337 | { |
| 338 | return (format (s, "un-set")); |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | |
| 343 | /** |
| 344 | * Function definition to inform the FIB node that its last lock has gone. |
| 345 | */ |
| 346 | static void |
| 347 | map_last_lock_gone (fib_node_t * node) |
| 348 | { |
| 349 | /* |
| 350 | * The MAP is a root of the graph. As such |
| 351 | * it never has children and thus is never locked. |
| 352 | */ |
| 353 | ASSERT (0); |
| 354 | } |
| 355 | |
| 356 | static map_main_pre_resolved_t * |
| 357 | map_from_fib_node (fib_node_t * node) |
| 358 | { |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 359 | ASSERT (FIB_NODE_TYPE_MAP_E == node->fn_type); |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 360 | return ((map_main_pre_resolved_t *) |
| 361 | (((char *) node) - |
| 362 | STRUCT_OFFSET_OF (map_main_pre_resolved_t, node))); |
| 363 | } |
| 364 | |
| 365 | static void |
| 366 | map_stack (map_main_pre_resolved_t * pr) |
| 367 | { |
| 368 | const dpo_id_t *dpo; |
| 369 | |
| 370 | dpo = fib_entry_contribute_ip_forwarding (pr->fei); |
| 371 | |
| 372 | dpo_copy (&pr->dpo, dpo); |
| 373 | } |
| 374 | |
| 375 | /** |
| 376 | * Function definition to backwalk a FIB node |
| 377 | */ |
| 378 | static fib_node_back_walk_rc_t |
| 379 | map_back_walk (fib_node_t * node, fib_node_back_walk_ctx_t * ctx) |
| 380 | { |
| 381 | map_stack (map_from_fib_node (node)); |
| 382 | |
| 383 | return (FIB_NODE_BACK_WALK_CONTINUE); |
| 384 | } |
| 385 | |
| 386 | /** |
| 387 | * Function definition to get a FIB node from its index |
| 388 | */ |
| 389 | static fib_node_t * |
| 390 | map_fib_node_get (fib_node_index_t index) |
| 391 | { |
| 392 | return (&pre_resolved[index].node); |
| 393 | } |
| 394 | |
| 395 | /* |
| 396 | * Virtual function table registered by MPLS GRE tunnels |
| 397 | * for participation in the FIB object graph. |
| 398 | */ |
| 399 | const static fib_node_vft_t map_vft = { |
| 400 | .fnv_get = map_fib_node_get, |
| 401 | .fnv_last_lock = map_last_lock_gone, |
| 402 | .fnv_back_walk = map_back_walk, |
| 403 | }; |
| 404 | |
| 405 | static void |
| 406 | map_fib_resolve (map_main_pre_resolved_t * pr, |
| 407 | fib_protocol_t proto, u8 len, const ip46_address_t * addr) |
| 408 | { |
| 409 | fib_prefix_t pfx = { |
| 410 | .fp_proto = proto, |
| 411 | .fp_len = len, |
| 412 | .fp_addr = *addr, |
| 413 | }; |
| 414 | |
| 415 | pr->fei = fib_table_entry_special_add (0, // default fib |
| 416 | &pfx, |
Neale Ranns | a055830 | 2017-04-13 00:44:52 -0700 | [diff] [blame] | 417 | FIB_SOURCE_RR, FIB_ENTRY_FLAG_NONE); |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 418 | pr->sibling = fib_entry_child_add (pr->fei, FIB_NODE_TYPE_MAP_E, proto); |
| 419 | map_stack (pr); |
| 420 | } |
| 421 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 422 | static void |
Neale Ranns | 69b7aa4 | 2017-03-10 03:04:12 -0800 | [diff] [blame] | 423 | map_fib_unresolve (map_main_pre_resolved_t * pr, |
| 424 | fib_protocol_t proto, u8 len, const ip46_address_t * addr) |
| 425 | { |
| 426 | fib_prefix_t pfx = { |
| 427 | .fp_proto = proto, |
| 428 | .fp_len = len, |
| 429 | .fp_addr = *addr, |
| 430 | }; |
| 431 | |
| 432 | fib_entry_child_remove (pr->fei, pr->sibling); |
| 433 | |
| 434 | fib_table_entry_special_remove (0, // default fib |
| 435 | &pfx, FIB_SOURCE_RR); |
| 436 | dpo_reset (&pr->dpo); |
| 437 | |
| 438 | pr->fei = FIB_NODE_INDEX_INVALID; |
| 439 | pr->sibling = FIB_NODE_INDEX_INVALID; |
| 440 | } |
| 441 | |
| 442 | static void |
| 443 | map_pre_resolve (ip4_address_t * ip4, ip6_address_t * ip6, int is_del) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 444 | { |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 445 | if (ip6 && (ip6->as_u64[0] != 0 || ip6->as_u64[1] != 0)) |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 446 | { |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 447 | ip46_address_t addr = { |
| 448 | .ip6 = *ip6, |
| 449 | }; |
Neale Ranns | 69b7aa4 | 2017-03-10 03:04:12 -0800 | [diff] [blame] | 450 | if (is_del) |
| 451 | map_fib_unresolve (&pre_resolved[FIB_PROTOCOL_IP6], |
| 452 | FIB_PROTOCOL_IP6, 128, &addr); |
| 453 | else |
| 454 | map_fib_resolve (&pre_resolved[FIB_PROTOCOL_IP6], |
| 455 | FIB_PROTOCOL_IP6, 128, &addr); |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 456 | } |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 457 | if (ip4 && (ip4->as_u32 != 0)) |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 458 | { |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 459 | ip46_address_t addr = { |
| 460 | .ip4 = *ip4, |
| 461 | }; |
Neale Ranns | 69b7aa4 | 2017-03-10 03:04:12 -0800 | [diff] [blame] | 462 | if (is_del) |
| 463 | map_fib_unresolve (&pre_resolved[FIB_PROTOCOL_IP4], |
| 464 | FIB_PROTOCOL_IP4, 32, &addr); |
| 465 | else |
| 466 | map_fib_resolve (&pre_resolved[FIB_PROTOCOL_IP4], |
| 467 | FIB_PROTOCOL_IP4, 32, &addr); |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 468 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 469 | } |
| 470 | #endif |
| 471 | |
| 472 | static clib_error_t * |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 473 | map_security_check_command_fn (vlib_main_t * vm, |
| 474 | unformat_input_t * input, |
| 475 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 476 | { |
| 477 | unformat_input_t _line_input, *line_input = &_line_input; |
| 478 | map_main_t *mm = &map_main; |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 479 | clib_error_t *error = NULL; |
| 480 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 481 | /* Get a line of input. */ |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 482 | if (!unformat_user (input, unformat_line_input, line_input)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 483 | return 0; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 484 | |
| 485 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 486 | { |
| 487 | if (unformat (line_input, "off")) |
| 488 | mm->sec_check = false; |
| 489 | else if (unformat (line_input, "on")) |
| 490 | mm->sec_check = true; |
| 491 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 492 | { |
| 493 | error = clib_error_return (0, "unknown input `%U'", |
| 494 | format_unformat_error, line_input); |
| 495 | goto done; |
| 496 | } |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 497 | } |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 498 | |
| 499 | done: |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 500 | unformat_free (line_input); |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 501 | |
| 502 | return error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | static clib_error_t * |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 506 | map_security_check_frag_command_fn (vlib_main_t * vm, |
| 507 | unformat_input_t * input, |
| 508 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 509 | { |
| 510 | unformat_input_t _line_input, *line_input = &_line_input; |
| 511 | map_main_t *mm = &map_main; |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 512 | clib_error_t *error = NULL; |
| 513 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 514 | /* Get a line of input. */ |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 515 | if (!unformat_user (input, unformat_line_input, line_input)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 516 | return 0; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 517 | |
| 518 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 519 | { |
| 520 | if (unformat (line_input, "off")) |
| 521 | mm->sec_check_frag = false; |
| 522 | else if (unformat (line_input, "on")) |
| 523 | mm->sec_check_frag = true; |
| 524 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 525 | { |
| 526 | error = clib_error_return (0, "unknown input `%U'", |
| 527 | format_unformat_error, line_input); |
| 528 | goto done; |
| 529 | } |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 530 | } |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 531 | |
| 532 | done: |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 533 | unformat_free (line_input); |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 534 | |
| 535 | return error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | static clib_error_t * |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 539 | map_add_domain_command_fn (vlib_main_t * vm, |
| 540 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 541 | { |
| 542 | unformat_input_t _line_input, *line_input = &_line_input; |
| 543 | ip4_address_t ip4_prefix; |
| 544 | ip6_address_t ip6_prefix; |
| 545 | ip6_address_t ip6_src; |
Dave Barach | 042ffb4 | 2016-08-12 09:26:47 -0400 | [diff] [blame] | 546 | u32 ip6_prefix_len = 0, ip4_prefix_len = 0, map_domain_index, ip6_src_len; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 547 | u32 num_m_args = 0; |
| 548 | /* Optional arguments */ |
Dave Barach | 042ffb4 | 2016-08-12 09:26:47 -0400 | [diff] [blame] | 549 | u32 ea_bits_len = 0, psid_offset = 0, psid_length = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 550 | u32 mtu = 0; |
| 551 | u8 flags = 0; |
| 552 | ip6_src_len = 128; |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 553 | clib_error_t *error = NULL; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 554 | |
| 555 | /* Get a line of input. */ |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 556 | if (!unformat_user (input, unformat_line_input, line_input)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 557 | return 0; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 558 | |
| 559 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 560 | { |
| 561 | if (unformat |
| 562 | (line_input, "ip4-pfx %U/%d", unformat_ip4_address, &ip4_prefix, |
| 563 | &ip4_prefix_len)) |
| 564 | num_m_args++; |
| 565 | else |
| 566 | if (unformat |
| 567 | (line_input, "ip6-pfx %U/%d", unformat_ip6_address, &ip6_prefix, |
| 568 | &ip6_prefix_len)) |
| 569 | num_m_args++; |
| 570 | else |
| 571 | if (unformat |
| 572 | (line_input, "ip6-src %U/%d", unformat_ip6_address, &ip6_src, |
| 573 | &ip6_src_len)) |
| 574 | num_m_args++; |
| 575 | else |
| 576 | if (unformat |
| 577 | (line_input, "ip6-src %U", unformat_ip6_address, &ip6_src)) |
| 578 | num_m_args++; |
| 579 | else if (unformat (line_input, "ea-bits-len %d", &ea_bits_len)) |
| 580 | num_m_args++; |
| 581 | else if (unformat (line_input, "psid-offset %d", &psid_offset)) |
| 582 | num_m_args++; |
| 583 | else if (unformat (line_input, "psid-len %d", &psid_length)) |
| 584 | num_m_args++; |
| 585 | else if (unformat (line_input, "mtu %d", &mtu)) |
| 586 | num_m_args++; |
| 587 | else if (unformat (line_input, "map-t")) |
| 588 | flags |= MAP_DOMAIN_TRANSLATION; |
| 589 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 590 | { |
| 591 | error = clib_error_return (0, "unknown input `%U'", |
| 592 | format_unformat_error, line_input); |
| 593 | goto done; |
| 594 | } |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 595 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 596 | |
| 597 | if (num_m_args < 3) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 598 | { |
| 599 | error = clib_error_return (0, "mandatory argument(s) missing"); |
| 600 | goto done; |
| 601 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 602 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 603 | map_create_domain (&ip4_prefix, ip4_prefix_len, |
| 604 | &ip6_prefix, ip6_prefix_len, &ip6_src, ip6_src_len, |
| 605 | ea_bits_len, psid_offset, psid_length, &map_domain_index, |
| 606 | mtu, flags); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 607 | |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 608 | done: |
| 609 | unformat_free (line_input); |
| 610 | |
| 611 | return error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | static clib_error_t * |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 615 | map_del_domain_command_fn (vlib_main_t * vm, |
| 616 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 617 | { |
| 618 | unformat_input_t _line_input, *line_input = &_line_input; |
| 619 | u32 num_m_args = 0; |
| 620 | u32 map_domain_index; |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 621 | clib_error_t *error = NULL; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 622 | |
| 623 | /* Get a line of input. */ |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 624 | if (!unformat_user (input, unformat_line_input, line_input)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 625 | return 0; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 626 | |
| 627 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 628 | { |
| 629 | if (unformat (line_input, "index %d", &map_domain_index)) |
| 630 | num_m_args++; |
| 631 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 632 | { |
| 633 | error = clib_error_return (0, "unknown input `%U'", |
| 634 | format_unformat_error, line_input); |
| 635 | goto done; |
| 636 | } |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 637 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 638 | |
| 639 | if (num_m_args != 1) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 640 | { |
| 641 | error = clib_error_return (0, "mandatory argument(s) missing"); |
| 642 | goto done; |
| 643 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 644 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 645 | map_delete_domain (map_domain_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 646 | |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 647 | done: |
| 648 | unformat_free (line_input); |
| 649 | |
| 650 | return error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | static clib_error_t * |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 654 | map_add_rule_command_fn (vlib_main_t * vm, |
| 655 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 656 | { |
| 657 | unformat_input_t _line_input, *line_input = &_line_input; |
| 658 | ip6_address_t tep; |
| 659 | u32 num_m_args = 0; |
Dave Barach | 042ffb4 | 2016-08-12 09:26:47 -0400 | [diff] [blame] | 660 | u32 psid = 0, map_domain_index; |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 661 | clib_error_t *error = NULL; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 662 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 663 | /* Get a line of input. */ |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 664 | if (!unformat_user (input, unformat_line_input, line_input)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 665 | return 0; |
| 666 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 667 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 668 | { |
| 669 | if (unformat (line_input, "index %d", &map_domain_index)) |
| 670 | num_m_args++; |
| 671 | else if (unformat (line_input, "psid %d", &psid)) |
| 672 | num_m_args++; |
| 673 | else |
| 674 | if (unformat (line_input, "ip6-dst %U", unformat_ip6_address, &tep)) |
| 675 | num_m_args++; |
| 676 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 677 | { |
| 678 | error = clib_error_return (0, "unknown input `%U'", |
| 679 | format_unformat_error, line_input); |
| 680 | goto done; |
| 681 | } |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 682 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 683 | |
| 684 | if (num_m_args != 3) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 685 | { |
| 686 | error = clib_error_return (0, "mandatory argument(s) missing"); |
| 687 | goto done; |
| 688 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 689 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 690 | if (map_add_del_psid (map_domain_index, psid, &tep, 1) != 0) |
| 691 | { |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 692 | error = clib_error_return (0, "Failing to add Mapping Rule"); |
| 693 | goto done; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 694 | } |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 695 | |
| 696 | done: |
| 697 | unformat_free (line_input); |
| 698 | |
| 699 | return error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | #if MAP_SKIP_IP6_LOOKUP |
| 703 | static clib_error_t * |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 704 | map_pre_resolve_command_fn (vlib_main_t * vm, |
| 705 | unformat_input_t * input, |
| 706 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 707 | { |
| 708 | unformat_input_t _line_input, *line_input = &_line_input; |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 709 | ip4_address_t ip4nh, *p_v4 = NULL; |
| 710 | ip6_address_t ip6nh, *p_v6 = NULL; |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 711 | clib_error_t *error = NULL; |
Neale Ranns | 69b7aa4 | 2017-03-10 03:04:12 -0800 | [diff] [blame] | 712 | int is_del = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 713 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 714 | memset (&ip4nh, 0, sizeof (ip4nh)); |
| 715 | memset (&ip6nh, 0, sizeof (ip6nh)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 716 | |
| 717 | /* Get a line of input. */ |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 718 | if (!unformat_user (input, unformat_line_input, line_input)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 719 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 720 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 721 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 722 | { |
| 723 | if (unformat (line_input, "ip4-nh %U", unformat_ip4_address, &ip4nh)) |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 724 | p_v4 = &ip4nh; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 725 | else |
| 726 | if (unformat (line_input, "ip6-nh %U", unformat_ip6_address, &ip6nh)) |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 727 | p_v6 = &ip6nh; |
Neale Ranns | 69b7aa4 | 2017-03-10 03:04:12 -0800 | [diff] [blame] | 728 | else if (unformat (line_input, "del")) |
| 729 | is_del = 1; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 730 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 731 | { |
| 732 | error = clib_error_return (0, "unknown input `%U'", |
| 733 | format_unformat_error, line_input); |
| 734 | goto done; |
| 735 | } |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 736 | } |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 737 | |
Neale Ranns | 69b7aa4 | 2017-03-10 03:04:12 -0800 | [diff] [blame] | 738 | map_pre_resolve (p_v4, p_v6, is_del); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 739 | |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 740 | done: |
| 741 | unformat_free (line_input); |
| 742 | |
| 743 | return error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 744 | } |
| 745 | #endif |
| 746 | |
| 747 | static clib_error_t * |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 748 | map_icmp_relay_source_address_command_fn (vlib_main_t * vm, |
| 749 | unformat_input_t * input, |
| 750 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 751 | { |
| 752 | unformat_input_t _line_input, *line_input = &_line_input; |
| 753 | ip4_address_t icmp_src_address; |
| 754 | map_main_t *mm = &map_main; |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 755 | clib_error_t *error = NULL; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 756 | |
Ole Troan | cda9482 | 2016-01-07 14:37:25 +0100 | [diff] [blame] | 757 | mm->icmp4_src_address.as_u32 = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 758 | |
| 759 | /* Get a line of input. */ |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 760 | if (!unformat_user (input, unformat_line_input, line_input)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 761 | return 0; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 762 | |
| 763 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 764 | { |
| 765 | if (unformat |
| 766 | (line_input, "%U", unformat_ip4_address, &icmp_src_address)) |
| 767 | mm->icmp4_src_address = icmp_src_address; |
| 768 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 769 | { |
| 770 | error = clib_error_return (0, "unknown input `%U'", |
| 771 | format_unformat_error, line_input); |
| 772 | goto done; |
| 773 | } |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 774 | } |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 775 | |
| 776 | done: |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 777 | unformat_free (line_input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 778 | |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 779 | return error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | static clib_error_t * |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 783 | map_icmp_unreachables_command_fn (vlib_main_t * vm, |
| 784 | unformat_input_t * input, |
| 785 | vlib_cli_command_t * cmd) |
Ole Troan | cda9482 | 2016-01-07 14:37:25 +0100 | [diff] [blame] | 786 | { |
| 787 | unformat_input_t _line_input, *line_input = &_line_input; |
| 788 | map_main_t *mm = &map_main; |
| 789 | int num_m_args = 0; |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 790 | clib_error_t *error = NULL; |
Ole Troan | cda9482 | 2016-01-07 14:37:25 +0100 | [diff] [blame] | 791 | |
| 792 | /* Get a line of input. */ |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 793 | if (!unformat_user (input, unformat_line_input, line_input)) |
Ole Troan | cda9482 | 2016-01-07 14:37:25 +0100 | [diff] [blame] | 794 | return 0; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 795 | |
| 796 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 797 | { |
| 798 | num_m_args++; |
| 799 | if (unformat (line_input, "on")) |
| 800 | mm->icmp6_enabled = true; |
| 801 | else if (unformat (line_input, "off")) |
| 802 | mm->icmp6_enabled = false; |
| 803 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 804 | { |
| 805 | error = clib_error_return (0, "unknown input `%U'", |
| 806 | format_unformat_error, line_input); |
| 807 | goto done; |
| 808 | } |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 809 | } |
Ole Troan | cda9482 | 2016-01-07 14:37:25 +0100 | [diff] [blame] | 810 | |
| 811 | |
| 812 | if (num_m_args != 1) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 813 | error = clib_error_return (0, "mandatory argument(s) missing"); |
Ole Troan | cda9482 | 2016-01-07 14:37:25 +0100 | [diff] [blame] | 814 | |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 815 | done: |
| 816 | unformat_free (line_input); |
| 817 | |
| 818 | return error; |
Ole Troan | cda9482 | 2016-01-07 14:37:25 +0100 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | static clib_error_t * |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 822 | map_fragment_command_fn (vlib_main_t * vm, |
| 823 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ole Troan | 9fb8755 | 2016-01-13 22:30:43 +0100 | [diff] [blame] | 824 | { |
| 825 | unformat_input_t _line_input, *line_input = &_line_input; |
| 826 | map_main_t *mm = &map_main; |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 827 | clib_error_t *error = NULL; |
Ole Troan | 9fb8755 | 2016-01-13 22:30:43 +0100 | [diff] [blame] | 828 | |
| 829 | /* Get a line of input. */ |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 830 | if (!unformat_user (input, unformat_line_input, line_input)) |
Ole Troan | 9fb8755 | 2016-01-13 22:30:43 +0100 | [diff] [blame] | 831 | return 0; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 832 | |
| 833 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 834 | { |
| 835 | if (unformat (line_input, "inner")) |
| 836 | mm->frag_inner = true; |
| 837 | else if (unformat (line_input, "outer")) |
| 838 | mm->frag_inner = false; |
| 839 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 840 | { |
| 841 | error = clib_error_return (0, "unknown input `%U'", |
| 842 | format_unformat_error, line_input); |
| 843 | goto done; |
| 844 | } |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 845 | } |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 846 | |
| 847 | done: |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 848 | unformat_free (line_input); |
Ole Troan | 9fb8755 | 2016-01-13 22:30:43 +0100 | [diff] [blame] | 849 | |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 850 | return error; |
Ole Troan | 9fb8755 | 2016-01-13 22:30:43 +0100 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | static clib_error_t * |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 854 | map_fragment_df_command_fn (vlib_main_t * vm, |
| 855 | unformat_input_t * input, |
| 856 | vlib_cli_command_t * cmd) |
Ole Troan | 9fb8755 | 2016-01-13 22:30:43 +0100 | [diff] [blame] | 857 | { |
| 858 | unformat_input_t _line_input, *line_input = &_line_input; |
| 859 | map_main_t *mm = &map_main; |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 860 | clib_error_t *error = NULL; |
Ole Troan | 9fb8755 | 2016-01-13 22:30:43 +0100 | [diff] [blame] | 861 | |
| 862 | /* Get a line of input. */ |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 863 | if (!unformat_user (input, unformat_line_input, line_input)) |
Ole Troan | 9fb8755 | 2016-01-13 22:30:43 +0100 | [diff] [blame] | 864 | return 0; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 865 | |
| 866 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 867 | { |
| 868 | if (unformat (line_input, "on")) |
| 869 | mm->frag_ignore_df = true; |
| 870 | else if (unformat (line_input, "off")) |
| 871 | mm->frag_ignore_df = false; |
| 872 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 873 | { |
| 874 | error = clib_error_return (0, "unknown input `%U'", |
| 875 | format_unformat_error, line_input); |
| 876 | goto done; |
| 877 | } |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 878 | } |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 879 | |
| 880 | done: |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 881 | unformat_free (line_input); |
Ole Troan | 9fb8755 | 2016-01-13 22:30:43 +0100 | [diff] [blame] | 882 | |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 883 | return error; |
Ole Troan | 9fb8755 | 2016-01-13 22:30:43 +0100 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | static clib_error_t * |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 887 | map_traffic_class_command_fn (vlib_main_t * vm, |
| 888 | unformat_input_t * input, |
| 889 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 890 | { |
| 891 | unformat_input_t _line_input, *line_input = &_line_input; |
| 892 | map_main_t *mm = &map_main; |
| 893 | u32 tc = 0; |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 894 | clib_error_t *error = NULL; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 895 | |
| 896 | mm->tc_copy = false; |
| 897 | |
| 898 | /* Get a line of input. */ |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 899 | if (!unformat_user (input, unformat_line_input, line_input)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 900 | return 0; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 901 | |
| 902 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 903 | { |
| 904 | if (unformat (line_input, "copy")) |
| 905 | mm->tc_copy = true; |
| 906 | else if (unformat (line_input, "%x", &tc)) |
| 907 | mm->tc = tc & 0xff; |
| 908 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 909 | { |
| 910 | error = clib_error_return (0, "unknown input `%U'", |
| 911 | format_unformat_error, line_input); |
| 912 | goto done; |
| 913 | } |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 914 | } |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 915 | |
| 916 | done: |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 917 | unformat_free (line_input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 918 | |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 919 | return error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | static u8 * |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 923 | format_map_domain (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 924 | { |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 925 | map_domain_t *d = va_arg (*args, map_domain_t *); |
| 926 | bool counters = va_arg (*args, int); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 927 | map_main_t *mm = &map_main; |
| 928 | ip6_address_t ip6_prefix; |
| 929 | |
| 930 | if (d->rules) |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 931 | memset (&ip6_prefix, 0, sizeof (ip6_prefix)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 932 | else |
| 933 | ip6_prefix = d->ip6_prefix; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 934 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 935 | s = format (s, |
| 936 | "[%d] ip4-pfx %U/%d ip6-pfx %U/%d ip6-src %U/%d ea_bits_len %d psid-offset %d psid-len %d mtu %d %s", |
| 937 | d - mm->domains, |
| 938 | format_ip4_address, &d->ip4_prefix, d->ip4_prefix_len, |
| 939 | format_ip6_address, &ip6_prefix, d->ip6_prefix_len, |
| 940 | format_ip6_address, &d->ip6_src, d->ip6_src_len, |
| 941 | d->ea_bits_len, d->psid_offset, d->psid_length, d->mtu, |
| 942 | (d->flags & MAP_DOMAIN_TRANSLATION) ? "map-t" : ""); |
Ole Troan | 366ac6e | 2016-01-06 12:40:28 +0100 | [diff] [blame] | 943 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 944 | if (counters) |
| 945 | { |
| 946 | map_domain_counter_lock (mm); |
| 947 | vlib_counter_t v; |
| 948 | vlib_get_combined_counter (&mm->domain_counters[MAP_DOMAIN_COUNTER_TX], |
| 949 | d - mm->domains, &v); |
| 950 | s = format (s, " TX: %lld/%lld", v.packets, v.bytes); |
| 951 | vlib_get_combined_counter (&mm->domain_counters[MAP_DOMAIN_COUNTER_RX], |
| 952 | d - mm->domains, &v); |
| 953 | s = format (s, " RX: %lld/%lld", v.packets, v.bytes); |
| 954 | map_domain_counter_unlock (mm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 955 | } |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 956 | s = format (s, "\n"); |
| 957 | |
| 958 | if (d->rules) |
| 959 | { |
| 960 | int i; |
| 961 | ip6_address_t dst; |
| 962 | for (i = 0; i < (0x1 << d->psid_length); i++) |
| 963 | { |
| 964 | dst = d->rules[i]; |
| 965 | if (dst.as_u64[0] == 0 && dst.as_u64[1] == 0) |
| 966 | continue; |
| 967 | s = format (s, |
| 968 | " rule psid: %d ip6-dst %U\n", i, format_ip6_address, |
| 969 | &dst); |
| 970 | } |
| 971 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 972 | return s; |
| 973 | } |
| 974 | |
| 975 | static u8 * |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 976 | format_map_ip4_reass (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 977 | { |
| 978 | map_main_t *mm = &map_main; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 979 | map_ip4_reass_t *r = va_arg (*args, map_ip4_reass_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 980 | map_ip4_reass_key_t *k = &r->key; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 981 | f64 now = vlib_time_now (mm->vlib_main); |
| 982 | f64 lifetime = (((f64) mm->ip4_reass_conf_lifetime_ms) / 1000); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 983 | f64 dt = (r->ts + lifetime > now) ? (r->ts + lifetime - now) : -1; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 984 | s = format (s, |
| 985 | "ip4-reass src=%U dst=%U protocol=%d identifier=%d port=%d lifetime=%.3lf\n", |
| 986 | format_ip4_address, &k->src.as_u8, format_ip4_address, |
| 987 | &k->dst.as_u8, k->protocol, |
| 988 | clib_net_to_host_u16 (k->fragment_id), |
| 989 | (r->port >= 0) ? clib_net_to_host_u16 (r->port) : -1, dt); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 990 | return s; |
| 991 | } |
| 992 | |
| 993 | static u8 * |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 994 | format_map_ip6_reass (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 995 | { |
| 996 | map_main_t *mm = &map_main; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 997 | map_ip6_reass_t *r = va_arg (*args, map_ip6_reass_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 998 | map_ip6_reass_key_t *k = &r->key; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 999 | f64 now = vlib_time_now (mm->vlib_main); |
| 1000 | f64 lifetime = (((f64) mm->ip6_reass_conf_lifetime_ms) / 1000); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1001 | f64 dt = (r->ts + lifetime > now) ? (r->ts + lifetime - now) : -1; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1002 | s = format (s, |
| 1003 | "ip6-reass src=%U dst=%U protocol=%d identifier=%d lifetime=%.3lf\n", |
| 1004 | format_ip6_address, &k->src.as_u8, format_ip6_address, |
| 1005 | &k->dst.as_u8, k->protocol, |
| 1006 | clib_net_to_host_u32 (k->fragment_id), dt); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1007 | return s; |
| 1008 | } |
| 1009 | |
| 1010 | static clib_error_t * |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1011 | show_map_domain_command_fn (vlib_main_t * vm, unformat_input_t * input, |
| 1012 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1013 | { |
| 1014 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1015 | map_main_t *mm = &map_main; |
| 1016 | map_domain_t *d; |
| 1017 | bool counters = false; |
| 1018 | u32 map_domain_index = ~0; |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 1019 | clib_error_t *error = NULL; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1020 | |
| 1021 | /* Get a line of input. */ |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1022 | if (!unformat_user (input, unformat_line_input, line_input)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1023 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1024 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1025 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1026 | { |
| 1027 | if (unformat (line_input, "counters")) |
| 1028 | counters = true; |
| 1029 | else if (unformat (line_input, "index %d", &map_domain_index)) |
| 1030 | ; |
| 1031 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 1032 | { |
| 1033 | error = clib_error_return (0, "unknown input `%U'", |
| 1034 | format_unformat_error, line_input); |
| 1035 | goto done; |
| 1036 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1037 | } |
| 1038 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1039 | if (pool_elts (mm->domains) == 0) |
| 1040 | vlib_cli_output (vm, "No MAP domains are configured..."); |
| 1041 | |
| 1042 | if (map_domain_index == ~0) |
| 1043 | { |
| 1044 | /* *INDENT-OFF* */ |
| 1045 | pool_foreach(d, mm->domains, ({vlib_cli_output(vm, "%U", format_map_domain, d, counters);})); |
| 1046 | /* *INDENT-ON* */ |
| 1047 | } |
| 1048 | else |
| 1049 | { |
| 1050 | if (pool_is_free_index (mm->domains, map_domain_index)) |
| 1051 | { |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 1052 | error = clib_error_return (0, "MAP domain does not exists %d", |
| 1053 | map_domain_index); |
| 1054 | goto done; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | d = pool_elt_at_index (mm->domains, map_domain_index); |
| 1058 | vlib_cli_output (vm, "%U", format_map_domain, d, counters); |
| 1059 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1060 | |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 1061 | done: |
| 1062 | unformat_free (line_input); |
| 1063 | |
| 1064 | return error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | static clib_error_t * |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1068 | show_map_fragments_command_fn (vlib_main_t * vm, unformat_input_t * input, |
| 1069 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1070 | { |
| 1071 | map_main_t *mm = &map_main; |
| 1072 | map_ip4_reass_t *f4; |
| 1073 | map_ip6_reass_t *f6; |
| 1074 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1075 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1076 | pool_foreach(f4, mm->ip4_reass_pool, ({vlib_cli_output (vm, "%U", format_map_ip4_reass, f4);})); |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1077 | /* *INDENT-ON* */ |
| 1078 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1079 | pool_foreach(f6, mm->ip6_reass_pool, ({vlib_cli_output (vm, "%U", format_map_ip6_reass, f6);})); |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1080 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1081 | return (0); |
| 1082 | } |
| 1083 | |
| 1084 | u64 |
| 1085 | map_error_counter_get (u32 node_index, map_error_t map_error) |
| 1086 | { |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1087 | vlib_main_t *vm = vlib_get_main (); |
| 1088 | vlib_node_runtime_t *error_node = vlib_node_get_runtime (vm, node_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1089 | vlib_error_main_t *em = &vm->error_main; |
| 1090 | vlib_error_t e = error_node->errors[map_error]; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1091 | vlib_node_t *n = vlib_get_node (vm, node_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1092 | u32 ci; |
| 1093 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1094 | ci = vlib_error_get_code (e); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1095 | ASSERT (ci < n->n_errors); |
| 1096 | ci += n->error_heap_index; |
| 1097 | |
| 1098 | return (em->counters[ci]); |
| 1099 | } |
| 1100 | |
| 1101 | static clib_error_t * |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1102 | show_map_stats_command_fn (vlib_main_t * vm, unformat_input_t * input, |
| 1103 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1104 | { |
| 1105 | map_main_t *mm = &map_main; |
| 1106 | map_domain_t *d; |
| 1107 | int domains = 0, rules = 0, domaincount = 0, rulecount = 0; |
| 1108 | if (pool_elts (mm->domains) == 0) |
Ole Troan | c08b096 | 2017-06-26 18:12:37 +0200 | [diff] [blame] | 1109 | { |
| 1110 | vlib_cli_output (vm, "No MAP domains are configured..."); |
| 1111 | return 0; |
| 1112 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1113 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1114 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1115 | pool_foreach(d, mm->domains, ({ |
| 1116 | if (d->rules) { |
| 1117 | rulecount+= 0x1 << d->psid_length; |
| 1118 | rules += sizeof(ip6_address_t) * 0x1 << d->psid_length; |
| 1119 | } |
| 1120 | domains += sizeof(*d); |
| 1121 | domaincount++; |
| 1122 | })); |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1123 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1124 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1125 | vlib_cli_output (vm, "MAP domains structure: %d\n", sizeof (map_domain_t)); |
| 1126 | vlib_cli_output (vm, "MAP domains: %d (%d bytes)\n", domaincount, domains); |
| 1127 | vlib_cli_output (vm, "MAP rules: %d (%d bytes)\n", rulecount, rules); |
| 1128 | vlib_cli_output (vm, "Total: %d bytes)\n", rules + domains); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1129 | |
| 1130 | #if MAP_SKIP_IP6_LOOKUP |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1131 | vlib_cli_output (vm, |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 1132 | "MAP pre-resolve: IP6 next-hop: %U, IP4 next-hop: %U\n", |
| 1133 | format_map_pre_resolve, &pre_resolved[FIB_PROTOCOL_IP6], |
| 1134 | format_map_pre_resolve, &pre_resolved[FIB_PROTOCOL_IP4]); |
| 1135 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1136 | #endif |
| 1137 | |
| 1138 | if (mm->tc_copy) |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1139 | vlib_cli_output (vm, "MAP traffic-class: copy"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1140 | else |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1141 | vlib_cli_output (vm, "MAP traffic-class: %x", mm->tc); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1142 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1143 | vlib_cli_output (vm, |
| 1144 | "MAP IPv6 inbound security check: %s, fragmented packet security check: %s", |
| 1145 | mm->sec_check ? "enabled" : "disabled", |
| 1146 | mm->sec_check_frag ? "enabled" : "disabled"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1147 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1148 | vlib_cli_output (vm, "ICMP-relay IPv4 source address: %U\n", |
| 1149 | format_ip4_address, &mm->icmp4_src_address); |
| 1150 | vlib_cli_output (vm, "ICMP6 unreachables sent for unmatched packets: %s\n", |
| 1151 | mm->icmp6_enabled ? "enabled" : "disabled"); |
| 1152 | vlib_cli_output (vm, "Inner fragmentation: %s\n", |
| 1153 | mm->frag_inner ? "enabled" : "disabled"); |
| 1154 | vlib_cli_output (vm, "Fragment packets regardless of DF flag: %s\n", |
| 1155 | mm->frag_ignore_df ? "enabled" : "disabled"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1156 | |
| 1157 | /* |
| 1158 | * Counters |
| 1159 | */ |
| 1160 | vlib_combined_counter_main_t *cm = mm->domain_counters; |
| 1161 | u64 total_pkts[MAP_N_DOMAIN_COUNTER]; |
| 1162 | u64 total_bytes[MAP_N_DOMAIN_COUNTER]; |
| 1163 | int which, i; |
| 1164 | vlib_counter_t v; |
| 1165 | |
| 1166 | memset (total_pkts, 0, sizeof (total_pkts)); |
| 1167 | memset (total_bytes, 0, sizeof (total_bytes)); |
| 1168 | |
| 1169 | map_domain_counter_lock (mm); |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1170 | vec_foreach (cm, mm->domain_counters) |
| 1171 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1172 | which = cm - mm->domain_counters; |
| 1173 | |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 1174 | for (i = 0; i < vlib_combined_counter_n_counters (cm); i++) |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1175 | { |
| 1176 | vlib_get_combined_counter (cm, i, &v); |
| 1177 | total_pkts[which] += v.packets; |
| 1178 | total_bytes[which] += v.bytes; |
| 1179 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1180 | } |
| 1181 | map_domain_counter_unlock (mm); |
| 1182 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1183 | vlib_cli_output (vm, "Encapsulated packets: %lld bytes: %lld\n", |
| 1184 | total_pkts[MAP_DOMAIN_COUNTER_TX], |
| 1185 | total_bytes[MAP_DOMAIN_COUNTER_TX]); |
| 1186 | vlib_cli_output (vm, "Decapsulated packets: %lld bytes: %lld\n", |
| 1187 | total_pkts[MAP_DOMAIN_COUNTER_RX], |
| 1188 | total_bytes[MAP_DOMAIN_COUNTER_RX]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1189 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1190 | vlib_cli_output (vm, "ICMP relayed packets: %d\n", |
| 1191 | vlib_get_simple_counter (&mm->icmp_relayed, 0)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1192 | |
| 1193 | return 0; |
| 1194 | } |
| 1195 | |
| 1196 | static clib_error_t * |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1197 | map_params_reass_command_fn (vlib_main_t * vm, unformat_input_t * input, |
| 1198 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1199 | { |
| 1200 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1201 | u32 lifetime = ~0; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1202 | f64 ht_ratio = (MAP_IP4_REASS_CONF_HT_RATIO_MAX + 1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1203 | u32 pool_size = ~0; |
| 1204 | u64 buffers = ~(0ull); |
| 1205 | u8 ip4 = 0, ip6 = 0; |
| 1206 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1207 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 1208 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1209 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1210 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1211 | { |
Ole Troan | 58a90a4 | 2016-08-04 10:19:17 +0200 | [diff] [blame] | 1212 | if (unformat (line_input, "lifetime %u", &lifetime)) |
| 1213 | ; |
| 1214 | else if (unformat (line_input, "ht-ratio %lf", &ht_ratio)) |
| 1215 | ; |
| 1216 | else if (unformat (line_input, "pool-size %u", &pool_size)) |
| 1217 | ; |
| 1218 | else if (unformat (line_input, "buffers %llu", &buffers)) |
| 1219 | ; |
| 1220 | else if (unformat (line_input, "ip4")) |
| 1221 | ip4 = 1; |
| 1222 | else if (unformat (line_input, "ip6")) |
| 1223 | ip6 = 1; |
| 1224 | else |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1225 | { |
| 1226 | unformat_free (line_input); |
| 1227 | return clib_error_return (0, "invalid input"); |
| 1228 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1229 | } |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1230 | unformat_free (line_input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1231 | |
| 1232 | if (!ip4 && !ip6) |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1233 | return clib_error_return (0, "must specify ip4 and/or ip6"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1234 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1235 | if (ip4) |
| 1236 | { |
| 1237 | if (pool_size != ~0 && pool_size > MAP_IP4_REASS_CONF_POOL_SIZE_MAX) |
| 1238 | return clib_error_return (0, "invalid ip4-reass pool-size ( > %d)", |
| 1239 | MAP_IP4_REASS_CONF_POOL_SIZE_MAX); |
| 1240 | if (ht_ratio != (MAP_IP4_REASS_CONF_HT_RATIO_MAX + 1) |
| 1241 | && ht_ratio > MAP_IP4_REASS_CONF_HT_RATIO_MAX) |
| 1242 | return clib_error_return (0, "invalid ip4-reass ht-ratio ( > %d)", |
| 1243 | MAP_IP4_REASS_CONF_HT_RATIO_MAX); |
| 1244 | if (lifetime != ~0 && lifetime > MAP_IP4_REASS_CONF_LIFETIME_MAX) |
| 1245 | return clib_error_return (0, "invalid ip4-reass lifetime ( > %d)", |
| 1246 | MAP_IP4_REASS_CONF_LIFETIME_MAX); |
| 1247 | if (buffers != ~(0ull) && buffers > MAP_IP4_REASS_CONF_BUFFERS_MAX) |
| 1248 | return clib_error_return (0, "invalid ip4-reass buffers ( > %ld)", |
| 1249 | MAP_IP4_REASS_CONF_BUFFERS_MAX); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1250 | } |
| 1251 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1252 | if (ip6) |
| 1253 | { |
| 1254 | if (pool_size != ~0 && pool_size > MAP_IP6_REASS_CONF_POOL_SIZE_MAX) |
| 1255 | return clib_error_return (0, "invalid ip6-reass pool-size ( > %d)", |
| 1256 | MAP_IP6_REASS_CONF_POOL_SIZE_MAX); |
| 1257 | if (ht_ratio != (MAP_IP4_REASS_CONF_HT_RATIO_MAX + 1) |
| 1258 | && ht_ratio > MAP_IP6_REASS_CONF_HT_RATIO_MAX) |
| 1259 | return clib_error_return (0, "invalid ip6-reass ht-log2len ( > %d)", |
| 1260 | MAP_IP6_REASS_CONF_HT_RATIO_MAX); |
| 1261 | if (lifetime != ~0 && lifetime > MAP_IP6_REASS_CONF_LIFETIME_MAX) |
| 1262 | return clib_error_return (0, "invalid ip6-reass lifetime ( > %d)", |
| 1263 | MAP_IP6_REASS_CONF_LIFETIME_MAX); |
| 1264 | if (buffers != ~(0ull) && buffers > MAP_IP6_REASS_CONF_BUFFERS_MAX) |
| 1265 | return clib_error_return (0, "invalid ip6-reass buffers ( > %ld)", |
| 1266 | MAP_IP6_REASS_CONF_BUFFERS_MAX); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1267 | } |
| 1268 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1269 | if (ip4) |
| 1270 | { |
| 1271 | u32 reass = 0, packets = 0; |
| 1272 | if (pool_size != ~0) |
| 1273 | { |
| 1274 | if (map_ip4_reass_conf_pool_size (pool_size, &reass, &packets)) |
| 1275 | { |
| 1276 | vlib_cli_output (vm, "Could not set ip4-reass pool-size"); |
| 1277 | } |
| 1278 | else |
| 1279 | { |
| 1280 | vlib_cli_output (vm, |
| 1281 | "Setting ip4-reass pool-size (destroyed-reassembly=%u , dropped-fragments=%u)", |
| 1282 | reass, packets); |
| 1283 | } |
| 1284 | } |
| 1285 | if (ht_ratio != (MAP_IP4_REASS_CONF_HT_RATIO_MAX + 1)) |
| 1286 | { |
| 1287 | if (map_ip4_reass_conf_ht_ratio (ht_ratio, &reass, &packets)) |
| 1288 | { |
| 1289 | vlib_cli_output (vm, "Could not set ip4-reass ht-log2len"); |
| 1290 | } |
| 1291 | else |
| 1292 | { |
| 1293 | vlib_cli_output (vm, |
| 1294 | "Setting ip4-reass ht-log2len (destroyed-reassembly=%u , dropped-fragments=%u)", |
| 1295 | reass, packets); |
| 1296 | } |
| 1297 | } |
| 1298 | if (lifetime != ~0) |
| 1299 | { |
| 1300 | if (map_ip4_reass_conf_lifetime (lifetime)) |
| 1301 | vlib_cli_output (vm, "Could not set ip4-reass lifetime"); |
| 1302 | else |
| 1303 | vlib_cli_output (vm, "Setting ip4-reass lifetime"); |
| 1304 | } |
| 1305 | if (buffers != ~(0ull)) |
| 1306 | { |
| 1307 | if (map_ip4_reass_conf_buffers (buffers)) |
| 1308 | vlib_cli_output (vm, "Could not set ip4-reass buffers"); |
| 1309 | else |
| 1310 | vlib_cli_output (vm, "Setting ip4-reass buffers"); |
| 1311 | } |
| 1312 | |
| 1313 | if (map_main.ip4_reass_conf_buffers > |
| 1314 | map_main.ip4_reass_conf_pool_size * |
| 1315 | MAP_IP4_REASS_MAX_FRAGMENTS_PER_REASSEMBLY) |
| 1316 | { |
| 1317 | vlib_cli_output (vm, |
| 1318 | "Note: 'ip4-reass buffers' > pool-size * max-fragments-per-reassembly."); |
| 1319 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1320 | } |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1321 | |
| 1322 | if (ip6) |
| 1323 | { |
| 1324 | u32 reass = 0, packets = 0; |
| 1325 | if (pool_size != ~0) |
| 1326 | { |
| 1327 | if (map_ip6_reass_conf_pool_size (pool_size, &reass, &packets)) |
| 1328 | { |
| 1329 | vlib_cli_output (vm, "Could not set ip6-reass pool-size"); |
| 1330 | } |
| 1331 | else |
| 1332 | { |
| 1333 | vlib_cli_output (vm, |
| 1334 | "Setting ip6-reass pool-size (destroyed-reassembly=%u , dropped-fragments=%u)", |
| 1335 | reass, packets); |
| 1336 | } |
| 1337 | } |
| 1338 | if (ht_ratio != (MAP_IP4_REASS_CONF_HT_RATIO_MAX + 1)) |
| 1339 | { |
| 1340 | if (map_ip6_reass_conf_ht_ratio (ht_ratio, &reass, &packets)) |
| 1341 | { |
| 1342 | vlib_cli_output (vm, "Could not set ip6-reass ht-log2len"); |
| 1343 | } |
| 1344 | else |
| 1345 | { |
| 1346 | vlib_cli_output (vm, |
| 1347 | "Setting ip6-reass ht-log2len (destroyed-reassembly=%u , dropped-fragments=%u)", |
| 1348 | reass, packets); |
| 1349 | } |
| 1350 | } |
| 1351 | if (lifetime != ~0) |
| 1352 | { |
| 1353 | if (map_ip6_reass_conf_lifetime (lifetime)) |
| 1354 | vlib_cli_output (vm, "Could not set ip6-reass lifetime"); |
| 1355 | else |
| 1356 | vlib_cli_output (vm, "Setting ip6-reass lifetime"); |
| 1357 | } |
| 1358 | if (buffers != ~(0ull)) |
| 1359 | { |
| 1360 | if (map_ip6_reass_conf_buffers (buffers)) |
| 1361 | vlib_cli_output (vm, "Could not set ip6-reass buffers"); |
| 1362 | else |
| 1363 | vlib_cli_output (vm, "Setting ip6-reass buffers"); |
| 1364 | } |
| 1365 | |
| 1366 | if (map_main.ip6_reass_conf_buffers > |
| 1367 | map_main.ip6_reass_conf_pool_size * |
| 1368 | MAP_IP6_REASS_MAX_FRAGMENTS_PER_REASSEMBLY) |
| 1369 | { |
| 1370 | vlib_cli_output (vm, |
| 1371 | "Note: 'ip6-reass buffers' > pool-size * max-fragments-per-reassembly."); |
| 1372 | } |
| 1373 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1374 | |
| 1375 | return 0; |
| 1376 | } |
| 1377 | |
| 1378 | |
| 1379 | /* |
| 1380 | * packet trace format function |
| 1381 | */ |
| 1382 | u8 * |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1383 | format_map_trace (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1384 | { |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1385 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 1386 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1387 | map_trace_t *t = va_arg (*args, map_trace_t *); |
| 1388 | u32 map_domain_index = t->map_domain_index; |
| 1389 | u16 port = t->port; |
| 1390 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1391 | s = |
| 1392 | format (s, "MAP domain index: %d L4 port: %u", map_domain_index, |
| 1393 | clib_net_to_host_u16 (port)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1394 | |
| 1395 | return s; |
| 1396 | } |
| 1397 | |
| 1398 | static_always_inline map_ip4_reass_t * |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1399 | map_ip4_reass_lookup (map_ip4_reass_key_t * k, u32 bucket, f64 now) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1400 | { |
| 1401 | map_main_t *mm = &map_main; |
| 1402 | u32 ri = mm->ip4_reass_hash_table[bucket]; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1403 | while (ri != MAP_REASS_INDEX_NONE) |
| 1404 | { |
| 1405 | map_ip4_reass_t *r = pool_elt_at_index (mm->ip4_reass_pool, ri); |
| 1406 | if (r->key.as_u64[0] == k->as_u64[0] && |
| 1407 | r->key.as_u64[1] == k->as_u64[1] && |
| 1408 | now < r->ts + (((f64) mm->ip4_reass_conf_lifetime_ms) / 1000)) |
| 1409 | { |
| 1410 | return r; |
| 1411 | } |
| 1412 | ri = r->bucket_next; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1413 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1414 | return NULL; |
| 1415 | } |
| 1416 | |
| 1417 | #define map_ip4_reass_pool_index(r) (r - map_main.ip4_reass_pool) |
| 1418 | |
| 1419 | void |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1420 | map_ip4_reass_free (map_ip4_reass_t * r, u32 ** pi_to_drop) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1421 | { |
| 1422 | map_main_t *mm = &map_main; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1423 | map_ip4_reass_get_fragments (r, pi_to_drop); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1424 | |
| 1425 | // Unlink in hash bucket |
| 1426 | map_ip4_reass_t *r2 = NULL; |
| 1427 | u32 r2i = mm->ip4_reass_hash_table[r->bucket]; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1428 | while (r2i != map_ip4_reass_pool_index (r)) |
| 1429 | { |
| 1430 | ASSERT (r2i != MAP_REASS_INDEX_NONE); |
| 1431 | r2 = pool_elt_at_index (mm->ip4_reass_pool, r2i); |
| 1432 | r2i = r2->bucket_next; |
| 1433 | } |
| 1434 | if (r2) |
| 1435 | { |
| 1436 | r2->bucket_next = r->bucket_next; |
| 1437 | } |
| 1438 | else |
| 1439 | { |
| 1440 | mm->ip4_reass_hash_table[r->bucket] = r->bucket_next; |
| 1441 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1442 | |
| 1443 | // Unlink in list |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1444 | if (r->fifo_next == map_ip4_reass_pool_index (r)) |
| 1445 | { |
| 1446 | mm->ip4_reass_fifo_last = MAP_REASS_INDEX_NONE; |
| 1447 | } |
| 1448 | else |
| 1449 | { |
| 1450 | if (mm->ip4_reass_fifo_last == map_ip4_reass_pool_index (r)) |
| 1451 | mm->ip4_reass_fifo_last = r->fifo_prev; |
| 1452 | pool_elt_at_index (mm->ip4_reass_pool, r->fifo_prev)->fifo_next = |
| 1453 | r->fifo_next; |
| 1454 | pool_elt_at_index (mm->ip4_reass_pool, r->fifo_next)->fifo_prev = |
| 1455 | r->fifo_prev; |
| 1456 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1457 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1458 | pool_put (mm->ip4_reass_pool, r); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1459 | mm->ip4_reass_allocated--; |
| 1460 | } |
| 1461 | |
| 1462 | map_ip4_reass_t * |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1463 | map_ip4_reass_get (u32 src, u32 dst, u16 fragment_id, |
| 1464 | u8 protocol, u32 ** pi_to_drop) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1465 | { |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1466 | map_ip4_reass_t *r; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1467 | map_main_t *mm = &map_main; |
| 1468 | map_ip4_reass_key_t k = {.src.data_u32 = src, |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1469 | .dst.data_u32 = dst, |
| 1470 | .fragment_id = fragment_id, |
| 1471 | .protocol = protocol |
| 1472 | }; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1473 | |
| 1474 | u32 h = 0; |
Christophe Fontaine | b4bd28a | 2017-05-31 11:27:19 +0200 | [diff] [blame] | 1475 | #ifdef clib_crc32c_uses_intrinsics |
| 1476 | h = clib_crc32c ((u8 *) k.as_u32, 16); |
| 1477 | #else |
| 1478 | u64 tmp = k.as_u32[0] ^ k.as_u32[1] ^ k.as_u32[2] ^ k.as_u32[3]; |
| 1479 | h = clib_xxhash (tmp); |
| 1480 | #endif |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1481 | h = h >> (32 - mm->ip4_reass_ht_log2len); |
| 1482 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1483 | f64 now = vlib_time_now (mm->vlib_main); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1484 | |
| 1485 | //Cache garbage collection |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1486 | while (mm->ip4_reass_fifo_last != MAP_REASS_INDEX_NONE) |
| 1487 | { |
| 1488 | map_ip4_reass_t *last = |
| 1489 | pool_elt_at_index (mm->ip4_reass_pool, mm->ip4_reass_fifo_last); |
| 1490 | if (last->ts + (((f64) mm->ip4_reass_conf_lifetime_ms) / 1000) < now) |
| 1491 | map_ip4_reass_free (last, pi_to_drop); |
| 1492 | else |
| 1493 | break; |
| 1494 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1495 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1496 | if ((r = map_ip4_reass_lookup (&k, h, now))) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1497 | return r; |
| 1498 | |
| 1499 | if (mm->ip4_reass_allocated >= mm->ip4_reass_conf_pool_size) |
| 1500 | return NULL; |
| 1501 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1502 | pool_get (mm->ip4_reass_pool, r); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1503 | mm->ip4_reass_allocated++; |
| 1504 | int i; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1505 | for (i = 0; i < MAP_IP4_REASS_MAX_FRAGMENTS_PER_REASSEMBLY; i++) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1506 | r->fragments[i] = ~0; |
| 1507 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1508 | u32 ri = map_ip4_reass_pool_index (r); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1509 | |
| 1510 | //Link in new bucket |
| 1511 | r->bucket = h; |
| 1512 | r->bucket_next = mm->ip4_reass_hash_table[h]; |
| 1513 | mm->ip4_reass_hash_table[h] = ri; |
| 1514 | |
| 1515 | //Link in fifo |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1516 | if (mm->ip4_reass_fifo_last != MAP_REASS_INDEX_NONE) |
| 1517 | { |
| 1518 | r->fifo_next = |
| 1519 | pool_elt_at_index (mm->ip4_reass_pool, |
| 1520 | mm->ip4_reass_fifo_last)->fifo_next; |
| 1521 | r->fifo_prev = mm->ip4_reass_fifo_last; |
| 1522 | pool_elt_at_index (mm->ip4_reass_pool, r->fifo_prev)->fifo_next = ri; |
| 1523 | pool_elt_at_index (mm->ip4_reass_pool, r->fifo_next)->fifo_prev = ri; |
| 1524 | } |
| 1525 | else |
| 1526 | { |
| 1527 | r->fifo_next = r->fifo_prev = ri; |
| 1528 | mm->ip4_reass_fifo_last = ri; |
| 1529 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1530 | |
| 1531 | //Set other fields |
| 1532 | r->ts = now; |
| 1533 | r->key = k; |
| 1534 | r->port = -1; |
| 1535 | #ifdef MAP_IP4_REASS_COUNT_BYTES |
| 1536 | r->expected_total = 0xffff; |
| 1537 | r->forwarded = 0; |
| 1538 | #endif |
| 1539 | |
| 1540 | return r; |
| 1541 | } |
| 1542 | |
| 1543 | int |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1544 | map_ip4_reass_add_fragment (map_ip4_reass_t * r, u32 pi) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1545 | { |
| 1546 | if (map_main.ip4_reass_buffered_counter >= map_main.ip4_reass_conf_buffers) |
| 1547 | return -1; |
| 1548 | |
| 1549 | int i; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1550 | for (i = 0; i < MAP_IP4_REASS_MAX_FRAGMENTS_PER_REASSEMBLY; i++) |
| 1551 | if (r->fragments[i] == ~0) |
| 1552 | { |
| 1553 | r->fragments[i] = pi; |
| 1554 | map_main.ip4_reass_buffered_counter++; |
| 1555 | return 0; |
| 1556 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1557 | return -1; |
| 1558 | } |
| 1559 | |
| 1560 | static_always_inline map_ip6_reass_t * |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1561 | map_ip6_reass_lookup (map_ip6_reass_key_t * k, u32 bucket, f64 now) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1562 | { |
| 1563 | map_main_t *mm = &map_main; |
| 1564 | u32 ri = mm->ip6_reass_hash_table[bucket]; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1565 | while (ri != MAP_REASS_INDEX_NONE) |
| 1566 | { |
| 1567 | map_ip6_reass_t *r = pool_elt_at_index (mm->ip6_reass_pool, ri); |
| 1568 | if (now < r->ts + (((f64) mm->ip6_reass_conf_lifetime_ms) / 1000) && |
| 1569 | r->key.as_u64[0] == k->as_u64[0] && |
| 1570 | r->key.as_u64[1] == k->as_u64[1] && |
| 1571 | r->key.as_u64[2] == k->as_u64[2] && |
| 1572 | r->key.as_u64[3] == k->as_u64[3] && |
| 1573 | r->key.as_u64[4] == k->as_u64[4]) |
| 1574 | return r; |
| 1575 | ri = r->bucket_next; |
| 1576 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1577 | return NULL; |
| 1578 | } |
| 1579 | |
| 1580 | #define map_ip6_reass_pool_index(r) (r - map_main.ip6_reass_pool) |
| 1581 | |
| 1582 | void |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1583 | map_ip6_reass_free (map_ip6_reass_t * r, u32 ** pi_to_drop) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1584 | { |
| 1585 | map_main_t *mm = &map_main; |
| 1586 | int i; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1587 | for (i = 0; i < MAP_IP6_REASS_MAX_FRAGMENTS_PER_REASSEMBLY; i++) |
| 1588 | if (r->fragments[i].pi != ~0) |
| 1589 | { |
| 1590 | vec_add1 (*pi_to_drop, r->fragments[i].pi); |
| 1591 | r->fragments[i].pi = ~0; |
| 1592 | map_main.ip6_reass_buffered_counter--; |
| 1593 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1594 | |
| 1595 | // Unlink in hash bucket |
| 1596 | map_ip6_reass_t *r2 = NULL; |
| 1597 | u32 r2i = mm->ip6_reass_hash_table[r->bucket]; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1598 | while (r2i != map_ip6_reass_pool_index (r)) |
| 1599 | { |
| 1600 | ASSERT (r2i != MAP_REASS_INDEX_NONE); |
| 1601 | r2 = pool_elt_at_index (mm->ip6_reass_pool, r2i); |
| 1602 | r2i = r2->bucket_next; |
| 1603 | } |
| 1604 | if (r2) |
| 1605 | { |
| 1606 | r2->bucket_next = r->bucket_next; |
| 1607 | } |
| 1608 | else |
| 1609 | { |
| 1610 | mm->ip6_reass_hash_table[r->bucket] = r->bucket_next; |
| 1611 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1612 | |
| 1613 | // Unlink in list |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1614 | if (r->fifo_next == map_ip6_reass_pool_index (r)) |
| 1615 | { |
| 1616 | //Single element in the list, list is now empty |
| 1617 | mm->ip6_reass_fifo_last = MAP_REASS_INDEX_NONE; |
| 1618 | } |
| 1619 | else |
| 1620 | { |
| 1621 | if (mm->ip6_reass_fifo_last == map_ip6_reass_pool_index (r)) //First element |
| 1622 | mm->ip6_reass_fifo_last = r->fifo_prev; |
| 1623 | pool_elt_at_index (mm->ip6_reass_pool, r->fifo_prev)->fifo_next = |
| 1624 | r->fifo_next; |
| 1625 | pool_elt_at_index (mm->ip6_reass_pool, r->fifo_next)->fifo_prev = |
| 1626 | r->fifo_prev; |
| 1627 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1628 | |
| 1629 | // Free from pool if necessary |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1630 | pool_put (mm->ip6_reass_pool, r); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1631 | mm->ip6_reass_allocated--; |
| 1632 | } |
| 1633 | |
| 1634 | map_ip6_reass_t * |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1635 | map_ip6_reass_get (ip6_address_t * src, ip6_address_t * dst, u32 fragment_id, |
| 1636 | u8 protocol, u32 ** pi_to_drop) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1637 | { |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1638 | map_ip6_reass_t *r; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1639 | map_main_t *mm = &map_main; |
| 1640 | map_ip6_reass_key_t k = { |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1641 | .src = *src, |
| 1642 | .dst = *dst, |
| 1643 | .fragment_id = fragment_id, |
| 1644 | .protocol = protocol |
| 1645 | }; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1646 | |
| 1647 | u32 h = 0; |
| 1648 | int i; |
Christophe Fontaine | b4bd28a | 2017-05-31 11:27:19 +0200 | [diff] [blame] | 1649 | |
| 1650 | #ifdef clib_crc32c_uses_intrinsics |
| 1651 | h = clib_crc32c ((u8 *) k.as_u32, 40); |
| 1652 | #else |
| 1653 | u64 tmp = |
| 1654 | k.as_u64[0] ^ k.as_u64[1] ^ k.as_u64[2] ^ k.as_u64[3] ^ k.as_u64[4]; |
| 1655 | h = clib_xxhash (tmp); |
| 1656 | #endif |
| 1657 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1658 | h = h >> (32 - mm->ip6_reass_ht_log2len); |
| 1659 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1660 | f64 now = vlib_time_now (mm->vlib_main); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1661 | |
| 1662 | //Cache garbage collection |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1663 | while (mm->ip6_reass_fifo_last != MAP_REASS_INDEX_NONE) |
| 1664 | { |
| 1665 | map_ip6_reass_t *last = |
| 1666 | pool_elt_at_index (mm->ip6_reass_pool, mm->ip6_reass_fifo_last); |
| 1667 | if (last->ts + (((f64) mm->ip6_reass_conf_lifetime_ms) / 1000) < now) |
| 1668 | map_ip6_reass_free (last, pi_to_drop); |
| 1669 | else |
| 1670 | break; |
| 1671 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1672 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1673 | if ((r = map_ip6_reass_lookup (&k, h, now))) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1674 | return r; |
| 1675 | |
| 1676 | if (mm->ip6_reass_allocated >= mm->ip6_reass_conf_pool_size) |
| 1677 | return NULL; |
| 1678 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1679 | pool_get (mm->ip6_reass_pool, r); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1680 | mm->ip6_reass_allocated++; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1681 | for (i = 0; i < MAP_IP6_REASS_MAX_FRAGMENTS_PER_REASSEMBLY; i++) |
| 1682 | { |
| 1683 | r->fragments[i].pi = ~0; |
| 1684 | r->fragments[i].next_data_len = 0; |
| 1685 | r->fragments[i].next_data_offset = 0; |
| 1686 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1687 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1688 | u32 ri = map_ip6_reass_pool_index (r); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1689 | |
| 1690 | //Link in new bucket |
| 1691 | r->bucket = h; |
| 1692 | r->bucket_next = mm->ip6_reass_hash_table[h]; |
| 1693 | mm->ip6_reass_hash_table[h] = ri; |
| 1694 | |
| 1695 | //Link in fifo |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1696 | if (mm->ip6_reass_fifo_last != MAP_REASS_INDEX_NONE) |
| 1697 | { |
| 1698 | r->fifo_next = |
| 1699 | pool_elt_at_index (mm->ip6_reass_pool, |
| 1700 | mm->ip6_reass_fifo_last)->fifo_next; |
| 1701 | r->fifo_prev = mm->ip6_reass_fifo_last; |
| 1702 | pool_elt_at_index (mm->ip6_reass_pool, r->fifo_prev)->fifo_next = ri; |
| 1703 | pool_elt_at_index (mm->ip6_reass_pool, r->fifo_next)->fifo_prev = ri; |
| 1704 | } |
| 1705 | else |
| 1706 | { |
| 1707 | r->fifo_next = r->fifo_prev = ri; |
| 1708 | mm->ip6_reass_fifo_last = ri; |
| 1709 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1710 | |
| 1711 | //Set other fields |
| 1712 | r->ts = now; |
| 1713 | r->key = k; |
| 1714 | r->ip4_header.ip_version_and_header_length = 0; |
| 1715 | #ifdef MAP_IP6_REASS_COUNT_BYTES |
| 1716 | r->expected_total = 0xffff; |
| 1717 | r->forwarded = 0; |
| 1718 | #endif |
| 1719 | return r; |
| 1720 | } |
| 1721 | |
| 1722 | int |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1723 | map_ip6_reass_add_fragment (map_ip6_reass_t * r, u32 pi, |
| 1724 | u16 data_offset, u16 next_data_offset, |
| 1725 | u8 * data_start, u16 data_len) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1726 | { |
| 1727 | map_ip6_fragment_t *f = NULL, *prev_f = NULL; |
| 1728 | u16 copied_len = (data_len > 20) ? 20 : data_len; |
| 1729 | |
| 1730 | if (map_main.ip6_reass_buffered_counter >= map_main.ip6_reass_conf_buffers) |
| 1731 | return -1; |
| 1732 | |
| 1733 | //Lookup for fragments for the current buffer |
| 1734 | //and the one before that |
| 1735 | int i; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1736 | for (i = 0; i < MAP_IP6_REASS_MAX_FRAGMENTS_PER_REASSEMBLY; i++) |
| 1737 | { |
| 1738 | if (data_offset && r->fragments[i].next_data_offset == data_offset) |
| 1739 | { |
| 1740 | prev_f = &r->fragments[i]; // This is buffer for previous packet |
| 1741 | } |
| 1742 | else if (r->fragments[i].next_data_offset == next_data_offset) |
| 1743 | { |
| 1744 | f = &r->fragments[i]; // This is a buffer for the current packet |
| 1745 | } |
| 1746 | else if (r->fragments[i].next_data_offset == 0) |
| 1747 | { //Available |
| 1748 | if (f == NULL) |
| 1749 | f = &r->fragments[i]; |
| 1750 | else if (prev_f == NULL) |
| 1751 | prev_f = &r->fragments[i]; |
| 1752 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1753 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1754 | |
| 1755 | if (!f || f->pi != ~0) |
| 1756 | return -1; |
| 1757 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1758 | if (data_offset) |
| 1759 | { |
| 1760 | if (!prev_f) |
| 1761 | return -1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1762 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1763 | clib_memcpy (prev_f->next_data, data_start, copied_len); |
| 1764 | prev_f->next_data_len = copied_len; |
| 1765 | prev_f->next_data_offset = data_offset; |
| 1766 | } |
| 1767 | else |
| 1768 | { |
| 1769 | if (((ip4_header_t *) data_start)->ip_version_and_header_length != 0x45) |
| 1770 | return -1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1771 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1772 | if (r->ip4_header.ip_version_and_header_length == 0) |
| 1773 | clib_memcpy (&r->ip4_header, data_start, sizeof (ip4_header_t)); |
| 1774 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1775 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1776 | if (data_len > 20) |
| 1777 | { |
| 1778 | f->next_data_offset = next_data_offset; |
| 1779 | f->pi = pi; |
| 1780 | map_main.ip6_reass_buffered_counter++; |
| 1781 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1782 | return 0; |
| 1783 | } |
| 1784 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1785 | void |
| 1786 | map_ip4_reass_reinit (u32 * trashed_reass, u32 * dropped_packets) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1787 | { |
| 1788 | map_main_t *mm = &map_main; |
| 1789 | int i; |
| 1790 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1791 | if (dropped_packets) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1792 | *dropped_packets = mm->ip4_reass_buffered_counter; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1793 | if (trashed_reass) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1794 | *trashed_reass = mm->ip4_reass_allocated; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1795 | if (mm->ip4_reass_fifo_last != MAP_REASS_INDEX_NONE) |
| 1796 | { |
| 1797 | u16 ri = mm->ip4_reass_fifo_last; |
| 1798 | do |
| 1799 | { |
| 1800 | map_ip4_reass_t *r = pool_elt_at_index (mm->ip4_reass_pool, ri); |
| 1801 | for (i = 0; i < MAP_IP4_REASS_MAX_FRAGMENTS_PER_REASSEMBLY; i++) |
| 1802 | if (r->fragments[i] != ~0) |
| 1803 | map_ip4_drop_pi (r->fragments[i]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1804 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1805 | ri = r->fifo_next; |
| 1806 | pool_put (mm->ip4_reass_pool, r); |
| 1807 | } |
| 1808 | while (ri != mm->ip4_reass_fifo_last); |
| 1809 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1810 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1811 | vec_free (mm->ip4_reass_hash_table); |
| 1812 | vec_resize (mm->ip4_reass_hash_table, 1 << mm->ip4_reass_ht_log2len); |
| 1813 | for (i = 0; i < (1 << mm->ip4_reass_ht_log2len); i++) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1814 | mm->ip4_reass_hash_table[i] = MAP_REASS_INDEX_NONE; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1815 | pool_free (mm->ip4_reass_pool); |
| 1816 | pool_alloc (mm->ip4_reass_pool, mm->ip4_reass_conf_pool_size); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1817 | |
| 1818 | mm->ip4_reass_allocated = 0; |
| 1819 | mm->ip4_reass_fifo_last = MAP_REASS_INDEX_NONE; |
| 1820 | mm->ip4_reass_buffered_counter = 0; |
| 1821 | } |
| 1822 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1823 | u8 |
| 1824 | map_get_ht_log2len (f32 ht_ratio, u16 pool_size) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1825 | { |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1826 | u32 desired_size = (u32) (pool_size * ht_ratio); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1827 | u8 i; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1828 | for (i = 1; i < 31; i++) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1829 | if ((1 << i) >= desired_size) |
| 1830 | return i; |
| 1831 | return 4; |
| 1832 | } |
| 1833 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1834 | int |
| 1835 | map_ip4_reass_conf_ht_ratio (f32 ht_ratio, u32 * trashed_reass, |
| 1836 | u32 * dropped_packets) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1837 | { |
| 1838 | map_main_t *mm = &map_main; |
| 1839 | if (ht_ratio > MAP_IP4_REASS_CONF_HT_RATIO_MAX) |
| 1840 | return -1; |
| 1841 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1842 | map_ip4_reass_lock (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1843 | mm->ip4_reass_conf_ht_ratio = ht_ratio; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1844 | mm->ip4_reass_ht_log2len = |
| 1845 | map_get_ht_log2len (ht_ratio, mm->ip4_reass_conf_pool_size); |
| 1846 | map_ip4_reass_reinit (trashed_reass, dropped_packets); |
| 1847 | map_ip4_reass_unlock (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1848 | return 0; |
| 1849 | } |
| 1850 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1851 | int |
| 1852 | map_ip4_reass_conf_pool_size (u16 pool_size, u32 * trashed_reass, |
| 1853 | u32 * dropped_packets) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1854 | { |
| 1855 | map_main_t *mm = &map_main; |
| 1856 | if (pool_size > MAP_IP4_REASS_CONF_POOL_SIZE_MAX) |
| 1857 | return -1; |
| 1858 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1859 | map_ip4_reass_lock (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1860 | mm->ip4_reass_conf_pool_size = pool_size; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1861 | map_ip4_reass_reinit (trashed_reass, dropped_packets); |
| 1862 | map_ip4_reass_unlock (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1863 | return 0; |
| 1864 | } |
| 1865 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1866 | int |
| 1867 | map_ip4_reass_conf_lifetime (u16 lifetime_ms) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1868 | { |
| 1869 | map_main.ip4_reass_conf_lifetime_ms = lifetime_ms; |
| 1870 | return 0; |
| 1871 | } |
| 1872 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1873 | int |
| 1874 | map_ip4_reass_conf_buffers (u32 buffers) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1875 | { |
| 1876 | map_main.ip4_reass_conf_buffers = buffers; |
| 1877 | return 0; |
| 1878 | } |
| 1879 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1880 | void |
| 1881 | map_ip6_reass_reinit (u32 * trashed_reass, u32 * dropped_packets) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1882 | { |
| 1883 | map_main_t *mm = &map_main; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1884 | if (dropped_packets) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1885 | *dropped_packets = mm->ip6_reass_buffered_counter; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1886 | if (trashed_reass) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1887 | *trashed_reass = mm->ip6_reass_allocated; |
| 1888 | int i; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1889 | if (mm->ip6_reass_fifo_last != MAP_REASS_INDEX_NONE) |
| 1890 | { |
| 1891 | u16 ri = mm->ip6_reass_fifo_last; |
| 1892 | do |
| 1893 | { |
| 1894 | map_ip6_reass_t *r = pool_elt_at_index (mm->ip6_reass_pool, ri); |
| 1895 | for (i = 0; i < MAP_IP6_REASS_MAX_FRAGMENTS_PER_REASSEMBLY; i++) |
| 1896 | if (r->fragments[i].pi != ~0) |
| 1897 | map_ip6_drop_pi (r->fragments[i].pi); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1898 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1899 | ri = r->fifo_next; |
| 1900 | pool_put (mm->ip6_reass_pool, r); |
| 1901 | } |
| 1902 | while (ri != mm->ip6_reass_fifo_last); |
| 1903 | mm->ip6_reass_fifo_last = MAP_REASS_INDEX_NONE; |
| 1904 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1905 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1906 | vec_free (mm->ip6_reass_hash_table); |
| 1907 | vec_resize (mm->ip6_reass_hash_table, 1 << mm->ip6_reass_ht_log2len); |
| 1908 | for (i = 0; i < (1 << mm->ip6_reass_ht_log2len); i++) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1909 | mm->ip6_reass_hash_table[i] = MAP_REASS_INDEX_NONE; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1910 | pool_free (mm->ip6_reass_pool); |
| 1911 | pool_alloc (mm->ip6_reass_pool, mm->ip4_reass_conf_pool_size); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1912 | |
| 1913 | mm->ip6_reass_allocated = 0; |
| 1914 | mm->ip6_reass_buffered_counter = 0; |
| 1915 | } |
| 1916 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1917 | int |
| 1918 | map_ip6_reass_conf_ht_ratio (f32 ht_ratio, u32 * trashed_reass, |
| 1919 | u32 * dropped_packets) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1920 | { |
| 1921 | map_main_t *mm = &map_main; |
| 1922 | if (ht_ratio > MAP_IP6_REASS_CONF_HT_RATIO_MAX) |
| 1923 | return -1; |
| 1924 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1925 | map_ip6_reass_lock (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1926 | mm->ip6_reass_conf_ht_ratio = ht_ratio; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1927 | mm->ip6_reass_ht_log2len = |
| 1928 | map_get_ht_log2len (ht_ratio, mm->ip6_reass_conf_pool_size); |
| 1929 | map_ip6_reass_reinit (trashed_reass, dropped_packets); |
| 1930 | map_ip6_reass_unlock (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1931 | return 0; |
| 1932 | } |
| 1933 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1934 | int |
| 1935 | map_ip6_reass_conf_pool_size (u16 pool_size, u32 * trashed_reass, |
| 1936 | u32 * dropped_packets) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1937 | { |
| 1938 | map_main_t *mm = &map_main; |
| 1939 | if (pool_size > MAP_IP6_REASS_CONF_POOL_SIZE_MAX) |
| 1940 | return -1; |
| 1941 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1942 | map_ip6_reass_lock (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1943 | mm->ip6_reass_conf_pool_size = pool_size; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1944 | map_ip6_reass_reinit (trashed_reass, dropped_packets); |
| 1945 | map_ip6_reass_unlock (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1946 | return 0; |
| 1947 | } |
| 1948 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1949 | int |
| 1950 | map_ip6_reass_conf_lifetime (u16 lifetime_ms) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1951 | { |
| 1952 | map_main.ip6_reass_conf_lifetime_ms = lifetime_ms; |
| 1953 | return 0; |
| 1954 | } |
| 1955 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1956 | int |
| 1957 | map_ip6_reass_conf_buffers (u32 buffers) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1958 | { |
| 1959 | map_main.ip6_reass_conf_buffers = buffers; |
| 1960 | return 0; |
| 1961 | } |
| 1962 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 1963 | /* *INDENT-OFF* */ |
Ole Troan | 96eefd4 | 2016-09-12 12:25:30 +0200 | [diff] [blame] | 1964 | |
| 1965 | /*? |
| 1966 | * Configure MAP reassembly behaviour |
| 1967 | * |
| 1968 | * @cliexpar |
| 1969 | * @cliexstart{map params reassembly} |
| 1970 | * @cliexend |
| 1971 | ?*/ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1972 | VLIB_CLI_COMMAND(map_ip4_reass_lifetime_command, static) = { |
| 1973 | .path = "map params reassembly", |
Ole Troan | 96eefd4 | 2016-09-12 12:25:30 +0200 | [diff] [blame] | 1974 | .short_help = "map params reassembly [ip4 | ip6] [lifetime <lifetime-ms>] " |
| 1975 | "[pool-size <pool-size>] [buffers <buffers>] " |
| 1976 | "[ht-ratio <ht-ratio>]", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1977 | .function = map_params_reass_command_fn, |
| 1978 | }; |
| 1979 | |
Ole Troan | 96eefd4 | 2016-09-12 12:25:30 +0200 | [diff] [blame] | 1980 | /*? |
| 1981 | * Set or copy the IP TOS/Traffic Class field |
| 1982 | * |
| 1983 | * @cliexpar |
| 1984 | * @cliexstart{map params traffic-class} |
| 1985 | * |
| 1986 | * This command is used to set the traffic-class field in translated |
| 1987 | * or encapsulated packets. If copy is specifed (the default) then the |
| 1988 | * traffic-class/TOS field is copied from the original packet to the |
| 1989 | * translated / encapsulating header. |
| 1990 | * @cliexend |
| 1991 | ?*/ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1992 | VLIB_CLI_COMMAND(map_traffic_class_command, static) = { |
| 1993 | .path = "map params traffic-class", |
Ole Troan | 96eefd4 | 2016-09-12 12:25:30 +0200 | [diff] [blame] | 1994 | .short_help = "map params traffic-class {0x0-0xff | copy}", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1995 | .function = map_traffic_class_command_fn, |
| 1996 | }; |
| 1997 | |
Ole Troan | 96eefd4 | 2016-09-12 12:25:30 +0200 | [diff] [blame] | 1998 | /*? |
| 1999 | * Bypass IP4/IP6 lookup |
| 2000 | * |
| 2001 | * @cliexpar |
| 2002 | * @cliexstart{map params pre-resolve} |
| 2003 | * |
| 2004 | * Bypass a second FIB lookup of the translated or encapsulated |
| 2005 | * packet, and forward the packet directly to the specified |
| 2006 | * next-hop. This optimization trades forwarding flexibility for |
| 2007 | * performance. |
| 2008 | * @cliexend |
| 2009 | ?*/ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2010 | VLIB_CLI_COMMAND(map_pre_resolve_command, static) = { |
| 2011 | .path = "map params pre-resolve", |
Ole Troan | 96eefd4 | 2016-09-12 12:25:30 +0200 | [diff] [blame] | 2012 | .short_help = " map params pre-resolve {ip4-nh <address>} " |
| 2013 | "| {ip6-nh <address>}", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2014 | .function = map_pre_resolve_command_fn, |
| 2015 | }; |
| 2016 | |
Ole Troan | 96eefd4 | 2016-09-12 12:25:30 +0200 | [diff] [blame] | 2017 | /*? |
| 2018 | * Enable or disable the MAP-E inbound security check |
| 2019 | * |
| 2020 | * @cliexpar |
| 2021 | * @cliexstart{map params security-check} |
| 2022 | * |
| 2023 | * By default, a decapsulated packet's IPv4 source address will be |
| 2024 | * verified against the outer header's IPv6 source address. Disabling |
| 2025 | * this feature will allow IPv4 source address spoofing. |
| 2026 | * @cliexend |
| 2027 | ?*/ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2028 | VLIB_CLI_COMMAND(map_security_check_command, static) = { |
| 2029 | .path = "map params security-check", |
Ole Troan | 96eefd4 | 2016-09-12 12:25:30 +0200 | [diff] [blame] | 2030 | .short_help = "map params security-check on|off", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2031 | .function = map_security_check_command_fn, |
| 2032 | }; |
| 2033 | |
Ole Troan | 96eefd4 | 2016-09-12 12:25:30 +0200 | [diff] [blame] | 2034 | /*? |
| 2035 | * Specifiy the IPv4 source address used for relayed ICMP error messages |
| 2036 | * |
| 2037 | * @cliexpar |
| 2038 | * @cliexstart{map params icmp source-address} |
| 2039 | * |
| 2040 | * This command specifies which IPv4 source address (must be local to |
| 2041 | * the system), that is used for relayed received IPv6 ICMP error |
| 2042 | * messages. |
| 2043 | * @cliexend |
| 2044 | ?*/ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2045 | VLIB_CLI_COMMAND(map_icmp_relay_source_address_command, static) = { |
Ole Troan | cda9482 | 2016-01-07 14:37:25 +0100 | [diff] [blame] | 2046 | .path = "map params icmp source-address", |
Ole Troan | 96eefd4 | 2016-09-12 12:25:30 +0200 | [diff] [blame] | 2047 | .short_help = "map params icmp source-address <ip4-address>", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2048 | .function = map_icmp_relay_source_address_command_fn, |
| 2049 | }; |
| 2050 | |
Ole Troan | 96eefd4 | 2016-09-12 12:25:30 +0200 | [diff] [blame] | 2051 | /*? |
| 2052 | * Send IPv6 ICMP unreachables |
| 2053 | * |
| 2054 | * @cliexpar |
| 2055 | * @cliexstart{map params icmp6 unreachables} |
| 2056 | * |
| 2057 | * Send IPv6 ICMP unreachable messages back if security check fails or |
| 2058 | * no MAP domain exists. |
| 2059 | * @cliexend |
| 2060 | ?*/ |
Ole Troan | cda9482 | 2016-01-07 14:37:25 +0100 | [diff] [blame] | 2061 | VLIB_CLI_COMMAND(map_icmp_unreachables_command, static) = { |
Ole Troan | 9fb8755 | 2016-01-13 22:30:43 +0100 | [diff] [blame] | 2062 | .path = "map params icmp6 unreachables", |
Ole Troan | 96eefd4 | 2016-09-12 12:25:30 +0200 | [diff] [blame] | 2063 | .short_help = "map params icmp6 unreachables {on|off}", |
Ole Troan | cda9482 | 2016-01-07 14:37:25 +0100 | [diff] [blame] | 2064 | .function = map_icmp_unreachables_command_fn, |
| 2065 | }; |
| 2066 | |
Ole Troan | 96eefd4 | 2016-09-12 12:25:30 +0200 | [diff] [blame] | 2067 | /*? |
| 2068 | * Configure MAP fragmentation behaviour |
| 2069 | * |
| 2070 | * @cliexpar |
| 2071 | * @cliexstart{map params fragment} |
| 2072 | * @cliexend |
| 2073 | ?*/ |
Ole Troan | 9fb8755 | 2016-01-13 22:30:43 +0100 | [diff] [blame] | 2074 | VLIB_CLI_COMMAND(map_fragment_command, static) = { |
| 2075 | .path = "map params fragment", |
Ole Troan | 96eefd4 | 2016-09-12 12:25:30 +0200 | [diff] [blame] | 2076 | .short_help = "map params fragment inner|outer", |
Ole Troan | 9fb8755 | 2016-01-13 22:30:43 +0100 | [diff] [blame] | 2077 | .function = map_fragment_command_fn, |
| 2078 | }; |
| 2079 | |
Ole Troan | 96eefd4 | 2016-09-12 12:25:30 +0200 | [diff] [blame] | 2080 | /*? |
| 2081 | * Ignore the IPv4 Don't fragment bit |
| 2082 | * |
| 2083 | * @cliexpar |
| 2084 | * @cliexstart{map params fragment ignore-df} |
| 2085 | * |
| 2086 | * Allows fragmentation of the IPv4 packet even if the DF bit is |
| 2087 | * set. The choice between inner or outer fragmentation of tunnel |
| 2088 | * packets is complicated. The benefit of inner fragmentation is that |
| 2089 | * the ultimate endpoint must reassemble, instead of the tunnel |
| 2090 | * endpoint. |
| 2091 | * @cliexend |
| 2092 | ?*/ |
Ole Troan | 9fb8755 | 2016-01-13 22:30:43 +0100 | [diff] [blame] | 2093 | VLIB_CLI_COMMAND(map_fragment_df_command, static) = { |
| 2094 | .path = "map params fragment ignore-df", |
Ole Troan | 96eefd4 | 2016-09-12 12:25:30 +0200 | [diff] [blame] | 2095 | .short_help = "map params fragment ignore-df on|off", |
Ole Troan | 9fb8755 | 2016-01-13 22:30:43 +0100 | [diff] [blame] | 2096 | .function = map_fragment_df_command_fn, |
| 2097 | }; |
| 2098 | |
Ole Troan | 96eefd4 | 2016-09-12 12:25:30 +0200 | [diff] [blame] | 2099 | /*? |
| 2100 | * Specifiy if the inbound security check should be done on fragments |
| 2101 | * |
| 2102 | * @cliexpar |
| 2103 | * @cliexstart{map params security-check fragments} |
| 2104 | * |
| 2105 | * Typically the inbound on-decapsulation security check is only done |
| 2106 | * on the first packet. The packet that contains the L4 |
| 2107 | * information. While a security check on every fragment is possible, |
| 2108 | * it has a cost. State must be created on the first fragment. |
| 2109 | * @cliexend |
| 2110 | ?*/ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2111 | VLIB_CLI_COMMAND(map_security_check_frag_command, static) = { |
| 2112 | .path = "map params security-check fragments", |
Ole Troan | 96eefd4 | 2016-09-12 12:25:30 +0200 | [diff] [blame] | 2113 | .short_help = "map params security-check fragments on|off", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2114 | .function = map_security_check_frag_command_fn, |
| 2115 | }; |
| 2116 | |
Ole Troan | 96eefd4 | 2016-09-12 12:25:30 +0200 | [diff] [blame] | 2117 | /*? |
| 2118 | * Add MAP domain |
| 2119 | * |
| 2120 | * @cliexpar |
| 2121 | * @cliexstart{map add domain} |
| 2122 | * @cliexend |
| 2123 | ?*/ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2124 | VLIB_CLI_COMMAND(map_add_domain_command, static) = { |
| 2125 | .path = "map add domain", |
Ole Troan | 96eefd4 | 2016-09-12 12:25:30 +0200 | [diff] [blame] | 2126 | .short_help = "map add domain ip4-pfx <ip4-pfx> ip6-pfx <ip6-pfx> " |
| 2127 | "ip6-src <ip6-pfx> ea-bits-len <n> psid-offset <n> psid-len <n> " |
| 2128 | "[map-t] [mtu <mtu>]", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2129 | .function = map_add_domain_command_fn, |
| 2130 | }; |
| 2131 | |
Ole Troan | 96eefd4 | 2016-09-12 12:25:30 +0200 | [diff] [blame] | 2132 | /*? |
| 2133 | * Add MAP rule to a domain |
| 2134 | * |
| 2135 | * @cliexpar |
| 2136 | * @cliexstart{map add rule} |
| 2137 | * @cliexend |
| 2138 | ?*/ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2139 | VLIB_CLI_COMMAND(map_add_rule_command, static) = { |
| 2140 | .path = "map add rule", |
Ole Troan | 96eefd4 | 2016-09-12 12:25:30 +0200 | [diff] [blame] | 2141 | .short_help = "map add rule index <domain> psid <psid> ip6-dst <ip6-addr>", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2142 | .function = map_add_rule_command_fn, |
| 2143 | }; |
| 2144 | |
Ole Troan | 96eefd4 | 2016-09-12 12:25:30 +0200 | [diff] [blame] | 2145 | /*? |
| 2146 | * Delete MAP domain |
| 2147 | * |
| 2148 | * @cliexpar |
| 2149 | * @cliexstart{map del domain} |
| 2150 | * @cliexend |
| 2151 | ?*/ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2152 | VLIB_CLI_COMMAND(map_del_command, static) = { |
| 2153 | .path = "map del domain", |
Ole Troan | 96eefd4 | 2016-09-12 12:25:30 +0200 | [diff] [blame] | 2154 | .short_help = "map del domain index <domain>", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2155 | .function = map_del_domain_command_fn, |
| 2156 | }; |
| 2157 | |
Ole Troan | 96eefd4 | 2016-09-12 12:25:30 +0200 | [diff] [blame] | 2158 | /*? |
| 2159 | * Show MAP domains |
| 2160 | * |
| 2161 | * @cliexpar |
| 2162 | * @cliexstart{show map domain} |
| 2163 | * @cliexend |
| 2164 | ?*/ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2165 | VLIB_CLI_COMMAND(show_map_domain_command, static) = { |
| 2166 | .path = "show map domain", |
Ole Troan | 96eefd4 | 2016-09-12 12:25:30 +0200 | [diff] [blame] | 2167 | .short_help = "show map domain index <n> [counters]", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2168 | .function = show_map_domain_command_fn, |
| 2169 | }; |
| 2170 | |
Ole Troan | 96eefd4 | 2016-09-12 12:25:30 +0200 | [diff] [blame] | 2171 | /*? |
| 2172 | * Show MAP statistics |
| 2173 | * |
| 2174 | * @cliexpar |
| 2175 | * @cliexstart{show map stats} |
| 2176 | * @cliexend |
| 2177 | ?*/ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2178 | VLIB_CLI_COMMAND(show_map_stats_command, static) = { |
| 2179 | .path = "show map stats", |
Ole Troan | 96eefd4 | 2016-09-12 12:25:30 +0200 | [diff] [blame] | 2180 | .short_help = "show map stats", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2181 | .function = show_map_stats_command_fn, |
| 2182 | }; |
| 2183 | |
Ole Troan | 96eefd4 | 2016-09-12 12:25:30 +0200 | [diff] [blame] | 2184 | /*? |
| 2185 | * Show MAP fragmentation information |
| 2186 | * |
| 2187 | * @cliexpar |
| 2188 | * @cliexstart{show map fragments} |
| 2189 | * @cliexend |
| 2190 | ?*/ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2191 | VLIB_CLI_COMMAND(show_map_fragments_command, static) = { |
| 2192 | .path = "show map fragments", |
Ole Troan | 96eefd4 | 2016-09-12 12:25:30 +0200 | [diff] [blame] | 2193 | .short_help = "show map fragments", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2194 | .function = show_map_fragments_command_fn, |
| 2195 | }; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 2196 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2197 | |
| 2198 | /* |
| 2199 | * map_init |
| 2200 | */ |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 2201 | clib_error_t * |
| 2202 | map_init (vlib_main_t * vm) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2203 | { |
| 2204 | map_main_t *mm = &map_main; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 2205 | mm->vnet_main = vnet_get_main (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2206 | mm->vlib_main = vm; |
| 2207 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 2208 | #ifdef MAP_SKIP_IP6_LOOKUP |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 2209 | fib_protocol_t proto; |
| 2210 | |
| 2211 | FOR_EACH_FIB_PROTOCOL (proto) |
| 2212 | { |
| 2213 | map_pre_resolve_init (&pre_resolved[proto]); |
| 2214 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2215 | #endif |
| 2216 | |
| 2217 | /* traffic class */ |
| 2218 | mm->tc = 0; |
| 2219 | mm->tc_copy = true; |
| 2220 | |
| 2221 | /* Inbound security check */ |
| 2222 | mm->sec_check = true; |
| 2223 | mm->sec_check_frag = false; |
| 2224 | |
Ole Troan | cda9482 | 2016-01-07 14:37:25 +0100 | [diff] [blame] | 2225 | /* ICMP6 Type 1, Code 5 for security check failure */ |
| 2226 | mm->icmp6_enabled = false; |
| 2227 | |
Ole Troan | 9fb8755 | 2016-01-13 22:30:43 +0100 | [diff] [blame] | 2228 | /* Inner or outer fragmentation */ |
| 2229 | mm->frag_inner = false; |
| 2230 | mm->frag_ignore_df = false; |
| 2231 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 2232 | vec_validate (mm->domain_counters, MAP_N_DOMAIN_COUNTER - 1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2233 | mm->domain_counters[MAP_DOMAIN_COUNTER_RX].name = "rx"; |
| 2234 | mm->domain_counters[MAP_DOMAIN_COUNTER_TX].name = "tx"; |
| 2235 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 2236 | vlib_validate_simple_counter (&mm->icmp_relayed, 0); |
| 2237 | vlib_zero_simple_counter (&mm->icmp_relayed, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2238 | |
| 2239 | /* IP4 virtual reassembly */ |
| 2240 | mm->ip4_reass_hash_table = 0; |
| 2241 | mm->ip4_reass_pool = 0; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 2242 | mm->ip4_reass_lock = |
| 2243 | clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES, CLIB_CACHE_LINE_BYTES); |
dongjuan | 01e078f | 2017-09-07 14:58:56 +0800 | [diff] [blame] | 2244 | *mm->ip4_reass_lock = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2245 | mm->ip4_reass_conf_ht_ratio = MAP_IP4_REASS_HT_RATIO_DEFAULT; |
| 2246 | mm->ip4_reass_conf_lifetime_ms = MAP_IP4_REASS_LIFETIME_DEFAULT; |
| 2247 | mm->ip4_reass_conf_pool_size = MAP_IP4_REASS_POOL_SIZE_DEFAULT; |
| 2248 | mm->ip4_reass_conf_buffers = MAP_IP4_REASS_BUFFERS_DEFAULT; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 2249 | mm->ip4_reass_ht_log2len = |
| 2250 | map_get_ht_log2len (mm->ip4_reass_conf_ht_ratio, |
| 2251 | mm->ip4_reass_conf_pool_size); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2252 | mm->ip4_reass_fifo_last = MAP_REASS_INDEX_NONE; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 2253 | map_ip4_reass_reinit (NULL, NULL); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2254 | |
| 2255 | /* IP6 virtual reassembly */ |
| 2256 | mm->ip6_reass_hash_table = 0; |
| 2257 | mm->ip6_reass_pool = 0; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 2258 | mm->ip6_reass_lock = |
| 2259 | clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES, CLIB_CACHE_LINE_BYTES); |
dongjuan | 01e078f | 2017-09-07 14:58:56 +0800 | [diff] [blame] | 2260 | *mm->ip6_reass_lock = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2261 | mm->ip6_reass_conf_ht_ratio = MAP_IP6_REASS_HT_RATIO_DEFAULT; |
| 2262 | mm->ip6_reass_conf_lifetime_ms = MAP_IP6_REASS_LIFETIME_DEFAULT; |
| 2263 | mm->ip6_reass_conf_pool_size = MAP_IP6_REASS_POOL_SIZE_DEFAULT; |
| 2264 | mm->ip6_reass_conf_buffers = MAP_IP6_REASS_BUFFERS_DEFAULT; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 2265 | mm->ip6_reass_ht_log2len = |
| 2266 | map_get_ht_log2len (mm->ip6_reass_conf_ht_ratio, |
| 2267 | mm->ip6_reass_conf_pool_size); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2268 | mm->ip6_reass_fifo_last = MAP_REASS_INDEX_NONE; |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 2269 | map_ip6_reass_reinit (NULL, NULL); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2270 | |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 2271 | #ifdef MAP_SKIP_IP6_LOOKUP |
| 2272 | fib_node_register_type (FIB_NODE_TYPE_MAP_E, &map_vft); |
| 2273 | #endif |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2274 | map_dpo_module_init (); |
| 2275 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2276 | return 0; |
| 2277 | } |
| 2278 | |
Keith Burns (alagalah) | 06e3d07 | 2016-08-07 08:43:18 -0700 | [diff] [blame] | 2279 | VLIB_INIT_FUNCTION (map_init); |
| 2280 | |
| 2281 | /* |
| 2282 | * fd.io coding-style-patch-verification: ON |
| 2283 | * |
| 2284 | * Local Variables: |
| 2285 | * eval: (c-set-style "gnu") |
| 2286 | * End: |
| 2287 | */ |