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