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