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