Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ip/ip6_neighbor.c: IP6 neighbor handling |
| 3 | * |
| 4 | * Copyright (c) 2010 Cisco and/or its affiliates. |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #include <vnet/ip/ip.h> |
Pavel Kotucek | 3e046ea | 2016-12-05 08:27:37 +0100 | [diff] [blame] | 19 | #include <vnet/ip/ip6_neighbor.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 20 | #include <vnet/ethernet/ethernet.h> |
| 21 | #include <vppinfra/mhash.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 22 | #include <vnet/adj/adj.h> |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 23 | #include <vnet/adj/adj_mcast.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 24 | #include <vnet/fib/fib_table.h> |
| 25 | #include <vnet/fib/ip6_fib.h> |
Neale Ranns | 4008ac9 | 2017-02-13 23:20:04 -0800 | [diff] [blame] | 26 | #include <vnet/mfib/ip6_mfib.h> |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 27 | #include <vnet/ip/ip6_ll_table.h> |
Neale Ranns | 3b81a1e | 2018-09-06 09:50:26 -0700 | [diff] [blame] | 28 | #include <vnet/l2/l2_input.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 29 | |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 30 | /** |
| 31 | * @file |
| 32 | * @brief IPv6 Neighbor Adjacency and Neighbor Discovery. |
| 33 | * |
| 34 | * The files contains the API and CLI code for managing IPv6 neighbor |
| 35 | * adjacency tables and neighbor discovery logic. |
| 36 | */ |
| 37 | |
Pavel Kotucek | 3e046ea | 2016-12-05 08:27:37 +0100 | [diff] [blame] | 38 | /* can't use sizeof link_layer_address, that's 8 */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 39 | #define ETHER_MAC_ADDR_LEN 6 |
| 40 | |
Pavel Kotucek | 3e046ea | 2016-12-05 08:27:37 +0100 | [diff] [blame] | 41 | /* advertised prefix option */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 42 | typedef struct |
| 43 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 44 | /* basic advertised information */ |
| 45 | ip6_address_t prefix; |
| 46 | u8 prefix_len; |
| 47 | int adv_on_link_flag; |
| 48 | int adv_autonomous_flag; |
| 49 | u32 adv_valid_lifetime_in_secs; |
| 50 | u32 adv_pref_lifetime_in_secs; |
| 51 | |
| 52 | /* advertised values are computed from these times if decrementing */ |
| 53 | f64 valid_lifetime_expires; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 54 | f64 pref_lifetime_expires; |
| 55 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 56 | /* local information */ |
| 57 | int enabled; |
| 58 | int deprecated_prefix_flag; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 59 | int decrement_lifetime_flag; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 60 | |
| 61 | #define MIN_ADV_VALID_LIFETIME 7203 /* seconds */ |
| 62 | #define DEF_ADV_VALID_LIFETIME 2592000 |
| 63 | #define DEF_ADV_PREF_LIFETIME 604800 |
| 64 | |
| 65 | /* extensions are added here, mobile, DNS etc.. */ |
| 66 | } ip6_radv_prefix_t; |
| 67 | |
| 68 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 69 | typedef struct |
| 70 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 71 | /* group information */ |
| 72 | u8 type; |
| 73 | ip6_address_t mcast_address; |
| 74 | u16 num_sources; |
| 75 | ip6_address_t *mcast_source_address_pool; |
| 76 | } ip6_mldp_group_t; |
| 77 | |
| 78 | /* configured router advertisement information per ipv6 interface */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 79 | typedef struct |
| 80 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 81 | |
| 82 | /* advertised config information, zero means unspecified */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 83 | u8 curr_hop_limit; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 84 | int adv_managed_flag; |
| 85 | int adv_other_flag; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 86 | u16 adv_router_lifetime_in_sec; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 87 | u32 adv_neighbor_reachable_time_in_msec; |
| 88 | u32 adv_time_in_msec_between_retransmitted_neighbor_solicitations; |
| 89 | |
| 90 | /* mtu option */ |
| 91 | u32 adv_link_mtu; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 92 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 93 | /* source link layer option */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 94 | u8 link_layer_address[8]; |
| 95 | u8 link_layer_addr_len; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 96 | |
| 97 | /* prefix option */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 98 | ip6_radv_prefix_t *adv_prefixes_pool; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 99 | |
| 100 | /* Hash table mapping address to index in interface advertised prefix pool. */ |
| 101 | mhash_t address_to_prefix_index; |
| 102 | |
| 103 | /* MLDP group information */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 104 | ip6_mldp_group_t *mldp_group_pool; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 105 | |
| 106 | /* Hash table mapping address to index in mldp address pool. */ |
| 107 | mhash_t address_to_mldp_index; |
| 108 | |
| 109 | /* local information */ |
| 110 | u32 sw_if_index; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 111 | int send_radv; /* radv on/off on this interface - set by config */ |
| 112 | int cease_radv; /* we are ceasing to send - set byf config */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 113 | int send_unicast; |
| 114 | int adv_link_layer_address; |
| 115 | int prefix_option; |
| 116 | int failed_device_check; |
| 117 | int all_routers_mcast; |
| 118 | u32 seed; |
| 119 | u64 randomizer; |
| 120 | int ref_count; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 121 | adj_index_t mcast_adj_index; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 122 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 123 | /* timing information */ |
| 124 | #define DEF_MAX_RADV_INTERVAL 200 |
| 125 | #define DEF_MIN_RADV_INTERVAL .75 * DEF_MAX_RADV_INTERVAL |
| 126 | #define DEF_CURR_HOP_LIMIT 64 |
| 127 | #define DEF_DEF_RTR_LIFETIME 3 * DEF_MAX_RADV_INTERVAL |
| 128 | #define MAX_DEF_RTR_LIFETIME 9000 |
| 129 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 130 | #define MAX_INITIAL_RTR_ADVERT_INTERVAL 16 /* seconds */ |
| 131 | #define MAX_INITIAL_RTR_ADVERTISEMENTS 3 /*transmissions */ |
| 132 | #define MIN_DELAY_BETWEEN_RAS 3 /* seconds */ |
| 133 | #define MAX_DELAY_BETWEEN_RAS 1800 /* seconds */ |
| 134 | #define MAX_RA_DELAY_TIME .5 /* seconds */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 135 | |
| 136 | f64 max_radv_interval; |
| 137 | f64 min_radv_interval; |
| 138 | f64 min_delay_between_radv; |
| 139 | f64 max_delay_between_radv; |
| 140 | f64 max_rtr_default_lifetime; |
| 141 | |
| 142 | f64 last_radv_time; |
| 143 | f64 last_multicast_time; |
| 144 | f64 next_multicast_time; |
| 145 | |
| 146 | |
| 147 | u32 initial_adverts_count; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 148 | f64 initial_adverts_interval; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 149 | u32 initial_adverts_sent; |
| 150 | |
| 151 | /* stats */ |
| 152 | u32 n_advertisements_sent; |
| 153 | u32 n_solicitations_rcvd; |
| 154 | u32 n_solicitations_dropped; |
| 155 | |
| 156 | /* Link local address to use (defaults to underlying physical for logical interfaces */ |
| 157 | ip6_address_t link_local_address; |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 158 | |
| 159 | /* router solicitations sending state */ |
| 160 | u8 keep_sending_rs; /* when true then next fields are valid */ |
| 161 | icmp6_send_router_solicitation_params_t params; |
| 162 | f64 sleep_interval; |
| 163 | f64 due_time; |
| 164 | u32 n_left; |
| 165 | f64 start_time; |
| 166 | vlib_buffer_t *buffer; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 167 | } ip6_radv_t; |
| 168 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 169 | typedef struct |
| 170 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 171 | u32 next_index; |
| 172 | uword node_index; |
| 173 | uword type_opaque; |
| 174 | uword data; |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 175 | /* Used for nd event notification only */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 176 | void *data_callback; |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 177 | u32 pid; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 178 | } pending_resolution_t; |
| 179 | |
| 180 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 181 | typedef struct |
| 182 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 183 | /* Hash tables mapping name to opcode. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 184 | uword *opcode_by_name; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 185 | |
| 186 | /* lite beer "glean" adjacency handling */ |
| 187 | mhash_t pending_resolutions_by_address; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 188 | pending_resolution_t *pending_resolutions; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 189 | |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 190 | /* Mac address change notification */ |
| 191 | mhash_t mac_changes_by_address; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 192 | pending_resolution_t *mac_changes; |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 193 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 194 | u32 *neighbor_input_next_index_by_hw_if_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 195 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 196 | ip6_neighbor_t *neighbor_pool; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 197 | |
| 198 | mhash_t neighbor_index_by_key; |
| 199 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 200 | u32 *if_radv_pool_index_by_sw_if_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 201 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 202 | ip6_radv_t *if_radv_pool; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 203 | |
| 204 | /* Neighbor attack mitigation */ |
| 205 | u32 limit_neighbor_cache_size; |
| 206 | u32 neighbor_delete_rotor; |
| 207 | |
Eyal Bari | c125ecc | 2017-09-20 11:29:17 +0300 | [diff] [blame] | 208 | /* Wildcard nd report publisher */ |
| 209 | uword wc_ip6_nd_publisher_node; |
| 210 | uword wc_ip6_nd_publisher_et; |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 211 | |
| 212 | /* Router advertisement report publisher */ |
| 213 | uword ip6_ra_publisher_node; |
| 214 | uword ip6_ra_publisher_et; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 215 | } ip6_neighbor_main_t; |
| 216 | |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 217 | /* ipv6 neighbor discovery - timer/event types */ |
| 218 | typedef enum |
| 219 | { |
| 220 | ICMP6_ND_EVENT_INIT, |
| 221 | } ip6_icmp_neighbor_discovery_event_type_t; |
| 222 | |
| 223 | typedef union |
| 224 | { |
| 225 | u32 add_del_swindex; |
| 226 | struct |
| 227 | { |
| 228 | u32 up_down_swindex; |
| 229 | u32 fib_index; |
| 230 | } up_down_event; |
| 231 | } ip6_icmp_neighbor_discovery_event_data_t; |
| 232 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 233 | static ip6_neighbor_main_t ip6_neighbor_main; |
Juraj Sloboda | 5257452 | 2018-05-03 10:03:50 +0200 | [diff] [blame] | 234 | ip6_neighbor_public_main_t ip6_neighbor_public_main; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 235 | static ip6_address_t ip6a_zero; /* ip6 address 0 */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 236 | |
Eyal Bari | c125ecc | 2017-09-20 11:29:17 +0300 | [diff] [blame] | 237 | static void wc_nd_signal_report (wc_nd_report_t * r); |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 238 | static void ra_signal_report (ra_report_t * r); |
Eyal Bari | c125ecc | 2017-09-20 11:29:17 +0300 | [diff] [blame] | 239 | |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 240 | ip6_address_t |
| 241 | ip6_neighbor_get_link_local_address (u32 sw_if_index) |
| 242 | { |
| 243 | static ip6_address_t empty_address = { {0} }; |
| 244 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 245 | ip6_radv_t *radv_info; |
Juraj Sloboda | 5bb1eca | 2018-10-22 09:57:13 +0200 | [diff] [blame] | 246 | u32 ri = ~0; |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 247 | |
Juraj Sloboda | 5bb1eca | 2018-10-22 09:57:13 +0200 | [diff] [blame] | 248 | if (vec_len (nm->if_radv_pool_index_by_sw_if_index) > sw_if_index) |
| 249 | ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index]; |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 250 | if (ri == ~0) |
| 251 | { |
| 252 | clib_warning ("IPv6 is not enabled for sw_if_index %d", sw_if_index); |
| 253 | return empty_address; |
| 254 | } |
| 255 | radv_info = pool_elt_at_index (nm->if_radv_pool, ri); |
| 256 | if (radv_info == NULL) |
| 257 | { |
| 258 | clib_warning ("Internal error"); |
| 259 | return empty_address; |
| 260 | } |
| 261 | return radv_info->link_local_address; |
| 262 | } |
| 263 | |
Eyal Bari | c125ecc | 2017-09-20 11:29:17 +0300 | [diff] [blame] | 264 | /** |
| 265 | * @brief publish wildcard arp event |
| 266 | * @param sw_if_index The interface on which the ARP entires are acted |
| 267 | */ |
| 268 | static int |
| 269 | vnet_nd_wc_publish (u32 sw_if_index, u8 * mac, ip6_address_t * ip6) |
| 270 | { |
| 271 | wc_nd_report_t r = { |
| 272 | .sw_if_index = sw_if_index, |
| 273 | .ip6 = *ip6, |
| 274 | }; |
| 275 | memcpy (r.mac, mac, sizeof r.mac); |
| 276 | |
| 277 | void vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length); |
| 278 | vl_api_rpc_call_main_thread (wc_nd_signal_report, (u8 *) & r, sizeof r); |
| 279 | return 0; |
| 280 | } |
| 281 | |
| 282 | static void |
| 283 | wc_nd_signal_report (wc_nd_report_t * r) |
| 284 | { |
| 285 | vlib_main_t *vm = vlib_get_main (); |
| 286 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 287 | uword ni = nm->wc_ip6_nd_publisher_node; |
| 288 | uword et = nm->wc_ip6_nd_publisher_et; |
| 289 | |
| 290 | if (ni == (uword) ~ 0) |
| 291 | return; |
| 292 | wc_nd_report_t *q = |
| 293 | vlib_process_signal_event_data (vm, ni, et, 1, sizeof *q); |
| 294 | |
| 295 | *q = *r; |
| 296 | } |
| 297 | |
| 298 | void |
| 299 | wc_nd_set_publisher_node (uword node_index, uword event_type) |
| 300 | { |
| 301 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 302 | nm->wc_ip6_nd_publisher_node = node_index; |
| 303 | nm->wc_ip6_nd_publisher_et = event_type; |
| 304 | } |
| 305 | |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 306 | static int |
| 307 | ra_publish (ra_report_t * r) |
| 308 | { |
| 309 | void vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length); |
| 310 | vl_api_rpc_call_main_thread (ra_signal_report, (u8 *) r, sizeof *r); |
| 311 | return 0; |
| 312 | } |
| 313 | |
| 314 | static void |
| 315 | ra_signal_report (ra_report_t * r) |
| 316 | { |
| 317 | vlib_main_t *vm = vlib_get_main (); |
| 318 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 319 | uword ni = nm->ip6_ra_publisher_node; |
| 320 | uword et = nm->ip6_ra_publisher_et; |
| 321 | |
| 322 | if (ni == (uword) ~ 0) |
| 323 | return; |
| 324 | ra_report_t *q = vlib_process_signal_event_data (vm, ni, et, 1, sizeof *q); |
| 325 | |
| 326 | *q = *r; |
| 327 | } |
| 328 | |
| 329 | void |
| 330 | ra_set_publisher_node (uword node_index, uword event_type) |
| 331 | { |
| 332 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 333 | nm->ip6_ra_publisher_node = node_index; |
| 334 | nm->ip6_ra_publisher_et = event_type; |
| 335 | } |
| 336 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 337 | static u8 * |
| 338 | format_ip6_neighbor_ip6_entry (u8 * s, va_list * va) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 339 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 340 | vlib_main_t *vm = va_arg (*va, vlib_main_t *); |
| 341 | ip6_neighbor_t *n = va_arg (*va, ip6_neighbor_t *); |
| 342 | vnet_main_t *vnm = vnet_get_main (); |
| 343 | vnet_sw_interface_t *si; |
| 344 | u8 *flags = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 345 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 346 | if (!n) |
shubing guo | 3074629 | 2018-08-10 15:51:44 +0800 | [diff] [blame] | 347 | return format (s, "%=12s%=45s%=6s%=20s%=40s", "Time", "Address", "Flags", |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 348 | "Link layer", "Interface"); |
Pierre Pfister | 1dabaaf | 2016-04-25 14:15:15 +0100 | [diff] [blame] | 349 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 350 | if (n->flags & IP6_NEIGHBOR_FLAG_DYNAMIC) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 351 | flags = format (flags, "D"); |
Pierre Pfister | 1dabaaf | 2016-04-25 14:15:15 +0100 | [diff] [blame] | 352 | |
| 353 | if (n->flags & IP6_NEIGHBOR_FLAG_STATIC) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 354 | flags = format (flags, "S"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 355 | |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 356 | if (n->flags & IP6_NEIGHBOR_FLAG_NO_FIB_ENTRY) |
| 357 | flags = format (flags, "N"); |
| 358 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 359 | si = vnet_get_sw_interface (vnm, n->key.sw_if_index); |
shubing guo | 3074629 | 2018-08-10 15:51:44 +0800 | [diff] [blame] | 360 | s = format (s, "%=12U%=45U%=6s%=20U%=40U", |
John Lo | 7f358b3 | 2018-04-28 01:19:24 -0400 | [diff] [blame] | 361 | format_vlib_time, vm, n->time_last_updated, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 362 | format_ip6_address, &n->key.ip6_address, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 363 | flags ? (char *) flags : "", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 364 | format_ethernet_address, n->link_layer_address, |
| 365 | format_vnet_sw_interface_name, vnm, si); |
| 366 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 367 | vec_free (flags); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 368 | return s; |
| 369 | } |
| 370 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 371 | static void |
Neale Ranns | 6b3a8ef | 2017-09-11 10:34:33 -0700 | [diff] [blame] | 372 | ip6_neighbor_adj_fib_remove (ip6_neighbor_t * n, u32 fib_index) |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 373 | { |
| 374 | if (FIB_NODE_INDEX_INVALID != n->fib_entry_index) |
| 375 | { |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 376 | if (ip6_address_is_link_local_unicast (&n->key.ip6_address)) |
| 377 | { |
| 378 | ip6_ll_prefix_t pfx = { |
| 379 | .ilp_addr = n->key.ip6_address, |
| 380 | .ilp_sw_if_index = n->key.sw_if_index, |
| 381 | }; |
| 382 | ip6_ll_table_entry_delete (&pfx); |
| 383 | } |
| 384 | else |
| 385 | { |
| 386 | fib_prefix_t pfx = { |
| 387 | .fp_len = 128, |
| 388 | .fp_proto = FIB_PROTOCOL_IP6, |
| 389 | .fp_addr.ip6 = n->key.ip6_address, |
| 390 | }; |
| 391 | fib_table_entry_path_remove (fib_index, |
| 392 | &pfx, |
| 393 | FIB_SOURCE_ADJ, |
| 394 | DPO_PROTO_IP6, |
| 395 | &pfx.fp_addr, |
| 396 | n->key.sw_if_index, ~0, |
| 397 | 1, FIB_ROUTE_PATH_FLAG_NONE); |
| 398 | } |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 399 | } |
| 400 | } |
| 401 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 402 | typedef struct |
| 403 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 404 | u8 is_add; |
Pierre Pfister | 1dabaaf | 2016-04-25 14:15:15 +0100 | [diff] [blame] | 405 | u8 is_static; |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 406 | u8 is_no_fib_entry; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 407 | u8 link_layer_address[6]; |
| 408 | u32 sw_if_index; |
| 409 | ip6_address_t addr; |
| 410 | } ip6_neighbor_set_unset_rpc_args_t; |
| 411 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 412 | static void ip6_neighbor_set_unset_rpc_callback |
| 413 | (ip6_neighbor_set_unset_rpc_args_t * a); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 414 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 415 | static void set_unset_ip6_neighbor_rpc |
| 416 | (vlib_main_t * vm, |
| 417 | u32 sw_if_index, |
Neale Ranns | 0bdd319 | 2018-09-07 11:04:52 -0700 | [diff] [blame] | 418 | const ip6_address_t * a, |
| 419 | const u8 * link_layer_address, |
| 420 | int is_add, int is_static, int is_no_fib_entry) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 421 | { |
| 422 | ip6_neighbor_set_unset_rpc_args_t args; |
Dave Barach | f9bd620 | 2015-12-14 13:22:11 -0500 | [diff] [blame] | 423 | void vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 424 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 425 | args.sw_if_index = sw_if_index; |
| 426 | args.is_add = is_add; |
Pierre Pfister | 1dabaaf | 2016-04-25 14:15:15 +0100 | [diff] [blame] | 427 | args.is_static = is_static; |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 428 | args.is_no_fib_entry = is_no_fib_entry; |
Damjan Marion | f1213b8 | 2016-03-13 02:22:06 +0100 | [diff] [blame] | 429 | clib_memcpy (&args.addr, a, sizeof (*a)); |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 430 | if (NULL != link_layer_address) |
| 431 | clib_memcpy (args.link_layer_address, link_layer_address, 6); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 432 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 433 | vl_api_rpc_call_main_thread (ip6_neighbor_set_unset_rpc_callback, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 434 | (u8 *) & args, sizeof (args)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 435 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 436 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 437 | static void |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 438 | ip6_nbr_probe (ip_adjacency_t * adj) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 439 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 440 | icmp6_neighbor_solicitation_header_t *h; |
| 441 | vnet_main_t *vnm = vnet_get_main (); |
| 442 | ip6_main_t *im = &ip6_main; |
| 443 | ip_interface_address_t *ia; |
| 444 | ip6_address_t *dst, *src; |
| 445 | vnet_hw_interface_t *hi; |
| 446 | vnet_sw_interface_t *si; |
| 447 | vlib_buffer_t *b; |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 448 | int bogus_length; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 449 | vlib_main_t *vm; |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 450 | u32 bi = 0; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 451 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 452 | vm = vlib_get_main (); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 453 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 454 | si = vnet_get_sw_interface (vnm, adj->rewrite_header.sw_if_index); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 455 | dst = &adj->sub_type.nbr.next_hop.ip6; |
| 456 | |
| 457 | if (!(si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP)) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 458 | { |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 459 | return; |
| 460 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 461 | src = ip6_interface_address_matching_destination (im, dst, |
| 462 | adj->rewrite_header. |
| 463 | sw_if_index, &ia); |
| 464 | if (!src) |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 465 | { |
| 466 | return; |
| 467 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 468 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 469 | h = vlib_packet_template_get_packet (vm, |
| 470 | &im->discover_neighbor_packet_template, |
| 471 | &bi); |
John Lo | 084606b | 2018-06-19 15:27:48 -0400 | [diff] [blame] | 472 | if (!h) |
| 473 | return; |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 474 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 475 | hi = vnet_get_sup_hw_interface (vnm, adj->rewrite_header.sw_if_index); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 476 | |
| 477 | h->ip.dst_address.as_u8[13] = dst->as_u8[13]; |
| 478 | h->ip.dst_address.as_u8[14] = dst->as_u8[14]; |
| 479 | h->ip.dst_address.as_u8[15] = dst->as_u8[15]; |
| 480 | h->ip.src_address = src[0]; |
| 481 | h->neighbor.target_address = dst[0]; |
| 482 | |
| 483 | clib_memcpy (h->link_layer_option.ethernet_address, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 484 | hi->hw_address, vec_len (hi->hw_address)); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 485 | |
| 486 | h->neighbor.icmp.checksum = |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 487 | ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h->ip, &bogus_length); |
| 488 | ASSERT (bogus_length == 0); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 489 | |
| 490 | b = vlib_get_buffer (vm, bi); |
| 491 | vnet_buffer (b)->sw_if_index[VLIB_RX] = |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 492 | vnet_buffer (b)->sw_if_index[VLIB_TX] = adj->rewrite_header.sw_if_index; |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 493 | |
| 494 | /* Add encapsulation string for software interface (e.g. ethernet header). */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 495 | vnet_rewrite_one_header (adj[0], h, sizeof (ethernet_header_t)); |
| 496 | vlib_buffer_advance (b, -adj->rewrite_header.data_bytes); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 497 | |
| 498 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 499 | vlib_frame_t *f = vlib_get_frame_to_node (vm, hi->output_node_index); |
| 500 | u32 *to_next = vlib_frame_vector_args (f); |
| 501 | to_next[0] = bi; |
| 502 | f->n_vectors = 1; |
| 503 | vlib_put_frame_to_node (vm, hi->output_node_index, f); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 504 | } |
| 505 | } |
| 506 | |
| 507 | static void |
| 508 | ip6_nd_mk_complete (adj_index_t ai, ip6_neighbor_t * nbr) |
| 509 | { |
| 510 | adj_nbr_update_rewrite (ai, ADJ_NBR_REWRITE_FLAG_COMPLETE, |
| 511 | ethernet_build_rewrite (vnet_get_main (), |
| 512 | nbr->key.sw_if_index, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 513 | adj_get_link_type (ai), |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 514 | nbr->link_layer_address)); |
| 515 | } |
| 516 | |
| 517 | static void |
Neale Ranns | 19c68d2 | 2016-12-07 15:38:14 +0000 | [diff] [blame] | 518 | ip6_nd_mk_incomplete (adj_index_t ai) |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 519 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 520 | ip_adjacency_t *adj = adj_get (ai); |
Neale Ranns | 19c68d2 | 2016-12-07 15:38:14 +0000 | [diff] [blame] | 521 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 522 | adj_nbr_update_rewrite (ai, |
| 523 | ADJ_NBR_REWRITE_FLAG_INCOMPLETE, |
| 524 | ethernet_build_rewrite (vnet_get_main (), |
| 525 | adj->rewrite_header. |
| 526 | sw_if_index, |
| 527 | adj_get_link_type (ai), |
| 528 | VNET_REWRITE_FOR_SW_INTERFACE_ADDRESS_BROADCAST)); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | #define IP6_NBR_MK_KEY(k, sw_if_index, addr) \ |
| 532 | { \ |
| 533 | k.sw_if_index = sw_if_index; \ |
| 534 | k.ip6_address = *addr; \ |
| 535 | k.pad = 0; \ |
| 536 | } |
| 537 | |
| 538 | static ip6_neighbor_t * |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 539 | ip6_nd_find (u32 sw_if_index, const ip6_address_t * addr) |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 540 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 541 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 542 | ip6_neighbor_t *n = NULL; |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 543 | ip6_neighbor_key_t k; |
| 544 | uword *p; |
| 545 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 546 | IP6_NBR_MK_KEY (k, sw_if_index, addr); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 547 | |
| 548 | p = mhash_get (&nm->neighbor_index_by_key, &k); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 549 | if (p) |
| 550 | { |
| 551 | n = pool_elt_at_index (nm->neighbor_pool, p[0]); |
| 552 | } |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 553 | |
| 554 | return (n); |
| 555 | } |
| 556 | |
| 557 | static adj_walk_rc_t |
| 558 | ip6_nd_mk_complete_walk (adj_index_t ai, void *ctx) |
| 559 | { |
| 560 | ip6_neighbor_t *nbr = ctx; |
| 561 | |
| 562 | ip6_nd_mk_complete (ai, nbr); |
| 563 | |
| 564 | return (ADJ_WALK_RC_CONTINUE); |
| 565 | } |
| 566 | |
| 567 | static adj_walk_rc_t |
| 568 | ip6_nd_mk_incomplete_walk (adj_index_t ai, void *ctx) |
| 569 | { |
Neale Ranns | 19c68d2 | 2016-12-07 15:38:14 +0000 | [diff] [blame] | 570 | ip6_nd_mk_incomplete (ai); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 571 | |
| 572 | return (ADJ_WALK_RC_CONTINUE); |
| 573 | } |
| 574 | |
John Lo | 4fed5b1 | 2018-05-22 03:35:06 -0400 | [diff] [blame] | 575 | static clib_error_t * |
| 576 | ip6_neighbor_sw_interface_up_down (vnet_main_t * vnm, |
| 577 | u32 sw_if_index, u32 flags) |
| 578 | { |
| 579 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 580 | ip6_neighbor_t *n; |
| 581 | u32 i, *to_delete = 0; |
| 582 | |
| 583 | /* *INDENT-OFF* */ |
| 584 | pool_foreach (n, nm->neighbor_pool, |
| 585 | ({ |
| 586 | if (n->key.sw_if_index == sw_if_index) |
| 587 | vec_add1 (to_delete, n - nm->neighbor_pool); |
| 588 | })); |
| 589 | /* *INDENT-ON* */ |
| 590 | |
| 591 | if (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) |
| 592 | { |
| 593 | for (i = 0; i < vec_len (to_delete); i++) |
| 594 | { |
| 595 | n = pool_elt_at_index (nm->neighbor_pool, to_delete[i]); |
| 596 | adj_nbr_walk_nh6 (n->key.sw_if_index, &n->key.ip6_address, |
| 597 | ip6_nd_mk_complete_walk, n); |
| 598 | } |
| 599 | } |
| 600 | else |
| 601 | { |
| 602 | for (i = 0; i < vec_len (to_delete); i++) |
| 603 | { |
| 604 | n = pool_elt_at_index (nm->neighbor_pool, to_delete[i]); |
| 605 | adj_nbr_walk_nh6 (n->key.sw_if_index, &n->key.ip6_address, |
| 606 | ip6_nd_mk_incomplete_walk, NULL); |
| 607 | if (n->flags & IP6_NEIGHBOR_FLAG_STATIC) |
| 608 | continue; |
| 609 | ip6_neighbor_adj_fib_remove (n, |
| 610 | ip6_fib_table_get_index_for_sw_if_index |
| 611 | (n->key.sw_if_index)); |
| 612 | mhash_unset (&nm->neighbor_index_by_key, &n->key, 0); |
| 613 | pool_put (nm->neighbor_pool, n); |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | vec_free (to_delete); |
| 618 | return 0; |
| 619 | } |
| 620 | |
| 621 | VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (ip6_neighbor_sw_interface_up_down); |
| 622 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 623 | void |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 624 | ip6_ethernet_update_adjacency (vnet_main_t * vnm, u32 sw_if_index, u32 ai) |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 625 | { |
| 626 | ip6_neighbor_t *nbr; |
| 627 | ip_adjacency_t *adj; |
| 628 | |
| 629 | adj = adj_get (ai); |
| 630 | |
| 631 | nbr = ip6_nd_find (sw_if_index, &adj->sub_type.nbr.next_hop.ip6); |
| 632 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 633 | switch (adj->lookup_next_index) |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 634 | { |
Ole Trøan | 438f630 | 2018-02-15 21:56:06 +0000 | [diff] [blame] | 635 | case IP_LOOKUP_NEXT_GLEAN: |
Neale Ranns | c819fc6 | 2018-02-16 02:44:05 -0800 | [diff] [blame] | 636 | adj_glean_update_rewrite (ai); |
| 637 | break; |
| 638 | case IP_LOOKUP_NEXT_ARP: |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 639 | if (NULL != nbr) |
| 640 | { |
| 641 | adj_nbr_walk_nh6 (sw_if_index, &nbr->key.ip6_address, |
| 642 | ip6_nd_mk_complete_walk, nbr); |
| 643 | } |
| 644 | else |
| 645 | { |
| 646 | /* |
| 647 | * no matching ND entry. |
| 648 | * construct the rewrite required to for an ND packet, and stick |
| 649 | * that in the adj's pipe to smoke. |
| 650 | */ |
| 651 | adj_nbr_update_rewrite (ai, |
| 652 | ADJ_NBR_REWRITE_FLAG_INCOMPLETE, |
| 653 | ethernet_build_rewrite (vnm, |
| 654 | sw_if_index, |
| 655 | VNET_LINK_IP6, |
| 656 | VNET_REWRITE_FOR_SW_INTERFACE_ADDRESS_BROADCAST)); |
| 657 | |
| 658 | /* |
| 659 | * since the FIB has added this adj for a route, it makes sense it may |
| 660 | * want to forward traffic sometime soon. Let's send a speculative ND. |
| 661 | * just one. If we were to do periodically that wouldn't be bad either, |
| 662 | * but that's more code than i'm prepared to write at this time for |
| 663 | * relatively little reward. |
| 664 | */ |
| 665 | ip6_nbr_probe (adj); |
| 666 | } |
| 667 | break; |
Neale Ranns | 1855b8e | 2018-07-11 10:31:26 -0700 | [diff] [blame] | 668 | case IP_LOOKUP_NEXT_BCAST: |
| 669 | adj_nbr_update_rewrite (ai, |
| 670 | ADJ_NBR_REWRITE_FLAG_COMPLETE, |
| 671 | ethernet_build_rewrite (vnm, |
| 672 | sw_if_index, |
| 673 | VNET_LINK_IP6, |
| 674 | VNET_REWRITE_FOR_SW_INTERFACE_ADDRESS_BROADCAST)); |
| 675 | break; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 676 | case IP_LOOKUP_NEXT_MCAST: |
Neale Ranns | 2e7fbcc | 2017-03-15 04:22:25 -0700 | [diff] [blame] | 677 | { |
| 678 | /* |
| 679 | * Construct a partial rewrite from the known ethernet mcast dest MAC |
| 680 | */ |
| 681 | u8 *rewrite; |
| 682 | u8 offset; |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 683 | |
Neale Ranns | 2e7fbcc | 2017-03-15 04:22:25 -0700 | [diff] [blame] | 684 | rewrite = ethernet_build_rewrite (vnm, |
| 685 | sw_if_index, |
| 686 | adj->ia_link, |
| 687 | ethernet_ip6_mcast_dst_addr ()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 688 | |
Neale Ranns | 2e7fbcc | 2017-03-15 04:22:25 -0700 | [diff] [blame] | 689 | /* |
| 690 | * Complete the remaining fields of the adj's rewrite to direct the |
| 691 | * complete of the rewrite at switch time by copying in the IP |
| 692 | * dst address's bytes. |
Neale Ranns | 889fe94 | 2017-06-01 05:43:19 -0400 | [diff] [blame] | 693 | * Ofset is 2 bytes into the desintation address. |
Neale Ranns | 2e7fbcc | 2017-03-15 04:22:25 -0700 | [diff] [blame] | 694 | */ |
| 695 | offset = vec_len (rewrite) - 2; |
Neale Ranns | 889fe94 | 2017-06-01 05:43:19 -0400 | [diff] [blame] | 696 | adj_mcast_update_rewrite (ai, rewrite, offset); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 697 | |
Neale Ranns | 2e7fbcc | 2017-03-15 04:22:25 -0700 | [diff] [blame] | 698 | break; |
| 699 | } |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 700 | case IP_LOOKUP_NEXT_DROP: |
| 701 | case IP_LOOKUP_NEXT_PUNT: |
| 702 | case IP_LOOKUP_NEXT_LOCAL: |
| 703 | case IP_LOOKUP_NEXT_REWRITE: |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 704 | case IP_LOOKUP_NEXT_MCAST_MIDCHAIN: |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 705 | case IP_LOOKUP_NEXT_MIDCHAIN: |
| 706 | case IP_LOOKUP_NEXT_ICMP_ERROR: |
| 707 | case IP_LOOKUP_N_NEXT: |
| 708 | ASSERT (0); |
| 709 | break; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 710 | } |
| 711 | } |
| 712 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 713 | |
| 714 | static void |
Neale Ranns | 6b3a8ef | 2017-09-11 10:34:33 -0700 | [diff] [blame] | 715 | ip6_neighbor_adj_fib_add (ip6_neighbor_t * n, u32 fib_index) |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 716 | { |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 717 | if (ip6_address_is_link_local_unicast (&n->key.ip6_address)) |
| 718 | { |
| 719 | ip6_ll_prefix_t pfx = { |
| 720 | .ilp_addr = n->key.ip6_address, |
| 721 | .ilp_sw_if_index = n->key.sw_if_index, |
| 722 | }; |
| 723 | n->fib_entry_index = |
| 724 | ip6_ll_table_entry_update (&pfx, FIB_ROUTE_PATH_FLAG_NONE); |
| 725 | } |
| 726 | else |
| 727 | { |
| 728 | fib_prefix_t pfx = { |
| 729 | .fp_len = 128, |
| 730 | .fp_proto = FIB_PROTOCOL_IP6, |
| 731 | .fp_addr.ip6 = n->key.ip6_address, |
| 732 | }; |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 733 | |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 734 | n->fib_entry_index = |
| 735 | fib_table_entry_path_add (fib_index, &pfx, FIB_SOURCE_ADJ, |
| 736 | FIB_ENTRY_FLAG_ATTACHED, |
| 737 | DPO_PROTO_IP6, &pfx.fp_addr, |
| 738 | n->key.sw_if_index, ~0, 1, NULL, |
| 739 | FIB_ROUTE_PATH_FLAG_NONE); |
| 740 | } |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 741 | } |
| 742 | |
John Lo | 4fed5b1 | 2018-05-22 03:35:06 -0400 | [diff] [blame] | 743 | static ip6_neighbor_t * |
| 744 | force_reuse_neighbor_entry (void) |
| 745 | { |
| 746 | ip6_neighbor_t *n; |
| 747 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 748 | u32 count = 0; |
| 749 | u32 index = pool_next_index (nm->neighbor_pool, nm->neighbor_delete_rotor); |
| 750 | if (index == ~0) /* Try again from elt 0 */ |
| 751 | index = pool_next_index (nm->neighbor_pool, index); |
| 752 | |
| 753 | /* Find a non-static random entry to free up for reuse */ |
| 754 | do |
| 755 | { |
| 756 | if ((count++ == 100) || (index == ~0)) |
| 757 | return NULL; /* give up after 100 entries */ |
| 758 | n = pool_elt_at_index (nm->neighbor_pool, index); |
| 759 | nm->neighbor_delete_rotor = index; |
| 760 | index = pool_next_index (nm->neighbor_pool, index); |
| 761 | } |
| 762 | while (n->flags & IP6_NEIGHBOR_FLAG_STATIC); |
| 763 | |
| 764 | /* Remove ARP entry from its interface and update fib */ |
| 765 | adj_nbr_walk_nh6 (n->key.sw_if_index, |
| 766 | &n->key.ip6_address, ip6_nd_mk_incomplete_walk, NULL); |
| 767 | ip6_neighbor_adj_fib_remove |
| 768 | (n, ip6_fib_table_get_index_for_sw_if_index (n->key.sw_if_index)); |
| 769 | mhash_unset (&nm->neighbor_index_by_key, &n->key, 0); |
| 770 | |
| 771 | return n; |
| 772 | } |
| 773 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 774 | int |
| 775 | vnet_set_ip6_ethernet_neighbor (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 776 | u32 sw_if_index, |
Neale Ranns | 0bdd319 | 2018-09-07 11:04:52 -0700 | [diff] [blame] | 777 | const ip6_address_t * a, |
| 778 | const u8 * link_layer_address, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 779 | uword n_bytes_link_layer_address, |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 780 | int is_static, int is_no_fib_entry) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 781 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 782 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 783 | ip6_neighbor_key_t k; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 784 | ip6_neighbor_t *n = 0; |
| 785 | int make_new_nd_cache_entry = 1; |
| 786 | uword *p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 787 | u32 next_index; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 788 | pending_resolution_t *pr, *mc; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 789 | |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 790 | if (vlib_get_thread_index ()) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 791 | { |
| 792 | set_unset_ip6_neighbor_rpc (vm, sw_if_index, a, link_layer_address, |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 793 | 1 /* set new neighbor */ , is_static, |
| 794 | is_no_fib_entry); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 795 | return 0; |
| 796 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 797 | |
| 798 | k.sw_if_index = sw_if_index; |
| 799 | k.ip6_address = a[0]; |
| 800 | k.pad = 0; |
| 801 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 802 | p = mhash_get (&nm->neighbor_index_by_key, &k); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 803 | if (p) |
| 804 | { |
| 805 | n = pool_elt_at_index (nm->neighbor_pool, p[0]); |
| 806 | /* Refuse to over-write static neighbor entry. */ |
| 807 | if (!is_static && (n->flags & IP6_NEIGHBOR_FLAG_STATIC)) |
John Lo | 0e6f4d6 | 2018-07-13 17:29:58 -0400 | [diff] [blame] | 808 | { |
| 809 | /* if MAC address match, still check to send event */ |
| 810 | if (0 == memcmp (n->link_layer_address, |
| 811 | link_layer_address, n_bytes_link_layer_address)) |
| 812 | goto check_customers; |
| 813 | return -2; |
| 814 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 815 | make_new_nd_cache_entry = 0; |
| 816 | } |
Pierre Pfister | 1dabaaf | 2016-04-25 14:15:15 +0100 | [diff] [blame] | 817 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 818 | if (make_new_nd_cache_entry) |
| 819 | { |
John Lo | 4fed5b1 | 2018-05-22 03:35:06 -0400 | [diff] [blame] | 820 | if (nm->limit_neighbor_cache_size && |
| 821 | pool_elts (nm->neighbor_pool) >= nm->limit_neighbor_cache_size) |
| 822 | { |
| 823 | n = force_reuse_neighbor_entry (); |
| 824 | if (NULL == n) |
| 825 | return -2; |
| 826 | } |
| 827 | else |
| 828 | pool_get (nm->neighbor_pool, n); |
| 829 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 830 | mhash_set (&nm->neighbor_index_by_key, &k, n - nm->neighbor_pool, |
| 831 | /* old value */ 0); |
| 832 | n->key = k; |
Neale Ranns | d5b6aa1 | 2017-05-16 08:46:45 -0700 | [diff] [blame] | 833 | n->fib_entry_index = FIB_NODE_INDEX_INVALID; |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 834 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 835 | clib_memcpy (n->link_layer_address, |
| 836 | link_layer_address, n_bytes_link_layer_address); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 837 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 838 | /* |
| 839 | * create the adj-fib. the entry in the FIB table for and to the peer. |
| 840 | */ |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 841 | if (!is_no_fib_entry) |
| 842 | { |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 843 | ip6_neighbor_adj_fib_add |
| 844 | (n, ip6_fib_table_get_index_for_sw_if_index (n->key.sw_if_index)); |
Neale Ranns | 2a3ea49 | 2017-04-19 05:24:40 -0700 | [diff] [blame] | 845 | } |
| 846 | else |
| 847 | { |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 848 | n->flags |= IP6_NEIGHBOR_FLAG_NO_FIB_ENTRY; |
| 849 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 850 | } |
Neale Ranns | 33a7dd5 | 2016-10-07 15:14:33 +0100 | [diff] [blame] | 851 | else |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 852 | { |
| 853 | /* |
| 854 | * prevent a DoS attack from the data-plane that |
| 855 | * spams us with no-op updates to the MAC address |
| 856 | */ |
| 857 | if (0 == memcmp (n->link_layer_address, |
| 858 | link_layer_address, n_bytes_link_layer_address)) |
John Lo | 7f358b3 | 2018-04-28 01:19:24 -0400 | [diff] [blame] | 859 | { |
| 860 | n->time_last_updated = vlib_time_now (vm); |
| 861 | goto check_customers; |
| 862 | } |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 863 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 864 | clib_memcpy (n->link_layer_address, |
| 865 | link_layer_address, n_bytes_link_layer_address); |
| 866 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 867 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 868 | /* Update time stamp and flags. */ |
John Lo | 7f358b3 | 2018-04-28 01:19:24 -0400 | [diff] [blame] | 869 | n->time_last_updated = vlib_time_now (vm); |
Pierre Pfister | 1dabaaf | 2016-04-25 14:15:15 +0100 | [diff] [blame] | 870 | if (is_static) |
John Lo | 4fed5b1 | 2018-05-22 03:35:06 -0400 | [diff] [blame] | 871 | { |
| 872 | n->flags |= IP6_NEIGHBOR_FLAG_STATIC; |
| 873 | n->flags &= ~IP6_NEIGHBOR_FLAG_DYNAMIC; |
| 874 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 875 | else |
John Lo | 4fed5b1 | 2018-05-22 03:35:06 -0400 | [diff] [blame] | 876 | { |
| 877 | n->flags |= IP6_NEIGHBOR_FLAG_DYNAMIC; |
| 878 | n->flags &= ~IP6_NEIGHBOR_FLAG_STATIC; |
| 879 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 880 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 881 | adj_nbr_walk_nh6 (sw_if_index, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 882 | &n->key.ip6_address, ip6_nd_mk_complete_walk, n); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 883 | |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 884 | check_customers: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 885 | /* Customer(s) waiting for this address to be resolved? */ |
| 886 | p = mhash_get (&nm->pending_resolutions_by_address, a); |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 887 | if (p) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 888 | { |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 889 | next_index = p[0]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 890 | |
| 891 | while (next_index != (u32) ~ 0) |
| 892 | { |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 893 | pr = pool_elt_at_index (nm->pending_resolutions, next_index); |
| 894 | vlib_process_signal_event (vm, pr->node_index, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 895 | pr->type_opaque, pr->data); |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 896 | next_index = pr->next_index; |
| 897 | pool_put (nm->pending_resolutions, pr); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 898 | } |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 899 | |
Neale Ranns | 0bdd319 | 2018-09-07 11:04:52 -0700 | [diff] [blame] | 900 | mhash_unset (&nm->pending_resolutions_by_address, (void *) a, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 901 | } |
| 902 | |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 903 | /* Customer(s) requesting ND event for this address? */ |
| 904 | p = mhash_get (&nm->mac_changes_by_address, a); |
| 905 | if (p) |
| 906 | { |
| 907 | next_index = p[0]; |
| 908 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 909 | while (next_index != (u32) ~ 0) |
| 910 | { |
| 911 | int (*fp) (u32, u8 *, u32, ip6_address_t *); |
| 912 | int rv = 1; |
| 913 | mc = pool_elt_at_index (nm->mac_changes, next_index); |
| 914 | fp = mc->data_callback; |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 915 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 916 | /* Call the user's data callback, return 1 to suppress dup events */ |
| 917 | if (fp) |
| 918 | rv = |
Neale Ranns | 0bdd319 | 2018-09-07 11:04:52 -0700 | [diff] [blame] | 919 | (*fp) (mc->data, (u8 *) link_layer_address, sw_if_index, |
| 920 | &ip6a_zero); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 921 | /* |
| 922 | * Signal the resolver process, as long as the user |
| 923 | * says they want to be notified |
| 924 | */ |
| 925 | if (rv == 0) |
| 926 | vlib_process_signal_event (vm, mc->node_index, |
| 927 | mc->type_opaque, mc->data); |
| 928 | next_index = mc->next_index; |
| 929 | } |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 930 | } |
| 931 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 932 | return 0; |
| 933 | } |
| 934 | |
| 935 | int |
| 936 | vnet_unset_ip6_ethernet_neighbor (vlib_main_t * vm, |
Neale Ranns | 0bdd319 | 2018-09-07 11:04:52 -0700 | [diff] [blame] | 937 | u32 sw_if_index, const ip6_address_t * a) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 938 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 939 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 940 | ip6_neighbor_key_t k; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 941 | ip6_neighbor_t *n; |
| 942 | uword *p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 943 | int rv = 0; |
| 944 | |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 945 | if (vlib_get_thread_index ()) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 946 | { |
Neale Ranns | 0bdd319 | 2018-09-07 11:04:52 -0700 | [diff] [blame] | 947 | set_unset_ip6_neighbor_rpc (vm, sw_if_index, a, NULL, |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 948 | 0 /* unset */ , 0, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 949 | return 0; |
| 950 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 951 | |
| 952 | k.sw_if_index = sw_if_index; |
| 953 | k.ip6_address = a[0]; |
| 954 | k.pad = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 955 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 956 | p = mhash_get (&nm->neighbor_index_by_key, &k); |
| 957 | if (p == 0) |
| 958 | { |
| 959 | rv = -1; |
| 960 | goto out; |
| 961 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 962 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 963 | n = pool_elt_at_index (nm->neighbor_pool, p[0]); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 964 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 965 | adj_nbr_walk_nh6 (sw_if_index, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 966 | &n->key.ip6_address, ip6_nd_mk_incomplete_walk, NULL); |
John Lo | 4fed5b1 | 2018-05-22 03:35:06 -0400 | [diff] [blame] | 967 | ip6_neighbor_adj_fib_remove |
| 968 | (n, ip6_fib_table_get_index_for_sw_if_index (sw_if_index)); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 969 | |
John Lo | 4fed5b1 | 2018-05-22 03:35:06 -0400 | [diff] [blame] | 970 | mhash_unset (&nm->neighbor_index_by_key, &n->key, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 971 | pool_put (nm->neighbor_pool, n); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 972 | |
| 973 | out: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 974 | return rv; |
| 975 | } |
| 976 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 977 | static void ip6_neighbor_set_unset_rpc_callback |
| 978 | (ip6_neighbor_set_unset_rpc_args_t * a) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 979 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 980 | vlib_main_t *vm = vlib_get_main (); |
| 981 | if (a->is_add) |
| 982 | vnet_set_ip6_ethernet_neighbor (vm, a->sw_if_index, &a->addr, |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 983 | a->link_layer_address, 6, a->is_static, |
| 984 | a->is_no_fib_entry); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 985 | else |
Neale Ranns | 0bdd319 | 2018-09-07 11:04:52 -0700 | [diff] [blame] | 986 | vnet_unset_ip6_ethernet_neighbor (vm, a->sw_if_index, &a->addr); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 987 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 988 | |
| 989 | static int |
| 990 | ip6_neighbor_sort (void *a1, void *a2) |
| 991 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 992 | vnet_main_t *vnm = vnet_get_main (); |
| 993 | ip6_neighbor_t *n1 = a1, *n2 = a2; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 994 | int cmp; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 995 | cmp = vnet_sw_interface_compare (vnm, n1->key.sw_if_index, |
| 996 | n2->key.sw_if_index); |
| 997 | if (!cmp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 998 | cmp = ip6_address_compare (&n1->key.ip6_address, &n2->key.ip6_address); |
| 999 | return cmp; |
| 1000 | } |
| 1001 | |
Pavel Kotucek | 3e046ea | 2016-12-05 08:27:37 +0100 | [diff] [blame] | 1002 | ip6_neighbor_t * |
John Lo | 7f358b3 | 2018-04-28 01:19:24 -0400 | [diff] [blame] | 1003 | ip6_neighbors_pool (void) |
| 1004 | { |
| 1005 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 1006 | return nm->neighbor_pool; |
| 1007 | } |
| 1008 | |
| 1009 | ip6_neighbor_t * |
Pavel Kotucek | 3e046ea | 2016-12-05 08:27:37 +0100 | [diff] [blame] | 1010 | ip6_neighbors_entries (u32 sw_if_index) |
| 1011 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1012 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
Pavel Kotucek | 3e046ea | 2016-12-05 08:27:37 +0100 | [diff] [blame] | 1013 | ip6_neighbor_t *n, *ns = 0; |
| 1014 | |
| 1015 | /* *INDENT-OFF* */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1016 | pool_foreach (n, nm->neighbor_pool, |
| 1017 | ({ |
Pavel Kotucek | 3e046ea | 2016-12-05 08:27:37 +0100 | [diff] [blame] | 1018 | if (sw_if_index != ~0 && n->key.sw_if_index != sw_if_index) |
| 1019 | continue; |
| 1020 | vec_add1 (ns, n[0]); |
| 1021 | })); |
| 1022 | /* *INDENT-ON* */ |
| 1023 | |
| 1024 | if (ns) |
| 1025 | vec_sort_with_function (ns, ip6_neighbor_sort); |
| 1026 | return ns; |
| 1027 | } |
| 1028 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1029 | static clib_error_t * |
| 1030 | show_ip6_neighbors (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1031 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1032 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1033 | vnet_main_t *vnm = vnet_get_main (); |
| 1034 | ip6_neighbor_t *n, *ns; |
| 1035 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1036 | u32 sw_if_index; |
| 1037 | |
| 1038 | /* Filter entries by interface if given. */ |
| 1039 | sw_if_index = ~0; |
| 1040 | (void) unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index); |
| 1041 | |
Pavel Kotucek | 3e046ea | 2016-12-05 08:27:37 +0100 | [diff] [blame] | 1042 | ns = ip6_neighbors_entries (sw_if_index); |
Billy McFall | 46529cd | 2016-10-14 10:45:49 -0400 | [diff] [blame] | 1043 | if (ns) |
| 1044 | { |
Billy McFall | 46529cd | 2016-10-14 10:45:49 -0400 | [diff] [blame] | 1045 | vlib_cli_output (vm, "%U", format_ip6_neighbor_ip6_entry, vm, 0); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1046 | vec_foreach (n, ns) |
| 1047 | { |
| 1048 | vlib_cli_output (vm, "%U", format_ip6_neighbor_ip6_entry, vm, n); |
Billy McFall | 46529cd | 2016-10-14 10:45:49 -0400 | [diff] [blame] | 1049 | } |
| 1050 | vec_free (ns); |
| 1051 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1052 | |
| 1053 | return error; |
| 1054 | } |
| 1055 | |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 1056 | /*? |
| 1057 | * This command is used to display the adjacent IPv6 hosts found via |
| 1058 | * neighbor discovery. Optionally, limit the output to the specified |
| 1059 | * interface. |
| 1060 | * |
| 1061 | * @cliexpar |
| 1062 | * Example of how to display the IPv6 neighbor adjacency table: |
| 1063 | * @cliexstart{show ip6 neighbors} |
| 1064 | * Time Address Flags Link layer Interface |
| 1065 | * 34.0910 ::a:1:1:0:7 02:fe:6a:07:39:6f GigabitEthernet2/0/0 |
| 1066 | * 173.2916 ::b:5:1:c:2 02:fe:50:62:3a:94 GigabitEthernet2/0/0 |
| 1067 | * 886.6654 ::1:1:c:0:9 S 02:fe:e4:45:27:5b GigabitEthernet3/0/0 |
| 1068 | * @cliexend |
| 1069 | * Example of how to display the IPv6 neighbor adjacency table for given interface: |
| 1070 | * @cliexstart{show ip6 neighbors GigabitEthernet2/0/0} |
| 1071 | * Time Address Flags Link layer Interface |
| 1072 | * 34.0910 ::a:1:1:0:7 02:fe:6a:07:39:6f GigabitEthernet2/0/0 |
| 1073 | * 173.2916 ::b:5:1:c:2 02:fe:50:62:3a:94 GigabitEthernet2/0/0 |
| 1074 | * @cliexend |
| 1075 | ?*/ |
| 1076 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1077 | VLIB_CLI_COMMAND (show_ip6_neighbors_command, static) = { |
| 1078 | .path = "show ip6 neighbors", |
| 1079 | .function = show_ip6_neighbors, |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 1080 | .short_help = "show ip6 neighbors [<interface>]", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1081 | }; |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 1082 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1083 | |
| 1084 | static clib_error_t * |
| 1085 | set_ip6_neighbor (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1086 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1087 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1088 | vnet_main_t *vnm = vnet_get_main (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1089 | ip6_address_t addr; |
| 1090 | u8 mac_address[6]; |
| 1091 | int addr_valid = 0; |
| 1092 | int is_del = 0; |
Pierre Pfister | 1dabaaf | 2016-04-25 14:15:15 +0100 | [diff] [blame] | 1093 | int is_static = 0; |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 1094 | int is_no_fib_entry = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1095 | u32 sw_if_index; |
| 1096 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1097 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1098 | { |
| 1099 | /* intfc, ip6-address, mac-address */ |
| 1100 | if (unformat (input, "%U %U %U", |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1101 | unformat_vnet_sw_interface, vnm, &sw_if_index, |
| 1102 | unformat_ip6_address, &addr, |
| 1103 | unformat_ethernet_address, mac_address)) |
| 1104 | addr_valid = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1105 | |
| 1106 | else if (unformat (input, "delete") || unformat (input, "del")) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1107 | is_del = 1; |
Pierre Pfister | 1dabaaf | 2016-04-25 14:15:15 +0100 | [diff] [blame] | 1108 | else if (unformat (input, "static")) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1109 | is_static = 1; |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 1110 | else if (unformat (input, "no-fib-entry")) |
| 1111 | is_no_fib_entry = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1112 | else |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1113 | break; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | if (!addr_valid) |
| 1117 | return clib_error_return (0, "Missing interface, ip6 or hw address"); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1118 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1119 | if (!is_del) |
| 1120 | vnet_set_ip6_ethernet_neighbor (vm, sw_if_index, &addr, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1121 | mac_address, sizeof (mac_address), |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 1122 | is_static, is_no_fib_entry); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1123 | else |
Neale Ranns | 0bdd319 | 2018-09-07 11:04:52 -0700 | [diff] [blame] | 1124 | vnet_unset_ip6_ethernet_neighbor (vm, sw_if_index, &addr); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1125 | return 0; |
| 1126 | } |
| 1127 | |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 1128 | /*? |
| 1129 | * This command is used to manually add an entry to the IPv6 neighbor |
| 1130 | * adjacency table. Optionally, the entry can be added as static. It is |
| 1131 | * also used to remove an entry from the table. Use the '<em>show ip6 |
| 1132 | * neighbors</em>' command to display all learned and manually entered entries. |
| 1133 | * |
| 1134 | * @cliexpar |
| 1135 | * Example of how to add a static entry to the IPv6 neighbor adjacency table: |
| 1136 | * @cliexcmd{set ip6 neighbor GigabitEthernet2/0/0 ::1:1:c:0:9 02:fe:e4:45:27:5b static} |
| 1137 | * Example of how to delete an entry from the IPv6 neighbor adjacency table: |
| 1138 | * @cliexcmd{set ip6 neighbor del GigabitEthernet2/0/0 ::1:1:c:0:9 02:fe:e4:45:27:5b} |
| 1139 | ?*/ |
| 1140 | /* *INDENT-OFF* */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1141 | VLIB_CLI_COMMAND (set_ip6_neighbor_command, static) = |
| 1142 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1143 | .path = "set ip6 neighbor", |
| 1144 | .function = set_ip6_neighbor, |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 1145 | .short_help = "set ip6 neighbor [del] <interface> <ip6-address> <mac-address> [static]", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1146 | }; |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 1147 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1148 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1149 | typedef enum |
| 1150 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1151 | ICMP6_NEIGHBOR_SOLICITATION_NEXT_DROP, |
| 1152 | ICMP6_NEIGHBOR_SOLICITATION_NEXT_REPLY, |
| 1153 | ICMP6_NEIGHBOR_SOLICITATION_N_NEXT, |
| 1154 | } icmp6_neighbor_solicitation_or_advertisement_next_t; |
| 1155 | |
| 1156 | static_always_inline uword |
| 1157 | icmp6_neighbor_solicitation_or_advertisement (vlib_main_t * vm, |
| 1158 | vlib_node_runtime_t * node, |
| 1159 | vlib_frame_t * frame, |
| 1160 | uword is_solicitation) |
| 1161 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1162 | vnet_main_t *vnm = vnet_get_main (); |
| 1163 | ip6_main_t *im = &ip6_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1164 | uword n_packets = frame->n_vectors; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1165 | u32 *from, *to_next; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1166 | u32 n_left_from, n_left_to_next, next_index, n_advertisements_sent; |
| 1167 | icmp6_neighbor_discovery_option_type_t option_type; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1168 | vlib_node_runtime_t *error_node = |
| 1169 | vlib_node_get_runtime (vm, ip6_icmp_input_node.index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1170 | int bogus_length; |
| 1171 | |
| 1172 | from = vlib_frame_vector_args (frame); |
| 1173 | n_left_from = n_packets; |
| 1174 | next_index = node->cached_next_index; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1175 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1176 | if (node->flags & VLIB_NODE_FLAG_TRACE) |
| 1177 | vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors, |
| 1178 | /* stride */ 1, |
| 1179 | sizeof (icmp6_input_trace_t)); |
| 1180 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1181 | option_type = |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1182 | (is_solicitation |
| 1183 | ? ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address |
| 1184 | : ICMP6_NEIGHBOR_DISCOVERY_OPTION_target_link_layer_address); |
| 1185 | n_advertisements_sent = 0; |
| 1186 | |
| 1187 | while (n_left_from > 0) |
| 1188 | { |
| 1189 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
| 1190 | |
| 1191 | while (n_left_from > 0 && n_left_to_next > 0) |
| 1192 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1193 | vlib_buffer_t *p0; |
| 1194 | ip6_header_t *ip0; |
| 1195 | icmp6_neighbor_solicitation_or_advertisement_header_t *h0; |
| 1196 | icmp6_neighbor_discovery_ethernet_link_layer_address_option_t *o0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1197 | u32 bi0, options_len0, sw_if_index0, next0, error0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1198 | u32 ip6_sadd_link_local, ip6_sadd_unspecified; |
| 1199 | int is_rewrite0; |
| 1200 | u32 ni0; |
| 1201 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1202 | bi0 = to_next[0] = from[0]; |
| 1203 | |
| 1204 | from += 1; |
| 1205 | to_next += 1; |
| 1206 | n_left_from -= 1; |
| 1207 | n_left_to_next -= 1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1208 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1209 | p0 = vlib_get_buffer (vm, bi0); |
| 1210 | ip0 = vlib_buffer_get_current (p0); |
| 1211 | h0 = ip6_next_header (ip0); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1212 | options_len0 = |
| 1213 | clib_net_to_host_u16 (ip0->payload_length) - sizeof (h0[0]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1214 | |
| 1215 | error0 = ICMP6_ERROR_NONE; |
| 1216 | sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1217 | ip6_sadd_link_local = |
| 1218 | ip6_address_is_link_local_unicast (&ip0->src_address); |
| 1219 | ip6_sadd_unspecified = |
| 1220 | ip6_address_is_unspecified (&ip0->src_address); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1221 | |
| 1222 | /* Check that source address is unspecified, link-local or else on-link. */ |
| 1223 | if (!ip6_sadd_unspecified && !ip6_sadd_link_local) |
| 1224 | { |
| 1225 | u32 src_adj_index0 = ip6_src_lookup_for_packet (im, p0, ip0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1226 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1227 | if (ADJ_INDEX_INVALID != src_adj_index0) |
| 1228 | { |
Neale Ranns | 107e7d4 | 2017-04-11 09:55:19 -0700 | [diff] [blame] | 1229 | ip_adjacency_t *adj0 = adj_get (src_adj_index0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1230 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1231 | /* Allow all realistic-looking rewrite adjacencies to pass */ |
| 1232 | ni0 = adj0->lookup_next_index; |
| 1233 | is_rewrite0 = (ni0 >= IP_LOOKUP_NEXT_ARP) && |
| 1234 | (ni0 < IP6_LOOKUP_N_NEXT); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1235 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1236 | error0 = ((adj0->rewrite_header.sw_if_index != sw_if_index0 |
| 1237 | || !is_rewrite0) |
| 1238 | ? |
| 1239 | ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_NOT_ON_LINK |
| 1240 | : error0); |
| 1241 | } |
| 1242 | else |
| 1243 | { |
| 1244 | error0 = |
| 1245 | ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_NOT_ON_LINK; |
| 1246 | } |
| 1247 | } |
| 1248 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1249 | o0 = (void *) (h0 + 1); |
| 1250 | o0 = ((options_len0 == 8 && o0->header.type == option_type |
| 1251 | && o0->header.n_data_u64s == 1) ? o0 : 0); |
| 1252 | |
| 1253 | /* If src address unspecified or link local, donot learn neighbor MAC */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1254 | if (PREDICT_TRUE (error0 == ICMP6_ERROR_NONE && o0 != 0 && |
Neale Ranns | 2a3ea49 | 2017-04-19 05:24:40 -0700 | [diff] [blame] | 1255 | !ip6_sadd_unspecified)) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1256 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1257 | vnet_set_ip6_ethernet_neighbor (vm, sw_if_index0, |
| 1258 | is_solicitation ? |
| 1259 | &ip0->src_address : |
| 1260 | &h0->target_address, |
| 1261 | o0->ethernet_address, |
| 1262 | sizeof (o0->ethernet_address), |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 1263 | 0, 0); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1264 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1265 | |
| 1266 | if (is_solicitation && error0 == ICMP6_ERROR_NONE) |
| 1267 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1268 | /* Check that target address is local to this router. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1269 | fib_node_index_t fei; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1270 | u32 fib_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1271 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1272 | fib_index = |
| 1273 | ip6_fib_table_get_index_for_sw_if_index (sw_if_index0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1274 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1275 | if (~0 == fib_index) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1276 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1277 | error0 = ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_UNKNOWN; |
| 1278 | } |
| 1279 | else |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1280 | { |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 1281 | if (ip6_address_is_link_local_unicast (&h0->target_address)) |
| 1282 | { |
| 1283 | fei = ip6_fib_table_lookup_exact_match |
| 1284 | (ip6_ll_fib_get (sw_if_index0), |
| 1285 | &h0->target_address, 128); |
| 1286 | } |
| 1287 | else |
| 1288 | { |
| 1289 | fei = ip6_fib_table_lookup_exact_match (fib_index, |
| 1290 | &h0->target_address, |
| 1291 | 128); |
| 1292 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1293 | |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1294 | if (FIB_NODE_INDEX_INVALID == fei) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1295 | { |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1296 | /* The target address is not in the FIB */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1297 | error0 = |
| 1298 | ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_UNKNOWN; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1299 | } |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1300 | else |
| 1301 | { |
| 1302 | if (FIB_ENTRY_FLAG_LOCAL & |
| 1303 | fib_entry_get_flags_for_source (fei, |
| 1304 | FIB_SOURCE_INTERFACE)) |
| 1305 | { |
| 1306 | /* It's an address that belongs to one of our interfaces |
| 1307 | * that's good. */ |
| 1308 | } |
| 1309 | else |
| 1310 | if (fib_entry_is_sourced |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 1311 | (fei, FIB_SOURCE_IP6_ND_PROXY) || |
| 1312 | fib_entry_is_sourced (fei, FIB_SOURCE_IP6_ND)) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1313 | { |
| 1314 | /* The address was added by IPv6 Proxy ND config. |
| 1315 | * We should only respond to these if the NS arrived on |
| 1316 | * the link that has a matching covering prefix */ |
| 1317 | } |
| 1318 | else |
| 1319 | { |
| 1320 | error0 = |
| 1321 | ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_UNKNOWN; |
| 1322 | } |
| 1323 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1324 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1325 | } |
| 1326 | |
| 1327 | if (is_solicitation) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1328 | next0 = (error0 != ICMP6_ERROR_NONE |
| 1329 | ? ICMP6_NEIGHBOR_SOLICITATION_NEXT_DROP |
| 1330 | : ICMP6_NEIGHBOR_SOLICITATION_NEXT_REPLY); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1331 | else |
| 1332 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1333 | next0 = 0; |
| 1334 | error0 = error0 == ICMP6_ERROR_NONE ? |
| 1335 | ICMP6_ERROR_NEIGHBOR_ADVERTISEMENTS_RX : error0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1336 | } |
| 1337 | |
| 1338 | if (is_solicitation && error0 == ICMP6_ERROR_NONE) |
| 1339 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1340 | vnet_sw_interface_t *sw_if0; |
| 1341 | ethernet_interface_t *eth_if0; |
| 1342 | ethernet_header_t *eth0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1343 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1344 | /* dst address is either source address or the all-nodes mcast addr */ |
| 1345 | if (!ip6_sadd_unspecified) |
| 1346 | ip0->dst_address = ip0->src_address; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1347 | else |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1348 | ip6_set_reserved_multicast_address (&ip0->dst_address, |
| 1349 | IP6_MULTICAST_SCOPE_link_local, |
| 1350 | IP6_MULTICAST_GROUP_ID_all_hosts); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1351 | |
| 1352 | ip0->src_address = h0->target_address; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1353 | ip0->hop_limit = 255; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1354 | h0->icmp.type = ICMP6_neighbor_advertisement; |
| 1355 | |
| 1356 | sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index0); |
| 1357 | ASSERT (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1358 | eth_if0 = |
| 1359 | ethernet_get_interface (ðernet_main, sw_if0->hw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1360 | if (eth_if0 && o0) |
| 1361 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1362 | clib_memcpy (o0->ethernet_address, eth_if0->address, 6); |
| 1363 | o0->header.type = |
| 1364 | ICMP6_NEIGHBOR_DISCOVERY_OPTION_target_link_layer_address; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | h0->advertisement_flags = clib_host_to_net_u32 |
| 1368 | (ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_SOLICITED |
| 1369 | | ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_OVERRIDE); |
| 1370 | |
| 1371 | h0->icmp.checksum = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1372 | h0->icmp.checksum = |
| 1373 | ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip0, |
| 1374 | &bogus_length); |
| 1375 | ASSERT (bogus_length == 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1376 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1377 | /* Reuse current MAC header, copy SMAC to DMAC and |
| 1378 | * interface MAC to SMAC */ |
| 1379 | vlib_buffer_advance (p0, -ethernet_buffer_header_size (p0)); |
| 1380 | eth0 = vlib_buffer_get_current (p0); |
| 1381 | clib_memcpy (eth0->dst_address, eth0->src_address, 6); |
| 1382 | if (eth_if0) |
| 1383 | clib_memcpy (eth0->src_address, eth_if0->address, 6); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1384 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1385 | /* Setup input and output sw_if_index for packet */ |
| 1386 | ASSERT (vnet_buffer (p0)->sw_if_index[VLIB_RX] == sw_if_index0); |
| 1387 | vnet_buffer (p0)->sw_if_index[VLIB_TX] = sw_if_index0; |
| 1388 | vnet_buffer (p0)->sw_if_index[VLIB_RX] = |
| 1389 | vnet_main.local_interface_sw_if_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1390 | |
| 1391 | n_advertisements_sent++; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1392 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1393 | |
| 1394 | p0->error = error_node->errors[error0]; |
| 1395 | |
| 1396 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 1397 | to_next, n_left_to_next, |
| 1398 | bi0, next0); |
| 1399 | } |
| 1400 | |
| 1401 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 1402 | } |
| 1403 | |
| 1404 | /* Account for advertisements sent. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1405 | vlib_error_count (vm, error_node->node_index, |
| 1406 | ICMP6_ERROR_NEIGHBOR_ADVERTISEMENTS_TX, |
| 1407 | n_advertisements_sent); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1408 | |
| 1409 | return frame->n_vectors; |
| 1410 | } |
| 1411 | |
| 1412 | /* for "syslogging" - use elog for now */ |
| 1413 | #define foreach_log_level \ |
| 1414 | _ (DEBUG, "DEBUG") \ |
| 1415 | _ (INFO, "INFORMATION") \ |
| 1416 | _ (NOTICE, "NOTICE") \ |
| 1417 | _ (WARNING, "WARNING") \ |
| 1418 | _ (ERR, "ERROR") \ |
| 1419 | _ (CRIT, "CRITICAL") \ |
| 1420 | _ (ALERT, "ALERT") \ |
| 1421 | _ (EMERG, "EMERGENCY") |
| 1422 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1423 | typedef enum |
| 1424 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1425 | #define _(f,s) LOG_##f, |
| 1426 | foreach_log_level |
| 1427 | #undef _ |
| 1428 | } log_level_t; |
| 1429 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1430 | static char *log_level_strings[] = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1431 | #define _(f,s) s, |
| 1432 | foreach_log_level |
| 1433 | #undef _ |
| 1434 | }; |
| 1435 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1436 | static int logmask = 1 << LOG_DEBUG; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1437 | |
| 1438 | static void |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1439 | ip6_neighbor_syslog (vlib_main_t * vm, int priority, char *fmt, ...) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1440 | { |
| 1441 | /* just use elog for now */ |
| 1442 | u8 *what; |
| 1443 | va_list va; |
| 1444 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1445 | if ((priority > LOG_EMERG) || !(logmask & (1 << priority))) |
| 1446 | return; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1447 | |
| 1448 | va_start (va, fmt); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1449 | if (fmt) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1450 | { |
| 1451 | what = va_format (0, fmt, &va); |
| 1452 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1453 | ELOG_TYPE_DECLARE (e) = |
| 1454 | { |
| 1455 | .format = "ip6 nd: (%s): %s",.format_args = "T4T4",}; |
| 1456 | struct |
| 1457 | { |
| 1458 | u32 s[2]; |
| 1459 | } *ed; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1460 | ed = ELOG_DATA (&vm->elog_main, e); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1461 | ed->s[0] = elog_string (&vm->elog_main, log_level_strings[priority]); |
| 1462 | ed->s[1] = elog_string (&vm->elog_main, (char *) what); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1463 | } |
| 1464 | va_end (va); |
| 1465 | return; |
| 1466 | } |
| 1467 | |
Juraj Sloboda | 5257452 | 2018-05-03 10:03:50 +0200 | [diff] [blame] | 1468 | clib_error_t * |
| 1469 | call_ip6_neighbor_callbacks (void *data, |
| 1470 | _vnet_ip6_neighbor_function_list_elt_t * elt) |
| 1471 | { |
| 1472 | clib_error_t *error = 0; |
| 1473 | |
| 1474 | while (elt) |
| 1475 | { |
| 1476 | error = elt->fp (data); |
| 1477 | if (error) |
| 1478 | return error; |
| 1479 | elt = elt->next_ip6_neighbor_function; |
| 1480 | } |
| 1481 | |
| 1482 | return error; |
| 1483 | } |
| 1484 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1485 | /* ipv6 neighbor discovery - router advertisements */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1486 | typedef enum |
| 1487 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1488 | ICMP6_ROUTER_SOLICITATION_NEXT_DROP, |
| 1489 | ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_RW, |
| 1490 | ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_TX, |
| 1491 | ICMP6_ROUTER_SOLICITATION_N_NEXT, |
| 1492 | } icmp6_router_solicitation_or_advertisement_next_t; |
| 1493 | |
| 1494 | static_always_inline uword |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1495 | icmp6_router_solicitation (vlib_main_t * vm, |
| 1496 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1497 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1498 | vnet_main_t *vnm = vnet_get_main (); |
| 1499 | ip6_main_t *im = &ip6_main; |
| 1500 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1501 | uword n_packets = frame->n_vectors; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1502 | u32 *from, *to_next; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1503 | u32 n_left_from, n_left_to_next, next_index; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1504 | u32 n_advertisements_sent = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1505 | int bogus_length; |
| 1506 | |
| 1507 | icmp6_neighbor_discovery_option_type_t option_type; |
| 1508 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1509 | vlib_node_runtime_t *error_node = |
| 1510 | vlib_node_get_runtime (vm, ip6_icmp_input_node.index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1511 | |
| 1512 | from = vlib_frame_vector_args (frame); |
| 1513 | n_left_from = n_packets; |
| 1514 | next_index = node->cached_next_index; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1515 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1516 | if (node->flags & VLIB_NODE_FLAG_TRACE) |
| 1517 | vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors, |
| 1518 | /* stride */ 1, |
| 1519 | sizeof (icmp6_input_trace_t)); |
| 1520 | |
| 1521 | /* source may append his LL address */ |
| 1522 | option_type = ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address; |
| 1523 | |
| 1524 | while (n_left_from > 0) |
| 1525 | { |
| 1526 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1527 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1528 | while (n_left_from > 0 && n_left_to_next > 0) |
| 1529 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1530 | vlib_buffer_t *p0; |
| 1531 | ip6_header_t *ip0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1532 | ip6_radv_t *radv_info = 0; |
| 1533 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1534 | icmp6_neighbor_discovery_header_t *h0; |
| 1535 | icmp6_neighbor_discovery_ethernet_link_layer_address_option_t *o0; |
| 1536 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1537 | u32 bi0, options_len0, sw_if_index0, next0, error0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1538 | u32 is_solicitation = 1, is_dropped = 0; |
| 1539 | u32 is_unspecified, is_link_local; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1540 | |
| 1541 | bi0 = to_next[0] = from[0]; |
| 1542 | |
| 1543 | from += 1; |
| 1544 | to_next += 1; |
| 1545 | n_left_from -= 1; |
| 1546 | n_left_to_next -= 1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1547 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1548 | p0 = vlib_get_buffer (vm, bi0); |
| 1549 | ip0 = vlib_buffer_get_current (p0); |
| 1550 | h0 = ip6_next_header (ip0); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1551 | options_len0 = |
| 1552 | clib_net_to_host_u16 (ip0->payload_length) - sizeof (h0[0]); |
| 1553 | is_unspecified = ip6_address_is_unspecified (&ip0->src_address); |
| 1554 | is_link_local = |
| 1555 | ip6_address_is_link_local_unicast (&ip0->src_address); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1556 | |
| 1557 | error0 = ICMP6_ERROR_NONE; |
| 1558 | sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1559 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1560 | /* check if solicitation (not from nd_timer node) */ |
| 1561 | if (ip6_address_is_unspecified (&ip0->dst_address)) |
| 1562 | is_solicitation = 0; |
| 1563 | |
| 1564 | /* Check that source address is unspecified, link-local or else on-link. */ |
| 1565 | if (!is_unspecified && !is_link_local) |
| 1566 | { |
| 1567 | u32 src_adj_index0 = ip6_src_lookup_for_packet (im, p0, ip0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1568 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1569 | if (ADJ_INDEX_INVALID != src_adj_index0) |
| 1570 | { |
Neale Ranns | 107e7d4 | 2017-04-11 09:55:19 -0700 | [diff] [blame] | 1571 | ip_adjacency_t *adj0 = adj_get (src_adj_index0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1572 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1573 | error0 = (adj0->rewrite_header.sw_if_index != sw_if_index0 |
| 1574 | ? |
| 1575 | ICMP6_ERROR_ROUTER_SOLICITATION_SOURCE_NOT_ON_LINK |
| 1576 | : error0); |
| 1577 | } |
| 1578 | else |
| 1579 | { |
| 1580 | error0 = ICMP6_ERROR_ROUTER_SOLICITATION_SOURCE_NOT_ON_LINK; |
| 1581 | } |
| 1582 | } |
| 1583 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1584 | /* check for source LL option and process */ |
| 1585 | o0 = (void *) (h0 + 1); |
| 1586 | o0 = ((options_len0 == 8 |
| 1587 | && o0->header.type == option_type |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1588 | && o0->header.n_data_u64s == 1) ? o0 : 0); |
| 1589 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1590 | /* if src address unspecified IGNORE any options */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1591 | if (PREDICT_TRUE (error0 == ICMP6_ERROR_NONE && o0 != 0 && |
| 1592 | !is_unspecified && !is_link_local)) |
| 1593 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1594 | vnet_set_ip6_ethernet_neighbor (vm, sw_if_index0, |
| 1595 | &ip0->src_address, |
| 1596 | o0->ethernet_address, |
| 1597 | sizeof (o0->ethernet_address), |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 1598 | 0, 0); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1599 | } |
| 1600 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1601 | /* default is to drop */ |
| 1602 | next0 = ICMP6_ROUTER_SOLICITATION_NEXT_DROP; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1603 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1604 | if (error0 == ICMP6_ERROR_NONE) |
| 1605 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1606 | vnet_sw_interface_t *sw_if0; |
| 1607 | ethernet_interface_t *eth_if0; |
| 1608 | u32 adj_index0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1609 | |
| 1610 | sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index0); |
| 1611 | ASSERT (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1612 | eth_if0 = |
| 1613 | ethernet_get_interface (ðernet_main, sw_if0->hw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1614 | |
| 1615 | /* only support ethernet interface type for now */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1616 | error0 = |
| 1617 | (!eth_if0) ? ICMP6_ERROR_ROUTER_SOLICITATION_UNSUPPORTED_INTF |
| 1618 | : error0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1619 | |
| 1620 | if (error0 == ICMP6_ERROR_NONE) |
| 1621 | { |
| 1622 | u32 ri; |
| 1623 | |
| 1624 | /* adjust the sizeof the buffer to just include the ipv6 header */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1625 | p0->current_length -= |
| 1626 | (options_len0 + |
| 1627 | sizeof (icmp6_neighbor_discovery_header_t)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1628 | |
| 1629 | /* look up the radv_t information for this interface */ |
Neale Ranns | 8e25495 | 2018-04-25 05:40:48 -0700 | [diff] [blame] | 1630 | if (vec_len (nm->if_radv_pool_index_by_sw_if_index) > |
| 1631 | sw_if_index0) |
| 1632 | { |
| 1633 | ri = |
| 1634 | nm->if_radv_pool_index_by_sw_if_index[sw_if_index0]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1635 | |
Neale Ranns | 8e25495 | 2018-04-25 05:40:48 -0700 | [diff] [blame] | 1636 | if (ri != ~0) |
| 1637 | radv_info = pool_elt_at_index (nm->if_radv_pool, ri); |
| 1638 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1639 | |
| 1640 | error0 = |
| 1641 | ((!radv_info) ? |
| 1642 | ICMP6_ERROR_ROUTER_SOLICITATION_RADV_NOT_CONFIG : |
| 1643 | error0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1644 | |
| 1645 | if (error0 == ICMP6_ERROR_NONE) |
| 1646 | { |
| 1647 | f64 now = vlib_time_now (vm); |
| 1648 | |
| 1649 | /* for solicited adverts - need to rate limit */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1650 | if (is_solicitation) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1651 | { |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 1652 | if (0 != radv_info->last_radv_time && |
| 1653 | (now - radv_info->last_radv_time) < |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1654 | MIN_DELAY_BETWEEN_RAS) |
| 1655 | is_dropped = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1656 | else |
| 1657 | radv_info->last_radv_time = now; |
| 1658 | } |
| 1659 | |
| 1660 | /* send now */ |
| 1661 | icmp6_router_advertisement_header_t rh; |
| 1662 | |
| 1663 | rh.icmp.type = ICMP6_router_advertisement; |
| 1664 | rh.icmp.code = 0; |
| 1665 | rh.icmp.checksum = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1666 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1667 | rh.current_hop_limit = radv_info->curr_hop_limit; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1668 | rh.router_lifetime_in_sec = |
| 1669 | clib_host_to_net_u16 |
| 1670 | (radv_info->adv_router_lifetime_in_sec); |
| 1671 | rh. |
| 1672 | time_in_msec_between_retransmitted_neighbor_solicitations |
| 1673 | = |
| 1674 | clib_host_to_net_u32 (radv_info-> |
| 1675 | adv_time_in_msec_between_retransmitted_neighbor_solicitations); |
| 1676 | rh.neighbor_reachable_time_in_msec = |
| 1677 | clib_host_to_net_u32 (radv_info-> |
| 1678 | adv_neighbor_reachable_time_in_msec); |
| 1679 | |
| 1680 | rh.flags = |
| 1681 | (radv_info->adv_managed_flag) ? |
| 1682 | ICMP6_ROUTER_DISCOVERY_FLAG_ADDRESS_CONFIG_VIA_DHCP : |
| 1683 | 0; |
| 1684 | rh.flags |= |
| 1685 | ((radv_info->adv_other_flag) ? |
| 1686 | ICMP6_ROUTER_DISCOVERY_FLAG_OTHER_CONFIG_VIA_DHCP : |
| 1687 | 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1688 | |
| 1689 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1690 | u16 payload_length = |
| 1691 | sizeof (icmp6_router_advertisement_header_t); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1692 | |
Dave Barach | 3a63fc5 | 2019-01-07 09:15:47 -0500 | [diff] [blame^] | 1693 | if (vlib_buffer_add_data |
| 1694 | (vm, vlib_buffer_get_free_list_index |
| 1695 | (p0), &bi0, (void *) &rh, |
| 1696 | sizeof (icmp6_router_advertisement_header_t))) |
| 1697 | { |
| 1698 | /* buffer allocation failed, drop the pkt */ |
| 1699 | error0 = ICMP6_ERROR_ALLOC_FAILURE; |
| 1700 | goto drop0; |
| 1701 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1702 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1703 | if (radv_info->adv_link_layer_address) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1704 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1705 | icmp6_neighbor_discovery_ethernet_link_layer_address_option_t |
| 1706 | h; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1707 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1708 | h.header.type = |
| 1709 | ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1710 | h.header.n_data_u64s = 1; |
| 1711 | |
| 1712 | /* copy ll address */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1713 | clib_memcpy (&h.ethernet_address[0], |
| 1714 | eth_if0->address, 6); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1715 | |
Dave Barach | 3a63fc5 | 2019-01-07 09:15:47 -0500 | [diff] [blame^] | 1716 | if (vlib_buffer_add_data |
| 1717 | (vm, vlib_buffer_get_free_list_index |
| 1718 | (p0), &bi0, (void *) &h, |
| 1719 | sizeof |
| 1720 | (icmp6_neighbor_discovery_ethernet_link_layer_address_option_t))) |
| 1721 | { |
| 1722 | error0 = ICMP6_ERROR_ALLOC_FAILURE; |
| 1723 | goto drop0; |
| 1724 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1725 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1726 | payload_length += |
| 1727 | sizeof |
| 1728 | (icmp6_neighbor_discovery_ethernet_link_layer_address_option_t); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1729 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1730 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1731 | /* add MTU option */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1732 | if (radv_info->adv_link_mtu) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1733 | { |
| 1734 | icmp6_neighbor_discovery_mtu_option_t h; |
| 1735 | |
| 1736 | h.unused = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1737 | h.mtu = |
| 1738 | clib_host_to_net_u32 (radv_info->adv_link_mtu); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1739 | h.header.type = ICMP6_NEIGHBOR_DISCOVERY_OPTION_mtu; |
| 1740 | h.header.n_data_u64s = 1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1741 | |
| 1742 | payload_length += |
| 1743 | sizeof (icmp6_neighbor_discovery_mtu_option_t); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1744 | |
Dave Barach | 3a63fc5 | 2019-01-07 09:15:47 -0500 | [diff] [blame^] | 1745 | if (vlib_buffer_add_data |
| 1746 | (vm, vlib_buffer_get_free_list_index |
| 1747 | (p0), &bi0, (void *) &h, |
| 1748 | sizeof |
| 1749 | (icmp6_neighbor_discovery_mtu_option_t))) |
| 1750 | { |
| 1751 | error0 = ICMP6_ERROR_ALLOC_FAILURE; |
| 1752 | goto drop0; |
| 1753 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1754 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1755 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1756 | /* add advertised prefix options */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1757 | ip6_radv_prefix_t *pr_info; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1758 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1759 | /* *INDENT-OFF* */ |
| 1760 | pool_foreach (pr_info, radv_info->adv_prefixes_pool, |
| 1761 | ({ |
| 1762 | if(pr_info->enabled && |
| 1763 | (!pr_info->decrement_lifetime_flag |
| 1764 | || (pr_info->pref_lifetime_expires >0))) |
| 1765 | { |
| 1766 | /* advertise this prefix */ |
| 1767 | icmp6_neighbor_discovery_prefix_information_option_t h; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1768 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1769 | h.header.type = ICMP6_NEIGHBOR_DISCOVERY_OPTION_prefix_information; |
| 1770 | h.header.n_data_u64s = (sizeof(icmp6_neighbor_discovery_prefix_information_option_t) >> 3); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1771 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1772 | h.dst_address_length = pr_info->prefix_len; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1773 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1774 | h.flags = (pr_info->adv_on_link_flag) ? ICMP6_NEIGHBOR_DISCOVERY_PREFIX_INFORMATION_FLAG_ON_LINK : 0; |
| 1775 | h.flags |= (pr_info->adv_autonomous_flag) ? ICMP6_NEIGHBOR_DISCOVERY_PREFIX_INFORMATION_AUTO : 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1776 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1777 | if(radv_info->cease_radv && pr_info->deprecated_prefix_flag) |
| 1778 | { |
| 1779 | h.valid_time = clib_host_to_net_u32(MIN_ADV_VALID_LIFETIME); |
| 1780 | h.preferred_time = 0; |
| 1781 | } |
| 1782 | else |
| 1783 | { |
| 1784 | if(pr_info->decrement_lifetime_flag) |
| 1785 | { |
| 1786 | pr_info->adv_valid_lifetime_in_secs = ((pr_info->valid_lifetime_expires > now)) ? |
| 1787 | (pr_info->valid_lifetime_expires - now) : 0; |
| 1788 | |
| 1789 | pr_info->adv_pref_lifetime_in_secs = ((pr_info->pref_lifetime_expires > now)) ? |
| 1790 | (pr_info->pref_lifetime_expires - now) : 0; |
| 1791 | } |
| 1792 | |
| 1793 | h.valid_time = clib_host_to_net_u32(pr_info->adv_valid_lifetime_in_secs); |
| 1794 | h.preferred_time = clib_host_to_net_u32(pr_info->adv_pref_lifetime_in_secs) ; |
| 1795 | } |
| 1796 | h.unused = 0; |
| 1797 | |
| 1798 | clib_memcpy(&h.dst_address, &pr_info->prefix, sizeof(ip6_address_t)); |
| 1799 | |
| 1800 | payload_length += sizeof( icmp6_neighbor_discovery_prefix_information_option_t); |
| 1801 | |
Dave Barach | 3a63fc5 | 2019-01-07 09:15:47 -0500 | [diff] [blame^] | 1802 | if (vlib_buffer_add_data |
| 1803 | (vm, vlib_buffer_get_free_list_index (p0), |
| 1804 | &bi0, |
| 1805 | (void *)&h, |
| 1806 | sizeof(icmp6_neighbor_discovery_prefix_information_option_t))) |
| 1807 | { |
| 1808 | error0 = ICMP6_ERROR_ALLOC_FAILURE; |
| 1809 | goto drop0; |
| 1810 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1811 | |
| 1812 | } |
| 1813 | })); |
| 1814 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1815 | |
| 1816 | /* add additional options before here */ |
| 1817 | |
| 1818 | /* finish building the router advertisement... */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1819 | if (!is_unspecified && radv_info->send_unicast) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1820 | { |
| 1821 | ip0->dst_address = ip0->src_address; |
| 1822 | } |
| 1823 | else |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1824 | { |
| 1825 | /* target address is all-nodes mcast addr */ |
| 1826 | ip6_set_reserved_multicast_address |
| 1827 | (&ip0->dst_address, |
| 1828 | IP6_MULTICAST_SCOPE_link_local, |
| 1829 | IP6_MULTICAST_GROUP_ID_all_hosts); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1830 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1831 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1832 | /* source address MUST be the link-local address */ |
| 1833 | ip0->src_address = radv_info->link_local_address; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1834 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1835 | ip0->hop_limit = 255; |
| 1836 | ip0->payload_length = |
| 1837 | clib_host_to_net_u16 (payload_length); |
| 1838 | |
| 1839 | icmp6_router_advertisement_header_t *rh0 = |
| 1840 | (icmp6_router_advertisement_header_t *) (ip0 + 1); |
| 1841 | rh0->icmp.checksum = |
| 1842 | ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip0, |
| 1843 | &bogus_length); |
| 1844 | ASSERT (bogus_length == 0); |
| 1845 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1846 | /* setup output if and adjacency */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1847 | vnet_buffer (p0)->sw_if_index[VLIB_RX] = |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1848 | vnet_main.local_interface_sw_if_index; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1849 | |
| 1850 | if (is_solicitation) |
| 1851 | { |
| 1852 | ethernet_header_t *eth0; |
| 1853 | /* Reuse current MAC header, copy SMAC to DMAC and |
| 1854 | * interface MAC to SMAC */ |
| 1855 | vlib_buffer_reset (p0); |
| 1856 | eth0 = vlib_buffer_get_current (p0); |
| 1857 | clib_memcpy (eth0->dst_address, eth0->src_address, |
| 1858 | 6); |
| 1859 | clib_memcpy (eth0->src_address, eth_if0->address, |
| 1860 | 6); |
| 1861 | next0 = |
| 1862 | is_dropped ? next0 : |
| 1863 | ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_TX; |
| 1864 | vnet_buffer (p0)->sw_if_index[VLIB_TX] = |
| 1865 | sw_if_index0; |
| 1866 | } |
| 1867 | else |
| 1868 | { |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1869 | adj_index0 = radv_info->mcast_adj_index; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1870 | if (adj_index0 == 0) |
| 1871 | error0 = ICMP6_ERROR_DST_LOOKUP_MISS; |
| 1872 | else |
| 1873 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1874 | next0 = |
| 1875 | is_dropped ? next0 : |
| 1876 | ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_RW; |
| 1877 | vnet_buffer (p0)->ip.adj_index[VLIB_TX] = |
| 1878 | adj_index0; |
| 1879 | } |
| 1880 | } |
Damjan Marion | 213b5aa | 2017-07-13 21:19:27 +0200 | [diff] [blame] | 1881 | p0->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1882 | |
| 1883 | radv_info->n_solicitations_dropped += is_dropped; |
| 1884 | radv_info->n_solicitations_rcvd += is_solicitation; |
| 1885 | |
| 1886 | if ((error0 == ICMP6_ERROR_NONE) && !is_dropped) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1887 | { |
| 1888 | radv_info->n_advertisements_sent++; |
| 1889 | n_advertisements_sent++; |
| 1890 | } |
| 1891 | } |
| 1892 | } |
| 1893 | } |
| 1894 | |
Dave Barach | 3a63fc5 | 2019-01-07 09:15:47 -0500 | [diff] [blame^] | 1895 | drop0: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1896 | p0->error = error_node->errors[error0]; |
| 1897 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1898 | if (error0 != ICMP6_ERROR_NONE) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1899 | vlib_error_count (vm, error_node->node_index, error0, 1); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1900 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1901 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 1902 | to_next, n_left_to_next, |
| 1903 | bi0, next0); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1904 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1905 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1906 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1907 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 1908 | } |
| 1909 | |
| 1910 | /* Account for router advertisements sent. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1911 | vlib_error_count (vm, error_node->node_index, |
| 1912 | ICMP6_ERROR_ROUTER_ADVERTISEMENTS_TX, |
| 1913 | n_advertisements_sent); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1914 | |
| 1915 | return frame->n_vectors; |
| 1916 | } |
| 1917 | |
| 1918 | /* validate advertised info for consistancy (see RFC-4861 section 6.2.7) - log any inconsistencies, packet will always be dropped */ |
| 1919 | static_always_inline uword |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1920 | icmp6_router_advertisement (vlib_main_t * vm, |
| 1921 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1922 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1923 | vnet_main_t *vnm = vnet_get_main (); |
| 1924 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1925 | uword n_packets = frame->n_vectors; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1926 | u32 *from, *to_next; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1927 | u32 n_left_from, n_left_to_next, next_index; |
| 1928 | u32 n_advertisements_rcvd = 0; |
| 1929 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1930 | vlib_node_runtime_t *error_node = |
| 1931 | vlib_node_get_runtime (vm, ip6_icmp_input_node.index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1932 | |
| 1933 | from = vlib_frame_vector_args (frame); |
| 1934 | n_left_from = n_packets; |
| 1935 | next_index = node->cached_next_index; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1936 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1937 | if (node->flags & VLIB_NODE_FLAG_TRACE) |
| 1938 | vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors, |
| 1939 | /* stride */ 1, |
| 1940 | sizeof (icmp6_input_trace_t)); |
| 1941 | |
| 1942 | while (n_left_from > 0) |
| 1943 | { |
| 1944 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1945 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1946 | while (n_left_from > 0 && n_left_to_next > 0) |
| 1947 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1948 | vlib_buffer_t *p0; |
| 1949 | ip6_header_t *ip0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1950 | ip6_radv_t *radv_info = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1951 | icmp6_router_advertisement_header_t *h0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1952 | u32 bi0, options_len0, sw_if_index0, next0, error0; |
| 1953 | |
| 1954 | bi0 = to_next[0] = from[0]; |
| 1955 | |
| 1956 | from += 1; |
| 1957 | to_next += 1; |
| 1958 | n_left_from -= 1; |
| 1959 | n_left_to_next -= 1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1960 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1961 | p0 = vlib_get_buffer (vm, bi0); |
| 1962 | ip0 = vlib_buffer_get_current (p0); |
| 1963 | h0 = ip6_next_header (ip0); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1964 | options_len0 = |
| 1965 | clib_net_to_host_u16 (ip0->payload_length) - sizeof (h0[0]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1966 | |
| 1967 | error0 = ICMP6_ERROR_NONE; |
| 1968 | sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX]; |
| 1969 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1970 | /* Check that source address is link-local */ |
| 1971 | error0 = (!ip6_address_is_link_local_unicast (&ip0->src_address)) ? |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1972 | ICMP6_ERROR_ROUTER_ADVERTISEMENT_SOURCE_NOT_LINK_LOCAL : error0; |
| 1973 | |
| 1974 | /* default is to drop */ |
| 1975 | next0 = ICMP6_ROUTER_SOLICITATION_NEXT_DROP; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1976 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1977 | n_advertisements_rcvd++; |
| 1978 | |
| 1979 | if (error0 == ICMP6_ERROR_NONE) |
| 1980 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1981 | vnet_sw_interface_t *sw_if0; |
| 1982 | ethernet_interface_t *eth_if0; |
| 1983 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1984 | sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index0); |
| 1985 | ASSERT (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1986 | eth_if0 = |
| 1987 | ethernet_get_interface (ðernet_main, sw_if0->hw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1988 | |
| 1989 | /* only support ethernet interface type for now */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1990 | error0 = |
| 1991 | (!eth_if0) ? ICMP6_ERROR_ROUTER_SOLICITATION_UNSUPPORTED_INTF |
| 1992 | : error0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1993 | |
| 1994 | if (error0 == ICMP6_ERROR_NONE) |
| 1995 | { |
| 1996 | u32 ri; |
| 1997 | |
| 1998 | /* look up the radv_t information for this interface */ |
Neale Ranns | 8e25495 | 2018-04-25 05:40:48 -0700 | [diff] [blame] | 1999 | if (vec_len (nm->if_radv_pool_index_by_sw_if_index) > |
| 2000 | sw_if_index0) |
| 2001 | { |
| 2002 | ri = |
| 2003 | nm->if_radv_pool_index_by_sw_if_index[sw_if_index0]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2004 | |
Neale Ranns | 8e25495 | 2018-04-25 05:40:48 -0700 | [diff] [blame] | 2005 | if (ri != ~0) |
| 2006 | radv_info = pool_elt_at_index (nm->if_radv_pool, ri); |
| 2007 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2008 | |
| 2009 | error0 = |
| 2010 | ((!radv_info) ? |
| 2011 | ICMP6_ERROR_ROUTER_SOLICITATION_RADV_NOT_CONFIG : |
| 2012 | error0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2013 | |
| 2014 | if (error0 == ICMP6_ERROR_NONE) |
| 2015 | { |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 2016 | radv_info->keep_sending_rs = 0; |
| 2017 | |
| 2018 | ra_report_t r; |
| 2019 | |
| 2020 | r.sw_if_index = sw_if_index0; |
| 2021 | memcpy (r.router_address, &ip0->src_address, 16); |
| 2022 | r.current_hop_limit = h0->current_hop_limit; |
| 2023 | r.flags = h0->flags; |
| 2024 | r.router_lifetime_in_sec = |
| 2025 | clib_net_to_host_u16 (h0->router_lifetime_in_sec); |
| 2026 | r.neighbor_reachable_time_in_msec = |
| 2027 | clib_net_to_host_u32 |
| 2028 | (h0->neighbor_reachable_time_in_msec); |
| 2029 | r.time_in_msec_between_retransmitted_neighbor_solicitations = clib_net_to_host_u32 (h0->time_in_msec_between_retransmitted_neighbor_solicitations); |
| 2030 | r.prefixes = 0; |
| 2031 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2032 | /* validate advertised information */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2033 | if ((h0->current_hop_limit && radv_info->curr_hop_limit) |
| 2034 | && (h0->current_hop_limit != |
| 2035 | radv_info->curr_hop_limit)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2036 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2037 | ip6_neighbor_syslog (vm, LOG_WARNING, |
| 2038 | "our AdvCurHopLimit on %U doesn't agree with %U", |
| 2039 | format_vnet_sw_if_index_name, |
| 2040 | vnm, sw_if_index0, |
| 2041 | format_ip6_address, |
| 2042 | &ip0->src_address); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2043 | } |
| 2044 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2045 | if ((h0->flags & |
| 2046 | ICMP6_ROUTER_DISCOVERY_FLAG_ADDRESS_CONFIG_VIA_DHCP) |
| 2047 | != radv_info->adv_managed_flag) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2048 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2049 | ip6_neighbor_syslog (vm, LOG_WARNING, |
| 2050 | "our AdvManagedFlag on %U doesn't agree with %U", |
| 2051 | format_vnet_sw_if_index_name, |
| 2052 | vnm, sw_if_index0, |
| 2053 | format_ip6_address, |
| 2054 | &ip0->src_address); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2055 | } |
| 2056 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2057 | if ((h0->flags & |
| 2058 | ICMP6_ROUTER_DISCOVERY_FLAG_OTHER_CONFIG_VIA_DHCP) |
| 2059 | != radv_info->adv_other_flag) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2060 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2061 | ip6_neighbor_syslog (vm, LOG_WARNING, |
| 2062 | "our AdvOtherConfigFlag on %U doesn't agree with %U", |
| 2063 | format_vnet_sw_if_index_name, |
| 2064 | vnm, sw_if_index0, |
| 2065 | format_ip6_address, |
| 2066 | &ip0->src_address); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2067 | } |
| 2068 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2069 | if ((h0-> |
| 2070 | time_in_msec_between_retransmitted_neighbor_solicitations |
| 2071 | && radv_info-> |
| 2072 | adv_time_in_msec_between_retransmitted_neighbor_solicitations) |
| 2073 | && (h0-> |
| 2074 | time_in_msec_between_retransmitted_neighbor_solicitations |
| 2075 | != |
| 2076 | clib_host_to_net_u32 (radv_info-> |
| 2077 | adv_time_in_msec_between_retransmitted_neighbor_solicitations))) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2078 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2079 | ip6_neighbor_syslog (vm, LOG_WARNING, |
| 2080 | "our AdvRetransTimer on %U doesn't agree with %U", |
| 2081 | format_vnet_sw_if_index_name, |
| 2082 | vnm, sw_if_index0, |
| 2083 | format_ip6_address, |
| 2084 | &ip0->src_address); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2085 | } |
| 2086 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2087 | if ((h0->neighbor_reachable_time_in_msec && |
| 2088 | radv_info->adv_neighbor_reachable_time_in_msec) && |
| 2089 | (h0->neighbor_reachable_time_in_msec != |
| 2090 | clib_host_to_net_u32 |
| 2091 | (radv_info->adv_neighbor_reachable_time_in_msec))) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2092 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2093 | ip6_neighbor_syslog (vm, LOG_WARNING, |
| 2094 | "our AdvReachableTime on %U doesn't agree with %U", |
| 2095 | format_vnet_sw_if_index_name, |
| 2096 | vnm, sw_if_index0, |
| 2097 | format_ip6_address, |
| 2098 | &ip0->src_address); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2099 | } |
| 2100 | |
| 2101 | /* check for MTU or prefix options or .. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2102 | u8 *opt_hdr = (u8 *) (h0 + 1); |
| 2103 | while (options_len0 > 0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2104 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2105 | icmp6_neighbor_discovery_option_header_t *o0 = |
| 2106 | (icmp6_neighbor_discovery_option_header_t *) |
| 2107 | opt_hdr; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2108 | int opt_len = o0->n_data_u64s << 3; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2109 | icmp6_neighbor_discovery_option_type_t option_type = |
| 2110 | o0->type; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2111 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2112 | if (options_len0 < 2) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2113 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2114 | ip6_neighbor_syslog (vm, LOG_ERR, |
| 2115 | "malformed RA packet on %U from %U", |
| 2116 | format_vnet_sw_if_index_name, |
| 2117 | vnm, sw_if_index0, |
| 2118 | format_ip6_address, |
| 2119 | &ip0->src_address); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2120 | break; |
| 2121 | } |
| 2122 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2123 | if (opt_len == 0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2124 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2125 | ip6_neighbor_syslog (vm, LOG_ERR, |
| 2126 | " zero length option in RA on %U from %U", |
| 2127 | format_vnet_sw_if_index_name, |
| 2128 | vnm, sw_if_index0, |
| 2129 | format_ip6_address, |
| 2130 | &ip0->src_address); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2131 | break; |
| 2132 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2133 | else if (opt_len > options_len0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2134 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2135 | ip6_neighbor_syslog (vm, LOG_ERR, |
| 2136 | "option length in RA packet greater than total length on %U from %U", |
| 2137 | format_vnet_sw_if_index_name, |
| 2138 | vnm, sw_if_index0, |
| 2139 | format_ip6_address, |
| 2140 | &ip0->src_address); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2141 | break; |
| 2142 | } |
| 2143 | |
| 2144 | options_len0 -= opt_len; |
| 2145 | opt_hdr += opt_len; |
| 2146 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2147 | switch (option_type) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2148 | { |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 2149 | case ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address: |
| 2150 | { |
| 2151 | icmp6_neighbor_discovery_ethernet_link_layer_address_option_t |
| 2152 | * h = |
| 2153 | (icmp6_neighbor_discovery_ethernet_link_layer_address_option_t |
| 2154 | *) (o0); |
| 2155 | |
| 2156 | if (opt_len < sizeof (*h)) |
| 2157 | break; |
| 2158 | |
| 2159 | memcpy (r.slla, h->ethernet_address, 6); |
| 2160 | } |
| 2161 | break; |
| 2162 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2163 | case ICMP6_NEIGHBOR_DISCOVERY_OPTION_mtu: |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2164 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2165 | icmp6_neighbor_discovery_mtu_option_t *h = |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2166 | (icmp6_neighbor_discovery_mtu_option_t |
| 2167 | *) (o0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2168 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2169 | if (opt_len < sizeof (*h)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2170 | break; |
| 2171 | |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 2172 | r.mtu = clib_net_to_host_u32 (h->mtu); |
| 2173 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2174 | if ((h->mtu && radv_info->adv_link_mtu) && |
| 2175 | (h->mtu != |
| 2176 | clib_host_to_net_u32 |
| 2177 | (radv_info->adv_link_mtu))) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2178 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2179 | ip6_neighbor_syslog (vm, LOG_WARNING, |
| 2180 | "our AdvLinkMTU on %U doesn't agree with %U", |
| 2181 | format_vnet_sw_if_index_name, |
| 2182 | vnm, sw_if_index0, |
| 2183 | format_ip6_address, |
| 2184 | &ip0->src_address); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2185 | } |
| 2186 | } |
| 2187 | break; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2188 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2189 | case ICMP6_NEIGHBOR_DISCOVERY_OPTION_prefix_information: |
| 2190 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2191 | icmp6_neighbor_discovery_prefix_information_option_t |
| 2192 | * h = |
| 2193 | (icmp6_neighbor_discovery_prefix_information_option_t |
| 2194 | *) (o0); |
| 2195 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2196 | /* validate advertised prefix options */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2197 | ip6_radv_prefix_t *pr_info; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2198 | u32 preferred, valid; |
| 2199 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2200 | if (opt_len < sizeof (*h)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2201 | break; |
| 2202 | |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 2203 | vec_validate (r.prefixes, |
| 2204 | vec_len (r.prefixes)); |
| 2205 | ra_report_prefix_info_t *prefix = |
| 2206 | vec_elt_at_index (r.prefixes, |
| 2207 | vec_len (r.prefixes) - 1); |
| 2208 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2209 | preferred = |
| 2210 | clib_net_to_host_u32 (h->preferred_time); |
| 2211 | valid = clib_net_to_host_u32 (h->valid_time); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2212 | |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 2213 | prefix->preferred_time = preferred; |
| 2214 | prefix->valid_time = valid; |
| 2215 | prefix->flags = h->flags & 0xc0; |
| 2216 | prefix->dst_address_length = |
| 2217 | h->dst_address_length; |
| 2218 | prefix->dst_address = h->dst_address; |
| 2219 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2220 | /* look for matching prefix - if we our advertising it, it better be consistant */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2221 | /* *INDENT-OFF* */ |
| 2222 | pool_foreach (pr_info, radv_info->adv_prefixes_pool, |
| 2223 | ({ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2224 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2225 | ip6_address_t mask; |
| 2226 | ip6_address_mask_from_width(&mask, pr_info->prefix_len); |
| 2227 | |
| 2228 | if(pr_info->enabled && |
| 2229 | (pr_info->prefix_len == h->dst_address_length) && |
| 2230 | ip6_address_is_equal_masked (&pr_info->prefix, &h->dst_address, &mask)) |
| 2231 | { |
| 2232 | /* found it */ |
| 2233 | if(!pr_info->decrement_lifetime_flag && |
| 2234 | valid != pr_info->adv_valid_lifetime_in_secs) |
| 2235 | { |
| 2236 | ip6_neighbor_syslog(vm, LOG_WARNING, |
| 2237 | "our ADV validlifetime on %U for %U does not agree with %U", |
| 2238 | format_vnet_sw_if_index_name, vnm, sw_if_index0,format_ip6_address, &pr_info->prefix, |
| 2239 | format_ip6_address, &h->dst_address); |
| 2240 | } |
| 2241 | if(!pr_info->decrement_lifetime_flag && |
| 2242 | preferred != pr_info->adv_pref_lifetime_in_secs) |
| 2243 | { |
| 2244 | ip6_neighbor_syslog(vm, LOG_WARNING, |
| 2245 | "our ADV preferredlifetime on %U for %U does not agree with %U", |
| 2246 | format_vnet_sw_if_index_name, vnm, sw_if_index0,format_ip6_address, &pr_info->prefix, |
| 2247 | format_ip6_address, &h->dst_address); |
| 2248 | } |
| 2249 | } |
| 2250 | break; |
| 2251 | })); |
| 2252 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2253 | break; |
| 2254 | } |
| 2255 | default: |
| 2256 | /* skip this one */ |
| 2257 | break; |
| 2258 | } |
| 2259 | } |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 2260 | ra_publish (&r); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2261 | } |
| 2262 | } |
| 2263 | } |
| 2264 | |
| 2265 | p0->error = error_node->errors[error0]; |
| 2266 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2267 | if (error0 != ICMP6_ERROR_NONE) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2268 | vlib_error_count (vm, error_node->node_index, error0, 1); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2269 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2270 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 2271 | to_next, n_left_to_next, |
| 2272 | bi0, next0); |
| 2273 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2274 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2275 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 2276 | } |
| 2277 | |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 2278 | /* Account for router advertisements received. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2279 | vlib_error_count (vm, error_node->node_index, |
| 2280 | ICMP6_ERROR_ROUTER_ADVERTISEMENTS_RX, |
| 2281 | n_advertisements_rcvd); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2282 | |
| 2283 | return frame->n_vectors; |
| 2284 | } |
| 2285 | |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 2286 | static inline f64 |
| 2287 | random_f64_from_to (f64 from, f64 to) |
| 2288 | { |
| 2289 | static u32 seed = 0; |
| 2290 | static u8 seed_set = 0; |
| 2291 | if (!seed_set) |
| 2292 | { |
| 2293 | seed = random_default_seed (); |
| 2294 | seed_set = 1; |
| 2295 | } |
| 2296 | return random_f64 (&seed) * (to - from) + from; |
| 2297 | } |
| 2298 | |
| 2299 | static inline u8 |
| 2300 | get_mac_address (u32 sw_if_index, u8 * address) |
| 2301 | { |
| 2302 | vnet_main_t *vnm = vnet_get_main (); |
| 2303 | vnet_hw_interface_t *hw_if = vnet_get_sup_hw_interface (vnm, sw_if_index); |
| 2304 | if (!hw_if->hw_address) |
| 2305 | return 1; |
| 2306 | clib_memcpy (address, hw_if->hw_address, 6); |
| 2307 | return 0; |
| 2308 | } |
| 2309 | |
| 2310 | static inline vlib_buffer_t * |
| 2311 | create_buffer_for_rs (vlib_main_t * vm, ip6_radv_t * radv_info) |
| 2312 | { |
| 2313 | u32 bi0; |
| 2314 | vlib_buffer_t *p0; |
| 2315 | vlib_buffer_free_list_t *fl; |
| 2316 | icmp6_router_solicitation_header_t *rh; |
| 2317 | u16 payload_length; |
| 2318 | int bogus_length; |
| 2319 | u32 sw_if_index; |
| 2320 | |
| 2321 | sw_if_index = radv_info->sw_if_index; |
| 2322 | |
| 2323 | if (vlib_buffer_alloc (vm, &bi0, 1) != 1) |
| 2324 | { |
| 2325 | clib_warning ("buffer allocation failure"); |
| 2326 | return 0; |
| 2327 | } |
| 2328 | |
| 2329 | p0 = vlib_get_buffer (vm, bi0); |
| 2330 | fl = vlib_buffer_get_free_list (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX); |
| 2331 | vlib_buffer_init_for_free_list (p0, fl); |
| 2332 | VLIB_BUFFER_TRACE_TRAJECTORY_INIT (p0); |
| 2333 | p0->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED; |
| 2334 | |
| 2335 | vnet_buffer (p0)->sw_if_index[VLIB_RX] = sw_if_index; |
| 2336 | vnet_buffer (p0)->sw_if_index[VLIB_TX] = sw_if_index; |
| 2337 | |
| 2338 | vnet_buffer (p0)->ip.adj_index[VLIB_TX] = radv_info->mcast_adj_index; |
| 2339 | |
| 2340 | rh = vlib_buffer_get_current (p0); |
| 2341 | p0->current_length = sizeof (*rh); |
| 2342 | |
| 2343 | rh->neighbor.icmp.type = ICMP6_router_solicitation; |
| 2344 | rh->neighbor.icmp.code = 0; |
| 2345 | rh->neighbor.icmp.checksum = 0; |
| 2346 | rh->neighbor.reserved_must_be_zero = 0; |
| 2347 | |
| 2348 | rh->link_layer_option.header.type = |
| 2349 | ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address; |
| 2350 | if (0 != get_mac_address (sw_if_index, |
| 2351 | rh->link_layer_option.ethernet_address)) |
| 2352 | { |
| 2353 | clib_warning ("interface with sw_if_index %u has no mac address", |
| 2354 | sw_if_index); |
| 2355 | vlib_buffer_free (vm, &bi0, 1); |
| 2356 | return 0; |
| 2357 | } |
| 2358 | rh->link_layer_option.header.n_data_u64s = 1; |
| 2359 | |
| 2360 | payload_length = sizeof (rh->neighbor) + sizeof (u64); |
| 2361 | |
| 2362 | rh->ip.ip_version_traffic_class_and_flow_label = |
| 2363 | clib_host_to_net_u32 (0x6 << 28); |
| 2364 | rh->ip.payload_length = clib_host_to_net_u16 (payload_length); |
| 2365 | rh->ip.protocol = IP_PROTOCOL_ICMP6; |
| 2366 | rh->ip.hop_limit = 255; |
| 2367 | rh->ip.src_address = radv_info->link_local_address; |
| 2368 | /* set address ff02::2 */ |
David Johnson | d9818dd | 2018-12-14 14:53:41 -0500 | [diff] [blame] | 2369 | rh->ip.dst_address.as_u64[0] = clib_host_to_net_u64 (0xff02ULL << 48); |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 2370 | rh->ip.dst_address.as_u64[1] = clib_host_to_net_u64 (2); |
| 2371 | |
| 2372 | rh->neighbor.icmp.checksum = ip6_tcp_udp_icmp_compute_checksum (vm, p0, |
| 2373 | &rh->ip, |
| 2374 | &bogus_length); |
| 2375 | |
| 2376 | return p0; |
| 2377 | } |
| 2378 | |
| 2379 | static inline void |
| 2380 | stop_sending_rs (vlib_main_t * vm, ip6_radv_t * ra) |
| 2381 | { |
| 2382 | u32 bi0; |
| 2383 | |
| 2384 | ra->keep_sending_rs = 0; |
| 2385 | if (ra->buffer) |
| 2386 | { |
| 2387 | bi0 = vlib_get_buffer_index (vm, ra->buffer); |
| 2388 | vlib_buffer_free (vm, &bi0, 1); |
| 2389 | ra->buffer = 0; |
| 2390 | } |
| 2391 | } |
| 2392 | |
| 2393 | static inline bool |
| 2394 | check_send_rs (vlib_main_t * vm, ip6_radv_t * radv_info, f64 current_time, |
| 2395 | f64 * due_time) |
| 2396 | { |
| 2397 | vlib_buffer_t *p0; |
| 2398 | vlib_frame_t *f; |
| 2399 | u32 *to_next; |
| 2400 | u32 next_index; |
| 2401 | vlib_buffer_t *c0; |
| 2402 | u32 ci0; |
| 2403 | |
| 2404 | icmp6_send_router_solicitation_params_t *params; |
| 2405 | |
| 2406 | if (!radv_info->keep_sending_rs) |
| 2407 | return false; |
| 2408 | |
| 2409 | params = &radv_info->params; |
| 2410 | |
| 2411 | if (radv_info->due_time > current_time) |
| 2412 | { |
| 2413 | *due_time = radv_info->due_time; |
| 2414 | return true; |
| 2415 | } |
| 2416 | |
| 2417 | p0 = radv_info->buffer; |
| 2418 | |
| 2419 | next_index = ip6_rewrite_mcast_node.index; |
| 2420 | |
| 2421 | c0 = vlib_buffer_copy (vm, p0); |
| 2422 | ci0 = vlib_get_buffer_index (vm, c0); |
| 2423 | |
| 2424 | f = vlib_get_frame_to_node (vm, next_index); |
| 2425 | to_next = vlib_frame_vector_args (f); |
| 2426 | to_next[0] = ci0; |
| 2427 | f->n_vectors = 1; |
| 2428 | vlib_put_frame_to_node (vm, next_index, f); |
| 2429 | |
| 2430 | if (params->mrc != 0 && --radv_info->n_left == 0) |
| 2431 | stop_sending_rs (vm, radv_info); |
| 2432 | else |
| 2433 | { |
| 2434 | radv_info->sleep_interval = |
| 2435 | (2 + random_f64_from_to (-0.1, 0.1)) * radv_info->sleep_interval; |
| 2436 | if (radv_info->sleep_interval > params->mrt) |
| 2437 | radv_info->sleep_interval = |
| 2438 | (1 + random_f64_from_to (-0.1, 0.1)) * params->mrt; |
| 2439 | |
| 2440 | radv_info->due_time = current_time + radv_info->sleep_interval; |
| 2441 | |
| 2442 | if (params->mrd != 0 |
| 2443 | && current_time > radv_info->start_time + params->mrd) |
| 2444 | stop_sending_rs (vm, radv_info); |
| 2445 | else |
| 2446 | *due_time = radv_info->due_time; |
| 2447 | } |
| 2448 | |
| 2449 | return radv_info->keep_sending_rs; |
| 2450 | } |
| 2451 | |
| 2452 | static uword |
| 2453 | send_rs_process (vlib_main_t * vm, vlib_node_runtime_t * rt, |
| 2454 | vlib_frame_t * f0) |
| 2455 | { |
| 2456 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 2457 | ip6_radv_t *radv_info; |
| 2458 | uword *event_data = 0; |
| 2459 | f64 sleep_time = 1e9; |
| 2460 | f64 current_time; |
| 2461 | f64 due_time; |
| 2462 | f64 dt = 0; |
| 2463 | |
| 2464 | while (true) |
| 2465 | { |
| 2466 | vlib_process_wait_for_event_or_clock (vm, sleep_time); |
| 2467 | vlib_process_get_events (vm, &event_data); |
| 2468 | vec_reset_length (event_data); |
| 2469 | |
| 2470 | current_time = vlib_time_now (vm); |
| 2471 | do |
| 2472 | { |
| 2473 | due_time = current_time + 1e9; |
| 2474 | /* *INDENT-OFF* */ |
| 2475 | pool_foreach (radv_info, nm->if_radv_pool, |
| 2476 | ({ |
| 2477 | if (check_send_rs (vm, radv_info, current_time, &dt) |
| 2478 | && (dt < due_time)) |
| 2479 | due_time = dt; |
| 2480 | })); |
| 2481 | /* *INDENT-ON* */ |
| 2482 | current_time = vlib_time_now (vm); |
| 2483 | } |
| 2484 | while (due_time < current_time); |
| 2485 | |
| 2486 | sleep_time = due_time - current_time; |
| 2487 | } |
| 2488 | |
| 2489 | return 0; |
| 2490 | } |
| 2491 | |
| 2492 | /* *INDENT-OFF* */ |
| 2493 | VLIB_REGISTER_NODE (send_rs_process_node) = { |
| 2494 | .function = send_rs_process, |
| 2495 | .type = VLIB_NODE_TYPE_PROCESS, |
| 2496 | .name = "send-rs-process", |
| 2497 | }; |
| 2498 | /* *INDENT-ON* */ |
| 2499 | |
| 2500 | void |
| 2501 | icmp6_send_router_solicitation (vlib_main_t * vm, u32 sw_if_index, u8 stop, |
| 2502 | icmp6_send_router_solicitation_params_t * |
| 2503 | params) |
| 2504 | { |
| 2505 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 2506 | u32 rai; |
| 2507 | ip6_radv_t *ra = 0; |
| 2508 | |
| 2509 | ASSERT (~0 != sw_if_index); |
| 2510 | |
| 2511 | rai = nm->if_radv_pool_index_by_sw_if_index[sw_if_index]; |
| 2512 | ra = pool_elt_at_index (nm->if_radv_pool, rai); |
| 2513 | |
Juraj Sloboda | 5257452 | 2018-05-03 10:03:50 +0200 | [diff] [blame] | 2514 | stop_sending_rs (vm, ra); |
| 2515 | |
| 2516 | if (!stop) |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 2517 | { |
| 2518 | ra->keep_sending_rs = 1; |
| 2519 | ra->params = *params; |
| 2520 | ra->n_left = params->mrc; |
| 2521 | ra->start_time = vlib_time_now (vm); |
| 2522 | ra->sleep_interval = (1 + random_f64_from_to (-0.1, 0.1)) * params->irt; |
| 2523 | ra->due_time = 0; /* send first packet ASAP */ |
| 2524 | ra->buffer = create_buffer_for_rs (vm, ra); |
| 2525 | if (!ra->buffer) |
| 2526 | ra->keep_sending_rs = 0; |
| 2527 | else |
| 2528 | vlib_process_signal_event (vm, send_rs_process_node.index, 1, 0); |
| 2529 | } |
| 2530 | } |
| 2531 | |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 2532 | /** |
| 2533 | * @brief Add a multicast Address to the advertised MLD set |
| 2534 | */ |
| 2535 | static void |
| 2536 | ip6_neighbor_add_mld_prefix (ip6_radv_t * radv_info, ip6_address_t * addr) |
| 2537 | { |
| 2538 | ip6_mldp_group_t *mcast_group_info; |
| 2539 | uword *p; |
| 2540 | |
| 2541 | /* lookup mldp info for this interface */ |
Neale Ranns | e0a3544 | 2018-02-25 10:39:02 -0800 | [diff] [blame] | 2542 | p = mhash_get (&radv_info->address_to_mldp_index, addr); |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 2543 | mcast_group_info = |
| 2544 | p ? pool_elt_at_index (radv_info->mldp_group_pool, p[0]) : 0; |
| 2545 | |
| 2546 | /* add address */ |
| 2547 | if (!mcast_group_info) |
| 2548 | { |
| 2549 | /* add */ |
| 2550 | u32 mi; |
| 2551 | pool_get (radv_info->mldp_group_pool, mcast_group_info); |
| 2552 | |
| 2553 | mi = mcast_group_info - radv_info->mldp_group_pool; |
Neale Ranns | e0a3544 | 2018-02-25 10:39:02 -0800 | [diff] [blame] | 2554 | mhash_set (&radv_info->address_to_mldp_index, addr, mi, /* old_value */ |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 2555 | 0); |
| 2556 | |
| 2557 | mcast_group_info->type = 4; |
| 2558 | mcast_group_info->mcast_source_address_pool = 0; |
| 2559 | mcast_group_info->num_sources = 0; |
Neale Ranns | e0a3544 | 2018-02-25 10:39:02 -0800 | [diff] [blame] | 2560 | clib_memcpy (&mcast_group_info->mcast_address, addr, |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 2561 | sizeof (ip6_address_t)); |
| 2562 | } |
| 2563 | } |
| 2564 | |
| 2565 | /** |
| 2566 | * @brief Delete a multicast Address from the advertised MLD set |
| 2567 | */ |
| 2568 | static void |
| 2569 | ip6_neighbor_del_mld_prefix (ip6_radv_t * radv_info, ip6_address_t * addr) |
| 2570 | { |
| 2571 | ip6_mldp_group_t *mcast_group_info; |
| 2572 | uword *p; |
| 2573 | |
| 2574 | p = mhash_get (&radv_info->address_to_mldp_index, &addr); |
| 2575 | mcast_group_info = |
| 2576 | p ? pool_elt_at_index (radv_info->mldp_group_pool, p[0]) : 0; |
| 2577 | |
| 2578 | if (mcast_group_info) |
| 2579 | { |
| 2580 | mhash_unset (&radv_info->address_to_mldp_index, &addr, |
| 2581 | /* old_value */ 0); |
| 2582 | pool_put (radv_info->mldp_group_pool, mcast_group_info); |
| 2583 | } |
| 2584 | } |
| 2585 | |
| 2586 | /** |
| 2587 | * @brief Add a multicast Address to the advertised MLD set |
| 2588 | */ |
| 2589 | static void |
| 2590 | ip6_neighbor_add_mld_grp (ip6_radv_t * a, |
| 2591 | ip6_multicast_address_scope_t scope, |
| 2592 | ip6_multicast_link_local_group_id_t group) |
| 2593 | { |
| 2594 | ip6_address_t addr; |
| 2595 | |
| 2596 | ip6_set_reserved_multicast_address (&addr, scope, group); |
| 2597 | |
| 2598 | ip6_neighbor_add_mld_prefix (a, &addr); |
| 2599 | } |
| 2600 | |
| 2601 | /** |
| 2602 | * @brief create and initialize router advertisement parameters with default |
| 2603 | * values for this intfc |
| 2604 | */ |
Pavel Kotucek | 9f5a2b6 | 2017-06-14 13:56:55 +0200 | [diff] [blame] | 2605 | u32 |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2606 | ip6_neighbor_sw_interface_add_del (vnet_main_t * vnm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2607 | u32 sw_if_index, u32 is_add) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2608 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2609 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 2610 | ip6_radv_t *a = 0; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2611 | u32 ri = ~0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2612 | vnet_sw_interface_t *sw_if0; |
| 2613 | ethernet_interface_t *eth_if0 = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2614 | |
| 2615 | /* lookup radv container - ethernet interfaces only */ |
| 2616 | sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2617 | if (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2618 | eth_if0 = ethernet_get_interface (ðernet_main, sw_if0->hw_if_index); |
| 2619 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2620 | if (!eth_if0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2621 | return ri; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2622 | |
| 2623 | vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index, |
| 2624 | ~0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2625 | ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index]; |
| 2626 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2627 | if (ri != ~0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2628 | { |
| 2629 | a = pool_elt_at_index (nm->if_radv_pool, ri); |
| 2630 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2631 | if (!is_add) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2632 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2633 | ip6_radv_prefix_t *p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2634 | ip6_mldp_group_t *m; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2635 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2636 | /* release the lock on the interface's mcast adj */ |
| 2637 | adj_unlock (a->mcast_adj_index); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2638 | |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 2639 | /* clean up prefix and MDP pools */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2640 | /* *INDENT-OFF* */ |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 2641 | pool_flush(p, a->adv_prefixes_pool, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2642 | ({ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2643 | mhash_unset (&a->address_to_prefix_index, &p->prefix, 0); |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 2644 | })); |
| 2645 | pool_flush (m, a->mldp_group_pool, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2646 | ({ |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 2647 | mhash_unset (&a->address_to_mldp_index, &m->mcast_address, 0); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2648 | })); |
| 2649 | /* *INDENT-ON* */ |
| 2650 | |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 2651 | pool_free (a->mldp_group_pool); |
| 2652 | pool_free (a->adv_prefixes_pool); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2653 | |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 2654 | mhash_free (&a->address_to_prefix_index); |
| 2655 | mhash_free (&a->address_to_mldp_index); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2656 | |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 2657 | if (a->keep_sending_rs) |
| 2658 | a->keep_sending_rs = 0; |
| 2659 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2660 | pool_put (nm->if_radv_pool, a); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2661 | nm->if_radv_pool_index_by_sw_if_index[sw_if_index] = ~0; |
| 2662 | ri = ~0; |
| 2663 | } |
| 2664 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2665 | else |
| 2666 | { |
| 2667 | if (is_add) |
| 2668 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2669 | pool_get (nm->if_radv_pool, a); |
| 2670 | |
| 2671 | ri = a - nm->if_radv_pool; |
| 2672 | nm->if_radv_pool_index_by_sw_if_index[sw_if_index] = ri; |
| 2673 | |
| 2674 | /* initialize default values (most of which are zero) */ |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 2675 | clib_memset (a, 0, sizeof (a[0])); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2676 | |
| 2677 | a->sw_if_index = sw_if_index; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2678 | a->max_radv_interval = DEF_MAX_RADV_INTERVAL; |
| 2679 | a->min_radv_interval = DEF_MIN_RADV_INTERVAL; |
| 2680 | a->curr_hop_limit = DEF_CURR_HOP_LIMIT; |
| 2681 | a->adv_router_lifetime_in_sec = DEF_DEF_RTR_LIFETIME; |
| 2682 | |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 2683 | /* send ll address source address option */ |
| 2684 | a->adv_link_layer_address = 1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2685 | |
| 2686 | a->min_delay_between_radv = MIN_DELAY_BETWEEN_RAS; |
| 2687 | a->max_delay_between_radv = MAX_DELAY_BETWEEN_RAS; |
| 2688 | a->max_rtr_default_lifetime = MAX_DEF_RTR_LIFETIME; |
| 2689 | a->seed = (u32) clib_cpu_time_now (); |
| 2690 | (void) random_u32 (&a->seed); |
| 2691 | a->randomizer = clib_cpu_time_now (); |
| 2692 | (void) random_u64 (&a->randomizer); |
| 2693 | |
| 2694 | a->initial_adverts_count = MAX_INITIAL_RTR_ADVERTISEMENTS; |
| 2695 | a->initial_adverts_sent = a->initial_adverts_count - 1; |
| 2696 | a->initial_adverts_interval = MAX_INITIAL_RTR_ADVERT_INTERVAL; |
| 2697 | |
| 2698 | /* deafult is to send */ |
| 2699 | a->send_radv = 1; |
| 2700 | |
| 2701 | /* fill in radv_info for this interface that will be needed later */ |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 2702 | a->adv_link_mtu = |
| 2703 | vnet_sw_interface_get_mtu (vnm, sw_if_index, VNET_MTU_IP6); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2704 | |
| 2705 | clib_memcpy (a->link_layer_address, eth_if0->address, 6); |
| 2706 | |
| 2707 | /* fill in default link-local address (this may be overridden) */ |
| 2708 | ip6_link_local_address_from_ethernet_address |
| 2709 | (&a->link_local_address, eth_if0->address); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2710 | |
| 2711 | mhash_init (&a->address_to_prefix_index, sizeof (uword), |
| 2712 | sizeof (ip6_address_t)); |
| 2713 | mhash_init (&a->address_to_mldp_index, sizeof (uword), |
| 2714 | sizeof (ip6_address_t)); |
| 2715 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2716 | a->mcast_adj_index = adj_mcast_add_or_lock (FIB_PROTOCOL_IP6, |
| 2717 | VNET_LINK_IP6, |
| 2718 | sw_if_index); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2719 | |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 2720 | a->keep_sending_rs = 0; |
| 2721 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2722 | /* add multicast groups we will always be reporting */ |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 2723 | ip6_neighbor_add_mld_grp (a, |
| 2724 | IP6_MULTICAST_SCOPE_link_local, |
| 2725 | IP6_MULTICAST_GROUP_ID_all_hosts); |
| 2726 | ip6_neighbor_add_mld_grp (a, |
| 2727 | IP6_MULTICAST_SCOPE_link_local, |
| 2728 | IP6_MULTICAST_GROUP_ID_all_routers); |
| 2729 | ip6_neighbor_add_mld_grp (a, |
| 2730 | IP6_MULTICAST_SCOPE_link_local, |
| 2731 | IP6_MULTICAST_GROUP_ID_mldv2_routers); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2732 | } |
| 2733 | } |
| 2734 | return ri; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2735 | } |
| 2736 | |
| 2737 | /* send an mldpv2 report */ |
| 2738 | static void |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2739 | ip6_neighbor_send_mldpv2_report (u32 sw_if_index) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2740 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2741 | vnet_main_t *vnm = vnet_get_main (); |
| 2742 | vlib_main_t *vm = vnm->vlib_main; |
| 2743 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 2744 | vnet_sw_interface_t *sw_if0; |
| 2745 | ethernet_interface_t *eth_if0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2746 | u32 ri; |
| 2747 | int bogus_length; |
| 2748 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2749 | ip6_radv_t *radv_info; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2750 | u16 payload_length; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2751 | vlib_buffer_t *b0; |
| 2752 | ip6_header_t *ip0; |
| 2753 | u32 *to_next; |
| 2754 | vlib_frame_t *f; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2755 | u32 bo0; |
| 2756 | u32 n_to_alloc = 1; |
| 2757 | u32 n_allocated; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2758 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2759 | icmp6_multicast_listener_report_header_t *rh0; |
| 2760 | icmp6_multicast_listener_report_packet_t *rp0; |
| 2761 | |
| 2762 | sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index); |
| 2763 | ASSERT (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE); |
| 2764 | eth_if0 = ethernet_get_interface (ðernet_main, sw_if0->hw_if_index); |
| 2765 | |
| 2766 | if (!eth_if0 || !vnet_sw_interface_is_admin_up (vnm, sw_if_index)) |
| 2767 | return; |
| 2768 | |
| 2769 | /* look up the radv_t information for this interface */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2770 | vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index, |
| 2771 | ~0); |
| 2772 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2773 | ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2774 | |
| 2775 | if (ri == ~0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2776 | return; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2777 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2778 | /* send report now - build a mldpv2 report packet */ |
Damjan Marion | 671e60e | 2018-12-30 18:09:59 +0100 | [diff] [blame] | 2779 | n_allocated = vlib_buffer_alloc (vm, &bo0, n_to_alloc); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2780 | if (PREDICT_FALSE (n_allocated == 0)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2781 | { |
Dave Barach | 3a63fc5 | 2019-01-07 09:15:47 -0500 | [diff] [blame^] | 2782 | alloc_fail: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2783 | clib_warning ("buffer allocation failure"); |
| 2784 | return; |
| 2785 | } |
| 2786 | |
| 2787 | b0 = vlib_get_buffer (vm, bo0); |
| 2788 | |
| 2789 | /* adjust the sizeof the buffer to just include the ipv6 header */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2790 | b0->current_length = sizeof (icmp6_multicast_listener_report_packet_t); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2791 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2792 | payload_length = sizeof (icmp6_multicast_listener_report_header_t); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2793 | |
| 2794 | b0->error = ICMP6_ERROR_NONE; |
| 2795 | |
| 2796 | rp0 = vlib_buffer_get_current (b0); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2797 | ip0 = (ip6_header_t *) & rp0->ip; |
| 2798 | rh0 = (icmp6_multicast_listener_report_header_t *) & rp0->report_hdr; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2799 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 2800 | clib_memset (rp0, 0x0, sizeof (icmp6_multicast_listener_report_packet_t)); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2801 | |
| 2802 | ip0->ip_version_traffic_class_and_flow_label = |
| 2803 | clib_host_to_net_u32 (0x6 << 28); |
| 2804 | |
| 2805 | ip0->protocol = IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2806 | /* for DEBUG - vnet driver won't seem to emit router alerts */ |
| 2807 | /* ip0->protocol = IP_PROTOCOL_ICMP6; */ |
| 2808 | ip0->hop_limit = 1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2809 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2810 | rh0->icmp.type = ICMP6_multicast_listener_report_v2; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2811 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2812 | /* source address MUST be the link-local address */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2813 | radv_info = pool_elt_at_index (nm->if_radv_pool, ri); |
| 2814 | ip0->src_address = radv_info->link_local_address; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2815 | |
| 2816 | /* destination is all mldpv2 routers */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2817 | ip6_set_reserved_multicast_address (&ip0->dst_address, |
| 2818 | IP6_MULTICAST_SCOPE_link_local, |
| 2819 | IP6_MULTICAST_GROUP_ID_mldv2_routers); |
| 2820 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2821 | /* add reports here */ |
| 2822 | ip6_mldp_group_t *m; |
| 2823 | int num_addr_records = 0; |
| 2824 | icmp6_multicast_address_record_t rr; |
| 2825 | |
| 2826 | /* fill in the hop-by-hop extension header (router alert) info */ |
| 2827 | rh0->ext_hdr.next_hdr = IP_PROTOCOL_ICMP6; |
| 2828 | rh0->ext_hdr.n_data_u64s = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2829 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2830 | rh0->alert.type = IP6_MLDP_ALERT_TYPE; |
| 2831 | rh0->alert.len = 2; |
| 2832 | rh0->alert.value = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2833 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2834 | rh0->pad.type = 1; |
| 2835 | rh0->pad.len = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2836 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2837 | rh0->icmp.checksum = 0; |
| 2838 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2839 | /* *INDENT-OFF* */ |
| 2840 | pool_foreach (m, radv_info->mldp_group_pool, |
| 2841 | ({ |
| 2842 | rr.type = m->type; |
| 2843 | rr.aux_data_len_u32s = 0; |
| 2844 | rr.num_sources = clib_host_to_net_u16 (m->num_sources); |
| 2845 | clib_memcpy(&rr.mcast_addr, &m->mcast_address, sizeof(ip6_address_t)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2846 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2847 | num_addr_records++; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2848 | |
Dave Barach | 3a63fc5 | 2019-01-07 09:15:47 -0500 | [diff] [blame^] | 2849 | if(vlib_buffer_add_data |
| 2850 | (vm, vlib_buffer_get_free_list_index (b0), &bo0, |
| 2851 | (void *)&rr, sizeof(icmp6_multicast_address_record_t))) |
| 2852 | { |
| 2853 | vlib_buffer_free (vm, &bo0, 1); |
| 2854 | goto alloc_fail; |
| 2855 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2856 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2857 | payload_length += sizeof( icmp6_multicast_address_record_t); |
| 2858 | })); |
| 2859 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2860 | |
| 2861 | rh0->rsvd = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2862 | rh0->num_addr_records = clib_host_to_net_u16 (num_addr_records); |
| 2863 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2864 | /* update lengths */ |
| 2865 | ip0->payload_length = clib_host_to_net_u16 (payload_length); |
| 2866 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2867 | rh0->icmp.checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip0, |
| 2868 | &bogus_length); |
| 2869 | ASSERT (bogus_length == 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2870 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2871 | /* |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2872 | * OK to override w/ no regard for actual FIB, because |
Neale Ranns | f06aea5 | 2016-11-29 06:51:37 -0800 | [diff] [blame] | 2873 | * ip6-rewrite only looks at the adjacency. |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2874 | */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2875 | vnet_buffer (b0)->sw_if_index[VLIB_RX] = |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2876 | vnet_main.local_interface_sw_if_index; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2877 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2878 | vnet_buffer (b0)->ip.adj_index[VLIB_TX] = radv_info->mcast_adj_index; |
Damjan Marion | 213b5aa | 2017-07-13 21:19:27 +0200 | [diff] [blame] | 2879 | b0->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2880 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2881 | vlib_node_t *node = vlib_get_node_by_name (vm, (u8 *) "ip6-rewrite-mcast"); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2882 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2883 | f = vlib_get_frame_to_node (vm, node->index); |
| 2884 | to_next = vlib_frame_vector_args (f); |
| 2885 | to_next[0] = bo0; |
| 2886 | f->n_vectors = 1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2887 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2888 | vlib_put_frame_to_node (vm, node->index, f); |
| 2889 | return; |
| 2890 | } |
| 2891 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2892 | /* *INDENT-OFF* */ |
| 2893 | VLIB_REGISTER_NODE (ip6_icmp_router_solicitation_node,static) = |
| 2894 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2895 | .function = icmp6_router_solicitation, |
| 2896 | .name = "icmp6-router-solicitation", |
| 2897 | |
| 2898 | .vector_size = sizeof (u32), |
| 2899 | |
| 2900 | .format_trace = format_icmp6_input_trace, |
| 2901 | |
| 2902 | .n_next_nodes = ICMP6_ROUTER_SOLICITATION_N_NEXT, |
| 2903 | .next_nodes = { |
Vijayabhaskar Katamreddy | ce07412 | 2017-11-15 13:50:26 -0800 | [diff] [blame] | 2904 | [ICMP6_ROUTER_SOLICITATION_NEXT_DROP] = "ip6-drop", |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2905 | [ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_RW] = "ip6-rewrite-mcast", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2906 | [ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_TX] = "interface-output", |
| 2907 | }, |
| 2908 | }; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2909 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2910 | |
| 2911 | /* send a RA or update the timer info etc.. */ |
| 2912 | static uword |
| 2913 | ip6_neighbor_process_timer_event (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2914 | vlib_node_runtime_t * node, |
| 2915 | vlib_frame_t * frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2916 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2917 | vnet_main_t *vnm = vnet_get_main (); |
| 2918 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 2919 | ip6_radv_t *radv_info; |
| 2920 | vlib_frame_t *f = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2921 | u32 n_this_frame = 0; |
Benoît Ganne | d530445 | 2016-04-08 22:25:05 -0700 | [diff] [blame] | 2922 | u32 n_left_to_next = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2923 | u32 *to_next = 0; |
| 2924 | u32 bo0; |
| 2925 | icmp6_router_solicitation_header_t *h0; |
| 2926 | vlib_buffer_t *b0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2927 | f64 now = vlib_time_now (vm); |
| 2928 | |
| 2929 | /* Interface ip6 radv info list */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2930 | /* *INDENT-OFF* */ |
| 2931 | pool_foreach (radv_info, nm->if_radv_pool, |
| 2932 | ({ |
| 2933 | if( !vnet_sw_interface_is_admin_up (vnm, radv_info->sw_if_index)) |
| 2934 | { |
| 2935 | radv_info->initial_adverts_sent = radv_info->initial_adverts_count-1; |
| 2936 | radv_info->next_multicast_time = now; |
| 2937 | radv_info->last_multicast_time = now; |
| 2938 | radv_info->last_radv_time = 0; |
| 2939 | radv_info->all_routers_mcast = 0; |
| 2940 | continue; |
| 2941 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2942 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2943 | /* Make sure that we've joined the all-routers multicast group */ |
| 2944 | if(!radv_info->all_routers_mcast) |
| 2945 | { |
| 2946 | /* send MDLP_REPORT_EVENT message */ |
| 2947 | ip6_neighbor_send_mldpv2_report(radv_info->sw_if_index); |
| 2948 | radv_info->all_routers_mcast = 1; |
| 2949 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2950 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2951 | /* is it time to send a multicast RA on this interface? */ |
| 2952 | if(radv_info->send_radv && (now >= radv_info->next_multicast_time)) |
| 2953 | { |
| 2954 | u32 n_to_alloc = 1; |
| 2955 | u32 n_allocated; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2956 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2957 | f64 rfn = (radv_info->max_radv_interval - radv_info->min_radv_interval) * |
| 2958 | random_f64 (&radv_info->seed) + radv_info->min_radv_interval; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2959 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2960 | /* multicast send - compute next multicast send time */ |
| 2961 | if( radv_info->initial_adverts_sent > 0) |
| 2962 | { |
| 2963 | radv_info->initial_adverts_sent--; |
| 2964 | if(rfn > radv_info-> initial_adverts_interval) |
| 2965 | rfn = radv_info-> initial_adverts_interval; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2966 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2967 | /* check to see if we are ceasing to send */ |
| 2968 | if( radv_info->initial_adverts_sent == 0) |
| 2969 | if(radv_info->cease_radv) |
| 2970 | radv_info->send_radv = 0; |
| 2971 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2972 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2973 | radv_info->next_multicast_time = rfn + now; |
| 2974 | radv_info->last_multicast_time = now; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2975 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2976 | /* send advert now - build a "solicted" router advert with unspecified source address */ |
Damjan Marion | 671e60e | 2018-12-30 18:09:59 +0100 | [diff] [blame] | 2977 | n_allocated = vlib_buffer_alloc (vm, &bo0, n_to_alloc); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2978 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2979 | if (PREDICT_FALSE(n_allocated == 0)) |
| 2980 | { |
| 2981 | clib_warning ("buffer allocation failure"); |
| 2982 | continue; |
| 2983 | } |
| 2984 | b0 = vlib_get_buffer (vm, bo0); |
| 2985 | b0->current_length = sizeof( icmp6_router_solicitation_header_t); |
| 2986 | b0->error = ICMP6_ERROR_NONE; |
| 2987 | vnet_buffer (b0)->sw_if_index[VLIB_RX] = radv_info->sw_if_index; |
| 2988 | |
| 2989 | h0 = vlib_buffer_get_current (b0); |
| 2990 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 2991 | clib_memset (h0, 0, sizeof (icmp6_router_solicitation_header_t)); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2992 | |
| 2993 | h0->ip.ip_version_traffic_class_and_flow_label = clib_host_to_net_u32 (0x6 << 28); |
| 2994 | h0->ip.payload_length = clib_host_to_net_u16 (sizeof (icmp6_router_solicitation_header_t) |
| 2995 | - STRUCT_OFFSET_OF (icmp6_router_solicitation_header_t, neighbor)); |
| 2996 | h0->ip.protocol = IP_PROTOCOL_ICMP6; |
| 2997 | h0->ip.hop_limit = 255; |
| 2998 | |
| 2999 | /* set src/dst address as "unspecified" this marks this packet as internally generated rather than recieved */ |
| 3000 | h0->ip.src_address.as_u64[0] = 0; |
| 3001 | h0->ip.src_address.as_u64[1] = 0; |
| 3002 | |
| 3003 | h0->ip.dst_address.as_u64[0] = 0; |
| 3004 | h0->ip.dst_address.as_u64[1] = 0; |
| 3005 | |
| 3006 | h0->neighbor.icmp.type = ICMP6_router_solicitation; |
| 3007 | |
| 3008 | if (PREDICT_FALSE(f == 0)) |
| 3009 | { |
| 3010 | f = vlib_get_frame_to_node (vm, ip6_icmp_router_solicitation_node.index); |
| 3011 | to_next = vlib_frame_vector_args (f); |
| 3012 | n_left_to_next = VLIB_FRAME_SIZE; |
| 3013 | n_this_frame = 0; |
| 3014 | } |
| 3015 | |
| 3016 | n_this_frame++; |
| 3017 | n_left_to_next--; |
| 3018 | to_next[0] = bo0; |
| 3019 | to_next += 1; |
| 3020 | |
| 3021 | if (PREDICT_FALSE(n_left_to_next == 0)) |
| 3022 | { |
| 3023 | f->n_vectors = n_this_frame; |
| 3024 | vlib_put_frame_to_node (vm, ip6_icmp_router_solicitation_node.index, f); |
| 3025 | f = 0; |
| 3026 | } |
| 3027 | } |
| 3028 | })); |
| 3029 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3030 | |
| 3031 | if (f) |
| 3032 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3033 | ASSERT (n_this_frame); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3034 | f->n_vectors = n_this_frame; |
| 3035 | vlib_put_frame_to_node (vm, ip6_icmp_router_solicitation_node.index, f); |
| 3036 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3037 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3038 | } |
| 3039 | |
| 3040 | static uword |
| 3041 | ip6_icmp_neighbor_discovery_event_process (vlib_main_t * vm, |
| 3042 | vlib_node_runtime_t * node, |
| 3043 | vlib_frame_t * frame) |
| 3044 | { |
| 3045 | uword event_type; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3046 | ip6_icmp_neighbor_discovery_event_data_t *event_data; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3047 | |
| 3048 | /* init code here */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3049 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3050 | while (1) |
| 3051 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3052 | vlib_process_wait_for_event_or_clock (vm, 1. /* seconds */ ); |
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 | event_data = vlib_process_get_event_data (vm, &event_type); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3055 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3056 | if (!event_data) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3057 | { |
| 3058 | /* No events found: timer expired. */ |
| 3059 | /* process interface list and send RAs as appropriate, update timer info */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3060 | ip6_neighbor_process_timer_event (vm, node, frame); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3061 | } |
| 3062 | else |
| 3063 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3064 | switch (event_type) |
| 3065 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3066 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3067 | case ICMP6_ND_EVENT_INIT: |
| 3068 | break; |
| 3069 | |
| 3070 | case ~0: |
| 3071 | break; |
| 3072 | |
| 3073 | default: |
| 3074 | ASSERT (0); |
| 3075 | } |
| 3076 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3077 | if (event_data) |
| 3078 | _vec_len (event_data) = 0; |
| 3079 | } |
| 3080 | } |
| 3081 | return frame->n_vectors; |
| 3082 | } |
| 3083 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3084 | /* *INDENT-OFF* */ |
| 3085 | VLIB_REGISTER_NODE (ip6_icmp_router_advertisement_node,static) = |
| 3086 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3087 | .function = icmp6_router_advertisement, |
| 3088 | .name = "icmp6-router-advertisement", |
| 3089 | |
| 3090 | .vector_size = sizeof (u32), |
| 3091 | |
| 3092 | .format_trace = format_icmp6_input_trace, |
| 3093 | |
| 3094 | .n_next_nodes = 1, |
| 3095 | .next_nodes = { |
Vijayabhaskar Katamreddy | ce07412 | 2017-11-15 13:50:26 -0800 | [diff] [blame] | 3096 | [0] = "ip6-drop", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3097 | }, |
| 3098 | }; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3099 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3100 | |
| 3101 | vlib_node_registration_t ip6_icmp_neighbor_discovery_event_node = { |
| 3102 | |
| 3103 | .function = ip6_icmp_neighbor_discovery_event_process, |
| 3104 | .name = "ip6-icmp-neighbor-discovery-event-process", |
| 3105 | .type = VLIB_NODE_TYPE_PROCESS, |
| 3106 | }; |
| 3107 | |
| 3108 | static uword |
| 3109 | icmp6_neighbor_solicitation (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3110 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
| 3111 | { |
| 3112 | return icmp6_neighbor_solicitation_or_advertisement (vm, node, frame, |
| 3113 | /* is_solicitation */ |
| 3114 | 1); |
| 3115 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3116 | |
| 3117 | static uword |
| 3118 | icmp6_neighbor_advertisement (vlib_main_t * vm, |
| 3119 | vlib_node_runtime_t * node, |
| 3120 | vlib_frame_t * frame) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3121 | { |
| 3122 | return icmp6_neighbor_solicitation_or_advertisement (vm, node, frame, |
| 3123 | /* is_solicitation */ |
| 3124 | 0); |
| 3125 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3126 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3127 | /* *INDENT-OFF* */ |
| 3128 | VLIB_REGISTER_NODE (ip6_icmp_neighbor_solicitation_node,static) = |
| 3129 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3130 | .function = icmp6_neighbor_solicitation, |
| 3131 | .name = "icmp6-neighbor-solicitation", |
| 3132 | |
| 3133 | .vector_size = sizeof (u32), |
| 3134 | |
| 3135 | .format_trace = format_icmp6_input_trace, |
| 3136 | |
| 3137 | .n_next_nodes = ICMP6_NEIGHBOR_SOLICITATION_N_NEXT, |
| 3138 | .next_nodes = { |
Vijayabhaskar Katamreddy | ce07412 | 2017-11-15 13:50:26 -0800 | [diff] [blame] | 3139 | [ICMP6_NEIGHBOR_SOLICITATION_NEXT_DROP] = "ip6-drop", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3140 | [ICMP6_NEIGHBOR_SOLICITATION_NEXT_REPLY] = "interface-output", |
| 3141 | }, |
| 3142 | }; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3143 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3144 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3145 | /* *INDENT-OFF* */ |
| 3146 | VLIB_REGISTER_NODE (ip6_icmp_neighbor_advertisement_node,static) = |
| 3147 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3148 | .function = icmp6_neighbor_advertisement, |
| 3149 | .name = "icmp6-neighbor-advertisement", |
| 3150 | |
| 3151 | .vector_size = sizeof (u32), |
| 3152 | |
| 3153 | .format_trace = format_icmp6_input_trace, |
| 3154 | |
| 3155 | .n_next_nodes = 1, |
| 3156 | .next_nodes = { |
Vijayabhaskar Katamreddy | ce07412 | 2017-11-15 13:50:26 -0800 | [diff] [blame] | 3157 | [0] = "ip6-drop", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3158 | }, |
| 3159 | }; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3160 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3161 | |
Neale Ranns | c7b8f20 | 2018-04-25 06:34:31 -0700 | [diff] [blame] | 3162 | typedef enum |
| 3163 | { |
| 3164 | IP6_DISCOVER_NEIGHBOR_NEXT_DROP, |
| 3165 | IP6_DISCOVER_NEIGHBOR_NEXT_REPLY_TX, |
| 3166 | IP6_DISCOVER_NEIGHBOR_N_NEXT, |
| 3167 | } ip6_discover_neighbor_next_t; |
| 3168 | |
| 3169 | typedef enum |
| 3170 | { |
| 3171 | IP6_DISCOVER_NEIGHBOR_ERROR_DROP, |
| 3172 | IP6_DISCOVER_NEIGHBOR_ERROR_REQUEST_SENT, |
| 3173 | IP6_DISCOVER_NEIGHBOR_ERROR_NO_SOURCE_ADDRESS, |
| 3174 | } ip6_discover_neighbor_error_t; |
| 3175 | |
| 3176 | static uword |
| 3177 | ip6_discover_neighbor_inline (vlib_main_t * vm, |
| 3178 | vlib_node_runtime_t * node, |
| 3179 | vlib_frame_t * frame, int is_glean) |
| 3180 | { |
| 3181 | vnet_main_t *vnm = vnet_get_main (); |
| 3182 | ip6_main_t *im = &ip6_main; |
| 3183 | ip_lookup_main_t *lm = &im->lookup_main; |
| 3184 | u32 *from, *to_next_drop; |
| 3185 | uword n_left_from, n_left_to_next_drop; |
Dave Barach | 49433ad | 2018-08-08 17:59:03 -0400 | [diff] [blame] | 3186 | u64 seed; |
| 3187 | u32 thread_index = vm->thread_index; |
Neale Ranns | c7b8f20 | 2018-04-25 06:34:31 -0700 | [diff] [blame] | 3188 | int bogus_length; |
| 3189 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 3190 | |
| 3191 | if (node->flags & VLIB_NODE_FLAG_TRACE) |
| 3192 | ip6_forward_next_trace (vm, node, frame, VLIB_TX); |
| 3193 | |
Neale Ranns | cd35e53 | 2018-08-31 02:51:45 -0700 | [diff] [blame] | 3194 | seed = throttle_seed (&im->nd_throttle, thread_index, vlib_time_now (vm)); |
Neale Ranns | c7b8f20 | 2018-04-25 06:34:31 -0700 | [diff] [blame] | 3195 | |
| 3196 | from = vlib_frame_vector_args (frame); |
| 3197 | n_left_from = frame->n_vectors; |
| 3198 | |
| 3199 | while (n_left_from > 0) |
| 3200 | { |
| 3201 | vlib_get_next_frame (vm, node, IP6_DISCOVER_NEIGHBOR_NEXT_DROP, |
| 3202 | to_next_drop, n_left_to_next_drop); |
| 3203 | |
| 3204 | while (n_left_from > 0 && n_left_to_next_drop > 0) |
| 3205 | { |
Neale Ranns | cd35e53 | 2018-08-31 02:51:45 -0700 | [diff] [blame] | 3206 | u32 pi0, adj_index0, sw_if_index0, drop0, r0, next0; |
Neale Ranns | c7b8f20 | 2018-04-25 06:34:31 -0700 | [diff] [blame] | 3207 | vnet_hw_interface_t *hw_if0; |
| 3208 | ip6_radv_t *radv_info; |
Neale Ranns | cd35e53 | 2018-08-31 02:51:45 -0700 | [diff] [blame] | 3209 | ip_adjacency_t *adj0; |
| 3210 | vlib_buffer_t *p0; |
| 3211 | ip6_header_t *ip0; |
Neale Ranns | c7b8f20 | 2018-04-25 06:34:31 -0700 | [diff] [blame] | 3212 | |
| 3213 | pi0 = from[0]; |
| 3214 | |
| 3215 | p0 = vlib_get_buffer (vm, pi0); |
| 3216 | |
| 3217 | adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX]; |
| 3218 | |
| 3219 | ip0 = vlib_buffer_get_current (p0); |
| 3220 | |
| 3221 | adj0 = adj_get (adj_index0); |
| 3222 | |
| 3223 | if (!is_glean) |
| 3224 | { |
| 3225 | ip0->dst_address.as_u64[0] = |
| 3226 | adj0->sub_type.nbr.next_hop.ip6.as_u64[0]; |
| 3227 | ip0->dst_address.as_u64[1] = |
| 3228 | adj0->sub_type.nbr.next_hop.ip6.as_u64[1]; |
| 3229 | } |
| 3230 | |
Neale Ranns | c7b8f20 | 2018-04-25 06:34:31 -0700 | [diff] [blame] | 3231 | sw_if_index0 = adj0->rewrite_header.sw_if_index; |
| 3232 | vnet_buffer (p0)->sw_if_index[VLIB_TX] = sw_if_index0; |
| 3233 | |
Neale Ranns | cd35e53 | 2018-08-31 02:51:45 -0700 | [diff] [blame] | 3234 | /* combine the address and interface for a hash */ |
| 3235 | r0 = ip6_address_hash_to_u64 (&ip0->dst_address) ^ sw_if_index0; |
Neale Ranns | c7b8f20 | 2018-04-25 06:34:31 -0700 | [diff] [blame] | 3236 | |
Neale Ranns | cd35e53 | 2018-08-31 02:51:45 -0700 | [diff] [blame] | 3237 | drop0 = throttle_check (&im->nd_throttle, thread_index, r0, seed); |
Neale Ranns | c7b8f20 | 2018-04-25 06:34:31 -0700 | [diff] [blame] | 3238 | |
| 3239 | from += 1; |
| 3240 | n_left_from -= 1; |
| 3241 | to_next_drop[0] = pi0; |
| 3242 | to_next_drop += 1; |
| 3243 | n_left_to_next_drop -= 1; |
| 3244 | |
| 3245 | hw_if0 = vnet_get_sup_hw_interface (vnm, sw_if_index0); |
| 3246 | |
| 3247 | /* If the interface is link-down, drop the pkt */ |
| 3248 | if (!(hw_if0->flags & VNET_HW_INTERFACE_FLAG_LINK_UP)) |
| 3249 | drop0 = 1; |
| 3250 | |
| 3251 | if (vec_len (nm->if_radv_pool_index_by_sw_if_index) > sw_if_index0) |
| 3252 | { |
| 3253 | u32 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index0]; |
| 3254 | |
| 3255 | if (ri != ~0) |
| 3256 | radv_info = pool_elt_at_index (nm->if_radv_pool, ri); |
| 3257 | else |
| 3258 | drop0 = 1; |
| 3259 | } |
| 3260 | else |
| 3261 | drop0 = 1; |
| 3262 | |
| 3263 | /* |
| 3264 | * the adj has been updated to a rewrite but the node the DPO that got |
| 3265 | * us here hasn't - yet. no big deal. we'll drop while we wait. |
| 3266 | */ |
| 3267 | if (IP_LOOKUP_NEXT_REWRITE == adj0->lookup_next_index) |
| 3268 | drop0 = 1; |
| 3269 | |
| 3270 | p0->error = |
| 3271 | node->errors[drop0 ? IP6_DISCOVER_NEIGHBOR_ERROR_DROP |
| 3272 | : IP6_DISCOVER_NEIGHBOR_ERROR_REQUEST_SENT]; |
| 3273 | |
| 3274 | if (drop0) |
| 3275 | continue; |
| 3276 | |
| 3277 | { |
| 3278 | u32 bi0 = 0; |
| 3279 | icmp6_neighbor_solicitation_header_t *h0; |
| 3280 | vlib_buffer_t *b0; |
| 3281 | |
| 3282 | h0 = vlib_packet_template_get_packet |
| 3283 | (vm, &im->discover_neighbor_packet_template, &bi0); |
John Lo | 084606b | 2018-06-19 15:27:48 -0400 | [diff] [blame] | 3284 | if (!h0) |
| 3285 | continue; |
Neale Ranns | c7b8f20 | 2018-04-25 06:34:31 -0700 | [diff] [blame] | 3286 | |
| 3287 | /* |
| 3288 | * Build ethernet header. |
| 3289 | * Choose source address based on destination lookup |
| 3290 | * adjacency. |
| 3291 | */ |
| 3292 | if (!ip6_src_address_for_packet (lm, |
| 3293 | sw_if_index0, |
| 3294 | &ip0->dst_address, |
| 3295 | &h0->ip.src_address)) |
| 3296 | { |
| 3297 | /* There is no address on the interface */ |
| 3298 | p0->error = |
| 3299 | node->errors[IP6_DISCOVER_NEIGHBOR_ERROR_NO_SOURCE_ADDRESS]; |
| 3300 | vlib_buffer_free (vm, &bi0, 1); |
| 3301 | continue; |
| 3302 | } |
| 3303 | |
| 3304 | /* |
| 3305 | * Destination address is a solicited node multicast address. |
| 3306 | * We need to fill in |
| 3307 | * the low 24 bits with low 24 bits of target's address. |
| 3308 | */ |
| 3309 | h0->ip.dst_address.as_u8[13] = ip0->dst_address.as_u8[13]; |
| 3310 | h0->ip.dst_address.as_u8[14] = ip0->dst_address.as_u8[14]; |
| 3311 | h0->ip.dst_address.as_u8[15] = ip0->dst_address.as_u8[15]; |
| 3312 | |
| 3313 | h0->neighbor.target_address = ip0->dst_address; |
| 3314 | |
| 3315 | clib_memcpy (h0->link_layer_option.ethernet_address, |
| 3316 | hw_if0->hw_address, vec_len (hw_if0->hw_address)); |
| 3317 | |
| 3318 | /* $$$$ appears we need this; why is the checksum non-zero? */ |
| 3319 | h0->neighbor.icmp.checksum = 0; |
| 3320 | h0->neighbor.icmp.checksum = |
| 3321 | ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h0->ip, |
| 3322 | &bogus_length); |
| 3323 | |
| 3324 | ASSERT (bogus_length == 0); |
| 3325 | |
| 3326 | vlib_buffer_copy_trace_flag (vm, p0, bi0); |
| 3327 | b0 = vlib_get_buffer (vm, bi0); |
| 3328 | vnet_buffer (b0)->sw_if_index[VLIB_TX] |
| 3329 | = vnet_buffer (p0)->sw_if_index[VLIB_TX]; |
| 3330 | |
| 3331 | vnet_buffer (b0)->ip.adj_index[VLIB_TX] = |
| 3332 | radv_info->mcast_adj_index; |
| 3333 | |
| 3334 | b0->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED; |
| 3335 | next0 = IP6_DISCOVER_NEIGHBOR_NEXT_REPLY_TX; |
| 3336 | |
| 3337 | vlib_set_next_frame_buffer (vm, node, next0, bi0); |
| 3338 | } |
| 3339 | } |
| 3340 | |
| 3341 | vlib_put_next_frame (vm, node, IP6_DISCOVER_NEIGHBOR_NEXT_DROP, |
| 3342 | n_left_to_next_drop); |
| 3343 | } |
| 3344 | |
| 3345 | return frame->n_vectors; |
| 3346 | } |
| 3347 | |
| 3348 | static uword |
| 3349 | ip6_discover_neighbor (vlib_main_t * vm, |
| 3350 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
| 3351 | { |
| 3352 | return (ip6_discover_neighbor_inline (vm, node, frame, 0)); |
| 3353 | } |
| 3354 | |
| 3355 | static uword |
| 3356 | ip6_glean (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) |
| 3357 | { |
| 3358 | return (ip6_discover_neighbor_inline (vm, node, frame, 1)); |
| 3359 | } |
| 3360 | |
| 3361 | static char *ip6_discover_neighbor_error_strings[] = { |
| 3362 | [IP6_DISCOVER_NEIGHBOR_ERROR_DROP] = "address overflow drops", |
| 3363 | [IP6_DISCOVER_NEIGHBOR_ERROR_REQUEST_SENT] = "neighbor solicitations sent", |
| 3364 | [IP6_DISCOVER_NEIGHBOR_ERROR_NO_SOURCE_ADDRESS] |
| 3365 | = "no source address for ND solicitation", |
| 3366 | }; |
| 3367 | |
| 3368 | /* *INDENT-OFF* */ |
| 3369 | VLIB_REGISTER_NODE (ip6_glean_node) = |
| 3370 | { |
| 3371 | .function = ip6_glean, |
| 3372 | .name = "ip6-glean", |
| 3373 | .vector_size = sizeof (u32), |
| 3374 | .format_trace = format_ip6_forward_next_trace, |
| 3375 | .n_errors = ARRAY_LEN (ip6_discover_neighbor_error_strings), |
| 3376 | .error_strings = ip6_discover_neighbor_error_strings, |
| 3377 | .n_next_nodes = IP6_DISCOVER_NEIGHBOR_N_NEXT, |
| 3378 | .next_nodes = |
| 3379 | { |
| 3380 | [IP6_DISCOVER_NEIGHBOR_NEXT_DROP] = "ip6-drop", |
| 3381 | [IP6_DISCOVER_NEIGHBOR_NEXT_REPLY_TX] = "ip6-rewrite-mcast", |
| 3382 | }, |
| 3383 | }; |
| 3384 | VLIB_REGISTER_NODE (ip6_discover_neighbor_node) = |
| 3385 | { |
| 3386 | .function = ip6_discover_neighbor, |
| 3387 | .name = "ip6-discover-neighbor", |
| 3388 | .vector_size = sizeof (u32), |
| 3389 | .format_trace = format_ip6_forward_next_trace, |
| 3390 | .n_errors = ARRAY_LEN (ip6_discover_neighbor_error_strings), |
| 3391 | .error_strings = ip6_discover_neighbor_error_strings, |
| 3392 | .n_next_nodes = IP6_DISCOVER_NEIGHBOR_N_NEXT, |
| 3393 | .next_nodes = |
| 3394 | { |
| 3395 | [IP6_DISCOVER_NEIGHBOR_NEXT_DROP] = "ip6-drop", |
| 3396 | [IP6_DISCOVER_NEIGHBOR_NEXT_REPLY_TX] = "ip6-rewrite-mcast", |
| 3397 | }, |
| 3398 | }; |
| 3399 | /* *INDENT-ON* */ |
| 3400 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3401 | /* API support functions */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3402 | int |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3403 | ip6_neighbor_ra_config (vlib_main_t * vm, u32 sw_if_index, |
| 3404 | u8 suppress, u8 managed, u8 other, |
| 3405 | u8 ll_option, u8 send_unicast, u8 cease, |
| 3406 | u8 use_lifetime, u32 lifetime, |
| 3407 | u32 initial_count, u32 initial_interval, |
| 3408 | u32 max_interval, u32 min_interval, u8 is_no) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3409 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3410 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 3411 | int error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3412 | u32 ri; |
| 3413 | |
| 3414 | /* look up the radv_t information for this interface */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3415 | vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index, |
| 3416 | ~0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3417 | ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3418 | error = (ri != ~0) ? 0 : VNET_API_ERROR_INVALID_SW_IF_INDEX; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3419 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3420 | if (!error) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3421 | { |
| 3422 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3423 | ip6_radv_t *radv_info; |
| 3424 | radv_info = pool_elt_at_index (nm->if_radv_pool, ri); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3425 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3426 | if ((max_interval != 0) && (min_interval == 0)) |
| 3427 | min_interval = .75 * max_interval; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3428 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3429 | max_interval = |
| 3430 | (max_interval != |
| 3431 | 0) ? ((is_no) ? DEF_MAX_RADV_INTERVAL : max_interval) : |
| 3432 | radv_info->max_radv_interval; |
| 3433 | min_interval = |
| 3434 | (min_interval != |
| 3435 | 0) ? ((is_no) ? DEF_MIN_RADV_INTERVAL : min_interval) : |
| 3436 | radv_info->min_radv_interval; |
| 3437 | lifetime = |
| 3438 | (use_lifetime != |
| 3439 | 0) ? ((is_no) ? DEF_DEF_RTR_LIFETIME : lifetime) : |
| 3440 | radv_info->adv_router_lifetime_in_sec; |
| 3441 | |
| 3442 | if (lifetime) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3443 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3444 | if (lifetime > MAX_DEF_RTR_LIFETIME) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3445 | lifetime = MAX_DEF_RTR_LIFETIME; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3446 | |
| 3447 | if (lifetime <= max_interval) |
| 3448 | return VNET_API_ERROR_INVALID_VALUE; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3449 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3450 | |
| 3451 | if (min_interval != 0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3452 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3453 | if ((min_interval > .75 * max_interval) || (min_interval < 3)) |
| 3454 | return VNET_API_ERROR_INVALID_VALUE; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3455 | } |
| 3456 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3457 | if ((initial_count > MAX_INITIAL_RTR_ADVERTISEMENTS) || |
| 3458 | (initial_interval > MAX_INITIAL_RTR_ADVERT_INTERVAL)) |
| 3459 | return VNET_API_ERROR_INVALID_VALUE; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3460 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3461 | /* |
| 3462 | if "flag" is set and is_no is true then restore default value else set value corresponding to "flag" |
| 3463 | if "flag" is clear don't change corresponding value |
| 3464 | */ |
| 3465 | radv_info->send_radv = |
| 3466 | (suppress != 0) ? ((is_no != 0) ? 1 : 0) : radv_info->send_radv; |
| 3467 | radv_info->adv_managed_flag = |
| 3468 | (managed != 0) ? ((is_no) ? 0 : 1) : radv_info->adv_managed_flag; |
| 3469 | radv_info->adv_other_flag = |
| 3470 | (other != 0) ? ((is_no) ? 0 : 1) : radv_info->adv_other_flag; |
| 3471 | radv_info->adv_link_layer_address = |
| 3472 | (ll_option != |
| 3473 | 0) ? ((is_no) ? 1 : 0) : radv_info->adv_link_layer_address; |
| 3474 | radv_info->send_unicast = |
| 3475 | (send_unicast != 0) ? ((is_no) ? 0 : 1) : radv_info->send_unicast; |
| 3476 | radv_info->cease_radv = |
| 3477 | (cease != 0) ? ((is_no) ? 0 : 1) : radv_info->cease_radv; |
| 3478 | |
| 3479 | radv_info->min_radv_interval = min_interval; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3480 | radv_info->max_radv_interval = max_interval; |
| 3481 | radv_info->adv_router_lifetime_in_sec = lifetime; |
| 3482 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3483 | radv_info->initial_adverts_count = |
| 3484 | (initial_count != |
| 3485 | 0) ? ((is_no) ? MAX_INITIAL_RTR_ADVERTISEMENTS : initial_count) : |
| 3486 | radv_info->initial_adverts_count; |
| 3487 | radv_info->initial_adverts_interval = |
| 3488 | (initial_interval != |
| 3489 | 0) ? ((is_no) ? MAX_INITIAL_RTR_ADVERT_INTERVAL : initial_interval) : |
| 3490 | radv_info->initial_adverts_interval; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3491 | |
| 3492 | /* restart */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3493 | if ((cease != 0) && (is_no)) |
| 3494 | radv_info->send_radv = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3495 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3496 | radv_info->initial_adverts_sent = radv_info->initial_adverts_count - 1; |
| 3497 | radv_info->next_multicast_time = vlib_time_now (vm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3498 | radv_info->last_multicast_time = vlib_time_now (vm); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3499 | radv_info->last_radv_time = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3500 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3501 | return (error); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3502 | } |
| 3503 | |
| 3504 | int |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3505 | ip6_neighbor_ra_prefix (vlib_main_t * vm, u32 sw_if_index, |
| 3506 | ip6_address_t * prefix_addr, u8 prefix_len, |
| 3507 | u8 use_default, u32 val_lifetime, u32 pref_lifetime, |
| 3508 | u8 no_advertise, u8 off_link, u8 no_autoconfig, |
| 3509 | u8 no_onlink, u8 is_no) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3510 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3511 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3512 | int error; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3513 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3514 | u32 ri; |
| 3515 | |
| 3516 | /* look up the radv_t information for this interface */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3517 | vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index, |
| 3518 | ~0); |
| 3519 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3520 | ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index]; |
| 3521 | |
| 3522 | error = (ri != ~0) ? 0 : VNET_API_ERROR_INVALID_SW_IF_INDEX; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3523 | |
| 3524 | if (!error) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3525 | { |
| 3526 | f64 now = vlib_time_now (vm); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3527 | ip6_radv_t *radv_info; |
| 3528 | radv_info = pool_elt_at_index (nm->if_radv_pool, ri); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3529 | |
| 3530 | /* prefix info add, delete or update */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3531 | ip6_radv_prefix_t *prefix; |
| 3532 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3533 | /* lookup prefix info for this address on this interface */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3534 | uword *p = mhash_get (&radv_info->address_to_prefix_index, prefix_addr); |
| 3535 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3536 | prefix = p ? pool_elt_at_index (radv_info->adv_prefixes_pool, p[0]) : 0; |
| 3537 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3538 | if (is_no) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3539 | { |
| 3540 | /* delete */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3541 | if (!prefix) |
| 3542 | return VNET_API_ERROR_INVALID_VALUE; /* invalid prefix */ |
| 3543 | |
| 3544 | if (prefix->prefix_len != prefix_len) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3545 | return VNET_API_ERROR_INVALID_VALUE_2; |
| 3546 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3547 | /* FIXME - Should the DP do this or the CP ? */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3548 | /* do specific delete processing here before returning */ |
| 3549 | /* try to remove from routing table */ |
| 3550 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3551 | mhash_unset (&radv_info->address_to_prefix_index, prefix_addr, |
| 3552 | /* old_value */ 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3553 | pool_put (radv_info->adv_prefixes_pool, prefix); |
| 3554 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3555 | radv_info->initial_adverts_sent = |
| 3556 | radv_info->initial_adverts_count - 1; |
| 3557 | radv_info->next_multicast_time = vlib_time_now (vm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3558 | radv_info->last_multicast_time = vlib_time_now (vm); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3559 | radv_info->last_radv_time = 0; |
| 3560 | return (error); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3561 | } |
| 3562 | |
| 3563 | /* adding or changing */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3564 | if (!prefix) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3565 | { |
| 3566 | /* add */ |
| 3567 | u32 pi; |
| 3568 | pool_get (radv_info->adv_prefixes_pool, prefix); |
| 3569 | pi = prefix - radv_info->adv_prefixes_pool; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3570 | mhash_set (&radv_info->address_to_prefix_index, prefix_addr, pi, |
| 3571 | /* old_value */ 0); |
| 3572 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 3573 | clib_memset (prefix, 0x0, sizeof (ip6_radv_prefix_t)); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3574 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3575 | prefix->prefix_len = prefix_len; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3576 | clib_memcpy (&prefix->prefix, prefix_addr, sizeof (ip6_address_t)); |
| 3577 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3578 | /* initialize default values */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3579 | prefix->adv_on_link_flag = 1; /* L bit set */ |
| 3580 | prefix->adv_autonomous_flag = 1; /* A bit set */ |
| 3581 | prefix->adv_valid_lifetime_in_secs = DEF_ADV_VALID_LIFETIME; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3582 | prefix->adv_pref_lifetime_in_secs = DEF_ADV_PREF_LIFETIME; |
| 3583 | prefix->enabled = 1; |
| 3584 | prefix->decrement_lifetime_flag = 1; |
| 3585 | prefix->deprecated_prefix_flag = 1; |
| 3586 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3587 | if (off_link == 0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3588 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3589 | /* FIXME - Should the DP do this or the CP ? */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3590 | /* insert prefix into routing table as a connected prefix */ |
| 3591 | } |
| 3592 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3593 | if (use_default) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3594 | goto restart; |
| 3595 | } |
| 3596 | else |
| 3597 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3598 | |
| 3599 | if (prefix->prefix_len != prefix_len) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3600 | return VNET_API_ERROR_INVALID_VALUE_2; |
| 3601 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3602 | if (off_link != 0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3603 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3604 | /* FIXME - Should the DP do this or the CP ? */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3605 | /* remove from routing table if already there */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3606 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3607 | } |
| 3608 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3609 | if ((val_lifetime == ~0) || (pref_lifetime == ~0)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3610 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3611 | prefix->adv_valid_lifetime_in_secs = ~0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3612 | prefix->adv_pref_lifetime_in_secs = ~0; |
| 3613 | prefix->decrement_lifetime_flag = 0; |
| 3614 | } |
| 3615 | else |
| 3616 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3617 | prefix->adv_valid_lifetime_in_secs = val_lifetime;; |
| 3618 | prefix->adv_pref_lifetime_in_secs = pref_lifetime; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3619 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3620 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3621 | /* copy remaining */ |
| 3622 | prefix->enabled = !(no_advertise != 0); |
| 3623 | prefix->adv_on_link_flag = !((off_link != 0) || (no_onlink != 0)); |
| 3624 | prefix->adv_autonomous_flag = !(no_autoconfig != 0); |
| 3625 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3626 | restart: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3627 | /* restart */ |
| 3628 | /* fill in the expiration times */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3629 | prefix->valid_lifetime_expires = |
| 3630 | now + prefix->adv_valid_lifetime_in_secs; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3631 | prefix->pref_lifetime_expires = now + prefix->adv_pref_lifetime_in_secs; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3632 | |
| 3633 | radv_info->initial_adverts_sent = radv_info->initial_adverts_count - 1; |
| 3634 | radv_info->next_multicast_time = vlib_time_now (vm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3635 | radv_info->last_multicast_time = vlib_time_now (vm); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3636 | radv_info->last_radv_time = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3637 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3638 | return (error); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3639 | } |
| 3640 | |
| 3641 | clib_error_t * |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3642 | ip6_neighbor_cmd (vlib_main_t * vm, unformat_input_t * main_input, |
| 3643 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3644 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3645 | vnet_main_t *vnm = vnet_get_main (); |
| 3646 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 3647 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3648 | u8 is_no = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3649 | u8 suppress = 0, managed = 0, other = 0; |
| 3650 | u8 suppress_ll_option = 0, send_unicast = 0, cease = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3651 | u8 use_lifetime = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3652 | u32 sw_if_index, ra_lifetime = 0, ra_initial_count = |
| 3653 | 0, ra_initial_interval = 0; |
| 3654 | u32 ra_max_interval = 0, ra_min_interval = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3655 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3656 | unformat_input_t _line_input, *line_input = &_line_input; |
| 3657 | vnet_sw_interface_t *sw_if0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3658 | |
| 3659 | int add_radv_info = 1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3660 | __attribute__ ((unused)) ip6_radv_t *radv_info = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3661 | ip6_address_t ip6_addr; |
| 3662 | u32 addr_len; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3663 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3664 | |
| 3665 | /* Get a line of input. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3666 | if (!unformat_user (main_input, unformat_line_input, line_input)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3667 | return 0; |
| 3668 | |
| 3669 | /* get basic radv info for this interface */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3670 | if (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3671 | { |
| 3672 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3673 | if (unformat_user (line_input, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3674 | unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 3675 | { |
| 3676 | u32 ri; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3677 | ethernet_interface_t *eth_if0 = 0; |
| 3678 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3679 | sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3680 | if (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE) |
| 3681 | eth_if0 = |
| 3682 | ethernet_get_interface (ðernet_main, sw_if0->hw_if_index); |
| 3683 | |
| 3684 | if (!eth_if0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3685 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3686 | error = |
| 3687 | clib_error_return (0, "Interface must be of ethernet type"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3688 | goto done; |
| 3689 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3690 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3691 | /* look up the radv_t information for this interface */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3692 | vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, |
| 3693 | sw_if_index, ~0); |
| 3694 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3695 | ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3696 | |
| 3697 | if (ri != ~0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3698 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3699 | radv_info = pool_elt_at_index (nm->if_radv_pool, ri); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3700 | } |
| 3701 | else |
| 3702 | { |
| 3703 | error = clib_error_return (0, "unknown interface %U'", |
| 3704 | format_unformat_error, line_input); |
| 3705 | goto done; |
| 3706 | } |
| 3707 | } |
| 3708 | else |
| 3709 | { |
| 3710 | error = clib_error_return (0, "invalid interface name %U'", |
| 3711 | format_unformat_error, line_input); |
| 3712 | goto done; |
| 3713 | } |
| 3714 | } |
| 3715 | |
| 3716 | /* get the rest of the command */ |
| 3717 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 3718 | { |
| 3719 | if (unformat (line_input, "no")) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3720 | is_no = 1; |
| 3721 | else if (unformat (line_input, "prefix %U/%d", |
| 3722 | unformat_ip6_address, &ip6_addr, &addr_len)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3723 | { |
| 3724 | add_radv_info = 0; |
| 3725 | break; |
| 3726 | } |
| 3727 | else if (unformat (line_input, "ra-managed-config-flag")) |
| 3728 | { |
| 3729 | managed = 1; |
| 3730 | break; |
| 3731 | } |
| 3732 | else if (unformat (line_input, "ra-other-config-flag")) |
| 3733 | { |
| 3734 | other = 1; |
| 3735 | break; |
| 3736 | } |
Chris Luke | 33879c9 | 2016-06-28 19:54:21 -0400 | [diff] [blame] | 3737 | else if (unformat (line_input, "ra-suppress") || |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3738 | unformat (line_input, "ra-surpress")) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3739 | { |
Chris Luke | 33879c9 | 2016-06-28 19:54:21 -0400 | [diff] [blame] | 3740 | suppress = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3741 | break; |
| 3742 | } |
Chris Luke | 33879c9 | 2016-06-28 19:54:21 -0400 | [diff] [blame] | 3743 | else if (unformat (line_input, "ra-suppress-link-layer") || |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3744 | unformat (line_input, "ra-surpress-link-layer")) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3745 | { |
Chris Luke | 33879c9 | 2016-06-28 19:54:21 -0400 | [diff] [blame] | 3746 | suppress_ll_option = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3747 | break; |
| 3748 | } |
| 3749 | else if (unformat (line_input, "ra-send-unicast")) |
| 3750 | { |
| 3751 | send_unicast = 1; |
| 3752 | break; |
| 3753 | } |
| 3754 | else if (unformat (line_input, "ra-lifetime")) |
| 3755 | { |
| 3756 | if (!unformat (line_input, "%d", &ra_lifetime)) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 3757 | { |
| 3758 | error = unformat_parse_error (line_input); |
| 3759 | goto done; |
| 3760 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3761 | use_lifetime = 1; |
| 3762 | break; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3763 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3764 | else if (unformat (line_input, "ra-initial")) |
| 3765 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3766 | if (!unformat |
| 3767 | (line_input, "%d %d", &ra_initial_count, &ra_initial_interval)) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 3768 | { |
| 3769 | error = unformat_parse_error (line_input); |
| 3770 | goto done; |
| 3771 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3772 | break; |
| 3773 | } |
| 3774 | else if (unformat (line_input, "ra-interval")) |
| 3775 | { |
| 3776 | if (!unformat (line_input, "%d", &ra_max_interval)) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 3777 | { |
| 3778 | error = unformat_parse_error (line_input); |
| 3779 | goto done; |
| 3780 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3781 | |
| 3782 | if (!unformat (line_input, "%d", &ra_min_interval)) |
| 3783 | ra_min_interval = 0; |
| 3784 | break; |
| 3785 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3786 | else if (unformat (line_input, "ra-cease")) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3787 | { |
| 3788 | cease = 1; |
| 3789 | break; |
| 3790 | } |
| 3791 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 3792 | { |
| 3793 | error = unformat_parse_error (line_input); |
| 3794 | goto done; |
| 3795 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3796 | } |
| 3797 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3798 | if (add_radv_info) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3799 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3800 | ip6_neighbor_ra_config (vm, sw_if_index, |
| 3801 | suppress, managed, other, |
| 3802 | suppress_ll_option, send_unicast, cease, |
| 3803 | use_lifetime, ra_lifetime, |
| 3804 | ra_initial_count, ra_initial_interval, |
| 3805 | ra_max_interval, ra_min_interval, is_no); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3806 | } |
| 3807 | else |
| 3808 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3809 | u32 valid_lifetime_in_secs = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3810 | u32 pref_lifetime_in_secs = 0; |
| 3811 | u8 use_prefix_default_values = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3812 | u8 no_advertise = 0; |
| 3813 | u8 off_link = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3814 | u8 no_autoconfig = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3815 | u8 no_onlink = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3816 | |
| 3817 | /* get the rest of the command */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3818 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3819 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3820 | if (unformat (line_input, "default")) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3821 | { |
| 3822 | use_prefix_default_values = 1; |
| 3823 | break; |
| 3824 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3825 | else if (unformat (line_input, "infinite")) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3826 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3827 | valid_lifetime_in_secs = ~0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3828 | pref_lifetime_in_secs = ~0; |
| 3829 | break; |
| 3830 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3831 | else if (unformat (line_input, "%d %d", &valid_lifetime_in_secs, |
| 3832 | &pref_lifetime_in_secs)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3833 | break; |
| 3834 | else |
| 3835 | break; |
| 3836 | } |
| 3837 | |
| 3838 | |
| 3839 | /* get the rest of the command */ |
| 3840 | while (!use_prefix_default_values && |
| 3841 | unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 3842 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3843 | if (unformat (line_input, "no-advertise")) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3844 | no_advertise = 1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3845 | else if (unformat (line_input, "off-link")) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3846 | off_link = 1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3847 | else if (unformat (line_input, "no-autoconfig")) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3848 | no_autoconfig = 1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3849 | else if (unformat (line_input, "no-onlink")) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3850 | no_onlink = 1; |
| 3851 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 3852 | { |
| 3853 | error = unformat_parse_error (line_input); |
| 3854 | goto done; |
| 3855 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3856 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3857 | |
| 3858 | ip6_neighbor_ra_prefix (vm, sw_if_index, |
| 3859 | &ip6_addr, addr_len, |
| 3860 | use_prefix_default_values, |
| 3861 | valid_lifetime_in_secs, |
| 3862 | pref_lifetime_in_secs, |
| 3863 | no_advertise, |
| 3864 | off_link, no_autoconfig, no_onlink, is_no); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3865 | } |
| 3866 | |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 3867 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3868 | unformat_free (line_input); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3869 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3870 | return error; |
| 3871 | } |
| 3872 | |
Chris Luke | bfd32fd | 2016-06-24 20:38:06 -0400 | [diff] [blame] | 3873 | static void |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3874 | ip6_print_addrs (vlib_main_t * vm, u32 * addrs) |
Chris Luke | bfd32fd | 2016-06-24 20:38:06 -0400 | [diff] [blame] | 3875 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3876 | ip_lookup_main_t *lm = &ip6_main.lookup_main; |
Chris Luke | bfd32fd | 2016-06-24 20:38:06 -0400 | [diff] [blame] | 3877 | u32 i; |
| 3878 | |
| 3879 | for (i = 0; i < vec_len (addrs); i++) |
| 3880 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3881 | ip_interface_address_t *a = |
| 3882 | pool_elt_at_index (lm->if_address_pool, addrs[i]); |
| 3883 | ip6_address_t *address = ip_interface_address_get_address (lm, a); |
Chris Luke | bfd32fd | 2016-06-24 20:38:06 -0400 | [diff] [blame] | 3884 | |
| 3885 | vlib_cli_output (vm, "\t\t%U/%d", |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3886 | format_ip6_address, address, a->address_length); |
Chris Luke | bfd32fd | 2016-06-24 20:38:06 -0400 | [diff] [blame] | 3887 | } |
| 3888 | } |
| 3889 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3890 | static clib_error_t * |
| 3891 | show_ip6_interface_cmd (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3892 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3893 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3894 | vnet_main_t *vnm = vnet_get_main (); |
| 3895 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 3896 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3897 | u32 sw_if_index; |
| 3898 | |
| 3899 | sw_if_index = ~0; |
| 3900 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3901 | if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3902 | { |
| 3903 | u32 ri; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3904 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3905 | /* look up the radv_t information for this interface */ |
| 3906 | vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, |
| 3907 | sw_if_index, ~0); |
| 3908 | |
| 3909 | ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index]; |
| 3910 | |
| 3911 | if (ri != ~0) |
| 3912 | { |
| 3913 | ip_lookup_main_t *lm = &ip6_main.lookup_main; |
| 3914 | ip6_radv_t *radv_info; |
| 3915 | radv_info = pool_elt_at_index (nm->if_radv_pool, ri); |
| 3916 | |
| 3917 | vlib_cli_output (vm, "%U is admin %s\n", |
| 3918 | format_vnet_sw_interface_name, vnm, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3919 | vnet_get_sw_interface (vnm, sw_if_index), |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3920 | (vnet_sw_interface_is_admin_up (vnm, sw_if_index) ? |
| 3921 | "up" : "down")); |
| 3922 | |
Chris Luke | bfd32fd | 2016-06-24 20:38:06 -0400 | [diff] [blame] | 3923 | u32 ai; |
| 3924 | u32 *link_scope = 0, *global_scope = 0; |
| 3925 | u32 *local_scope = 0, *unknown_scope = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3926 | ip_interface_address_t *a; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3927 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3928 | vec_validate_init_empty (lm->if_address_pool_index_by_sw_if_index, |
| 3929 | sw_if_index, ~0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3930 | ai = lm->if_address_pool_index_by_sw_if_index[sw_if_index]; |
| 3931 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3932 | while (ai != (u32) ~ 0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3933 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3934 | a = pool_elt_at_index (lm->if_address_pool, ai); |
| 3935 | ip6_address_t *address = |
| 3936 | ip_interface_address_get_address (lm, a); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3937 | |
Chris Luke | bfd32fd | 2016-06-24 20:38:06 -0400 | [diff] [blame] | 3938 | if (ip6_address_is_link_local_unicast (address)) |
| 3939 | vec_add1 (link_scope, ai); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3940 | else if (ip6_address_is_global_unicast (address)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3941 | vec_add1 (global_scope, ai); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3942 | else if (ip6_address_is_local_unicast (address)) |
Chris Luke | bfd32fd | 2016-06-24 20:38:06 -0400 | [diff] [blame] | 3943 | vec_add1 (local_scope, ai); |
| 3944 | else |
| 3945 | vec_add1 (unknown_scope, ai); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3946 | |
| 3947 | ai = a->next_this_sw_interface; |
| 3948 | } |
| 3949 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3950 | if (vec_len (link_scope)) |
| 3951 | { |
| 3952 | vlib_cli_output (vm, "\tLink-local address(es):\n"); |
| 3953 | ip6_print_addrs (vm, link_scope); |
| 3954 | vec_free (link_scope); |
| 3955 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3956 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3957 | if (vec_len (local_scope)) |
| 3958 | { |
| 3959 | vlib_cli_output (vm, "\tLocal unicast address(es):\n"); |
| 3960 | ip6_print_addrs (vm, local_scope); |
| 3961 | vec_free (local_scope); |
| 3962 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3963 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3964 | if (vec_len (global_scope)) |
| 3965 | { |
| 3966 | vlib_cli_output (vm, "\tGlobal unicast address(es):\n"); |
| 3967 | ip6_print_addrs (vm, global_scope); |
| 3968 | vec_free (global_scope); |
| 3969 | } |
Chris Luke | bfd32fd | 2016-06-24 20:38:06 -0400 | [diff] [blame] | 3970 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3971 | if (vec_len (unknown_scope)) |
| 3972 | { |
| 3973 | vlib_cli_output (vm, "\tOther-scope address(es):\n"); |
| 3974 | ip6_print_addrs (vm, unknown_scope); |
| 3975 | vec_free (unknown_scope); |
| 3976 | } |
Chris Luke | bfd32fd | 2016-06-24 20:38:06 -0400 | [diff] [blame] | 3977 | |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 3978 | vlib_cli_output (vm, "\tLink-local address(es):\n"); |
| 3979 | vlib_cli_output (vm, "\t\t%U\n", format_ip6_address, |
| 3980 | &radv_info->link_local_address); |
| 3981 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3982 | vlib_cli_output (vm, "\tJoined group address(es):\n"); |
| 3983 | ip6_mldp_group_t *m; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3984 | /* *INDENT-OFF* */ |
| 3985 | pool_foreach (m, radv_info->mldp_group_pool, |
| 3986 | ({ |
| 3987 | vlib_cli_output (vm, "\t\t%U\n", format_ip6_address, |
| 3988 | &m->mcast_address); |
| 3989 | })); |
| 3990 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3991 | |
| 3992 | vlib_cli_output (vm, "\tAdvertised Prefixes:\n"); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3993 | ip6_radv_prefix_t *p; |
| 3994 | /* *INDENT-OFF* */ |
| 3995 | pool_foreach (p, radv_info->adv_prefixes_pool, |
| 3996 | ({ |
| 3997 | vlib_cli_output (vm, "\t\tprefix %U, length %d\n", |
| 3998 | format_ip6_address, &p->prefix, p->prefix_len); |
| 3999 | })); |
| 4000 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4001 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4002 | vlib_cli_output (vm, "\tMTU is %d\n", radv_info->adv_link_mtu); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4003 | vlib_cli_output (vm, "\tICMP error messages are unlimited\n"); |
| 4004 | vlib_cli_output (vm, "\tICMP redirects are disabled\n"); |
| 4005 | vlib_cli_output (vm, "\tICMP unreachables are not sent\n"); |
| 4006 | vlib_cli_output (vm, "\tND DAD is disabled\n"); |
| 4007 | //vlib_cli_output (vm, "\tND reachable time is %d milliseconds\n",); |
| 4008 | vlib_cli_output (vm, "\tND advertised reachable time is %d\n", |
| 4009 | radv_info->adv_neighbor_reachable_time_in_msec); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4010 | vlib_cli_output (vm, |
| 4011 | "\tND advertised retransmit interval is %d (msec)\n", |
| 4012 | radv_info-> |
| 4013 | adv_time_in_msec_between_retransmitted_neighbor_solicitations); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4014 | |
| 4015 | u32 ra_interval = radv_info->max_radv_interval; |
| 4016 | u32 ra_interval_min = radv_info->min_radv_interval; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4017 | vlib_cli_output (vm, |
| 4018 | "\tND router advertisements are sent every %d seconds (min interval is %d)\n", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4019 | ra_interval, ra_interval_min); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4020 | vlib_cli_output (vm, |
| 4021 | "\tND router advertisements live for %d seconds\n", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4022 | radv_info->adv_router_lifetime_in_sec); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4023 | vlib_cli_output (vm, |
| 4024 | "\tHosts %s stateless autoconfig for addresses\n", |
| 4025 | (radv_info->adv_managed_flag) ? "use" : |
| 4026 | " don't use"); |
| 4027 | vlib_cli_output (vm, "\tND router advertisements sent %d\n", |
| 4028 | radv_info->n_advertisements_sent); |
| 4029 | vlib_cli_output (vm, "\tND router solicitations received %d\n", |
| 4030 | radv_info->n_solicitations_rcvd); |
| 4031 | vlib_cli_output (vm, "\tND router solicitations dropped %d\n", |
| 4032 | radv_info->n_solicitations_dropped); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4033 | } |
| 4034 | else |
| 4035 | { |
Chris Luke | bfd32fd | 2016-06-24 20:38:06 -0400 | [diff] [blame] | 4036 | error = clib_error_return (0, "IPv6 not enabled on interface", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4037 | format_unformat_error, input); |
| 4038 | |
| 4039 | } |
| 4040 | } |
| 4041 | return error; |
| 4042 | } |
| 4043 | |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 4044 | /*? |
| 4045 | * This command is used to display various IPv6 attributes on a given |
| 4046 | * interface. |
| 4047 | * |
| 4048 | * @cliexpar |
| 4049 | * Example of how to display IPv6 settings: |
| 4050 | * @cliexstart{show ip6 interface GigabitEthernet2/0/0} |
| 4051 | * GigabitEthernet2/0/0 is admin up |
| 4052 | * Link-local address(es): |
| 4053 | * fe80::ab8/64 |
| 4054 | * Joined group address(es): |
| 4055 | * ff02::1 |
| 4056 | * ff02::2 |
| 4057 | * ff02::16 |
| 4058 | * ff02::1:ff00:ab8 |
| 4059 | * Advertised Prefixes: |
| 4060 | * prefix fe80::fe:28ff:fe9c:75b3, length 64 |
| 4061 | * MTU is 1500 |
| 4062 | * ICMP error messages are unlimited |
| 4063 | * ICMP redirects are disabled |
| 4064 | * ICMP unreachables are not sent |
| 4065 | * ND DAD is disabled |
| 4066 | * ND advertised reachable time is 0 |
| 4067 | * ND advertised retransmit interval is 0 (msec) |
| 4068 | * ND router advertisements are sent every 200 seconds (min interval is 150) |
| 4069 | * ND router advertisements live for 600 seconds |
| 4070 | * Hosts use stateless autoconfig for addresses |
| 4071 | * ND router advertisements sent 19336 |
| 4072 | * ND router solicitations received 0 |
| 4073 | * ND router solicitations dropped 0 |
| 4074 | * @cliexend |
| 4075 | * Example of output if IPv6 is not enabled on the interface: |
| 4076 | * @cliexstart{show ip6 interface GigabitEthernet2/0/0} |
| 4077 | * show ip6 interface: IPv6 not enabled on interface |
| 4078 | * @cliexend |
| 4079 | ?*/ |
| 4080 | /* *INDENT-OFF* */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4081 | VLIB_CLI_COMMAND (show_ip6_interface_command, static) = |
| 4082 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4083 | .path = "show ip6 interface", |
| 4084 | .function = show_ip6_interface_cmd, |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 4085 | .short_help = "show ip6 interface <interface>", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4086 | }; |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 4087 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4088 | |
| 4089 | clib_error_t * |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4090 | disable_ip6_interface (vlib_main_t * vm, u32 sw_if_index) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4091 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4092 | clib_error_t *error = 0; |
| 4093 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4094 | u32 ri; |
| 4095 | |
| 4096 | /* look up the radv_t information for this interface */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4097 | vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index, |
| 4098 | ~0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4099 | ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4100 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4101 | /* if not created - do nothing */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4102 | if (ri != ~0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4103 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4104 | ip6_radv_t *radv_info; |
| 4105 | |
| 4106 | radv_info = pool_elt_at_index (nm->if_radv_pool, ri); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4107 | |
| 4108 | /* check radv_info ref count for other ip6 addresses on this interface */ |
Wojciech Dec | 7bc7310 | 2017-02-14 16:24:28 +0100 | [diff] [blame] | 4109 | /* This implicitly excludes the link local address */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4110 | if (radv_info->ref_count == 0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4111 | { |
| 4112 | /* essentially "disables" ipv6 on this interface */ |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 4113 | ip6_ll_prefix_t ilp = { |
| 4114 | .ilp_addr = radv_info->link_local_address, |
| 4115 | .ilp_sw_if_index = sw_if_index, |
| 4116 | }; |
| 4117 | ip6_ll_table_entry_delete (&ilp); |
| 4118 | ip6_sw_interface_enable_disable (sw_if_index, 0); |
Neale Ranns | 4008ac9 | 2017-02-13 23:20:04 -0800 | [diff] [blame] | 4119 | ip6_mfib_interface_enable_disable (sw_if_index, 0); |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 4120 | ip6_neighbor_sw_interface_add_del (vnet_get_main (), sw_if_index, |
| 4121 | 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4122 | } |
| 4123 | } |
| 4124 | return error; |
| 4125 | } |
| 4126 | |
| 4127 | int |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4128 | ip6_interface_enabled (vlib_main_t * vm, u32 sw_if_index) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4129 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4130 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 4131 | u32 ri = ~0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4132 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4133 | /* look up the radv_t information for this interface */ |
| 4134 | vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index, |
| 4135 | ~0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4136 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4137 | ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4138 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4139 | return ri != ~0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4140 | } |
| 4141 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4142 | clib_error_t * |
| 4143 | enable_ip6_interface (vlib_main_t * vm, u32 sw_if_index) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4144 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4145 | clib_error_t *error = 0; |
| 4146 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4147 | u32 ri; |
| 4148 | int is_add = 1; |
| 4149 | |
| 4150 | /* look up the radv_t information for this interface */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4151 | vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index, |
| 4152 | ~0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4153 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4154 | ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index]; |
| 4155 | |
| 4156 | /* if not created yet */ |
| 4157 | if (ri == ~0) |
| 4158 | { |
| 4159 | vnet_main_t *vnm = vnet_get_main (); |
| 4160 | vnet_sw_interface_t *sw_if0; |
| 4161 | |
| 4162 | sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index); |
| 4163 | if (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE) |
| 4164 | { |
| 4165 | ethernet_interface_t *eth_if0; |
| 4166 | |
| 4167 | eth_if0 = |
| 4168 | ethernet_get_interface (ðernet_main, sw_if0->hw_if_index); |
| 4169 | if (eth_if0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4170 | { |
| 4171 | /* create radv_info. for this interface. This holds all the info needed for router adverts */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4172 | ri = |
| 4173 | ip6_neighbor_sw_interface_add_del (vnm, sw_if_index, is_add); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4174 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4175 | if (ri != ~0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4176 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4177 | ip6_radv_t *radv_info; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4178 | ip6_address_t link_local_address; |
| 4179 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4180 | radv_info = pool_elt_at_index (nm->if_radv_pool, ri); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4181 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4182 | ip6_link_local_address_from_ethernet_mac_address |
| 4183 | (&link_local_address, eth_if0->address); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4184 | |
| 4185 | sw_if0 = vnet_get_sw_interface (vnm, sw_if_index); |
Pavel Kotucek | 8dc8020 | 2017-08-15 13:52:22 +0200 | [diff] [blame] | 4186 | if (sw_if0->type == VNET_SW_INTERFACE_TYPE_SUB || |
Neale Ranns | 17ff3c1 | 2018-07-04 10:24:24 -0700 | [diff] [blame] | 4187 | sw_if0->type == VNET_SW_INTERFACE_TYPE_PIPE || |
Pavel Kotucek | 8dc8020 | 2017-08-15 13:52:22 +0200 | [diff] [blame] | 4188 | sw_if0->type == VNET_SW_INTERFACE_TYPE_P2P) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4189 | { |
| 4190 | /* make up an interface id */ |
Dave Barach | 611d918 | 2018-03-12 15:56:41 -0400 | [diff] [blame] | 4191 | link_local_address.as_u64[1] = |
| 4192 | random_u64 (&radv_info->randomizer); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4193 | |
| 4194 | link_local_address.as_u64[0] = |
| 4195 | clib_host_to_net_u64 (0xFE80000000000000ULL); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4196 | /* clear u bit */ |
| 4197 | link_local_address.as_u8[8] &= 0xfd; |
| 4198 | } |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 4199 | { |
| 4200 | ip6_ll_prefix_t ilp = { |
| 4201 | .ilp_addr = link_local_address, |
| 4202 | .ilp_sw_if_index = sw_if_index, |
| 4203 | }; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4204 | |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 4205 | ip6_ll_table_entry_update (&ilp, FIB_ROUTE_PATH_LOCAL); |
| 4206 | } |
Neale Ranns | 4008ac9 | 2017-02-13 23:20:04 -0800 | [diff] [blame] | 4207 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4208 | /* essentially "enables" ipv6 on this interface */ |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 4209 | ip6_mfib_interface_enable_disable (sw_if_index, 1); |
| 4210 | ip6_sw_interface_enable_disable (sw_if_index, 1); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4211 | |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 4212 | if (!error) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4213 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4214 | radv_info->link_local_address = link_local_address; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4215 | } |
| 4216 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4217 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4218 | } |
| 4219 | } |
| 4220 | return error; |
| 4221 | } |
| 4222 | |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 4223 | int |
| 4224 | ip6_get_ll_address (u32 sw_if_index, ip6_address_t * addr) |
| 4225 | { |
| 4226 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 4227 | ip6_radv_t *radv_info; |
| 4228 | u32 ri; |
| 4229 | |
Eyal Bari | cd30774 | 2018-07-22 12:45:15 +0300 | [diff] [blame] | 4230 | if (vec_len (nm->if_radv_pool_index_by_sw_if_index) <= sw_if_index) |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 4231 | return 0; |
| 4232 | |
| 4233 | ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index]; |
| 4234 | |
| 4235 | if (ri == ~0) |
| 4236 | return 0; |
| 4237 | |
| 4238 | radv_info = pool_elt_at_index (nm->if_radv_pool, ri); |
| 4239 | *addr = radv_info->link_local_address; |
| 4240 | |
| 4241 | return (!0); |
| 4242 | } |
| 4243 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4244 | static clib_error_t * |
| 4245 | enable_ip6_interface_cmd (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4246 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4247 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4248 | vnet_main_t *vnm = vnet_get_main (); |
| 4249 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4250 | u32 sw_if_index; |
| 4251 | |
| 4252 | sw_if_index = ~0; |
| 4253 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4254 | if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4255 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4256 | enable_ip6_interface (vm, sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4257 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4258 | else |
| 4259 | { |
| 4260 | error = clib_error_return (0, "unknown interface\n'", |
| 4261 | format_unformat_error, input); |
| 4262 | |
| 4263 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4264 | return error; |
| 4265 | } |
| 4266 | |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 4267 | /*? |
| 4268 | * This command is used to enable IPv6 on a given interface. |
| 4269 | * |
| 4270 | * @cliexpar |
| 4271 | * Example of how enable IPv6 on a given interface: |
| 4272 | * @cliexcmd{enable ip6 interface GigabitEthernet2/0/0} |
| 4273 | ?*/ |
| 4274 | /* *INDENT-OFF* */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4275 | VLIB_CLI_COMMAND (enable_ip6_interface_command, static) = |
| 4276 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4277 | .path = "enable ip6 interface", |
| 4278 | .function = enable_ip6_interface_cmd, |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 4279 | .short_help = "enable ip6 interface <interface>", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4280 | }; |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 4281 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4282 | |
| 4283 | static clib_error_t * |
| 4284 | disable_ip6_interface_cmd (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4285 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4286 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4287 | vnet_main_t *vnm = vnet_get_main (); |
| 4288 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4289 | u32 sw_if_index; |
| 4290 | |
| 4291 | sw_if_index = ~0; |
| 4292 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4293 | if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4294 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4295 | error = disable_ip6_interface (vm, sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4296 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4297 | else |
| 4298 | { |
| 4299 | error = clib_error_return (0, "unknown interface\n'", |
| 4300 | format_unformat_error, input); |
| 4301 | |
| 4302 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4303 | return error; |
| 4304 | } |
| 4305 | |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 4306 | /*? |
| 4307 | * This command is used to disable IPv6 on a given interface. |
| 4308 | * |
| 4309 | * @cliexpar |
| 4310 | * Example of how disable IPv6 on a given interface: |
| 4311 | * @cliexcmd{disable ip6 interface GigabitEthernet2/0/0} |
| 4312 | ?*/ |
| 4313 | /* *INDENT-OFF* */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4314 | VLIB_CLI_COMMAND (disable_ip6_interface_command, static) = |
| 4315 | { |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 4316 | .path = "disable ip6 interface", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4317 | .function = disable_ip6_interface_cmd, |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 4318 | .short_help = "disable ip6 interface <interface>", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4319 | }; |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 4320 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4321 | |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 4322 | /*? |
| 4323 | * This command is used to configure the neighbor discovery |
| 4324 | * parameters on a given interface. Use the '<em>show ip6 interface</em>' |
| 4325 | * command to display some of the current neighbor discovery parameters |
| 4326 | * on a given interface. This command has three formats: |
| 4327 | * |
| 4328 | * |
| 4329 | * <b>Format 1 - Router Advertisement Options:</b> (Only one can be entered in a single command) |
| 4330 | * |
| 4331 | * '<em><b>ip6 nd <interface> [no] [ra-managed-config-flag] | [ra-other-config-flag] | [ra-suppress] | [ra-suppress-link-layer] | [ra-send-unicast] | [ra-lifetime <lifetime>] | [ra-initial <cnt> <interval>] | [ra-interval <max-interval> [<min-interval>]] | [ra-cease]</b></em>' |
| 4332 | * |
| 4333 | * Where: |
| 4334 | * |
| 4335 | * <em>[no] ra-managed-config-flag</em> - Advertises in ICMPv6 |
| 4336 | * router-advertisement messages to use stateful address |
| 4337 | * auto-configuration to obtain address information (sets the M-bit). |
| 4338 | * Default is the M-bit is not set and the '<em>no</em>' option |
| 4339 | * returns it to this default state. |
| 4340 | * |
| 4341 | * <em>[no] ra-other-config-flag</em> - Indicates in ICMPv6 |
| 4342 | * router-advertisement messages that hosts use stateful auto |
| 4343 | * configuration to obtain nonaddress related information (sets |
| 4344 | * the O-bit). Default is the O-bit is not set and the '<em>no</em>' |
| 4345 | * option returns it to this default state. |
| 4346 | * |
| 4347 | * <em>[no] ra-suppress</em> - Disables sending ICMPv6 router-advertisement |
| 4348 | * messages. The '<em>no</em>' option implies to enable sending ICMPv6 |
| 4349 | * router-advertisement messages. |
| 4350 | * |
| 4351 | * <em>[no] ra-suppress-link-layer</em> - Indicates not to include the |
| 4352 | * optional source link-layer address in the ICMPv6 router-advertisement |
| 4353 | * messages. Default is to include the optional source link-layer address |
| 4354 | * and the '<em>no</em>' option returns it to this default state. |
| 4355 | * |
| 4356 | * <em>[no] ra-send-unicast</em> - Use the source address of the |
| 4357 | * router-solicitation message if availiable. The default is to use |
| 4358 | * multicast address of all nodes, and the '<em>no</em>' option returns |
| 4359 | * it to this default state. |
| 4360 | * |
| 4361 | * <em>[no] ra-lifetime <lifetime></em> - Advertises the lifetime of a |
| 4362 | * default router in ICMPv6 router-advertisement messages. The range is |
| 4363 | * from 0 to 9000 seconds. '<em><lifetime></em>' must be greater than |
| 4364 | * '<em><max-interval></em>'. The default value is 600 seconds and the |
| 4365 | * '<em>no</em>' option returns it to this default value. |
| 4366 | * |
| 4367 | * <em>[no] ra-initial <cnt> <interval></em> - Number of initial ICMPv6 |
| 4368 | * router-advertisement messages sent and the interval between each |
| 4369 | * message. Range for count is 1 - 3 and default is 3. Range for interval |
| 4370 | * is 1 to 16 seconds, and default is 16 seconds. The '<em>no</em>' option |
| 4371 | * returns both to their default value. |
| 4372 | * |
| 4373 | * <em>[no] ra-interval <max-interval> [<min-interval>]</em> - Configures the |
| 4374 | * interval between sending ICMPv6 router-advertisement messages. The |
| 4375 | * range for max-interval is from 4 to 200 seconds. min-interval can not |
| 4376 | * be more than 75% of max-interval. If not set, min-interval will be |
| 4377 | * set to 75% of max-interval. The range for min-interval is from 3 to |
| 4378 | * 150 seconds. The '<em>no</em>' option returns both to their default |
| 4379 | * value. |
| 4380 | * |
| 4381 | * <em>[no] ra-cease</em> - Cease sending ICMPv6 router-advertisement messages. |
| 4382 | * The '<em>no</em>' options implies to start (or restart) sending |
| 4383 | * ICMPv6 router-advertisement messages. |
| 4384 | * |
| 4385 | * |
| 4386 | * <b>Format 2 - Prefix Options:</b> |
| 4387 | * |
| 4388 | * '<em><b>ip6 nd <interface> [no] prefix <ip6-address>/<width> [<valid-lifetime> <pref-lifetime> | infinite] [no-advertise] [off-link] [no-autoconfig] [no-onlink]</b></em>' |
| 4389 | * |
| 4390 | * Where: |
| 4391 | * |
| 4392 | * <em>no</em> - All additional flags are ignored and the prefix is deleted. |
| 4393 | * |
| 4394 | * <em><valid-lifetime> <pref-lifetime></em> - '<em><valid-lifetime></em>' is the |
| 4395 | * length of time in seconds during what the prefix is valid for the purpose of |
| 4396 | * on-link determination. Range is 7203 to 2592000 seconds and default is 2592000 |
| 4397 | * seconds (30 days). '<em><pref-lifetime></em>' is the prefered-lifetime and is the |
| 4398 | * length of time in seconds during what addresses generated from the prefix remain |
| 4399 | * preferred. Range is 0 to 604800 seconds and default is 604800 seconds (7 days). |
| 4400 | * |
| 4401 | * <em>infinite</em> - Both '<em><valid-lifetime></em>' and '<em><<pref-lifetime></em>' |
| 4402 | * are inifinte, no timeout. |
| 4403 | * |
| 4404 | * <em>no-advertise</em> - Do not send full router address in prefix |
| 4405 | * advertisement. Default is to advertise (i.e. - This flag is off by default). |
| 4406 | * |
| 4407 | * <em>off-link</em> - Prefix is off-link, clear L-bit in packet. Default is on-link |
| 4408 | * (i.e. - This flag is off and L-bit in packet is set by default and this prefix can |
| 4409 | * be used for on-link determination). '<em>no-onlink</em>' also controls the L-bit. |
| 4410 | * |
| 4411 | * <em>no-autoconfig</em> - Do not use prefix for autoconfiguration, clear A-bit in packet. |
| 4412 | * Default is autoconfig (i.e. - This flag is off and A-bit in packet is set by default. |
| 4413 | * |
| 4414 | * <em>no-onlink</em> - Do not use prefix for onlink determination, clear L-bit in packet. |
| 4415 | * Default is on-link (i.e. - This flag is off and L-bit in packet is set by default and |
| 4416 | * this prefix can be used for on-link determination). '<em>off-link</em>' also controls |
| 4417 | * the L-bit. |
| 4418 | * |
| 4419 | * |
| 4420 | * <b>Format 3: - Default of Prefix:</b> |
| 4421 | * |
| 4422 | * '<em><b>ip6 nd <interface> [no] prefix <ip6-address>/<width> default</b></em>' |
| 4423 | * |
| 4424 | * When a new prefix is added (or existing one is being overwritten) <em>default</em> |
| 4425 | * uses default values for the prefix. If <em>no</em> is used, the <em>default</em> |
| 4426 | * is ignored and the prefix is deleted. |
| 4427 | * |
| 4428 | * |
| 4429 | * @cliexpar |
| 4430 | * Example of how set a router advertisement option: |
| 4431 | * @cliexcmd{ip6 nd GigabitEthernet2/0/0 ra-interval 100 20} |
| 4432 | * Example of how to add a prefix: |
| 4433 | * @cliexcmd{ip6 nd GigabitEthernet2/0/0 prefix fe80::fe:28ff:fe9c:75b3/64 infinite no-advertise} |
| 4434 | * Example of how to delete a prefix: |
| 4435 | * @cliexcmd{ip6 nd GigabitEthernet2/0/0 no prefix fe80::fe:28ff:fe9c:75b3/64} |
| 4436 | ?*/ |
| 4437 | /* *INDENT-OFF* */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4438 | VLIB_CLI_COMMAND (ip6_nd_command, static) = |
| 4439 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4440 | .path = "ip6 nd", |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 4441 | .short_help = "ip6 nd <interface> ...", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4442 | .function = ip6_neighbor_cmd, |
| 4443 | }; |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 4444 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4445 | |
| 4446 | clib_error_t * |
Juraj Sloboda | 5bb1eca | 2018-10-22 09:57:13 +0200 | [diff] [blame] | 4447 | ip6_neighbor_set_link_local_address (vlib_main_t * vm, u32 sw_if_index, |
| 4448 | ip6_address_t * address) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4449 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4450 | clib_error_t *error = 0; |
| 4451 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4452 | u32 ri; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4453 | ip6_radv_t *radv_info; |
| 4454 | vnet_main_t *vnm = vnet_get_main (); |
Juraj Sloboda | 5bb1eca | 2018-10-22 09:57:13 +0200 | [diff] [blame] | 4455 | ip6_ll_prefix_t pfx = { 0, }; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4456 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4457 | if (!ip6_address_is_link_local_unicast (address)) |
Juraj Sloboda | 5bb1eca | 2018-10-22 09:57:13 +0200 | [diff] [blame] | 4458 | return (error = clib_error_return (0, "address not link-local", |
| 4459 | format_unformat_error)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4460 | |
| 4461 | /* call enable ipv6 */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4462 | enable_ip6_interface (vm, sw_if_index); |
| 4463 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4464 | ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4465 | |
| 4466 | if (ri != ~0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4467 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4468 | radv_info = pool_elt_at_index (nm->if_radv_pool, ri); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4469 | |
Juraj Sloboda | 5bb1eca | 2018-10-22 09:57:13 +0200 | [diff] [blame] | 4470 | pfx.ilp_sw_if_index = sw_if_index; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4471 | |
Juraj Sloboda | 5bb1eca | 2018-10-22 09:57:13 +0200 | [diff] [blame] | 4472 | pfx.ilp_addr = radv_info->link_local_address; |
| 4473 | ip6_ll_table_entry_delete (&pfx); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4474 | |
Juraj Sloboda | 5bb1eca | 2018-10-22 09:57:13 +0200 | [diff] [blame] | 4475 | pfx.ilp_addr = *address; |
| 4476 | ip6_ll_table_entry_update (&pfx, FIB_ROUTE_PATH_LOCAL); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4477 | |
Juraj Sloboda | 5bb1eca | 2018-10-22 09:57:13 +0200 | [diff] [blame] | 4478 | radv_info = pool_elt_at_index (nm->if_radv_pool, ri); |
| 4479 | radv_info->link_local_address = *address; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4480 | } |
| 4481 | else |
| 4482 | { |
| 4483 | vnm->api_errno = VNET_API_ERROR_IP6_NOT_ENABLED; |
| 4484 | error = clib_error_return (0, "ip6 not enabled for interface", |
| 4485 | format_unformat_error); |
| 4486 | } |
| 4487 | return error; |
| 4488 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4489 | |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 4490 | /** |
| 4491 | * @brief callback when an interface address is added or deleted |
| 4492 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4493 | static void |
| 4494 | ip6_neighbor_add_del_interface_address (ip6_main_t * im, |
| 4495 | uword opaque, |
| 4496 | u32 sw_if_index, |
| 4497 | ip6_address_t * address, |
| 4498 | u32 address_length, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4499 | u32 if_address_index, u32 is_delete) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4500 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4501 | vnet_main_t *vnm = vnet_get_main (); |
| 4502 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4503 | u32 ri; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4504 | vlib_main_t *vm = vnm->vlib_main; |
| 4505 | ip6_radv_t *radv_info; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4506 | ip6_address_t a; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4507 | |
| 4508 | /* create solicited node multicast address for this interface adddress */ |
| 4509 | ip6_set_solicited_node_multicast_address (&a, 0); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4510 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4511 | a.as_u8[0xd] = address->as_u8[0xd]; |
| 4512 | a.as_u8[0xe] = address->as_u8[0xe]; |
| 4513 | a.as_u8[0xf] = address->as_u8[0xf]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4514 | |
| 4515 | if (!is_delete) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4516 | { |
| 4517 | /* try to create radv_info - does nothing if ipv6 already enabled */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4518 | enable_ip6_interface (vm, sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4519 | |
| 4520 | /* look up the radv_t information for this interface */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4521 | vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, |
| 4522 | sw_if_index, ~0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4523 | ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4524 | if (ri != ~0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4525 | { |
| 4526 | /* get radv_info */ |
| 4527 | radv_info = pool_elt_at_index (nm->if_radv_pool, ri); |
| 4528 | |
| 4529 | /* add address */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4530 | if (!ip6_address_is_link_local_unicast (address)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4531 | radv_info->ref_count++; |
| 4532 | |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 4533 | ip6_neighbor_add_mld_prefix (radv_info, &a); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4534 | } |
| 4535 | } |
| 4536 | else |
| 4537 | { |
| 4538 | |
| 4539 | /* delete */ |
| 4540 | /* look up the radv_t information for this interface */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4541 | vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, |
| 4542 | sw_if_index, ~0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4543 | ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index]; |
Wojciech Dec | 7bc7310 | 2017-02-14 16:24:28 +0100 | [diff] [blame] | 4544 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4545 | if (ri != ~0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4546 | { |
| 4547 | /* get radv_info */ |
| 4548 | radv_info = pool_elt_at_index (nm->if_radv_pool, ri); |
| 4549 | |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 4550 | ip6_neighbor_del_mld_prefix (radv_info, &a); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4551 | |
| 4552 | /* if interface up send MLDP "report" */ |
| 4553 | radv_info->all_routers_mcast = 0; |
| 4554 | |
| 4555 | /* add address */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4556 | if (!ip6_address_is_link_local_unicast (address)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4557 | radv_info->ref_count--; |
| 4558 | } |
Wojciech Dec | 7bc7310 | 2017-02-14 16:24:28 +0100 | [diff] [blame] | 4559 | /* Ensure that IPv6 is disabled, and LL removed after ref_count reaches 0 */ |
| 4560 | disable_ip6_interface (vm, sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4561 | } |
| 4562 | } |
| 4563 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4564 | clib_error_t * |
| 4565 | ip6_set_neighbor_limit (u32 neighbor_limit) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4566 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4567 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4568 | |
| 4569 | nm->limit_neighbor_cache_size = neighbor_limit; |
| 4570 | return 0; |
| 4571 | } |
| 4572 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 4573 | static void |
| 4574 | ip6_neighbor_table_bind (ip6_main_t * im, |
| 4575 | uword opaque, |
| 4576 | u32 sw_if_index, |
| 4577 | u32 new_fib_index, u32 old_fib_index) |
| 4578 | { |
| 4579 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 4580 | ip6_neighbor_t *n = NULL; |
| 4581 | u32 i, *to_re_add = 0; |
| 4582 | |
| 4583 | /* *INDENT-OFF* */ |
| 4584 | pool_foreach (n, nm->neighbor_pool, |
| 4585 | ({ |
| 4586 | if (n->key.sw_if_index == sw_if_index) |
| 4587 | vec_add1 (to_re_add, n - nm->neighbor_pool); |
| 4588 | })); |
| 4589 | /* *INDENT-ON* */ |
| 4590 | |
| 4591 | for (i = 0; i < vec_len (to_re_add); i++) |
| 4592 | { |
| 4593 | n = pool_elt_at_index (nm->neighbor_pool, to_re_add[i]); |
| 4594 | ip6_neighbor_adj_fib_remove (n, old_fib_index); |
| 4595 | ip6_neighbor_adj_fib_add (n, new_fib_index); |
| 4596 | } |
| 4597 | vec_free (to_re_add); |
| 4598 | } |
| 4599 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4600 | static clib_error_t * |
| 4601 | ip6_neighbor_init (vlib_main_t * vm) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4602 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4603 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 4604 | ip6_main_t *im = &ip6_main; |
| 4605 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4606 | mhash_init (&nm->neighbor_index_by_key, |
| 4607 | /* value size */ sizeof (uword), |
| 4608 | /* key size */ sizeof (ip6_neighbor_key_t)); |
| 4609 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4610 | icmp6_register_type (vm, ICMP6_neighbor_solicitation, |
| 4611 | ip6_icmp_neighbor_solicitation_node.index); |
| 4612 | icmp6_register_type (vm, ICMP6_neighbor_advertisement, |
| 4613 | ip6_icmp_neighbor_advertisement_node.index); |
| 4614 | icmp6_register_type (vm, ICMP6_router_solicitation, |
| 4615 | ip6_icmp_router_solicitation_node.index); |
| 4616 | icmp6_register_type (vm, ICMP6_router_advertisement, |
| 4617 | ip6_icmp_router_advertisement_node.index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4618 | |
| 4619 | /* handler node for ip6 neighbor discovery events and timers */ |
| 4620 | vlib_register_node (vm, &ip6_icmp_neighbor_discovery_event_node); |
| 4621 | |
| 4622 | /* add call backs */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4623 | ip6_add_del_interface_address_callback_t cb; |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 4624 | clib_memset (&cb, 0x0, sizeof (ip6_add_del_interface_address_callback_t)); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4625 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4626 | /* when an interface address changes... */ |
| 4627 | cb.function = ip6_neighbor_add_del_interface_address; |
| 4628 | cb.function_opaque = 0; |
| 4629 | vec_add1 (im->add_del_interface_address_callbacks, cb); |
| 4630 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 4631 | ip6_table_bind_callback_t cbt; |
| 4632 | cbt.function = ip6_neighbor_table_bind; |
| 4633 | cbt.function_opaque = 0; |
| 4634 | vec_add1 (im->table_bind_callbacks, cbt); |
| 4635 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4636 | mhash_init (&nm->pending_resolutions_by_address, |
| 4637 | /* value size */ sizeof (uword), |
| 4638 | /* key size */ sizeof (ip6_address_t)); |
| 4639 | |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4640 | mhash_init (&nm->mac_changes_by_address, |
| 4641 | /* value size */ sizeof (uword), |
| 4642 | /* key size */ sizeof (ip6_address_t)); |
| 4643 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4644 | /* default, configurable */ |
| 4645 | nm->limit_neighbor_cache_size = 50000; |
| 4646 | |
Eyal Bari | c125ecc | 2017-09-20 11:29:17 +0300 | [diff] [blame] | 4647 | nm->wc_ip6_nd_publisher_node = (uword) ~ 0; |
| 4648 | |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 4649 | nm->ip6_ra_publisher_node = (uword) ~ 0; |
| 4650 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4651 | #if 0 |
| 4652 | /* $$$$ Hack fix for today */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4653 | vec_validate_init_empty |
| 4654 | (im->discover_neighbor_next_index_by_hw_if_index, 32, 0 /* drop */ ); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4655 | #endif |
| 4656 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4657 | return 0; |
| 4658 | } |
| 4659 | |
| 4660 | VLIB_INIT_FUNCTION (ip6_neighbor_init); |
| 4661 | |
| 4662 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4663 | void |
| 4664 | vnet_register_ip6_neighbor_resolution_event (vnet_main_t * vnm, |
| 4665 | void *address_arg, |
| 4666 | uword node_index, |
| 4667 | uword type_opaque, uword data) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4668 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4669 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 4670 | ip6_address_t *address = address_arg; |
| 4671 | uword *p; |
| 4672 | pending_resolution_t *pr; |
| 4673 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4674 | pool_get (nm->pending_resolutions, pr); |
| 4675 | |
| 4676 | pr->next_index = ~0; |
| 4677 | pr->node_index = node_index; |
| 4678 | pr->type_opaque = type_opaque; |
| 4679 | pr->data = data; |
| 4680 | |
| 4681 | p = mhash_get (&nm->pending_resolutions_by_address, address); |
| 4682 | if (p) |
| 4683 | { |
| 4684 | /* Insert new resolution at the head of the list */ |
| 4685 | pr->next_index = p[0]; |
| 4686 | mhash_unset (&nm->pending_resolutions_by_address, address, 0); |
| 4687 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4688 | |
| 4689 | mhash_set (&nm->pending_resolutions_by_address, address, |
| 4690 | pr - nm->pending_resolutions, 0 /* old value */ ); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4691 | } |
| 4692 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4693 | int |
| 4694 | vnet_add_del_ip6_nd_change_event (vnet_main_t * vnm, |
| 4695 | void *data_callback, |
| 4696 | u32 pid, |
| 4697 | void *address_arg, |
| 4698 | uword node_index, |
| 4699 | uword type_opaque, uword data, int is_add) |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4700 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4701 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 4702 | ip6_address_t *address = address_arg; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4703 | |
Eyal Bari | f9f4065 | 2017-04-01 03:55:08 +0300 | [diff] [blame] | 4704 | /* Try to find an existing entry */ |
| 4705 | u32 *first = (u32 *) mhash_get (&nm->mac_changes_by_address, address); |
| 4706 | u32 *p = first; |
| 4707 | pending_resolution_t *mc; |
| 4708 | while (p && *p != ~0) |
| 4709 | { |
| 4710 | mc = pool_elt_at_index (nm->mac_changes, *p); |
| 4711 | if (mc->node_index == node_index && mc->type_opaque == type_opaque |
| 4712 | && mc->pid == pid) |
| 4713 | break; |
| 4714 | p = &mc->next_index; |
| 4715 | } |
| 4716 | |
| 4717 | int found = p && *p != ~0; |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4718 | if (is_add) |
| 4719 | { |
Eyal Bari | f9f4065 | 2017-04-01 03:55:08 +0300 | [diff] [blame] | 4720 | if (found) |
| 4721 | return VNET_API_ERROR_ENTRY_ALREADY_EXISTS; |
| 4722 | |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4723 | pool_get (nm->mac_changes, mc); |
Neale Ranns | f12dad6 | 2018-06-04 18:41:24 -0700 | [diff] [blame] | 4724 | /* *INDENT-OFF* */ |
Eyal Bari | f9f4065 | 2017-04-01 03:55:08 +0300 | [diff] [blame] | 4725 | *mc = (pending_resolution_t) |
| 4726 | { |
Neale Ranns | f12dad6 | 2018-06-04 18:41:24 -0700 | [diff] [blame] | 4727 | .next_index = ~0, |
| 4728 | .node_index = node_index, |
| 4729 | .type_opaque = type_opaque, |
| 4730 | .data = data, |
| 4731 | .data_callback = data_callback, |
| 4732 | .pid = pid, |
| 4733 | }; |
| 4734 | /* *INDENT-ON* */ |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4735 | |
Eyal Bari | f9f4065 | 2017-04-01 03:55:08 +0300 | [diff] [blame] | 4736 | /* Insert new resolution at the end of the list */ |
| 4737 | u32 new_idx = mc - nm->mac_changes; |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4738 | if (p) |
Eyal Bari | f9f4065 | 2017-04-01 03:55:08 +0300 | [diff] [blame] | 4739 | p[0] = new_idx; |
| 4740 | else |
| 4741 | mhash_set (&nm->mac_changes_by_address, address, new_idx, 0); |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4742 | } |
| 4743 | else |
| 4744 | { |
Eyal Bari | f9f4065 | 2017-04-01 03:55:08 +0300 | [diff] [blame] | 4745 | if (!found) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4746 | return VNET_API_ERROR_NO_SUCH_ENTRY; |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4747 | |
Eyal Bari | f9f4065 | 2017-04-01 03:55:08 +0300 | [diff] [blame] | 4748 | /* Clients may need to clean up pool entries, too */ |
| 4749 | void (*fp) (u32, u8 *) = data_callback; |
| 4750 | if (fp) |
| 4751 | (*fp) (mc->data, 0 /* no new mac addrs */ ); |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4752 | |
Eyal Bari | f9f4065 | 2017-04-01 03:55:08 +0300 | [diff] [blame] | 4753 | /* Remove the entry from the list and delete the entry */ |
| 4754 | *p = mc->next_index; |
| 4755 | pool_put (nm->mac_changes, mc); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4756 | |
Eyal Bari | f9f4065 | 2017-04-01 03:55:08 +0300 | [diff] [blame] | 4757 | /* Remove from hash if we deleted the last entry */ |
| 4758 | if (*p == ~0 && p == first) |
| 4759 | mhash_unset (&nm->mac_changes_by_address, address, 0); |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4760 | } |
Eyal Bari | f9f4065 | 2017-04-01 03:55:08 +0300 | [diff] [blame] | 4761 | return 0; |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4762 | } |
| 4763 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4764 | int |
| 4765 | vnet_ip6_nd_term (vlib_main_t * vm, |
| 4766 | vlib_node_runtime_t * node, |
| 4767 | vlib_buffer_t * p0, |
| 4768 | ethernet_header_t * eth, |
Eyal Bari | a0623f8 | 2017-03-30 03:05:06 +0300 | [diff] [blame] | 4769 | ip6_header_t * ip, u32 sw_if_index, u16 bd_index) |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4770 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4771 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 4772 | icmp6_neighbor_solicitation_or_advertisement_header_t *ndh; |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4773 | |
| 4774 | ndh = ip6_next_header (ip); |
| 4775 | if (ndh->icmp.type != ICMP6_neighbor_solicitation && |
| 4776 | ndh->icmp.type != ICMP6_neighbor_advertisement) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4777 | return 0; |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4778 | |
| 4779 | if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && |
| 4780 | (p0->flags & VLIB_BUFFER_IS_TRACED))) |
| 4781 | { |
| 4782 | u8 *t0 = vlib_add_trace (vm, node, p0, |
| 4783 | sizeof (icmp6_input_trace_t)); |
| 4784 | clib_memcpy (t0, ip, sizeof (icmp6_input_trace_t)); |
| 4785 | } |
| 4786 | |
| 4787 | /* Check if anyone want ND events for L2 BDs */ |
Eyal Bari | c125ecc | 2017-09-20 11:29:17 +0300 | [diff] [blame] | 4788 | if (PREDICT_FALSE |
| 4789 | (nm->wc_ip6_nd_publisher_node != (uword) ~ 0 |
| 4790 | && !ip6_address_is_link_local_unicast (&ip->src_address))) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4791 | { |
Eyal Bari | c125ecc | 2017-09-20 11:29:17 +0300 | [diff] [blame] | 4792 | vnet_nd_wc_publish (sw_if_index, eth->src_address, &ip->src_address); |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4793 | } |
| 4794 | |
| 4795 | /* Check if MAC entry exsist for solicited target IP */ |
| 4796 | if (ndh->icmp.type == ICMP6_neighbor_solicitation) |
| 4797 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4798 | icmp6_neighbor_discovery_ethernet_link_layer_address_option_t *opt; |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4799 | l2_bridge_domain_t *bd_config; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4800 | u8 *macp; |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4801 | |
| 4802 | opt = (void *) (ndh + 1); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4803 | if ((opt->header.type != |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4804 | ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address) || |
| 4805 | (opt->header.n_data_u64s != 1)) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4806 | return 0; /* source link layer address option not present */ |
| 4807 | |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4808 | bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4809 | macp = |
| 4810 | (u8 *) hash_get_mem (bd_config->mac_by_ip6, &ndh->target_address); |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4811 | if (macp) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4812 | { /* found ip-mac entry, generate eighbor advertisement response */ |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4813 | int bogus_length; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4814 | vlib_node_runtime_t *error_node = |
| 4815 | vlib_node_get_runtime (vm, ip6_icmp_input_node.index); |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4816 | ip->dst_address = ip->src_address; |
| 4817 | ip->src_address = ndh->target_address; |
| 4818 | ip->hop_limit = 255; |
| 4819 | opt->header.type = |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4820 | ICMP6_NEIGHBOR_DISCOVERY_OPTION_target_link_layer_address; |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4821 | clib_memcpy (opt->ethernet_address, macp, 6); |
| 4822 | ndh->icmp.type = ICMP6_neighbor_advertisement; |
| 4823 | ndh->advertisement_flags = clib_host_to_net_u32 |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4824 | (ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_SOLICITED | |
| 4825 | ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_OVERRIDE); |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4826 | ndh->icmp.checksum = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4827 | ndh->icmp.checksum = |
| 4828 | ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip, &bogus_length); |
| 4829 | clib_memcpy (eth->dst_address, eth->src_address, 6); |
| 4830 | clib_memcpy (eth->src_address, macp, 6); |
| 4831 | vlib_error_count (vm, error_node->node_index, |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4832 | ICMP6_ERROR_NEIGHBOR_ADVERTISEMENTS_TX, 1); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4833 | return 1; |
| 4834 | } |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4835 | } |
| 4836 | |
| 4837 | return 0; |
| 4838 | |
| 4839 | } |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 4840 | |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 4841 | int |
| 4842 | ip6_neighbor_proxy_add_del (u32 sw_if_index, ip6_address_t * addr, u8 is_del) |
| 4843 | { |
| 4844 | u32 fib_index; |
| 4845 | |
| 4846 | fib_prefix_t pfx = { |
| 4847 | .fp_len = 128, |
| 4848 | .fp_proto = FIB_PROTOCOL_IP6, |
| 4849 | .fp_addr = { |
| 4850 | .ip6 = *addr, |
| 4851 | }, |
| 4852 | }; |
| 4853 | ip46_address_t nh = { |
| 4854 | .ip6 = *addr, |
| 4855 | }; |
| 4856 | |
| 4857 | fib_index = ip6_fib_table_get_index_for_sw_if_index (sw_if_index); |
| 4858 | |
| 4859 | if (~0 == fib_index) |
| 4860 | return VNET_API_ERROR_NO_SUCH_FIB; |
| 4861 | |
| 4862 | if (is_del) |
| 4863 | { |
| 4864 | fib_table_entry_path_remove (fib_index, |
| 4865 | &pfx, |
| 4866 | FIB_SOURCE_IP6_ND_PROXY, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 4867 | DPO_PROTO_IP6, |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 4868 | &nh, |
| 4869 | sw_if_index, |
| 4870 | ~0, 1, FIB_ROUTE_PATH_FLAG_NONE); |
| 4871 | /* flush the ND cache of this address if it's there */ |
Neale Ranns | 0bdd319 | 2018-09-07 11:04:52 -0700 | [diff] [blame] | 4872 | vnet_unset_ip6_ethernet_neighbor (vlib_get_main (), sw_if_index, addr); |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 4873 | } |
| 4874 | else |
| 4875 | { |
| 4876 | fib_table_entry_path_add (fib_index, |
| 4877 | &pfx, |
| 4878 | FIB_SOURCE_IP6_ND_PROXY, |
| 4879 | FIB_ENTRY_FLAG_NONE, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 4880 | DPO_PROTO_IP6, |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 4881 | &nh, |
| 4882 | sw_if_index, |
| 4883 | ~0, 1, NULL, FIB_ROUTE_PATH_FLAG_NONE); |
| 4884 | } |
| 4885 | return (0); |
| 4886 | } |
| 4887 | |
| 4888 | static clib_error_t * |
| 4889 | set_ip6_nd_proxy_cmd (vlib_main_t * vm, |
| 4890 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 4891 | { |
| 4892 | vnet_main_t *vnm = vnet_get_main (); |
| 4893 | clib_error_t *error = 0; |
| 4894 | ip6_address_t addr; |
| 4895 | u32 sw_if_index; |
| 4896 | u8 is_del = 0; |
| 4897 | |
| 4898 | if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 4899 | { |
| 4900 | /* get the rest of the command */ |
| 4901 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 4902 | { |
| 4903 | if (unformat (input, "%U", unformat_ip6_address, &addr)) |
| 4904 | break; |
| 4905 | else if (unformat (input, "delete") || unformat (input, "del")) |
| 4906 | is_del = 1; |
| 4907 | else |
| 4908 | return (unformat_parse_error (input)); |
| 4909 | } |
| 4910 | } |
| 4911 | |
| 4912 | ip6_neighbor_proxy_add_del (sw_if_index, &addr, is_del); |
| 4913 | |
| 4914 | return error; |
| 4915 | } |
| 4916 | |
| 4917 | /* *INDENT-OFF* */ |
| 4918 | VLIB_CLI_COMMAND (set_ip6_nd_proxy_command, static) = |
| 4919 | { |
| 4920 | .path = "set ip6 nd proxy", |
| 4921 | .short_help = "set ip6 nd proxy <HOST> <INTERFACE>", |
| 4922 | .function = set_ip6_nd_proxy_cmd, |
| 4923 | }; |
| 4924 | /* *INDENT-ON* */ |
| 4925 | |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 4926 | void |
Neale Ranns | 3be6b28 | 2016-12-20 14:24:01 +0000 | [diff] [blame] | 4927 | ethernet_ndp_change_mac (u32 sw_if_index) |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 4928 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4929 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 4930 | ip6_neighbor_t *n; |
Neale Ranns | c819fc6 | 2018-02-16 02:44:05 -0800 | [diff] [blame] | 4931 | adj_index_t ai; |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 4932 | |
| 4933 | /* *INDENT-OFF* */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4934 | pool_foreach (n, nm->neighbor_pool, |
| 4935 | ({ |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 4936 | if (n->key.sw_if_index == sw_if_index) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4937 | { |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 4938 | adj_nbr_walk_nh6 (sw_if_index, |
| 4939 | &n->key.ip6_address, |
| 4940 | ip6_nd_mk_complete_walk, n); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4941 | } |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 4942 | })); |
| 4943 | /* *INDENT-ON* */ |
Neale Ranns | c819fc6 | 2018-02-16 02:44:05 -0800 | [diff] [blame] | 4944 | |
| 4945 | ai = adj_glean_get (FIB_PROTOCOL_IP6, sw_if_index); |
| 4946 | |
| 4947 | if (ADJ_INDEX_INVALID != ai) |
| 4948 | adj_glean_update_rewrite (ai); |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 4949 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4950 | |
John Lo | 8b81cb4 | 2017-06-26 01:40:20 -0400 | [diff] [blame] | 4951 | void |
Steven | 9f781d8 | 2018-06-05 11:09:32 -0700 | [diff] [blame] | 4952 | send_ip6_na (vlib_main_t * vm, u32 sw_if_index) |
John Lo | 8b81cb4 | 2017-06-26 01:40:20 -0400 | [diff] [blame] | 4953 | { |
| 4954 | ip6_main_t *i6m = &ip6_main; |
John Lo | 8b81cb4 | 2017-06-26 01:40:20 -0400 | [diff] [blame] | 4955 | ip6_address_t *ip6_addr = ip6_interface_first_address (i6m, sw_if_index); |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 4956 | |
Steven | 9f781d8 | 2018-06-05 11:09:32 -0700 | [diff] [blame] | 4957 | send_ip6_na_w_addr (vm, ip6_addr, sw_if_index); |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 4958 | } |
| 4959 | |
| 4960 | void |
| 4961 | send_ip6_na_w_addr (vlib_main_t * vm, |
Steven | 9f781d8 | 2018-06-05 11:09:32 -0700 | [diff] [blame] | 4962 | const ip6_address_t * ip6_addr, u32 sw_if_index) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 4963 | { |
| 4964 | ip6_main_t *i6m = &ip6_main; |
Steven | 9f781d8 | 2018-06-05 11:09:32 -0700 | [diff] [blame] | 4965 | vnet_main_t *vnm = vnet_get_main (); |
| 4966 | u8 *rewrite, rewrite_len; |
| 4967 | vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm, sw_if_index); |
| 4968 | u8 dst_address[6]; |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 4969 | |
John Lo | 8b81cb4 | 2017-06-26 01:40:20 -0400 | [diff] [blame] | 4970 | if (ip6_addr) |
| 4971 | { |
| 4972 | clib_warning |
| 4973 | ("Sending unsolicitated NA IP6 address %U on sw_if_idex %d", |
| 4974 | format_ip6_address, ip6_addr, sw_if_index); |
| 4975 | |
| 4976 | /* Form unsolicited neighbor advertisement packet from NS pkt template */ |
| 4977 | int bogus_length; |
| 4978 | u32 bi = 0; |
| 4979 | icmp6_neighbor_solicitation_header_t *h = |
| 4980 | vlib_packet_template_get_packet (vm, |
| 4981 | &i6m->discover_neighbor_packet_template, |
| 4982 | &bi); |
John Lo | 084606b | 2018-06-19 15:27:48 -0400 | [diff] [blame] | 4983 | if (!h) |
| 4984 | return; |
| 4985 | |
John Lo | 8b81cb4 | 2017-06-26 01:40:20 -0400 | [diff] [blame] | 4986 | ip6_set_reserved_multicast_address (&h->ip.dst_address, |
| 4987 | IP6_MULTICAST_SCOPE_link_local, |
| 4988 | IP6_MULTICAST_GROUP_ID_all_hosts); |
| 4989 | h->ip.src_address = ip6_addr[0]; |
| 4990 | h->neighbor.icmp.type = ICMP6_neighbor_advertisement; |
| 4991 | h->neighbor.target_address = ip6_addr[0]; |
| 4992 | h->neighbor.advertisement_flags = clib_host_to_net_u32 |
| 4993 | (ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_OVERRIDE); |
ahdj007 | 22130e1 | 2018-08-14 10:35:43 +0800 | [diff] [blame] | 4994 | h->link_layer_option.header.type = |
| 4995 | ICMP6_NEIGHBOR_DISCOVERY_OPTION_target_link_layer_address; |
John Lo | 8b81cb4 | 2017-06-26 01:40:20 -0400 | [diff] [blame] | 4996 | clib_memcpy (h->link_layer_option.ethernet_address, |
| 4997 | hi->hw_address, vec_len (hi->hw_address)); |
| 4998 | h->neighbor.icmp.checksum = |
| 4999 | ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h->ip, &bogus_length); |
| 5000 | ASSERT (bogus_length == 0); |
| 5001 | |
| 5002 | /* Setup MAC header with IP6 Etype and mcast DMAC */ |
| 5003 | vlib_buffer_t *b = vlib_get_buffer (vm, bi); |
Steven | 9f781d8 | 2018-06-05 11:09:32 -0700 | [diff] [blame] | 5004 | ip6_multicast_ethernet_address (dst_address, |
John Lo | 8b81cb4 | 2017-06-26 01:40:20 -0400 | [diff] [blame] | 5005 | IP6_MULTICAST_GROUP_ID_all_hosts); |
Steven | 9f781d8 | 2018-06-05 11:09:32 -0700 | [diff] [blame] | 5006 | rewrite = |
| 5007 | ethernet_build_rewrite (vnm, sw_if_index, VNET_LINK_IP6, dst_address); |
| 5008 | rewrite_len = vec_len (rewrite); |
| 5009 | vlib_buffer_advance (b, -rewrite_len); |
| 5010 | ethernet_header_t *e = vlib_buffer_get_current (b); |
| 5011 | clib_memcpy (e->dst_address, rewrite, rewrite_len); |
| 5012 | vec_free (rewrite); |
John Lo | 8b81cb4 | 2017-06-26 01:40:20 -0400 | [diff] [blame] | 5013 | |
| 5014 | /* Send unsolicited ND advertisement packet out the specified interface */ |
| 5015 | vnet_buffer (b)->sw_if_index[VLIB_RX] = |
| 5016 | vnet_buffer (b)->sw_if_index[VLIB_TX] = sw_if_index; |
| 5017 | vlib_frame_t *f = vlib_get_frame_to_node (vm, hi->output_node_index); |
| 5018 | u32 *to_next = vlib_frame_vector_args (f); |
| 5019 | to_next[0] = bi; |
| 5020 | f->n_vectors = 1; |
| 5021 | vlib_put_frame_to_node (vm, hi->output_node_index, f); |
| 5022 | } |
| 5023 | } |
| 5024 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 5025 | /* |
| 5026 | * fd.io coding-style-patch-verification: ON |
| 5027 | * |
| 5028 | * Local Variables: |
| 5029 | * eval: (c-set-style "gnu") |
| 5030 | * End: |
| 5031 | */ |