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