blob: 6b63e6fbbf6c61f31f52b1ae0b0e4ff65e44587e [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
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 Kotucek3e046ea2016-12-05 08:27:37 +010019#include <vnet/ip/ip6_neighbor.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070020#include <vnet/ethernet/ethernet.h>
21#include <vppinfra/mhash.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010022#include <vnet/adj/adj.h>
Neale Ranns32e1c012016-11-22 17:07:28 +000023#include <vnet/adj/adj_mcast.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010024#include <vnet/fib/fib_table.h>
25#include <vnet/fib/ip6_fib.h>
Neale Ranns4008ac92017-02-13 23:20:04 -080026#include <vnet/mfib/ip6_mfib.h>
Neale Ranns53da2212018-02-24 02:11:19 -080027#include <vnet/ip/ip6_ll_table.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070028
Billy McFall0683c9c2016-10-13 08:27:31 -040029/**
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 Kotucek3e046ea2016-12-05 08:27:37 +010037/* can't use sizeof link_layer_address, that's 8 */
Ed Warnickecb9cada2015-12-08 15:45:58 -070038#define ETHER_MAC_ADDR_LEN 6
39
Pavel Kotucek3e046ea2016-12-05 08:27:37 +010040/* advertised prefix option */
Dave Barachd7cb1b52016-12-09 09:52:16 -050041typedef struct
42{
Ed Warnickecb9cada2015-12-08 15:45:58 -070043 /* 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 Barachd7cb1b52016-12-09 09:52:16 -050053 f64 pref_lifetime_expires;
54
Ed Warnickecb9cada2015-12-08 15:45:58 -070055 /* local information */
56 int enabled;
57 int deprecated_prefix_flag;
Dave Barachd7cb1b52016-12-09 09:52:16 -050058 int decrement_lifetime_flag;
Ed Warnickecb9cada2015-12-08 15:45:58 -070059
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 Barachd7cb1b52016-12-09 09:52:16 -050068typedef struct
69{
Ed Warnickecb9cada2015-12-08 15:45:58 -070070 /* 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 Barachd7cb1b52016-12-09 09:52:16 -050078typedef struct
79{
Ed Warnickecb9cada2015-12-08 15:45:58 -070080
81 /* advertised config information, zero means unspecified */
Dave Barachd7cb1b52016-12-09 09:52:16 -050082 u8 curr_hop_limit;
Ed Warnickecb9cada2015-12-08 15:45:58 -070083 int adv_managed_flag;
84 int adv_other_flag;
Dave Barachd7cb1b52016-12-09 09:52:16 -050085 u16 adv_router_lifetime_in_sec;
Ed Warnickecb9cada2015-12-08 15:45:58 -070086 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 Barachd7cb1b52016-12-09 09:52:16 -050091
Ed Warnickecb9cada2015-12-08 15:45:58 -070092 /* source link layer option */
Dave Barachd7cb1b52016-12-09 09:52:16 -050093 u8 link_layer_address[8];
94 u8 link_layer_addr_len;
Ed Warnickecb9cada2015-12-08 15:45:58 -070095
96 /* prefix option */
Dave Barachd7cb1b52016-12-09 09:52:16 -050097 ip6_radv_prefix_t *adv_prefixes_pool;
Ed Warnickecb9cada2015-12-08 15:45:58 -070098
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 Barachd7cb1b52016-12-09 09:52:16 -0500103 ip6_mldp_group_t *mldp_group_pool;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700104
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 Barachd7cb1b52016-12-09 09:52:16 -0500110 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 Warnickecb9cada2015-12-08 15:45:58 -0700112 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 Ranns32e1c012016-11-22 17:07:28 +0000120 adj_index_t mcast_adj_index;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500121
Ed Warnickecb9cada2015-12-08 15:45:58 -0700122 /* 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 Barachd7cb1b52016-12-09 09:52:16 -0500129#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 Warnickecb9cada2015-12-08 15:45:58 -0700134
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 Barachd7cb1b52016-12-09 09:52:16 -0500147 f64 initial_adverts_interval;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700148 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;
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100157
158 /* router solicitations sending state */
159 u8 keep_sending_rs; /* when true then next fields are valid */
160 icmp6_send_router_solicitation_params_t params;
161 f64 sleep_interval;
162 f64 due_time;
163 u32 n_left;
164 f64 start_time;
165 vlib_buffer_t *buffer;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700166} ip6_radv_t;
167
Dave Barachd7cb1b52016-12-09 09:52:16 -0500168typedef struct
169{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700170 u32 next_index;
171 uword node_index;
172 uword type_opaque;
173 uword data;
John Lo1edfba92016-08-27 01:11:57 -0400174 /* Used for nd event notification only */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500175 void *data_callback;
John Lo1edfba92016-08-27 01:11:57 -0400176 u32 pid;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700177} pending_resolution_t;
178
179
Dave Barachd7cb1b52016-12-09 09:52:16 -0500180typedef struct
181{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700182 /* Hash tables mapping name to opcode. */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500183 uword *opcode_by_name;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700184
185 /* lite beer "glean" adjacency handling */
186 mhash_t pending_resolutions_by_address;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500187 pending_resolution_t *pending_resolutions;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700188
John Lo1edfba92016-08-27 01:11:57 -0400189 /* Mac address change notification */
190 mhash_t mac_changes_by_address;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500191 pending_resolution_t *mac_changes;
John Lo1edfba92016-08-27 01:11:57 -0400192
Dave Barachd7cb1b52016-12-09 09:52:16 -0500193 u32 *neighbor_input_next_index_by_hw_if_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700194
Dave Barachd7cb1b52016-12-09 09:52:16 -0500195 ip6_neighbor_t *neighbor_pool;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700196
197 mhash_t neighbor_index_by_key;
198
Dave Barachd7cb1b52016-12-09 09:52:16 -0500199 u32 *if_radv_pool_index_by_sw_if_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700200
Dave Barachd7cb1b52016-12-09 09:52:16 -0500201 ip6_radv_t *if_radv_pool;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700202
203 /* Neighbor attack mitigation */
204 u32 limit_neighbor_cache_size;
205 u32 neighbor_delete_rotor;
206
Eyal Baric125ecc2017-09-20 11:29:17 +0300207 /* Wildcard nd report publisher */
208 uword wc_ip6_nd_publisher_node;
209 uword wc_ip6_nd_publisher_et;
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100210
211 /* Router advertisement report publisher */
212 uword ip6_ra_publisher_node;
213 uword ip6_ra_publisher_et;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700214} ip6_neighbor_main_t;
215
Neale Ranns3f844d02017-02-18 00:03:54 -0800216/* ipv6 neighbor discovery - timer/event types */
217typedef enum
218{
219 ICMP6_ND_EVENT_INIT,
220} ip6_icmp_neighbor_discovery_event_type_t;
221
222typedef union
223{
224 u32 add_del_swindex;
225 struct
226 {
227 u32 up_down_swindex;
228 u32 fib_index;
229 } up_down_event;
230} ip6_icmp_neighbor_discovery_event_data_t;
231
Ed Warnickecb9cada2015-12-08 15:45:58 -0700232static ip6_neighbor_main_t ip6_neighbor_main;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500233static ip6_address_t ip6a_zero; /* ip6 address 0 */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700234
Eyal Baric125ecc2017-09-20 11:29:17 +0300235static void wc_nd_signal_report (wc_nd_report_t * r);
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100236static void ra_signal_report (ra_report_t * r);
Eyal Baric125ecc2017-09-20 11:29:17 +0300237
238/**
239 * @brief publish wildcard arp event
240 * @param sw_if_index The interface on which the ARP entires are acted
241 */
242static int
243vnet_nd_wc_publish (u32 sw_if_index, u8 * mac, ip6_address_t * ip6)
244{
245 wc_nd_report_t r = {
246 .sw_if_index = sw_if_index,
247 .ip6 = *ip6,
248 };
249 memcpy (r.mac, mac, sizeof r.mac);
250
251 void vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length);
252 vl_api_rpc_call_main_thread (wc_nd_signal_report, (u8 *) & r, sizeof r);
253 return 0;
254}
255
256static void
257wc_nd_signal_report (wc_nd_report_t * r)
258{
259 vlib_main_t *vm = vlib_get_main ();
260 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
261 uword ni = nm->wc_ip6_nd_publisher_node;
262 uword et = nm->wc_ip6_nd_publisher_et;
263
264 if (ni == (uword) ~ 0)
265 return;
266 wc_nd_report_t *q =
267 vlib_process_signal_event_data (vm, ni, et, 1, sizeof *q);
268
269 *q = *r;
270}
271
272void
273wc_nd_set_publisher_node (uword node_index, uword event_type)
274{
275 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
276 nm->wc_ip6_nd_publisher_node = node_index;
277 nm->wc_ip6_nd_publisher_et = event_type;
278}
279
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100280static int
281ra_publish (ra_report_t * r)
282{
283 void vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length);
284 vl_api_rpc_call_main_thread (ra_signal_report, (u8 *) r, sizeof *r);
285 return 0;
286}
287
288static void
289ra_signal_report (ra_report_t * r)
290{
291 vlib_main_t *vm = vlib_get_main ();
292 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
293 uword ni = nm->ip6_ra_publisher_node;
294 uword et = nm->ip6_ra_publisher_et;
295
296 if (ni == (uword) ~ 0)
297 return;
298 ra_report_t *q = vlib_process_signal_event_data (vm, ni, et, 1, sizeof *q);
299
300 *q = *r;
301}
302
303void
304ra_set_publisher_node (uword node_index, uword event_type)
305{
306 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
307 nm->ip6_ra_publisher_node = node_index;
308 nm->ip6_ra_publisher_et = event_type;
309}
310
Dave Barachd7cb1b52016-12-09 09:52:16 -0500311static u8 *
312format_ip6_neighbor_ip6_entry (u8 * s, va_list * va)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700313{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500314 vlib_main_t *vm = va_arg (*va, vlib_main_t *);
315 ip6_neighbor_t *n = va_arg (*va, ip6_neighbor_t *);
316 vnet_main_t *vnm = vnet_get_main ();
317 vnet_sw_interface_t *si;
318 u8 *flags = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700319
Dave Barachd7cb1b52016-12-09 09:52:16 -0500320 if (!n)
Neale Ranns53da2212018-02-24 02:11:19 -0800321 return format (s, "%=12s%=25s%=6s%=20s%=40s", "Time", "Address", "Flags",
Dave Barachd7cb1b52016-12-09 09:52:16 -0500322 "Link layer", "Interface");
Pierre Pfister1dabaaf2016-04-25 14:15:15 +0100323
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100324 if (n->flags & IP6_NEIGHBOR_FLAG_DYNAMIC)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500325 flags = format (flags, "D");
Pierre Pfister1dabaaf2016-04-25 14:15:15 +0100326
327 if (n->flags & IP6_NEIGHBOR_FLAG_STATIC)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500328 flags = format (flags, "S");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700329
Neale Rannsb3b2de72017-03-08 05:17:22 -0800330 if (n->flags & IP6_NEIGHBOR_FLAG_NO_FIB_ENTRY)
331 flags = format (flags, "N");
332
Ed Warnickecb9cada2015-12-08 15:45:58 -0700333 si = vnet_get_sw_interface (vnm, n->key.sw_if_index);
Neale Ranns53da2212018-02-24 02:11:19 -0800334 s = format (s, "%=12U%=25U%=6s%=20U%=40U",
John Lo7f358b32018-04-28 01:19:24 -0400335 format_vlib_time, vm, n->time_last_updated,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700336 format_ip6_address, &n->key.ip6_address,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500337 flags ? (char *) flags : "",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700338 format_ethernet_address, n->link_layer_address,
339 format_vnet_sw_interface_name, vnm, si);
340
Dave Barachd7cb1b52016-12-09 09:52:16 -0500341 vec_free (flags);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700342 return s;
343}
344
Neale Ranns15002542017-09-10 04:39:11 -0700345static void
Neale Ranns6b3a8ef2017-09-11 10:34:33 -0700346ip6_neighbor_adj_fib_remove (ip6_neighbor_t * n, u32 fib_index)
Neale Ranns15002542017-09-10 04:39:11 -0700347{
348 if (FIB_NODE_INDEX_INVALID != n->fib_entry_index)
349 {
Neale Ranns53da2212018-02-24 02:11:19 -0800350 if (ip6_address_is_link_local_unicast (&n->key.ip6_address))
351 {
352 ip6_ll_prefix_t pfx = {
353 .ilp_addr = n->key.ip6_address,
354 .ilp_sw_if_index = n->key.sw_if_index,
355 };
356 ip6_ll_table_entry_delete (&pfx);
357 }
358 else
359 {
360 fib_prefix_t pfx = {
361 .fp_len = 128,
362 .fp_proto = FIB_PROTOCOL_IP6,
363 .fp_addr.ip6 = n->key.ip6_address,
364 };
365 fib_table_entry_path_remove (fib_index,
366 &pfx,
367 FIB_SOURCE_ADJ,
368 DPO_PROTO_IP6,
369 &pfx.fp_addr,
370 n->key.sw_if_index, ~0,
371 1, FIB_ROUTE_PATH_FLAG_NONE);
372 }
Neale Ranns15002542017-09-10 04:39:11 -0700373 }
374}
375
Ed Warnickecb9cada2015-12-08 15:45:58 -0700376static clib_error_t *
377ip6_neighbor_sw_interface_up_down (vnet_main_t * vnm,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500378 u32 sw_if_index, u32 flags)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700379{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500380 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
381 ip6_neighbor_t *n;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700382
Dave Barachd7cb1b52016-12-09 09:52:16 -0500383 if (!(flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP))
384 {
385 u32 i, *to_delete = 0;
386
387 /* *INDENT-OFF* */
388 pool_foreach (n, nm->neighbor_pool,
389 ({
Ed Warnickecb9cada2015-12-08 15:45:58 -0700390 if (n->key.sw_if_index == sw_if_index)
391 vec_add1 (to_delete, n - nm->neighbor_pool);
392 }));
Dave Barachd7cb1b52016-12-09 09:52:16 -0500393 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700394
395 for (i = 0; i < vec_len (to_delete); i++)
396 {
397 n = pool_elt_at_index (nm->neighbor_pool, to_delete[i]);
398 mhash_unset (&nm->neighbor_index_by_key, &n->key, 0);
Neale Ranns15002542017-09-10 04:39:11 -0700399 ip6_neighbor_adj_fib_remove (n,
400 ip6_fib_table_get_index_for_sw_if_index
401 (n->key.sw_if_index));
402 pool_put (nm->neighbor_pool, n);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700403 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700404 vec_free (to_delete);
405 }
406
407 return 0;
408}
409
410VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (ip6_neighbor_sw_interface_up_down);
411
Dave Barachd7cb1b52016-12-09 09:52:16 -0500412static void
413unset_random_neighbor_entry (void)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700414{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500415 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
416 vnet_main_t *vnm = vnet_get_main ();
417 vlib_main_t *vm = vnm->vlib_main;
418 ip6_neighbor_t *e;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700419 u32 index;
420
421 index = pool_next_index (nm->neighbor_pool, nm->neighbor_delete_rotor);
422 nm->neighbor_delete_rotor = index;
423
424 /* Try again from elt 0, could happen if an intfc goes down */
425 if (index == ~0)
426 {
427 index = pool_next_index (nm->neighbor_pool, nm->neighbor_delete_rotor);
428 nm->neighbor_delete_rotor = index;
429 }
430
431 /* Nothing left in the pool */
432 if (index == ~0)
433 return;
434
435 e = pool_elt_at_index (nm->neighbor_pool, index);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500436
Ed Warnickecb9cada2015-12-08 15:45:58 -0700437 vnet_unset_ip6_ethernet_neighbor (vm, e->key.sw_if_index,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500438 &e->key.ip6_address,
439 e->link_layer_address,
440 ETHER_MAC_ADDR_LEN);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700441}
442
Dave Barachd7cb1b52016-12-09 09:52:16 -0500443typedef struct
444{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700445 u8 is_add;
Pierre Pfister1dabaaf2016-04-25 14:15:15 +0100446 u8 is_static;
Neale Rannsb3b2de72017-03-08 05:17:22 -0800447 u8 is_no_fib_entry;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700448 u8 link_layer_address[6];
449 u32 sw_if_index;
450 ip6_address_t addr;
451} ip6_neighbor_set_unset_rpc_args_t;
452
Dave Barachd7cb1b52016-12-09 09:52:16 -0500453static void ip6_neighbor_set_unset_rpc_callback
454 (ip6_neighbor_set_unset_rpc_args_t * a);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700455
Dave Barachd7cb1b52016-12-09 09:52:16 -0500456static void set_unset_ip6_neighbor_rpc
457 (vlib_main_t * vm,
458 u32 sw_if_index,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800459 ip6_address_t * a, u8 * link_layer_address, int is_add, int is_static,
460 int is_no_fib_entry)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700461{
462 ip6_neighbor_set_unset_rpc_args_t args;
Dave Barachf9bd6202015-12-14 13:22:11 -0500463 void vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500464
Ed Warnickecb9cada2015-12-08 15:45:58 -0700465 args.sw_if_index = sw_if_index;
466 args.is_add = is_add;
Pierre Pfister1dabaaf2016-04-25 14:15:15 +0100467 args.is_static = is_static;
Neale Rannsb3b2de72017-03-08 05:17:22 -0800468 args.is_no_fib_entry = is_no_fib_entry;
Damjan Marionf1213b82016-03-13 02:22:06 +0100469 clib_memcpy (&args.addr, a, sizeof (*a));
Neale Ranns3f844d02017-02-18 00:03:54 -0800470 if (NULL != link_layer_address)
471 clib_memcpy (args.link_layer_address, link_layer_address, 6);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500472
Ed Warnickecb9cada2015-12-08 15:45:58 -0700473 vl_api_rpc_call_main_thread (ip6_neighbor_set_unset_rpc_callback,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500474 (u8 *) & args, sizeof (args));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700475}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700476
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100477static void
Dave Barachd7cb1b52016-12-09 09:52:16 -0500478ip6_nbr_probe (ip_adjacency_t * adj)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100479{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500480 icmp6_neighbor_solicitation_header_t *h;
481 vnet_main_t *vnm = vnet_get_main ();
482 ip6_main_t *im = &ip6_main;
483 ip_interface_address_t *ia;
484 ip6_address_t *dst, *src;
485 vnet_hw_interface_t *hi;
486 vnet_sw_interface_t *si;
487 vlib_buffer_t *b;
Neale Rannsb80c5362016-10-08 13:03:40 +0100488 int bogus_length;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500489 vlib_main_t *vm;
Neale Rannsb80c5362016-10-08 13:03:40 +0100490 u32 bi = 0;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100491
Dave Barachd7cb1b52016-12-09 09:52:16 -0500492 vm = vlib_get_main ();
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100493
Dave Barachd7cb1b52016-12-09 09:52:16 -0500494 si = vnet_get_sw_interface (vnm, adj->rewrite_header.sw_if_index);
Neale Rannsb80c5362016-10-08 13:03:40 +0100495 dst = &adj->sub_type.nbr.next_hop.ip6;
496
497 if (!(si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP))
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100498 {
Neale Rannsb80c5362016-10-08 13:03:40 +0100499 return;
500 }
Dave Barachd7cb1b52016-12-09 09:52:16 -0500501 src = ip6_interface_address_matching_destination (im, dst,
502 adj->rewrite_header.
503 sw_if_index, &ia);
504 if (!src)
Neale Rannsb80c5362016-10-08 13:03:40 +0100505 {
506 return;
507 }
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100508
Dave Barachd7cb1b52016-12-09 09:52:16 -0500509 h = vlib_packet_template_get_packet (vm,
510 &im->discover_neighbor_packet_template,
511 &bi);
Neale Rannsb80c5362016-10-08 13:03:40 +0100512
Dave Barachd7cb1b52016-12-09 09:52:16 -0500513 hi = vnet_get_sup_hw_interface (vnm, adj->rewrite_header.sw_if_index);
Neale Rannsb80c5362016-10-08 13:03:40 +0100514
515 h->ip.dst_address.as_u8[13] = dst->as_u8[13];
516 h->ip.dst_address.as_u8[14] = dst->as_u8[14];
517 h->ip.dst_address.as_u8[15] = dst->as_u8[15];
518 h->ip.src_address = src[0];
519 h->neighbor.target_address = dst[0];
520
521 clib_memcpy (h->link_layer_option.ethernet_address,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500522 hi->hw_address, vec_len (hi->hw_address));
Neale Rannsb80c5362016-10-08 13:03:40 +0100523
524 h->neighbor.icmp.checksum =
Dave Barachd7cb1b52016-12-09 09:52:16 -0500525 ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h->ip, &bogus_length);
526 ASSERT (bogus_length == 0);
Neale Rannsb80c5362016-10-08 13:03:40 +0100527
528 b = vlib_get_buffer (vm, bi);
529 vnet_buffer (b)->sw_if_index[VLIB_RX] =
Dave Barachd7cb1b52016-12-09 09:52:16 -0500530 vnet_buffer (b)->sw_if_index[VLIB_TX] = adj->rewrite_header.sw_if_index;
Neale Rannsb80c5362016-10-08 13:03:40 +0100531
532 /* Add encapsulation string for software interface (e.g. ethernet header). */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500533 vnet_rewrite_one_header (adj[0], h, sizeof (ethernet_header_t));
534 vlib_buffer_advance (b, -adj->rewrite_header.data_bytes);
Neale Rannsb80c5362016-10-08 13:03:40 +0100535
536 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500537 vlib_frame_t *f = vlib_get_frame_to_node (vm, hi->output_node_index);
538 u32 *to_next = vlib_frame_vector_args (f);
539 to_next[0] = bi;
540 f->n_vectors = 1;
541 vlib_put_frame_to_node (vm, hi->output_node_index, f);
Neale Rannsb80c5362016-10-08 13:03:40 +0100542 }
543}
544
545static void
546ip6_nd_mk_complete (adj_index_t ai, ip6_neighbor_t * nbr)
547{
548 adj_nbr_update_rewrite (ai, ADJ_NBR_REWRITE_FLAG_COMPLETE,
549 ethernet_build_rewrite (vnet_get_main (),
550 nbr->key.sw_if_index,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500551 adj_get_link_type (ai),
Neale Rannsb80c5362016-10-08 13:03:40 +0100552 nbr->link_layer_address));
553}
554
555static void
Neale Ranns19c68d22016-12-07 15:38:14 +0000556ip6_nd_mk_incomplete (adj_index_t ai)
Neale Rannsb80c5362016-10-08 13:03:40 +0100557{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500558 ip_adjacency_t *adj = adj_get (ai);
Neale Ranns19c68d22016-12-07 15:38:14 +0000559
Dave Barachd7cb1b52016-12-09 09:52:16 -0500560 adj_nbr_update_rewrite (ai,
561 ADJ_NBR_REWRITE_FLAG_INCOMPLETE,
562 ethernet_build_rewrite (vnet_get_main (),
563 adj->rewrite_header.
564 sw_if_index,
565 adj_get_link_type (ai),
566 VNET_REWRITE_FOR_SW_INTERFACE_ADDRESS_BROADCAST));
Neale Rannsb80c5362016-10-08 13:03:40 +0100567}
568
569#define IP6_NBR_MK_KEY(k, sw_if_index, addr) \
570{ \
571 k.sw_if_index = sw_if_index; \
572 k.ip6_address = *addr; \
573 k.pad = 0; \
574}
575
576static ip6_neighbor_t *
Dave Barachd7cb1b52016-12-09 09:52:16 -0500577ip6_nd_find (u32 sw_if_index, const ip6_address_t * addr)
Neale Rannsb80c5362016-10-08 13:03:40 +0100578{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500579 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
580 ip6_neighbor_t *n = NULL;
Neale Rannsb80c5362016-10-08 13:03:40 +0100581 ip6_neighbor_key_t k;
582 uword *p;
583
Dave Barachd7cb1b52016-12-09 09:52:16 -0500584 IP6_NBR_MK_KEY (k, sw_if_index, addr);
Neale Rannsb80c5362016-10-08 13:03:40 +0100585
586 p = mhash_get (&nm->neighbor_index_by_key, &k);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500587 if (p)
588 {
589 n = pool_elt_at_index (nm->neighbor_pool, p[0]);
590 }
Neale Rannsb80c5362016-10-08 13:03:40 +0100591
592 return (n);
593}
594
595static adj_walk_rc_t
596ip6_nd_mk_complete_walk (adj_index_t ai, void *ctx)
597{
598 ip6_neighbor_t *nbr = ctx;
599
600 ip6_nd_mk_complete (ai, nbr);
601
602 return (ADJ_WALK_RC_CONTINUE);
603}
604
605static adj_walk_rc_t
606ip6_nd_mk_incomplete_walk (adj_index_t ai, void *ctx)
607{
Neale Ranns19c68d22016-12-07 15:38:14 +0000608 ip6_nd_mk_incomplete (ai);
Neale Rannsb80c5362016-10-08 13:03:40 +0100609
610 return (ADJ_WALK_RC_CONTINUE);
611}
612
613void
Dave Barachd7cb1b52016-12-09 09:52:16 -0500614ip6_ethernet_update_adjacency (vnet_main_t * vnm, u32 sw_if_index, u32 ai)
Neale Rannsb80c5362016-10-08 13:03:40 +0100615{
616 ip6_neighbor_t *nbr;
617 ip_adjacency_t *adj;
618
619 adj = adj_get (ai);
620
621 nbr = ip6_nd_find (sw_if_index, &adj->sub_type.nbr.next_hop.ip6);
622
Neale Ranns32e1c012016-11-22 17:07:28 +0000623 switch (adj->lookup_next_index)
Neale Rannsb80c5362016-10-08 13:03:40 +0100624 {
Ole Trøan438f6302018-02-15 21:56:06 +0000625 case IP_LOOKUP_NEXT_GLEAN:
Neale Rannsc819fc62018-02-16 02:44:05 -0800626 adj_glean_update_rewrite (ai);
627 break;
628 case IP_LOOKUP_NEXT_ARP:
Neale Ranns32e1c012016-11-22 17:07:28 +0000629 if (NULL != nbr)
630 {
631 adj_nbr_walk_nh6 (sw_if_index, &nbr->key.ip6_address,
632 ip6_nd_mk_complete_walk, nbr);
633 }
634 else
635 {
636 /*
637 * no matching ND entry.
638 * construct the rewrite required to for an ND packet, and stick
639 * that in the adj's pipe to smoke.
640 */
641 adj_nbr_update_rewrite (ai,
642 ADJ_NBR_REWRITE_FLAG_INCOMPLETE,
643 ethernet_build_rewrite (vnm,
644 sw_if_index,
645 VNET_LINK_IP6,
646 VNET_REWRITE_FOR_SW_INTERFACE_ADDRESS_BROADCAST));
647
648 /*
649 * since the FIB has added this adj for a route, it makes sense it may
650 * want to forward traffic sometime soon. Let's send a speculative ND.
651 * just one. If we were to do periodically that wouldn't be bad either,
652 * but that's more code than i'm prepared to write at this time for
653 * relatively little reward.
654 */
655 ip6_nbr_probe (adj);
656 }
657 break;
658 case IP_LOOKUP_NEXT_MCAST:
Neale Ranns2e7fbcc2017-03-15 04:22:25 -0700659 {
660 /*
661 * Construct a partial rewrite from the known ethernet mcast dest MAC
662 */
663 u8 *rewrite;
664 u8 offset;
Neale Rannsb80c5362016-10-08 13:03:40 +0100665
Neale Ranns2e7fbcc2017-03-15 04:22:25 -0700666 rewrite = ethernet_build_rewrite (vnm,
667 sw_if_index,
668 adj->ia_link,
669 ethernet_ip6_mcast_dst_addr ());
Neale Ranns32e1c012016-11-22 17:07:28 +0000670
Neale Ranns2e7fbcc2017-03-15 04:22:25 -0700671 /*
672 * Complete the remaining fields of the adj's rewrite to direct the
673 * complete of the rewrite at switch time by copying in the IP
674 * dst address's bytes.
Neale Ranns889fe942017-06-01 05:43:19 -0400675 * Ofset is 2 bytes into the desintation address.
Neale Ranns2e7fbcc2017-03-15 04:22:25 -0700676 */
677 offset = vec_len (rewrite) - 2;
Neale Ranns889fe942017-06-01 05:43:19 -0400678 adj_mcast_update_rewrite (ai, rewrite, offset);
Neale Ranns32e1c012016-11-22 17:07:28 +0000679
Neale Ranns2e7fbcc2017-03-15 04:22:25 -0700680 break;
681 }
Neale Ranns32e1c012016-11-22 17:07:28 +0000682 case IP_LOOKUP_NEXT_DROP:
683 case IP_LOOKUP_NEXT_PUNT:
684 case IP_LOOKUP_NEXT_LOCAL:
685 case IP_LOOKUP_NEXT_REWRITE:
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800686 case IP_LOOKUP_NEXT_MCAST_MIDCHAIN:
Neale Ranns32e1c012016-11-22 17:07:28 +0000687 case IP_LOOKUP_NEXT_MIDCHAIN:
688 case IP_LOOKUP_NEXT_ICMP_ERROR:
689 case IP_LOOKUP_N_NEXT:
690 ASSERT (0);
691 break;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100692 }
693}
694
Neale Ranns15002542017-09-10 04:39:11 -0700695
696static void
Neale Ranns6b3a8ef2017-09-11 10:34:33 -0700697ip6_neighbor_adj_fib_add (ip6_neighbor_t * n, u32 fib_index)
Neale Ranns15002542017-09-10 04:39:11 -0700698{
Neale Ranns53da2212018-02-24 02:11:19 -0800699 if (ip6_address_is_link_local_unicast (&n->key.ip6_address))
700 {
701 ip6_ll_prefix_t pfx = {
702 .ilp_addr = n->key.ip6_address,
703 .ilp_sw_if_index = n->key.sw_if_index,
704 };
705 n->fib_entry_index =
706 ip6_ll_table_entry_update (&pfx, FIB_ROUTE_PATH_FLAG_NONE);
707 }
708 else
709 {
710 fib_prefix_t pfx = {
711 .fp_len = 128,
712 .fp_proto = FIB_PROTOCOL_IP6,
713 .fp_addr.ip6 = n->key.ip6_address,
714 };
Neale Ranns15002542017-09-10 04:39:11 -0700715
Neale Ranns53da2212018-02-24 02:11:19 -0800716 n->fib_entry_index =
717 fib_table_entry_path_add (fib_index, &pfx, FIB_SOURCE_ADJ,
718 FIB_ENTRY_FLAG_ATTACHED,
719 DPO_PROTO_IP6, &pfx.fp_addr,
720 n->key.sw_if_index, ~0, 1, NULL,
721 FIB_ROUTE_PATH_FLAG_NONE);
722 }
Neale Ranns15002542017-09-10 04:39:11 -0700723}
724
Ed Warnickecb9cada2015-12-08 15:45:58 -0700725int
726vnet_set_ip6_ethernet_neighbor (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500727 u32 sw_if_index,
728 ip6_address_t * a,
729 u8 * link_layer_address,
730 uword n_bytes_link_layer_address,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800731 int is_static, int is_no_fib_entry)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700732{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500733 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700734 ip6_neighbor_key_t k;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500735 ip6_neighbor_t *n = 0;
736 int make_new_nd_cache_entry = 1;
737 uword *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700738 u32 next_index;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500739 pending_resolution_t *pr, *mc;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700740
Damjan Marion586afd72017-04-05 19:18:20 +0200741 if (vlib_get_thread_index ())
Ed Warnickecb9cada2015-12-08 15:45:58 -0700742 {
743 set_unset_ip6_neighbor_rpc (vm, sw_if_index, a, link_layer_address,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800744 1 /* set new neighbor */ , is_static,
745 is_no_fib_entry);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700746 return 0;
747 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700748
749 k.sw_if_index = sw_if_index;
750 k.ip6_address = a[0];
751 k.pad = 0;
752
Ed Warnickecb9cada2015-12-08 15:45:58 -0700753 p = mhash_get (&nm->neighbor_index_by_key, &k);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500754 if (p)
755 {
756 n = pool_elt_at_index (nm->neighbor_pool, p[0]);
757 /* Refuse to over-write static neighbor entry. */
758 if (!is_static && (n->flags & IP6_NEIGHBOR_FLAG_STATIC))
759 return -2;
760 make_new_nd_cache_entry = 0;
761 }
Pierre Pfister1dabaaf2016-04-25 14:15:15 +0100762
Dave Barachd7cb1b52016-12-09 09:52:16 -0500763 if (make_new_nd_cache_entry)
764 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500765 pool_get (nm->neighbor_pool, n);
766 mhash_set (&nm->neighbor_index_by_key, &k, n - nm->neighbor_pool,
767 /* old value */ 0);
768 n->key = k;
Neale Rannsd5b6aa12017-05-16 08:46:45 -0700769 n->fib_entry_index = FIB_NODE_INDEX_INVALID;
Neale Rannsb80c5362016-10-08 13:03:40 +0100770
Dave Barachd7cb1b52016-12-09 09:52:16 -0500771 clib_memcpy (n->link_layer_address,
772 link_layer_address, n_bytes_link_layer_address);
Neale Rannsb80c5362016-10-08 13:03:40 +0100773
Dave Barachd7cb1b52016-12-09 09:52:16 -0500774 /*
775 * create the adj-fib. the entry in the FIB table for and to the peer.
776 */
Neale Rannsb3b2de72017-03-08 05:17:22 -0800777 if (!is_no_fib_entry)
778 {
Neale Ranns53da2212018-02-24 02:11:19 -0800779 ip6_neighbor_adj_fib_add
780 (n, ip6_fib_table_get_index_for_sw_if_index (n->key.sw_if_index));
Neale Ranns2a3ea492017-04-19 05:24:40 -0700781 }
782 else
783 {
Neale Rannsb3b2de72017-03-08 05:17:22 -0800784 n->flags |= IP6_NEIGHBOR_FLAG_NO_FIB_ENTRY;
785 }
Dave Barachd7cb1b52016-12-09 09:52:16 -0500786 }
Neale Ranns33a7dd52016-10-07 15:14:33 +0100787 else
Dave Barachd7cb1b52016-12-09 09:52:16 -0500788 {
789 /*
790 * prevent a DoS attack from the data-plane that
791 * spams us with no-op updates to the MAC address
792 */
793 if (0 == memcmp (n->link_layer_address,
794 link_layer_address, n_bytes_link_layer_address))
John Lo7f358b32018-04-28 01:19:24 -0400795 {
796 n->time_last_updated = vlib_time_now (vm);
797 goto check_customers;
798 }
Neale Rannsb80c5362016-10-08 13:03:40 +0100799
Dave Barachd7cb1b52016-12-09 09:52:16 -0500800 clib_memcpy (n->link_layer_address,
801 link_layer_address, n_bytes_link_layer_address);
802 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700803
Neale Rannsb80c5362016-10-08 13:03:40 +0100804 /* Update time stamp and flags. */
John Lo7f358b32018-04-28 01:19:24 -0400805 n->time_last_updated = vlib_time_now (vm);
Pierre Pfister1dabaaf2016-04-25 14:15:15 +0100806 if (is_static)
807 n->flags |= IP6_NEIGHBOR_FLAG_STATIC;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100808 else
809 n->flags |= IP6_NEIGHBOR_FLAG_DYNAMIC;
810
Neale Rannsb80c5362016-10-08 13:03:40 +0100811 adj_nbr_walk_nh6 (sw_if_index,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500812 &n->key.ip6_address, ip6_nd_mk_complete_walk, n);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700813
Dave Barach59b25652017-09-10 15:04:27 -0400814check_customers:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700815 /* Customer(s) waiting for this address to be resolved? */
816 p = mhash_get (&nm->pending_resolutions_by_address, a);
John Lo1edfba92016-08-27 01:11:57 -0400817 if (p)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700818 {
John Lo1edfba92016-08-27 01:11:57 -0400819 next_index = p[0];
Dave Barachd7cb1b52016-12-09 09:52:16 -0500820
821 while (next_index != (u32) ~ 0)
822 {
John Lo1edfba92016-08-27 01:11:57 -0400823 pr = pool_elt_at_index (nm->pending_resolutions, next_index);
824 vlib_process_signal_event (vm, pr->node_index,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500825 pr->type_opaque, pr->data);
John Lo1edfba92016-08-27 01:11:57 -0400826 next_index = pr->next_index;
827 pool_put (nm->pending_resolutions, pr);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500828 }
John Lo1edfba92016-08-27 01:11:57 -0400829
830 mhash_unset (&nm->pending_resolutions_by_address, a, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700831 }
832
John Lo1edfba92016-08-27 01:11:57 -0400833 /* Customer(s) requesting ND event for this address? */
834 p = mhash_get (&nm->mac_changes_by_address, a);
835 if (p)
836 {
837 next_index = p[0];
838
Dave Barachd7cb1b52016-12-09 09:52:16 -0500839 while (next_index != (u32) ~ 0)
840 {
841 int (*fp) (u32, u8 *, u32, ip6_address_t *);
842 int rv = 1;
843 mc = pool_elt_at_index (nm->mac_changes, next_index);
844 fp = mc->data_callback;
John Lo1edfba92016-08-27 01:11:57 -0400845
Dave Barachd7cb1b52016-12-09 09:52:16 -0500846 /* Call the user's data callback, return 1 to suppress dup events */
847 if (fp)
848 rv =
849 (*fp) (mc->data, link_layer_address, sw_if_index, &ip6a_zero);
850 /*
851 * Signal the resolver process, as long as the user
852 * says they want to be notified
853 */
854 if (rv == 0)
855 vlib_process_signal_event (vm, mc->node_index,
856 mc->type_opaque, mc->data);
857 next_index = mc->next_index;
858 }
John Lo1edfba92016-08-27 01:11:57 -0400859 }
860
Ed Warnickecb9cada2015-12-08 15:45:58 -0700861 return 0;
862}
863
864int
865vnet_unset_ip6_ethernet_neighbor (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500866 u32 sw_if_index,
867 ip6_address_t * a,
868 u8 * link_layer_address,
869 uword n_bytes_link_layer_address)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700870{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500871 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700872 ip6_neighbor_key_t k;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500873 ip6_neighbor_t *n;
874 uword *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700875 int rv = 0;
876
Damjan Marion586afd72017-04-05 19:18:20 +0200877 if (vlib_get_thread_index ())
Ed Warnickecb9cada2015-12-08 15:45:58 -0700878 {
879 set_unset_ip6_neighbor_rpc (vm, sw_if_index, a, link_layer_address,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800880 0 /* unset */ , 0, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700881 return 0;
882 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700883
884 k.sw_if_index = sw_if_index;
885 k.ip6_address = a[0];
886 k.pad = 0;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500887
Ed Warnickecb9cada2015-12-08 15:45:58 -0700888 p = mhash_get (&nm->neighbor_index_by_key, &k);
889 if (p == 0)
890 {
891 rv = -1;
892 goto out;
893 }
Dave Barachd7cb1b52016-12-09 09:52:16 -0500894
Ed Warnickecb9cada2015-12-08 15:45:58 -0700895 n = pool_elt_at_index (nm->neighbor_pool, p[0]);
Neale Ranns19c68d22016-12-07 15:38:14 +0000896 mhash_unset (&nm->neighbor_index_by_key, &n->key, 0);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100897
Neale Rannsb80c5362016-10-08 13:03:40 +0100898 adj_nbr_walk_nh6 (sw_if_index,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500899 &n->key.ip6_address, ip6_nd_mk_incomplete_walk, NULL);
Neale Rannsb80c5362016-10-08 13:03:40 +0100900
Neale Rannsd5b6aa12017-05-16 08:46:45 -0700901
902 if (FIB_NODE_INDEX_INVALID != n->fib_entry_index)
Neale Rannsdcd6d622017-05-26 02:59:16 -0700903 {
904 fib_prefix_t pfx = {
905 .fp_len = 128,
906 .fp_proto = FIB_PROTOCOL_IP6,
907 .fp_addr.ip6 = n->key.ip6_address,
908 };
909 fib_table_entry_path_remove
910 (ip6_fib_table_get_index_for_sw_if_index (n->key.sw_if_index),
911 &pfx,
912 FIB_SOURCE_ADJ,
Neale Rannsda78f952017-05-24 09:15:43 -0700913 DPO_PROTO_IP6,
Neale Rannsdcd6d622017-05-26 02:59:16 -0700914 &pfx.fp_addr, n->key.sw_if_index, ~0, 1, FIB_ROUTE_PATH_FLAG_NONE);
915 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700916 pool_put (nm->neighbor_pool, n);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500917
918out:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700919 return rv;
920}
921
Dave Barachd7cb1b52016-12-09 09:52:16 -0500922static void ip6_neighbor_set_unset_rpc_callback
923 (ip6_neighbor_set_unset_rpc_args_t * a)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700924{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500925 vlib_main_t *vm = vlib_get_main ();
926 if (a->is_add)
927 vnet_set_ip6_ethernet_neighbor (vm, a->sw_if_index, &a->addr,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800928 a->link_layer_address, 6, a->is_static,
929 a->is_no_fib_entry);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700930 else
Dave Barachd7cb1b52016-12-09 09:52:16 -0500931 vnet_unset_ip6_ethernet_neighbor (vm, a->sw_if_index, &a->addr,
932 a->link_layer_address, 6);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700933}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700934
935static int
936ip6_neighbor_sort (void *a1, void *a2)
937{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500938 vnet_main_t *vnm = vnet_get_main ();
939 ip6_neighbor_t *n1 = a1, *n2 = a2;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700940 int cmp;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500941 cmp = vnet_sw_interface_compare (vnm, n1->key.sw_if_index,
942 n2->key.sw_if_index);
943 if (!cmp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700944 cmp = ip6_address_compare (&n1->key.ip6_address, &n2->key.ip6_address);
945 return cmp;
946}
947
Pavel Kotucek3e046ea2016-12-05 08:27:37 +0100948ip6_neighbor_t *
John Lo7f358b32018-04-28 01:19:24 -0400949ip6_neighbors_pool (void)
950{
951 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
952 return nm->neighbor_pool;
953}
954
955ip6_neighbor_t *
Pavel Kotucek3e046ea2016-12-05 08:27:37 +0100956ip6_neighbors_entries (u32 sw_if_index)
957{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500958 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
Pavel Kotucek3e046ea2016-12-05 08:27:37 +0100959 ip6_neighbor_t *n, *ns = 0;
960
961 /* *INDENT-OFF* */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500962 pool_foreach (n, nm->neighbor_pool,
963 ({
Pavel Kotucek3e046ea2016-12-05 08:27:37 +0100964 if (sw_if_index != ~0 && n->key.sw_if_index != sw_if_index)
965 continue;
966 vec_add1 (ns, n[0]);
967 }));
968 /* *INDENT-ON* */
969
970 if (ns)
971 vec_sort_with_function (ns, ip6_neighbor_sort);
972 return ns;
973}
974
Ed Warnickecb9cada2015-12-08 15:45:58 -0700975static clib_error_t *
976show_ip6_neighbors (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -0500977 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700978{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500979 vnet_main_t *vnm = vnet_get_main ();
980 ip6_neighbor_t *n, *ns;
981 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700982 u32 sw_if_index;
983
984 /* Filter entries by interface if given. */
985 sw_if_index = ~0;
986 (void) unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index);
987
Pavel Kotucek3e046ea2016-12-05 08:27:37 +0100988 ns = ip6_neighbors_entries (sw_if_index);
Billy McFall46529cd2016-10-14 10:45:49 -0400989 if (ns)
990 {
Billy McFall46529cd2016-10-14 10:45:49 -0400991 vlib_cli_output (vm, "%U", format_ip6_neighbor_ip6_entry, vm, 0);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500992 vec_foreach (n, ns)
993 {
994 vlib_cli_output (vm, "%U", format_ip6_neighbor_ip6_entry, vm, n);
Billy McFall46529cd2016-10-14 10:45:49 -0400995 }
996 vec_free (ns);
997 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700998
999 return error;
1000}
1001
Billy McFall0683c9c2016-10-13 08:27:31 -04001002/*?
1003 * This command is used to display the adjacent IPv6 hosts found via
1004 * neighbor discovery. Optionally, limit the output to the specified
1005 * interface.
1006 *
1007 * @cliexpar
1008 * Example of how to display the IPv6 neighbor adjacency table:
1009 * @cliexstart{show ip6 neighbors}
1010 * Time Address Flags Link layer Interface
1011 * 34.0910 ::a:1:1:0:7 02:fe:6a:07:39:6f GigabitEthernet2/0/0
1012 * 173.2916 ::b:5:1:c:2 02:fe:50:62:3a:94 GigabitEthernet2/0/0
1013 * 886.6654 ::1:1:c:0:9 S 02:fe:e4:45:27:5b GigabitEthernet3/0/0
1014 * @cliexend
1015 * Example of how to display the IPv6 neighbor adjacency table for given interface:
1016 * @cliexstart{show ip6 neighbors GigabitEthernet2/0/0}
1017 * Time Address Flags Link layer Interface
1018 * 34.0910 ::a:1:1:0:7 02:fe:6a:07:39:6f GigabitEthernet2/0/0
1019 * 173.2916 ::b:5:1:c:2 02:fe:50:62:3a:94 GigabitEthernet2/0/0
1020 * @cliexend
1021?*/
1022/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001023VLIB_CLI_COMMAND (show_ip6_neighbors_command, static) = {
1024 .path = "show ip6 neighbors",
1025 .function = show_ip6_neighbors,
Billy McFall0683c9c2016-10-13 08:27:31 -04001026 .short_help = "show ip6 neighbors [<interface>]",
Ed Warnickecb9cada2015-12-08 15:45:58 -07001027};
Billy McFall0683c9c2016-10-13 08:27:31 -04001028/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001029
1030static clib_error_t *
1031set_ip6_neighbor (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001032 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001033{
Dave Barachd7cb1b52016-12-09 09:52:16 -05001034 vnet_main_t *vnm = vnet_get_main ();
Ed Warnickecb9cada2015-12-08 15:45:58 -07001035 ip6_address_t addr;
1036 u8 mac_address[6];
1037 int addr_valid = 0;
1038 int is_del = 0;
Pierre Pfister1dabaaf2016-04-25 14:15:15 +01001039 int is_static = 0;
Neale Rannsb3b2de72017-03-08 05:17:22 -08001040 int is_no_fib_entry = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001041 u32 sw_if_index;
1042
Dave Barachd7cb1b52016-12-09 09:52:16 -05001043 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001044 {
1045 /* intfc, ip6-address, mac-address */
1046 if (unformat (input, "%U %U %U",
Dave Barachd7cb1b52016-12-09 09:52:16 -05001047 unformat_vnet_sw_interface, vnm, &sw_if_index,
1048 unformat_ip6_address, &addr,
1049 unformat_ethernet_address, mac_address))
1050 addr_valid = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001051
1052 else if (unformat (input, "delete") || unformat (input, "del"))
Dave Barachd7cb1b52016-12-09 09:52:16 -05001053 is_del = 1;
Pierre Pfister1dabaaf2016-04-25 14:15:15 +01001054 else if (unformat (input, "static"))
Dave Barachd7cb1b52016-12-09 09:52:16 -05001055 is_static = 1;
Neale Rannsb3b2de72017-03-08 05:17:22 -08001056 else if (unformat (input, "no-fib-entry"))
1057 is_no_fib_entry = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001058 else
Dave Barachd7cb1b52016-12-09 09:52:16 -05001059 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001060 }
1061
1062 if (!addr_valid)
1063 return clib_error_return (0, "Missing interface, ip6 or hw address");
Dave Barachd7cb1b52016-12-09 09:52:16 -05001064
Ed Warnickecb9cada2015-12-08 15:45:58 -07001065 if (!is_del)
1066 vnet_set_ip6_ethernet_neighbor (vm, sw_if_index, &addr,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001067 mac_address, sizeof (mac_address),
Neale Rannsb3b2de72017-03-08 05:17:22 -08001068 is_static, is_no_fib_entry);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001069 else
1070 vnet_unset_ip6_ethernet_neighbor (vm, sw_if_index, &addr,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001071 mac_address, sizeof (mac_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001072 return 0;
1073}
1074
Billy McFall0683c9c2016-10-13 08:27:31 -04001075/*?
1076 * This command is used to manually add an entry to the IPv6 neighbor
1077 * adjacency table. Optionally, the entry can be added as static. It is
1078 * also used to remove an entry from the table. Use the '<em>show ip6
1079 * neighbors</em>' command to display all learned and manually entered entries.
1080 *
1081 * @cliexpar
1082 * Example of how to add a static entry to the IPv6 neighbor adjacency table:
1083 * @cliexcmd{set ip6 neighbor GigabitEthernet2/0/0 ::1:1:c:0:9 02:fe:e4:45:27:5b static}
1084 * Example of how to delete an entry from the IPv6 neighbor adjacency table:
1085 * @cliexcmd{set ip6 neighbor del GigabitEthernet2/0/0 ::1:1:c:0:9 02:fe:e4:45:27:5b}
1086?*/
1087/* *INDENT-OFF* */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001088VLIB_CLI_COMMAND (set_ip6_neighbor_command, static) =
1089{
Ed Warnickecb9cada2015-12-08 15:45:58 -07001090 .path = "set ip6 neighbor",
1091 .function = set_ip6_neighbor,
Billy McFall0683c9c2016-10-13 08:27:31 -04001092 .short_help = "set ip6 neighbor [del] <interface> <ip6-address> <mac-address> [static]",
Ed Warnickecb9cada2015-12-08 15:45:58 -07001093};
Billy McFall0683c9c2016-10-13 08:27:31 -04001094/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001095
Dave Barachd7cb1b52016-12-09 09:52:16 -05001096typedef enum
1097{
Ed Warnickecb9cada2015-12-08 15:45:58 -07001098 ICMP6_NEIGHBOR_SOLICITATION_NEXT_DROP,
1099 ICMP6_NEIGHBOR_SOLICITATION_NEXT_REPLY,
1100 ICMP6_NEIGHBOR_SOLICITATION_N_NEXT,
1101} icmp6_neighbor_solicitation_or_advertisement_next_t;
1102
1103static_always_inline uword
1104icmp6_neighbor_solicitation_or_advertisement (vlib_main_t * vm,
1105 vlib_node_runtime_t * node,
1106 vlib_frame_t * frame,
1107 uword is_solicitation)
1108{
Dave Barachd7cb1b52016-12-09 09:52:16 -05001109 vnet_main_t *vnm = vnet_get_main ();
1110 ip6_main_t *im = &ip6_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001111 uword n_packets = frame->n_vectors;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001112 u32 *from, *to_next;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001113 u32 n_left_from, n_left_to_next, next_index, n_advertisements_sent;
1114 icmp6_neighbor_discovery_option_type_t option_type;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001115 vlib_node_runtime_t *error_node =
1116 vlib_node_get_runtime (vm, ip6_icmp_input_node.index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001117 int bogus_length;
1118
1119 from = vlib_frame_vector_args (frame);
1120 n_left_from = n_packets;
1121 next_index = node->cached_next_index;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001122
Ed Warnickecb9cada2015-12-08 15:45:58 -07001123 if (node->flags & VLIB_NODE_FLAG_TRACE)
1124 vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors,
1125 /* stride */ 1,
1126 sizeof (icmp6_input_trace_t));
1127
Dave Barachd7cb1b52016-12-09 09:52:16 -05001128 option_type =
Ed Warnickecb9cada2015-12-08 15:45:58 -07001129 (is_solicitation
1130 ? ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address
1131 : ICMP6_NEIGHBOR_DISCOVERY_OPTION_target_link_layer_address);
1132 n_advertisements_sent = 0;
1133
1134 while (n_left_from > 0)
1135 {
1136 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1137
1138 while (n_left_from > 0 && n_left_to_next > 0)
1139 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001140 vlib_buffer_t *p0;
1141 ip6_header_t *ip0;
1142 icmp6_neighbor_solicitation_or_advertisement_header_t *h0;
1143 icmp6_neighbor_discovery_ethernet_link_layer_address_option_t *o0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001144 u32 bi0, options_len0, sw_if_index0, next0, error0;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001145 u32 ip6_sadd_link_local, ip6_sadd_unspecified;
1146 int is_rewrite0;
1147 u32 ni0;
1148
Ed Warnickecb9cada2015-12-08 15:45:58 -07001149 bi0 = to_next[0] = from[0];
1150
1151 from += 1;
1152 to_next += 1;
1153 n_left_from -= 1;
1154 n_left_to_next -= 1;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001155
Ed Warnickecb9cada2015-12-08 15:45:58 -07001156 p0 = vlib_get_buffer (vm, bi0);
1157 ip0 = vlib_buffer_get_current (p0);
1158 h0 = ip6_next_header (ip0);
Dave Barachd7cb1b52016-12-09 09:52:16 -05001159 options_len0 =
1160 clib_net_to_host_u16 (ip0->payload_length) - sizeof (h0[0]);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001161
1162 error0 = ICMP6_ERROR_NONE;
1163 sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX];
Dave Barachd7cb1b52016-12-09 09:52:16 -05001164 ip6_sadd_link_local =
1165 ip6_address_is_link_local_unicast (&ip0->src_address);
1166 ip6_sadd_unspecified =
1167 ip6_address_is_unspecified (&ip0->src_address);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001168
1169 /* Check that source address is unspecified, link-local or else on-link. */
1170 if (!ip6_sadd_unspecified && !ip6_sadd_link_local)
1171 {
1172 u32 src_adj_index0 = ip6_src_lookup_for_packet (im, p0, ip0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001173
Dave Barachd7cb1b52016-12-09 09:52:16 -05001174 if (ADJ_INDEX_INVALID != src_adj_index0)
1175 {
Neale Ranns107e7d42017-04-11 09:55:19 -07001176 ip_adjacency_t *adj0 = adj_get (src_adj_index0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001177
Dave Barachd7cb1b52016-12-09 09:52:16 -05001178 /* Allow all realistic-looking rewrite adjacencies to pass */
1179 ni0 = adj0->lookup_next_index;
1180 is_rewrite0 = (ni0 >= IP_LOOKUP_NEXT_ARP) &&
1181 (ni0 < IP6_LOOKUP_N_NEXT);
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001182
Dave Barachd7cb1b52016-12-09 09:52:16 -05001183 error0 = ((adj0->rewrite_header.sw_if_index != sw_if_index0
1184 || !is_rewrite0)
1185 ?
1186 ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_NOT_ON_LINK
1187 : error0);
1188 }
1189 else
1190 {
1191 error0 =
1192 ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_NOT_ON_LINK;
1193 }
1194 }
1195
Ed Warnickecb9cada2015-12-08 15:45:58 -07001196 o0 = (void *) (h0 + 1);
1197 o0 = ((options_len0 == 8 && o0->header.type == option_type
1198 && o0->header.n_data_u64s == 1) ? o0 : 0);
1199
1200 /* If src address unspecified or link local, donot learn neighbor MAC */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001201 if (PREDICT_TRUE (error0 == ICMP6_ERROR_NONE && o0 != 0 &&
Neale Ranns2a3ea492017-04-19 05:24:40 -07001202 !ip6_sadd_unspecified))
Dave Barachd7cb1b52016-12-09 09:52:16 -05001203 {
1204 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
1205 if (nm->limit_neighbor_cache_size &&
1206 pool_elts (nm->neighbor_pool) >=
1207 nm->limit_neighbor_cache_size)
1208 unset_random_neighbor_entry ();
1209 vnet_set_ip6_ethernet_neighbor (vm, sw_if_index0,
1210 is_solicitation ?
1211 &ip0->src_address :
1212 &h0->target_address,
1213 o0->ethernet_address,
1214 sizeof (o0->ethernet_address),
Neale Ranns53da2212018-02-24 02:11:19 -08001215 0, 0);
Dave Barachd7cb1b52016-12-09 09:52:16 -05001216 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001217
1218 if (is_solicitation && error0 == ICMP6_ERROR_NONE)
1219 {
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001220 /* Check that target address is local to this router. */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001221 fib_node_index_t fei;
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001222 u32 fib_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001223
Dave Barachd7cb1b52016-12-09 09:52:16 -05001224 fib_index =
1225 ip6_fib_table_get_index_for_sw_if_index (sw_if_index0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001226
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001227 if (~0 == fib_index)
Dave Barachd7cb1b52016-12-09 09:52:16 -05001228 {
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001229 error0 = ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_UNKNOWN;
1230 }
1231 else
Dave Barachd7cb1b52016-12-09 09:52:16 -05001232 {
Neale Ranns53da2212018-02-24 02:11:19 -08001233 if (ip6_address_is_link_local_unicast (&h0->target_address))
1234 {
1235 fei = ip6_fib_table_lookup_exact_match
1236 (ip6_ll_fib_get (sw_if_index0),
1237 &h0->target_address, 128);
1238 }
1239 else
1240 {
1241 fei = ip6_fib_table_lookup_exact_match (fib_index,
1242 &h0->target_address,
1243 128);
1244 }
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001245
Neale Ranns3f844d02017-02-18 00:03:54 -08001246 if (FIB_NODE_INDEX_INVALID == fei)
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001247 {
Neale Ranns3f844d02017-02-18 00:03:54 -08001248 /* The target address is not in the FIB */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001249 error0 =
1250 ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_UNKNOWN;
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001251 }
Neale Ranns3f844d02017-02-18 00:03:54 -08001252 else
1253 {
1254 if (FIB_ENTRY_FLAG_LOCAL &
1255 fib_entry_get_flags_for_source (fei,
1256 FIB_SOURCE_INTERFACE))
1257 {
1258 /* It's an address that belongs to one of our interfaces
1259 * that's good. */
1260 }
1261 else
1262 if (fib_entry_is_sourced
Neale Ranns53da2212018-02-24 02:11:19 -08001263 (fei, FIB_SOURCE_IP6_ND_PROXY) ||
1264 fib_entry_is_sourced (fei, FIB_SOURCE_IP6_ND))
Neale Ranns3f844d02017-02-18 00:03:54 -08001265 {
1266 /* The address was added by IPv6 Proxy ND config.
1267 * We should only respond to these if the NS arrived on
1268 * the link that has a matching covering prefix */
1269 }
1270 else
1271 {
1272 error0 =
1273 ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_UNKNOWN;
1274 }
1275 }
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001276 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001277 }
1278
1279 if (is_solicitation)
Dave Barachd7cb1b52016-12-09 09:52:16 -05001280 next0 = (error0 != ICMP6_ERROR_NONE
1281 ? ICMP6_NEIGHBOR_SOLICITATION_NEXT_DROP
1282 : ICMP6_NEIGHBOR_SOLICITATION_NEXT_REPLY);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001283 else
1284 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001285 next0 = 0;
1286 error0 = error0 == ICMP6_ERROR_NONE ?
1287 ICMP6_ERROR_NEIGHBOR_ADVERTISEMENTS_RX : error0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001288 }
1289
1290 if (is_solicitation && error0 == ICMP6_ERROR_NONE)
1291 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001292 vnet_sw_interface_t *sw_if0;
1293 ethernet_interface_t *eth_if0;
1294 ethernet_header_t *eth0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001295
Dave Barachd7cb1b52016-12-09 09:52:16 -05001296 /* dst address is either source address or the all-nodes mcast addr */
1297 if (!ip6_sadd_unspecified)
1298 ip0->dst_address = ip0->src_address;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001299 else
Dave Barachd7cb1b52016-12-09 09:52:16 -05001300 ip6_set_reserved_multicast_address (&ip0->dst_address,
1301 IP6_MULTICAST_SCOPE_link_local,
1302 IP6_MULTICAST_GROUP_ID_all_hosts);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001303
1304 ip0->src_address = h0->target_address;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001305 ip0->hop_limit = 255;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001306 h0->icmp.type = ICMP6_neighbor_advertisement;
1307
1308 sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index0);
1309 ASSERT (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE);
Dave Barachd7cb1b52016-12-09 09:52:16 -05001310 eth_if0 =
1311 ethernet_get_interface (&ethernet_main, sw_if0->hw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001312 if (eth_if0 && o0)
1313 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001314 clib_memcpy (o0->ethernet_address, eth_if0->address, 6);
1315 o0->header.type =
1316 ICMP6_NEIGHBOR_DISCOVERY_OPTION_target_link_layer_address;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001317 }
1318
1319 h0->advertisement_flags = clib_host_to_net_u32
1320 (ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_SOLICITED
1321 | ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_OVERRIDE);
1322
1323 h0->icmp.checksum = 0;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001324 h0->icmp.checksum =
1325 ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip0,
1326 &bogus_length);
1327 ASSERT (bogus_length == 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001328
Dave Barachd7cb1b52016-12-09 09:52:16 -05001329 /* Reuse current MAC header, copy SMAC to DMAC and
1330 * interface MAC to SMAC */
1331 vlib_buffer_advance (p0, -ethernet_buffer_header_size (p0));
1332 eth0 = vlib_buffer_get_current (p0);
1333 clib_memcpy (eth0->dst_address, eth0->src_address, 6);
1334 if (eth_if0)
1335 clib_memcpy (eth0->src_address, eth_if0->address, 6);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001336
Dave Barachd7cb1b52016-12-09 09:52:16 -05001337 /* Setup input and output sw_if_index for packet */
1338 ASSERT (vnet_buffer (p0)->sw_if_index[VLIB_RX] == sw_if_index0);
1339 vnet_buffer (p0)->sw_if_index[VLIB_TX] = sw_if_index0;
1340 vnet_buffer (p0)->sw_if_index[VLIB_RX] =
1341 vnet_main.local_interface_sw_if_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001342
1343 n_advertisements_sent++;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001344 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001345
1346 p0->error = error_node->errors[error0];
1347
1348 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1349 to_next, n_left_to_next,
1350 bi0, next0);
1351 }
1352
1353 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1354 }
1355
1356 /* Account for advertisements sent. */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001357 vlib_error_count (vm, error_node->node_index,
1358 ICMP6_ERROR_NEIGHBOR_ADVERTISEMENTS_TX,
1359 n_advertisements_sent);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001360
1361 return frame->n_vectors;
1362}
1363
1364/* for "syslogging" - use elog for now */
1365#define foreach_log_level \
1366 _ (DEBUG, "DEBUG") \
1367 _ (INFO, "INFORMATION") \
1368 _ (NOTICE, "NOTICE") \
1369 _ (WARNING, "WARNING") \
1370 _ (ERR, "ERROR") \
1371 _ (CRIT, "CRITICAL") \
1372 _ (ALERT, "ALERT") \
1373 _ (EMERG, "EMERGENCY")
1374
Dave Barachd7cb1b52016-12-09 09:52:16 -05001375typedef enum
1376{
Ed Warnickecb9cada2015-12-08 15:45:58 -07001377#define _(f,s) LOG_##f,
1378 foreach_log_level
1379#undef _
1380} log_level_t;
1381
Dave Barachd7cb1b52016-12-09 09:52:16 -05001382static char *log_level_strings[] = {
Ed Warnickecb9cada2015-12-08 15:45:58 -07001383#define _(f,s) s,
1384 foreach_log_level
1385#undef _
1386};
1387
Dave Barachd7cb1b52016-12-09 09:52:16 -05001388static int logmask = 1 << LOG_DEBUG;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001389
1390static void
Dave Barachd7cb1b52016-12-09 09:52:16 -05001391ip6_neighbor_syslog (vlib_main_t * vm, int priority, char *fmt, ...)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001392{
1393 /* just use elog for now */
1394 u8 *what;
1395 va_list va;
1396
Dave Barachd7cb1b52016-12-09 09:52:16 -05001397 if ((priority > LOG_EMERG) || !(logmask & (1 << priority)))
1398 return;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001399
1400 va_start (va, fmt);
Dave Barachd7cb1b52016-12-09 09:52:16 -05001401 if (fmt)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001402 {
1403 what = va_format (0, fmt, &va);
1404
Dave Barachd7cb1b52016-12-09 09:52:16 -05001405 ELOG_TYPE_DECLARE (e) =
1406 {
1407 .format = "ip6 nd: (%s): %s",.format_args = "T4T4",};
1408 struct
1409 {
1410 u32 s[2];
1411 } *ed;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001412 ed = ELOG_DATA (&vm->elog_main, e);
Dave Barachd7cb1b52016-12-09 09:52:16 -05001413 ed->s[0] = elog_string (&vm->elog_main, log_level_strings[priority]);
1414 ed->s[1] = elog_string (&vm->elog_main, (char *) what);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001415 }
1416 va_end (va);
1417 return;
1418}
1419
1420/* ipv6 neighbor discovery - router advertisements */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001421typedef enum
1422{
Ed Warnickecb9cada2015-12-08 15:45:58 -07001423 ICMP6_ROUTER_SOLICITATION_NEXT_DROP,
1424 ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_RW,
1425 ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_TX,
1426 ICMP6_ROUTER_SOLICITATION_N_NEXT,
1427} icmp6_router_solicitation_or_advertisement_next_t;
1428
1429static_always_inline uword
Dave Barachd7cb1b52016-12-09 09:52:16 -05001430icmp6_router_solicitation (vlib_main_t * vm,
1431 vlib_node_runtime_t * node, vlib_frame_t * frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001432{
Dave Barachd7cb1b52016-12-09 09:52:16 -05001433 vnet_main_t *vnm = vnet_get_main ();
1434 ip6_main_t *im = &ip6_main;
1435 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001436 uword n_packets = frame->n_vectors;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001437 u32 *from, *to_next;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001438 u32 n_left_from, n_left_to_next, next_index;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001439 u32 n_advertisements_sent = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001440 int bogus_length;
1441
1442 icmp6_neighbor_discovery_option_type_t option_type;
1443
Dave Barachd7cb1b52016-12-09 09:52:16 -05001444 vlib_node_runtime_t *error_node =
1445 vlib_node_get_runtime (vm, ip6_icmp_input_node.index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001446
1447 from = vlib_frame_vector_args (frame);
1448 n_left_from = n_packets;
1449 next_index = node->cached_next_index;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001450
Ed Warnickecb9cada2015-12-08 15:45:58 -07001451 if (node->flags & VLIB_NODE_FLAG_TRACE)
1452 vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors,
1453 /* stride */ 1,
1454 sizeof (icmp6_input_trace_t));
1455
1456 /* source may append his LL address */
1457 option_type = ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address;
1458
1459 while (n_left_from > 0)
1460 {
1461 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
Dave Barachd7cb1b52016-12-09 09:52:16 -05001462
Ed Warnickecb9cada2015-12-08 15:45:58 -07001463 while (n_left_from > 0 && n_left_to_next > 0)
1464 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001465 vlib_buffer_t *p0;
1466 ip6_header_t *ip0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001467 ip6_radv_t *radv_info = 0;
1468
Dave Barachd7cb1b52016-12-09 09:52:16 -05001469 icmp6_neighbor_discovery_header_t *h0;
1470 icmp6_neighbor_discovery_ethernet_link_layer_address_option_t *o0;
1471
Ed Warnickecb9cada2015-12-08 15:45:58 -07001472 u32 bi0, options_len0, sw_if_index0, next0, error0;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001473 u32 is_solicitation = 1, is_dropped = 0;
1474 u32 is_unspecified, is_link_local;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001475
1476 bi0 = to_next[0] = from[0];
1477
1478 from += 1;
1479 to_next += 1;
1480 n_left_from -= 1;
1481 n_left_to_next -= 1;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001482
Ed Warnickecb9cada2015-12-08 15:45:58 -07001483 p0 = vlib_get_buffer (vm, bi0);
1484 ip0 = vlib_buffer_get_current (p0);
1485 h0 = ip6_next_header (ip0);
Dave Barachd7cb1b52016-12-09 09:52:16 -05001486 options_len0 =
1487 clib_net_to_host_u16 (ip0->payload_length) - sizeof (h0[0]);
1488 is_unspecified = ip6_address_is_unspecified (&ip0->src_address);
1489 is_link_local =
1490 ip6_address_is_link_local_unicast (&ip0->src_address);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001491
1492 error0 = ICMP6_ERROR_NONE;
1493 sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX];
Dave Barachd7cb1b52016-12-09 09:52:16 -05001494
Ed Warnickecb9cada2015-12-08 15:45:58 -07001495 /* check if solicitation (not from nd_timer node) */
1496 if (ip6_address_is_unspecified (&ip0->dst_address))
1497 is_solicitation = 0;
1498
1499 /* Check that source address is unspecified, link-local or else on-link. */
1500 if (!is_unspecified && !is_link_local)
1501 {
1502 u32 src_adj_index0 = ip6_src_lookup_for_packet (im, p0, ip0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001503
Dave Barachd7cb1b52016-12-09 09:52:16 -05001504 if (ADJ_INDEX_INVALID != src_adj_index0)
1505 {
Neale Ranns107e7d42017-04-11 09:55:19 -07001506 ip_adjacency_t *adj0 = adj_get (src_adj_index0);
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001507
Dave Barachd7cb1b52016-12-09 09:52:16 -05001508 error0 = (adj0->rewrite_header.sw_if_index != sw_if_index0
1509 ?
1510 ICMP6_ERROR_ROUTER_SOLICITATION_SOURCE_NOT_ON_LINK
1511 : error0);
1512 }
1513 else
1514 {
1515 error0 = ICMP6_ERROR_ROUTER_SOLICITATION_SOURCE_NOT_ON_LINK;
1516 }
1517 }
1518
Ed Warnickecb9cada2015-12-08 15:45:58 -07001519 /* check for source LL option and process */
1520 o0 = (void *) (h0 + 1);
1521 o0 = ((options_len0 == 8
1522 && o0->header.type == option_type
Dave Barachd7cb1b52016-12-09 09:52:16 -05001523 && o0->header.n_data_u64s == 1) ? o0 : 0);
1524
Ed Warnickecb9cada2015-12-08 15:45:58 -07001525 /* if src address unspecified IGNORE any options */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001526 if (PREDICT_TRUE (error0 == ICMP6_ERROR_NONE && o0 != 0 &&
1527 !is_unspecified && !is_link_local))
1528 {
1529 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
1530 if (nm->limit_neighbor_cache_size &&
1531 pool_elts (nm->neighbor_pool) >=
1532 nm->limit_neighbor_cache_size)
1533 unset_random_neighbor_entry ();
1534
1535 vnet_set_ip6_ethernet_neighbor (vm, sw_if_index0,
1536 &ip0->src_address,
1537 o0->ethernet_address,
1538 sizeof (o0->ethernet_address),
Neale Rannsb3b2de72017-03-08 05:17:22 -08001539 0, 0);
Dave Barachd7cb1b52016-12-09 09:52:16 -05001540 }
1541
Ed Warnickecb9cada2015-12-08 15:45:58 -07001542 /* default is to drop */
1543 next0 = ICMP6_ROUTER_SOLICITATION_NEXT_DROP;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001544
Ed Warnickecb9cada2015-12-08 15:45:58 -07001545 if (error0 == ICMP6_ERROR_NONE)
1546 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001547 vnet_sw_interface_t *sw_if0;
1548 ethernet_interface_t *eth_if0;
1549 u32 adj_index0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001550
1551 sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index0);
1552 ASSERT (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE);
Dave Barachd7cb1b52016-12-09 09:52:16 -05001553 eth_if0 =
1554 ethernet_get_interface (&ethernet_main, sw_if0->hw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001555
1556 /* only support ethernet interface type for now */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001557 error0 =
1558 (!eth_if0) ? ICMP6_ERROR_ROUTER_SOLICITATION_UNSUPPORTED_INTF
1559 : error0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001560
1561 if (error0 == ICMP6_ERROR_NONE)
1562 {
1563 u32 ri;
1564
1565 /* adjust the sizeof the buffer to just include the ipv6 header */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001566 p0->current_length -=
1567 (options_len0 +
1568 sizeof (icmp6_neighbor_discovery_header_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001569
1570 /* look up the radv_t information for this interface */
Neale Ranns8e254952018-04-25 05:40:48 -07001571 if (vec_len (nm->if_radv_pool_index_by_sw_if_index) >
1572 sw_if_index0)
1573 {
1574 ri =
1575 nm->if_radv_pool_index_by_sw_if_index[sw_if_index0];
Ed Warnickecb9cada2015-12-08 15:45:58 -07001576
Neale Ranns8e254952018-04-25 05:40:48 -07001577 if (ri != ~0)
1578 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
1579 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05001580
1581 error0 =
1582 ((!radv_info) ?
1583 ICMP6_ERROR_ROUTER_SOLICITATION_RADV_NOT_CONFIG :
1584 error0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001585
1586 if (error0 == ICMP6_ERROR_NONE)
1587 {
1588 f64 now = vlib_time_now (vm);
1589
1590 /* for solicited adverts - need to rate limit */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001591 if (is_solicitation)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001592 {
Neale Ranns75152282017-01-09 01:00:45 -08001593 if (0 != radv_info->last_radv_time &&
1594 (now - radv_info->last_radv_time) <
Dave Barachd7cb1b52016-12-09 09:52:16 -05001595 MIN_DELAY_BETWEEN_RAS)
1596 is_dropped = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001597 else
1598 radv_info->last_radv_time = now;
1599 }
1600
1601 /* send now */
1602 icmp6_router_advertisement_header_t rh;
1603
1604 rh.icmp.type = ICMP6_router_advertisement;
1605 rh.icmp.code = 0;
1606 rh.icmp.checksum = 0;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001607
Ed Warnickecb9cada2015-12-08 15:45:58 -07001608 rh.current_hop_limit = radv_info->curr_hop_limit;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001609 rh.router_lifetime_in_sec =
1610 clib_host_to_net_u16
1611 (radv_info->adv_router_lifetime_in_sec);
1612 rh.
1613 time_in_msec_between_retransmitted_neighbor_solicitations
1614 =
1615 clib_host_to_net_u32 (radv_info->
1616 adv_time_in_msec_between_retransmitted_neighbor_solicitations);
1617 rh.neighbor_reachable_time_in_msec =
1618 clib_host_to_net_u32 (radv_info->
1619 adv_neighbor_reachable_time_in_msec);
1620
1621 rh.flags =
1622 (radv_info->adv_managed_flag) ?
1623 ICMP6_ROUTER_DISCOVERY_FLAG_ADDRESS_CONFIG_VIA_DHCP :
1624 0;
1625 rh.flags |=
1626 ((radv_info->adv_other_flag) ?
1627 ICMP6_ROUTER_DISCOVERY_FLAG_OTHER_CONFIG_VIA_DHCP :
1628 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001629
1630
Dave Barachd7cb1b52016-12-09 09:52:16 -05001631 u16 payload_length =
1632 sizeof (icmp6_router_advertisement_header_t);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001633
1634 vlib_buffer_add_data (vm,
Damjan Marion072401e2017-07-13 18:53:27 +02001635 vlib_buffer_get_free_list_index
1636 (p0), bi0, (void *) &rh,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001637 sizeof
1638 (icmp6_router_advertisement_header_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001639
Dave Barachd7cb1b52016-12-09 09:52:16 -05001640 if (radv_info->adv_link_layer_address)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001641 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001642 icmp6_neighbor_discovery_ethernet_link_layer_address_option_t
1643 h;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001644
Dave Barachd7cb1b52016-12-09 09:52:16 -05001645 h.header.type =
1646 ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001647 h.header.n_data_u64s = 1;
1648
1649 /* copy ll address */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001650 clib_memcpy (&h.ethernet_address[0],
1651 eth_if0->address, 6);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001652
1653 vlib_buffer_add_data (vm,
Damjan Marion072401e2017-07-13 18:53:27 +02001654 vlib_buffer_get_free_list_index
1655 (p0), bi0, (void *) &h,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001656 sizeof
1657 (icmp6_neighbor_discovery_ethernet_link_layer_address_option_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001658
Dave Barachd7cb1b52016-12-09 09:52:16 -05001659 payload_length +=
1660 sizeof
1661 (icmp6_neighbor_discovery_ethernet_link_layer_address_option_t);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001662 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05001663
Ed Warnickecb9cada2015-12-08 15:45:58 -07001664 /* add MTU option */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001665 if (radv_info->adv_link_mtu)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001666 {
1667 icmp6_neighbor_discovery_mtu_option_t h;
1668
1669 h.unused = 0;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001670 h.mtu =
1671 clib_host_to_net_u32 (radv_info->adv_link_mtu);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001672 h.header.type = ICMP6_NEIGHBOR_DISCOVERY_OPTION_mtu;
1673 h.header.n_data_u64s = 1;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001674
1675 payload_length +=
1676 sizeof (icmp6_neighbor_discovery_mtu_option_t);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001677
1678 vlib_buffer_add_data (vm,
Damjan Marion072401e2017-07-13 18:53:27 +02001679 vlib_buffer_get_free_list_index
1680 (p0), bi0, (void *) &h,
Dave Barachd7cb1b52016-12-09 09:52:16 -05001681 sizeof
1682 (icmp6_neighbor_discovery_mtu_option_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -07001683 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05001684
Ed Warnickecb9cada2015-12-08 15:45:58 -07001685 /* add advertised prefix options */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001686 ip6_radv_prefix_t *pr_info;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001687
Dave Barachd7cb1b52016-12-09 09:52:16 -05001688 /* *INDENT-OFF* */
1689 pool_foreach (pr_info, radv_info->adv_prefixes_pool,
1690 ({
1691 if(pr_info->enabled &&
1692 (!pr_info->decrement_lifetime_flag
1693 || (pr_info->pref_lifetime_expires >0)))
1694 {
1695 /* advertise this prefix */
1696 icmp6_neighbor_discovery_prefix_information_option_t h;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001697
Dave Barachd7cb1b52016-12-09 09:52:16 -05001698 h.header.type = ICMP6_NEIGHBOR_DISCOVERY_OPTION_prefix_information;
1699 h.header.n_data_u64s = (sizeof(icmp6_neighbor_discovery_prefix_information_option_t) >> 3);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001700
Dave Barachd7cb1b52016-12-09 09:52:16 -05001701 h.dst_address_length = pr_info->prefix_len;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001702
Dave Barachd7cb1b52016-12-09 09:52:16 -05001703 h.flags = (pr_info->adv_on_link_flag) ? ICMP6_NEIGHBOR_DISCOVERY_PREFIX_INFORMATION_FLAG_ON_LINK : 0;
1704 h.flags |= (pr_info->adv_autonomous_flag) ? ICMP6_NEIGHBOR_DISCOVERY_PREFIX_INFORMATION_AUTO : 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001705
Dave Barachd7cb1b52016-12-09 09:52:16 -05001706 if(radv_info->cease_radv && pr_info->deprecated_prefix_flag)
1707 {
1708 h.valid_time = clib_host_to_net_u32(MIN_ADV_VALID_LIFETIME);
1709 h.preferred_time = 0;
1710 }
1711 else
1712 {
1713 if(pr_info->decrement_lifetime_flag)
1714 {
1715 pr_info->adv_valid_lifetime_in_secs = ((pr_info->valid_lifetime_expires > now)) ?
1716 (pr_info->valid_lifetime_expires - now) : 0;
1717
1718 pr_info->adv_pref_lifetime_in_secs = ((pr_info->pref_lifetime_expires > now)) ?
1719 (pr_info->pref_lifetime_expires - now) : 0;
1720 }
1721
1722 h.valid_time = clib_host_to_net_u32(pr_info->adv_valid_lifetime_in_secs);
1723 h.preferred_time = clib_host_to_net_u32(pr_info->adv_pref_lifetime_in_secs) ;
1724 }
1725 h.unused = 0;
1726
1727 clib_memcpy(&h.dst_address, &pr_info->prefix, sizeof(ip6_address_t));
1728
1729 payload_length += sizeof( icmp6_neighbor_discovery_prefix_information_option_t);
1730
1731 vlib_buffer_add_data (vm,
Damjan Marion072401e2017-07-13 18:53:27 +02001732 vlib_buffer_get_free_list_index (p0),
Dave Barachd7cb1b52016-12-09 09:52:16 -05001733 bi0,
1734 (void *)&h, sizeof(icmp6_neighbor_discovery_prefix_information_option_t));
1735
1736 }
1737 }));
1738 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001739
1740 /* add additional options before here */
1741
1742 /* finish building the router advertisement... */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001743 if (!is_unspecified && radv_info->send_unicast)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001744 {
1745 ip0->dst_address = ip0->src_address;
1746 }
1747 else
Dave Barachd7cb1b52016-12-09 09:52:16 -05001748 {
1749 /* target address is all-nodes mcast addr */
1750 ip6_set_reserved_multicast_address
1751 (&ip0->dst_address,
1752 IP6_MULTICAST_SCOPE_link_local,
1753 IP6_MULTICAST_GROUP_ID_all_hosts);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001754 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05001755
Ed Warnickecb9cada2015-12-08 15:45:58 -07001756 /* source address MUST be the link-local address */
1757 ip0->src_address = radv_info->link_local_address;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001758
Dave Barachd7cb1b52016-12-09 09:52:16 -05001759 ip0->hop_limit = 255;
1760 ip0->payload_length =
1761 clib_host_to_net_u16 (payload_length);
1762
1763 icmp6_router_advertisement_header_t *rh0 =
1764 (icmp6_router_advertisement_header_t *) (ip0 + 1);
1765 rh0->icmp.checksum =
1766 ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip0,
1767 &bogus_length);
1768 ASSERT (bogus_length == 0);
1769
Ed Warnickecb9cada2015-12-08 15:45:58 -07001770 /* setup output if and adjacency */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001771 vnet_buffer (p0)->sw_if_index[VLIB_RX] =
Ed Warnickecb9cada2015-12-08 15:45:58 -07001772 vnet_main.local_interface_sw_if_index;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001773
1774 if (is_solicitation)
1775 {
1776 ethernet_header_t *eth0;
1777 /* Reuse current MAC header, copy SMAC to DMAC and
1778 * interface MAC to SMAC */
1779 vlib_buffer_reset (p0);
1780 eth0 = vlib_buffer_get_current (p0);
1781 clib_memcpy (eth0->dst_address, eth0->src_address,
1782 6);
1783 clib_memcpy (eth0->src_address, eth_if0->address,
1784 6);
1785 next0 =
1786 is_dropped ? next0 :
1787 ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_TX;
1788 vnet_buffer (p0)->sw_if_index[VLIB_TX] =
1789 sw_if_index0;
1790 }
1791 else
1792 {
Neale Ranns32e1c012016-11-22 17:07:28 +00001793 adj_index0 = radv_info->mcast_adj_index;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001794 if (adj_index0 == 0)
1795 error0 = ICMP6_ERROR_DST_LOOKUP_MISS;
1796 else
1797 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001798 next0 =
1799 is_dropped ? next0 :
1800 ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_RW;
1801 vnet_buffer (p0)->ip.adj_index[VLIB_TX] =
1802 adj_index0;
1803 }
1804 }
Damjan Marion213b5aa2017-07-13 21:19:27 +02001805 p0->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001806
1807 radv_info->n_solicitations_dropped += is_dropped;
1808 radv_info->n_solicitations_rcvd += is_solicitation;
1809
1810 if ((error0 == ICMP6_ERROR_NONE) && !is_dropped)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001811 {
1812 radv_info->n_advertisements_sent++;
1813 n_advertisements_sent++;
1814 }
1815 }
1816 }
1817 }
1818
1819 p0->error = error_node->errors[error0];
1820
Dave Barachd7cb1b52016-12-09 09:52:16 -05001821 if (error0 != ICMP6_ERROR_NONE)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001822 vlib_error_count (vm, error_node->node_index, error0, 1);
Dave Barachd7cb1b52016-12-09 09:52:16 -05001823
Ed Warnickecb9cada2015-12-08 15:45:58 -07001824 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1825 to_next, n_left_to_next,
1826 bi0, next0);
Dave Barachd7cb1b52016-12-09 09:52:16 -05001827
Ed Warnickecb9cada2015-12-08 15:45:58 -07001828 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05001829
Ed Warnickecb9cada2015-12-08 15:45:58 -07001830 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1831 }
1832
1833 /* Account for router advertisements sent. */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001834 vlib_error_count (vm, error_node->node_index,
1835 ICMP6_ERROR_ROUTER_ADVERTISEMENTS_TX,
1836 n_advertisements_sent);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001837
1838 return frame->n_vectors;
1839}
1840
1841 /* validate advertised info for consistancy (see RFC-4861 section 6.2.7) - log any inconsistencies, packet will always be dropped */
1842static_always_inline uword
Dave Barachd7cb1b52016-12-09 09:52:16 -05001843icmp6_router_advertisement (vlib_main_t * vm,
1844 vlib_node_runtime_t * node, vlib_frame_t * frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001845{
Dave Barachd7cb1b52016-12-09 09:52:16 -05001846 vnet_main_t *vnm = vnet_get_main ();
1847 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001848 uword n_packets = frame->n_vectors;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001849 u32 *from, *to_next;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001850 u32 n_left_from, n_left_to_next, next_index;
1851 u32 n_advertisements_rcvd = 0;
1852
Dave Barachd7cb1b52016-12-09 09:52:16 -05001853 vlib_node_runtime_t *error_node =
1854 vlib_node_get_runtime (vm, ip6_icmp_input_node.index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001855
1856 from = vlib_frame_vector_args (frame);
1857 n_left_from = n_packets;
1858 next_index = node->cached_next_index;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001859
Ed Warnickecb9cada2015-12-08 15:45:58 -07001860 if (node->flags & VLIB_NODE_FLAG_TRACE)
1861 vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors,
1862 /* stride */ 1,
1863 sizeof (icmp6_input_trace_t));
1864
1865 while (n_left_from > 0)
1866 {
1867 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
Dave Barachd7cb1b52016-12-09 09:52:16 -05001868
Ed Warnickecb9cada2015-12-08 15:45:58 -07001869 while (n_left_from > 0 && n_left_to_next > 0)
1870 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001871 vlib_buffer_t *p0;
1872 ip6_header_t *ip0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001873 ip6_radv_t *radv_info = 0;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001874 icmp6_router_advertisement_header_t *h0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001875 u32 bi0, options_len0, sw_if_index0, next0, error0;
1876
1877 bi0 = to_next[0] = from[0];
1878
1879 from += 1;
1880 to_next += 1;
1881 n_left_from -= 1;
1882 n_left_to_next -= 1;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001883
Ed Warnickecb9cada2015-12-08 15:45:58 -07001884 p0 = vlib_get_buffer (vm, bi0);
1885 ip0 = vlib_buffer_get_current (p0);
1886 h0 = ip6_next_header (ip0);
Dave Barachd7cb1b52016-12-09 09:52:16 -05001887 options_len0 =
1888 clib_net_to_host_u16 (ip0->payload_length) - sizeof (h0[0]);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001889
1890 error0 = ICMP6_ERROR_NONE;
1891 sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX];
1892
Dave Barachd7cb1b52016-12-09 09:52:16 -05001893 /* Check that source address is link-local */
1894 error0 = (!ip6_address_is_link_local_unicast (&ip0->src_address)) ?
Ed Warnickecb9cada2015-12-08 15:45:58 -07001895 ICMP6_ERROR_ROUTER_ADVERTISEMENT_SOURCE_NOT_LINK_LOCAL : error0;
1896
1897 /* default is to drop */
1898 next0 = ICMP6_ROUTER_SOLICITATION_NEXT_DROP;
Dave Barachd7cb1b52016-12-09 09:52:16 -05001899
Ed Warnickecb9cada2015-12-08 15:45:58 -07001900 n_advertisements_rcvd++;
1901
1902 if (error0 == ICMP6_ERROR_NONE)
1903 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001904 vnet_sw_interface_t *sw_if0;
1905 ethernet_interface_t *eth_if0;
1906
Ed Warnickecb9cada2015-12-08 15:45:58 -07001907 sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index0);
1908 ASSERT (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE);
Dave Barachd7cb1b52016-12-09 09:52:16 -05001909 eth_if0 =
1910 ethernet_get_interface (&ethernet_main, sw_if0->hw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001911
1912 /* only support ethernet interface type for now */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001913 error0 =
1914 (!eth_if0) ? ICMP6_ERROR_ROUTER_SOLICITATION_UNSUPPORTED_INTF
1915 : error0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001916
1917 if (error0 == ICMP6_ERROR_NONE)
1918 {
1919 u32 ri;
1920
1921 /* look up the radv_t information for this interface */
Neale Ranns8e254952018-04-25 05:40:48 -07001922 if (vec_len (nm->if_radv_pool_index_by_sw_if_index) >
1923 sw_if_index0)
1924 {
1925 ri =
1926 nm->if_radv_pool_index_by_sw_if_index[sw_if_index0];
Ed Warnickecb9cada2015-12-08 15:45:58 -07001927
Neale Ranns8e254952018-04-25 05:40:48 -07001928 if (ri != ~0)
1929 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
1930 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05001931
1932 error0 =
1933 ((!radv_info) ?
1934 ICMP6_ERROR_ROUTER_SOLICITATION_RADV_NOT_CONFIG :
1935 error0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001936
1937 if (error0 == ICMP6_ERROR_NONE)
1938 {
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01001939 radv_info->keep_sending_rs = 0;
1940
1941 ra_report_t r;
1942
1943 r.sw_if_index = sw_if_index0;
1944 memcpy (r.router_address, &ip0->src_address, 16);
1945 r.current_hop_limit = h0->current_hop_limit;
1946 r.flags = h0->flags;
1947 r.router_lifetime_in_sec =
1948 clib_net_to_host_u16 (h0->router_lifetime_in_sec);
1949 r.neighbor_reachable_time_in_msec =
1950 clib_net_to_host_u32
1951 (h0->neighbor_reachable_time_in_msec);
1952 r.time_in_msec_between_retransmitted_neighbor_solicitations = clib_net_to_host_u32 (h0->time_in_msec_between_retransmitted_neighbor_solicitations);
1953 r.prefixes = 0;
1954
Ed Warnickecb9cada2015-12-08 15:45:58 -07001955 /* validate advertised information */
Dave Barachd7cb1b52016-12-09 09:52:16 -05001956 if ((h0->current_hop_limit && radv_info->curr_hop_limit)
1957 && (h0->current_hop_limit !=
1958 radv_info->curr_hop_limit))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001959 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001960 ip6_neighbor_syslog (vm, LOG_WARNING,
1961 "our AdvCurHopLimit on %U doesn't agree with %U",
1962 format_vnet_sw_if_index_name,
1963 vnm, sw_if_index0,
1964 format_ip6_address,
1965 &ip0->src_address);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001966 }
1967
Dave Barachd7cb1b52016-12-09 09:52:16 -05001968 if ((h0->flags &
1969 ICMP6_ROUTER_DISCOVERY_FLAG_ADDRESS_CONFIG_VIA_DHCP)
1970 != radv_info->adv_managed_flag)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001971 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001972 ip6_neighbor_syslog (vm, LOG_WARNING,
1973 "our AdvManagedFlag on %U doesn't agree with %U",
1974 format_vnet_sw_if_index_name,
1975 vnm, sw_if_index0,
1976 format_ip6_address,
1977 &ip0->src_address);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001978 }
1979
Dave Barachd7cb1b52016-12-09 09:52:16 -05001980 if ((h0->flags &
1981 ICMP6_ROUTER_DISCOVERY_FLAG_OTHER_CONFIG_VIA_DHCP)
1982 != radv_info->adv_other_flag)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001983 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05001984 ip6_neighbor_syslog (vm, LOG_WARNING,
1985 "our AdvOtherConfigFlag on %U doesn't agree with %U",
1986 format_vnet_sw_if_index_name,
1987 vnm, sw_if_index0,
1988 format_ip6_address,
1989 &ip0->src_address);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001990 }
1991
Dave Barachd7cb1b52016-12-09 09:52:16 -05001992 if ((h0->
1993 time_in_msec_between_retransmitted_neighbor_solicitations
1994 && radv_info->
1995 adv_time_in_msec_between_retransmitted_neighbor_solicitations)
1996 && (h0->
1997 time_in_msec_between_retransmitted_neighbor_solicitations
1998 !=
1999 clib_host_to_net_u32 (radv_info->
2000 adv_time_in_msec_between_retransmitted_neighbor_solicitations)))
Ed Warnickecb9cada2015-12-08 15:45:58 -07002001 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002002 ip6_neighbor_syslog (vm, LOG_WARNING,
2003 "our AdvRetransTimer on %U doesn't agree with %U",
2004 format_vnet_sw_if_index_name,
2005 vnm, sw_if_index0,
2006 format_ip6_address,
2007 &ip0->src_address);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002008 }
2009
Dave Barachd7cb1b52016-12-09 09:52:16 -05002010 if ((h0->neighbor_reachable_time_in_msec &&
2011 radv_info->adv_neighbor_reachable_time_in_msec) &&
2012 (h0->neighbor_reachable_time_in_msec !=
2013 clib_host_to_net_u32
2014 (radv_info->adv_neighbor_reachable_time_in_msec)))
Ed Warnickecb9cada2015-12-08 15:45:58 -07002015 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002016 ip6_neighbor_syslog (vm, LOG_WARNING,
2017 "our AdvReachableTime on %U doesn't agree with %U",
2018 format_vnet_sw_if_index_name,
2019 vnm, sw_if_index0,
2020 format_ip6_address,
2021 &ip0->src_address);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002022 }
2023
2024 /* check for MTU or prefix options or .. */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002025 u8 *opt_hdr = (u8 *) (h0 + 1);
2026 while (options_len0 > 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002027 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002028 icmp6_neighbor_discovery_option_header_t *o0 =
2029 (icmp6_neighbor_discovery_option_header_t *)
2030 opt_hdr;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002031 int opt_len = o0->n_data_u64s << 3;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002032 icmp6_neighbor_discovery_option_type_t option_type =
2033 o0->type;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002034
Dave Barachd7cb1b52016-12-09 09:52:16 -05002035 if (options_len0 < 2)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002036 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002037 ip6_neighbor_syslog (vm, LOG_ERR,
2038 "malformed RA packet on %U from %U",
2039 format_vnet_sw_if_index_name,
2040 vnm, sw_if_index0,
2041 format_ip6_address,
2042 &ip0->src_address);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002043 break;
2044 }
2045
Dave Barachd7cb1b52016-12-09 09:52:16 -05002046 if (opt_len == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002047 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002048 ip6_neighbor_syslog (vm, LOG_ERR,
2049 " zero length option in RA on %U from %U",
2050 format_vnet_sw_if_index_name,
2051 vnm, sw_if_index0,
2052 format_ip6_address,
2053 &ip0->src_address);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002054 break;
2055 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05002056 else if (opt_len > options_len0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002057 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002058 ip6_neighbor_syslog (vm, LOG_ERR,
2059 "option length in RA packet greater than total length on %U from %U",
2060 format_vnet_sw_if_index_name,
2061 vnm, sw_if_index0,
2062 format_ip6_address,
2063 &ip0->src_address);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002064 break;
2065 }
2066
2067 options_len0 -= opt_len;
2068 opt_hdr += opt_len;
2069
Dave Barachd7cb1b52016-12-09 09:52:16 -05002070 switch (option_type)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002071 {
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002072 case ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address:
2073 {
2074 icmp6_neighbor_discovery_ethernet_link_layer_address_option_t
2075 * h =
2076 (icmp6_neighbor_discovery_ethernet_link_layer_address_option_t
2077 *) (o0);
2078
2079 if (opt_len < sizeof (*h))
2080 break;
2081
2082 memcpy (r.slla, h->ethernet_address, 6);
2083 }
2084 break;
2085
Ed Warnickecb9cada2015-12-08 15:45:58 -07002086 case ICMP6_NEIGHBOR_DISCOVERY_OPTION_mtu:
Dave Barachd7cb1b52016-12-09 09:52:16 -05002087 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07002088 icmp6_neighbor_discovery_mtu_option_t *h =
Dave Barachd7cb1b52016-12-09 09:52:16 -05002089 (icmp6_neighbor_discovery_mtu_option_t
2090 *) (o0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002091
Dave Barachd7cb1b52016-12-09 09:52:16 -05002092 if (opt_len < sizeof (*h))
Ed Warnickecb9cada2015-12-08 15:45:58 -07002093 break;
2094
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002095 r.mtu = clib_net_to_host_u32 (h->mtu);
2096
Dave Barachd7cb1b52016-12-09 09:52:16 -05002097 if ((h->mtu && radv_info->adv_link_mtu) &&
2098 (h->mtu !=
2099 clib_host_to_net_u32
2100 (radv_info->adv_link_mtu)))
Ed Warnickecb9cada2015-12-08 15:45:58 -07002101 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002102 ip6_neighbor_syslog (vm, LOG_WARNING,
2103 "our AdvLinkMTU on %U doesn't agree with %U",
2104 format_vnet_sw_if_index_name,
2105 vnm, sw_if_index0,
2106 format_ip6_address,
2107 &ip0->src_address);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002108 }
2109 }
2110 break;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002111
Ed Warnickecb9cada2015-12-08 15:45:58 -07002112 case ICMP6_NEIGHBOR_DISCOVERY_OPTION_prefix_information:
2113 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002114 icmp6_neighbor_discovery_prefix_information_option_t
2115 * h =
2116 (icmp6_neighbor_discovery_prefix_information_option_t
2117 *) (o0);
2118
Ed Warnickecb9cada2015-12-08 15:45:58 -07002119 /* validate advertised prefix options */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002120 ip6_radv_prefix_t *pr_info;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002121 u32 preferred, valid;
2122
Dave Barachd7cb1b52016-12-09 09:52:16 -05002123 if (opt_len < sizeof (*h))
Ed Warnickecb9cada2015-12-08 15:45:58 -07002124 break;
2125
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002126 vec_validate (r.prefixes,
2127 vec_len (r.prefixes));
2128 ra_report_prefix_info_t *prefix =
2129 vec_elt_at_index (r.prefixes,
2130 vec_len (r.prefixes) - 1);
2131
Dave Barachd7cb1b52016-12-09 09:52:16 -05002132 preferred =
2133 clib_net_to_host_u32 (h->preferred_time);
2134 valid = clib_net_to_host_u32 (h->valid_time);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002135
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002136 prefix->preferred_time = preferred;
2137 prefix->valid_time = valid;
2138 prefix->flags = h->flags & 0xc0;
2139 prefix->dst_address_length =
2140 h->dst_address_length;
2141 prefix->dst_address = h->dst_address;
2142
Ed Warnickecb9cada2015-12-08 15:45:58 -07002143 /* look for matching prefix - if we our advertising it, it better be consistant */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002144 /* *INDENT-OFF* */
2145 pool_foreach (pr_info, radv_info->adv_prefixes_pool,
2146 ({
Ed Warnickecb9cada2015-12-08 15:45:58 -07002147
Dave Barachd7cb1b52016-12-09 09:52:16 -05002148 ip6_address_t mask;
2149 ip6_address_mask_from_width(&mask, pr_info->prefix_len);
2150
2151 if(pr_info->enabled &&
2152 (pr_info->prefix_len == h->dst_address_length) &&
2153 ip6_address_is_equal_masked (&pr_info->prefix, &h->dst_address, &mask))
2154 {
2155 /* found it */
2156 if(!pr_info->decrement_lifetime_flag &&
2157 valid != pr_info->adv_valid_lifetime_in_secs)
2158 {
2159 ip6_neighbor_syslog(vm, LOG_WARNING,
2160 "our ADV validlifetime on %U for %U does not agree with %U",
2161 format_vnet_sw_if_index_name, vnm, sw_if_index0,format_ip6_address, &pr_info->prefix,
2162 format_ip6_address, &h->dst_address);
2163 }
2164 if(!pr_info->decrement_lifetime_flag &&
2165 preferred != pr_info->adv_pref_lifetime_in_secs)
2166 {
2167 ip6_neighbor_syslog(vm, LOG_WARNING,
2168 "our ADV preferredlifetime on %U for %U does not agree with %U",
2169 format_vnet_sw_if_index_name, vnm, sw_if_index0,format_ip6_address, &pr_info->prefix,
2170 format_ip6_address, &h->dst_address);
2171 }
2172 }
2173 break;
2174 }));
2175 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07002176 break;
2177 }
2178 default:
2179 /* skip this one */
2180 break;
2181 }
2182 }
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002183 ra_publish (&r);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002184 }
2185 }
2186 }
2187
2188 p0->error = error_node->errors[error0];
2189
Dave Barachd7cb1b52016-12-09 09:52:16 -05002190 if (error0 != ICMP6_ERROR_NONE)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002191 vlib_error_count (vm, error_node->node_index, error0, 1);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002192
Ed Warnickecb9cada2015-12-08 15:45:58 -07002193 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
2194 to_next, n_left_to_next,
2195 bi0, next0);
2196 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05002197
Ed Warnickecb9cada2015-12-08 15:45:58 -07002198 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
2199 }
2200
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002201 /* Account for router advertisements received. */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002202 vlib_error_count (vm, error_node->node_index,
2203 ICMP6_ERROR_ROUTER_ADVERTISEMENTS_RX,
2204 n_advertisements_rcvd);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002205
2206 return frame->n_vectors;
2207}
2208
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002209static inline f64
2210random_f64_from_to (f64 from, f64 to)
2211{
2212 static u32 seed = 0;
2213 static u8 seed_set = 0;
2214 if (!seed_set)
2215 {
2216 seed = random_default_seed ();
2217 seed_set = 1;
2218 }
2219 return random_f64 (&seed) * (to - from) + from;
2220}
2221
2222static inline u8
2223get_mac_address (u32 sw_if_index, u8 * address)
2224{
2225 vnet_main_t *vnm = vnet_get_main ();
2226 vnet_hw_interface_t *hw_if = vnet_get_sup_hw_interface (vnm, sw_if_index);
2227 if (!hw_if->hw_address)
2228 return 1;
2229 clib_memcpy (address, hw_if->hw_address, 6);
2230 return 0;
2231}
2232
2233static inline vlib_buffer_t *
2234create_buffer_for_rs (vlib_main_t * vm, ip6_radv_t * radv_info)
2235{
2236 u32 bi0;
2237 vlib_buffer_t *p0;
2238 vlib_buffer_free_list_t *fl;
2239 icmp6_router_solicitation_header_t *rh;
2240 u16 payload_length;
2241 int bogus_length;
2242 u32 sw_if_index;
2243
2244 sw_if_index = radv_info->sw_if_index;
2245
2246 if (vlib_buffer_alloc (vm, &bi0, 1) != 1)
2247 {
2248 clib_warning ("buffer allocation failure");
2249 return 0;
2250 }
2251
2252 p0 = vlib_get_buffer (vm, bi0);
2253 fl = vlib_buffer_get_free_list (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
2254 vlib_buffer_init_for_free_list (p0, fl);
2255 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (p0);
2256 p0->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
2257
2258 vnet_buffer (p0)->sw_if_index[VLIB_RX] = sw_if_index;
2259 vnet_buffer (p0)->sw_if_index[VLIB_TX] = sw_if_index;
2260
2261 vnet_buffer (p0)->ip.adj_index[VLIB_TX] = radv_info->mcast_adj_index;
2262
2263 rh = vlib_buffer_get_current (p0);
2264 p0->current_length = sizeof (*rh);
2265
2266 rh->neighbor.icmp.type = ICMP6_router_solicitation;
2267 rh->neighbor.icmp.code = 0;
2268 rh->neighbor.icmp.checksum = 0;
2269 rh->neighbor.reserved_must_be_zero = 0;
2270
2271 rh->link_layer_option.header.type =
2272 ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address;
2273 if (0 != get_mac_address (sw_if_index,
2274 rh->link_layer_option.ethernet_address))
2275 {
2276 clib_warning ("interface with sw_if_index %u has no mac address",
2277 sw_if_index);
2278 vlib_buffer_free (vm, &bi0, 1);
2279 return 0;
2280 }
2281 rh->link_layer_option.header.n_data_u64s = 1;
2282
2283 payload_length = sizeof (rh->neighbor) + sizeof (u64);
2284
2285 rh->ip.ip_version_traffic_class_and_flow_label =
2286 clib_host_to_net_u32 (0x6 << 28);
2287 rh->ip.payload_length = clib_host_to_net_u16 (payload_length);
2288 rh->ip.protocol = IP_PROTOCOL_ICMP6;
2289 rh->ip.hop_limit = 255;
2290 rh->ip.src_address = radv_info->link_local_address;
2291 /* set address ff02::2 */
2292 rh->ip.dst_address.as_u64[0] = clib_host_to_net_u64 (0xff02L << 48);
2293 rh->ip.dst_address.as_u64[1] = clib_host_to_net_u64 (2);
2294
2295 rh->neighbor.icmp.checksum = ip6_tcp_udp_icmp_compute_checksum (vm, p0,
2296 &rh->ip,
2297 &bogus_length);
2298
2299 return p0;
2300}
2301
2302static inline void
2303stop_sending_rs (vlib_main_t * vm, ip6_radv_t * ra)
2304{
2305 u32 bi0;
2306
2307 ra->keep_sending_rs = 0;
2308 if (ra->buffer)
2309 {
2310 bi0 = vlib_get_buffer_index (vm, ra->buffer);
2311 vlib_buffer_free (vm, &bi0, 1);
2312 ra->buffer = 0;
2313 }
2314}
2315
2316static inline bool
2317check_send_rs (vlib_main_t * vm, ip6_radv_t * radv_info, f64 current_time,
2318 f64 * due_time)
2319{
2320 vlib_buffer_t *p0;
2321 vlib_frame_t *f;
2322 u32 *to_next;
2323 u32 next_index;
2324 vlib_buffer_t *c0;
2325 u32 ci0;
2326
2327 icmp6_send_router_solicitation_params_t *params;
2328
2329 if (!radv_info->keep_sending_rs)
2330 return false;
2331
2332 params = &radv_info->params;
2333
2334 if (radv_info->due_time > current_time)
2335 {
2336 *due_time = radv_info->due_time;
2337 return true;
2338 }
2339
2340 p0 = radv_info->buffer;
2341
2342 next_index = ip6_rewrite_mcast_node.index;
2343
2344 c0 = vlib_buffer_copy (vm, p0);
2345 ci0 = vlib_get_buffer_index (vm, c0);
2346
2347 f = vlib_get_frame_to_node (vm, next_index);
2348 to_next = vlib_frame_vector_args (f);
2349 to_next[0] = ci0;
2350 f->n_vectors = 1;
2351 vlib_put_frame_to_node (vm, next_index, f);
2352
2353 if (params->mrc != 0 && --radv_info->n_left == 0)
2354 stop_sending_rs (vm, radv_info);
2355 else
2356 {
2357 radv_info->sleep_interval =
2358 (2 + random_f64_from_to (-0.1, 0.1)) * radv_info->sleep_interval;
2359 if (radv_info->sleep_interval > params->mrt)
2360 radv_info->sleep_interval =
2361 (1 + random_f64_from_to (-0.1, 0.1)) * params->mrt;
2362
2363 radv_info->due_time = current_time + radv_info->sleep_interval;
2364
2365 if (params->mrd != 0
2366 && current_time > radv_info->start_time + params->mrd)
2367 stop_sending_rs (vm, radv_info);
2368 else
2369 *due_time = radv_info->due_time;
2370 }
2371
2372 return radv_info->keep_sending_rs;
2373}
2374
2375static uword
2376send_rs_process (vlib_main_t * vm, vlib_node_runtime_t * rt,
2377 vlib_frame_t * f0)
2378{
2379 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
2380 ip6_radv_t *radv_info;
2381 uword *event_data = 0;
2382 f64 sleep_time = 1e9;
2383 f64 current_time;
2384 f64 due_time;
2385 f64 dt = 0;
2386
2387 while (true)
2388 {
2389 vlib_process_wait_for_event_or_clock (vm, sleep_time);
2390 vlib_process_get_events (vm, &event_data);
2391 vec_reset_length (event_data);
2392
2393 current_time = vlib_time_now (vm);
2394 do
2395 {
2396 due_time = current_time + 1e9;
2397 /* *INDENT-OFF* */
2398 pool_foreach (radv_info, nm->if_radv_pool,
2399 ({
2400 if (check_send_rs (vm, radv_info, current_time, &dt)
2401 && (dt < due_time))
2402 due_time = dt;
2403 }));
2404 /* *INDENT-ON* */
2405 current_time = vlib_time_now (vm);
2406 }
2407 while (due_time < current_time);
2408
2409 sleep_time = due_time - current_time;
2410 }
2411
2412 return 0;
2413}
2414
2415/* *INDENT-OFF* */
2416VLIB_REGISTER_NODE (send_rs_process_node) = {
2417 .function = send_rs_process,
2418 .type = VLIB_NODE_TYPE_PROCESS,
2419 .name = "send-rs-process",
2420};
2421/* *INDENT-ON* */
2422
2423void
2424icmp6_send_router_solicitation (vlib_main_t * vm, u32 sw_if_index, u8 stop,
2425 icmp6_send_router_solicitation_params_t *
2426 params)
2427{
2428 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
2429 u32 rai;
2430 ip6_radv_t *ra = 0;
2431
2432 ASSERT (~0 != sw_if_index);
2433
2434 rai = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
2435 ra = pool_elt_at_index (nm->if_radv_pool, rai);
2436
2437 if (stop)
2438 stop_sending_rs (vm, ra);
2439 else
2440 {
2441 ra->keep_sending_rs = 1;
2442 ra->params = *params;
2443 ra->n_left = params->mrc;
2444 ra->start_time = vlib_time_now (vm);
2445 ra->sleep_interval = (1 + random_f64_from_to (-0.1, 0.1)) * params->irt;
2446 ra->due_time = 0; /* send first packet ASAP */
2447 ra->buffer = create_buffer_for_rs (vm, ra);
2448 if (!ra->buffer)
2449 ra->keep_sending_rs = 0;
2450 else
2451 vlib_process_signal_event (vm, send_rs_process_node.index, 1, 0);
2452 }
2453}
2454
Neale Ranns87df12d2017-02-18 08:16:41 -08002455/**
2456 * @brief Add a multicast Address to the advertised MLD set
2457 */
2458static void
2459ip6_neighbor_add_mld_prefix (ip6_radv_t * radv_info, ip6_address_t * addr)
2460{
2461 ip6_mldp_group_t *mcast_group_info;
2462 uword *p;
2463
2464 /* lookup mldp info for this interface */
Neale Rannse0a35442018-02-25 10:39:02 -08002465 p = mhash_get (&radv_info->address_to_mldp_index, addr);
Neale Ranns87df12d2017-02-18 08:16:41 -08002466 mcast_group_info =
2467 p ? pool_elt_at_index (radv_info->mldp_group_pool, p[0]) : 0;
2468
2469 /* add address */
2470 if (!mcast_group_info)
2471 {
2472 /* add */
2473 u32 mi;
2474 pool_get (radv_info->mldp_group_pool, mcast_group_info);
2475
2476 mi = mcast_group_info - radv_info->mldp_group_pool;
Neale Rannse0a35442018-02-25 10:39:02 -08002477 mhash_set (&radv_info->address_to_mldp_index, addr, mi, /* old_value */
Neale Ranns87df12d2017-02-18 08:16:41 -08002478 0);
2479
2480 mcast_group_info->type = 4;
2481 mcast_group_info->mcast_source_address_pool = 0;
2482 mcast_group_info->num_sources = 0;
Neale Rannse0a35442018-02-25 10:39:02 -08002483 clib_memcpy (&mcast_group_info->mcast_address, addr,
Neale Ranns87df12d2017-02-18 08:16:41 -08002484 sizeof (ip6_address_t));
2485 }
2486}
2487
2488/**
2489 * @brief Delete a multicast Address from the advertised MLD set
2490 */
2491static void
2492ip6_neighbor_del_mld_prefix (ip6_radv_t * radv_info, ip6_address_t * addr)
2493{
2494 ip6_mldp_group_t *mcast_group_info;
2495 uword *p;
2496
2497 p = mhash_get (&radv_info->address_to_mldp_index, &addr);
2498 mcast_group_info =
2499 p ? pool_elt_at_index (radv_info->mldp_group_pool, p[0]) : 0;
2500
2501 if (mcast_group_info)
2502 {
2503 mhash_unset (&radv_info->address_to_mldp_index, &addr,
2504 /* old_value */ 0);
2505 pool_put (radv_info->mldp_group_pool, mcast_group_info);
2506 }
2507}
2508
2509/**
2510 * @brief Add a multicast Address to the advertised MLD set
2511 */
2512static void
2513ip6_neighbor_add_mld_grp (ip6_radv_t * a,
2514 ip6_multicast_address_scope_t scope,
2515 ip6_multicast_link_local_group_id_t group)
2516{
2517 ip6_address_t addr;
2518
2519 ip6_set_reserved_multicast_address (&addr, scope, group);
2520
2521 ip6_neighbor_add_mld_prefix (a, &addr);
2522}
2523
2524/**
2525 * @brief create and initialize router advertisement parameters with default
2526 * values for this intfc
2527 */
Pavel Kotucek9f5a2b62017-06-14 13:56:55 +02002528u32
Ed Warnickecb9cada2015-12-08 15:45:58 -07002529ip6_neighbor_sw_interface_add_del (vnet_main_t * vnm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002530 u32 sw_if_index, u32 is_add)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002531{
Dave Barachd7cb1b52016-12-09 09:52:16 -05002532 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
2533 ip6_radv_t *a = 0;
Neale Ranns0bfe5d82016-08-25 15:29:12 +01002534 u32 ri = ~0;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002535 vnet_sw_interface_t *sw_if0;
2536 ethernet_interface_t *eth_if0 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002537
2538 /* lookup radv container - ethernet interfaces only */
2539 sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002540 if (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002541 eth_if0 = ethernet_get_interface (&ethernet_main, sw_if0->hw_if_index);
2542
Dave Barachd7cb1b52016-12-09 09:52:16 -05002543 if (!eth_if0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002544 return ri;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002545
2546 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index,
2547 ~0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002548 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
2549
Dave Barachd7cb1b52016-12-09 09:52:16 -05002550 if (ri != ~0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002551 {
2552 a = pool_elt_at_index (nm->if_radv_pool, ri);
2553
Dave Barachd7cb1b52016-12-09 09:52:16 -05002554 if (!is_add)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002555 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002556 ip6_radv_prefix_t *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002557 ip6_mldp_group_t *m;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002558
Neale Ranns32e1c012016-11-22 17:07:28 +00002559 /* release the lock on the interface's mcast adj */
2560 adj_unlock (a->mcast_adj_index);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002561
Neale Ranns87df12d2017-02-18 08:16:41 -08002562 /* clean up prefix and MDP pools */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002563 /* *INDENT-OFF* */
Neale Ranns87df12d2017-02-18 08:16:41 -08002564 pool_flush(p, a->adv_prefixes_pool,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002565 ({
Ed Warnickecb9cada2015-12-08 15:45:58 -07002566 mhash_unset (&a->address_to_prefix_index, &p->prefix, 0);
Neale Ranns87df12d2017-02-18 08:16:41 -08002567 }));
2568 pool_flush (m, a->mldp_group_pool,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002569 ({
Neale Ranns87df12d2017-02-18 08:16:41 -08002570 mhash_unset (&a->address_to_mldp_index, &m->mcast_address, 0);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002571 }));
2572 /* *INDENT-ON* */
2573
Neale Ranns87df12d2017-02-18 08:16:41 -08002574 pool_free (a->mldp_group_pool);
2575 pool_free (a->adv_prefixes_pool);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002576
Neale Ranns87df12d2017-02-18 08:16:41 -08002577 mhash_free (&a->address_to_prefix_index);
2578 mhash_free (&a->address_to_mldp_index);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002579
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002580 if (a->keep_sending_rs)
2581 a->keep_sending_rs = 0;
2582
Dave Barachd7cb1b52016-12-09 09:52:16 -05002583 pool_put (nm->if_radv_pool, a);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002584 nm->if_radv_pool_index_by_sw_if_index[sw_if_index] = ~0;
2585 ri = ~0;
2586 }
2587 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05002588 else
2589 {
2590 if (is_add)
2591 {
Damjan Marionfe7d4a22018-04-13 19:43:39 +02002592 vnet_hw_interface_t *hw_if0;
2593
2594 hw_if0 = vnet_get_sup_hw_interface (vnm, sw_if_index);
2595
Dave Barachd7cb1b52016-12-09 09:52:16 -05002596 pool_get (nm->if_radv_pool, a);
2597
2598 ri = a - nm->if_radv_pool;
2599 nm->if_radv_pool_index_by_sw_if_index[sw_if_index] = ri;
2600
2601 /* initialize default values (most of which are zero) */
2602 memset (a, 0, sizeof (a[0]));
2603
2604 a->sw_if_index = sw_if_index;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002605 a->max_radv_interval = DEF_MAX_RADV_INTERVAL;
2606 a->min_radv_interval = DEF_MIN_RADV_INTERVAL;
2607 a->curr_hop_limit = DEF_CURR_HOP_LIMIT;
2608 a->adv_router_lifetime_in_sec = DEF_DEF_RTR_LIFETIME;
2609
Neale Ranns87df12d2017-02-18 08:16:41 -08002610 /* send ll address source address option */
2611 a->adv_link_layer_address = 1;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002612
2613 a->min_delay_between_radv = MIN_DELAY_BETWEEN_RAS;
2614 a->max_delay_between_radv = MAX_DELAY_BETWEEN_RAS;
2615 a->max_rtr_default_lifetime = MAX_DEF_RTR_LIFETIME;
2616 a->seed = (u32) clib_cpu_time_now ();
2617 (void) random_u32 (&a->seed);
2618 a->randomizer = clib_cpu_time_now ();
2619 (void) random_u64 (&a->randomizer);
2620
2621 a->initial_adverts_count = MAX_INITIAL_RTR_ADVERTISEMENTS;
2622 a->initial_adverts_sent = a->initial_adverts_count - 1;
2623 a->initial_adverts_interval = MAX_INITIAL_RTR_ADVERT_INTERVAL;
2624
2625 /* deafult is to send */
2626 a->send_radv = 1;
2627
2628 /* fill in radv_info for this interface that will be needed later */
Damjan Marionfe7d4a22018-04-13 19:43:39 +02002629 a->adv_link_mtu = hw_if0->max_l3_packet_bytes[VLIB_RX];
Dave Barachd7cb1b52016-12-09 09:52:16 -05002630
2631 clib_memcpy (a->link_layer_address, eth_if0->address, 6);
2632
2633 /* fill in default link-local address (this may be overridden) */
2634 ip6_link_local_address_from_ethernet_address
2635 (&a->link_local_address, eth_if0->address);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002636
2637 mhash_init (&a->address_to_prefix_index, sizeof (uword),
2638 sizeof (ip6_address_t));
2639 mhash_init (&a->address_to_mldp_index, sizeof (uword),
2640 sizeof (ip6_address_t));
2641
Neale Ranns32e1c012016-11-22 17:07:28 +00002642 a->mcast_adj_index = adj_mcast_add_or_lock (FIB_PROTOCOL_IP6,
2643 VNET_LINK_IP6,
2644 sw_if_index);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002645
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01002646 a->keep_sending_rs = 0;
2647
Dave Barachd7cb1b52016-12-09 09:52:16 -05002648 /* add multicast groups we will always be reporting */
Neale Ranns87df12d2017-02-18 08:16:41 -08002649 ip6_neighbor_add_mld_grp (a,
2650 IP6_MULTICAST_SCOPE_link_local,
2651 IP6_MULTICAST_GROUP_ID_all_hosts);
2652 ip6_neighbor_add_mld_grp (a,
2653 IP6_MULTICAST_SCOPE_link_local,
2654 IP6_MULTICAST_GROUP_ID_all_routers);
2655 ip6_neighbor_add_mld_grp (a,
2656 IP6_MULTICAST_SCOPE_link_local,
2657 IP6_MULTICAST_GROUP_ID_mldv2_routers);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002658 }
2659 }
2660 return ri;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002661}
2662
2663/* send an mldpv2 report */
2664static void
Dave Barachd7cb1b52016-12-09 09:52:16 -05002665ip6_neighbor_send_mldpv2_report (u32 sw_if_index)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002666{
Dave Barachd7cb1b52016-12-09 09:52:16 -05002667 vnet_main_t *vnm = vnet_get_main ();
2668 vlib_main_t *vm = vnm->vlib_main;
2669 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
2670 vnet_sw_interface_t *sw_if0;
2671 ethernet_interface_t *eth_if0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002672 u32 ri;
2673 int bogus_length;
2674
Dave Barachd7cb1b52016-12-09 09:52:16 -05002675 ip6_radv_t *radv_info;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002676 u16 payload_length;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002677 vlib_buffer_t *b0;
2678 ip6_header_t *ip0;
2679 u32 *to_next;
2680 vlib_frame_t *f;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002681 u32 bo0;
2682 u32 n_to_alloc = 1;
2683 u32 n_allocated;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002684
Ed Warnickecb9cada2015-12-08 15:45:58 -07002685 icmp6_multicast_listener_report_header_t *rh0;
2686 icmp6_multicast_listener_report_packet_t *rp0;
2687
2688 sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index);
2689 ASSERT (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE);
2690 eth_if0 = ethernet_get_interface (&ethernet_main, sw_if0->hw_if_index);
2691
2692 if (!eth_if0 || !vnet_sw_interface_is_admin_up (vnm, sw_if_index))
2693 return;
2694
2695 /* look up the radv_t information for this interface */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002696 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index,
2697 ~0);
2698
Ed Warnickecb9cada2015-12-08 15:45:58 -07002699 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
Dave Barachd7cb1b52016-12-09 09:52:16 -05002700
2701 if (ri == ~0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002702 return;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002703
Ed Warnickecb9cada2015-12-08 15:45:58 -07002704 /* send report now - build a mldpv2 report packet */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002705 n_allocated = vlib_buffer_alloc_from_free_list (vm,
2706 &bo0,
2707 n_to_alloc,
2708 VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
2709 if (PREDICT_FALSE (n_allocated == 0))
Ed Warnickecb9cada2015-12-08 15:45:58 -07002710 {
2711 clib_warning ("buffer allocation failure");
2712 return;
2713 }
2714
2715 b0 = vlib_get_buffer (vm, bo0);
2716
2717 /* adjust the sizeof the buffer to just include the ipv6 header */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002718 b0->current_length = sizeof (icmp6_multicast_listener_report_packet_t);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002719
Dave Barachd7cb1b52016-12-09 09:52:16 -05002720 payload_length = sizeof (icmp6_multicast_listener_report_header_t);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002721
2722 b0->error = ICMP6_ERROR_NONE;
2723
2724 rp0 = vlib_buffer_get_current (b0);
Dave Barachd7cb1b52016-12-09 09:52:16 -05002725 ip0 = (ip6_header_t *) & rp0->ip;
2726 rh0 = (icmp6_multicast_listener_report_header_t *) & rp0->report_hdr;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002727
Dave Barachd7cb1b52016-12-09 09:52:16 -05002728 memset (rp0, 0x0, sizeof (icmp6_multicast_listener_report_packet_t));
2729
2730 ip0->ip_version_traffic_class_and_flow_label =
2731 clib_host_to_net_u32 (0x6 << 28);
2732
2733 ip0->protocol = IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002734 /* for DEBUG - vnet driver won't seem to emit router alerts */
2735 /* ip0->protocol = IP_PROTOCOL_ICMP6; */
2736 ip0->hop_limit = 1;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002737
Ed Warnickecb9cada2015-12-08 15:45:58 -07002738 rh0->icmp.type = ICMP6_multicast_listener_report_v2;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002739
Ed Warnickecb9cada2015-12-08 15:45:58 -07002740 /* source address MUST be the link-local address */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002741 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
2742 ip0->src_address = radv_info->link_local_address;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002743
2744 /* destination is all mldpv2 routers */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002745 ip6_set_reserved_multicast_address (&ip0->dst_address,
2746 IP6_MULTICAST_SCOPE_link_local,
2747 IP6_MULTICAST_GROUP_ID_mldv2_routers);
2748
Ed Warnickecb9cada2015-12-08 15:45:58 -07002749 /* add reports here */
2750 ip6_mldp_group_t *m;
2751 int num_addr_records = 0;
2752 icmp6_multicast_address_record_t rr;
2753
2754 /* fill in the hop-by-hop extension header (router alert) info */
2755 rh0->ext_hdr.next_hdr = IP_PROTOCOL_ICMP6;
2756 rh0->ext_hdr.n_data_u64s = 0;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002757
Ed Warnickecb9cada2015-12-08 15:45:58 -07002758 rh0->alert.type = IP6_MLDP_ALERT_TYPE;
2759 rh0->alert.len = 2;
2760 rh0->alert.value = 0;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002761
Ed Warnickecb9cada2015-12-08 15:45:58 -07002762 rh0->pad.type = 1;
2763 rh0->pad.len = 0;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002764
Ed Warnickecb9cada2015-12-08 15:45:58 -07002765 rh0->icmp.checksum = 0;
2766
Dave Barachd7cb1b52016-12-09 09:52:16 -05002767 /* *INDENT-OFF* */
2768 pool_foreach (m, radv_info->mldp_group_pool,
2769 ({
2770 rr.type = m->type;
2771 rr.aux_data_len_u32s = 0;
2772 rr.num_sources = clib_host_to_net_u16 (m->num_sources);
2773 clib_memcpy(&rr.mcast_addr, &m->mcast_address, sizeof(ip6_address_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -07002774
Dave Barachd7cb1b52016-12-09 09:52:16 -05002775 num_addr_records++;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002776
Dave Barachd7cb1b52016-12-09 09:52:16 -05002777 vlib_buffer_add_data
Damjan Marion072401e2017-07-13 18:53:27 +02002778 (vm, vlib_buffer_get_free_list_index (b0), bo0,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002779 (void *)&rr, sizeof(icmp6_multicast_address_record_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -07002780
Dave Barachd7cb1b52016-12-09 09:52:16 -05002781 payload_length += sizeof( icmp6_multicast_address_record_t);
2782 }));
2783 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07002784
2785 rh0->rsvd = 0;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002786 rh0->num_addr_records = clib_host_to_net_u16 (num_addr_records);
2787
Ed Warnickecb9cada2015-12-08 15:45:58 -07002788 /* update lengths */
2789 ip0->payload_length = clib_host_to_net_u16 (payload_length);
2790
Dave Barachd7cb1b52016-12-09 09:52:16 -05002791 rh0->icmp.checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip0,
2792 &bogus_length);
2793 ASSERT (bogus_length == 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002794
Dave Barachd7cb1b52016-12-09 09:52:16 -05002795 /*
Ed Warnickecb9cada2015-12-08 15:45:58 -07002796 * OK to override w/ no regard for actual FIB, because
Neale Rannsf06aea52016-11-29 06:51:37 -08002797 * ip6-rewrite only looks at the adjacency.
Ed Warnickecb9cada2015-12-08 15:45:58 -07002798 */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002799 vnet_buffer (b0)->sw_if_index[VLIB_RX] =
Ed Warnickecb9cada2015-12-08 15:45:58 -07002800 vnet_main.local_interface_sw_if_index;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002801
Neale Ranns32e1c012016-11-22 17:07:28 +00002802 vnet_buffer (b0)->ip.adj_index[VLIB_TX] = radv_info->mcast_adj_index;
Damjan Marion213b5aa2017-07-13 21:19:27 +02002803 b0->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002804
Neale Ranns32e1c012016-11-22 17:07:28 +00002805 vlib_node_t *node = vlib_get_node_by_name (vm, (u8 *) "ip6-rewrite-mcast");
Dave Barachd7cb1b52016-12-09 09:52:16 -05002806
Ed Warnickecb9cada2015-12-08 15:45:58 -07002807 f = vlib_get_frame_to_node (vm, node->index);
2808 to_next = vlib_frame_vector_args (f);
2809 to_next[0] = bo0;
2810 f->n_vectors = 1;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002811
Ed Warnickecb9cada2015-12-08 15:45:58 -07002812 vlib_put_frame_to_node (vm, node->index, f);
2813 return;
2814}
2815
Dave Barachd7cb1b52016-12-09 09:52:16 -05002816/* *INDENT-OFF* */
2817VLIB_REGISTER_NODE (ip6_icmp_router_solicitation_node,static) =
2818{
Ed Warnickecb9cada2015-12-08 15:45:58 -07002819 .function = icmp6_router_solicitation,
2820 .name = "icmp6-router-solicitation",
2821
2822 .vector_size = sizeof (u32),
2823
2824 .format_trace = format_icmp6_input_trace,
2825
2826 .n_next_nodes = ICMP6_ROUTER_SOLICITATION_N_NEXT,
2827 .next_nodes = {
Vijayabhaskar Katamreddyce074122017-11-15 13:50:26 -08002828 [ICMP6_ROUTER_SOLICITATION_NEXT_DROP] = "ip6-drop",
Neale Ranns32e1c012016-11-22 17:07:28 +00002829 [ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_RW] = "ip6-rewrite-mcast",
Ed Warnickecb9cada2015-12-08 15:45:58 -07002830 [ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_TX] = "interface-output",
2831 },
2832};
Dave Barachd7cb1b52016-12-09 09:52:16 -05002833/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07002834
2835/* send a RA or update the timer info etc.. */
2836static uword
2837ip6_neighbor_process_timer_event (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05002838 vlib_node_runtime_t * node,
2839 vlib_frame_t * frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002840{
Dave Barachd7cb1b52016-12-09 09:52:16 -05002841 vnet_main_t *vnm = vnet_get_main ();
2842 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
2843 ip6_radv_t *radv_info;
2844 vlib_frame_t *f = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002845 u32 n_this_frame = 0;
Benoît Ganned5304452016-04-08 22:25:05 -07002846 u32 n_left_to_next = 0;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002847 u32 *to_next = 0;
2848 u32 bo0;
2849 icmp6_router_solicitation_header_t *h0;
2850 vlib_buffer_t *b0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002851 f64 now = vlib_time_now (vm);
2852
2853 /* Interface ip6 radv info list */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002854 /* *INDENT-OFF* */
2855 pool_foreach (radv_info, nm->if_radv_pool,
2856 ({
2857 if( !vnet_sw_interface_is_admin_up (vnm, radv_info->sw_if_index))
2858 {
2859 radv_info->initial_adverts_sent = radv_info->initial_adverts_count-1;
2860 radv_info->next_multicast_time = now;
2861 radv_info->last_multicast_time = now;
2862 radv_info->last_radv_time = 0;
2863 radv_info->all_routers_mcast = 0;
2864 continue;
2865 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07002866
Dave Barachd7cb1b52016-12-09 09:52:16 -05002867 /* Make sure that we've joined the all-routers multicast group */
2868 if(!radv_info->all_routers_mcast)
2869 {
2870 /* send MDLP_REPORT_EVENT message */
2871 ip6_neighbor_send_mldpv2_report(radv_info->sw_if_index);
2872 radv_info->all_routers_mcast = 1;
2873 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07002874
Dave Barachd7cb1b52016-12-09 09:52:16 -05002875 /* is it time to send a multicast RA on this interface? */
2876 if(radv_info->send_radv && (now >= radv_info->next_multicast_time))
2877 {
2878 u32 n_to_alloc = 1;
2879 u32 n_allocated;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002880
Dave Barachd7cb1b52016-12-09 09:52:16 -05002881 f64 rfn = (radv_info->max_radv_interval - radv_info->min_radv_interval) *
2882 random_f64 (&radv_info->seed) + radv_info->min_radv_interval;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002883
Dave Barachd7cb1b52016-12-09 09:52:16 -05002884 /* multicast send - compute next multicast send time */
2885 if( radv_info->initial_adverts_sent > 0)
2886 {
2887 radv_info->initial_adverts_sent--;
2888 if(rfn > radv_info-> initial_adverts_interval)
2889 rfn = radv_info-> initial_adverts_interval;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002890
Dave Barachd7cb1b52016-12-09 09:52:16 -05002891 /* check to see if we are ceasing to send */
2892 if( radv_info->initial_adverts_sent == 0)
2893 if(radv_info->cease_radv)
2894 radv_info->send_radv = 0;
2895 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07002896
Dave Barachd7cb1b52016-12-09 09:52:16 -05002897 radv_info->next_multicast_time = rfn + now;
2898 radv_info->last_multicast_time = now;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002899
Dave Barachd7cb1b52016-12-09 09:52:16 -05002900 /* send advert now - build a "solicted" router advert with unspecified source address */
2901 n_allocated = vlib_buffer_alloc_from_free_list
2902 (vm, &bo0, n_to_alloc, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002903
Dave Barachd7cb1b52016-12-09 09:52:16 -05002904 if (PREDICT_FALSE(n_allocated == 0))
2905 {
2906 clib_warning ("buffer allocation failure");
2907 continue;
2908 }
2909 b0 = vlib_get_buffer (vm, bo0);
2910 b0->current_length = sizeof( icmp6_router_solicitation_header_t);
2911 b0->error = ICMP6_ERROR_NONE;
2912 vnet_buffer (b0)->sw_if_index[VLIB_RX] = radv_info->sw_if_index;
2913
2914 h0 = vlib_buffer_get_current (b0);
2915
2916 memset (h0, 0, sizeof (icmp6_router_solicitation_header_t));
2917
2918 h0->ip.ip_version_traffic_class_and_flow_label = clib_host_to_net_u32 (0x6 << 28);
2919 h0->ip.payload_length = clib_host_to_net_u16 (sizeof (icmp6_router_solicitation_header_t)
2920 - STRUCT_OFFSET_OF (icmp6_router_solicitation_header_t, neighbor));
2921 h0->ip.protocol = IP_PROTOCOL_ICMP6;
2922 h0->ip.hop_limit = 255;
2923
2924 /* set src/dst address as "unspecified" this marks this packet as internally generated rather than recieved */
2925 h0->ip.src_address.as_u64[0] = 0;
2926 h0->ip.src_address.as_u64[1] = 0;
2927
2928 h0->ip.dst_address.as_u64[0] = 0;
2929 h0->ip.dst_address.as_u64[1] = 0;
2930
2931 h0->neighbor.icmp.type = ICMP6_router_solicitation;
2932
2933 if (PREDICT_FALSE(f == 0))
2934 {
2935 f = vlib_get_frame_to_node (vm, ip6_icmp_router_solicitation_node.index);
2936 to_next = vlib_frame_vector_args (f);
2937 n_left_to_next = VLIB_FRAME_SIZE;
2938 n_this_frame = 0;
2939 }
2940
2941 n_this_frame++;
2942 n_left_to_next--;
2943 to_next[0] = bo0;
2944 to_next += 1;
2945
2946 if (PREDICT_FALSE(n_left_to_next == 0))
2947 {
2948 f->n_vectors = n_this_frame;
2949 vlib_put_frame_to_node (vm, ip6_icmp_router_solicitation_node.index, f);
2950 f = 0;
2951 }
2952 }
2953 }));
2954 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07002955
2956 if (f)
2957 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002958 ASSERT (n_this_frame);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002959 f->n_vectors = n_this_frame;
2960 vlib_put_frame_to_node (vm, ip6_icmp_router_solicitation_node.index, f);
2961 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05002962 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002963}
2964
2965static uword
2966ip6_icmp_neighbor_discovery_event_process (vlib_main_t * vm,
2967 vlib_node_runtime_t * node,
2968 vlib_frame_t * frame)
2969{
2970 uword event_type;
Dave Barachd7cb1b52016-12-09 09:52:16 -05002971 ip6_icmp_neighbor_discovery_event_data_t *event_data;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002972
2973 /* init code here */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002974
Ed Warnickecb9cada2015-12-08 15:45:58 -07002975 while (1)
2976 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002977 vlib_process_wait_for_event_or_clock (vm, 1. /* seconds */ );
Ed Warnickecb9cada2015-12-08 15:45:58 -07002978
Dave Barachd7cb1b52016-12-09 09:52:16 -05002979 event_data = vlib_process_get_event_data (vm, &event_type);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002980
Dave Barachd7cb1b52016-12-09 09:52:16 -05002981 if (!event_data)
Ed Warnickecb9cada2015-12-08 15:45:58 -07002982 {
2983 /* No events found: timer expired. */
2984 /* process interface list and send RAs as appropriate, update timer info */
Dave Barachd7cb1b52016-12-09 09:52:16 -05002985 ip6_neighbor_process_timer_event (vm, node, frame);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002986 }
2987 else
2988 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05002989 switch (event_type)
2990 {
Ed Warnickecb9cada2015-12-08 15:45:58 -07002991
Dave Barachd7cb1b52016-12-09 09:52:16 -05002992 case ICMP6_ND_EVENT_INIT:
2993 break;
2994
2995 case ~0:
2996 break;
2997
2998 default:
2999 ASSERT (0);
3000 }
3001
Ed Warnickecb9cada2015-12-08 15:45:58 -07003002 if (event_data)
3003 _vec_len (event_data) = 0;
3004 }
3005 }
3006 return frame->n_vectors;
3007}
3008
Dave Barachd7cb1b52016-12-09 09:52:16 -05003009/* *INDENT-OFF* */
3010VLIB_REGISTER_NODE (ip6_icmp_router_advertisement_node,static) =
3011{
Ed Warnickecb9cada2015-12-08 15:45:58 -07003012 .function = icmp6_router_advertisement,
3013 .name = "icmp6-router-advertisement",
3014
3015 .vector_size = sizeof (u32),
3016
3017 .format_trace = format_icmp6_input_trace,
3018
3019 .n_next_nodes = 1,
3020 .next_nodes = {
Vijayabhaskar Katamreddyce074122017-11-15 13:50:26 -08003021 [0] = "ip6-drop",
Ed Warnickecb9cada2015-12-08 15:45:58 -07003022 },
3023};
Dave Barachd7cb1b52016-12-09 09:52:16 -05003024/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07003025
3026vlib_node_registration_t ip6_icmp_neighbor_discovery_event_node = {
3027
3028 .function = ip6_icmp_neighbor_discovery_event_process,
3029 .name = "ip6-icmp-neighbor-discovery-event-process",
3030 .type = VLIB_NODE_TYPE_PROCESS,
3031};
3032
3033static uword
3034icmp6_neighbor_solicitation (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05003035 vlib_node_runtime_t * node, vlib_frame_t * frame)
3036{
3037 return icmp6_neighbor_solicitation_or_advertisement (vm, node, frame,
3038 /* is_solicitation */
3039 1);
3040}
Ed Warnickecb9cada2015-12-08 15:45:58 -07003041
3042static uword
3043icmp6_neighbor_advertisement (vlib_main_t * vm,
3044 vlib_node_runtime_t * node,
3045 vlib_frame_t * frame)
Dave Barachd7cb1b52016-12-09 09:52:16 -05003046{
3047 return icmp6_neighbor_solicitation_or_advertisement (vm, node, frame,
3048 /* is_solicitation */
3049 0);
3050}
Ed Warnickecb9cada2015-12-08 15:45:58 -07003051
Dave Barachd7cb1b52016-12-09 09:52:16 -05003052/* *INDENT-OFF* */
3053VLIB_REGISTER_NODE (ip6_icmp_neighbor_solicitation_node,static) =
3054{
Ed Warnickecb9cada2015-12-08 15:45:58 -07003055 .function = icmp6_neighbor_solicitation,
3056 .name = "icmp6-neighbor-solicitation",
3057
3058 .vector_size = sizeof (u32),
3059
3060 .format_trace = format_icmp6_input_trace,
3061
3062 .n_next_nodes = ICMP6_NEIGHBOR_SOLICITATION_N_NEXT,
3063 .next_nodes = {
Vijayabhaskar Katamreddyce074122017-11-15 13:50:26 -08003064 [ICMP6_NEIGHBOR_SOLICITATION_NEXT_DROP] = "ip6-drop",
Ed Warnickecb9cada2015-12-08 15:45:58 -07003065 [ICMP6_NEIGHBOR_SOLICITATION_NEXT_REPLY] = "interface-output",
3066 },
3067};
Dave Barachd7cb1b52016-12-09 09:52:16 -05003068/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07003069
Dave Barachd7cb1b52016-12-09 09:52:16 -05003070/* *INDENT-OFF* */
3071VLIB_REGISTER_NODE (ip6_icmp_neighbor_advertisement_node,static) =
3072{
Ed Warnickecb9cada2015-12-08 15:45:58 -07003073 .function = icmp6_neighbor_advertisement,
3074 .name = "icmp6-neighbor-advertisement",
3075
3076 .vector_size = sizeof (u32),
3077
3078 .format_trace = format_icmp6_input_trace,
3079
3080 .n_next_nodes = 1,
3081 .next_nodes = {
Vijayabhaskar Katamreddyce074122017-11-15 13:50:26 -08003082 [0] = "ip6-drop",
Ed Warnickecb9cada2015-12-08 15:45:58 -07003083 },
3084};
Dave Barachd7cb1b52016-12-09 09:52:16 -05003085/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07003086
Neale Rannsc7b8f202018-04-25 06:34:31 -07003087typedef enum
3088{
3089 IP6_DISCOVER_NEIGHBOR_NEXT_DROP,
3090 IP6_DISCOVER_NEIGHBOR_NEXT_REPLY_TX,
3091 IP6_DISCOVER_NEIGHBOR_N_NEXT,
3092} ip6_discover_neighbor_next_t;
3093
3094typedef enum
3095{
3096 IP6_DISCOVER_NEIGHBOR_ERROR_DROP,
3097 IP6_DISCOVER_NEIGHBOR_ERROR_REQUEST_SENT,
3098 IP6_DISCOVER_NEIGHBOR_ERROR_NO_SOURCE_ADDRESS,
3099} ip6_discover_neighbor_error_t;
3100
3101static uword
3102ip6_discover_neighbor_inline (vlib_main_t * vm,
3103 vlib_node_runtime_t * node,
3104 vlib_frame_t * frame, int is_glean)
3105{
3106 vnet_main_t *vnm = vnet_get_main ();
3107 ip6_main_t *im = &ip6_main;
3108 ip_lookup_main_t *lm = &im->lookup_main;
3109 u32 *from, *to_next_drop;
3110 uword n_left_from, n_left_to_next_drop;
3111 static f64 time_last_seed_change = -1e100;
3112 static u32 hash_seeds[3];
3113 static uword hash_bitmap[256 / BITS (uword)];
3114 f64 time_now;
3115 int bogus_length;
3116 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
3117
3118 if (node->flags & VLIB_NODE_FLAG_TRACE)
3119 ip6_forward_next_trace (vm, node, frame, VLIB_TX);
3120
3121 time_now = vlib_time_now (vm);
3122 if (time_now - time_last_seed_change > 1e-3)
3123 {
3124 uword i;
3125 u32 *r = clib_random_buffer_get_data (&vm->random_buffer,
3126 sizeof (hash_seeds));
3127 for (i = 0; i < ARRAY_LEN (hash_seeds); i++)
3128 hash_seeds[i] = r[i];
3129
3130 /* Mark all hash keys as been not-seen before. */
3131 for (i = 0; i < ARRAY_LEN (hash_bitmap); i++)
3132 hash_bitmap[i] = 0;
3133
3134 time_last_seed_change = time_now;
3135 }
3136
3137 from = vlib_frame_vector_args (frame);
3138 n_left_from = frame->n_vectors;
3139
3140 while (n_left_from > 0)
3141 {
3142 vlib_get_next_frame (vm, node, IP6_DISCOVER_NEIGHBOR_NEXT_DROP,
3143 to_next_drop, n_left_to_next_drop);
3144
3145 while (n_left_from > 0 && n_left_to_next_drop > 0)
3146 {
3147 vlib_buffer_t *p0;
3148 ip6_header_t *ip0;
3149 u32 pi0, adj_index0, a0, b0, c0, m0, sw_if_index0, drop0;
3150 uword bm0;
3151 ip_adjacency_t *adj0;
3152 vnet_hw_interface_t *hw_if0;
3153 ip6_radv_t *radv_info;
3154 u32 next0;
3155
3156 pi0 = from[0];
3157
3158 p0 = vlib_get_buffer (vm, pi0);
3159
3160 adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
3161
3162 ip0 = vlib_buffer_get_current (p0);
3163
3164 adj0 = adj_get (adj_index0);
3165
3166 if (!is_glean)
3167 {
3168 ip0->dst_address.as_u64[0] =
3169 adj0->sub_type.nbr.next_hop.ip6.as_u64[0];
3170 ip0->dst_address.as_u64[1] =
3171 adj0->sub_type.nbr.next_hop.ip6.as_u64[1];
3172 }
3173
3174 a0 = hash_seeds[0];
3175 b0 = hash_seeds[1];
3176 c0 = hash_seeds[2];
3177
3178 sw_if_index0 = adj0->rewrite_header.sw_if_index;
3179 vnet_buffer (p0)->sw_if_index[VLIB_TX] = sw_if_index0;
3180
3181 a0 ^= sw_if_index0;
3182 b0 ^= ip0->dst_address.as_u32[0];
3183 c0 ^= ip0->dst_address.as_u32[1];
3184
3185 hash_v3_mix32 (a0, b0, c0);
3186
3187 b0 ^= ip0->dst_address.as_u32[2];
3188 c0 ^= ip0->dst_address.as_u32[3];
3189
3190 hash_v3_finalize32 (a0, b0, c0);
3191
3192 c0 &= BITS (hash_bitmap) - 1;
3193 c0 = c0 / BITS (uword);
3194 m0 = (uword) 1 << (c0 % BITS (uword));
3195
3196 bm0 = hash_bitmap[c0];
3197 drop0 = (bm0 & m0) != 0;
3198
3199 /* Mark it as seen. */
3200 hash_bitmap[c0] = bm0 | m0;
3201
3202 from += 1;
3203 n_left_from -= 1;
3204 to_next_drop[0] = pi0;
3205 to_next_drop += 1;
3206 n_left_to_next_drop -= 1;
3207
3208 hw_if0 = vnet_get_sup_hw_interface (vnm, sw_if_index0);
3209
3210 /* If the interface is link-down, drop the pkt */
3211 if (!(hw_if0->flags & VNET_HW_INTERFACE_FLAG_LINK_UP))
3212 drop0 = 1;
3213
3214 if (vec_len (nm->if_radv_pool_index_by_sw_if_index) > sw_if_index0)
3215 {
3216 u32 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index0];
3217
3218 if (ri != ~0)
3219 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
3220 else
3221 drop0 = 1;
3222 }
3223 else
3224 drop0 = 1;
3225
3226 /*
3227 * the adj has been updated to a rewrite but the node the DPO that got
3228 * us here hasn't - yet. no big deal. we'll drop while we wait.
3229 */
3230 if (IP_LOOKUP_NEXT_REWRITE == adj0->lookup_next_index)
3231 drop0 = 1;
3232
3233 p0->error =
3234 node->errors[drop0 ? IP6_DISCOVER_NEIGHBOR_ERROR_DROP
3235 : IP6_DISCOVER_NEIGHBOR_ERROR_REQUEST_SENT];
3236
3237 if (drop0)
3238 continue;
3239
3240 {
3241 u32 bi0 = 0;
3242 icmp6_neighbor_solicitation_header_t *h0;
3243 vlib_buffer_t *b0;
3244
3245 h0 = vlib_packet_template_get_packet
3246 (vm, &im->discover_neighbor_packet_template, &bi0);
3247
3248 /*
3249 * Build ethernet header.
3250 * Choose source address based on destination lookup
3251 * adjacency.
3252 */
3253 if (!ip6_src_address_for_packet (lm,
3254 sw_if_index0,
3255 &ip0->dst_address,
3256 &h0->ip.src_address))
3257 {
3258 /* There is no address on the interface */
3259 p0->error =
3260 node->errors[IP6_DISCOVER_NEIGHBOR_ERROR_NO_SOURCE_ADDRESS];
3261 vlib_buffer_free (vm, &bi0, 1);
3262 continue;
3263 }
3264
3265 /*
3266 * Destination address is a solicited node multicast address.
3267 * We need to fill in
3268 * the low 24 bits with low 24 bits of target's address.
3269 */
3270 h0->ip.dst_address.as_u8[13] = ip0->dst_address.as_u8[13];
3271 h0->ip.dst_address.as_u8[14] = ip0->dst_address.as_u8[14];
3272 h0->ip.dst_address.as_u8[15] = ip0->dst_address.as_u8[15];
3273
3274 h0->neighbor.target_address = ip0->dst_address;
3275
3276 clib_memcpy (h0->link_layer_option.ethernet_address,
3277 hw_if0->hw_address, vec_len (hw_if0->hw_address));
3278
3279 /* $$$$ appears we need this; why is the checksum non-zero? */
3280 h0->neighbor.icmp.checksum = 0;
3281 h0->neighbor.icmp.checksum =
3282 ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h0->ip,
3283 &bogus_length);
3284
3285 ASSERT (bogus_length == 0);
3286
3287 vlib_buffer_copy_trace_flag (vm, p0, bi0);
3288 b0 = vlib_get_buffer (vm, bi0);
3289 vnet_buffer (b0)->sw_if_index[VLIB_TX]
3290 = vnet_buffer (p0)->sw_if_index[VLIB_TX];
3291
3292 vnet_buffer (b0)->ip.adj_index[VLIB_TX] =
3293 radv_info->mcast_adj_index;
3294
3295 b0->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
3296 next0 = IP6_DISCOVER_NEIGHBOR_NEXT_REPLY_TX;
3297
3298 vlib_set_next_frame_buffer (vm, node, next0, bi0);
3299 }
3300 }
3301
3302 vlib_put_next_frame (vm, node, IP6_DISCOVER_NEIGHBOR_NEXT_DROP,
3303 n_left_to_next_drop);
3304 }
3305
3306 return frame->n_vectors;
3307}
3308
3309static uword
3310ip6_discover_neighbor (vlib_main_t * vm,
3311 vlib_node_runtime_t * node, vlib_frame_t * frame)
3312{
3313 return (ip6_discover_neighbor_inline (vm, node, frame, 0));
3314}
3315
3316static uword
3317ip6_glean (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
3318{
3319 return (ip6_discover_neighbor_inline (vm, node, frame, 1));
3320}
3321
3322static char *ip6_discover_neighbor_error_strings[] = {
3323 [IP6_DISCOVER_NEIGHBOR_ERROR_DROP] = "address overflow drops",
3324 [IP6_DISCOVER_NEIGHBOR_ERROR_REQUEST_SENT] = "neighbor solicitations sent",
3325 [IP6_DISCOVER_NEIGHBOR_ERROR_NO_SOURCE_ADDRESS]
3326 = "no source address for ND solicitation",
3327};
3328
3329/* *INDENT-OFF* */
3330VLIB_REGISTER_NODE (ip6_glean_node) =
3331{
3332 .function = ip6_glean,
3333 .name = "ip6-glean",
3334 .vector_size = sizeof (u32),
3335 .format_trace = format_ip6_forward_next_trace,
3336 .n_errors = ARRAY_LEN (ip6_discover_neighbor_error_strings),
3337 .error_strings = ip6_discover_neighbor_error_strings,
3338 .n_next_nodes = IP6_DISCOVER_NEIGHBOR_N_NEXT,
3339 .next_nodes =
3340 {
3341 [IP6_DISCOVER_NEIGHBOR_NEXT_DROP] = "ip6-drop",
3342 [IP6_DISCOVER_NEIGHBOR_NEXT_REPLY_TX] = "ip6-rewrite-mcast",
3343 },
3344};
3345VLIB_REGISTER_NODE (ip6_discover_neighbor_node) =
3346{
3347 .function = ip6_discover_neighbor,
3348 .name = "ip6-discover-neighbor",
3349 .vector_size = sizeof (u32),
3350 .format_trace = format_ip6_forward_next_trace,
3351 .n_errors = ARRAY_LEN (ip6_discover_neighbor_error_strings),
3352 .error_strings = ip6_discover_neighbor_error_strings,
3353 .n_next_nodes = IP6_DISCOVER_NEIGHBOR_N_NEXT,
3354 .next_nodes =
3355 {
3356 [IP6_DISCOVER_NEIGHBOR_NEXT_DROP] = "ip6-drop",
3357 [IP6_DISCOVER_NEIGHBOR_NEXT_REPLY_TX] = "ip6-rewrite-mcast",
3358 },
3359};
3360/* *INDENT-ON* */
3361
Dave Barachd7cb1b52016-12-09 09:52:16 -05003362/* API support functions */
Ed Warnickecb9cada2015-12-08 15:45:58 -07003363int
Dave Barachd7cb1b52016-12-09 09:52:16 -05003364ip6_neighbor_ra_config (vlib_main_t * vm, u32 sw_if_index,
3365 u8 suppress, u8 managed, u8 other,
3366 u8 ll_option, u8 send_unicast, u8 cease,
3367 u8 use_lifetime, u32 lifetime,
3368 u32 initial_count, u32 initial_interval,
3369 u32 max_interval, u32 min_interval, u8 is_no)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003370{
Dave Barachd7cb1b52016-12-09 09:52:16 -05003371 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
3372 int error;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003373 u32 ri;
3374
3375 /* look up the radv_t information for this interface */
Dave Barachd7cb1b52016-12-09 09:52:16 -05003376 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index,
3377 ~0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003378 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
Dave Barachd7cb1b52016-12-09 09:52:16 -05003379 error = (ri != ~0) ? 0 : VNET_API_ERROR_INVALID_SW_IF_INDEX;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003380
Dave Barachd7cb1b52016-12-09 09:52:16 -05003381 if (!error)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003382 {
3383
Dave Barachd7cb1b52016-12-09 09:52:16 -05003384 ip6_radv_t *radv_info;
3385 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003386
Dave Barachd7cb1b52016-12-09 09:52:16 -05003387 if ((max_interval != 0) && (min_interval == 0))
3388 min_interval = .75 * max_interval;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003389
Dave Barachd7cb1b52016-12-09 09:52:16 -05003390 max_interval =
3391 (max_interval !=
3392 0) ? ((is_no) ? DEF_MAX_RADV_INTERVAL : max_interval) :
3393 radv_info->max_radv_interval;
3394 min_interval =
3395 (min_interval !=
3396 0) ? ((is_no) ? DEF_MIN_RADV_INTERVAL : min_interval) :
3397 radv_info->min_radv_interval;
3398 lifetime =
3399 (use_lifetime !=
3400 0) ? ((is_no) ? DEF_DEF_RTR_LIFETIME : lifetime) :
3401 radv_info->adv_router_lifetime_in_sec;
3402
3403 if (lifetime)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003404 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05003405 if (lifetime > MAX_DEF_RTR_LIFETIME)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003406 lifetime = MAX_DEF_RTR_LIFETIME;
Dave Barachd7cb1b52016-12-09 09:52:16 -05003407
3408 if (lifetime <= max_interval)
3409 return VNET_API_ERROR_INVALID_VALUE;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003410 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05003411
3412 if (min_interval != 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003413 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05003414 if ((min_interval > .75 * max_interval) || (min_interval < 3))
3415 return VNET_API_ERROR_INVALID_VALUE;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003416 }
3417
Dave Barachd7cb1b52016-12-09 09:52:16 -05003418 if ((initial_count > MAX_INITIAL_RTR_ADVERTISEMENTS) ||
3419 (initial_interval > MAX_INITIAL_RTR_ADVERT_INTERVAL))
3420 return VNET_API_ERROR_INVALID_VALUE;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003421
Dave Barachd7cb1b52016-12-09 09:52:16 -05003422 /*
3423 if "flag" is set and is_no is true then restore default value else set value corresponding to "flag"
3424 if "flag" is clear don't change corresponding value
3425 */
3426 radv_info->send_radv =
3427 (suppress != 0) ? ((is_no != 0) ? 1 : 0) : radv_info->send_radv;
3428 radv_info->adv_managed_flag =
3429 (managed != 0) ? ((is_no) ? 0 : 1) : radv_info->adv_managed_flag;
3430 radv_info->adv_other_flag =
3431 (other != 0) ? ((is_no) ? 0 : 1) : radv_info->adv_other_flag;
3432 radv_info->adv_link_layer_address =
3433 (ll_option !=
3434 0) ? ((is_no) ? 1 : 0) : radv_info->adv_link_layer_address;
3435 radv_info->send_unicast =
3436 (send_unicast != 0) ? ((is_no) ? 0 : 1) : radv_info->send_unicast;
3437 radv_info->cease_radv =
3438 (cease != 0) ? ((is_no) ? 0 : 1) : radv_info->cease_radv;
3439
3440 radv_info->min_radv_interval = min_interval;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003441 radv_info->max_radv_interval = max_interval;
3442 radv_info->adv_router_lifetime_in_sec = lifetime;
3443
Dave Barachd7cb1b52016-12-09 09:52:16 -05003444 radv_info->initial_adverts_count =
3445 (initial_count !=
3446 0) ? ((is_no) ? MAX_INITIAL_RTR_ADVERTISEMENTS : initial_count) :
3447 radv_info->initial_adverts_count;
3448 radv_info->initial_adverts_interval =
3449 (initial_interval !=
3450 0) ? ((is_no) ? MAX_INITIAL_RTR_ADVERT_INTERVAL : initial_interval) :
3451 radv_info->initial_adverts_interval;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003452
3453 /* restart */
Dave Barachd7cb1b52016-12-09 09:52:16 -05003454 if ((cease != 0) && (is_no))
3455 radv_info->send_radv = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003456
Dave Barachd7cb1b52016-12-09 09:52:16 -05003457 radv_info->initial_adverts_sent = radv_info->initial_adverts_count - 1;
3458 radv_info->next_multicast_time = vlib_time_now (vm);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003459 radv_info->last_multicast_time = vlib_time_now (vm);
Dave Barachd7cb1b52016-12-09 09:52:16 -05003460 radv_info->last_radv_time = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003461 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05003462 return (error);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003463}
3464
3465int
Dave Barachd7cb1b52016-12-09 09:52:16 -05003466ip6_neighbor_ra_prefix (vlib_main_t * vm, u32 sw_if_index,
3467 ip6_address_t * prefix_addr, u8 prefix_len,
3468 u8 use_default, u32 val_lifetime, u32 pref_lifetime,
3469 u8 no_advertise, u8 off_link, u8 no_autoconfig,
3470 u8 no_onlink, u8 is_no)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003471{
Dave Barachd7cb1b52016-12-09 09:52:16 -05003472 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003473 int error;
Dave Barachd7cb1b52016-12-09 09:52:16 -05003474
Ed Warnickecb9cada2015-12-08 15:45:58 -07003475 u32 ri;
3476
3477 /* look up the radv_t information for this interface */
Dave Barachd7cb1b52016-12-09 09:52:16 -05003478 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index,
3479 ~0);
3480
Ed Warnickecb9cada2015-12-08 15:45:58 -07003481 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
3482
3483 error = (ri != ~0) ? 0 : VNET_API_ERROR_INVALID_SW_IF_INDEX;
Dave Barachd7cb1b52016-12-09 09:52:16 -05003484
3485 if (!error)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003486 {
3487 f64 now = vlib_time_now (vm);
Dave Barachd7cb1b52016-12-09 09:52:16 -05003488 ip6_radv_t *radv_info;
3489 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003490
3491 /* prefix info add, delete or update */
Dave Barachd7cb1b52016-12-09 09:52:16 -05003492 ip6_radv_prefix_t *prefix;
3493
Ed Warnickecb9cada2015-12-08 15:45:58 -07003494 /* lookup prefix info for this address on this interface */
Dave Barachd7cb1b52016-12-09 09:52:16 -05003495 uword *p = mhash_get (&radv_info->address_to_prefix_index, prefix_addr);
3496
Ed Warnickecb9cada2015-12-08 15:45:58 -07003497 prefix = p ? pool_elt_at_index (radv_info->adv_prefixes_pool, p[0]) : 0;
3498
Dave Barachd7cb1b52016-12-09 09:52:16 -05003499 if (is_no)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003500 {
3501 /* delete */
Dave Barachd7cb1b52016-12-09 09:52:16 -05003502 if (!prefix)
3503 return VNET_API_ERROR_INVALID_VALUE; /* invalid prefix */
3504
3505 if (prefix->prefix_len != prefix_len)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003506 return VNET_API_ERROR_INVALID_VALUE_2;
3507
Dave Barachd7cb1b52016-12-09 09:52:16 -05003508 /* FIXME - Should the DP do this or the CP ? */
Ed Warnickecb9cada2015-12-08 15:45:58 -07003509 /* do specific delete processing here before returning */
3510 /* try to remove from routing table */
3511
Dave Barachd7cb1b52016-12-09 09:52:16 -05003512 mhash_unset (&radv_info->address_to_prefix_index, prefix_addr,
3513 /* old_value */ 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003514 pool_put (radv_info->adv_prefixes_pool, prefix);
3515
Dave Barachd7cb1b52016-12-09 09:52:16 -05003516 radv_info->initial_adverts_sent =
3517 radv_info->initial_adverts_count - 1;
3518 radv_info->next_multicast_time = vlib_time_now (vm);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003519 radv_info->last_multicast_time = vlib_time_now (vm);
Dave Barachd7cb1b52016-12-09 09:52:16 -05003520 radv_info->last_radv_time = 0;
3521 return (error);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003522 }
3523
3524 /* adding or changing */
Dave Barachd7cb1b52016-12-09 09:52:16 -05003525 if (!prefix)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003526 {
3527 /* add */
3528 u32 pi;
3529 pool_get (radv_info->adv_prefixes_pool, prefix);
3530 pi = prefix - radv_info->adv_prefixes_pool;
Dave Barachd7cb1b52016-12-09 09:52:16 -05003531 mhash_set (&radv_info->address_to_prefix_index, prefix_addr, pi,
3532 /* old_value */ 0);
3533
3534 memset (prefix, 0x0, sizeof (ip6_radv_prefix_t));
3535
Ed Warnickecb9cada2015-12-08 15:45:58 -07003536 prefix->prefix_len = prefix_len;
Dave Barachd7cb1b52016-12-09 09:52:16 -05003537 clib_memcpy (&prefix->prefix, prefix_addr, sizeof (ip6_address_t));
3538
Ed Warnickecb9cada2015-12-08 15:45:58 -07003539 /* initialize default values */
Dave Barachd7cb1b52016-12-09 09:52:16 -05003540 prefix->adv_on_link_flag = 1; /* L bit set */
3541 prefix->adv_autonomous_flag = 1; /* A bit set */
3542 prefix->adv_valid_lifetime_in_secs = DEF_ADV_VALID_LIFETIME;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003543 prefix->adv_pref_lifetime_in_secs = DEF_ADV_PREF_LIFETIME;
3544 prefix->enabled = 1;
3545 prefix->decrement_lifetime_flag = 1;
3546 prefix->deprecated_prefix_flag = 1;
3547
Dave Barachd7cb1b52016-12-09 09:52:16 -05003548 if (off_link == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003549 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05003550 /* FIXME - Should the DP do this or the CP ? */
Ed Warnickecb9cada2015-12-08 15:45:58 -07003551 /* insert prefix into routing table as a connected prefix */
3552 }
3553
Dave Barachd7cb1b52016-12-09 09:52:16 -05003554 if (use_default)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003555 goto restart;
3556 }
3557 else
3558 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05003559
3560 if (prefix->prefix_len != prefix_len)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003561 return VNET_API_ERROR_INVALID_VALUE_2;
3562
Dave Barachd7cb1b52016-12-09 09:52:16 -05003563 if (off_link != 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003564 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05003565 /* FIXME - Should the DP do this or the CP ? */
Ed Warnickecb9cada2015-12-08 15:45:58 -07003566 /* remove from routing table if already there */
Dave Barachd7cb1b52016-12-09 09:52:16 -05003567 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003568 }
3569
Dave Barachd7cb1b52016-12-09 09:52:16 -05003570 if ((val_lifetime == ~0) || (pref_lifetime == ~0))
Ed Warnickecb9cada2015-12-08 15:45:58 -07003571 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05003572 prefix->adv_valid_lifetime_in_secs = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003573 prefix->adv_pref_lifetime_in_secs = ~0;
3574 prefix->decrement_lifetime_flag = 0;
3575 }
3576 else
3577 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05003578 prefix->adv_valid_lifetime_in_secs = val_lifetime;;
3579 prefix->adv_pref_lifetime_in_secs = pref_lifetime;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003580 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05003581
Ed Warnickecb9cada2015-12-08 15:45:58 -07003582 /* copy remaining */
3583 prefix->enabled = !(no_advertise != 0);
3584 prefix->adv_on_link_flag = !((off_link != 0) || (no_onlink != 0));
3585 prefix->adv_autonomous_flag = !(no_autoconfig != 0);
3586
Dave Barachd7cb1b52016-12-09 09:52:16 -05003587 restart:
Ed Warnickecb9cada2015-12-08 15:45:58 -07003588 /* restart */
3589 /* fill in the expiration times */
Dave Barachd7cb1b52016-12-09 09:52:16 -05003590 prefix->valid_lifetime_expires =
3591 now + prefix->adv_valid_lifetime_in_secs;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003592 prefix->pref_lifetime_expires = now + prefix->adv_pref_lifetime_in_secs;
Dave Barachd7cb1b52016-12-09 09:52:16 -05003593
3594 radv_info->initial_adverts_sent = radv_info->initial_adverts_count - 1;
3595 radv_info->next_multicast_time = vlib_time_now (vm);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003596 radv_info->last_multicast_time = vlib_time_now (vm);
Dave Barachd7cb1b52016-12-09 09:52:16 -05003597 radv_info->last_radv_time = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003598 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05003599 return (error);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003600}
3601
3602clib_error_t *
Dave Barachd7cb1b52016-12-09 09:52:16 -05003603ip6_neighbor_cmd (vlib_main_t * vm, unformat_input_t * main_input,
3604 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003605{
Dave Barachd7cb1b52016-12-09 09:52:16 -05003606 vnet_main_t *vnm = vnet_get_main ();
3607 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
3608 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003609 u8 is_no = 0;
Dave Barachd7cb1b52016-12-09 09:52:16 -05003610 u8 suppress = 0, managed = 0, other = 0;
3611 u8 suppress_ll_option = 0, send_unicast = 0, cease = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003612 u8 use_lifetime = 0;
Dave Barachd7cb1b52016-12-09 09:52:16 -05003613 u32 sw_if_index, ra_lifetime = 0, ra_initial_count =
3614 0, ra_initial_interval = 0;
3615 u32 ra_max_interval = 0, ra_min_interval = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003616
Dave Barachd7cb1b52016-12-09 09:52:16 -05003617 unformat_input_t _line_input, *line_input = &_line_input;
3618 vnet_sw_interface_t *sw_if0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003619
3620 int add_radv_info = 1;
Dave Barachd7cb1b52016-12-09 09:52:16 -05003621 __attribute__ ((unused)) ip6_radv_t *radv_info = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003622 ip6_address_t ip6_addr;
3623 u32 addr_len;
Dave Barachd7cb1b52016-12-09 09:52:16 -05003624
Ed Warnickecb9cada2015-12-08 15:45:58 -07003625
3626 /* Get a line of input. */
Dave Barachd7cb1b52016-12-09 09:52:16 -05003627 if (!unformat_user (main_input, unformat_line_input, line_input))
Ed Warnickecb9cada2015-12-08 15:45:58 -07003628 return 0;
3629
3630 /* get basic radv info for this interface */
Dave Barachd7cb1b52016-12-09 09:52:16 -05003631 if (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003632 {
3633
Dave Barachd7cb1b52016-12-09 09:52:16 -05003634 if (unformat_user (line_input,
Ed Warnickecb9cada2015-12-08 15:45:58 -07003635 unformat_vnet_sw_interface, vnm, &sw_if_index))
3636 {
3637 u32 ri;
Dave Barachd7cb1b52016-12-09 09:52:16 -05003638 ethernet_interface_t *eth_if0 = 0;
3639
Ed Warnickecb9cada2015-12-08 15:45:58 -07003640 sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index);
Dave Barachd7cb1b52016-12-09 09:52:16 -05003641 if (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE)
3642 eth_if0 =
3643 ethernet_get_interface (&ethernet_main, sw_if0->hw_if_index);
3644
3645 if (!eth_if0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003646 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05003647 error =
3648 clib_error_return (0, "Interface must be of ethernet type");
Ed Warnickecb9cada2015-12-08 15:45:58 -07003649 goto done;
3650 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05003651
Ed Warnickecb9cada2015-12-08 15:45:58 -07003652 /* look up the radv_t information for this interface */
Dave Barachd7cb1b52016-12-09 09:52:16 -05003653 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index,
3654 sw_if_index, ~0);
3655
Ed Warnickecb9cada2015-12-08 15:45:58 -07003656 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
Dave Barachd7cb1b52016-12-09 09:52:16 -05003657
3658 if (ri != ~0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003659 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05003660 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003661 }
3662 else
3663 {
3664 error = clib_error_return (0, "unknown interface %U'",
3665 format_unformat_error, line_input);
3666 goto done;
3667 }
3668 }
3669 else
3670 {
3671 error = clib_error_return (0, "invalid interface name %U'",
3672 format_unformat_error, line_input);
3673 goto done;
3674 }
3675 }
3676
3677 /* get the rest of the command */
3678 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
3679 {
3680 if (unformat (line_input, "no"))
Dave Barachd7cb1b52016-12-09 09:52:16 -05003681 is_no = 1;
3682 else if (unformat (line_input, "prefix %U/%d",
3683 unformat_ip6_address, &ip6_addr, &addr_len))
Ed Warnickecb9cada2015-12-08 15:45:58 -07003684 {
3685 add_radv_info = 0;
3686 break;
3687 }
3688 else if (unformat (line_input, "ra-managed-config-flag"))
3689 {
3690 managed = 1;
3691 break;
3692 }
3693 else if (unformat (line_input, "ra-other-config-flag"))
3694 {
3695 other = 1;
3696 break;
3697 }
Chris Luke33879c92016-06-28 19:54:21 -04003698 else if (unformat (line_input, "ra-suppress") ||
Dave Barachd7cb1b52016-12-09 09:52:16 -05003699 unformat (line_input, "ra-surpress"))
Ed Warnickecb9cada2015-12-08 15:45:58 -07003700 {
Chris Luke33879c92016-06-28 19:54:21 -04003701 suppress = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003702 break;
3703 }
Chris Luke33879c92016-06-28 19:54:21 -04003704 else if (unformat (line_input, "ra-suppress-link-layer") ||
Dave Barachd7cb1b52016-12-09 09:52:16 -05003705 unformat (line_input, "ra-surpress-link-layer"))
Ed Warnickecb9cada2015-12-08 15:45:58 -07003706 {
Chris Luke33879c92016-06-28 19:54:21 -04003707 suppress_ll_option = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003708 break;
3709 }
3710 else if (unformat (line_input, "ra-send-unicast"))
3711 {
3712 send_unicast = 1;
3713 break;
3714 }
3715 else if (unformat (line_input, "ra-lifetime"))
3716 {
3717 if (!unformat (line_input, "%d", &ra_lifetime))
Billy McFalla9a20e72017-02-15 11:39:12 -05003718 {
3719 error = unformat_parse_error (line_input);
3720 goto done;
3721 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003722 use_lifetime = 1;
3723 break;
Dave Barachd7cb1b52016-12-09 09:52:16 -05003724 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003725 else if (unformat (line_input, "ra-initial"))
3726 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05003727 if (!unformat
3728 (line_input, "%d %d", &ra_initial_count, &ra_initial_interval))
Billy McFalla9a20e72017-02-15 11:39:12 -05003729 {
3730 error = unformat_parse_error (line_input);
3731 goto done;
3732 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003733 break;
3734 }
3735 else if (unformat (line_input, "ra-interval"))
3736 {
3737 if (!unformat (line_input, "%d", &ra_max_interval))
Billy McFalla9a20e72017-02-15 11:39:12 -05003738 {
3739 error = unformat_parse_error (line_input);
3740 goto done;
3741 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003742
3743 if (!unformat (line_input, "%d", &ra_min_interval))
3744 ra_min_interval = 0;
3745 break;
3746 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05003747 else if (unformat (line_input, "ra-cease"))
Ed Warnickecb9cada2015-12-08 15:45:58 -07003748 {
3749 cease = 1;
3750 break;
3751 }
3752 else
Billy McFalla9a20e72017-02-15 11:39:12 -05003753 {
3754 error = unformat_parse_error (line_input);
3755 goto done;
3756 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003757 }
3758
Dave Barachd7cb1b52016-12-09 09:52:16 -05003759 if (add_radv_info)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003760 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05003761 ip6_neighbor_ra_config (vm, sw_if_index,
3762 suppress, managed, other,
3763 suppress_ll_option, send_unicast, cease,
3764 use_lifetime, ra_lifetime,
3765 ra_initial_count, ra_initial_interval,
3766 ra_max_interval, ra_min_interval, is_no);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003767 }
3768 else
3769 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05003770 u32 valid_lifetime_in_secs = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003771 u32 pref_lifetime_in_secs = 0;
3772 u8 use_prefix_default_values = 0;
Dave Barachd7cb1b52016-12-09 09:52:16 -05003773 u8 no_advertise = 0;
3774 u8 off_link = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003775 u8 no_autoconfig = 0;
Dave Barachd7cb1b52016-12-09 09:52:16 -05003776 u8 no_onlink = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003777
3778 /* get the rest of the command */
Dave Barachd7cb1b52016-12-09 09:52:16 -05003779 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003780 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05003781 if (unformat (line_input, "default"))
Ed Warnickecb9cada2015-12-08 15:45:58 -07003782 {
3783 use_prefix_default_values = 1;
3784 break;
3785 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05003786 else if (unformat (line_input, "infinite"))
Ed Warnickecb9cada2015-12-08 15:45:58 -07003787 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05003788 valid_lifetime_in_secs = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003789 pref_lifetime_in_secs = ~0;
3790 break;
3791 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05003792 else if (unformat (line_input, "%d %d", &valid_lifetime_in_secs,
3793 &pref_lifetime_in_secs))
Ed Warnickecb9cada2015-12-08 15:45:58 -07003794 break;
3795 else
3796 break;
3797 }
3798
3799
3800 /* get the rest of the command */
3801 while (!use_prefix_default_values &&
3802 unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
3803 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05003804 if (unformat (line_input, "no-advertise"))
Ed Warnickecb9cada2015-12-08 15:45:58 -07003805 no_advertise = 1;
Dave Barachd7cb1b52016-12-09 09:52:16 -05003806 else if (unformat (line_input, "off-link"))
Ed Warnickecb9cada2015-12-08 15:45:58 -07003807 off_link = 1;
Dave Barachd7cb1b52016-12-09 09:52:16 -05003808 else if (unformat (line_input, "no-autoconfig"))
Ed Warnickecb9cada2015-12-08 15:45:58 -07003809 no_autoconfig = 1;
Dave Barachd7cb1b52016-12-09 09:52:16 -05003810 else if (unformat (line_input, "no-onlink"))
Ed Warnickecb9cada2015-12-08 15:45:58 -07003811 no_onlink = 1;
3812 else
Billy McFalla9a20e72017-02-15 11:39:12 -05003813 {
3814 error = unformat_parse_error (line_input);
3815 goto done;
3816 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003817 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05003818
3819 ip6_neighbor_ra_prefix (vm, sw_if_index,
3820 &ip6_addr, addr_len,
3821 use_prefix_default_values,
3822 valid_lifetime_in_secs,
3823 pref_lifetime_in_secs,
3824 no_advertise,
3825 off_link, no_autoconfig, no_onlink, is_no);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003826 }
3827
Billy McFalla9a20e72017-02-15 11:39:12 -05003828done:
Ed Warnickecb9cada2015-12-08 15:45:58 -07003829 unformat_free (line_input);
Dave Barachd7cb1b52016-12-09 09:52:16 -05003830
Ed Warnickecb9cada2015-12-08 15:45:58 -07003831 return error;
3832}
3833
Chris Lukebfd32fd2016-06-24 20:38:06 -04003834static void
Dave Barachd7cb1b52016-12-09 09:52:16 -05003835ip6_print_addrs (vlib_main_t * vm, u32 * addrs)
Chris Lukebfd32fd2016-06-24 20:38:06 -04003836{
Dave Barachd7cb1b52016-12-09 09:52:16 -05003837 ip_lookup_main_t *lm = &ip6_main.lookup_main;
Chris Lukebfd32fd2016-06-24 20:38:06 -04003838 u32 i;
3839
3840 for (i = 0; i < vec_len (addrs); i++)
3841 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05003842 ip_interface_address_t *a =
3843 pool_elt_at_index (lm->if_address_pool, addrs[i]);
3844 ip6_address_t *address = ip_interface_address_get_address (lm, a);
Chris Lukebfd32fd2016-06-24 20:38:06 -04003845
3846 vlib_cli_output (vm, "\t\t%U/%d",
Dave Barachd7cb1b52016-12-09 09:52:16 -05003847 format_ip6_address, address, a->address_length);
Chris Lukebfd32fd2016-06-24 20:38:06 -04003848 }
3849}
3850
Ed Warnickecb9cada2015-12-08 15:45:58 -07003851static clib_error_t *
3852show_ip6_interface_cmd (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05003853 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003854{
Dave Barachd7cb1b52016-12-09 09:52:16 -05003855 vnet_main_t *vnm = vnet_get_main ();
3856 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
3857 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003858 u32 sw_if_index;
3859
3860 sw_if_index = ~0;
3861
Dave Barachd7cb1b52016-12-09 09:52:16 -05003862 if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -07003863 {
3864 u32 ri;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003865
Dave Barachd7cb1b52016-12-09 09:52:16 -05003866 /* look up the radv_t information for this interface */
3867 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index,
3868 sw_if_index, ~0);
3869
3870 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
3871
3872 if (ri != ~0)
3873 {
3874 ip_lookup_main_t *lm = &ip6_main.lookup_main;
3875 ip6_radv_t *radv_info;
3876 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
3877
3878 vlib_cli_output (vm, "%U is admin %s\n",
3879 format_vnet_sw_interface_name, vnm,
Ed Warnickecb9cada2015-12-08 15:45:58 -07003880 vnet_get_sw_interface (vnm, sw_if_index),
Dave Barachd7cb1b52016-12-09 09:52:16 -05003881 (vnet_sw_interface_is_admin_up (vnm, sw_if_index) ?
3882 "up" : "down"));
3883
Chris Lukebfd32fd2016-06-24 20:38:06 -04003884 u32 ai;
3885 u32 *link_scope = 0, *global_scope = 0;
3886 u32 *local_scope = 0, *unknown_scope = 0;
Dave Barachd7cb1b52016-12-09 09:52:16 -05003887 ip_interface_address_t *a;
Ed Warnickecb9cada2015-12-08 15:45:58 -07003888
Dave Barachd7cb1b52016-12-09 09:52:16 -05003889 vec_validate_init_empty (lm->if_address_pool_index_by_sw_if_index,
3890 sw_if_index, ~0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003891 ai = lm->if_address_pool_index_by_sw_if_index[sw_if_index];
3892
Dave Barachd7cb1b52016-12-09 09:52:16 -05003893 while (ai != (u32) ~ 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07003894 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05003895 a = pool_elt_at_index (lm->if_address_pool, ai);
3896 ip6_address_t *address =
3897 ip_interface_address_get_address (lm, a);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003898
Chris Lukebfd32fd2016-06-24 20:38:06 -04003899 if (ip6_address_is_link_local_unicast (address))
3900 vec_add1 (link_scope, ai);
Dave Barachd7cb1b52016-12-09 09:52:16 -05003901 else if (ip6_address_is_global_unicast (address))
Ed Warnickecb9cada2015-12-08 15:45:58 -07003902 vec_add1 (global_scope, ai);
Dave Barachd7cb1b52016-12-09 09:52:16 -05003903 else if (ip6_address_is_local_unicast (address))
Chris Lukebfd32fd2016-06-24 20:38:06 -04003904 vec_add1 (local_scope, ai);
3905 else
3906 vec_add1 (unknown_scope, ai);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003907
3908 ai = a->next_this_sw_interface;
3909 }
3910
Dave Barachd7cb1b52016-12-09 09:52:16 -05003911 if (vec_len (link_scope))
3912 {
3913 vlib_cli_output (vm, "\tLink-local address(es):\n");
3914 ip6_print_addrs (vm, link_scope);
3915 vec_free (link_scope);
3916 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003917
Dave Barachd7cb1b52016-12-09 09:52:16 -05003918 if (vec_len (local_scope))
3919 {
3920 vlib_cli_output (vm, "\tLocal unicast address(es):\n");
3921 ip6_print_addrs (vm, local_scope);
3922 vec_free (local_scope);
3923 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07003924
Dave Barachd7cb1b52016-12-09 09:52:16 -05003925 if (vec_len (global_scope))
3926 {
3927 vlib_cli_output (vm, "\tGlobal unicast address(es):\n");
3928 ip6_print_addrs (vm, global_scope);
3929 vec_free (global_scope);
3930 }
Chris Lukebfd32fd2016-06-24 20:38:06 -04003931
Dave Barachd7cb1b52016-12-09 09:52:16 -05003932 if (vec_len (unknown_scope))
3933 {
3934 vlib_cli_output (vm, "\tOther-scope address(es):\n");
3935 ip6_print_addrs (vm, unknown_scope);
3936 vec_free (unknown_scope);
3937 }
Chris Lukebfd32fd2016-06-24 20:38:06 -04003938
Neale Ranns53da2212018-02-24 02:11:19 -08003939 vlib_cli_output (vm, "\tLink-local address(es):\n");
3940 vlib_cli_output (vm, "\t\t%U\n", format_ip6_address,
3941 &radv_info->link_local_address);
3942
Ed Warnickecb9cada2015-12-08 15:45:58 -07003943 vlib_cli_output (vm, "\tJoined group address(es):\n");
3944 ip6_mldp_group_t *m;
Dave Barachd7cb1b52016-12-09 09:52:16 -05003945 /* *INDENT-OFF* */
3946 pool_foreach (m, radv_info->mldp_group_pool,
3947 ({
3948 vlib_cli_output (vm, "\t\t%U\n", format_ip6_address,
3949 &m->mcast_address);
3950 }));
3951 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07003952
3953 vlib_cli_output (vm, "\tAdvertised Prefixes:\n");
Dave Barachd7cb1b52016-12-09 09:52:16 -05003954 ip6_radv_prefix_t *p;
3955 /* *INDENT-OFF* */
3956 pool_foreach (p, radv_info->adv_prefixes_pool,
3957 ({
3958 vlib_cli_output (vm, "\t\tprefix %U, length %d\n",
3959 format_ip6_address, &p->prefix, p->prefix_len);
3960 }));
3961 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07003962
Dave Barachd7cb1b52016-12-09 09:52:16 -05003963 vlib_cli_output (vm, "\tMTU is %d\n", radv_info->adv_link_mtu);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003964 vlib_cli_output (vm, "\tICMP error messages are unlimited\n");
3965 vlib_cli_output (vm, "\tICMP redirects are disabled\n");
3966 vlib_cli_output (vm, "\tICMP unreachables are not sent\n");
3967 vlib_cli_output (vm, "\tND DAD is disabled\n");
3968 //vlib_cli_output (vm, "\tND reachable time is %d milliseconds\n",);
3969 vlib_cli_output (vm, "\tND advertised reachable time is %d\n",
3970 radv_info->adv_neighbor_reachable_time_in_msec);
Dave Barachd7cb1b52016-12-09 09:52:16 -05003971 vlib_cli_output (vm,
3972 "\tND advertised retransmit interval is %d (msec)\n",
3973 radv_info->
3974 adv_time_in_msec_between_retransmitted_neighbor_solicitations);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003975
3976 u32 ra_interval = radv_info->max_radv_interval;
3977 u32 ra_interval_min = radv_info->min_radv_interval;
Dave Barachd7cb1b52016-12-09 09:52:16 -05003978 vlib_cli_output (vm,
3979 "\tND router advertisements are sent every %d seconds (min interval is %d)\n",
Ed Warnickecb9cada2015-12-08 15:45:58 -07003980 ra_interval, ra_interval_min);
Dave Barachd7cb1b52016-12-09 09:52:16 -05003981 vlib_cli_output (vm,
3982 "\tND router advertisements live for %d seconds\n",
Ed Warnickecb9cada2015-12-08 15:45:58 -07003983 radv_info->adv_router_lifetime_in_sec);
Dave Barachd7cb1b52016-12-09 09:52:16 -05003984 vlib_cli_output (vm,
3985 "\tHosts %s stateless autoconfig for addresses\n",
3986 (radv_info->adv_managed_flag) ? "use" :
3987 " don't use");
3988 vlib_cli_output (vm, "\tND router advertisements sent %d\n",
3989 radv_info->n_advertisements_sent);
3990 vlib_cli_output (vm, "\tND router solicitations received %d\n",
3991 radv_info->n_solicitations_rcvd);
3992 vlib_cli_output (vm, "\tND router solicitations dropped %d\n",
3993 radv_info->n_solicitations_dropped);
Ed Warnickecb9cada2015-12-08 15:45:58 -07003994 }
3995 else
3996 {
Chris Lukebfd32fd2016-06-24 20:38:06 -04003997 error = clib_error_return (0, "IPv6 not enabled on interface",
Ed Warnickecb9cada2015-12-08 15:45:58 -07003998 format_unformat_error, input);
3999
4000 }
4001 }
4002 return error;
4003}
4004
Billy McFall0683c9c2016-10-13 08:27:31 -04004005/*?
4006 * This command is used to display various IPv6 attributes on a given
4007 * interface.
4008 *
4009 * @cliexpar
4010 * Example of how to display IPv6 settings:
4011 * @cliexstart{show ip6 interface GigabitEthernet2/0/0}
4012 * GigabitEthernet2/0/0 is admin up
4013 * Link-local address(es):
4014 * fe80::ab8/64
4015 * Joined group address(es):
4016 * ff02::1
4017 * ff02::2
4018 * ff02::16
4019 * ff02::1:ff00:ab8
4020 * Advertised Prefixes:
4021 * prefix fe80::fe:28ff:fe9c:75b3, length 64
4022 * MTU is 1500
4023 * ICMP error messages are unlimited
4024 * ICMP redirects are disabled
4025 * ICMP unreachables are not sent
4026 * ND DAD is disabled
4027 * ND advertised reachable time is 0
4028 * ND advertised retransmit interval is 0 (msec)
4029 * ND router advertisements are sent every 200 seconds (min interval is 150)
4030 * ND router advertisements live for 600 seconds
4031 * Hosts use stateless autoconfig for addresses
4032 * ND router advertisements sent 19336
4033 * ND router solicitations received 0
4034 * ND router solicitations dropped 0
4035 * @cliexend
4036 * Example of output if IPv6 is not enabled on the interface:
4037 * @cliexstart{show ip6 interface GigabitEthernet2/0/0}
4038 * show ip6 interface: IPv6 not enabled on interface
4039 * @cliexend
4040?*/
4041/* *INDENT-OFF* */
Dave Barachd7cb1b52016-12-09 09:52:16 -05004042VLIB_CLI_COMMAND (show_ip6_interface_command, static) =
4043{
Ed Warnickecb9cada2015-12-08 15:45:58 -07004044 .path = "show ip6 interface",
4045 .function = show_ip6_interface_cmd,
Billy McFall0683c9c2016-10-13 08:27:31 -04004046 .short_help = "show ip6 interface <interface>",
Ed Warnickecb9cada2015-12-08 15:45:58 -07004047};
Billy McFall0683c9c2016-10-13 08:27:31 -04004048/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07004049
4050clib_error_t *
Dave Barachd7cb1b52016-12-09 09:52:16 -05004051disable_ip6_interface (vlib_main_t * vm, u32 sw_if_index)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004052{
Dave Barachd7cb1b52016-12-09 09:52:16 -05004053 clib_error_t *error = 0;
4054 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004055 u32 ri;
4056
4057 /* look up the radv_t information for this interface */
Dave Barachd7cb1b52016-12-09 09:52:16 -05004058 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index,
4059 ~0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004060 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
Dave Barachd7cb1b52016-12-09 09:52:16 -05004061
Ed Warnickecb9cada2015-12-08 15:45:58 -07004062 /* if not created - do nothing */
Dave Barachd7cb1b52016-12-09 09:52:16 -05004063 if (ri != ~0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004064 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05004065 ip6_radv_t *radv_info;
4066
4067 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004068
4069 /* check radv_info ref count for other ip6 addresses on this interface */
Wojciech Dec7bc73102017-02-14 16:24:28 +01004070 /* This implicitly excludes the link local address */
Dave Barachd7cb1b52016-12-09 09:52:16 -05004071 if (radv_info->ref_count == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004072 {
4073 /* essentially "disables" ipv6 on this interface */
Neale Ranns53da2212018-02-24 02:11:19 -08004074 ip6_ll_prefix_t ilp = {
4075 .ilp_addr = radv_info->link_local_address,
4076 .ilp_sw_if_index = sw_if_index,
4077 };
4078 ip6_ll_table_entry_delete (&ilp);
4079 ip6_sw_interface_enable_disable (sw_if_index, 0);
Neale Ranns4008ac92017-02-13 23:20:04 -08004080 ip6_mfib_interface_enable_disable (sw_if_index, 0);
Neale Ranns53da2212018-02-24 02:11:19 -08004081 ip6_neighbor_sw_interface_add_del (vnet_get_main (), sw_if_index,
4082 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004083 }
4084 }
4085 return error;
4086}
4087
4088int
Dave Barachd7cb1b52016-12-09 09:52:16 -05004089ip6_interface_enabled (vlib_main_t * vm, u32 sw_if_index)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004090{
Dave Barachd7cb1b52016-12-09 09:52:16 -05004091 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
4092 u32 ri = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004093
Dave Barachd7cb1b52016-12-09 09:52:16 -05004094 /* look up the radv_t information for this interface */
4095 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index,
4096 ~0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004097
Dave Barachd7cb1b52016-12-09 09:52:16 -05004098 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
Ed Warnickecb9cada2015-12-08 15:45:58 -07004099
Dave Barachd7cb1b52016-12-09 09:52:16 -05004100 return ri != ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004101}
4102
Dave Barachd7cb1b52016-12-09 09:52:16 -05004103clib_error_t *
4104enable_ip6_interface (vlib_main_t * vm, u32 sw_if_index)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004105{
Dave Barachd7cb1b52016-12-09 09:52:16 -05004106 clib_error_t *error = 0;
4107 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004108 u32 ri;
4109 int is_add = 1;
4110
4111 /* look up the radv_t information for this interface */
Dave Barachd7cb1b52016-12-09 09:52:16 -05004112 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index,
4113 ~0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004114
Dave Barachd7cb1b52016-12-09 09:52:16 -05004115 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
4116
4117 /* if not created yet */
4118 if (ri == ~0)
4119 {
4120 vnet_main_t *vnm = vnet_get_main ();
4121 vnet_sw_interface_t *sw_if0;
4122
4123 sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index);
4124 if (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE)
4125 {
4126 ethernet_interface_t *eth_if0;
4127
4128 eth_if0 =
4129 ethernet_get_interface (&ethernet_main, sw_if0->hw_if_index);
4130 if (eth_if0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004131 {
4132 /* create radv_info. for this interface. This holds all the info needed for router adverts */
Dave Barachd7cb1b52016-12-09 09:52:16 -05004133 ri =
4134 ip6_neighbor_sw_interface_add_del (vnm, sw_if_index, is_add);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004135
Dave Barachd7cb1b52016-12-09 09:52:16 -05004136 if (ri != ~0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004137 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05004138 ip6_radv_t *radv_info;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004139 ip6_address_t link_local_address;
4140
Dave Barachd7cb1b52016-12-09 09:52:16 -05004141 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004142
Dave Barachd7cb1b52016-12-09 09:52:16 -05004143 ip6_link_local_address_from_ethernet_mac_address
4144 (&link_local_address, eth_if0->address);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004145
4146 sw_if0 = vnet_get_sw_interface (vnm, sw_if_index);
Pavel Kotucek8dc80202017-08-15 13:52:22 +02004147 if (sw_if0->type == VNET_SW_INTERFACE_TYPE_SUB ||
4148 sw_if0->type == VNET_SW_INTERFACE_TYPE_P2P)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004149 {
4150 /* make up an interface id */
Dave Barach611d9182018-03-12 15:56:41 -04004151 link_local_address.as_u64[1] =
4152 random_u64 (&radv_info->randomizer);
Dave Barachd7cb1b52016-12-09 09:52:16 -05004153
4154 link_local_address.as_u64[0] =
4155 clib_host_to_net_u64 (0xFE80000000000000ULL);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004156 /* clear u bit */
4157 link_local_address.as_u8[8] &= 0xfd;
4158 }
Neale Ranns53da2212018-02-24 02:11:19 -08004159 {
4160 ip6_ll_prefix_t ilp = {
4161 .ilp_addr = link_local_address,
4162 .ilp_sw_if_index = sw_if_index,
4163 };
Dave Barachd7cb1b52016-12-09 09:52:16 -05004164
Neale Ranns53da2212018-02-24 02:11:19 -08004165 ip6_ll_table_entry_update (&ilp, FIB_ROUTE_PATH_LOCAL);
4166 }
Neale Ranns4008ac92017-02-13 23:20:04 -08004167
Ed Warnickecb9cada2015-12-08 15:45:58 -07004168 /* essentially "enables" ipv6 on this interface */
Neale Ranns53da2212018-02-24 02:11:19 -08004169 ip6_mfib_interface_enable_disable (sw_if_index, 1);
4170 ip6_sw_interface_enable_disable (sw_if_index, 1);
Dave Barachd7cb1b52016-12-09 09:52:16 -05004171
Neale Ranns53da2212018-02-24 02:11:19 -08004172 if (!error)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004173 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05004174 radv_info->link_local_address = link_local_address;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004175 }
4176 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05004177 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004178 }
4179 }
4180 return error;
4181}
4182
Neale Ranns53da2212018-02-24 02:11:19 -08004183int
4184ip6_get_ll_address (u32 sw_if_index, ip6_address_t * addr)
4185{
4186 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
4187 ip6_radv_t *radv_info;
4188 u32 ri;
4189
4190 if (vec_len (nm->if_radv_pool_index_by_sw_if_index) < sw_if_index)
4191 return 0;
4192
4193 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
4194
4195 if (ri == ~0)
4196 return 0;
4197
4198 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
4199 *addr = radv_info->link_local_address;
4200
4201 return (!0);
4202}
4203
Ed Warnickecb9cada2015-12-08 15:45:58 -07004204static clib_error_t *
4205enable_ip6_interface_cmd (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05004206 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004207{
Dave Barachd7cb1b52016-12-09 09:52:16 -05004208 vnet_main_t *vnm = vnet_get_main ();
4209 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004210 u32 sw_if_index;
4211
4212 sw_if_index = ~0;
4213
Dave Barachd7cb1b52016-12-09 09:52:16 -05004214 if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -07004215 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05004216 enable_ip6_interface (vm, sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004217 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05004218 else
4219 {
4220 error = clib_error_return (0, "unknown interface\n'",
4221 format_unformat_error, input);
4222
4223 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004224 return error;
4225}
4226
Billy McFall0683c9c2016-10-13 08:27:31 -04004227/*?
4228 * This command is used to enable IPv6 on a given interface.
4229 *
4230 * @cliexpar
4231 * Example of how enable IPv6 on a given interface:
4232 * @cliexcmd{enable ip6 interface GigabitEthernet2/0/0}
4233?*/
4234/* *INDENT-OFF* */
Dave Barachd7cb1b52016-12-09 09:52:16 -05004235VLIB_CLI_COMMAND (enable_ip6_interface_command, static) =
4236{
Ed Warnickecb9cada2015-12-08 15:45:58 -07004237 .path = "enable ip6 interface",
4238 .function = enable_ip6_interface_cmd,
Billy McFall0683c9c2016-10-13 08:27:31 -04004239 .short_help = "enable ip6 interface <interface>",
Ed Warnickecb9cada2015-12-08 15:45:58 -07004240};
Billy McFall0683c9c2016-10-13 08:27:31 -04004241/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07004242
4243static clib_error_t *
4244disable_ip6_interface_cmd (vlib_main_t * vm,
Dave Barachd7cb1b52016-12-09 09:52:16 -05004245 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004246{
Dave Barachd7cb1b52016-12-09 09:52:16 -05004247 vnet_main_t *vnm = vnet_get_main ();
4248 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004249 u32 sw_if_index;
4250
4251 sw_if_index = ~0;
4252
Dave Barachd7cb1b52016-12-09 09:52:16 -05004253 if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -07004254 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05004255 error = disable_ip6_interface (vm, sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004256 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05004257 else
4258 {
4259 error = clib_error_return (0, "unknown interface\n'",
4260 format_unformat_error, input);
4261
4262 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07004263 return error;
4264}
4265
Billy McFall0683c9c2016-10-13 08:27:31 -04004266/*?
4267 * This command is used to disable IPv6 on a given interface.
4268 *
4269 * @cliexpar
4270 * Example of how disable IPv6 on a given interface:
4271 * @cliexcmd{disable ip6 interface GigabitEthernet2/0/0}
4272?*/
4273/* *INDENT-OFF* */
Dave Barachd7cb1b52016-12-09 09:52:16 -05004274VLIB_CLI_COMMAND (disable_ip6_interface_command, static) =
4275{
Billy McFall0683c9c2016-10-13 08:27:31 -04004276 .path = "disable ip6 interface",
Ed Warnickecb9cada2015-12-08 15:45:58 -07004277 .function = disable_ip6_interface_cmd,
Billy McFall0683c9c2016-10-13 08:27:31 -04004278 .short_help = "disable ip6 interface <interface>",
Ed Warnickecb9cada2015-12-08 15:45:58 -07004279};
Billy McFall0683c9c2016-10-13 08:27:31 -04004280/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07004281
Billy McFall0683c9c2016-10-13 08:27:31 -04004282/*?
4283 * This command is used to configure the neighbor discovery
4284 * parameters on a given interface. Use the '<em>show ip6 interface</em>'
4285 * command to display some of the current neighbor discovery parameters
4286 * on a given interface. This command has three formats:
4287 *
4288 *
4289 * <b>Format 1 - Router Advertisement Options:</b> (Only one can be entered in a single command)
4290 *
4291 * '<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>'
4292 *
4293 * Where:
4294 *
4295 * <em>[no] ra-managed-config-flag</em> - Advertises in ICMPv6
4296 * router-advertisement messages to use stateful address
4297 * auto-configuration to obtain address information (sets the M-bit).
4298 * Default is the M-bit is not set and the '<em>no</em>' option
4299 * returns it to this default state.
4300 *
4301 * <em>[no] ra-other-config-flag</em> - Indicates in ICMPv6
4302 * router-advertisement messages that hosts use stateful auto
4303 * configuration to obtain nonaddress related information (sets
4304 * the O-bit). Default is the O-bit is not set and the '<em>no</em>'
4305 * option returns it to this default state.
4306 *
4307 * <em>[no] ra-suppress</em> - Disables sending ICMPv6 router-advertisement
4308 * messages. The '<em>no</em>' option implies to enable sending ICMPv6
4309 * router-advertisement messages.
4310 *
4311 * <em>[no] ra-suppress-link-layer</em> - Indicates not to include the
4312 * optional source link-layer address in the ICMPv6 router-advertisement
4313 * messages. Default is to include the optional source link-layer address
4314 * and the '<em>no</em>' option returns it to this default state.
4315 *
4316 * <em>[no] ra-send-unicast</em> - Use the source address of the
4317 * router-solicitation message if availiable. The default is to use
4318 * multicast address of all nodes, and the '<em>no</em>' option returns
4319 * it to this default state.
4320 *
4321 * <em>[no] ra-lifetime <lifetime></em> - Advertises the lifetime of a
4322 * default router in ICMPv6 router-advertisement messages. The range is
4323 * from 0 to 9000 seconds. '<em><lifetime></em>' must be greater than
4324 * '<em><max-interval></em>'. The default value is 600 seconds and the
4325 * '<em>no</em>' option returns it to this default value.
4326 *
4327 * <em>[no] ra-initial <cnt> <interval></em> - Number of initial ICMPv6
4328 * router-advertisement messages sent and the interval between each
4329 * message. Range for count is 1 - 3 and default is 3. Range for interval
4330 * is 1 to 16 seconds, and default is 16 seconds. The '<em>no</em>' option
4331 * returns both to their default value.
4332 *
4333 * <em>[no] ra-interval <max-interval> [<min-interval>]</em> - Configures the
4334 * interval between sending ICMPv6 router-advertisement messages. The
4335 * range for max-interval is from 4 to 200 seconds. min-interval can not
4336 * be more than 75% of max-interval. If not set, min-interval will be
4337 * set to 75% of max-interval. The range for min-interval is from 3 to
4338 * 150 seconds. The '<em>no</em>' option returns both to their default
4339 * value.
4340 *
4341 * <em>[no] ra-cease</em> - Cease sending ICMPv6 router-advertisement messages.
4342 * The '<em>no</em>' options implies to start (or restart) sending
4343 * ICMPv6 router-advertisement messages.
4344 *
4345 *
4346 * <b>Format 2 - Prefix Options:</b>
4347 *
4348 * '<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>'
4349 *
4350 * Where:
4351 *
4352 * <em>no</em> - All additional flags are ignored and the prefix is deleted.
4353 *
4354 * <em><valid-lifetime> <pref-lifetime></em> - '<em><valid-lifetime></em>' is the
4355 * length of time in seconds during what the prefix is valid for the purpose of
4356 * on-link determination. Range is 7203 to 2592000 seconds and default is 2592000
4357 * seconds (30 days). '<em><pref-lifetime></em>' is the prefered-lifetime and is the
4358 * length of time in seconds during what addresses generated from the prefix remain
4359 * preferred. Range is 0 to 604800 seconds and default is 604800 seconds (7 days).
4360 *
4361 * <em>infinite</em> - Both '<em><valid-lifetime></em>' and '<em><<pref-lifetime></em>'
4362 * are inifinte, no timeout.
4363 *
4364 * <em>no-advertise</em> - Do not send full router address in prefix
4365 * advertisement. Default is to advertise (i.e. - This flag is off by default).
4366 *
4367 * <em>off-link</em> - Prefix is off-link, clear L-bit in packet. Default is on-link
4368 * (i.e. - This flag is off and L-bit in packet is set by default and this prefix can
4369 * be used for on-link determination). '<em>no-onlink</em>' also controls the L-bit.
4370 *
4371 * <em>no-autoconfig</em> - Do not use prefix for autoconfiguration, clear A-bit in packet.
4372 * Default is autoconfig (i.e. - This flag is off and A-bit in packet is set by default.
4373 *
4374 * <em>no-onlink</em> - Do not use prefix for onlink determination, clear L-bit in packet.
4375 * Default is on-link (i.e. - This flag is off and L-bit in packet is set by default and
4376 * this prefix can be used for on-link determination). '<em>off-link</em>' also controls
4377 * the L-bit.
4378 *
4379 *
4380 * <b>Format 3: - Default of Prefix:</b>
4381 *
4382 * '<em><b>ip6 nd <interface> [no] prefix <ip6-address>/<width> default</b></em>'
4383 *
4384 * When a new prefix is added (or existing one is being overwritten) <em>default</em>
4385 * uses default values for the prefix. If <em>no</em> is used, the <em>default</em>
4386 * is ignored and the prefix is deleted.
4387 *
4388 *
4389 * @cliexpar
4390 * Example of how set a router advertisement option:
4391 * @cliexcmd{ip6 nd GigabitEthernet2/0/0 ra-interval 100 20}
4392 * Example of how to add a prefix:
4393 * @cliexcmd{ip6 nd GigabitEthernet2/0/0 prefix fe80::fe:28ff:fe9c:75b3/64 infinite no-advertise}
4394 * Example of how to delete a prefix:
4395 * @cliexcmd{ip6 nd GigabitEthernet2/0/0 no prefix fe80::fe:28ff:fe9c:75b3/64}
4396?*/
4397/* *INDENT-OFF* */
Dave Barachd7cb1b52016-12-09 09:52:16 -05004398VLIB_CLI_COMMAND (ip6_nd_command, static) =
4399{
Ed Warnickecb9cada2015-12-08 15:45:58 -07004400 .path = "ip6 nd",
Billy McFall0683c9c2016-10-13 08:27:31 -04004401 .short_help = "ip6 nd <interface> ...",
Ed Warnickecb9cada2015-12-08 15:45:58 -07004402 .function = ip6_neighbor_cmd,
4403};
Billy McFall0683c9c2016-10-13 08:27:31 -04004404/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07004405
4406clib_error_t *
Dave Barachd7cb1b52016-12-09 09:52:16 -05004407set_ip6_link_local_address (vlib_main_t * vm,
Neale Ranns75152282017-01-09 01:00:45 -08004408 u32 sw_if_index, ip6_address_t * address)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004409{
Dave Barachd7cb1b52016-12-09 09:52:16 -05004410 clib_error_t *error = 0;
4411 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004412 u32 ri;
Dave Barachd7cb1b52016-12-09 09:52:16 -05004413 ip6_radv_t *radv_info;
4414 vnet_main_t *vnm = vnet_get_main ();
Ed Warnickecb9cada2015-12-08 15:45:58 -07004415
Dave Barachd7cb1b52016-12-09 09:52:16 -05004416 if (!ip6_address_is_link_local_unicast (address))
Ed Warnickecb9cada2015-12-08 15:45:58 -07004417 {
4418 vnm->api_errno = VNET_API_ERROR_ADDRESS_NOT_LINK_LOCAL;
Dave Barachd7cb1b52016-12-09 09:52:16 -05004419 return (error = clib_error_return (0, "address not link-local",
4420 format_unformat_error));
Ed Warnickecb9cada2015-12-08 15:45:58 -07004421 }
4422
4423 /* call enable ipv6 */
Dave Barachd7cb1b52016-12-09 09:52:16 -05004424 enable_ip6_interface (vm, sw_if_index);
4425
Ed Warnickecb9cada2015-12-08 15:45:58 -07004426 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
Dave Barachd7cb1b52016-12-09 09:52:16 -05004427
4428 if (ri != ~0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004429 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05004430 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004431
4432 /* save if link local address (overwrite default) */
Dave Barachd7cb1b52016-12-09 09:52:16 -05004433
Ed Warnickecb9cada2015-12-08 15:45:58 -07004434 /* delete the old one */
4435 error = ip6_add_del_interface_address (vm, sw_if_index,
4436 &radv_info->link_local_address,
Neale Ranns75152282017-01-09 01:00:45 -08004437 128, 1 /* is_del */ );
Dave Barachd7cb1b52016-12-09 09:52:16 -05004438
4439 if (!error)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004440 {
4441 /* add the new one */
4442 error = ip6_add_del_interface_address (vm, sw_if_index,
Neale Ranns75152282017-01-09 01:00:45 -08004443 address, 128,
Dave Barachd7cb1b52016-12-09 09:52:16 -05004444 0 /* is_del */ );
4445
4446 if (!error)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004447 {
4448 radv_info->link_local_address = *address;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004449 }
4450 }
4451 }
4452 else
4453 {
4454 vnm->api_errno = VNET_API_ERROR_IP6_NOT_ENABLED;
4455 error = clib_error_return (0, "ip6 not enabled for interface",
4456 format_unformat_error);
4457 }
4458 return error;
4459}
Dave Barachd7cb1b52016-12-09 09:52:16 -05004460
Ed Warnickecb9cada2015-12-08 15:45:58 -07004461clib_error_t *
4462set_ip6_link_local_address_cmd (vlib_main_t * vm,
4463 unformat_input_t * input,
4464 vlib_cli_command_t * cmd)
4465{
Dave Barachd7cb1b52016-12-09 09:52:16 -05004466 vnet_main_t *vnm = vnet_get_main ();
4467 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004468 u32 sw_if_index;
4469 ip6_address_t ip6_addr;
Dave Barachd7cb1b52016-12-09 09:52:16 -05004470
4471 if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -07004472 {
4473 /* get the rest of the command */
4474 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
4475 {
Neale Ranns75152282017-01-09 01:00:45 -08004476 if (unformat (input, "%U", unformat_ip6_address, &ip6_addr))
Ed Warnickecb9cada2015-12-08 15:45:58 -07004477 break;
4478 else
Dave Barachd7cb1b52016-12-09 09:52:16 -05004479 return (unformat_parse_error (input));
Ed Warnickecb9cada2015-12-08 15:45:58 -07004480 }
4481 }
Neale Ranns75152282017-01-09 01:00:45 -08004482 error = set_ip6_link_local_address (vm, sw_if_index, &ip6_addr);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004483 return error;
4484}
4485
Billy McFall0683c9c2016-10-13 08:27:31 -04004486/*?
4487 * This command is used to assign an IPv6 Link-local address to an
4488 * interface. This command will enable IPv6 on an interface if it
4489 * is not already enabled. Use the '<em>show ip6 interface</em>' command
4490 * to display the assigned Link-local address.
4491 *
4492 * @cliexpar
4493 * Example of how to assign an IPv6 Link-local address to an interface:
Neale Ranns75152282017-01-09 01:00:45 -08004494 * @cliexcmd{set ip6 link-local address GigabitEthernet2/0/0 FE80::AB8}
Billy McFall0683c9c2016-10-13 08:27:31 -04004495?*/
4496/* *INDENT-OFF* */
Dave Barachd7cb1b52016-12-09 09:52:16 -05004497VLIB_CLI_COMMAND (set_ip6_link_local_address_command, static) =
4498{
Ed Warnickecb9cada2015-12-08 15:45:58 -07004499 .path = "set ip6 link-local address",
Neale Ranns75152282017-01-09 01:00:45 -08004500 .short_help = "set ip6 link-local address <interface> <ip6-address>",
Ed Warnickecb9cada2015-12-08 15:45:58 -07004501 .function = set_ip6_link_local_address_cmd,
4502};
Billy McFall0683c9c2016-10-13 08:27:31 -04004503/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07004504
Neale Ranns87df12d2017-02-18 08:16:41 -08004505/**
4506 * @brief callback when an interface address is added or deleted
4507 */
Ed Warnickecb9cada2015-12-08 15:45:58 -07004508static void
4509ip6_neighbor_add_del_interface_address (ip6_main_t * im,
4510 uword opaque,
4511 u32 sw_if_index,
4512 ip6_address_t * address,
4513 u32 address_length,
Dave Barachd7cb1b52016-12-09 09:52:16 -05004514 u32 if_address_index, u32 is_delete)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004515{
Dave Barachd7cb1b52016-12-09 09:52:16 -05004516 vnet_main_t *vnm = vnet_get_main ();
4517 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004518 u32 ri;
Dave Barachd7cb1b52016-12-09 09:52:16 -05004519 vlib_main_t *vm = vnm->vlib_main;
4520 ip6_radv_t *radv_info;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004521 ip6_address_t a;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004522
4523 /* create solicited node multicast address for this interface adddress */
4524 ip6_set_solicited_node_multicast_address (&a, 0);
Dave Barachd7cb1b52016-12-09 09:52:16 -05004525
Ed Warnickecb9cada2015-12-08 15:45:58 -07004526 a.as_u8[0xd] = address->as_u8[0xd];
4527 a.as_u8[0xe] = address->as_u8[0xe];
4528 a.as_u8[0xf] = address->as_u8[0xf];
Dave Barachd7cb1b52016-12-09 09:52:16 -05004529
4530 if (!is_delete)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004531 {
4532 /* try to create radv_info - does nothing if ipv6 already enabled */
Dave Barachd7cb1b52016-12-09 09:52:16 -05004533 enable_ip6_interface (vm, sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004534
4535 /* look up the radv_t information for this interface */
Dave Barachd7cb1b52016-12-09 09:52:16 -05004536 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index,
4537 sw_if_index, ~0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004538 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
Dave Barachd7cb1b52016-12-09 09:52:16 -05004539 if (ri != ~0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004540 {
4541 /* get radv_info */
4542 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
4543
4544 /* add address */
Dave Barachd7cb1b52016-12-09 09:52:16 -05004545 if (!ip6_address_is_link_local_unicast (address))
Ed Warnickecb9cada2015-12-08 15:45:58 -07004546 radv_info->ref_count++;
4547
Neale Ranns87df12d2017-02-18 08:16:41 -08004548 ip6_neighbor_add_mld_prefix (radv_info, &a);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004549 }
4550 }
4551 else
4552 {
4553
4554 /* delete */
4555 /* look up the radv_t information for this interface */
Dave Barachd7cb1b52016-12-09 09:52:16 -05004556 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index,
4557 sw_if_index, ~0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004558 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
Wojciech Dec7bc73102017-02-14 16:24:28 +01004559
Dave Barachd7cb1b52016-12-09 09:52:16 -05004560 if (ri != ~0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004561 {
4562 /* get radv_info */
4563 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
4564
Neale Ranns87df12d2017-02-18 08:16:41 -08004565 ip6_neighbor_del_mld_prefix (radv_info, &a);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004566
4567 /* if interface up send MLDP "report" */
4568 radv_info->all_routers_mcast = 0;
4569
4570 /* add address */
Dave Barachd7cb1b52016-12-09 09:52:16 -05004571 if (!ip6_address_is_link_local_unicast (address))
Ed Warnickecb9cada2015-12-08 15:45:58 -07004572 radv_info->ref_count--;
4573 }
Wojciech Dec7bc73102017-02-14 16:24:28 +01004574 /* Ensure that IPv6 is disabled, and LL removed after ref_count reaches 0 */
4575 disable_ip6_interface (vm, sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004576 }
4577}
4578
Dave Barachd7cb1b52016-12-09 09:52:16 -05004579clib_error_t *
4580ip6_set_neighbor_limit (u32 neighbor_limit)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004581{
Dave Barachd7cb1b52016-12-09 09:52:16 -05004582 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07004583
4584 nm->limit_neighbor_cache_size = neighbor_limit;
4585 return 0;
4586}
4587
Neale Ranns15002542017-09-10 04:39:11 -07004588static void
4589ip6_neighbor_table_bind (ip6_main_t * im,
4590 uword opaque,
4591 u32 sw_if_index,
4592 u32 new_fib_index, u32 old_fib_index)
4593{
4594 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
4595 ip6_neighbor_t *n = NULL;
4596 u32 i, *to_re_add = 0;
4597
4598 /* *INDENT-OFF* */
4599 pool_foreach (n, nm->neighbor_pool,
4600 ({
4601 if (n->key.sw_if_index == sw_if_index)
4602 vec_add1 (to_re_add, n - nm->neighbor_pool);
4603 }));
4604 /* *INDENT-ON* */
4605
4606 for (i = 0; i < vec_len (to_re_add); i++)
4607 {
4608 n = pool_elt_at_index (nm->neighbor_pool, to_re_add[i]);
4609 ip6_neighbor_adj_fib_remove (n, old_fib_index);
4610 ip6_neighbor_adj_fib_add (n, new_fib_index);
4611 }
4612 vec_free (to_re_add);
4613}
4614
Dave Barachd7cb1b52016-12-09 09:52:16 -05004615static clib_error_t *
4616ip6_neighbor_init (vlib_main_t * vm)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004617{
Dave Barachd7cb1b52016-12-09 09:52:16 -05004618 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
4619 ip6_main_t *im = &ip6_main;
4620
Ed Warnickecb9cada2015-12-08 15:45:58 -07004621 mhash_init (&nm->neighbor_index_by_key,
4622 /* value size */ sizeof (uword),
4623 /* key size */ sizeof (ip6_neighbor_key_t));
4624
Dave Barachd7cb1b52016-12-09 09:52:16 -05004625 icmp6_register_type (vm, ICMP6_neighbor_solicitation,
4626 ip6_icmp_neighbor_solicitation_node.index);
4627 icmp6_register_type (vm, ICMP6_neighbor_advertisement,
4628 ip6_icmp_neighbor_advertisement_node.index);
4629 icmp6_register_type (vm, ICMP6_router_solicitation,
4630 ip6_icmp_router_solicitation_node.index);
4631 icmp6_register_type (vm, ICMP6_router_advertisement,
4632 ip6_icmp_router_advertisement_node.index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07004633
4634 /* handler node for ip6 neighbor discovery events and timers */
4635 vlib_register_node (vm, &ip6_icmp_neighbor_discovery_event_node);
4636
4637 /* add call backs */
Dave Barachd7cb1b52016-12-09 09:52:16 -05004638 ip6_add_del_interface_address_callback_t cb;
4639 memset (&cb, 0x0, sizeof (ip6_add_del_interface_address_callback_t));
4640
Ed Warnickecb9cada2015-12-08 15:45:58 -07004641 /* when an interface address changes... */
4642 cb.function = ip6_neighbor_add_del_interface_address;
4643 cb.function_opaque = 0;
4644 vec_add1 (im->add_del_interface_address_callbacks, cb);
4645
Neale Ranns15002542017-09-10 04:39:11 -07004646 ip6_table_bind_callback_t cbt;
4647 cbt.function = ip6_neighbor_table_bind;
4648 cbt.function_opaque = 0;
4649 vec_add1 (im->table_bind_callbacks, cbt);
4650
Ed Warnickecb9cada2015-12-08 15:45:58 -07004651 mhash_init (&nm->pending_resolutions_by_address,
4652 /* value size */ sizeof (uword),
4653 /* key size */ sizeof (ip6_address_t));
4654
John Lo1edfba92016-08-27 01:11:57 -04004655 mhash_init (&nm->mac_changes_by_address,
4656 /* value size */ sizeof (uword),
4657 /* key size */ sizeof (ip6_address_t));
4658
Ed Warnickecb9cada2015-12-08 15:45:58 -07004659 /* default, configurable */
4660 nm->limit_neighbor_cache_size = 50000;
4661
Eyal Baric125ecc2017-09-20 11:29:17 +03004662 nm->wc_ip6_nd_publisher_node = (uword) ~ 0;
4663
Juraj Sloboda4b9669d2018-01-15 10:39:21 +01004664 nm->ip6_ra_publisher_node = (uword) ~ 0;
4665
Ed Warnickecb9cada2015-12-08 15:45:58 -07004666#if 0
4667 /* $$$$ Hack fix for today */
Dave Barachd7cb1b52016-12-09 09:52:16 -05004668 vec_validate_init_empty
4669 (im->discover_neighbor_next_index_by_hw_if_index, 32, 0 /* drop */ );
Ed Warnickecb9cada2015-12-08 15:45:58 -07004670#endif
4671
Ed Warnickecb9cada2015-12-08 15:45:58 -07004672 return 0;
4673}
4674
4675VLIB_INIT_FUNCTION (ip6_neighbor_init);
4676
4677
Dave Barachd7cb1b52016-12-09 09:52:16 -05004678void
4679vnet_register_ip6_neighbor_resolution_event (vnet_main_t * vnm,
4680 void *address_arg,
4681 uword node_index,
4682 uword type_opaque, uword data)
Ed Warnickecb9cada2015-12-08 15:45:58 -07004683{
Dave Barachd7cb1b52016-12-09 09:52:16 -05004684 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
4685 ip6_address_t *address = address_arg;
4686 uword *p;
4687 pending_resolution_t *pr;
4688
Ed Warnickecb9cada2015-12-08 15:45:58 -07004689 pool_get (nm->pending_resolutions, pr);
4690
4691 pr->next_index = ~0;
4692 pr->node_index = node_index;
4693 pr->type_opaque = type_opaque;
4694 pr->data = data;
4695
4696 p = mhash_get (&nm->pending_resolutions_by_address, address);
4697 if (p)
4698 {
4699 /* Insert new resolution at the head of the list */
4700 pr->next_index = p[0];
4701 mhash_unset (&nm->pending_resolutions_by_address, address, 0);
4702 }
Dave Barachd7cb1b52016-12-09 09:52:16 -05004703
4704 mhash_set (&nm->pending_resolutions_by_address, address,
4705 pr - nm->pending_resolutions, 0 /* old value */ );
Ed Warnickecb9cada2015-12-08 15:45:58 -07004706}
4707
Dave Barachd7cb1b52016-12-09 09:52:16 -05004708int
4709vnet_add_del_ip6_nd_change_event (vnet_main_t * vnm,
4710 void *data_callback,
4711 u32 pid,
4712 void *address_arg,
4713 uword node_index,
4714 uword type_opaque, uword data, int is_add)
John Lo1edfba92016-08-27 01:11:57 -04004715{
Dave Barachd7cb1b52016-12-09 09:52:16 -05004716 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
4717 ip6_address_t *address = address_arg;
Dave Barachd7cb1b52016-12-09 09:52:16 -05004718
Eyal Barif9f40652017-04-01 03:55:08 +03004719 /* Try to find an existing entry */
4720 u32 *first = (u32 *) mhash_get (&nm->mac_changes_by_address, address);
4721 u32 *p = first;
4722 pending_resolution_t *mc;
4723 while (p && *p != ~0)
4724 {
4725 mc = pool_elt_at_index (nm->mac_changes, *p);
4726 if (mc->node_index == node_index && mc->type_opaque == type_opaque
4727 && mc->pid == pid)
4728 break;
4729 p = &mc->next_index;
4730 }
4731
4732 int found = p && *p != ~0;
John Lo1edfba92016-08-27 01:11:57 -04004733 if (is_add)
4734 {
Eyal Barif9f40652017-04-01 03:55:08 +03004735 if (found)
4736 return VNET_API_ERROR_ENTRY_ALREADY_EXISTS;
4737
John Lo1edfba92016-08-27 01:11:57 -04004738 pool_get (nm->mac_changes, mc);
Eyal Barif9f40652017-04-01 03:55:08 +03004739 *mc = (pending_resolution_t)
4740 {
4741 .next_index = ~0,.node_index = node_index,.type_opaque =
4742 type_opaque,.data = data,.data_callback = data_callback,.pid =
4743 pid,};
John Lo1edfba92016-08-27 01:11:57 -04004744
Eyal Barif9f40652017-04-01 03:55:08 +03004745 /* Insert new resolution at the end of the list */
4746 u32 new_idx = mc - nm->mac_changes;
John Lo1edfba92016-08-27 01:11:57 -04004747 if (p)
Eyal Barif9f40652017-04-01 03:55:08 +03004748 p[0] = new_idx;
4749 else
4750 mhash_set (&nm->mac_changes_by_address, address, new_idx, 0);
John Lo1edfba92016-08-27 01:11:57 -04004751 }
4752 else
4753 {
Eyal Barif9f40652017-04-01 03:55:08 +03004754 if (!found)
Dave Barachd7cb1b52016-12-09 09:52:16 -05004755 return VNET_API_ERROR_NO_SUCH_ENTRY;
John Lo1edfba92016-08-27 01:11:57 -04004756
Eyal Barif9f40652017-04-01 03:55:08 +03004757 /* Clients may need to clean up pool entries, too */
4758 void (*fp) (u32, u8 *) = data_callback;
4759 if (fp)
4760 (*fp) (mc->data, 0 /* no new mac addrs */ );
John Lo1edfba92016-08-27 01:11:57 -04004761
Eyal Barif9f40652017-04-01 03:55:08 +03004762 /* Remove the entry from the list and delete the entry */
4763 *p = mc->next_index;
4764 pool_put (nm->mac_changes, mc);
Dave Barachd7cb1b52016-12-09 09:52:16 -05004765
Eyal Barif9f40652017-04-01 03:55:08 +03004766 /* Remove from hash if we deleted the last entry */
4767 if (*p == ~0 && p == first)
4768 mhash_unset (&nm->mac_changes_by_address, address, 0);
John Lo1edfba92016-08-27 01:11:57 -04004769 }
Eyal Barif9f40652017-04-01 03:55:08 +03004770 return 0;
John Lo1edfba92016-08-27 01:11:57 -04004771}
4772
Dave Barachd7cb1b52016-12-09 09:52:16 -05004773int
4774vnet_ip6_nd_term (vlib_main_t * vm,
4775 vlib_node_runtime_t * node,
4776 vlib_buffer_t * p0,
4777 ethernet_header_t * eth,
Eyal Baria0623f82017-03-30 03:05:06 +03004778 ip6_header_t * ip, u32 sw_if_index, u16 bd_index)
John Lo1edfba92016-08-27 01:11:57 -04004779{
Dave Barachd7cb1b52016-12-09 09:52:16 -05004780 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
4781 icmp6_neighbor_solicitation_or_advertisement_header_t *ndh;
John Lo1edfba92016-08-27 01:11:57 -04004782
4783 ndh = ip6_next_header (ip);
4784 if (ndh->icmp.type != ICMP6_neighbor_solicitation &&
4785 ndh->icmp.type != ICMP6_neighbor_advertisement)
Dave Barachd7cb1b52016-12-09 09:52:16 -05004786 return 0;
John Lo1edfba92016-08-27 01:11:57 -04004787
4788 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) &&
4789 (p0->flags & VLIB_BUFFER_IS_TRACED)))
4790 {
4791 u8 *t0 = vlib_add_trace (vm, node, p0,
4792 sizeof (icmp6_input_trace_t));
4793 clib_memcpy (t0, ip, sizeof (icmp6_input_trace_t));
4794 }
4795
4796 /* Check if anyone want ND events for L2 BDs */
Eyal Baric125ecc2017-09-20 11:29:17 +03004797 if (PREDICT_FALSE
4798 (nm->wc_ip6_nd_publisher_node != (uword) ~ 0
4799 && !ip6_address_is_link_local_unicast (&ip->src_address)))
Dave Barachd7cb1b52016-12-09 09:52:16 -05004800 {
Eyal Baric125ecc2017-09-20 11:29:17 +03004801 vnet_nd_wc_publish (sw_if_index, eth->src_address, &ip->src_address);
John Lo1edfba92016-08-27 01:11:57 -04004802 }
4803
4804 /* Check if MAC entry exsist for solicited target IP */
4805 if (ndh->icmp.type == ICMP6_neighbor_solicitation)
4806 {
Dave Barachd7cb1b52016-12-09 09:52:16 -05004807 icmp6_neighbor_discovery_ethernet_link_layer_address_option_t *opt;
John Lo1edfba92016-08-27 01:11:57 -04004808 l2_bridge_domain_t *bd_config;
Dave Barachd7cb1b52016-12-09 09:52:16 -05004809 u8 *macp;
John Lo1edfba92016-08-27 01:11:57 -04004810
4811 opt = (void *) (ndh + 1);
Dave Barachd7cb1b52016-12-09 09:52:16 -05004812 if ((opt->header.type !=
John Lo1edfba92016-08-27 01:11:57 -04004813 ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address) ||
4814 (opt->header.n_data_u64s != 1))
Dave Barachd7cb1b52016-12-09 09:52:16 -05004815 return 0; /* source link layer address option not present */
4816
John Lo1edfba92016-08-27 01:11:57 -04004817 bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index);
Dave Barachd7cb1b52016-12-09 09:52:16 -05004818 macp =
4819 (u8 *) hash_get_mem (bd_config->mac_by_ip6, &ndh->target_address);
John Lo1edfba92016-08-27 01:11:57 -04004820 if (macp)
Dave Barachd7cb1b52016-12-09 09:52:16 -05004821 { /* found ip-mac entry, generate eighbor advertisement response */
John Lo1edfba92016-08-27 01:11:57 -04004822 int bogus_length;
Dave Barachd7cb1b52016-12-09 09:52:16 -05004823 vlib_node_runtime_t *error_node =
4824 vlib_node_get_runtime (vm, ip6_icmp_input_node.index);
John Lo1edfba92016-08-27 01:11:57 -04004825 ip->dst_address = ip->src_address;
4826 ip->src_address = ndh->target_address;
4827 ip->hop_limit = 255;
4828 opt->header.type =
Dave Barachd7cb1b52016-12-09 09:52:16 -05004829 ICMP6_NEIGHBOR_DISCOVERY_OPTION_target_link_layer_address;
John Lo1edfba92016-08-27 01:11:57 -04004830 clib_memcpy (opt->ethernet_address, macp, 6);
4831 ndh->icmp.type = ICMP6_neighbor_advertisement;
4832 ndh->advertisement_flags = clib_host_to_net_u32
Dave Barachd7cb1b52016-12-09 09:52:16 -05004833 (ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_SOLICITED |
4834 ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_OVERRIDE);
John Lo1edfba92016-08-27 01:11:57 -04004835 ndh->icmp.checksum = 0;
Dave Barachd7cb1b52016-12-09 09:52:16 -05004836 ndh->icmp.checksum =
4837 ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip, &bogus_length);
4838 clib_memcpy (eth->dst_address, eth->src_address, 6);
4839 clib_memcpy (eth->src_address, macp, 6);
4840 vlib_error_count (vm, error_node->node_index,
John Lo1edfba92016-08-27 01:11:57 -04004841 ICMP6_ERROR_NEIGHBOR_ADVERTISEMENTS_TX, 1);
Dave Barachd7cb1b52016-12-09 09:52:16 -05004842 return 1;
4843 }
John Lo1edfba92016-08-27 01:11:57 -04004844 }
4845
4846 return 0;
4847
4848}
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02004849
Neale Ranns3f844d02017-02-18 00:03:54 -08004850int
4851ip6_neighbor_proxy_add_del (u32 sw_if_index, ip6_address_t * addr, u8 is_del)
4852{
4853 u32 fib_index;
4854
4855 fib_prefix_t pfx = {
4856 .fp_len = 128,
4857 .fp_proto = FIB_PROTOCOL_IP6,
4858 .fp_addr = {
4859 .ip6 = *addr,
4860 },
4861 };
4862 ip46_address_t nh = {
4863 .ip6 = *addr,
4864 };
4865
4866 fib_index = ip6_fib_table_get_index_for_sw_if_index (sw_if_index);
4867
4868 if (~0 == fib_index)
4869 return VNET_API_ERROR_NO_SUCH_FIB;
4870
4871 if (is_del)
4872 {
4873 fib_table_entry_path_remove (fib_index,
4874 &pfx,
4875 FIB_SOURCE_IP6_ND_PROXY,
Neale Rannsda78f952017-05-24 09:15:43 -07004876 DPO_PROTO_IP6,
Neale Ranns3f844d02017-02-18 00:03:54 -08004877 &nh,
4878 sw_if_index,
4879 ~0, 1, FIB_ROUTE_PATH_FLAG_NONE);
4880 /* flush the ND cache of this address if it's there */
4881 vnet_unset_ip6_ethernet_neighbor (vlib_get_main (),
4882 sw_if_index, addr, NULL, 0);
4883 }
4884 else
4885 {
4886 fib_table_entry_path_add (fib_index,
4887 &pfx,
4888 FIB_SOURCE_IP6_ND_PROXY,
4889 FIB_ENTRY_FLAG_NONE,
Neale Rannsda78f952017-05-24 09:15:43 -07004890 DPO_PROTO_IP6,
Neale Ranns3f844d02017-02-18 00:03:54 -08004891 &nh,
4892 sw_if_index,
4893 ~0, 1, NULL, FIB_ROUTE_PATH_FLAG_NONE);
4894 }
4895 return (0);
4896}
4897
4898static clib_error_t *
4899set_ip6_nd_proxy_cmd (vlib_main_t * vm,
4900 unformat_input_t * input, vlib_cli_command_t * cmd)
4901{
4902 vnet_main_t *vnm = vnet_get_main ();
4903 clib_error_t *error = 0;
4904 ip6_address_t addr;
4905 u32 sw_if_index;
4906 u8 is_del = 0;
4907
4908 if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
4909 {
4910 /* get the rest of the command */
4911 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
4912 {
4913 if (unformat (input, "%U", unformat_ip6_address, &addr))
4914 break;
4915 else if (unformat (input, "delete") || unformat (input, "del"))
4916 is_del = 1;
4917 else
4918 return (unformat_parse_error (input));
4919 }
4920 }
4921
4922 ip6_neighbor_proxy_add_del (sw_if_index, &addr, is_del);
4923
4924 return error;
4925}
4926
4927/* *INDENT-OFF* */
4928VLIB_CLI_COMMAND (set_ip6_nd_proxy_command, static) =
4929{
4930 .path = "set ip6 nd proxy",
4931 .short_help = "set ip6 nd proxy <HOST> <INTERFACE>",
4932 .function = set_ip6_nd_proxy_cmd,
4933};
4934/* *INDENT-ON* */
4935
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02004936void
Neale Ranns3be6b282016-12-20 14:24:01 +00004937ethernet_ndp_change_mac (u32 sw_if_index)
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02004938{
Dave Barachd7cb1b52016-12-09 09:52:16 -05004939 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
4940 ip6_neighbor_t *n;
Neale Rannsc819fc62018-02-16 02:44:05 -08004941 adj_index_t ai;
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02004942
4943 /* *INDENT-OFF* */
Dave Barachd7cb1b52016-12-09 09:52:16 -05004944 pool_foreach (n, nm->neighbor_pool,
4945 ({
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02004946 if (n->key.sw_if_index == sw_if_index)
Dave Barachd7cb1b52016-12-09 09:52:16 -05004947 {
Neale Rannsb80c5362016-10-08 13:03:40 +01004948 adj_nbr_walk_nh6 (sw_if_index,
4949 &n->key.ip6_address,
4950 ip6_nd_mk_complete_walk, n);
Dave Barachd7cb1b52016-12-09 09:52:16 -05004951 }
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02004952 }));
4953 /* *INDENT-ON* */
Neale Rannsc819fc62018-02-16 02:44:05 -08004954
4955 ai = adj_glean_get (FIB_PROTOCOL_IP6, sw_if_index);
4956
4957 if (ADJ_INDEX_INVALID != ai)
4958 adj_glean_update_rewrite (ai);
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02004959}
Dave Barachd7cb1b52016-12-09 09:52:16 -05004960
John Lo8b81cb42017-06-26 01:40:20 -04004961void
Neale Ranns25b04942018-04-04 09:34:50 -07004962send_ip6_na (vlib_main_t * vm, const vnet_hw_interface_t * hi)
John Lo8b81cb42017-06-26 01:40:20 -04004963{
4964 ip6_main_t *i6m = &ip6_main;
4965 u32 sw_if_index = hi->sw_if_index;
4966 ip6_address_t *ip6_addr = ip6_interface_first_address (i6m, sw_if_index);
Neale Ranns25b04942018-04-04 09:34:50 -07004967
4968 send_ip6_na_w_addr (vm, ip6_addr, hi);
4969}
4970
4971void
4972send_ip6_na_w_addr (vlib_main_t * vm,
4973 const ip6_address_t * ip6_addr,
4974 const vnet_hw_interface_t * hi)
4975{
4976 ip6_main_t *i6m = &ip6_main;
4977 u32 sw_if_index = hi->sw_if_index;
4978
John Lo8b81cb42017-06-26 01:40:20 -04004979 if (ip6_addr)
4980 {
4981 clib_warning
4982 ("Sending unsolicitated NA IP6 address %U on sw_if_idex %d",
4983 format_ip6_address, ip6_addr, sw_if_index);
4984
4985 /* Form unsolicited neighbor advertisement packet from NS pkt template */
4986 int bogus_length;
4987 u32 bi = 0;
4988 icmp6_neighbor_solicitation_header_t *h =
4989 vlib_packet_template_get_packet (vm,
4990 &i6m->discover_neighbor_packet_template,
4991 &bi);
4992 ip6_set_reserved_multicast_address (&h->ip.dst_address,
4993 IP6_MULTICAST_SCOPE_link_local,
4994 IP6_MULTICAST_GROUP_ID_all_hosts);
4995 h->ip.src_address = ip6_addr[0];
4996 h->neighbor.icmp.type = ICMP6_neighbor_advertisement;
4997 h->neighbor.target_address = ip6_addr[0];
4998 h->neighbor.advertisement_flags = clib_host_to_net_u32
4999 (ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_OVERRIDE);
5000 clib_memcpy (h->link_layer_option.ethernet_address,
5001 hi->hw_address, vec_len (hi->hw_address));
5002 h->neighbor.icmp.checksum =
5003 ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h->ip, &bogus_length);
5004 ASSERT (bogus_length == 0);
5005
5006 /* Setup MAC header with IP6 Etype and mcast DMAC */
5007 vlib_buffer_t *b = vlib_get_buffer (vm, bi);
5008 vlib_buffer_advance (b, -sizeof (ethernet_header_t));
5009 ethernet_header_t *e = vlib_buffer_get_current (b);
5010 e->type = clib_host_to_net_u16 (ETHERNET_TYPE_IP6);
5011 clib_memcpy (e->src_address, hi->hw_address, sizeof (e->src_address));
5012 ip6_multicast_ethernet_address (e->dst_address,
5013 IP6_MULTICAST_GROUP_ID_all_hosts);
5014
5015 /* Send unsolicited ND advertisement packet out the specified interface */
5016 vnet_buffer (b)->sw_if_index[VLIB_RX] =
5017 vnet_buffer (b)->sw_if_index[VLIB_TX] = sw_if_index;
5018 vlib_frame_t *f = vlib_get_frame_to_node (vm, hi->output_node_index);
5019 u32 *to_next = vlib_frame_vector_args (f);
5020 to_next[0] = bi;
5021 f->n_vectors = 1;
5022 vlib_put_frame_to_node (vm, hi->output_node_index, f);
5023 }
5024}
5025
Dave Barachd7cb1b52016-12-09 09:52:16 -05005026/*
5027 * fd.io coding-style-patch-verification: ON
5028 *
5029 * Local Variables:
5030 * eval: (c-set-style "gnu")
5031 * End:
5032 */