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