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