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