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