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