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