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