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