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