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