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