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