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