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