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