Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
AkshayaNadahalli | ed4a2fd | 2016-08-09 13:38:04 +0530 | [diff] [blame] | 2 | * Copyright (c) 2016 Cisco and/or its affiliates. |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | /* |
| 16 | * ip/ip6_forward.c: IP v6 forwarding |
| 17 | * |
| 18 | * Copyright (c) 2008 Eliot Dresselhaus |
| 19 | * |
| 20 | * Permission is hereby granted, free of charge, to any person obtaining |
| 21 | * a copy of this software and associated documentation files (the |
| 22 | * "Software"), to deal in the Software without restriction, including |
| 23 | * without limitation the rights to use, copy, modify, merge, publish, |
| 24 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 25 | * permit persons to whom the Software is furnished to do so, subject to |
| 26 | * the following conditions: |
| 27 | * |
| 28 | * The above copyright notice and this permission notice shall be |
| 29 | * included in all copies or substantial portions of the Software. |
| 30 | * |
| 31 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 32 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 33 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 34 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 35 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 36 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 37 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 38 | */ |
| 39 | |
| 40 | #include <vnet/vnet.h> |
| 41 | #include <vnet/ip/ip.h> |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 42 | #include <vnet/ethernet/ethernet.h> /* for ethernet_header_t */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 43 | #include <vnet/srp/srp.h> /* for srp_hw_interface_class */ |
| 44 | #include <vppinfra/cache.h> |
AkshayaNadahalli | 0f438df | 2017-02-10 10:54:16 +0530 | [diff] [blame] | 45 | #include <vnet/fib/fib_urpf_list.h> /* for FIB uRPF check */ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 46 | #include <vnet/fib/ip6_fib.h> |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 47 | #include <vnet/mfib/ip6_mfib.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 48 | #include <vnet/dpo/load_balance.h> |
| 49 | #include <vnet/dpo/classify_dpo.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 50 | |
| 51 | #include <vppinfra/bihash_template.c> |
| 52 | |
AkshayaNadahalli | fdd81af | 2016-12-01 16:33:51 +0530 | [diff] [blame] | 53 | /* Flag used by IOAM code. Classifier sets it pop-hop-by-hop checks it */ |
| 54 | #define OI_DECAP 0x80000000 |
| 55 | |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 56 | /** |
| 57 | * @file |
| 58 | * @brief IPv6 Forwarding. |
| 59 | * |
| 60 | * This file contains the source code for IPv6 forwarding. |
| 61 | */ |
| 62 | |
Pierre Pfister | 0febaf1 | 2016-06-08 12:23:21 +0100 | [diff] [blame] | 63 | void |
| 64 | ip6_forward_next_trace (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 65 | vlib_node_runtime_t * node, |
| 66 | vlib_frame_t * frame, |
| 67 | vlib_rx_or_tx_t which_adj_index); |
Pierre Pfister | 0febaf1 | 2016-06-08 12:23:21 +0100 | [diff] [blame] | 68 | |
Damjan Marion | aca64c9 | 2016-04-13 09:48:56 +0200 | [diff] [blame] | 69 | always_inline uword |
| 70 | ip6_lookup_inline (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 71 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 72 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 73 | ip6_main_t *im = &ip6_main; |
| 74 | vlib_combined_counter_main_t *cm = &load_balance_main.lbm_to_counters; |
| 75 | u32 n_left_from, n_left_to_next, *from, *to_next; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 76 | ip_lookup_next_t next; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 77 | u32 cpu_index = os_get_cpu_number (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 78 | |
| 79 | from = vlib_frame_vector_args (frame); |
| 80 | n_left_from = frame->n_vectors; |
| 81 | next = node->cached_next_index; |
| 82 | |
| 83 | while (n_left_from > 0) |
| 84 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 85 | vlib_get_next_frame (vm, node, next, to_next, n_left_to_next); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 86 | |
| 87 | while (n_left_from >= 4 && n_left_to_next >= 2) |
| 88 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 89 | vlib_buffer_t *p0, *p1; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 90 | u32 pi0, pi1, lbi0, lbi1, wrong_next; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 91 | ip_lookup_next_t next0, next1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 92 | ip6_header_t *ip0, *ip1; |
| 93 | ip6_address_t *dst_addr0, *dst_addr1; |
| 94 | u32 fib_index0, fib_index1; |
| 95 | u32 flow_hash_config0, flow_hash_config1; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 96 | const dpo_id_t *dpo0, *dpo1; |
| 97 | const load_balance_t *lb0, *lb1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 98 | |
| 99 | /* Prefetch next iteration. */ |
| 100 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 101 | vlib_buffer_t *p2, *p3; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 102 | |
| 103 | p2 = vlib_get_buffer (vm, from[2]); |
| 104 | p3 = vlib_get_buffer (vm, from[3]); |
| 105 | |
| 106 | vlib_prefetch_buffer_header (p2, LOAD); |
| 107 | vlib_prefetch_buffer_header (p3, LOAD); |
| 108 | CLIB_PREFETCH (p2->data, sizeof (ip0[0]), LOAD); |
| 109 | CLIB_PREFETCH (p3->data, sizeof (ip0[0]), LOAD); |
| 110 | } |
| 111 | |
| 112 | pi0 = to_next[0] = from[0]; |
| 113 | pi1 = to_next[1] = from[1]; |
| 114 | |
| 115 | p0 = vlib_get_buffer (vm, pi0); |
| 116 | p1 = vlib_get_buffer (vm, pi1); |
| 117 | |
| 118 | ip0 = vlib_buffer_get_current (p0); |
| 119 | ip1 = vlib_buffer_get_current (p1); |
| 120 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 121 | dst_addr0 = &ip0->dst_address; |
| 122 | dst_addr1 = &ip1->dst_address; |
Damjan Marion | aca64c9 | 2016-04-13 09:48:56 +0200 | [diff] [blame] | 123 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 124 | fib_index0 = |
| 125 | vec_elt (im->fib_index_by_sw_if_index, |
| 126 | vnet_buffer (p0)->sw_if_index[VLIB_RX]); |
| 127 | fib_index1 = |
| 128 | vec_elt (im->fib_index_by_sw_if_index, |
| 129 | vnet_buffer (p1)->sw_if_index[VLIB_RX]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 130 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 131 | fib_index0 = (vnet_buffer (p0)->sw_if_index[VLIB_TX] == (u32) ~ 0) ? |
| 132 | fib_index0 : vnet_buffer (p0)->sw_if_index[VLIB_TX]; |
| 133 | fib_index1 = (vnet_buffer (p1)->sw_if_index[VLIB_TX] == (u32) ~ 0) ? |
| 134 | fib_index1 : vnet_buffer (p1)->sw_if_index[VLIB_TX]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 135 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 136 | lbi0 = ip6_fib_table_fwding_lookup (im, fib_index0, dst_addr0); |
| 137 | lbi1 = ip6_fib_table_fwding_lookup (im, fib_index1, dst_addr1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 138 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 139 | lb0 = load_balance_get (lbi0); |
| 140 | lb1 = load_balance_get (lbi1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 141 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 142 | vnet_buffer (p0)->ip.flow_hash = vnet_buffer (p1)->ip.flow_hash = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 143 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 144 | if (PREDICT_FALSE (lb0->lb_n_buckets > 1)) |
| 145 | { |
| 146 | flow_hash_config0 = lb0->lb_hash_config; |
| 147 | vnet_buffer (p0)->ip.flow_hash = |
| 148 | ip6_compute_flow_hash (ip0, flow_hash_config0); |
| 149 | } |
| 150 | if (PREDICT_FALSE (lb1->lb_n_buckets > 1)) |
| 151 | { |
| 152 | flow_hash_config1 = lb1->lb_hash_config; |
| 153 | vnet_buffer (p1)->ip.flow_hash = |
| 154 | ip6_compute_flow_hash (ip1, flow_hash_config1); |
| 155 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 156 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 157 | ASSERT (lb0->lb_n_buckets > 0); |
| 158 | ASSERT (lb1->lb_n_buckets > 0); |
| 159 | ASSERT (is_pow2 (lb0->lb_n_buckets)); |
| 160 | ASSERT (is_pow2 (lb1->lb_n_buckets)); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 161 | dpo0 = load_balance_get_bucket_i (lb0, |
| 162 | (vnet_buffer (p0)->ip.flow_hash & |
| 163 | lb0->lb_n_buckets_minus_1)); |
| 164 | dpo1 = load_balance_get_bucket_i (lb1, |
| 165 | (vnet_buffer (p1)->ip.flow_hash & |
| 166 | lb1->lb_n_buckets_minus_1)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 167 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 168 | next0 = dpo0->dpoi_next_node; |
| 169 | next1 = dpo1->dpoi_next_node; |
| 170 | |
| 171 | /* Only process the HBH Option Header if explicitly configured to do so */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 172 | if (PREDICT_FALSE |
| 173 | (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS)) |
Shwetha | 57fc854 | 2016-09-27 08:04:05 +0100 | [diff] [blame] | 174 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 175 | next0 = (dpo_is_adj (dpo0) && im->hbh_enabled) ? |
Shwetha | 57fc854 | 2016-09-27 08:04:05 +0100 | [diff] [blame] | 176 | (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next0; |
| 177 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 178 | if (PREDICT_FALSE |
| 179 | (ip1->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS)) |
Shwetha | 57fc854 | 2016-09-27 08:04:05 +0100 | [diff] [blame] | 180 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 181 | next1 = (dpo_is_adj (dpo1) && im->hbh_enabled) ? |
Shwetha | 57fc854 | 2016-09-27 08:04:05 +0100 | [diff] [blame] | 182 | (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next1; |
| 183 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 184 | vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index; |
| 185 | vnet_buffer (p1)->ip.adj_index[VLIB_TX] = dpo1->dpoi_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 186 | |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 187 | vlib_increment_combined_counter |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 188 | (cm, cpu_index, lbi0, 1, vlib_buffer_length_in_chain (vm, p0)); |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 189 | vlib_increment_combined_counter |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 190 | (cm, cpu_index, lbi1, 1, vlib_buffer_length_in_chain (vm, p1)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 191 | |
| 192 | from += 2; |
| 193 | to_next += 2; |
| 194 | n_left_to_next -= 2; |
| 195 | n_left_from -= 2; |
| 196 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 197 | wrong_next = (next0 != next) + 2 * (next1 != next); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 198 | if (PREDICT_FALSE (wrong_next != 0)) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 199 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 200 | switch (wrong_next) |
| 201 | { |
| 202 | case 1: |
| 203 | /* A B A */ |
| 204 | to_next[-2] = pi1; |
| 205 | to_next -= 1; |
| 206 | n_left_to_next += 1; |
| 207 | vlib_set_next_frame_buffer (vm, node, next0, pi0); |
| 208 | break; |
| 209 | |
| 210 | case 2: |
| 211 | /* A A B */ |
| 212 | to_next -= 1; |
| 213 | n_left_to_next += 1; |
| 214 | vlib_set_next_frame_buffer (vm, node, next1, pi1); |
| 215 | break; |
| 216 | |
| 217 | case 3: |
| 218 | /* A B C */ |
| 219 | to_next -= 2; |
| 220 | n_left_to_next += 2; |
| 221 | vlib_set_next_frame_buffer (vm, node, next0, pi0); |
| 222 | vlib_set_next_frame_buffer (vm, node, next1, pi1); |
| 223 | if (next0 == next1) |
| 224 | { |
| 225 | /* A B B */ |
| 226 | vlib_put_next_frame (vm, node, next, n_left_to_next); |
| 227 | next = next1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 228 | vlib_get_next_frame (vm, node, next, to_next, |
| 229 | n_left_to_next); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 230 | } |
| 231 | } |
| 232 | } |
| 233 | } |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 234 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 235 | while (n_left_from > 0 && n_left_to_next > 0) |
| 236 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 237 | vlib_buffer_t *p0; |
| 238 | ip6_header_t *ip0; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 239 | u32 pi0, lbi0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 240 | ip_lookup_next_t next0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 241 | load_balance_t *lb0; |
| 242 | ip6_address_t *dst_addr0; |
| 243 | u32 fib_index0, flow_hash_config0; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 244 | const dpo_id_t *dpo0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 245 | |
| 246 | pi0 = from[0]; |
| 247 | to_next[0] = pi0; |
| 248 | |
| 249 | p0 = vlib_get_buffer (vm, pi0); |
| 250 | |
| 251 | ip0 = vlib_buffer_get_current (p0); |
| 252 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 253 | dst_addr0 = &ip0->dst_address; |
Damjan Marion | aca64c9 | 2016-04-13 09:48:56 +0200 | [diff] [blame] | 254 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 255 | fib_index0 = |
| 256 | vec_elt (im->fib_index_by_sw_if_index, |
| 257 | vnet_buffer (p0)->sw_if_index[VLIB_RX]); |
| 258 | fib_index0 = |
| 259 | (vnet_buffer (p0)->sw_if_index[VLIB_TX] == |
| 260 | (u32) ~ 0) ? fib_index0 : vnet_buffer (p0)->sw_if_index[VLIB_TX]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 261 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 262 | flow_hash_config0 = ip6_fib_get (fib_index0)->flow_hash_config; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 263 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 264 | lbi0 = ip6_fib_table_fwding_lookup (im, fib_index0, dst_addr0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 265 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 266 | lb0 = load_balance_get (lbi0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 267 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 268 | vnet_buffer (p0)->ip.flow_hash = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 269 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 270 | if (PREDICT_FALSE (lb0->lb_n_buckets > 1)) |
| 271 | { |
| 272 | flow_hash_config0 = lb0->lb_hash_config; |
| 273 | vnet_buffer (p0)->ip.flow_hash = |
| 274 | ip6_compute_flow_hash (ip0, flow_hash_config0); |
| 275 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 276 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 277 | ASSERT (lb0->lb_n_buckets > 0); |
| 278 | ASSERT (is_pow2 (lb0->lb_n_buckets)); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 279 | dpo0 = load_balance_get_bucket_i (lb0, |
| 280 | (vnet_buffer (p0)->ip.flow_hash & |
| 281 | lb0->lb_n_buckets_minus_1)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 282 | next0 = dpo0->dpoi_next_node; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 283 | |
Shwetha | 57fc854 | 2016-09-27 08:04:05 +0100 | [diff] [blame] | 284 | /* Only process the HBH Option Header if explicitly configured to do so */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 285 | if (PREDICT_FALSE |
| 286 | (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS)) |
Shwetha | 57fc854 | 2016-09-27 08:04:05 +0100 | [diff] [blame] | 287 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 288 | next0 = (dpo_is_adj (dpo0) && im->hbh_enabled) ? |
Shwetha | 57fc854 | 2016-09-27 08:04:05 +0100 | [diff] [blame] | 289 | (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next0; |
| 290 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 291 | vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 292 | |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 293 | vlib_increment_combined_counter |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 294 | (cm, cpu_index, lbi0, 1, vlib_buffer_length_in_chain (vm, p0)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 295 | |
| 296 | from += 1; |
| 297 | to_next += 1; |
| 298 | n_left_to_next -= 1; |
| 299 | n_left_from -= 1; |
| 300 | |
| 301 | if (PREDICT_FALSE (next0 != next)) |
| 302 | { |
| 303 | n_left_to_next += 1; |
| 304 | vlib_put_next_frame (vm, node, next, n_left_to_next); |
| 305 | next = next0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 306 | vlib_get_next_frame (vm, node, next, to_next, n_left_to_next); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 307 | to_next[0] = pi0; |
| 308 | to_next += 1; |
| 309 | n_left_to_next -= 1; |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | vlib_put_next_frame (vm, node, next, n_left_to_next); |
| 314 | } |
| 315 | |
Pierre Pfister | a38c3df | 2016-06-13 10:28:09 +0100 | [diff] [blame] | 316 | if (node->flags & VLIB_NODE_FLAG_TRACE) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 317 | ip6_forward_next_trace (vm, node, frame, VLIB_TX); |
Pierre Pfister | a38c3df | 2016-06-13 10:28:09 +0100 | [diff] [blame] | 318 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 319 | return frame->n_vectors; |
| 320 | } |
| 321 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 322 | static void |
| 323 | ip6_add_interface_routes (vnet_main_t * vnm, u32 sw_if_index, |
| 324 | ip6_main_t * im, u32 fib_index, |
| 325 | ip_interface_address_t * a) |
| 326 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 327 | ip_lookup_main_t *lm = &im->lookup_main; |
| 328 | ip6_address_t *address = ip_interface_address_get_address (lm, a); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 329 | fib_prefix_t pfx = { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 330 | .fp_len = a->address_length, |
| 331 | .fp_proto = FIB_PROTOCOL_IP6, |
| 332 | .fp_addr.ip6 = *address, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 333 | }; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 334 | |
| 335 | a->neighbor_probe_adj_index = ~0; |
| 336 | if (a->address_length < 128) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 337 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 338 | fib_node_index_t fei; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 339 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 340 | fei = fib_table_entry_update_one_path (fib_index, &pfx, FIB_SOURCE_INTERFACE, (FIB_ENTRY_FLAG_CONNECTED | FIB_ENTRY_FLAG_ATTACHED), FIB_PROTOCOL_IP6, NULL, /* No next-hop address */ |
| 341 | sw_if_index, ~0, // invalid FIB index |
| 342 | 1, NULL, // no label stack |
| 343 | FIB_ROUTE_PATH_FLAG_NONE); |
| 344 | a->neighbor_probe_adj_index = fib_entry_get_adj (fei); |
| 345 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 346 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 347 | pfx.fp_len = 128; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 348 | if (sw_if_index < vec_len (lm->classify_table_index_by_sw_if_index)) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 349 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 350 | u32 classify_table_index = |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 351 | lm->classify_table_index_by_sw_if_index[sw_if_index]; |
| 352 | if (classify_table_index != (u32) ~ 0) |
| 353 | { |
| 354 | dpo_id_t dpo = DPO_INVALID; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 355 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 356 | dpo_set (&dpo, |
| 357 | DPO_CLASSIFY, |
| 358 | DPO_PROTO_IP6, |
| 359 | classify_dpo_create (DPO_PROTO_IP6, classify_table_index)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 360 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 361 | fib_table_entry_special_dpo_add (fib_index, |
| 362 | &pfx, |
| 363 | FIB_SOURCE_CLASSIFY, |
| 364 | FIB_ENTRY_FLAG_NONE, &dpo); |
| 365 | dpo_reset (&dpo); |
| 366 | } |
| 367 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 368 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 369 | fib_table_entry_update_one_path (fib_index, &pfx, FIB_SOURCE_INTERFACE, (FIB_ENTRY_FLAG_CONNECTED | FIB_ENTRY_FLAG_LOCAL), FIB_PROTOCOL_IP6, &pfx.fp_addr, sw_if_index, ~0, // invalid FIB index |
| 370 | 1, NULL, FIB_ROUTE_PATH_FLAG_NONE); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | static void |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 374 | ip6_del_interface_routes (ip6_main_t * im, |
| 375 | u32 fib_index, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 376 | ip6_address_t * address, u32 address_length) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 377 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 378 | fib_prefix_t pfx = { |
| 379 | .fp_len = address_length, |
| 380 | .fp_proto = FIB_PROTOCOL_IP6, |
| 381 | .fp_addr.ip6 = *address, |
| 382 | }; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 383 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 384 | if (pfx.fp_len < 128) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 385 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 386 | fib_table_entry_delete (fib_index, &pfx, FIB_SOURCE_INTERFACE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 387 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 388 | } |
| 389 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 390 | pfx.fp_len = 128; |
| 391 | fib_table_entry_delete (fib_index, &pfx, FIB_SOURCE_INTERFACE); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 392 | } |
| 393 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 394 | void |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 395 | ip6_sw_interface_enable_disable (u32 sw_if_index, u32 is_enable) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 396 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 397 | ip6_main_t *im = &ip6_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 398 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 399 | vec_validate_init_empty (im->ip_enabled_by_sw_if_index, sw_if_index, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 400 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 401 | /* |
| 402 | * enable/disable only on the 1<->0 transition |
| 403 | */ |
| 404 | if (is_enable) |
| 405 | { |
| 406 | if (1 != ++im->ip_enabled_by_sw_if_index[sw_if_index]) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 407 | return; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 408 | } |
| 409 | else |
| 410 | { |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 411 | /* The ref count is 0 when an address is removed from an interface that has |
| 412 | * no address - this is not a ciritical error */ |
| 413 | if (0 == im->ip_enabled_by_sw_if_index[sw_if_index] || |
| 414 | 0 != --im->ip_enabled_by_sw_if_index[sw_if_index]) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 415 | return; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 416 | } |
| 417 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 418 | if (sw_if_index != 0) |
| 419 | ip6_mfib_interface_enable_disable (sw_if_index, is_enable); |
| 420 | |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 421 | vnet_feature_enable_disable ("ip6-unicast", "ip6-lookup", sw_if_index, |
| 422 | is_enable, 0, 0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 423 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 424 | vnet_feature_enable_disable ("ip6-multicast", "ip6-mfib-forward-lookup", |
| 425 | sw_if_index, is_enable, 0, 0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 426 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 427 | } |
| 428 | |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 429 | /* get first interface address */ |
| 430 | ip6_address_t * |
Neale Ranns | 6cfc39c | 2017-02-14 01:44:25 -0800 | [diff] [blame] | 431 | ip6_interface_first_address (ip6_main_t * im, u32 sw_if_index) |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 432 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 433 | ip_lookup_main_t *lm = &im->lookup_main; |
| 434 | ip_interface_address_t *ia = 0; |
| 435 | ip6_address_t *result = 0; |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 436 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 437 | /* *INDENT-OFF* */ |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 438 | foreach_ip_interface_address (lm, ia, sw_if_index, |
| 439 | 1 /* honor unnumbered */, |
| 440 | ({ |
| 441 | ip6_address_t * a = ip_interface_address_get_address (lm, ia); |
| 442 | result = a; |
| 443 | break; |
| 444 | })); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 445 | /* *INDENT-ON* */ |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 446 | return result; |
| 447 | } |
| 448 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 449 | clib_error_t * |
| 450 | ip6_add_del_interface_address (vlib_main_t * vm, |
| 451 | u32 sw_if_index, |
| 452 | ip6_address_t * address, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 453 | u32 address_length, u32 is_del) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 454 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 455 | vnet_main_t *vnm = vnet_get_main (); |
| 456 | ip6_main_t *im = &ip6_main; |
| 457 | ip_lookup_main_t *lm = &im->lookup_main; |
| 458 | clib_error_t *error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 459 | u32 if_address_index; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 460 | ip6_address_fib_t ip6_af, *addr_fib = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 461 | |
| 462 | vec_validate (im->fib_index_by_sw_if_index, sw_if_index); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 463 | vec_validate (im->mfib_index_by_sw_if_index, sw_if_index); |
| 464 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 465 | ip6_addr_fib_init (&ip6_af, address, |
| 466 | vec_elt (im->fib_index_by_sw_if_index, sw_if_index)); |
| 467 | vec_add1 (addr_fib, ip6_af); |
| 468 | |
| 469 | { |
| 470 | uword elts_before = pool_elts (lm->if_address_pool); |
| 471 | |
| 472 | error = ip_interface_address_add_del |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 473 | (lm, sw_if_index, addr_fib, address_length, is_del, &if_address_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 474 | if (error) |
| 475 | goto done; |
| 476 | |
| 477 | /* Pool did not grow: add duplicate address. */ |
| 478 | if (elts_before == pool_elts (lm->if_address_pool)) |
| 479 | goto done; |
| 480 | } |
| 481 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 482 | ip6_sw_interface_enable_disable (sw_if_index, !is_del); |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 483 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 484 | if (is_del) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 485 | ip6_del_interface_routes (im, ip6_af.fib_index, address, address_length); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 486 | else |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 487 | ip6_add_interface_routes (vnm, sw_if_index, |
| 488 | im, ip6_af.fib_index, |
| 489 | pool_elt_at_index (lm->if_address_pool, |
| 490 | if_address_index)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 491 | |
| 492 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 493 | ip6_add_del_interface_address_callback_t *cb; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 494 | vec_foreach (cb, im->add_del_interface_address_callbacks) |
| 495 | cb->function (im, cb->function_opaque, sw_if_index, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 496 | address, address_length, if_address_index, is_del); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 497 | } |
| 498 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 499 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 500 | vec_free (addr_fib); |
| 501 | return error; |
| 502 | } |
| 503 | |
| 504 | clib_error_t * |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 505 | ip6_sw_interface_admin_up_down (vnet_main_t * vnm, u32 sw_if_index, u32 flags) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 506 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 507 | ip6_main_t *im = &ip6_main; |
| 508 | ip_interface_address_t *ia; |
| 509 | ip6_address_t *a; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 510 | u32 is_admin_up, fib_index; |
| 511 | |
| 512 | /* Fill in lookup tables with default table (0). */ |
| 513 | vec_validate (im->fib_index_by_sw_if_index, sw_if_index); |
| 514 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 515 | vec_validate_init_empty (im-> |
| 516 | lookup_main.if_address_pool_index_by_sw_if_index, |
| 517 | sw_if_index, ~0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 518 | |
| 519 | is_admin_up = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) != 0; |
| 520 | |
| 521 | fib_index = vec_elt (im->fib_index_by_sw_if_index, sw_if_index); |
| 522 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 523 | /* *INDENT-OFF* */ |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 524 | foreach_ip_interface_address (&im->lookup_main, ia, sw_if_index, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 525 | 0 /* honor unnumbered */, |
| 526 | ({ |
| 527 | a = ip_interface_address_get_address (&im->lookup_main, ia); |
| 528 | if (is_admin_up) |
| 529 | ip6_add_interface_routes (vnm, sw_if_index, |
| 530 | im, fib_index, |
| 531 | ia); |
| 532 | else |
| 533 | ip6_del_interface_routes (im, fib_index, |
| 534 | a, ia->address_length); |
| 535 | })); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 536 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 537 | |
| 538 | return 0; |
| 539 | } |
| 540 | |
| 541 | VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (ip6_sw_interface_admin_up_down); |
| 542 | |
Dave Barach | d653460 | 2016-06-14 18:38:02 -0400 | [diff] [blame] | 543 | /* Built-in ip6 unicast rx feature path definition */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 544 | /* *INDENT-OFF* */ |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 545 | VNET_FEATURE_ARC_INIT (ip6_unicast, static) = |
| 546 | { |
| 547 | .arc_name = "ip6-unicast", |
| 548 | .start_nodes = VNET_FEATURES ("ip6-input"), |
| 549 | .arc_index_ptr = &ip6_main.lookup_main.ucast_feature_arc_index, |
| 550 | }; |
| 551 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 552 | VNET_FEATURE_INIT (ip6_flow_classify, static) = |
| 553 | { |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 554 | .arc_name = "ip6-unicast", |
Juraj Sloboda | 506b245 | 2016-08-07 23:45:24 -0700 | [diff] [blame] | 555 | .node_name = "ip6-flow-classify", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 556 | .runs_before = VNET_FEATURES ("ip6-inacl"), |
Juraj Sloboda | 506b245 | 2016-08-07 23:45:24 -0700 | [diff] [blame] | 557 | }; |
| 558 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 559 | VNET_FEATURE_INIT (ip6_inacl, static) = |
| 560 | { |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 561 | .arc_name = "ip6-unicast", |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 562 | .node_name = "ip6-inacl", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 563 | .runs_before = VNET_FEATURES ("ip6-policer-classify"), |
Dave Barach | d653460 | 2016-06-14 18:38:02 -0400 | [diff] [blame] | 564 | }; |
| 565 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 566 | VNET_FEATURE_INIT (ip6_policer_classify, static) = |
| 567 | { |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 568 | .arc_name = "ip6-unicast", |
Matus Fabian | 70e6a8d | 2016-06-20 08:10:42 -0700 | [diff] [blame] | 569 | .node_name = "ip6-policer-classify", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 570 | .runs_before = VNET_FEATURES ("ipsec-input-ip6"), |
Matus Fabian | 70e6a8d | 2016-06-20 08:10:42 -0700 | [diff] [blame] | 571 | }; |
| 572 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 573 | VNET_FEATURE_INIT (ip6_ipsec, static) = |
| 574 | { |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 575 | .arc_name = "ip6-unicast", |
Dave Barach | d653460 | 2016-06-14 18:38:02 -0400 | [diff] [blame] | 576 | .node_name = "ipsec-input-ip6", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 577 | .runs_before = VNET_FEATURES ("l2tp-decap"), |
Dave Barach | d653460 | 2016-06-14 18:38:02 -0400 | [diff] [blame] | 578 | }; |
| 579 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 580 | VNET_FEATURE_INIT (ip6_l2tp, static) = |
| 581 | { |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 582 | .arc_name = "ip6-unicast", |
Dave Barach | d653460 | 2016-06-14 18:38:02 -0400 | [diff] [blame] | 583 | .node_name = "l2tp-decap", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 584 | .runs_before = VNET_FEATURES ("vpath-input-ip6"), |
Dave Barach | d653460 | 2016-06-14 18:38:02 -0400 | [diff] [blame] | 585 | }; |
| 586 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 587 | VNET_FEATURE_INIT (ip6_vpath, static) = |
| 588 | { |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 589 | .arc_name = "ip6-unicast", |
Dave Barach | d653460 | 2016-06-14 18:38:02 -0400 | [diff] [blame] | 590 | .node_name = "vpath-input-ip6", |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 591 | .runs_before = VNET_FEATURES ("ip6-vxlan-bypass"), |
| 592 | }; |
| 593 | |
| 594 | VNET_FEATURE_INIT (ip6_vxlan_bypass, static) = |
| 595 | { |
| 596 | .arc_name = "ip6-unicast", |
| 597 | .node_name = "ip6-vxlan-bypass", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 598 | .runs_before = VNET_FEATURES ("ip6-lookup"), |
Dave Barach | d653460 | 2016-06-14 18:38:02 -0400 | [diff] [blame] | 599 | }; |
| 600 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 601 | VNET_FEATURE_INIT (ip6_lookup, static) = |
| 602 | { |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 603 | .arc_name = "ip6-unicast", |
Dave Barach | d653460 | 2016-06-14 18:38:02 -0400 | [diff] [blame] | 604 | .node_name = "ip6-lookup", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 605 | .runs_before = VNET_FEATURES ("ip6-drop"), |
Dave Barach | d653460 | 2016-06-14 18:38:02 -0400 | [diff] [blame] | 606 | }; |
| 607 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 608 | VNET_FEATURE_INIT (ip6_drop, static) = |
| 609 | { |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 610 | .arc_name = "ip6-unicast", |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 611 | .node_name = "ip6-drop", |
| 612 | .runs_before = 0, /*last feature*/ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 613 | }; |
| 614 | |
Dave Barach | d653460 | 2016-06-14 18:38:02 -0400 | [diff] [blame] | 615 | /* Built-in ip6 multicast rx feature path definition (none now) */ |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 616 | VNET_FEATURE_ARC_INIT (ip6_multicast, static) = |
| 617 | { |
| 618 | .arc_name = "ip6-multicast", |
| 619 | .start_nodes = VNET_FEATURES ("ip6-input"), |
| 620 | .arc_index_ptr = &ip6_main.lookup_main.mcast_feature_arc_index, |
| 621 | }; |
| 622 | |
| 623 | VNET_FEATURE_INIT (ip6_vpath_mc, static) = { |
| 624 | .arc_name = "ip6-multicast", |
Dave Barach | d653460 | 2016-06-14 18:38:02 -0400 | [diff] [blame] | 625 | .node_name = "vpath-input-ip6", |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 626 | .runs_before = VNET_FEATURES ("ip6-mfib-forward-lookup"), |
Dave Barach | d653460 | 2016-06-14 18:38:02 -0400 | [diff] [blame] | 627 | }; |
| 628 | |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 629 | VNET_FEATURE_INIT (ip6_mc_lookup, static) = { |
| 630 | .arc_name = "ip6-multicast", |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 631 | .node_name = "ip6-mfib-forward-lookup", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 632 | .runs_before = VNET_FEATURES ("ip6-drop"), |
Dave Barach | d653460 | 2016-06-14 18:38:02 -0400 | [diff] [blame] | 633 | }; |
| 634 | |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 635 | VNET_FEATURE_INIT (ip6_drop_mc, static) = { |
| 636 | .arc_name = "ip6-multicast", |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 637 | .node_name = "ip6-drop", |
| 638 | .runs_before = 0, /* last feature */ |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 639 | }; |
Dave Barach | 5331c72 | 2016-08-17 11:54:30 -0400 | [diff] [blame] | 640 | |
| 641 | /* Built-in ip4 tx feature path definition */ |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 642 | VNET_FEATURE_ARC_INIT (ip6_output, static) = |
| 643 | { |
| 644 | .arc_name = "ip6-output", |
| 645 | .start_nodes = VNET_FEATURES ("ip6-rewrite", "ip6-midchain"), |
| 646 | .arc_index_ptr = &ip6_main.lookup_main.output_feature_arc_index, |
Dave Barach | 5331c72 | 2016-08-17 11:54:30 -0400 | [diff] [blame] | 647 | }; |
| 648 | |
Matus Fabian | 08a6f01 | 2016-11-15 06:08:51 -0800 | [diff] [blame] | 649 | VNET_FEATURE_INIT (ip6_ipsec_output, static) = { |
| 650 | .arc_name = "ip6-output", |
| 651 | .node_name = "ipsec-output-ip6", |
| 652 | .runs_before = VNET_FEATURES ("interface-output"), |
| 653 | }; |
| 654 | |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 655 | VNET_FEATURE_INIT (ip6_interface_output, static) = { |
| 656 | .arc_name = "ip6-output", |
| 657 | .node_name = "interface-output", |
| 658 | .runs_before = 0, /* not before any other features */ |
| 659 | }; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 660 | /* *INDENT-ON* */ |
Dave Barach | d653460 | 2016-06-14 18:38:02 -0400 | [diff] [blame] | 661 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 662 | clib_error_t * |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 663 | ip6_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 664 | { |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 665 | vnet_feature_enable_disable ("ip6-unicast", "ip6-drop", sw_if_index, |
| 666 | is_add, 0, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 667 | |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 668 | vnet_feature_enable_disable ("ip6-multicast", "ip6-drop", sw_if_index, |
| 669 | is_add, 0, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 670 | |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 671 | vnet_feature_enable_disable ("ip6-output", "interface-output", sw_if_index, |
| 672 | is_add, 0, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 673 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 674 | return /* no error */ 0; |
| 675 | } |
| 676 | |
| 677 | VNET_SW_INTERFACE_ADD_DEL_FUNCTION (ip6_sw_interface_add_del); |
| 678 | |
Damjan Marion | aca64c9 | 2016-04-13 09:48:56 +0200 | [diff] [blame] | 679 | static uword |
| 680 | ip6_lookup (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 681 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
Damjan Marion | aca64c9 | 2016-04-13 09:48:56 +0200 | [diff] [blame] | 682 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 683 | return ip6_lookup_inline (vm, node, frame); |
Damjan Marion | aca64c9 | 2016-04-13 09:48:56 +0200 | [diff] [blame] | 684 | } |
| 685 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 686 | static u8 *format_ip6_lookup_trace (u8 * s, va_list * args); |
Pierre Pfister | 0febaf1 | 2016-06-08 12:23:21 +0100 | [diff] [blame] | 687 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 688 | /* *INDENT-OFF* */ |
| 689 | VLIB_REGISTER_NODE (ip6_lookup_node) = |
| 690 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 691 | .function = ip6_lookup, |
| 692 | .name = "ip6-lookup", |
| 693 | .vector_size = sizeof (u32), |
Pierre Pfister | a38c3df | 2016-06-13 10:28:09 +0100 | [diff] [blame] | 694 | .format_trace = format_ip6_lookup_trace, |
Ole Troan | f0f8522 | 2016-06-14 21:12:32 +0200 | [diff] [blame] | 695 | .n_next_nodes = IP6_LOOKUP_N_NEXT, |
Damjan Marion | b270789 | 2016-04-13 11:21:07 +0200 | [diff] [blame] | 696 | .next_nodes = IP6_LOOKUP_NEXT_NODES, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 697 | }; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 698 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 699 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 700 | VLIB_NODE_FUNCTION_MULTIARCH (ip6_lookup_node, ip6_lookup); |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 701 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 702 | always_inline uword |
| 703 | ip6_load_balance (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 704 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
Damjan Marion | aca64c9 | 2016-04-13 09:48:56 +0200 | [diff] [blame] | 705 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 706 | vlib_combined_counter_main_t *cm = &load_balance_main.lbm_via_counters; |
| 707 | u32 n_left_from, n_left_to_next, *from, *to_next; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 708 | ip_lookup_next_t next; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 709 | u32 cpu_index = os_get_cpu_number (); |
| 710 | ip6_main_t *im = &ip6_main; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 711 | |
| 712 | from = vlib_frame_vector_args (frame); |
| 713 | n_left_from = frame->n_vectors; |
| 714 | next = node->cached_next_index; |
| 715 | |
| 716 | if (node->flags & VLIB_NODE_FLAG_TRACE) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 717 | ip6_forward_next_trace (vm, node, frame, VLIB_TX); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 718 | |
| 719 | while (n_left_from > 0) |
| 720 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 721 | vlib_get_next_frame (vm, node, next, to_next, n_left_to_next); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 722 | |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 723 | |
Neale Ranns | 2be95c1 | 2016-11-19 13:50:04 +0000 | [diff] [blame] | 724 | while (n_left_from >= 4 && n_left_to_next >= 2) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 725 | { |
| 726 | ip_lookup_next_t next0, next1; |
| 727 | const load_balance_t *lb0, *lb1; |
| 728 | vlib_buffer_t *p0, *p1; |
| 729 | u32 pi0, lbi0, hc0, pi1, lbi1, hc1; |
| 730 | const ip6_header_t *ip0, *ip1; |
| 731 | const dpo_id_t *dpo0, *dpo1; |
Neale Ranns | 2be95c1 | 2016-11-19 13:50:04 +0000 | [diff] [blame] | 732 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 733 | /* Prefetch next iteration. */ |
| 734 | { |
| 735 | vlib_buffer_t *p2, *p3; |
Neale Ranns | 2be95c1 | 2016-11-19 13:50:04 +0000 | [diff] [blame] | 736 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 737 | p2 = vlib_get_buffer (vm, from[2]); |
| 738 | p3 = vlib_get_buffer (vm, from[3]); |
Neale Ranns | 2be95c1 | 2016-11-19 13:50:04 +0000 | [diff] [blame] | 739 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 740 | vlib_prefetch_buffer_header (p2, STORE); |
| 741 | vlib_prefetch_buffer_header (p3, STORE); |
Neale Ranns | 2be95c1 | 2016-11-19 13:50:04 +0000 | [diff] [blame] | 742 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 743 | CLIB_PREFETCH (p2->data, sizeof (ip0[0]), STORE); |
| 744 | CLIB_PREFETCH (p3->data, sizeof (ip0[0]), STORE); |
| 745 | } |
Neale Ranns | 2be95c1 | 2016-11-19 13:50:04 +0000 | [diff] [blame] | 746 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 747 | pi0 = to_next[0] = from[0]; |
| 748 | pi1 = to_next[1] = from[1]; |
Neale Ranns | 2be95c1 | 2016-11-19 13:50:04 +0000 | [diff] [blame] | 749 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 750 | from += 2; |
| 751 | n_left_from -= 2; |
| 752 | to_next += 2; |
| 753 | n_left_to_next -= 2; |
Neale Ranns | 2be95c1 | 2016-11-19 13:50:04 +0000 | [diff] [blame] | 754 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 755 | p0 = vlib_get_buffer (vm, pi0); |
| 756 | p1 = vlib_get_buffer (vm, pi1); |
Neale Ranns | 2be95c1 | 2016-11-19 13:50:04 +0000 | [diff] [blame] | 757 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 758 | ip0 = vlib_buffer_get_current (p0); |
| 759 | ip1 = vlib_buffer_get_current (p1); |
| 760 | lbi0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX]; |
| 761 | lbi1 = vnet_buffer (p1)->ip.adj_index[VLIB_TX]; |
Neale Ranns | 2be95c1 | 2016-11-19 13:50:04 +0000 | [diff] [blame] | 762 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 763 | lb0 = load_balance_get (lbi0); |
| 764 | lb1 = load_balance_get (lbi1); |
Neale Ranns | 2be95c1 | 2016-11-19 13:50:04 +0000 | [diff] [blame] | 765 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 766 | /* |
| 767 | * this node is for via FIBs we can re-use the hash value from the |
| 768 | * to node if present. |
| 769 | * We don't want to use the same hash value at each level in the recursion |
| 770 | * graph as that would lead to polarisation |
| 771 | */ |
| 772 | hc0 = vnet_buffer (p0)->ip.flow_hash = 0; |
| 773 | hc1 = vnet_buffer (p1)->ip.flow_hash = 0; |
Neale Ranns | 2be95c1 | 2016-11-19 13:50:04 +0000 | [diff] [blame] | 774 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 775 | if (PREDICT_FALSE (lb0->lb_n_buckets > 1)) |
| 776 | { |
| 777 | if (PREDICT_TRUE (vnet_buffer (p0)->ip.flow_hash)) |
| 778 | { |
| 779 | hc0 = vnet_buffer (p0)->ip.flow_hash = |
| 780 | vnet_buffer (p0)->ip.flow_hash >> 1; |
| 781 | } |
| 782 | else |
| 783 | { |
| 784 | hc0 = vnet_buffer (p0)->ip.flow_hash = |
| 785 | ip6_compute_flow_hash (ip0, hc0); |
| 786 | } |
| 787 | } |
| 788 | if (PREDICT_FALSE (lb1->lb_n_buckets > 1)) |
| 789 | { |
| 790 | if (PREDICT_TRUE (vnet_buffer (p1)->ip.flow_hash)) |
| 791 | { |
| 792 | hc1 = vnet_buffer (p1)->ip.flow_hash = |
| 793 | vnet_buffer (p1)->ip.flow_hash >> 1; |
| 794 | } |
| 795 | else |
| 796 | { |
| 797 | hc1 = vnet_buffer (p1)->ip.flow_hash = |
| 798 | ip6_compute_flow_hash (ip1, hc1); |
| 799 | } |
| 800 | } |
Neale Ranns | 2be95c1 | 2016-11-19 13:50:04 +0000 | [diff] [blame] | 801 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 802 | dpo0 = |
| 803 | load_balance_get_bucket_i (lb0, |
| 804 | hc0 & (lb0->lb_n_buckets_minus_1)); |
| 805 | dpo1 = |
| 806 | load_balance_get_bucket_i (lb1, |
| 807 | hc1 & (lb1->lb_n_buckets_minus_1)); |
Neale Ranns | 2be95c1 | 2016-11-19 13:50:04 +0000 | [diff] [blame] | 808 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 809 | next0 = dpo0->dpoi_next_node; |
| 810 | next1 = dpo1->dpoi_next_node; |
Neale Ranns | 2be95c1 | 2016-11-19 13:50:04 +0000 | [diff] [blame] | 811 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 812 | /* Only process the HBH Option Header if explicitly configured to do so */ |
| 813 | if (PREDICT_FALSE |
| 814 | (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS)) |
| 815 | { |
| 816 | next0 = (dpo_is_adj (dpo0) && im->hbh_enabled) ? |
| 817 | (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next0; |
| 818 | } |
| 819 | /* Only process the HBH Option Header if explicitly configured to do so */ |
| 820 | if (PREDICT_FALSE |
| 821 | (ip1->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS)) |
| 822 | { |
| 823 | next1 = (dpo_is_adj (dpo1) && im->hbh_enabled) ? |
| 824 | (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next1; |
| 825 | } |
Neale Ranns | 2be95c1 | 2016-11-19 13:50:04 +0000 | [diff] [blame] | 826 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 827 | vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index; |
| 828 | vnet_buffer (p1)->ip.adj_index[VLIB_TX] = dpo1->dpoi_index; |
Neale Ranns | 2be95c1 | 2016-11-19 13:50:04 +0000 | [diff] [blame] | 829 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 830 | vlib_increment_combined_counter |
| 831 | (cm, cpu_index, lbi0, 1, vlib_buffer_length_in_chain (vm, p0)); |
| 832 | vlib_increment_combined_counter |
| 833 | (cm, cpu_index, lbi1, 1, vlib_buffer_length_in_chain (vm, p1)); |
Neale Ranns | 2be95c1 | 2016-11-19 13:50:04 +0000 | [diff] [blame] | 834 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 835 | vlib_validate_buffer_enqueue_x2 (vm, node, next, |
| 836 | to_next, n_left_to_next, |
| 837 | pi0, pi1, next0, next1); |
| 838 | } |
Neale Ranns | 2be95c1 | 2016-11-19 13:50:04 +0000 | [diff] [blame] | 839 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 840 | while (n_left_from > 0 && n_left_to_next > 0) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 841 | { |
| 842 | ip_lookup_next_t next0; |
| 843 | const load_balance_t *lb0; |
| 844 | vlib_buffer_t *p0; |
| 845 | u32 pi0, lbi0, hc0; |
| 846 | const ip6_header_t *ip0; |
| 847 | const dpo_id_t *dpo0; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 848 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 849 | pi0 = from[0]; |
| 850 | to_next[0] = pi0; |
| 851 | from += 1; |
| 852 | to_next += 1; |
| 853 | n_left_to_next -= 1; |
| 854 | n_left_from -= 1; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 855 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 856 | p0 = vlib_get_buffer (vm, pi0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 857 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 858 | ip0 = vlib_buffer_get_current (p0); |
| 859 | lbi0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX]; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 860 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 861 | lb0 = load_balance_get (lbi0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 862 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 863 | hc0 = vnet_buffer (p0)->ip.flow_hash = 0; |
| 864 | if (PREDICT_FALSE (lb0->lb_n_buckets > 1)) |
| 865 | { |
| 866 | if (PREDICT_TRUE (vnet_buffer (p0)->ip.flow_hash)) |
| 867 | { |
| 868 | hc0 = vnet_buffer (p0)->ip.flow_hash = |
| 869 | vnet_buffer (p0)->ip.flow_hash >> 1; |
| 870 | } |
| 871 | else |
| 872 | { |
| 873 | hc0 = vnet_buffer (p0)->ip.flow_hash = |
| 874 | ip6_compute_flow_hash (ip0, hc0); |
| 875 | } |
| 876 | } |
| 877 | dpo0 = |
| 878 | load_balance_get_bucket_i (lb0, |
| 879 | hc0 & (lb0->lb_n_buckets_minus_1)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 880 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 881 | next0 = dpo0->dpoi_next_node; |
| 882 | vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index; |
Neale Ranns | 2be95c1 | 2016-11-19 13:50:04 +0000 | [diff] [blame] | 883 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 884 | /* Only process the HBH Option Header if explicitly configured to do so */ |
| 885 | if (PREDICT_FALSE |
| 886 | (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS)) |
| 887 | { |
| 888 | next0 = (dpo_is_adj (dpo0) && im->hbh_enabled) ? |
| 889 | (ip_lookup_next_t) IP6_LOOKUP_NEXT_HOP_BY_HOP : next0; |
| 890 | } |
Neale Ranns | 2be95c1 | 2016-11-19 13:50:04 +0000 | [diff] [blame] | 891 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 892 | vlib_increment_combined_counter |
| 893 | (cm, cpu_index, lbi0, 1, vlib_buffer_length_in_chain (vm, p0)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 894 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 895 | vlib_validate_buffer_enqueue_x1 (vm, node, next, |
| 896 | to_next, n_left_to_next, |
| 897 | pi0, next0); |
| 898 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 899 | |
| 900 | vlib_put_next_frame (vm, node, next, n_left_to_next); |
| 901 | } |
| 902 | |
| 903 | return frame->n_vectors; |
Damjan Marion | aca64c9 | 2016-04-13 09:48:56 +0200 | [diff] [blame] | 904 | } |
| 905 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 906 | /* *INDENT-OFF* */ |
| 907 | VLIB_REGISTER_NODE (ip6_load_balance_node) = |
| 908 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 909 | .function = ip6_load_balance, |
| 910 | .name = "ip6-load-balance", |
Damjan Marion | aca64c9 | 2016-04-13 09:48:56 +0200 | [diff] [blame] | 911 | .vector_size = sizeof (u32), |
Ole Troan | f0f8522 | 2016-06-14 21:12:32 +0200 | [diff] [blame] | 912 | .sibling_of = "ip6-lookup", |
Pierre Pfister | a38c3df | 2016-06-13 10:28:09 +0100 | [diff] [blame] | 913 | .format_trace = format_ip6_lookup_trace, |
Damjan Marion | aca64c9 | 2016-04-13 09:48:56 +0200 | [diff] [blame] | 914 | }; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 915 | /* *INDENT-ON* */ |
Damjan Marion | aca64c9 | 2016-04-13 09:48:56 +0200 | [diff] [blame] | 916 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 917 | VLIB_NODE_FUNCTION_MULTIARCH (ip6_load_balance_node, ip6_load_balance); |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 918 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 919 | typedef struct |
| 920 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 921 | /* Adjacency taken. */ |
| 922 | u32 adj_index; |
| 923 | u32 flow_hash; |
John Lo | 2d34374 | 2016-01-19 17:27:17 -0500 | [diff] [blame] | 924 | u32 fib_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 925 | |
| 926 | /* Packet data, possibly *after* rewrite. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 927 | u8 packet_data[128 - 1 * sizeof (u32)]; |
| 928 | } |
| 929 | ip6_forward_next_trace_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 930 | |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 931 | u8 * |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 932 | format_ip6_forward_next_trace (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 933 | { |
Pierre Pfister | a38c3df | 2016-06-13 10:28:09 +0100 | [diff] [blame] | 934 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 935 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 936 | ip6_forward_next_trace_t *t = va_arg (*args, ip6_forward_next_trace_t *); |
Pierre Pfister | a38c3df | 2016-06-13 10:28:09 +0100 | [diff] [blame] | 937 | uword indent = format_get_indent (s); |
| 938 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 939 | s = format (s, "%U%U", |
| 940 | format_white_space, indent, |
| 941 | format_ip6_header, t->packet_data, sizeof (t->packet_data)); |
Pierre Pfister | a38c3df | 2016-06-13 10:28:09 +0100 | [diff] [blame] | 942 | return s; |
| 943 | } |
| 944 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 945 | static u8 * |
| 946 | format_ip6_lookup_trace (u8 * s, va_list * args) |
Pierre Pfister | a38c3df | 2016-06-13 10:28:09 +0100 | [diff] [blame] | 947 | { |
| 948 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 949 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 950 | ip6_forward_next_trace_t *t = va_arg (*args, ip6_forward_next_trace_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 951 | uword indent = format_get_indent (s); |
| 952 | |
John Lo | ac8146c | 2016-09-27 17:44:02 -0400 | [diff] [blame] | 953 | s = format (s, "fib %d dpo-idx %d flow hash: 0x%08x", |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 954 | t->fib_index, t->adj_index, t->flow_hash); |
| 955 | s = format (s, "\n%U%U", |
| 956 | format_white_space, indent, |
| 957 | format_ip6_header, t->packet_data, sizeof (t->packet_data)); |
Pierre Pfister | a38c3df | 2016-06-13 10:28:09 +0100 | [diff] [blame] | 958 | return s; |
| 959 | } |
Pierre Pfister | 0febaf1 | 2016-06-08 12:23:21 +0100 | [diff] [blame] | 960 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 961 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 962 | static u8 * |
| 963 | format_ip6_rewrite_trace (u8 * s, va_list * args) |
Pierre Pfister | a38c3df | 2016-06-13 10:28:09 +0100 | [diff] [blame] | 964 | { |
| 965 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 966 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 967 | ip6_forward_next_trace_t *t = va_arg (*args, ip6_forward_next_trace_t *); |
| 968 | vnet_main_t *vnm = vnet_get_main (); |
Pierre Pfister | a38c3df | 2016-06-13 10:28:09 +0100 | [diff] [blame] | 969 | uword indent = format_get_indent (s); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 970 | |
Pierre Pfister | a38c3df | 2016-06-13 10:28:09 +0100 | [diff] [blame] | 971 | s = format (s, "tx_sw_if_index %d adj-idx %d : %U flow hash: 0x%08x", |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 972 | t->fib_index, t->adj_index, format_ip_adjacency, |
| 973 | t->adj_index, FORMAT_IP_ADJACENCY_NONE, t->flow_hash); |
Pierre Pfister | a38c3df | 2016-06-13 10:28:09 +0100 | [diff] [blame] | 974 | s = format (s, "\n%U%U", |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 975 | format_white_space, indent, |
| 976 | format_ip_adjacency_packet_data, |
| 977 | vnm, t->adj_index, t->packet_data, sizeof (t->packet_data)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 978 | return s; |
| 979 | } |
| 980 | |
| 981 | /* Common trace function for all ip6-forward next nodes. */ |
| 982 | void |
| 983 | ip6_forward_next_trace (vlib_main_t * vm, |
| 984 | vlib_node_runtime_t * node, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 985 | vlib_frame_t * frame, vlib_rx_or_tx_t which_adj_index) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 986 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 987 | u32 *from, n_left; |
| 988 | ip6_main_t *im = &ip6_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 989 | |
| 990 | n_left = frame->n_vectors; |
| 991 | from = vlib_frame_vector_args (frame); |
Pierre Pfister | 0febaf1 | 2016-06-08 12:23:21 +0100 | [diff] [blame] | 992 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 993 | while (n_left >= 4) |
| 994 | { |
| 995 | u32 bi0, bi1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 996 | vlib_buffer_t *b0, *b1; |
| 997 | ip6_forward_next_trace_t *t0, *t1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 998 | |
| 999 | /* Prefetch next iteration. */ |
| 1000 | vlib_prefetch_buffer_with_index (vm, from[2], LOAD); |
| 1001 | vlib_prefetch_buffer_with_index (vm, from[3], LOAD); |
| 1002 | |
| 1003 | bi0 = from[0]; |
| 1004 | bi1 = from[1]; |
| 1005 | |
| 1006 | b0 = vlib_get_buffer (vm, bi0); |
| 1007 | b1 = vlib_get_buffer (vm, bi1); |
| 1008 | |
| 1009 | if (b0->flags & VLIB_BUFFER_IS_TRACED) |
| 1010 | { |
| 1011 | t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0])); |
| 1012 | t0->adj_index = vnet_buffer (b0)->ip.adj_index[which_adj_index]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1013 | t0->flow_hash = vnet_buffer (b0)->ip.flow_hash; |
| 1014 | t0->fib_index = |
| 1015 | (vnet_buffer (b0)->sw_if_index[VLIB_TX] != |
| 1016 | (u32) ~ 0) ? vnet_buffer (b0)->sw_if_index[VLIB_TX] : |
| 1017 | vec_elt (im->fib_index_by_sw_if_index, |
| 1018 | vnet_buffer (b0)->sw_if_index[VLIB_RX]); |
Pierre Pfister | 0febaf1 | 2016-06-08 12:23:21 +0100 | [diff] [blame] | 1019 | |
Damjan Marion | f1213b8 | 2016-03-13 02:22:06 +0100 | [diff] [blame] | 1020 | clib_memcpy (t0->packet_data, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1021 | vlib_buffer_get_current (b0), |
| 1022 | sizeof (t0->packet_data)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1023 | } |
| 1024 | if (b1->flags & VLIB_BUFFER_IS_TRACED) |
| 1025 | { |
| 1026 | t1 = vlib_add_trace (vm, node, b1, sizeof (t1[0])); |
| 1027 | t1->adj_index = vnet_buffer (b1)->ip.adj_index[which_adj_index]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1028 | t1->flow_hash = vnet_buffer (b1)->ip.flow_hash; |
| 1029 | t1->fib_index = |
| 1030 | (vnet_buffer (b1)->sw_if_index[VLIB_TX] != |
| 1031 | (u32) ~ 0) ? vnet_buffer (b1)->sw_if_index[VLIB_TX] : |
| 1032 | vec_elt (im->fib_index_by_sw_if_index, |
| 1033 | vnet_buffer (b1)->sw_if_index[VLIB_RX]); |
Pierre Pfister | 0febaf1 | 2016-06-08 12:23:21 +0100 | [diff] [blame] | 1034 | |
Damjan Marion | f1213b8 | 2016-03-13 02:22:06 +0100 | [diff] [blame] | 1035 | clib_memcpy (t1->packet_data, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1036 | vlib_buffer_get_current (b1), |
| 1037 | sizeof (t1->packet_data)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1038 | } |
| 1039 | from += 2; |
| 1040 | n_left -= 2; |
| 1041 | } |
| 1042 | |
| 1043 | while (n_left >= 1) |
| 1044 | { |
| 1045 | u32 bi0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1046 | vlib_buffer_t *b0; |
| 1047 | ip6_forward_next_trace_t *t0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1048 | |
| 1049 | bi0 = from[0]; |
| 1050 | |
| 1051 | b0 = vlib_get_buffer (vm, bi0); |
| 1052 | |
| 1053 | if (b0->flags & VLIB_BUFFER_IS_TRACED) |
| 1054 | { |
| 1055 | t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0])); |
| 1056 | t0->adj_index = vnet_buffer (b0)->ip.adj_index[which_adj_index]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1057 | t0->flow_hash = vnet_buffer (b0)->ip.flow_hash; |
| 1058 | t0->fib_index = |
| 1059 | (vnet_buffer (b0)->sw_if_index[VLIB_TX] != |
| 1060 | (u32) ~ 0) ? vnet_buffer (b0)->sw_if_index[VLIB_TX] : |
| 1061 | vec_elt (im->fib_index_by_sw_if_index, |
| 1062 | vnet_buffer (b0)->sw_if_index[VLIB_RX]); |
Pierre Pfister | 0febaf1 | 2016-06-08 12:23:21 +0100 | [diff] [blame] | 1063 | |
Damjan Marion | f1213b8 | 2016-03-13 02:22:06 +0100 | [diff] [blame] | 1064 | clib_memcpy (t0->packet_data, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1065 | vlib_buffer_get_current (b0), |
| 1066 | sizeof (t0->packet_data)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1067 | } |
| 1068 | from += 1; |
| 1069 | n_left -= 1; |
| 1070 | } |
| 1071 | } |
| 1072 | |
| 1073 | static uword |
| 1074 | ip6_drop_or_punt (vlib_main_t * vm, |
| 1075 | vlib_node_runtime_t * node, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1076 | vlib_frame_t * frame, ip6_error_t error_code) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1077 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1078 | u32 *buffers = vlib_frame_vector_args (frame); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1079 | uword n_packets = frame->n_vectors; |
| 1080 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1081 | vlib_error_drop_buffers (vm, node, buffers, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1082 | /* stride */ 1, |
| 1083 | n_packets, |
| 1084 | /* next */ 0, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1085 | ip6_input_node.index, error_code); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1086 | |
| 1087 | if (node->flags & VLIB_NODE_FLAG_TRACE) |
| 1088 | ip6_forward_next_trace (vm, node, frame, VLIB_TX); |
| 1089 | |
| 1090 | return n_packets; |
| 1091 | } |
| 1092 | |
| 1093 | static uword |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1094 | ip6_drop (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) |
| 1095 | { |
| 1096 | return ip6_drop_or_punt (vm, node, frame, IP6_ERROR_ADJACENCY_DROP); |
| 1097 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1098 | |
| 1099 | static uword |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1100 | ip6_punt (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) |
| 1101 | { |
| 1102 | return ip6_drop_or_punt (vm, node, frame, IP6_ERROR_ADJACENCY_PUNT); |
| 1103 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1104 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1105 | /* *INDENT-OFF* */ |
| 1106 | VLIB_REGISTER_NODE (ip6_drop_node, static) = |
| 1107 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1108 | .function = ip6_drop, |
| 1109 | .name = "ip6-drop", |
| 1110 | .vector_size = sizeof (u32), |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1111 | .format_trace = format_ip6_forward_next_trace, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1112 | .n_next_nodes = 1, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1113 | .next_nodes = |
| 1114 | { |
| 1115 | [0] = "error-drop",}, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1116 | }; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1117 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1118 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1119 | VLIB_NODE_FUNCTION_MULTIARCH (ip6_drop_node, ip6_drop); |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 1120 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1121 | /* *INDENT-OFF* */ |
| 1122 | VLIB_REGISTER_NODE (ip6_punt_node, static) = |
| 1123 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1124 | .function = ip6_punt, |
| 1125 | .name = "ip6-punt", |
| 1126 | .vector_size = sizeof (u32), |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1127 | .format_trace = format_ip6_forward_next_trace, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1128 | .n_next_nodes = 1, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1129 | .next_nodes = |
| 1130 | { |
| 1131 | [0] = "error-punt",}, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1132 | }; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1133 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1134 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1135 | VLIB_NODE_FUNCTION_MULTIARCH (ip6_punt_node, ip6_punt); |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 1136 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1137 | /* Compute TCP/UDP/ICMP6 checksum in software. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1138 | u16 |
| 1139 | ip6_tcp_udp_icmp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0, |
| 1140 | ip6_header_t * ip0, int *bogus_lengthp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1141 | { |
| 1142 | ip_csum_t sum0; |
| 1143 | u16 sum16, payload_length_host_byte_order; |
| 1144 | u32 i, n_this_buffer, n_bytes_left; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1145 | u32 headers_size = sizeof (ip0[0]); |
| 1146 | void *data_this_buffer; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1147 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1148 | ASSERT (bogus_lengthp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1149 | *bogus_lengthp = 0; |
| 1150 | |
| 1151 | /* Initialize checksum with ip header. */ |
| 1152 | sum0 = ip0->payload_length + clib_host_to_net_u16 (ip0->protocol); |
| 1153 | payload_length_host_byte_order = clib_net_to_host_u16 (ip0->payload_length); |
| 1154 | data_this_buffer = (void *) (ip0 + 1); |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1155 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1156 | for (i = 0; i < ARRAY_LEN (ip0->src_address.as_uword); i++) |
| 1157 | { |
| 1158 | sum0 = ip_csum_with_carry (sum0, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1159 | clib_mem_unaligned (&ip0-> |
| 1160 | src_address.as_uword[i], |
| 1161 | uword)); |
| 1162 | sum0 = |
| 1163 | ip_csum_with_carry (sum0, |
| 1164 | clib_mem_unaligned (&ip0->dst_address.as_uword[i], |
| 1165 | uword)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1166 | } |
| 1167 | |
| 1168 | /* some icmp packets may come with a "router alert" hop-by-hop extension header (e.g., mldv2 packets) */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1169 | if (PREDICT_FALSE (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1170 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1171 | u32 skip_bytes; |
| 1172 | ip6_hop_by_hop_ext_t *ext_hdr = |
| 1173 | (ip6_hop_by_hop_ext_t *) data_this_buffer; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1174 | |
| 1175 | /* validate really icmp6 next */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1176 | ASSERT (ext_hdr->next_hdr == IP_PROTOCOL_ICMP6); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1177 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1178 | skip_bytes = 8 * (1 + ext_hdr->n_data_u64s); |
| 1179 | data_this_buffer = (void *) ((u8 *) data_this_buffer + skip_bytes); |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1180 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1181 | payload_length_host_byte_order -= skip_bytes; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1182 | headers_size += skip_bytes; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1183 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1184 | |
| 1185 | n_bytes_left = n_this_buffer = payload_length_host_byte_order; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1186 | if (p0 && n_this_buffer + headers_size > p0->current_length) |
| 1187 | n_this_buffer = |
| 1188 | p0->current_length > |
| 1189 | headers_size ? p0->current_length - headers_size : 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1190 | while (1) |
| 1191 | { |
| 1192 | sum0 = ip_incremental_checksum (sum0, data_this_buffer, n_this_buffer); |
| 1193 | n_bytes_left -= n_this_buffer; |
| 1194 | if (n_bytes_left == 0) |
| 1195 | break; |
| 1196 | |
| 1197 | if (!(p0->flags & VLIB_BUFFER_NEXT_PRESENT)) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1198 | { |
| 1199 | *bogus_lengthp = 1; |
| 1200 | return 0xfefe; |
| 1201 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1202 | p0 = vlib_get_buffer (vm, p0->next_buffer); |
| 1203 | data_this_buffer = vlib_buffer_get_current (p0); |
| 1204 | n_this_buffer = p0->current_length; |
| 1205 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1206 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1207 | sum16 = ~ip_csum_fold (sum0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1208 | |
| 1209 | return sum16; |
| 1210 | } |
| 1211 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1212 | u32 |
| 1213 | ip6_tcp_udp_icmp_validate_checksum (vlib_main_t * vm, vlib_buffer_t * p0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1214 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1215 | ip6_header_t *ip0 = vlib_buffer_get_current (p0); |
| 1216 | udp_header_t *udp0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1217 | u16 sum16; |
| 1218 | int bogus_length; |
| 1219 | |
| 1220 | /* some icmp packets may come with a "router alert" hop-by-hop extension header (e.g., mldv2 packets) */ |
| 1221 | ASSERT (ip0->protocol == IP_PROTOCOL_TCP |
| 1222 | || ip0->protocol == IP_PROTOCOL_ICMP6 |
| 1223 | || ip0->protocol == IP_PROTOCOL_UDP |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1224 | || ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1225 | |
| 1226 | udp0 = (void *) (ip0 + 1); |
| 1227 | if (ip0->protocol == IP_PROTOCOL_UDP && udp0->checksum == 0) |
| 1228 | { |
| 1229 | p0->flags |= (IP_BUFFER_L4_CHECKSUM_COMPUTED |
| 1230 | | IP_BUFFER_L4_CHECKSUM_CORRECT); |
| 1231 | return p0->flags; |
| 1232 | } |
| 1233 | |
| 1234 | sum16 = ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip0, &bogus_length); |
| 1235 | |
| 1236 | p0->flags |= (IP_BUFFER_L4_CHECKSUM_COMPUTED |
| 1237 | | ((sum16 == 0) << LOG2_IP_BUFFER_L4_CHECKSUM_CORRECT)); |
| 1238 | |
| 1239 | return p0->flags; |
| 1240 | } |
| 1241 | |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1242 | /* ip6_locate_header |
| 1243 | * |
| 1244 | * This function is to search for the header specified by the find_hdr number. |
| 1245 | * 1. If the find_hdr < 0 then it finds and returns the protocol number and |
| 1246 | * offset stored in *offset of the transport or ESP header in the chain if |
| 1247 | * found. |
| 1248 | * 2. If a header with find_hdr > 0 protocol number is found then the |
| 1249 | * offset is stored in *offset and protocol number of the header is |
| 1250 | * returned. |
| 1251 | * 3. If find_hdr header is not found or packet is malformed or |
| 1252 | * it is a non-first fragment -1 is returned. |
| 1253 | */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1254 | always_inline int |
| 1255 | ip6_locate_header (vlib_buffer_t * p0, |
| 1256 | ip6_header_t * ip0, int find_hdr, u32 * offset) |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1257 | { |
| 1258 | u8 next_proto = ip0->protocol; |
| 1259 | u8 *next_header; |
| 1260 | u8 done = 0; |
| 1261 | u32 cur_offset; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1262 | u8 *temp_nxthdr = 0; |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1263 | u32 exthdr_len = 0; |
| 1264 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1265 | next_header = ip6_next_header (ip0); |
| 1266 | cur_offset = sizeof (ip6_header_t); |
| 1267 | while (1) |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1268 | { |
| 1269 | done = (next_proto == find_hdr); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1270 | if (PREDICT_FALSE |
| 1271 | (next_header >= |
| 1272 | (u8 *) vlib_buffer_get_current (p0) + p0->current_length)) |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1273 | { |
| 1274 | //A malicious packet could set an extension header with a too big size |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1275 | return (-1); |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1276 | } |
| 1277 | if (done) |
| 1278 | break; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1279 | if ((!ip6_ext_hdr (next_proto)) || next_proto == IP_PROTOCOL_IP6_NONXT) |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1280 | { |
| 1281 | if (find_hdr < 0) |
| 1282 | break; |
| 1283 | return -1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1284 | } |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1285 | if (next_proto == IP_PROTOCOL_IPV6_FRAGMENTATION) |
| 1286 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1287 | ip6_frag_hdr_t *frag_hdr = (ip6_frag_hdr_t *) next_header; |
| 1288 | u16 frag_off = ip6_frag_hdr_offset (frag_hdr); |
| 1289 | /* Non first fragment return -1 */ |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1290 | if (frag_off) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1291 | return (-1); |
| 1292 | exthdr_len = sizeof (ip6_frag_hdr_t); |
| 1293 | temp_nxthdr = next_header + exthdr_len; |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1294 | } |
| 1295 | else if (next_proto == IP_PROTOCOL_IPSEC_AH) |
| 1296 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1297 | exthdr_len = |
| 1298 | ip6_ext_authhdr_len (((ip6_ext_header_t *) next_header)); |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1299 | temp_nxthdr = next_header + exthdr_len; |
| 1300 | } |
| 1301 | else |
| 1302 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1303 | exthdr_len = |
| 1304 | ip6_ext_header_len (((ip6_ext_header_t *) next_header)); |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1305 | temp_nxthdr = next_header + exthdr_len; |
| 1306 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1307 | next_proto = ((ip6_ext_header_t *) next_header)->next_hdr; |
| 1308 | next_header = temp_nxthdr; |
| 1309 | cur_offset += exthdr_len; |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1310 | } |
| 1311 | |
| 1312 | *offset = cur_offset; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1313 | return (next_proto); |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1314 | } |
| 1315 | |
AkshayaNadahalli | 0f438df | 2017-02-10 10:54:16 +0530 | [diff] [blame] | 1316 | /** |
| 1317 | * @brief returns number of links on which src is reachable. |
| 1318 | */ |
| 1319 | always_inline int |
| 1320 | ip6_urpf_loose_check (ip6_main_t * im, vlib_buffer_t * b, ip6_header_t * i) |
| 1321 | { |
| 1322 | const load_balance_t *lb0; |
| 1323 | index_t lbi; |
| 1324 | |
| 1325 | lbi = ip6_fib_table_fwding_lookup_with_if_index (im, |
| 1326 | vnet_buffer |
| 1327 | (b)->sw_if_index[VLIB_RX], |
| 1328 | &i->src_address); |
| 1329 | |
| 1330 | lb0 = load_balance_get (lbi); |
| 1331 | |
| 1332 | return (fib_urpf_check_size (lb0->lb_urpf)); |
| 1333 | } |
| 1334 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1335 | static uword |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1336 | ip6_local (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1337 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1338 | ip6_main_t *im = &ip6_main; |
| 1339 | ip_lookup_main_t *lm = &im->lookup_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1340 | ip_local_next_t next_index; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1341 | u32 *from, *to_next, n_left_from, n_left_to_next; |
| 1342 | vlib_node_runtime_t *error_node = |
| 1343 | vlib_node_get_runtime (vm, ip6_input_node.index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1344 | |
| 1345 | from = vlib_frame_vector_args (frame); |
| 1346 | n_left_from = frame->n_vectors; |
| 1347 | next_index = node->cached_next_index; |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1348 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1349 | if (node->flags & VLIB_NODE_FLAG_TRACE) |
| 1350 | ip6_forward_next_trace (vm, node, frame, VLIB_TX); |
| 1351 | |
| 1352 | while (n_left_from > 0) |
| 1353 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1354 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1355 | |
| 1356 | while (n_left_from >= 4 && n_left_to_next >= 2) |
| 1357 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1358 | vlib_buffer_t *p0, *p1; |
| 1359 | ip6_header_t *ip0, *ip1; |
| 1360 | udp_header_t *udp0, *udp1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1361 | u32 pi0, ip_len0, udp_len0, flags0, next0; |
| 1362 | u32 pi1, ip_len1, udp_len1, flags1, next1; |
| 1363 | i32 len_diff0, len_diff1; |
| 1364 | u8 error0, type0, good_l4_checksum0; |
| 1365 | u8 error1, type1, good_l4_checksum1; |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1366 | u32 udp_offset0, udp_offset1; |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1367 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1368 | pi0 = to_next[0] = from[0]; |
| 1369 | pi1 = to_next[1] = from[1]; |
| 1370 | from += 2; |
| 1371 | n_left_from -= 2; |
| 1372 | to_next += 2; |
| 1373 | n_left_to_next -= 2; |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1374 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1375 | p0 = vlib_get_buffer (vm, pi0); |
| 1376 | p1 = vlib_get_buffer (vm, pi1); |
| 1377 | |
| 1378 | ip0 = vlib_buffer_get_current (p0); |
| 1379 | ip1 = vlib_buffer_get_current (p1); |
| 1380 | |
Filip Tehlar | b601f22 | 2017-01-02 10:22:56 +0100 | [diff] [blame] | 1381 | vnet_buffer (p0)->ip.start_of_ip_header = p0->current_data; |
| 1382 | vnet_buffer (p1)->ip.start_of_ip_header = p1->current_data; |
| 1383 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1384 | type0 = lm->builtin_protocol_by_ip_protocol[ip0->protocol]; |
| 1385 | type1 = lm->builtin_protocol_by_ip_protocol[ip1->protocol]; |
| 1386 | |
| 1387 | next0 = lm->local_next_by_ip_protocol[ip0->protocol]; |
| 1388 | next1 = lm->local_next_by_ip_protocol[ip1->protocol]; |
| 1389 | |
| 1390 | flags0 = p0->flags; |
| 1391 | flags1 = p1->flags; |
| 1392 | |
| 1393 | good_l4_checksum0 = (flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0; |
| 1394 | good_l4_checksum1 = (flags1 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0; |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1395 | len_diff0 = 0; |
| 1396 | len_diff1 = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1397 | |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1398 | /* Skip HBH local processing */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1399 | if (PREDICT_FALSE |
| 1400 | (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS)) |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1401 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1402 | ip6_hop_by_hop_ext_t *ext_hdr = |
| 1403 | (ip6_hop_by_hop_ext_t *) ip6_next_header (ip0); |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1404 | next0 = lm->local_next_by_ip_protocol[ext_hdr->next_hdr]; |
| 1405 | type0 = lm->builtin_protocol_by_ip_protocol[ext_hdr->next_hdr]; |
| 1406 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1407 | if (PREDICT_FALSE |
| 1408 | (ip1->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS)) |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1409 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1410 | ip6_hop_by_hop_ext_t *ext_hdr = |
| 1411 | (ip6_hop_by_hop_ext_t *) ip6_next_header (ip1); |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1412 | next1 = lm->local_next_by_ip_protocol[ext_hdr->next_hdr]; |
| 1413 | type1 = lm->builtin_protocol_by_ip_protocol[ext_hdr->next_hdr]; |
| 1414 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1415 | if (PREDICT_TRUE (IP_PROTOCOL_UDP == ip6_locate_header (p0, ip0, |
| 1416 | IP_PROTOCOL_UDP, |
| 1417 | &udp_offset0))) |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1418 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1419 | udp0 = (udp_header_t *) ((u8 *) ip0 + udp_offset0); |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1420 | /* Don't verify UDP checksum for packets with explicit zero checksum. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1421 | good_l4_checksum0 |= type0 == IP_BUILTIN_PROTOCOL_UDP |
| 1422 | && udp0->checksum == 0; |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1423 | /* Verify UDP length. */ |
| 1424 | ip_len0 = clib_net_to_host_u16 (ip0->payload_length); |
| 1425 | udp_len0 = clib_net_to_host_u16 (udp0->length); |
| 1426 | len_diff0 = ip_len0 - udp_len0; |
| 1427 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1428 | if (PREDICT_TRUE (IP_PROTOCOL_UDP == ip6_locate_header (p1, ip1, |
| 1429 | IP_PROTOCOL_UDP, |
| 1430 | &udp_offset1))) |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1431 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1432 | udp1 = (udp_header_t *) ((u8 *) ip1 + udp_offset1); |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1433 | /* Don't verify UDP checksum for packets with explicit zero checksum. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1434 | good_l4_checksum1 |= type1 == IP_BUILTIN_PROTOCOL_UDP |
| 1435 | && udp1->checksum == 0; |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1436 | /* Verify UDP length. */ |
| 1437 | ip_len1 = clib_net_to_host_u16 (ip1->payload_length); |
| 1438 | udp_len1 = clib_net_to_host_u16 (udp1->length); |
| 1439 | len_diff1 = ip_len1 - udp_len1; |
| 1440 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1441 | |
| 1442 | good_l4_checksum0 |= type0 == IP_BUILTIN_PROTOCOL_UNKNOWN; |
| 1443 | good_l4_checksum1 |= type1 == IP_BUILTIN_PROTOCOL_UNKNOWN; |
| 1444 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1445 | len_diff0 = type0 == IP_BUILTIN_PROTOCOL_UDP ? len_diff0 : 0; |
| 1446 | len_diff1 = type1 == IP_BUILTIN_PROTOCOL_UDP ? len_diff1 : 0; |
| 1447 | |
| 1448 | if (PREDICT_FALSE (type0 != IP_BUILTIN_PROTOCOL_UNKNOWN |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1449 | && !good_l4_checksum0 |
| 1450 | && !(flags0 & IP_BUFFER_L4_CHECKSUM_COMPUTED))) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1451 | { |
| 1452 | flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, p0); |
| 1453 | good_l4_checksum0 = |
| 1454 | (flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0; |
| 1455 | } |
| 1456 | if (PREDICT_FALSE (type1 != IP_BUILTIN_PROTOCOL_UNKNOWN |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1457 | && !good_l4_checksum1 |
| 1458 | && !(flags1 & IP_BUFFER_L4_CHECKSUM_COMPUTED))) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1459 | { |
| 1460 | flags1 = ip6_tcp_udp_icmp_validate_checksum (vm, p1); |
| 1461 | good_l4_checksum1 = |
| 1462 | (flags1 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0; |
| 1463 | } |
| 1464 | |
| 1465 | error0 = error1 = IP6_ERROR_UNKNOWN_PROTOCOL; |
| 1466 | |
| 1467 | error0 = len_diff0 < 0 ? IP6_ERROR_UDP_LENGTH : error0; |
| 1468 | error1 = len_diff1 < 0 ? IP6_ERROR_UDP_LENGTH : error1; |
| 1469 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1470 | ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_UDP == |
| 1471 | IP6_ERROR_UDP_CHECKSUM); |
| 1472 | ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_ICMP == |
| 1473 | IP6_ERROR_ICMP_CHECKSUM); |
| 1474 | error0 = |
| 1475 | (!good_l4_checksum0 ? IP6_ERROR_UDP_CHECKSUM + type0 : error0); |
| 1476 | error1 = |
| 1477 | (!good_l4_checksum1 ? IP6_ERROR_UDP_CHECKSUM + type1 : error1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1478 | |
| 1479 | /* Drop packets from unroutable hosts. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1480 | /* If this is a neighbor solicitation (ICMP), skip source RPF check */ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1481 | if (error0 == IP6_ERROR_UNKNOWN_PROTOCOL && |
| 1482 | type0 != IP_BUILTIN_PROTOCOL_ICMP && |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1483 | !ip6_address_is_link_local_unicast (&ip0->src_address)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1484 | { |
AkshayaNadahalli | 8ea6d71 | 2017-02-07 23:59:54 +0530 | [diff] [blame] | 1485 | error0 = (!ip6_urpf_loose_check (im, p0, ip0) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1486 | ? IP6_ERROR_SRC_LOOKUP_MISS : error0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1487 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1488 | if (error1 == IP6_ERROR_UNKNOWN_PROTOCOL && |
| 1489 | type1 != IP_BUILTIN_PROTOCOL_ICMP && |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1490 | !ip6_address_is_link_local_unicast (&ip1->src_address)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1491 | { |
AkshayaNadahalli | 8ea6d71 | 2017-02-07 23:59:54 +0530 | [diff] [blame] | 1492 | error1 = (!ip6_urpf_loose_check (im, p1, ip1) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1493 | ? IP6_ERROR_SRC_LOOKUP_MISS : error1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1494 | } |
| 1495 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1496 | next0 = |
| 1497 | error0 != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next0; |
| 1498 | next1 = |
| 1499 | error1 != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1500 | |
| 1501 | p0->error = error_node->errors[error0]; |
| 1502 | p1->error = error_node->errors[error1]; |
| 1503 | |
| 1504 | vlib_validate_buffer_enqueue_x2 (vm, node, next_index, |
| 1505 | to_next, n_left_to_next, |
| 1506 | pi0, pi1, next0, next1); |
| 1507 | } |
| 1508 | |
| 1509 | while (n_left_from > 0 && n_left_to_next > 0) |
| 1510 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1511 | vlib_buffer_t *p0; |
| 1512 | ip6_header_t *ip0; |
| 1513 | udp_header_t *udp0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1514 | u32 pi0, ip_len0, udp_len0, flags0, next0; |
| 1515 | i32 len_diff0; |
| 1516 | u8 error0, type0, good_l4_checksum0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1517 | u32 udp_offset0; |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1518 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1519 | pi0 = to_next[0] = from[0]; |
| 1520 | from += 1; |
| 1521 | n_left_from -= 1; |
| 1522 | to_next += 1; |
| 1523 | n_left_to_next -= 1; |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1524 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1525 | p0 = vlib_get_buffer (vm, pi0); |
| 1526 | |
| 1527 | ip0 = vlib_buffer_get_current (p0); |
| 1528 | |
Filip Tehlar | b601f22 | 2017-01-02 10:22:56 +0100 | [diff] [blame] | 1529 | vnet_buffer (p0)->ip.start_of_ip_header = p0->current_data; |
| 1530 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1531 | type0 = lm->builtin_protocol_by_ip_protocol[ip0->protocol]; |
| 1532 | next0 = lm->local_next_by_ip_protocol[ip0->protocol]; |
| 1533 | |
| 1534 | flags0 = p0->flags; |
| 1535 | |
| 1536 | good_l4_checksum0 = (flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0; |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1537 | len_diff0 = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1538 | |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1539 | /* Skip HBH local processing */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1540 | if (PREDICT_FALSE |
| 1541 | (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS)) |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1542 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1543 | ip6_hop_by_hop_ext_t *ext_hdr = |
| 1544 | (ip6_hop_by_hop_ext_t *) ip6_next_header (ip0); |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1545 | next0 = lm->local_next_by_ip_protocol[ext_hdr->next_hdr]; |
| 1546 | type0 = lm->builtin_protocol_by_ip_protocol[ext_hdr->next_hdr]; |
| 1547 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1548 | if (PREDICT_TRUE (IP_PROTOCOL_UDP == ip6_locate_header (p0, ip0, |
| 1549 | IP_PROTOCOL_UDP, |
| 1550 | &udp_offset0))) |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1551 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1552 | udp0 = (udp_header_t *) ((u8 *) ip0 + udp_offset0); |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1553 | /* Don't verify UDP checksum for packets with explicit zero checksum. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1554 | good_l4_checksum0 |= type0 == IP_BUILTIN_PROTOCOL_UDP |
| 1555 | && udp0->checksum == 0; |
Shwetha | b78292e | 2016-09-13 11:51:00 +0100 | [diff] [blame] | 1556 | /* Verify UDP length. */ |
| 1557 | ip_len0 = clib_net_to_host_u16 (ip0->payload_length); |
| 1558 | udp_len0 = clib_net_to_host_u16 (udp0->length); |
| 1559 | len_diff0 = ip_len0 - udp_len0; |
| 1560 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1561 | |
| 1562 | good_l4_checksum0 |= type0 == IP_BUILTIN_PROTOCOL_UNKNOWN; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1563 | len_diff0 = type0 == IP_BUILTIN_PROTOCOL_UDP ? len_diff0 : 0; |
| 1564 | |
| 1565 | if (PREDICT_FALSE (type0 != IP_BUILTIN_PROTOCOL_UNKNOWN |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1566 | && !good_l4_checksum0 |
| 1567 | && !(flags0 & IP_BUFFER_L4_CHECKSUM_COMPUTED))) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1568 | { |
| 1569 | flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, p0); |
| 1570 | good_l4_checksum0 = |
| 1571 | (flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0; |
| 1572 | } |
| 1573 | |
| 1574 | error0 = IP6_ERROR_UNKNOWN_PROTOCOL; |
| 1575 | |
| 1576 | error0 = len_diff0 < 0 ? IP6_ERROR_UDP_LENGTH : error0; |
| 1577 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1578 | ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_UDP == |
| 1579 | IP6_ERROR_UDP_CHECKSUM); |
| 1580 | ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_ICMP == |
| 1581 | IP6_ERROR_ICMP_CHECKSUM); |
| 1582 | error0 = |
| 1583 | (!good_l4_checksum0 ? IP6_ERROR_UDP_CHECKSUM + type0 : error0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1584 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1585 | /* If this is a neighbor solicitation (ICMP), skip source RPF check */ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1586 | if (error0 == IP6_ERROR_UNKNOWN_PROTOCOL && |
| 1587 | type0 != IP_BUILTIN_PROTOCOL_ICMP && |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1588 | !ip6_address_is_link_local_unicast (&ip0->src_address)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1589 | { |
AkshayaNadahalli | 8ea6d71 | 2017-02-07 23:59:54 +0530 | [diff] [blame] | 1590 | error0 = (!ip6_urpf_loose_check (im, p0, ip0) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1591 | ? IP6_ERROR_SRC_LOOKUP_MISS : error0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1592 | } |
| 1593 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1594 | next0 = |
| 1595 | error0 != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1596 | |
| 1597 | p0->error = error_node->errors[error0]; |
| 1598 | |
| 1599 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 1600 | to_next, n_left_to_next, |
| 1601 | pi0, next0); |
| 1602 | } |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1603 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1604 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 1605 | } |
| 1606 | |
| 1607 | return frame->n_vectors; |
| 1608 | } |
| 1609 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1610 | /* *INDENT-OFF* */ |
| 1611 | VLIB_REGISTER_NODE (ip6_local_node, static) = |
| 1612 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1613 | .function = ip6_local, |
| 1614 | .name = "ip6-local", |
| 1615 | .vector_size = sizeof (u32), |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1616 | .format_trace = format_ip6_forward_next_trace, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1617 | .n_next_nodes = IP_LOCAL_N_NEXT, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1618 | .next_nodes = |
| 1619 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1620 | [IP_LOCAL_NEXT_DROP] = "error-drop", |
| 1621 | [IP_LOCAL_NEXT_PUNT] = "error-punt", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1622 | [IP_LOCAL_NEXT_UDP_LOOKUP] = "ip6-udp-lookup", |
| 1623 | [IP_LOCAL_NEXT_ICMP] = "ip6-icmp-input", |
| 1624 | }, |
| 1625 | }; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1626 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1627 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1628 | VLIB_NODE_FUNCTION_MULTIARCH (ip6_local_node, ip6_local); |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 1629 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1630 | void |
| 1631 | ip6_register_protocol (u32 protocol, u32 node_index) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1632 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1633 | vlib_main_t *vm = vlib_get_main (); |
| 1634 | ip6_main_t *im = &ip6_main; |
| 1635 | ip_lookup_main_t *lm = &im->lookup_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1636 | |
| 1637 | ASSERT (protocol < ARRAY_LEN (lm->local_next_by_ip_protocol)); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1638 | lm->local_next_by_ip_protocol[protocol] = |
| 1639 | vlib_node_add_next (vm, ip6_local_node.index, node_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1640 | } |
| 1641 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1642 | typedef enum |
| 1643 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1644 | IP6_DISCOVER_NEIGHBOR_NEXT_DROP, |
John Lo | d1f5d04 | 2016-04-12 18:20:39 -0400 | [diff] [blame] | 1645 | IP6_DISCOVER_NEIGHBOR_NEXT_REPLY_TX, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1646 | IP6_DISCOVER_NEIGHBOR_N_NEXT, |
| 1647 | } ip6_discover_neighbor_next_t; |
| 1648 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1649 | typedef enum |
| 1650 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1651 | IP6_DISCOVER_NEIGHBOR_ERROR_DROP, |
| 1652 | IP6_DISCOVER_NEIGHBOR_ERROR_REQUEST_SENT, |
Pierre Pfister | d076f19 | 2016-06-22 12:58:30 +0100 | [diff] [blame] | 1653 | IP6_DISCOVER_NEIGHBOR_ERROR_NO_SOURCE_ADDRESS, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1654 | } ip6_discover_neighbor_error_t; |
| 1655 | |
| 1656 | static uword |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1657 | ip6_discover_neighbor_inline (vlib_main_t * vm, |
| 1658 | vlib_node_runtime_t * node, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1659 | vlib_frame_t * frame, int is_glean) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1660 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1661 | vnet_main_t *vnm = vnet_get_main (); |
| 1662 | ip6_main_t *im = &ip6_main; |
| 1663 | ip_lookup_main_t *lm = &im->lookup_main; |
| 1664 | u32 *from, *to_next_drop; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1665 | uword n_left_from, n_left_to_next_drop; |
| 1666 | static f64 time_last_seed_change = -1e100; |
| 1667 | static u32 hash_seeds[3]; |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1668 | static uword hash_bitmap[256 / BITS (uword)]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1669 | f64 time_now; |
| 1670 | int bogus_length; |
| 1671 | |
| 1672 | if (node->flags & VLIB_NODE_FLAG_TRACE) |
| 1673 | ip6_forward_next_trace (vm, node, frame, VLIB_TX); |
| 1674 | |
| 1675 | time_now = vlib_time_now (vm); |
| 1676 | if (time_now - time_last_seed_change > 1e-3) |
| 1677 | { |
| 1678 | uword i; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1679 | u32 *r = clib_random_buffer_get_data (&vm->random_buffer, |
| 1680 | sizeof (hash_seeds)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1681 | for (i = 0; i < ARRAY_LEN (hash_seeds); i++) |
| 1682 | hash_seeds[i] = r[i]; |
| 1683 | |
| 1684 | /* Mark all hash keys as been not-seen before. */ |
| 1685 | for (i = 0; i < ARRAY_LEN (hash_bitmap); i++) |
| 1686 | hash_bitmap[i] = 0; |
| 1687 | |
| 1688 | time_last_seed_change = time_now; |
| 1689 | } |
| 1690 | |
| 1691 | from = vlib_frame_vector_args (frame); |
| 1692 | n_left_from = frame->n_vectors; |
| 1693 | |
| 1694 | while (n_left_from > 0) |
| 1695 | { |
| 1696 | vlib_get_next_frame (vm, node, IP6_DISCOVER_NEIGHBOR_NEXT_DROP, |
| 1697 | to_next_drop, n_left_to_next_drop); |
| 1698 | |
| 1699 | while (n_left_from > 0 && n_left_to_next_drop > 0) |
| 1700 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1701 | vlib_buffer_t *p0; |
| 1702 | ip6_header_t *ip0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1703 | u32 pi0, adj_index0, a0, b0, c0, m0, sw_if_index0, drop0; |
| 1704 | uword bm0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1705 | ip_adjacency_t *adj0; |
| 1706 | vnet_hw_interface_t *hw_if0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1707 | u32 next0; |
| 1708 | |
| 1709 | pi0 = from[0]; |
| 1710 | |
| 1711 | p0 = vlib_get_buffer (vm, pi0); |
| 1712 | |
| 1713 | adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX]; |
| 1714 | |
| 1715 | ip0 = vlib_buffer_get_current (p0); |
| 1716 | |
| 1717 | adj0 = ip_get_adjacency (lm, adj_index0); |
| 1718 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1719 | if (!is_glean) |
| 1720 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1721 | ip0->dst_address.as_u64[0] = |
| 1722 | adj0->sub_type.nbr.next_hop.ip6.as_u64[0]; |
| 1723 | ip0->dst_address.as_u64[1] = |
| 1724 | adj0->sub_type.nbr.next_hop.ip6.as_u64[1]; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1725 | } |
Pierre Pfister | 1dabaaf | 2016-04-25 14:15:15 +0100 | [diff] [blame] | 1726 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1727 | a0 = hash_seeds[0]; |
| 1728 | b0 = hash_seeds[1]; |
| 1729 | c0 = hash_seeds[2]; |
| 1730 | |
| 1731 | sw_if_index0 = adj0->rewrite_header.sw_if_index; |
| 1732 | vnet_buffer (p0)->sw_if_index[VLIB_TX] = sw_if_index0; |
| 1733 | |
| 1734 | a0 ^= sw_if_index0; |
| 1735 | b0 ^= ip0->dst_address.as_u32[0]; |
| 1736 | c0 ^= ip0->dst_address.as_u32[1]; |
| 1737 | |
| 1738 | hash_v3_mix32 (a0, b0, c0); |
| 1739 | |
| 1740 | b0 ^= ip0->dst_address.as_u32[2]; |
| 1741 | c0 ^= ip0->dst_address.as_u32[3]; |
| 1742 | |
| 1743 | hash_v3_finalize32 (a0, b0, c0); |
| 1744 | |
| 1745 | c0 &= BITS (hash_bitmap) - 1; |
| 1746 | c0 = c0 / BITS (uword); |
| 1747 | m0 = (uword) 1 << (c0 % BITS (uword)); |
| 1748 | |
| 1749 | bm0 = hash_bitmap[c0]; |
| 1750 | drop0 = (bm0 & m0) != 0; |
| 1751 | |
| 1752 | /* Mark it as seen. */ |
| 1753 | hash_bitmap[c0] = bm0 | m0; |
| 1754 | |
| 1755 | from += 1; |
| 1756 | n_left_from -= 1; |
| 1757 | to_next_drop[0] = pi0; |
| 1758 | to_next_drop += 1; |
| 1759 | n_left_to_next_drop -= 1; |
| 1760 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1761 | hw_if0 = vnet_get_sup_hw_interface (vnm, sw_if_index0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1762 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1763 | /* If the interface is link-down, drop the pkt */ |
| 1764 | if (!(hw_if0->flags & VNET_HW_INTERFACE_FLAG_LINK_UP)) |
| 1765 | drop0 = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1766 | |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1767 | p0->error = |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1768 | node->errors[drop0 ? IP6_DISCOVER_NEIGHBOR_ERROR_DROP |
| 1769 | : IP6_DISCOVER_NEIGHBOR_ERROR_REQUEST_SENT]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1770 | if (drop0) |
| 1771 | continue; |
| 1772 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 1773 | /* |
| 1774 | * the adj has been updated to a rewrite but the node the DPO that got |
| 1775 | * us here hasn't - yet. no big deal. we'll drop while we wait. |
| 1776 | */ |
| 1777 | if (IP_LOOKUP_NEXT_REWRITE == adj0->lookup_next_index) |
| 1778 | continue; |
| 1779 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1780 | { |
| 1781 | u32 bi0 = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1782 | icmp6_neighbor_solicitation_header_t *h0; |
| 1783 | vlib_buffer_t *b0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1784 | |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1785 | h0 = vlib_packet_template_get_packet |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1786 | (vm, &im->discover_neighbor_packet_template, &bi0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1787 | |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1788 | /* |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1789 | * Build ethernet header. |
| 1790 | * Choose source address based on destination lookup |
| 1791 | * adjacency. |
| 1792 | */ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1793 | if (ip6_src_address_for_packet (lm, |
| 1794 | sw_if_index0, |
| 1795 | &h0->ip.src_address)) |
| 1796 | { |
| 1797 | /* There is no address on the interface */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1798 | p0->error = |
| 1799 | node->errors[IP6_DISCOVER_NEIGHBOR_ERROR_NO_SOURCE_ADDRESS]; |
| 1800 | vlib_buffer_free (vm, &bi0, 1); |
Pierre Pfister | d076f19 | 2016-06-22 12:58:30 +0100 | [diff] [blame] | 1801 | continue; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1802 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1803 | |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1804 | /* |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1805 | * Destination address is a solicited node multicast address. |
| 1806 | * We need to fill in |
| 1807 | * the low 24 bits with low 24 bits of target's address. |
| 1808 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1809 | h0->ip.dst_address.as_u8[13] = ip0->dst_address.as_u8[13]; |
| 1810 | h0->ip.dst_address.as_u8[14] = ip0->dst_address.as_u8[14]; |
| 1811 | h0->ip.dst_address.as_u8[15] = ip0->dst_address.as_u8[15]; |
| 1812 | |
| 1813 | h0->neighbor.target_address = ip0->dst_address; |
| 1814 | |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1815 | clib_memcpy (h0->link_layer_option.ethernet_address, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1816 | hw_if0->hw_address, vec_len (hw_if0->hw_address)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1817 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1818 | /* $$$$ appears we need this; why is the checksum non-zero? */ |
| 1819 | h0->neighbor.icmp.checksum = 0; |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1820 | h0->neighbor.icmp.checksum = |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1821 | ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h0->ip, |
| 1822 | &bogus_length); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1823 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1824 | ASSERT (bogus_length == 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1825 | |
| 1826 | vlib_buffer_copy_trace_flag (vm, p0, bi0); |
| 1827 | b0 = vlib_get_buffer (vm, bi0); |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1828 | vnet_buffer (b0)->sw_if_index[VLIB_TX] |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1829 | = vnet_buffer (p0)->sw_if_index[VLIB_TX]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1830 | |
| 1831 | /* Add rewrite/encap string. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1832 | vnet_rewrite_one_header (adj0[0], h0, sizeof (ethernet_header_t)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1833 | vlib_buffer_advance (b0, -adj0->rewrite_header.data_bytes); |
| 1834 | |
John Lo | d1f5d04 | 2016-04-12 18:20:39 -0400 | [diff] [blame] | 1835 | next0 = IP6_DISCOVER_NEIGHBOR_NEXT_REPLY_TX; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1836 | |
| 1837 | vlib_set_next_frame_buffer (vm, node, next0, bi0); |
| 1838 | } |
| 1839 | } |
| 1840 | |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1841 | vlib_put_next_frame (vm, node, IP6_DISCOVER_NEIGHBOR_NEXT_DROP, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1842 | n_left_to_next_drop); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1843 | } |
| 1844 | |
| 1845 | return frame->n_vectors; |
| 1846 | } |
| 1847 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1848 | static uword |
| 1849 | ip6_discover_neighbor (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1850 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1851 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1852 | return (ip6_discover_neighbor_inline (vm, node, frame, 0)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1853 | } |
| 1854 | |
| 1855 | static uword |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1856 | ip6_glean (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1857 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1858 | return (ip6_discover_neighbor_inline (vm, node, frame, 1)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1859 | } |
| 1860 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1861 | static char *ip6_discover_neighbor_error_strings[] = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1862 | [IP6_DISCOVER_NEIGHBOR_ERROR_DROP] = "address overflow drops", |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1863 | [IP6_DISCOVER_NEIGHBOR_ERROR_REQUEST_SENT] = "neighbor solicitations sent", |
Pierre Pfister | d076f19 | 2016-06-22 12:58:30 +0100 | [diff] [blame] | 1864 | [IP6_DISCOVER_NEIGHBOR_ERROR_NO_SOURCE_ADDRESS] |
| 1865 | = "no source address for ND solicitation", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1866 | }; |
| 1867 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1868 | /* *INDENT-OFF* */ |
| 1869 | VLIB_REGISTER_NODE (ip6_discover_neighbor_node) = |
| 1870 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1871 | .function = ip6_discover_neighbor, |
| 1872 | .name = "ip6-discover-neighbor", |
| 1873 | .vector_size = sizeof (u32), |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1874 | .format_trace = format_ip6_forward_next_trace, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1875 | .n_errors = ARRAY_LEN (ip6_discover_neighbor_error_strings), |
| 1876 | .error_strings = ip6_discover_neighbor_error_strings, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1877 | .n_next_nodes = IP6_DISCOVER_NEIGHBOR_N_NEXT, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1878 | .next_nodes = |
| 1879 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1880 | [IP6_DISCOVER_NEIGHBOR_NEXT_DROP] = "error-drop", |
John Lo | d1f5d04 | 2016-04-12 18:20:39 -0400 | [diff] [blame] | 1881 | [IP6_DISCOVER_NEIGHBOR_NEXT_REPLY_TX] = "interface-output", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1882 | }, |
| 1883 | }; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1884 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1885 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1886 | /* *INDENT-OFF* */ |
| 1887 | VLIB_REGISTER_NODE (ip6_glean_node) = |
| 1888 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1889 | .function = ip6_glean, |
| 1890 | .name = "ip6-glean", |
| 1891 | .vector_size = sizeof (u32), |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1892 | .format_trace = format_ip6_forward_next_trace, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1893 | .n_errors = ARRAY_LEN (ip6_discover_neighbor_error_strings), |
| 1894 | .error_strings = ip6_discover_neighbor_error_strings, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1895 | .n_next_nodes = IP6_DISCOVER_NEIGHBOR_N_NEXT, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1896 | .next_nodes = |
| 1897 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1898 | [IP6_DISCOVER_NEIGHBOR_NEXT_DROP] = "error-drop", |
| 1899 | [IP6_DISCOVER_NEIGHBOR_NEXT_REPLY_TX] = "interface-output", |
| 1900 | }, |
| 1901 | }; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1902 | /* *INDENT-ON* */ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1903 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1904 | clib_error_t * |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1905 | ip6_probe_neighbor (vlib_main_t * vm, ip6_address_t * dst, u32 sw_if_index) |
| 1906 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1907 | vnet_main_t *vnm = vnet_get_main (); |
| 1908 | ip6_main_t *im = &ip6_main; |
| 1909 | icmp6_neighbor_solicitation_header_t *h; |
| 1910 | ip6_address_t *src; |
| 1911 | ip_interface_address_t *ia; |
| 1912 | ip_adjacency_t *adj; |
| 1913 | vnet_hw_interface_t *hi; |
| 1914 | vnet_sw_interface_t *si; |
| 1915 | vlib_buffer_t *b; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1916 | u32 bi = 0; |
| 1917 | int bogus_length; |
| 1918 | |
| 1919 | si = vnet_get_sw_interface (vnm, sw_if_index); |
| 1920 | |
| 1921 | if (!(si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP)) |
| 1922 | { |
| 1923 | return clib_error_return (0, "%U: interface %U down", |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1924 | format_ip6_address, dst, |
| 1925 | format_vnet_sw_if_index_name, vnm, |
| 1926 | sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1927 | } |
| 1928 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1929 | src = |
| 1930 | ip6_interface_address_matching_destination (im, dst, sw_if_index, &ia); |
| 1931 | if (!src) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1932 | { |
| 1933 | vnm->api_errno = VNET_API_ERROR_NO_MATCHING_INTERFACE; |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1934 | return clib_error_return |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1935 | (0, "no matching interface address for destination %U (interface %U)", |
| 1936 | format_ip6_address, dst, |
| 1937 | format_vnet_sw_if_index_name, vnm, sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1938 | } |
| 1939 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1940 | h = |
| 1941 | vlib_packet_template_get_packet (vm, |
| 1942 | &im->discover_neighbor_packet_template, |
| 1943 | &bi); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1944 | |
| 1945 | hi = vnet_get_sup_hw_interface (vnm, sw_if_index); |
| 1946 | |
| 1947 | /* Destination address is a solicited node multicast address. We need to fill in |
| 1948 | the low 24 bits with low 24 bits of target's address. */ |
| 1949 | h->ip.dst_address.as_u8[13] = dst->as_u8[13]; |
| 1950 | h->ip.dst_address.as_u8[14] = dst->as_u8[14]; |
| 1951 | h->ip.dst_address.as_u8[15] = dst->as_u8[15]; |
| 1952 | |
| 1953 | h->ip.src_address = src[0]; |
| 1954 | h->neighbor.target_address = dst[0]; |
| 1955 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1956 | clib_memcpy (h->link_layer_option.ethernet_address, hi->hw_address, |
| 1957 | vec_len (hi->hw_address)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1958 | |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 1959 | h->neighbor.icmp.checksum = |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1960 | ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h->ip, &bogus_length); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1961 | ASSERT (bogus_length == 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1962 | |
| 1963 | b = vlib_get_buffer (vm, bi); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1964 | vnet_buffer (b)->sw_if_index[VLIB_RX] = |
| 1965 | vnet_buffer (b)->sw_if_index[VLIB_TX] = sw_if_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1966 | |
| 1967 | /* Add encapsulation string for software interface (e.g. ethernet header). */ |
| 1968 | adj = ip_get_adjacency (&im->lookup_main, ia->neighbor_probe_adj_index); |
| 1969 | vnet_rewrite_one_header (adj[0], h, sizeof (ethernet_header_t)); |
| 1970 | vlib_buffer_advance (b, -adj->rewrite_header.data_bytes); |
| 1971 | |
| 1972 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1973 | vlib_frame_t *f = vlib_get_frame_to_node (vm, hi->output_node_index); |
| 1974 | u32 *to_next = vlib_frame_vector_args (f); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1975 | to_next[0] = bi; |
| 1976 | f->n_vectors = 1; |
| 1977 | vlib_put_frame_to_node (vm, hi->output_node_index, f); |
| 1978 | } |
| 1979 | |
| 1980 | return /* no error */ 0; |
| 1981 | } |
| 1982 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1983 | typedef enum |
| 1984 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1985 | IP6_REWRITE_NEXT_DROP, |
Chris Luke | 816f3e1 | 2016-06-14 16:24:47 -0400 | [diff] [blame] | 1986 | IP6_REWRITE_NEXT_ICMP_ERROR, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1987 | } ip6_rewrite_next_t; |
| 1988 | |
| 1989 | always_inline uword |
| 1990 | ip6_rewrite_inline (vlib_main_t * vm, |
| 1991 | vlib_node_runtime_t * node, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1992 | vlib_frame_t * frame, int is_midchain, int is_mcast) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1993 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1994 | ip_lookup_main_t *lm = &ip6_main.lookup_main; |
| 1995 | u32 *from = vlib_frame_vector_args (frame); |
| 1996 | u32 n_left_from, n_left_to_next, *to_next, next_index; |
| 1997 | vlib_node_runtime_t *error_node = |
| 1998 | vlib_node_get_runtime (vm, ip6_input_node.index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1999 | |
| 2000 | n_left_from = frame->n_vectors; |
| 2001 | next_index = node->cached_next_index; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2002 | u32 cpu_index = os_get_cpu_number (); |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 2003 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2004 | while (n_left_from > 0) |
| 2005 | { |
| 2006 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
| 2007 | |
| 2008 | while (n_left_from >= 4 && n_left_to_next >= 2) |
| 2009 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2010 | ip_adjacency_t *adj0, *adj1; |
| 2011 | vlib_buffer_t *p0, *p1; |
| 2012 | ip6_header_t *ip0, *ip1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2013 | u32 pi0, rw_len0, next0, error0, adj_index0; |
| 2014 | u32 pi1, rw_len1, next1, error1, adj_index1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2015 | u32 tx_sw_if_index0, tx_sw_if_index1; |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 2016 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2017 | /* Prefetch next iteration. */ |
| 2018 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2019 | vlib_buffer_t *p2, *p3; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2020 | |
| 2021 | p2 = vlib_get_buffer (vm, from[2]); |
| 2022 | p3 = vlib_get_buffer (vm, from[3]); |
| 2023 | |
| 2024 | vlib_prefetch_buffer_header (p2, LOAD); |
| 2025 | vlib_prefetch_buffer_header (p3, LOAD); |
| 2026 | |
| 2027 | CLIB_PREFETCH (p2->pre_data, 32, STORE); |
| 2028 | CLIB_PREFETCH (p3->pre_data, 32, STORE); |
| 2029 | |
| 2030 | CLIB_PREFETCH (p2->data, sizeof (ip0[0]), STORE); |
| 2031 | CLIB_PREFETCH (p3->data, sizeof (ip0[0]), STORE); |
| 2032 | } |
| 2033 | |
| 2034 | pi0 = to_next[0] = from[0]; |
| 2035 | pi1 = to_next[1] = from[1]; |
| 2036 | |
| 2037 | from += 2; |
| 2038 | n_left_from -= 2; |
| 2039 | to_next += 2; |
| 2040 | n_left_to_next -= 2; |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 2041 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2042 | p0 = vlib_get_buffer (vm, pi0); |
| 2043 | p1 = vlib_get_buffer (vm, pi1); |
| 2044 | |
Neale Ranns | f06aea5 | 2016-11-29 06:51:37 -0800 | [diff] [blame] | 2045 | adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX]; |
| 2046 | adj_index1 = vnet_buffer (p1)->ip.adj_index[VLIB_TX]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2047 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2048 | /* We should never rewrite a pkt using the MISS adjacency */ |
| 2049 | ASSERT (adj_index0 && adj_index1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2050 | |
| 2051 | ip0 = vlib_buffer_get_current (p0); |
| 2052 | ip1 = vlib_buffer_get_current (p1); |
| 2053 | |
| 2054 | error0 = error1 = IP6_ERROR_NONE; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2055 | next0 = next1 = IP6_REWRITE_NEXT_DROP; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2056 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2057 | if (PREDICT_TRUE (!(p0->flags & VNET_BUFFER_LOCALLY_ORIGINATED))) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2058 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2059 | i32 hop_limit0 = ip0->hop_limit; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2060 | |
| 2061 | /* Input node should have reject packets with hop limit 0. */ |
| 2062 | ASSERT (ip0->hop_limit > 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2063 | |
| 2064 | hop_limit0 -= 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2065 | |
| 2066 | ip0->hop_limit = hop_limit0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2067 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2068 | /* |
| 2069 | * If the hop count drops below 1 when forwarding, generate |
| 2070 | * an ICMP response. |
| 2071 | */ |
| 2072 | if (PREDICT_FALSE (hop_limit0 <= 0)) |
| 2073 | { |
| 2074 | error0 = IP6_ERROR_TIME_EXPIRED; |
| 2075 | next0 = IP6_REWRITE_NEXT_ICMP_ERROR; |
| 2076 | vnet_buffer (p0)->sw_if_index[VLIB_TX] = (u32) ~ 0; |
| 2077 | icmp6_error_set_vnet_buffer (p0, ICMP6_time_exceeded, |
| 2078 | ICMP6_time_exceeded_ttl_exceeded_in_transit, |
| 2079 | 0); |
| 2080 | } |
Neale Ranns | f06aea5 | 2016-11-29 06:51:37 -0800 | [diff] [blame] | 2081 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2082 | else |
| 2083 | { |
| 2084 | p0->flags &= ~VNET_BUFFER_LOCALLY_ORIGINATED; |
| 2085 | } |
| 2086 | if (PREDICT_TRUE (!(p1->flags & VNET_BUFFER_LOCALLY_ORIGINATED))) |
| 2087 | { |
Neale Ranns | f06aea5 | 2016-11-29 06:51:37 -0800 | [diff] [blame] | 2088 | i32 hop_limit1 = ip1->hop_limit; |
| 2089 | |
| 2090 | /* Input node should have reject packets with hop limit 0. */ |
| 2091 | ASSERT (ip1->hop_limit > 0); |
| 2092 | |
| 2093 | hop_limit1 -= 1; |
| 2094 | |
| 2095 | ip1->hop_limit = hop_limit1; |
| 2096 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2097 | /* |
| 2098 | * If the hop count drops below 1 when forwarding, generate |
| 2099 | * an ICMP response. |
| 2100 | */ |
| 2101 | if (PREDICT_FALSE (hop_limit1 <= 0)) |
| 2102 | { |
| 2103 | error1 = IP6_ERROR_TIME_EXPIRED; |
| 2104 | next1 = IP6_REWRITE_NEXT_ICMP_ERROR; |
| 2105 | vnet_buffer (p1)->sw_if_index[VLIB_TX] = (u32) ~ 0; |
| 2106 | icmp6_error_set_vnet_buffer (p1, ICMP6_time_exceeded, |
| 2107 | ICMP6_time_exceeded_ttl_exceeded_in_transit, |
| 2108 | 0); |
| 2109 | } |
| 2110 | } |
| 2111 | else |
| 2112 | { |
| 2113 | p1->flags &= ~VNET_BUFFER_LOCALLY_ORIGINATED; |
| 2114 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2115 | adj0 = ip_get_adjacency (lm, adj_index0); |
| 2116 | adj1 = ip_get_adjacency (lm, adj_index1); |
| 2117 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2118 | rw_len0 = adj0[0].rewrite_header.data_bytes; |
| 2119 | rw_len1 = adj1[0].rewrite_header.data_bytes; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2120 | vnet_buffer (p0)->ip.save_rewrite_length = rw_len0; |
| 2121 | vnet_buffer (p1)->ip.save_rewrite_length = rw_len1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2122 | |
Neale Ranns | 044183f | 2017-01-24 01:34:25 -0800 | [diff] [blame] | 2123 | vlib_increment_combined_counter |
| 2124 | (&adjacency_counters, |
| 2125 | cpu_index, |
| 2126 | adj_index0, 1, vlib_buffer_length_in_chain (vm, p0) + rw_len0); |
| 2127 | vlib_increment_combined_counter |
| 2128 | (&adjacency_counters, |
| 2129 | cpu_index, adj_index1, |
| 2130 | 1, vlib_buffer_length_in_chain (vm, p1) + rw_len1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2131 | |
| 2132 | /* Check MTU of outgoing interface. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2133 | error0 = |
| 2134 | (vlib_buffer_length_in_chain (vm, p0) > |
| 2135 | adj0[0]. |
| 2136 | rewrite_header.max_l3_packet_bytes ? IP6_ERROR_MTU_EXCEEDED : |
| 2137 | error0); |
| 2138 | error1 = |
| 2139 | (vlib_buffer_length_in_chain (vm, p1) > |
| 2140 | adj1[0]. |
| 2141 | rewrite_header.max_l3_packet_bytes ? IP6_ERROR_MTU_EXCEEDED : |
| 2142 | error1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2143 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2144 | /* Don't adjust the buffer for hop count issue; icmp-error node |
| 2145 | * wants to see the IP headerr */ |
| 2146 | if (PREDICT_TRUE (error0 == IP6_ERROR_NONE)) |
| 2147 | { |
| 2148 | p0->current_data -= rw_len0; |
| 2149 | p0->current_length += rw_len0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2150 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2151 | tx_sw_if_index0 = adj0[0].rewrite_header.sw_if_index; |
| 2152 | vnet_buffer (p0)->sw_if_index[VLIB_TX] = tx_sw_if_index0; |
| 2153 | next0 = adj0[0].rewrite_header.next_index; |
Dave Barach | 5331c72 | 2016-08-17 11:54:30 -0400 | [diff] [blame] | 2154 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2155 | vnet_feature_arc_start (lm->output_feature_arc_index, |
| 2156 | tx_sw_if_index0, &next0, p0); |
| 2157 | } |
| 2158 | if (PREDICT_TRUE (error1 == IP6_ERROR_NONE)) |
| 2159 | { |
| 2160 | p1->current_data -= rw_len1; |
| 2161 | p1->current_length += rw_len1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2162 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2163 | tx_sw_if_index1 = adj1[0].rewrite_header.sw_if_index; |
| 2164 | vnet_buffer (p1)->sw_if_index[VLIB_TX] = tx_sw_if_index1; |
| 2165 | next1 = adj1[0].rewrite_header.next_index; |
Dave Barach | 5331c72 | 2016-08-17 11:54:30 -0400 | [diff] [blame] | 2166 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2167 | vnet_feature_arc_start (lm->output_feature_arc_index, |
| 2168 | tx_sw_if_index1, &next1, p1); |
| 2169 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2170 | |
| 2171 | /* Guess we are only writing on simple Ethernet header. */ |
| 2172 | vnet_rewrite_two_headers (adj0[0], adj1[0], |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2173 | ip0, ip1, sizeof (ethernet_header_t)); |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 2174 | |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 2175 | if (is_midchain) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2176 | { |
| 2177 | adj0->sub_type.midchain.fixup_func (vm, adj0, p0); |
| 2178 | adj1->sub_type.midchain.fixup_func (vm, adj1, p1); |
| 2179 | } |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2180 | if (is_mcast) |
| 2181 | { |
| 2182 | /* |
| 2183 | * copy bytes from the IP address into the MAC rewrite |
| 2184 | */ |
| 2185 | vnet_fixup_one_header (adj0[0], &ip0->dst_address, ip0, 0); |
| 2186 | vnet_fixup_one_header (adj1[0], &ip1->dst_address, ip1, 0); |
| 2187 | } |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 2188 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2189 | vlib_validate_buffer_enqueue_x2 (vm, node, next_index, |
| 2190 | to_next, n_left_to_next, |
| 2191 | pi0, pi1, next0, next1); |
| 2192 | } |
| 2193 | |
| 2194 | while (n_left_from > 0 && n_left_to_next > 0) |
| 2195 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2196 | ip_adjacency_t *adj0; |
| 2197 | vlib_buffer_t *p0; |
| 2198 | ip6_header_t *ip0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2199 | u32 pi0, rw_len0; |
| 2200 | u32 adj_index0, next0, error0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2201 | u32 tx_sw_if_index0; |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 2202 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2203 | pi0 = to_next[0] = from[0]; |
| 2204 | |
| 2205 | p0 = vlib_get_buffer (vm, pi0); |
| 2206 | |
Neale Ranns | f06aea5 | 2016-11-29 06:51:37 -0800 | [diff] [blame] | 2207 | adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2208 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2209 | /* We should never rewrite a pkt using the MISS adjacency */ |
| 2210 | ASSERT (adj_index0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2211 | |
| 2212 | adj0 = ip_get_adjacency (lm, adj_index0); |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 2213 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2214 | ip0 = vlib_buffer_get_current (p0); |
| 2215 | |
| 2216 | error0 = IP6_ERROR_NONE; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2217 | next0 = IP6_REWRITE_NEXT_DROP; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2218 | |
| 2219 | /* Check hop limit */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2220 | if (PREDICT_TRUE (!(p0->flags & VNET_BUFFER_LOCALLY_ORIGINATED))) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2221 | { |
| 2222 | i32 hop_limit0 = ip0->hop_limit; |
| 2223 | |
| 2224 | ASSERT (ip0->hop_limit > 0); |
| 2225 | |
| 2226 | hop_limit0 -= 1; |
| 2227 | |
| 2228 | ip0->hop_limit = hop_limit0; |
| 2229 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2230 | if (PREDICT_FALSE (hop_limit0 <= 0)) |
| 2231 | { |
| 2232 | /* |
| 2233 | * If the hop count drops below 1 when forwarding, generate |
| 2234 | * an ICMP response. |
| 2235 | */ |
| 2236 | error0 = IP6_ERROR_TIME_EXPIRED; |
| 2237 | next0 = IP6_REWRITE_NEXT_ICMP_ERROR; |
| 2238 | vnet_buffer (p0)->sw_if_index[VLIB_TX] = (u32) ~ 0; |
| 2239 | icmp6_error_set_vnet_buffer (p0, ICMP6_time_exceeded, |
| 2240 | ICMP6_time_exceeded_ttl_exceeded_in_transit, |
| 2241 | 0); |
| 2242 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2243 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2244 | else |
| 2245 | { |
| 2246 | p0->flags &= ~VNET_BUFFER_LOCALLY_ORIGINATED; |
| 2247 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2248 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2249 | /* Guess we are only writing on simple Ethernet header. */ |
| 2250 | vnet_rewrite_one_header (adj0[0], ip0, sizeof (ethernet_header_t)); |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 2251 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2252 | /* Update packet buffer attributes/set output interface. */ |
| 2253 | rw_len0 = adj0[0].rewrite_header.data_bytes; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2254 | vnet_buffer (p0)->ip.save_rewrite_length = rw_len0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2255 | |
Neale Ranns | 044183f | 2017-01-24 01:34:25 -0800 | [diff] [blame] | 2256 | vlib_increment_combined_counter |
| 2257 | (&adjacency_counters, |
| 2258 | cpu_index, |
| 2259 | adj_index0, 1, vlib_buffer_length_in_chain (vm, p0) + rw_len0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2260 | |
| 2261 | /* Check MTU of outgoing interface. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2262 | error0 = |
| 2263 | (vlib_buffer_length_in_chain (vm, p0) > |
| 2264 | adj0[0]. |
| 2265 | rewrite_header.max_l3_packet_bytes ? IP6_ERROR_MTU_EXCEEDED : |
| 2266 | error0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2267 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2268 | /* Don't adjust the buffer for hop count issue; icmp-error node |
| 2269 | * wants to see the IP headerr */ |
| 2270 | if (PREDICT_TRUE (error0 == IP6_ERROR_NONE)) |
| 2271 | { |
Chris Luke | 816f3e1 | 2016-06-14 16:24:47 -0400 | [diff] [blame] | 2272 | p0->current_data -= rw_len0; |
| 2273 | p0->current_length += rw_len0; |
| 2274 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2275 | tx_sw_if_index0 = adj0[0].rewrite_header.sw_if_index; |
Dave Barach | 5331c72 | 2016-08-17 11:54:30 -0400 | [diff] [blame] | 2276 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2277 | vnet_buffer (p0)->sw_if_index[VLIB_TX] = tx_sw_if_index0; |
| 2278 | next0 = adj0[0].rewrite_header.next_index; |
Dave Barach | 5331c72 | 2016-08-17 11:54:30 -0400 | [diff] [blame] | 2279 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2280 | vnet_feature_arc_start (lm->output_feature_arc_index, |
| 2281 | tx_sw_if_index0, &next0, p0); |
| 2282 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2283 | |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 2284 | if (is_midchain) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2285 | { |
| 2286 | adj0->sub_type.midchain.fixup_func (vm, adj0, p0); |
| 2287 | } |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2288 | if (is_mcast) |
| 2289 | { |
| 2290 | vnet_fixup_one_header (adj0[0], &ip0->dst_address, ip0, 0); |
| 2291 | } |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 2292 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2293 | p0->error = error_node->errors[error0]; |
| 2294 | |
| 2295 | from += 1; |
| 2296 | n_left_from -= 1; |
| 2297 | to_next += 1; |
| 2298 | n_left_to_next -= 1; |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 2299 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2300 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 2301 | to_next, n_left_to_next, |
| 2302 | pi0, next0); |
| 2303 | } |
| 2304 | |
| 2305 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 2306 | } |
| 2307 | |
| 2308 | /* Need to do trace after rewrites to pick up new packet data. */ |
| 2309 | if (node->flags & VLIB_NODE_FLAG_TRACE) |
Neale Ranns | f06aea5 | 2016-11-29 06:51:37 -0800 | [diff] [blame] | 2310 | ip6_forward_next_trace (vm, node, frame, VLIB_TX); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2311 | |
| 2312 | return frame->n_vectors; |
| 2313 | } |
| 2314 | |
| 2315 | static uword |
Neale Ranns | f06aea5 | 2016-11-29 06:51:37 -0800 | [diff] [blame] | 2316 | ip6_rewrite (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2317 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2318 | { |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2319 | return ip6_rewrite_inline (vm, node, frame, 0, 0); |
| 2320 | } |
| 2321 | |
| 2322 | static uword |
| 2323 | ip6_rewrite_mcast (vlib_main_t * vm, |
| 2324 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
| 2325 | { |
| 2326 | return ip6_rewrite_inline (vm, node, frame, 0, 1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2327 | } |
| 2328 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2329 | static uword |
| 2330 | ip6_midchain (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2331 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2332 | { |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2333 | return ip6_rewrite_inline (vm, node, frame, 1, 0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2334 | } |
| 2335 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2336 | /* *INDENT-OFF* */ |
| 2337 | VLIB_REGISTER_NODE (ip6_midchain_node) = |
| 2338 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2339 | .function = ip6_midchain, |
| 2340 | .name = "ip6-midchain", |
| 2341 | .vector_size = sizeof (u32), |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2342 | .format_trace = format_ip6_forward_next_trace, |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 2343 | .sibling_of = "ip6-rewrite", |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2344 | }; |
| 2345 | /* *INDENT-ON* */ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2346 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2347 | VLIB_NODE_FUNCTION_MULTIARCH (ip6_midchain_node, ip6_midchain); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2348 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2349 | /* *INDENT-OFF* */ |
| 2350 | VLIB_REGISTER_NODE (ip6_rewrite_node) = |
| 2351 | { |
Neale Ranns | f06aea5 | 2016-11-29 06:51:37 -0800 | [diff] [blame] | 2352 | .function = ip6_rewrite, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2353 | .name = "ip6-rewrite", |
| 2354 | .vector_size = sizeof (u32), |
Pierre Pfister | a38c3df | 2016-06-13 10:28:09 +0100 | [diff] [blame] | 2355 | .format_trace = format_ip6_rewrite_trace, |
Chris Luke | 816f3e1 | 2016-06-14 16:24:47 -0400 | [diff] [blame] | 2356 | .n_next_nodes = 2, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2357 | .next_nodes = |
| 2358 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2359 | [IP6_REWRITE_NEXT_DROP] = "error-drop", |
Chris Luke | 816f3e1 | 2016-06-14 16:24:47 -0400 | [diff] [blame] | 2360 | [IP6_REWRITE_NEXT_ICMP_ERROR] = "ip6-icmp-error", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2361 | }, |
| 2362 | }; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2363 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2364 | |
Neale Ranns | f06aea5 | 2016-11-29 06:51:37 -0800 | [diff] [blame] | 2365 | VLIB_NODE_FUNCTION_MULTIARCH (ip6_rewrite_node, ip6_rewrite); |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 2366 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2367 | /* *INDENT-OFF* */ |
| 2368 | VLIB_REGISTER_NODE (ip6_rewrite_mcast_node) = |
| 2369 | { |
| 2370 | .function = ip6_rewrite_mcast, |
| 2371 | .name = "ip6-rewrite-mcast", |
| 2372 | .vector_size = sizeof (u32), |
| 2373 | .format_trace = format_ip6_rewrite_trace, |
| 2374 | .sibling_of = "ip6-rewrite", |
| 2375 | }; |
| 2376 | /* *INDENT-ON* */ |
| 2377 | |
| 2378 | VLIB_NODE_FUNCTION_MULTIARCH (ip6_rewrite_mcast_node, ip6_rewrite_mcast); |
| 2379 | |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2380 | /* |
| 2381 | * Hop-by-Hop handling |
| 2382 | */ |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2383 | ip6_hop_by_hop_main_t ip6_hop_by_hop_main; |
| 2384 | |
| 2385 | #define foreach_ip6_hop_by_hop_error \ |
| 2386 | _(PROCESSED, "pkts with ip6 hop-by-hop options") \ |
| 2387 | _(FORMAT, "incorrectly formatted hop-by-hop options") \ |
| 2388 | _(UNKNOWN_OPTION, "unknown ip6 hop-by-hop options") |
| 2389 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2390 | /* *INDENT-OFF* */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2391 | typedef enum |
| 2392 | { |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2393 | #define _(sym,str) IP6_HOP_BY_HOP_ERROR_##sym, |
| 2394 | foreach_ip6_hop_by_hop_error |
| 2395 | #undef _ |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2396 | IP6_HOP_BY_HOP_N_ERROR, |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2397 | } ip6_hop_by_hop_error_t; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2398 | /* *INDENT-ON* */ |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2399 | |
| 2400 | /* |
| 2401 | * Primary h-b-h handler trace support |
| 2402 | * We work pretty hard on the problem for obvious reasons |
| 2403 | */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2404 | typedef struct |
| 2405 | { |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2406 | u32 next_index; |
| 2407 | u32 trace_len; |
| 2408 | u8 option_data[256]; |
| 2409 | } ip6_hop_by_hop_trace_t; |
| 2410 | |
| 2411 | vlib_node_registration_t ip6_hop_by_hop_node; |
| 2412 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2413 | static char *ip6_hop_by_hop_error_strings[] = { |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2414 | #define _(sym,string) string, |
| 2415 | foreach_ip6_hop_by_hop_error |
| 2416 | #undef _ |
| 2417 | }; |
| 2418 | |
| 2419 | static u8 * |
| 2420 | format_ip6_hop_by_hop_trace (u8 * s, va_list * args) |
| 2421 | { |
| 2422 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 2423 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2424 | ip6_hop_by_hop_trace_t *t = va_arg (*args, ip6_hop_by_hop_trace_t *); |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2425 | ip6_hop_by_hop_header_t *hbh0; |
| 2426 | ip6_hop_by_hop_option_t *opt0, *limit0; |
| 2427 | ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main; |
| 2428 | |
| 2429 | u8 type0; |
| 2430 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2431 | hbh0 = (ip6_hop_by_hop_header_t *) t->option_data; |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2432 | |
| 2433 | s = format (s, "IP6_HOP_BY_HOP: next index %d len %d traced %d", |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2434 | t->next_index, (hbh0->length + 1) << 3, t->trace_len); |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2435 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2436 | opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1); |
| 2437 | limit0 = (ip6_hop_by_hop_option_t *) ((u8 *) hbh0) + t->trace_len; |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2438 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2439 | while (opt0 < limit0) |
| 2440 | { |
| 2441 | type0 = opt0->type; |
| 2442 | switch (type0) |
| 2443 | { |
| 2444 | case 0: /* Pad, just stop */ |
| 2445 | opt0 = (ip6_hop_by_hop_option_t *) ((u8 *) opt0) + 1; |
| 2446 | break; |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2447 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2448 | default: |
| 2449 | if (hm->trace[type0]) |
| 2450 | { |
| 2451 | s = (*hm->trace[type0]) (s, opt0); |
| 2452 | } |
| 2453 | else |
| 2454 | { |
| 2455 | s = |
| 2456 | format (s, "\n unrecognized option %d length %d", type0, |
| 2457 | opt0->length); |
| 2458 | } |
| 2459 | opt0 = |
| 2460 | (ip6_hop_by_hop_option_t *) (((u8 *) opt0) + opt0->length + |
| 2461 | sizeof (ip6_hop_by_hop_option_t)); |
| 2462 | break; |
| 2463 | } |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2464 | } |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2465 | return s; |
| 2466 | } |
| 2467 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2468 | always_inline u8 |
| 2469 | ip6_scan_hbh_options (vlib_buffer_t * b0, |
| 2470 | ip6_header_t * ip0, |
| 2471 | ip6_hop_by_hop_header_t * hbh0, |
| 2472 | ip6_hop_by_hop_option_t * opt0, |
| 2473 | ip6_hop_by_hop_option_t * limit0, u32 * next0) |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2474 | { |
| 2475 | ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main; |
| 2476 | u8 type0; |
| 2477 | u8 error0 = 0; |
| 2478 | |
| 2479 | while (opt0 < limit0) |
| 2480 | { |
| 2481 | type0 = opt0->type; |
| 2482 | switch (type0) |
| 2483 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2484 | case 0: /* Pad1 */ |
| 2485 | opt0 = (ip6_hop_by_hop_option_t *) ((u8 *) opt0) + 1; |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2486 | continue; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2487 | case 1: /* PadN */ |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2488 | break; |
| 2489 | default: |
| 2490 | if (hm->options[type0]) |
| 2491 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2492 | if ((*hm->options[type0]) (b0, ip0, opt0) < 0) |
| 2493 | { |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2494 | error0 = IP6_HOP_BY_HOP_ERROR_FORMAT; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2495 | return (error0); |
| 2496 | } |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2497 | } |
| 2498 | else |
| 2499 | { |
| 2500 | /* Unrecognized mandatory option, check the two high order bits */ |
| 2501 | switch (opt0->type & HBH_OPTION_TYPE_HIGH_ORDER_BITS) |
| 2502 | { |
| 2503 | case HBH_OPTION_TYPE_SKIP_UNKNOWN: |
| 2504 | break; |
| 2505 | case HBH_OPTION_TYPE_DISCARD_UNKNOWN: |
| 2506 | error0 = IP6_HOP_BY_HOP_ERROR_UNKNOWN_OPTION; |
| 2507 | *next0 = IP_LOOKUP_NEXT_DROP; |
| 2508 | break; |
| 2509 | case HBH_OPTION_TYPE_DISCARD_UNKNOWN_ICMP: |
| 2510 | error0 = IP6_HOP_BY_HOP_ERROR_UNKNOWN_OPTION; |
| 2511 | *next0 = IP_LOOKUP_NEXT_ICMP_ERROR; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2512 | icmp6_error_set_vnet_buffer (b0, ICMP6_parameter_problem, |
| 2513 | ICMP6_parameter_problem_unrecognized_option, |
| 2514 | (u8 *) opt0 - (u8 *) ip0); |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2515 | break; |
| 2516 | case HBH_OPTION_TYPE_DISCARD_UNKNOWN_ICMP_NOT_MCAST: |
| 2517 | error0 = IP6_HOP_BY_HOP_ERROR_UNKNOWN_OPTION; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2518 | if (!ip6_address_is_multicast (&ip0->dst_address)) |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2519 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2520 | *next0 = IP_LOOKUP_NEXT_ICMP_ERROR; |
| 2521 | icmp6_error_set_vnet_buffer (b0, |
| 2522 | ICMP6_parameter_problem, |
| 2523 | ICMP6_parameter_problem_unrecognized_option, |
| 2524 | (u8 *) opt0 - (u8 *) ip0); |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2525 | } |
| 2526 | else |
| 2527 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2528 | *next0 = IP_LOOKUP_NEXT_DROP; |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2529 | } |
| 2530 | break; |
| 2531 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2532 | return (error0); |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2533 | } |
| 2534 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2535 | opt0 = |
| 2536 | (ip6_hop_by_hop_option_t *) (((u8 *) opt0) + opt0->length + |
| 2537 | sizeof (ip6_hop_by_hop_option_t)); |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2538 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2539 | return (error0); |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2540 | } |
| 2541 | |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2542 | /* |
| 2543 | * Process the Hop-by-Hop Options header |
| 2544 | */ |
| 2545 | static uword |
| 2546 | ip6_hop_by_hop (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2547 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2548 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2549 | vlib_node_runtime_t *error_node = |
| 2550 | vlib_node_get_runtime (vm, ip6_hop_by_hop_node.index); |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2551 | ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main; |
| 2552 | u32 n_left_from, *from, *to_next; |
| 2553 | ip_lookup_next_t next_index; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2554 | ip6_main_t *im = &ip6_main; |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2555 | ip_lookup_main_t *lm = &im->lookup_main; |
| 2556 | |
| 2557 | from = vlib_frame_vector_args (frame); |
| 2558 | n_left_from = frame->n_vectors; |
| 2559 | next_index = node->cached_next_index; |
| 2560 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2561 | while (n_left_from > 0) |
| 2562 | { |
| 2563 | u32 n_left_to_next; |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2564 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2565 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2566 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2567 | while (n_left_from >= 4 && n_left_to_next >= 2) |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2568 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2569 | u32 bi0, bi1; |
| 2570 | vlib_buffer_t *b0, *b1; |
| 2571 | u32 next0, next1; |
| 2572 | ip6_header_t *ip0, *ip1; |
| 2573 | ip6_hop_by_hop_header_t *hbh0, *hbh1; |
| 2574 | ip6_hop_by_hop_option_t *opt0, *limit0, *opt1, *limit1; |
| 2575 | u8 error0 = 0, error1 = 0; |
| 2576 | |
| 2577 | /* Prefetch next iteration. */ |
| 2578 | { |
| 2579 | vlib_buffer_t *p2, *p3; |
| 2580 | |
| 2581 | p2 = vlib_get_buffer (vm, from[2]); |
| 2582 | p3 = vlib_get_buffer (vm, from[3]); |
| 2583 | |
| 2584 | vlib_prefetch_buffer_header (p2, LOAD); |
| 2585 | vlib_prefetch_buffer_header (p3, LOAD); |
| 2586 | |
| 2587 | CLIB_PREFETCH (p2->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD); |
| 2588 | CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD); |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2589 | } |
| 2590 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2591 | /* Speculatively enqueue b0, b1 to the current next frame */ |
| 2592 | to_next[0] = bi0 = from[0]; |
| 2593 | to_next[1] = bi1 = from[1]; |
| 2594 | from += 2; |
| 2595 | to_next += 2; |
| 2596 | n_left_from -= 2; |
| 2597 | n_left_to_next -= 2; |
| 2598 | |
| 2599 | b0 = vlib_get_buffer (vm, bi0); |
| 2600 | b1 = vlib_get_buffer (vm, bi1); |
| 2601 | |
| 2602 | /* Default use the next_index from the adjacency. A HBH option rarely redirects to a different node */ |
| 2603 | u32 adj_index0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX]; |
| 2604 | ip_adjacency_t *adj0 = ip_get_adjacency (lm, adj_index0); |
| 2605 | u32 adj_index1 = vnet_buffer (b1)->ip.adj_index[VLIB_TX]; |
| 2606 | ip_adjacency_t *adj1 = ip_get_adjacency (lm, adj_index1); |
| 2607 | |
| 2608 | /* Default use the next_index from the adjacency. A HBH option rarely redirects to a different node */ |
| 2609 | next0 = adj0->lookup_next_index; |
| 2610 | next1 = adj1->lookup_next_index; |
| 2611 | |
| 2612 | ip0 = vlib_buffer_get_current (b0); |
| 2613 | ip1 = vlib_buffer_get_current (b1); |
| 2614 | hbh0 = (ip6_hop_by_hop_header_t *) (ip0 + 1); |
| 2615 | hbh1 = (ip6_hop_by_hop_header_t *) (ip1 + 1); |
| 2616 | opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1); |
| 2617 | opt1 = (ip6_hop_by_hop_option_t *) (hbh1 + 1); |
| 2618 | limit0 = |
| 2619 | (ip6_hop_by_hop_option_t *) ((u8 *) hbh0 + |
| 2620 | ((hbh0->length + 1) << 3)); |
| 2621 | limit1 = |
| 2622 | (ip6_hop_by_hop_option_t *) ((u8 *) hbh1 + |
| 2623 | ((hbh1->length + 1) << 3)); |
| 2624 | |
| 2625 | /* |
| 2626 | * Basic validity checks |
| 2627 | */ |
| 2628 | if ((hbh0->length + 1) << 3 > |
| 2629 | clib_net_to_host_u16 (ip0->payload_length)) |
| 2630 | { |
| 2631 | error0 = IP6_HOP_BY_HOP_ERROR_FORMAT; |
| 2632 | next0 = IP_LOOKUP_NEXT_DROP; |
| 2633 | goto outdual; |
| 2634 | } |
| 2635 | /* Scan the set of h-b-h options, process ones that we understand */ |
| 2636 | error0 = ip6_scan_hbh_options (b0, ip0, hbh0, opt0, limit0, &next0); |
| 2637 | |
| 2638 | if ((hbh1->length + 1) << 3 > |
| 2639 | clib_net_to_host_u16 (ip1->payload_length)) |
| 2640 | { |
| 2641 | error1 = IP6_HOP_BY_HOP_ERROR_FORMAT; |
| 2642 | next1 = IP_LOOKUP_NEXT_DROP; |
| 2643 | goto outdual; |
| 2644 | } |
| 2645 | /* Scan the set of h-b-h options, process ones that we understand */ |
| 2646 | error1 = ip6_scan_hbh_options (b1, ip1, hbh1, opt1, limit1, &next1); |
| 2647 | |
| 2648 | outdual: |
| 2649 | /* Has the classifier flagged this buffer for special treatment? */ |
| 2650 | if (PREDICT_FALSE |
| 2651 | ((error0 == 0) |
| 2652 | && (vnet_buffer (b0)->l2_classify.opaque_index & OI_DECAP))) |
| 2653 | next0 = hm->next_override; |
| 2654 | |
| 2655 | /* Has the classifier flagged this buffer for special treatment? */ |
| 2656 | if (PREDICT_FALSE |
| 2657 | ((error1 == 0) |
| 2658 | && (vnet_buffer (b1)->l2_classify.opaque_index & OI_DECAP))) |
| 2659 | next1 = hm->next_override; |
| 2660 | |
| 2661 | if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE))) |
| 2662 | { |
| 2663 | if (b0->flags & VLIB_BUFFER_IS_TRACED) |
| 2664 | { |
| 2665 | ip6_hop_by_hop_trace_t *t = |
| 2666 | vlib_add_trace (vm, node, b0, sizeof (*t)); |
| 2667 | u32 trace_len = (hbh0->length + 1) << 3; |
| 2668 | t->next_index = next0; |
| 2669 | /* Capture the h-b-h option verbatim */ |
| 2670 | trace_len = |
| 2671 | trace_len < |
| 2672 | ARRAY_LEN (t->option_data) ? trace_len : |
| 2673 | ARRAY_LEN (t->option_data); |
| 2674 | t->trace_len = trace_len; |
| 2675 | clib_memcpy (t->option_data, hbh0, trace_len); |
| 2676 | } |
| 2677 | if (b1->flags & VLIB_BUFFER_IS_TRACED) |
| 2678 | { |
| 2679 | ip6_hop_by_hop_trace_t *t = |
| 2680 | vlib_add_trace (vm, node, b1, sizeof (*t)); |
| 2681 | u32 trace_len = (hbh1->length + 1) << 3; |
| 2682 | t->next_index = next1; |
| 2683 | /* Capture the h-b-h option verbatim */ |
| 2684 | trace_len = |
| 2685 | trace_len < |
| 2686 | ARRAY_LEN (t->option_data) ? trace_len : |
| 2687 | ARRAY_LEN (t->option_data); |
| 2688 | t->trace_len = trace_len; |
| 2689 | clib_memcpy (t->option_data, hbh1, trace_len); |
| 2690 | } |
| 2691 | |
| 2692 | } |
| 2693 | |
| 2694 | b0->error = error_node->errors[error0]; |
| 2695 | b1->error = error_node->errors[error1]; |
| 2696 | |
| 2697 | /* verify speculative enqueue, maybe switch current next frame */ |
| 2698 | vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next, |
| 2699 | n_left_to_next, bi0, bi1, next0, |
| 2700 | next1); |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2701 | } |
| 2702 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2703 | while (n_left_from > 0 && n_left_to_next > 0) |
| 2704 | { |
| 2705 | u32 bi0; |
| 2706 | vlib_buffer_t *b0; |
| 2707 | u32 next0; |
| 2708 | ip6_header_t *ip0; |
| 2709 | ip6_hop_by_hop_header_t *hbh0; |
| 2710 | ip6_hop_by_hop_option_t *opt0, *limit0; |
| 2711 | u8 error0 = 0; |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2712 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2713 | /* Speculatively enqueue b0 to the current next frame */ |
| 2714 | bi0 = from[0]; |
| 2715 | to_next[0] = bi0; |
| 2716 | from += 1; |
| 2717 | to_next += 1; |
| 2718 | n_left_from -= 1; |
| 2719 | n_left_to_next -= 1; |
| 2720 | |
| 2721 | b0 = vlib_get_buffer (vm, bi0); |
| 2722 | /* |
| 2723 | * Default use the next_index from the adjacency. |
| 2724 | * A HBH option rarely redirects to a different node |
| 2725 | */ |
| 2726 | u32 adj_index0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX]; |
| 2727 | ip_adjacency_t *adj0 = ip_get_adjacency (lm, adj_index0); |
| 2728 | next0 = adj0->lookup_next_index; |
| 2729 | |
| 2730 | ip0 = vlib_buffer_get_current (b0); |
| 2731 | hbh0 = (ip6_hop_by_hop_header_t *) (ip0 + 1); |
| 2732 | opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1); |
| 2733 | limit0 = |
| 2734 | (ip6_hop_by_hop_option_t *) ((u8 *) hbh0 + |
| 2735 | ((hbh0->length + 1) << 3)); |
| 2736 | |
| 2737 | /* |
| 2738 | * Basic validity checks |
| 2739 | */ |
| 2740 | if ((hbh0->length + 1) << 3 > |
| 2741 | clib_net_to_host_u16 (ip0->payload_length)) |
| 2742 | { |
| 2743 | error0 = IP6_HOP_BY_HOP_ERROR_FORMAT; |
| 2744 | next0 = IP_LOOKUP_NEXT_DROP; |
| 2745 | goto out0; |
| 2746 | } |
| 2747 | |
| 2748 | /* Scan the set of h-b-h options, process ones that we understand */ |
| 2749 | error0 = ip6_scan_hbh_options (b0, ip0, hbh0, opt0, limit0, &next0); |
| 2750 | |
| 2751 | out0: |
| 2752 | /* Has the classifier flagged this buffer for special treatment? */ |
| 2753 | if (PREDICT_FALSE |
| 2754 | ((error0 == 0) |
| 2755 | && (vnet_buffer (b0)->l2_classify.opaque_index & OI_DECAP))) |
| 2756 | next0 = hm->next_override; |
| 2757 | |
| 2758 | if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 2759 | { |
| 2760 | ip6_hop_by_hop_trace_t *t = |
| 2761 | vlib_add_trace (vm, node, b0, sizeof (*t)); |
| 2762 | u32 trace_len = (hbh0->length + 1) << 3; |
| 2763 | t->next_index = next0; |
| 2764 | /* Capture the h-b-h option verbatim */ |
| 2765 | trace_len = |
| 2766 | trace_len < |
| 2767 | ARRAY_LEN (t->option_data) ? trace_len : |
| 2768 | ARRAY_LEN (t->option_data); |
| 2769 | t->trace_len = trace_len; |
| 2770 | clib_memcpy (t->option_data, hbh0, trace_len); |
| 2771 | } |
| 2772 | |
| 2773 | b0->error = error_node->errors[error0]; |
| 2774 | |
| 2775 | /* verify speculative enqueue, maybe switch current next frame */ |
| 2776 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, |
| 2777 | n_left_to_next, bi0, next0); |
| 2778 | } |
| 2779 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2780 | } |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2781 | return frame->n_vectors; |
| 2782 | } |
| 2783 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2784 | /* *INDENT-OFF* */ |
| 2785 | VLIB_REGISTER_NODE (ip6_hop_by_hop_node) = |
| 2786 | { |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2787 | .function = ip6_hop_by_hop, |
| 2788 | .name = "ip6-hop-by-hop", |
Ole Troan | 964f93e | 2016-06-10 13:22:36 +0200 | [diff] [blame] | 2789 | .sibling_of = "ip6-lookup", |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2790 | .vector_size = sizeof (u32), |
| 2791 | .format_trace = format_ip6_hop_by_hop_trace, |
| 2792 | .type = VLIB_NODE_TYPE_INTERNAL, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2793 | .n_errors = ARRAY_LEN (ip6_hop_by_hop_error_strings), |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2794 | .error_strings = ip6_hop_by_hop_error_strings, |
Ole Troan | 964f93e | 2016-06-10 13:22:36 +0200 | [diff] [blame] | 2795 | .n_next_nodes = 0, |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2796 | }; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2797 | /* *INDENT-ON* */ |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2798 | |
Dave Barach | 5331c72 | 2016-08-17 11:54:30 -0400 | [diff] [blame] | 2799 | VLIB_NODE_FUNCTION_MULTIARCH (ip6_hop_by_hop_node, ip6_hop_by_hop); |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2800 | |
| 2801 | static clib_error_t * |
| 2802 | ip6_hop_by_hop_init (vlib_main_t * vm) |
| 2803 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2804 | ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main; |
| 2805 | memset (hm->options, 0, sizeof (hm->options)); |
| 2806 | memset (hm->trace, 0, sizeof (hm->trace)); |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2807 | hm->next_override = IP6_LOOKUP_NEXT_POP_HOP_BY_HOP; |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2808 | return (0); |
| 2809 | } |
| 2810 | |
| 2811 | VLIB_INIT_FUNCTION (ip6_hop_by_hop_init); |
| 2812 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2813 | void |
| 2814 | ip6_hbh_set_next_override (uword next) |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2815 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2816 | ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main; |
Shwetha | a91cbe6 | 2016-08-08 15:51:04 +0100 | [diff] [blame] | 2817 | |
| 2818 | hm->next_override = next; |
| 2819 | } |
| 2820 | |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2821 | int |
| 2822 | ip6_hbh_register_option (u8 option, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2823 | int options (vlib_buffer_t * b, ip6_header_t * ip, |
| 2824 | ip6_hop_by_hop_option_t * opt), |
| 2825 | u8 * trace (u8 * s, ip6_hop_by_hop_option_t * opt)) |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2826 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2827 | ip6_main_t *im = &ip6_main; |
| 2828 | ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main; |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2829 | |
| 2830 | ASSERT (option < ARRAY_LEN (hm->options)); |
| 2831 | |
| 2832 | /* Already registered */ |
| 2833 | if (hm->options[option]) |
| 2834 | return (-1); |
| 2835 | |
| 2836 | hm->options[option] = options; |
| 2837 | hm->trace[option] = trace; |
| 2838 | |
| 2839 | /* Set global variable */ |
| 2840 | im->hbh_enabled = 1; |
| 2841 | |
| 2842 | return (0); |
| 2843 | } |
| 2844 | |
| 2845 | int |
| 2846 | ip6_hbh_unregister_option (u8 option) |
| 2847 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2848 | ip6_main_t *im = &ip6_main; |
| 2849 | ip6_hop_by_hop_main_t *hm = &ip6_hop_by_hop_main; |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2850 | |
| 2851 | ASSERT (option < ARRAY_LEN (hm->options)); |
| 2852 | |
| 2853 | /* Not registered */ |
| 2854 | if (!hm->options[option]) |
| 2855 | return (-1); |
| 2856 | |
| 2857 | hm->options[option] = NULL; |
| 2858 | hm->trace[option] = NULL; |
| 2859 | |
| 2860 | /* Disable global knob if this was the last option configured */ |
| 2861 | int i; |
| 2862 | bool found = false; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2863 | for (i = 0; i < 256; i++) |
| 2864 | { |
| 2865 | if (hm->options[option]) |
| 2866 | { |
| 2867 | found = true; |
| 2868 | break; |
| 2869 | } |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2870 | } |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2871 | if (!found) |
| 2872 | im->hbh_enabled = 0; |
| 2873 | |
| 2874 | return (0); |
| 2875 | } |
| 2876 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2877 | /* Global IP6 main. */ |
| 2878 | ip6_main_t ip6_main; |
| 2879 | |
| 2880 | static clib_error_t * |
| 2881 | ip6_lookup_init (vlib_main_t * vm) |
| 2882 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2883 | ip6_main_t *im = &ip6_main; |
| 2884 | clib_error_t *error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2885 | uword i; |
| 2886 | |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 2887 | if ((error = vlib_call_init_function (vm, vnet_feature_init))) |
| 2888 | return error; |
| 2889 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2890 | for (i = 0; i < ARRAY_LEN (im->fib_masks); i++) |
| 2891 | { |
| 2892 | u32 j, i0, i1; |
| 2893 | |
| 2894 | i0 = i / 32; |
| 2895 | i1 = i % 32; |
| 2896 | |
| 2897 | for (j = 0; j < i0; j++) |
| 2898 | im->fib_masks[i].as_u32[j] = ~0; |
| 2899 | |
| 2900 | if (i1) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2901 | im->fib_masks[i].as_u32[i0] = |
| 2902 | clib_host_to_net_u32 (pow2_mask (i1) << (32 - i1)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2903 | } |
| 2904 | |
| 2905 | ip_lookup_init (&im->lookup_main, /* is_ip6 */ 1); |
| 2906 | |
| 2907 | if (im->lookup_table_nbuckets == 0) |
| 2908 | im->lookup_table_nbuckets = IP6_FIB_DEFAULT_HASH_NUM_BUCKETS; |
| 2909 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2910 | im->lookup_table_nbuckets = 1 << max_log2 (im->lookup_table_nbuckets); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2911 | |
| 2912 | if (im->lookup_table_size == 0) |
| 2913 | im->lookup_table_size = IP6_FIB_DEFAULT_HASH_MEMORY_SIZE; |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 2914 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2915 | BV (clib_bihash_init) (&(im->ip6_table[IP6_FIB_TABLE_FWDING].ip6_hash), |
| 2916 | "ip6 FIB fwding table", |
| 2917 | im->lookup_table_nbuckets, im->lookup_table_size); |
| 2918 | BV (clib_bihash_init) (&im->ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash, |
| 2919 | "ip6 FIB non-fwding table", |
| 2920 | im->lookup_table_nbuckets, im->lookup_table_size); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2921 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2922 | /* Create FIB with index 0 and table id of 0. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2923 | fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6, 0); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2924 | mfib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2925 | |
| 2926 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2927 | pg_node_t *pn; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2928 | pn = pg_get_node (ip6_lookup_node.index); |
| 2929 | pn->unformat_edit = unformat_pg_ip6_header; |
| 2930 | } |
| 2931 | |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 2932 | /* Unless explicitly configured, don't process HBH options */ |
| 2933 | im->hbh_enabled = 0; |
| 2934 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2935 | { |
| 2936 | icmp6_neighbor_solicitation_header_t p; |
| 2937 | |
| 2938 | memset (&p, 0, sizeof (p)); |
| 2939 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2940 | p.ip.ip_version_traffic_class_and_flow_label = |
| 2941 | clib_host_to_net_u32 (0x6 << 28); |
| 2942 | p.ip.payload_length = |
| 2943 | clib_host_to_net_u16 (sizeof (p) - |
| 2944 | STRUCT_OFFSET_OF |
| 2945 | (icmp6_neighbor_solicitation_header_t, neighbor)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2946 | p.ip.protocol = IP_PROTOCOL_ICMP6; |
| 2947 | p.ip.hop_limit = 255; |
| 2948 | ip6_set_solicited_node_multicast_address (&p.ip.dst_address, 0); |
| 2949 | |
| 2950 | p.neighbor.icmp.type = ICMP6_neighbor_solicitation; |
| 2951 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2952 | p.link_layer_option.header.type = |
| 2953 | ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address; |
| 2954 | p.link_layer_option.header.n_data_u64s = |
| 2955 | sizeof (p.link_layer_option) / sizeof (u64); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2956 | |
| 2957 | vlib_packet_template_init (vm, |
| 2958 | &im->discover_neighbor_packet_template, |
| 2959 | &p, sizeof (p), |
| 2960 | /* alloc chunk size */ 8, |
| 2961 | "ip6 neighbor discovery"); |
| 2962 | } |
| 2963 | |
Dave Barach | 203c632 | 2016-06-26 10:29:03 -0400 | [diff] [blame] | 2964 | return error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2965 | } |
| 2966 | |
| 2967 | VLIB_INIT_FUNCTION (ip6_lookup_init); |
| 2968 | |
| 2969 | static clib_error_t * |
| 2970 | add_del_ip6_interface_table (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2971 | unformat_input_t * input, |
| 2972 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2973 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2974 | vnet_main_t *vnm = vnet_get_main (); |
| 2975 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2976 | u32 sw_if_index, table_id; |
| 2977 | |
| 2978 | sw_if_index = ~0; |
| 2979 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2980 | if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2981 | { |
| 2982 | error = clib_error_return (0, "unknown interface `%U'", |
| 2983 | format_unformat_error, input); |
| 2984 | goto done; |
| 2985 | } |
| 2986 | |
| 2987 | if (unformat (input, "%d", &table_id)) |
| 2988 | ; |
| 2989 | else |
| 2990 | { |
| 2991 | error = clib_error_return (0, "expected table id `%U'", |
| 2992 | format_unformat_error, input); |
| 2993 | goto done; |
| 2994 | } |
| 2995 | |
| 2996 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2997 | u32 fib_index = fib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6, |
| 2998 | table_id); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2999 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3000 | vec_validate (ip6_main.fib_index_by_sw_if_index, sw_if_index); |
| 3001 | ip6_main.fib_index_by_sw_if_index[sw_if_index] = fib_index; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 3002 | |
| 3003 | fib_index = mfib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6, |
| 3004 | table_id); |
| 3005 | |
| 3006 | vec_validate (ip6_main.mfib_index_by_sw_if_index, sw_if_index); |
| 3007 | ip6_main.mfib_index_by_sw_if_index[sw_if_index] = fib_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3008 | } |
| 3009 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3010 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3011 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3012 | return error; |
| 3013 | } |
| 3014 | |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3015 | /*? |
| 3016 | * Place the indicated interface into the supplied IPv6 FIB table (also known |
| 3017 | * as a VRF). If the FIB table does not exist, this command creates it. To |
| 3018 | * display the current IPv6 FIB table, use the command '<em>show ip6 fib</em>'. |
| 3019 | * FIB table will only be displayed if a route has been added to the table, or |
| 3020 | * an IP Address is assigned to an interface in the table (which adds a route |
| 3021 | * automatically). |
| 3022 | * |
| 3023 | * @note IP addresses added after setting the interface IP table end up in |
| 3024 | * the indicated FIB table. If the IP address is added prior to adding the |
| 3025 | * interface to the FIB table, it will NOT be part of the FIB table. Predictable |
| 3026 | * but potentially counter-intuitive results occur if you provision interface |
| 3027 | * addresses in multiple FIBs. Upon RX, packets will be processed in the last |
| 3028 | * IP table ID provisioned. It might be marginally useful to evade source RPF |
| 3029 | * drops to put an interface address into multiple FIBs. |
| 3030 | * |
| 3031 | * @cliexpar |
| 3032 | * Example of how to add an interface to an IPv6 FIB table (where 2 is the table-id): |
| 3033 | * @cliexcmd{set interface ip6 table GigabitEthernet2/0/0 2} |
| 3034 | ?*/ |
| 3035 | /* *INDENT-OFF* */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3036 | VLIB_CLI_COMMAND (set_interface_ip6_table_command, static) = |
| 3037 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3038 | .path = "set interface ip6 table", |
| 3039 | .function = add_del_ip6_interface_table, |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3040 | .short_help = "set interface ip6 table <interface> <table-id>" |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3041 | }; |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3042 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3043 | |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 3044 | void |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3045 | ip6_link_local_address_from_ethernet_mac_address (ip6_address_t * ip, |
| 3046 | u8 * mac) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3047 | { |
| 3048 | ip->as_u64[0] = clib_host_to_net_u64 (0xFE80000000000000ULL); |
| 3049 | /* Invert the "u" bit */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3050 | ip->as_u8[8] = mac[0] ^ (1 << 1); |
| 3051 | ip->as_u8[9] = mac[1]; |
| 3052 | ip->as_u8[10] = mac[2]; |
| 3053 | ip->as_u8[11] = 0xFF; |
| 3054 | ip->as_u8[12] = 0xFE; |
| 3055 | ip->as_u8[13] = mac[3]; |
| 3056 | ip->as_u8[14] = mac[4]; |
| 3057 | ip->as_u8[15] = mac[5]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3058 | } |
| 3059 | |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 3060 | void |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3061 | ip6_ethernet_mac_address_from_link_local_address (u8 * mac, |
| 3062 | ip6_address_t * ip) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3063 | { |
| 3064 | /* Invert the previously inverted "u" bit */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3065 | mac[0] = ip->as_u8[8] ^ (1 << 1); |
| 3066 | mac[1] = ip->as_u8[9]; |
| 3067 | mac[2] = ip->as_u8[10]; |
| 3068 | mac[3] = ip->as_u8[13]; |
| 3069 | mac[4] = ip->as_u8[14]; |
| 3070 | mac[5] = ip->as_u8[15]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3071 | } |
| 3072 | |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 3073 | static clib_error_t * |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3074 | test_ip6_link_command_fn (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3075 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3076 | { |
| 3077 | u8 mac[6]; |
| 3078 | ip6_address_t _a, *a = &_a; |
| 3079 | |
| 3080 | if (unformat (input, "%U", unformat_ethernet_address, mac)) |
| 3081 | { |
| 3082 | ip6_link_local_address_from_ethernet_mac_address (a, mac); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3083 | vlib_cli_output (vm, "Link local address: %U", format_ip6_address, a); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3084 | ip6_ethernet_mac_address_from_link_local_address (mac, a); |
| 3085 | vlib_cli_output (vm, "Original MAC address: %U", |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3086 | format_ethernet_address, mac); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3087 | } |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 3088 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3089 | return 0; |
| 3090 | } |
| 3091 | |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3092 | /*? |
| 3093 | * This command converts the given MAC Address into an IPv6 link-local |
| 3094 | * address. |
| 3095 | * |
| 3096 | * @cliexpar |
| 3097 | * Example of how to create an IPv6 link-local address: |
| 3098 | * @cliexstart{test ip6 link 16:d9:e0:91:79:86} |
| 3099 | * Link local address: fe80::14d9:e0ff:fe91:7986 |
| 3100 | * Original MAC address: 16:d9:e0:91:79:86 |
| 3101 | * @cliexend |
| 3102 | ?*/ |
| 3103 | /* *INDENT-OFF* */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3104 | VLIB_CLI_COMMAND (test_link_command, static) = |
| 3105 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3106 | .path = "test ip6 link", |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 3107 | .function = test_ip6_link_command_fn, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3108 | .short_help = "test ip6 link <mac-address>", |
| 3109 | }; |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3110 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3111 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3112 | int |
| 3113 | vnet_set_ip6_flow_hash (u32 table_id, u32 flow_hash_config) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3114 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3115 | ip6_main_t *im6 = &ip6_main; |
| 3116 | ip6_fib_t *fib; |
| 3117 | uword *p = hash_get (im6->fib_index_by_table_id, table_id); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3118 | |
| 3119 | if (p == 0) |
| 3120 | return -1; |
| 3121 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3122 | fib = ip6_fib_get (p[0]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3123 | |
| 3124 | fib->flow_hash_config = flow_hash_config; |
| 3125 | return 1; |
| 3126 | } |
| 3127 | |
| 3128 | static clib_error_t * |
| 3129 | set_ip6_flow_hash_command_fn (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3130 | unformat_input_t * input, |
| 3131 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3132 | { |
| 3133 | int matched = 0; |
| 3134 | u32 table_id = 0; |
| 3135 | u32 flow_hash_config = 0; |
| 3136 | int rv; |
| 3137 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3138 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 3139 | { |
| 3140 | if (unformat (input, "table %d", &table_id)) |
| 3141 | matched = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3142 | #define _(a,v) \ |
| 3143 | else if (unformat (input, #a)) { flow_hash_config |= v; matched=1;} |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3144 | foreach_flow_hash_bit |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3145 | #undef _ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3146 | else |
| 3147 | break; |
| 3148 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3149 | |
| 3150 | if (matched == 0) |
| 3151 | return clib_error_return (0, "unknown input `%U'", |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3152 | format_unformat_error, input); |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 3153 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3154 | rv = vnet_set_ip6_flow_hash (table_id, flow_hash_config); |
| 3155 | switch (rv) |
| 3156 | { |
| 3157 | case 1: |
| 3158 | break; |
| 3159 | |
| 3160 | case -1: |
| 3161 | return clib_error_return (0, "no such FIB table %d", table_id); |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 3162 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3163 | default: |
| 3164 | clib_warning ("BUG: illegal flow hash config 0x%x", flow_hash_config); |
| 3165 | break; |
| 3166 | } |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 3167 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3168 | return 0; |
| 3169 | } |
| 3170 | |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3171 | /*? |
| 3172 | * Configure the set of IPv6 fields used by the flow hash. |
| 3173 | * |
| 3174 | * @cliexpar |
| 3175 | * @parblock |
| 3176 | * Example of how to set the flow hash on a given table: |
Billy McFall | ebb9a6a | 2016-10-17 11:35:32 -0400 | [diff] [blame] | 3177 | * @cliexcmd{set ip6 flow-hash table 8 dst sport dport proto} |
| 3178 | * |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3179 | * Example of display the configured flow hash: |
| 3180 | * @cliexstart{show ip6 fib} |
Billy McFall | ebb9a6a | 2016-10-17 11:35:32 -0400 | [diff] [blame] | 3181 | * ipv6-VRF:0, fib_index 0, flow hash: src dst sport dport proto |
| 3182 | * @::/0 |
| 3183 | * unicast-ip6-chain |
| 3184 | * [@0]: dpo-load-balance: [index:5 buckets:1 uRPF:5 to:[0:0]] |
| 3185 | * [0] [@0]: dpo-drop ip6 |
| 3186 | * fe80::/10 |
| 3187 | * unicast-ip6-chain |
| 3188 | * [@0]: dpo-load-balance: [index:10 buckets:1 uRPF:10 to:[0:0]] |
| 3189 | * [0] [@2]: dpo-receive |
| 3190 | * ff02::1/128 |
| 3191 | * unicast-ip6-chain |
| 3192 | * [@0]: dpo-load-balance: [index:8 buckets:1 uRPF:8 to:[0:0]] |
| 3193 | * [0] [@2]: dpo-receive |
| 3194 | * ff02::2/128 |
| 3195 | * unicast-ip6-chain |
| 3196 | * [@0]: dpo-load-balance: [index:7 buckets:1 uRPF:7 to:[0:0]] |
| 3197 | * [0] [@2]: dpo-receive |
| 3198 | * ff02::16/128 |
| 3199 | * unicast-ip6-chain |
| 3200 | * [@0]: dpo-load-balance: [index:9 buckets:1 uRPF:9 to:[0:0]] |
| 3201 | * [0] [@2]: dpo-receive |
| 3202 | * ff02::1:ff00:0/104 |
| 3203 | * unicast-ip6-chain |
| 3204 | * [@0]: dpo-load-balance: [index:6 buckets:1 uRPF:6 to:[0:0]] |
| 3205 | * [0] [@2]: dpo-receive |
| 3206 | * ipv6-VRF:8, fib_index 1, flow hash: dst sport dport proto |
| 3207 | * @::/0 |
| 3208 | * unicast-ip6-chain |
| 3209 | * [@0]: dpo-load-balance: [index:21 buckets:1 uRPF:20 to:[0:0]] |
| 3210 | * [0] [@0]: dpo-drop ip6 |
| 3211 | * @::a:1:1:0:4/126 |
| 3212 | * unicast-ip6-chain |
| 3213 | * [@0]: dpo-load-balance: [index:27 buckets:1 uRPF:26 to:[0:0]] |
| 3214 | * [0] [@4]: ipv6-glean: af_packet0 |
| 3215 | * @::a:1:1:0:7/128 |
| 3216 | * unicast-ip6-chain |
| 3217 | * [@0]: dpo-load-balance: [index:28 buckets:1 uRPF:27 to:[0:0]] |
| 3218 | * [0] [@2]: dpo-receive: @::a:1:1:0:7 on af_packet0 |
| 3219 | * fe80::/10 |
| 3220 | * unicast-ip6-chain |
| 3221 | * [@0]: dpo-load-balance: [index:26 buckets:1 uRPF:25 to:[0:0]] |
| 3222 | * [0] [@2]: dpo-receive |
| 3223 | * fe80::fe:3eff:fe3e:9222/128 |
| 3224 | * unicast-ip6-chain |
| 3225 | * [@0]: dpo-load-balance: [index:29 buckets:1 uRPF:28 to:[0:0]] |
| 3226 | * [0] [@2]: dpo-receive: fe80::fe:3eff:fe3e:9222 on af_packet0 |
| 3227 | * ff02::1/128 |
| 3228 | * unicast-ip6-chain |
| 3229 | * [@0]: dpo-load-balance: [index:24 buckets:1 uRPF:23 to:[0:0]] |
| 3230 | * [0] [@2]: dpo-receive |
| 3231 | * ff02::2/128 |
| 3232 | * unicast-ip6-chain |
| 3233 | * [@0]: dpo-load-balance: [index:23 buckets:1 uRPF:22 to:[0:0]] |
| 3234 | * [0] [@2]: dpo-receive |
| 3235 | * ff02::16/128 |
| 3236 | * unicast-ip6-chain |
| 3237 | * [@0]: dpo-load-balance: [index:25 buckets:1 uRPF:24 to:[0:0]] |
| 3238 | * [0] [@2]: dpo-receive |
| 3239 | * ff02::1:ff00:0/104 |
| 3240 | * unicast-ip6-chain |
| 3241 | * [@0]: dpo-load-balance: [index:22 buckets:1 uRPF:21 to:[0:0]] |
| 3242 | * [0] [@2]: dpo-receive |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3243 | * @cliexend |
| 3244 | * @endparblock |
| 3245 | ?*/ |
| 3246 | /* *INDENT-OFF* */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3247 | VLIB_CLI_COMMAND (set_ip6_flow_hash_command, static) = |
| 3248 | { |
| 3249 | .path = "set ip6 flow-hash", |
| 3250 | .short_help = |
| 3251 | "set ip6 flow-hash table <table-id> [src] [dst] [sport] [dport] [proto] [reverse]", |
| 3252 | .function = set_ip6_flow_hash_command_fn, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3253 | }; |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3254 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3255 | |
| 3256 | static clib_error_t * |
| 3257 | show_ip6_local_command_fn (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3258 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3259 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3260 | ip6_main_t *im = &ip6_main; |
| 3261 | ip_lookup_main_t *lm = &im->lookup_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3262 | int i; |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 3263 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3264 | vlib_cli_output (vm, "Protocols handled by ip6_local"); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3265 | for (i = 0; i < ARRAY_LEN (lm->local_next_by_ip_protocol); i++) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3266 | { |
| 3267 | if (lm->local_next_by_ip_protocol[i] != IP_LOCAL_NEXT_PUNT) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3268 | vlib_cli_output (vm, "%d", i); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3269 | } |
| 3270 | return 0; |
| 3271 | } |
| 3272 | |
| 3273 | |
| 3274 | |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3275 | /*? |
| 3276 | * Display the set of protocols handled by the local IPv6 stack. |
| 3277 | * |
| 3278 | * @cliexpar |
| 3279 | * Example of how to display local protocol table: |
| 3280 | * @cliexstart{show ip6 local} |
| 3281 | * Protocols handled by ip6_local |
| 3282 | * 17 |
| 3283 | * 43 |
| 3284 | * 58 |
| 3285 | * 115 |
| 3286 | * @cliexend |
| 3287 | ?*/ |
| 3288 | /* *INDENT-OFF* */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3289 | VLIB_CLI_COMMAND (show_ip6_local, static) = |
| 3290 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3291 | .path = "show ip6 local", |
| 3292 | .function = show_ip6_local_command_fn, |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3293 | .short_help = "show ip6 local", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3294 | }; |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3295 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3296 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3297 | int |
| 3298 | vnet_set_ip6_classify_intfc (vlib_main_t * vm, u32 sw_if_index, |
| 3299 | u32 table_index) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3300 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3301 | vnet_main_t *vnm = vnet_get_main (); |
| 3302 | vnet_interface_main_t *im = &vnm->interface_main; |
| 3303 | ip6_main_t *ipm = &ip6_main; |
| 3304 | ip_lookup_main_t *lm = &ipm->lookup_main; |
| 3305 | vnet_classify_main_t *cm = &vnet_classify_main; |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 3306 | ip6_address_t *if_addr; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3307 | |
| 3308 | if (pool_is_free_index (im->sw_interfaces, sw_if_index)) |
| 3309 | return VNET_API_ERROR_NO_MATCHING_INTERFACE; |
| 3310 | |
| 3311 | if (table_index != ~0 && pool_is_free_index (cm->tables, table_index)) |
| 3312 | return VNET_API_ERROR_NO_SUCH_ENTRY; |
| 3313 | |
| 3314 | vec_validate (lm->classify_table_index_by_sw_if_index, sw_if_index); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3315 | lm->classify_table_index_by_sw_if_index[sw_if_index] = table_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3316 | |
Neale Ranns | 6cfc39c | 2017-02-14 01:44:25 -0800 | [diff] [blame] | 3317 | if_addr = ip6_interface_first_address (ipm, sw_if_index); |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 3318 | |
| 3319 | if (NULL != if_addr) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3320 | { |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 3321 | fib_prefix_t pfx = { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3322 | .fp_len = 128, |
| 3323 | .fp_proto = FIB_PROTOCOL_IP6, |
| 3324 | .fp_addr.ip6 = *if_addr, |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 3325 | }; |
| 3326 | u32 fib_index; |
| 3327 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3328 | fib_index = fib_table_get_index_for_sw_if_index (FIB_PROTOCOL_IP4, |
| 3329 | sw_if_index); |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 3330 | |
| 3331 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3332 | if (table_index != (u32) ~ 0) |
| 3333 | { |
| 3334 | dpo_id_t dpo = DPO_INVALID; |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 3335 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3336 | dpo_set (&dpo, |
| 3337 | DPO_CLASSIFY, |
| 3338 | DPO_PROTO_IP6, |
| 3339 | classify_dpo_create (DPO_PROTO_IP6, table_index)); |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 3340 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3341 | fib_table_entry_special_dpo_add (fib_index, |
| 3342 | &pfx, |
| 3343 | FIB_SOURCE_CLASSIFY, |
| 3344 | FIB_ENTRY_FLAG_NONE, &dpo); |
| 3345 | dpo_reset (&dpo); |
| 3346 | } |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 3347 | else |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3348 | { |
| 3349 | fib_table_entry_special_remove (fib_index, |
| 3350 | &pfx, FIB_SOURCE_CLASSIFY); |
| 3351 | } |
| 3352 | } |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 3353 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3354 | return 0; |
| 3355 | } |
| 3356 | |
| 3357 | static clib_error_t * |
| 3358 | set_ip6_classify_command_fn (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3359 | unformat_input_t * input, |
| 3360 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3361 | { |
| 3362 | u32 table_index = ~0; |
| 3363 | int table_index_set = 0; |
| 3364 | u32 sw_if_index = ~0; |
| 3365 | int rv; |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 3366 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3367 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 3368 | { |
| 3369 | if (unformat (input, "table-index %d", &table_index)) |
| 3370 | table_index_set = 1; |
| 3371 | else if (unformat (input, "intfc %U", unformat_vnet_sw_interface, |
| 3372 | vnet_get_main (), &sw_if_index)) |
| 3373 | ; |
| 3374 | else |
| 3375 | break; |
| 3376 | } |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 3377 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3378 | if (table_index_set == 0) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3379 | return clib_error_return (0, "classify table-index must be specified"); |
Dave Barach | 75fc854 | 2016-10-11 16:16:02 -0400 | [diff] [blame] | 3380 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3381 | if (sw_if_index == ~0) |
| 3382 | return clib_error_return (0, "interface / subif must be specified"); |
| 3383 | |
| 3384 | rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index); |
| 3385 | |
| 3386 | switch (rv) |
| 3387 | { |
| 3388 | case 0: |
| 3389 | break; |
| 3390 | |
| 3391 | case VNET_API_ERROR_NO_MATCHING_INTERFACE: |
| 3392 | return clib_error_return (0, "No such interface"); |
| 3393 | |
| 3394 | case VNET_API_ERROR_NO_SUCH_ENTRY: |
| 3395 | return clib_error_return (0, "No such classifier table"); |
| 3396 | } |
| 3397 | return 0; |
| 3398 | } |
| 3399 | |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3400 | /*? |
| 3401 | * Assign a classification table to an interface. The classification |
| 3402 | * table is created using the '<em>classify table</em>' and '<em>classify session</em>' |
| 3403 | * commands. Once the table is create, use this command to filter packets |
| 3404 | * on an interface. |
| 3405 | * |
| 3406 | * @cliexpar |
| 3407 | * Example of how to assign a classification table to an interface: |
| 3408 | * @cliexcmd{set ip6 classify intfc GigabitEthernet2/0/0 table-index 1} |
| 3409 | ?*/ |
| 3410 | /* *INDENT-OFF* */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3411 | VLIB_CLI_COMMAND (set_ip6_classify_command, static) = |
| 3412 | { |
| 3413 | .path = "set ip6 classify", |
| 3414 | .short_help = |
| 3415 | "set ip6 classify intfc <interface> table-index <classify-idx>", |
| 3416 | .function = set_ip6_classify_command_fn, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3417 | }; |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3418 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3419 | |
| 3420 | static clib_error_t * |
| 3421 | ip6_config (vlib_main_t * vm, unformat_input_t * input) |
| 3422 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3423 | ip6_main_t *im = &ip6_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3424 | uword heapsize = 0; |
| 3425 | u32 tmp; |
| 3426 | u32 nbuckets = 0; |
| 3427 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3428 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 3429 | { |
| 3430 | if (unformat (input, "hash-buckets %d", &tmp)) |
| 3431 | nbuckets = tmp; |
| 3432 | else if (unformat (input, "heap-size %dm", &tmp)) |
| 3433 | heapsize = ((u64) tmp) << 20; |
| 3434 | else if (unformat (input, "heap-size %dM", &tmp)) |
| 3435 | heapsize = ((u64) tmp) << 20; |
| 3436 | else if (unformat (input, "heap-size %dg", &tmp)) |
| 3437 | heapsize = ((u64) tmp) << 30; |
| 3438 | else if (unformat (input, "heap-size %dG", &tmp)) |
| 3439 | heapsize = ((u64) tmp) << 30; |
| 3440 | else |
| 3441 | return clib_error_return (0, "unknown input '%U'", |
| 3442 | format_unformat_error, input); |
| 3443 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3444 | |
| 3445 | im->lookup_table_nbuckets = nbuckets; |
| 3446 | im->lookup_table_size = heapsize; |
| 3447 | |
| 3448 | return 0; |
| 3449 | } |
| 3450 | |
| 3451 | VLIB_EARLY_CONFIG_FUNCTION (ip6_config, "ip6"); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3452 | |
| 3453 | /* |
| 3454 | * fd.io coding-style-patch-verification: ON |
| 3455 | * |
| 3456 | * Local Variables: |
| 3457 | * eval: (c-set-style "gnu") |
| 3458 | * End: |
| 3459 | */ |