blob: c2a7ccacbc118e1941b0da8ad38471dd8cd75c2f [file] [log] [blame]
Neale Rannscbe25aa2019-09-30 10:53:31 +00001/*
2 * Copyright (c) 2019 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#include <vnet/ip/ip6_link.h>
17#include <vnet/ip/ip6_ll_table.h>
18
19#include <vnet/ethernet/ethernet.h>
20#include <vnet/mfib/ip6_mfib.h>
21#include <vnet/adj/adj_mcast.h>
22
23typedef struct ip6_link_delegate_t_
24{
25 u32 ild_sw_if_index;
26 ip6_link_delegate_id_t ild_type;
27 index_t ild_index;
28} ip6_link_delegate_t;
29
30const static ip6_link_delegate_t ip6_link_delegate_uninit = {
31 .ild_sw_if_index = ~0,
32};
33
34typedef struct ip6_link_t_
35{
36 /** interface ip6 is enabled on */
37 u32 il_sw_if_index;
38
39 /** link-local address - if unset that IP6 is disabled*/
40 ip6_address_t il_ll_addr;
41
42 /** list of delegates */
43 ip6_link_delegate_t *il_delegates;
44
45 /** multicast adjacency for this link */
46 adj_index_t il_mcast_adj;
47
48 /** number of references to IP6 enabled on this link */
49 u32 il_locks;
50} ip6_link_t;
51
52#define FOREACH_IP6_LINK_DELEGATE(_ild, _il, body) \
53{ \
54 if (NULL != _il) { \
55 vec_foreach (_ild, _il->il_delegates) { \
56 if (ip6_link_delegate_is_init(_ild)) \
57 body; \
58 } \
59 } \
60}
61
62#define FOREACH_IP6_LINK_DELEGATE_ID(_id) \
63 for (_id = 0; _id < il_delegate_id; _id++)
64
65/** last used delegate ID */
66static ip6_link_delegate_id_t il_delegate_id;
67
68/** VFT registered per-delegate type */
69static ip6_link_delegate_vft_t *il_delegate_vfts;
70
71/** Per interface configs */
72static ip6_link_t *ip6_links;
73
74/** Randomizer */
75static u64 il_randomizer;
76
77/** Logging */
78static vlib_log_class_t ip6_link_logger;
79
80#define IP6_LINK_DBG(...) \
81 vlib_log_debug (ip6_link_logger, __VA_ARGS__);
82
83#define IP6_LINK_INFO(...) \
84 vlib_log_notice (ip6_link_logger, __VA_ARGS__);
85
86static bool
87ip6_link_delegate_is_init (const ip6_link_delegate_t * ild)
88{
89 return (~0 != ild->ild_sw_if_index);
90}
91
92static bool
93ip6_link_is_enabled_i (const ip6_link_t * il)
94{
95 return (!ip6_address_is_zero (&il->il_ll_addr));
96}
97
98static void
99ip6_link_local_address_from_mac (ip6_address_t * ip, const u8 * mac)
100{
101 ip->as_u64[0] = clib_host_to_net_u64 (0xFE80000000000000ULL);
102 /* Invert the "u" bit */
103 ip->as_u8[8] = mac[0] ^ (1 << 1);
104 ip->as_u8[9] = mac[1];
105 ip->as_u8[10] = mac[2];
106 ip->as_u8[11] = 0xFF;
107 ip->as_u8[12] = 0xFE;
108 ip->as_u8[13] = mac[3];
109 ip->as_u8[14] = mac[4];
110 ip->as_u8[15] = mac[5];
111}
112
113static void
114ip6_mac_address_from_link_local (u8 * mac, const ip6_address_t * ip)
115{
116 /* Invert the previously inverted "u" bit */
117 mac[0] = ip->as_u8[8] ^ (1 << 1);
118 mac[1] = ip->as_u8[9];
119 mac[2] = ip->as_u8[10];
120 mac[3] = ip->as_u8[13];
121 mac[4] = ip->as_u8[14];
122 mac[5] = ip->as_u8[15];
123}
124
125static ip6_link_t *
126ip6_link_get (u32 sw_if_index)
127{
128 ip6_link_t *il;
129
130 if (sw_if_index >= vec_len (ip6_links))
131 return (NULL);
132
133 il = &ip6_links[sw_if_index];
134
135 if (!ip6_link_is_enabled_i (il))
136 return (NULL);
137
138 return (il);
139}
140
141bool
142ip6_link_is_enabled (u32 sw_if_index)
143{
144 return (NULL != ip6_link_get (sw_if_index));
145}
146
147
148int
Neale Rannsec40a7d2020-04-23 07:36:12 +0000149ip6_link_enable (u32 sw_if_index, const ip6_address_t * link_local_addr)
Neale Rannscbe25aa2019-09-30 10:53:31 +0000150{
151 ip6_link_t *il;
152 int rv;
153
154 il = ip6_link_get (sw_if_index);
155
156 if (NULL == il)
157 {
Neale Rannsdfef64b2021-05-20 16:28:12 +0000158 const vnet_sw_interface_t *sw_sup;
Neale Rannscbe25aa2019-09-30 10:53:31 +0000159 const ethernet_interface_t *eth;
160 vnet_main_t *vnm;
161
Neale Rannsdfef64b2021-05-20 16:28:12 +0000162 eth = NULL;
Neale Rannscbe25aa2019-09-30 10:53:31 +0000163 vnm = vnet_get_main ();
164
165 IP6_LINK_INFO ("enable: %U",
166 format_vnet_sw_if_index_name, vnm, sw_if_index);
167
168 sw_sup = vnet_get_sup_sw_interface (vnm, sw_if_index);
Neale Rannscbe25aa2019-09-30 10:53:31 +0000169 vec_validate (ip6_links, sw_if_index);
170
171 il = &ip6_links[sw_if_index];
Neale Rannsc96ac762020-10-12 11:46:53 +0000172 il->il_locks = 0;
Neale Rannscbe25aa2019-09-30 10:53:31 +0000173 il->il_sw_if_index = sw_if_index;
Neale Rannsdfef64b2021-05-20 16:28:12 +0000174 il->il_mcast_adj = ADJ_INDEX_INVALID;
Neale Rannscbe25aa2019-09-30 10:53:31 +0000175
Neale Rannsdfef64b2021-05-20 16:28:12 +0000176 if (sw_sup->type == VNET_SW_INTERFACE_TYPE_HARDWARE)
177 eth = ethernet_get_interface (&ethernet_main, sw_sup->hw_if_index);
Neale Rannscbe25aa2019-09-30 10:53:31 +0000178
Neale Rannsdfef64b2021-05-20 16:28:12 +0000179 /* use a user provided LL address if given */
Neale Rannsec40a7d2020-04-23 07:36:12 +0000180 if (NULL != link_local_addr)
181 ip6_address_copy (&il->il_ll_addr, link_local_addr);
Neale Rannsdfef64b2021-05-20 16:28:12 +0000182
183 /* generate from ethernet MAC */
184 if (ip6_address_is_zero (&il->il_ll_addr) && NULL != eth)
185 ip6_link_local_address_from_mac (&il->il_ll_addr,
186 eth->address.mac.bytes);
187
188 /* choose a random address */
189 if (ip6_address_is_zero (&il->il_ll_addr))
Neale Rannscbe25aa2019-09-30 10:53:31 +0000190 {
191 il->il_ll_addr.as_u64[0] =
192 clib_host_to_net_u64 (0xFE80000000000000ULL);
193
194 /* make up an interface id */
195 il->il_ll_addr.as_u64[1] = random_u64 (&il_randomizer);
196
197 /* clear u bit */
198 il->il_ll_addr.as_u8[8] &= 0xfd;
199 }
Neale Rannscbe25aa2019-09-30 10:53:31 +0000200
201 {
202 ip6_ll_prefix_t ilp = {
203 .ilp_addr = il->il_ll_addr,
204 .ilp_sw_if_index = sw_if_index,
205 };
206
207 ip6_ll_table_entry_update (&ilp, FIB_ROUTE_PATH_LOCAL);
208 }
209
210 /* essentially "enables" ipv6 on this interface */
211 ip6_mfib_interface_enable_disable (sw_if_index, 1);
212 ip6_sw_interface_enable_disable (sw_if_index, 1);
213
Neale Rannsdfef64b2021-05-20 16:28:12 +0000214 /* only ehternet interfaces support MLD and RA, which use the mcast adj
215 */
216 if (NULL != eth)
217 il->il_mcast_adj =
218 adj_mcast_add_or_lock (FIB_PROTOCOL_IP6, VNET_LINK_IP6, sw_if_index);
Neale Rannscbe25aa2019-09-30 10:53:31 +0000219
220 /* inform all register clients */
221 ip6_link_delegate_id_t id;
222 FOREACH_IP6_LINK_DELEGATE_ID (id)
223 {
224 if (NULL != il_delegate_vfts[id].ildv_enable)
225 il_delegate_vfts[id].ildv_enable (il->il_sw_if_index);
226 }
227
228 rv = 0;
229 }
230 else
231 {
232 rv = VNET_API_ERROR_VALUE_EXIST;
233 }
234
Neale Rannsc96ac762020-10-12 11:46:53 +0000235 il->il_locks++;
236
Neale Rannscbe25aa2019-09-30 10:53:31 +0000237 return (rv);
238}
239
240static void
241ip6_link_delegate_flush (ip6_link_t * il)
242{
243 ip6_link_delegate_t *ild;
244
Neale Ranns306c3082020-01-01 21:55:41 +0000245 FOREACH_IP6_LINK_DELEGATE (ild, il,
246 ({
247 il_delegate_vfts[ild->ild_type].ildv_disable(ild->ild_index);
248 }));
Neale Rannscbe25aa2019-09-30 10:53:31 +0000249
250 vec_free (il->il_delegates);
251 il->il_delegates = NULL;
252}
253
254static void
255ip6_link_last_lock_gone (ip6_link_t * il)
256{
257 ip6_ll_prefix_t ilp = {
258 .ilp_addr = il->il_ll_addr,
259 .ilp_sw_if_index = il->il_sw_if_index,
260 };
261
262 IP6_LINK_INFO ("last-lock: %U",
263 format_vnet_sw_if_index_name,
264 vnet_get_main (), il->il_sw_if_index);
265
266 ip6_link_delegate_flush (il);
267 ip6_ll_table_entry_delete (&ilp);
268
269 ip6_mfib_interface_enable_disable (il->il_sw_if_index, 0);
270 ip6_sw_interface_enable_disable (il->il_sw_if_index, 0);
271
272 ip6_address_set_zero (&il->il_ll_addr);
273 adj_unlock (il->il_mcast_adj);
274 il->il_mcast_adj = ADJ_INDEX_INVALID;
275}
276
277static void
278ip6_link_unlock (ip6_link_t * il)
279{
280 if (NULL == il)
281 return;
282
283 il->il_locks--;
284
285 if (0 == il->il_locks)
286 ip6_link_last_lock_gone (il);
287}
288
289int
290ip6_link_disable (u32 sw_if_index)
291{
292 ip6_link_t *il;
293
294 il = ip6_link_get (sw_if_index);
295
296 if (NULL == il)
297 return (VNET_API_ERROR_IP6_NOT_ENABLED);
298
299 IP6_LINK_INFO ("disable: %U",
300 format_vnet_sw_if_index_name, vnet_get_main (), sw_if_index);
301
302 ip6_link_unlock (il);
303
304 return (0);
305}
306
307const ip6_address_t *
308ip6_get_link_local_address (u32 sw_if_index)
309{
310 const ip6_link_t *il;
311
Benoît Ganneaea54eb2021-01-18 19:37:55 +0100312 il = ip6_link_get (sw_if_index);
Neale Rannscbe25aa2019-09-30 10:53:31 +0000313
Benoît Ganneaea54eb2021-01-18 19:37:55 +0100314 if (NULL == il)
315 return (NULL);
Neale Rannscbe25aa2019-09-30 10:53:31 +0000316
317 return (&il->il_ll_addr);
318}
319
320adj_index_t
321ip6_link_get_mcast_adj (u32 sw_if_index)
322{
323 const ip6_link_t *il;
324
Benoît Ganneaea54eb2021-01-18 19:37:55 +0100325 il = ip6_link_get (sw_if_index);
326
327 if (NULL == il)
328 return (INDEX_INVALID);
Neale Rannscbe25aa2019-09-30 10:53:31 +0000329
330 return (il->il_mcast_adj);
331}
332
333int
Neale Rannsec40a7d2020-04-23 07:36:12 +0000334ip6_link_set_local_address (u32 sw_if_index, const ip6_address_t * address)
Neale Rannscbe25aa2019-09-30 10:53:31 +0000335{
336 ip6_link_delegate_t *ild;
337 ip6_link_t *il;
338
339 il = ip6_link_get (sw_if_index);
340
341 if (NULL == il)
Neale Rannsec40a7d2020-04-23 07:36:12 +0000342 return ip6_link_enable (sw_if_index, address);
Neale Rannscbe25aa2019-09-30 10:53:31 +0000343
344 ip6_ll_prefix_t ilp = {
345 .ilp_addr = il->il_ll_addr,
346 .ilp_sw_if_index = sw_if_index,
347 };
348
349 IP6_LINK_INFO ("set-ll: %U -> %U",
350 format_vnet_sw_if_index_name, vnet_get_main (), sw_if_index,
351 format_ip6_address, address);
352
353 ip6_ll_table_entry_delete (&ilp);
354 ip6_address_copy (&il->il_ll_addr, address);
355 ip6_address_copy (&ilp.ilp_addr, address);
356 ip6_ll_table_entry_update (&ilp, FIB_ROUTE_PATH_LOCAL);
357
Neale Rannscbe25aa2019-09-30 10:53:31 +0000358 FOREACH_IP6_LINK_DELEGATE (ild, il,
359 ({
360 if (NULL != il_delegate_vfts[ild->ild_type].ildv_ll_change)
361 il_delegate_vfts[ild->ild_type].ildv_ll_change(ild->ild_index,
362 &il->il_ll_addr);
363 }));
Neale Rannscbe25aa2019-09-30 10:53:31 +0000364
365 return (0);
366}
367
368ip6_link_delegate_id_t
369ip6_link_delegate_register (const ip6_link_delegate_vft_t * vft)
370{
371 ip6_link_delegate_id_t rc = il_delegate_id++;
372
373 ASSERT (vft->ildv_disable);
374
375 vec_validate (il_delegate_vfts, rc);
376
377 il_delegate_vfts[rc] = *vft;
378
379 return (rc);
380}
381
382index_t
383ip6_link_delegate_get (u32 sw_if_index, ip6_link_delegate_id_t id)
384{
385 ip6_link_t *il;
386
387 il = ip6_link_get (sw_if_index);
388
389 if (NULL == il)
390 return (INDEX_INVALID);
391
392 vec_validate_init_empty (il->il_delegates, id, ip6_link_delegate_uninit);
393
394 if (!ip6_link_delegate_is_init (&il->il_delegates[id]))
395 return (INDEX_INVALID);
396
397 return (il->il_delegates[id].ild_index);
398}
399
400bool
401ip6_link_delegate_update (u32 sw_if_index,
402 ip6_link_delegate_id_t id, index_t ii)
403{
404 ip6_link_t *il;
405
406 il = ip6_link_get (sw_if_index);
407
408 if (NULL == il)
409 return (false);
410
411 vec_validate_init_empty (il->il_delegates, id, ip6_link_delegate_uninit);
412
413 il->il_delegates[id].ild_sw_if_index = sw_if_index;
414 il->il_delegates[id].ild_type = id;
415 il->il_delegates[id].ild_index = ii;
416
417 return (true);
418}
419
420void
421ip6_link_delegate_remove (u32 sw_if_index,
422 ip6_link_delegate_id_t id, index_t ii)
423{
424 ip6_link_t *il;
425
426 il = ip6_link_get (sw_if_index);
427
428 if (NULL != il)
429 {
430 if (vec_len (il->il_delegates) > id)
431 {
432 clib_memcpy (&il->il_delegates[id],
433 &ip6_link_delegate_uninit,
434 sizeof (il->il_delegates[0]));
435 }
436 }
437}
438
439static void
440ip6_link_add_del_address (ip6_main_t * im,
441 uword opaque,
442 u32 sw_if_index,
443 ip6_address_t * address,
444 u32 address_length,
445 u32 if_address_index, u32 is_delete)
446{
447 const ip6_link_delegate_t *ild;
448 ip6_link_t *il;
449
450 if (ip6_address_is_link_local_unicast (address))
451 // only interested in global addresses here
452 return;
453
454 IP6_LINK_INFO ("addr-%s: %U -> %U",
455 (is_delete ? "del" : "add"),
456 format_vnet_sw_if_index_name, vnet_get_main (), sw_if_index,
457 format_ip6_address, address);
458
459 il = ip6_link_get (sw_if_index);
460
461 if (NULL == il)
462 return;
463
Neale Rannscbe25aa2019-09-30 10:53:31 +0000464 FOREACH_IP6_LINK_DELEGATE (ild, il,
465 ({
466 if (is_delete)
467 {
468 if (NULL != il_delegate_vfts[ild->ild_type].ildv_addr_del)
469 il_delegate_vfts[ild->ild_type].ildv_addr_del(ild->ild_index,
470 address, address_length);
471 }
472 else
473 {
474 if (NULL != il_delegate_vfts[ild->ild_type].ildv_addr_add)
475 il_delegate_vfts[ild->ild_type].ildv_addr_add(ild->ild_index,
476 address, address_length);
477 }
478 }));
Neale Rannscbe25aa2019-09-30 10:53:31 +0000479}
480
481static clib_error_t *
482ip6_link_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add)
483{
484 if (!is_add)
485 {
486 ip6_link_t *il;
487
488 il = ip6_link_get (sw_if_index);
489
490 IP6_LINK_DBG ("link-del: %U",
491 format_vnet_sw_if_index_name, vnet_get_main (),
492 sw_if_index);
493
494 if (NULL != il)
495 /* force cleanup */
496 ip6_link_last_lock_gone (il);
497 }
498
499 return (NULL);
500}
501
502VNET_SW_INTERFACE_ADD_DEL_FUNCTION (ip6_link_interface_add_del);
503
504static clib_error_t *
505ip6_link_init (vlib_main_t * vm)
506{
507 il_randomizer = clib_cpu_time_now ();
508 ip6_link_logger = vlib_log_register_class ("ip6", "link");
509
510 {
511 ip6_add_del_interface_address_callback_t cb = {
512 .function = ip6_link_add_del_address,
513 };
514 vec_add1 (ip6_main.add_del_interface_address_callbacks, cb);
515 }
516 return (NULL);
517}
518
519VLIB_INIT_FUNCTION (ip6_link_init);
520
521
522static clib_error_t *
523test_ip6_link_command_fn (vlib_main_t * vm,
524 unformat_input_t * input, vlib_cli_command_t * cmd)
525{
526 u8 mac[6];
527 ip6_address_t _a, *a = &_a;
528
529 if (unformat (input, "%U", unformat_ethernet_address, mac))
530 {
531 ip6_link_local_address_from_mac (a, mac);
532 vlib_cli_output (vm, "Link local address: %U", format_ip6_address, a);
533 ip6_mac_address_from_link_local (mac, a);
534 vlib_cli_output (vm, "Original MAC address: %U",
535 format_ethernet_address, mac);
536 }
537
538 return 0;
539}
540
541/*?
542 * This command converts the given MAC Address into an IPv6 link-local
543 * address.
544 *
545 * @cliexpar
546 * Example of how to create an IPv6 link-local address:
547 * @cliexstart{test ip6 link 16:d9:e0:91:79:86}
548 * Link local address: fe80::14d9:e0ff:fe91:7986
549 * Original MAC address: 16:d9:e0:91:79:86
550 * @cliexend
551?*/
Neale Rannscbe25aa2019-09-30 10:53:31 +0000552VLIB_CLI_COMMAND (test_link_command, static) =
553{
554 .path = "test ip6 link",
555 .function = test_ip6_link_command_fn,
556 .short_help = "test ip6 link <mac-address>",
557};
Neale Rannscbe25aa2019-09-30 10:53:31 +0000558
559static u8 *
560ip6_print_addrs (u8 * s, u32 * addrs)
561{
562 ip_lookup_main_t *lm = &ip6_main.lookup_main;
563 u32 i;
564
565 for (i = 0; i < vec_len (addrs); i++)
566 {
567 ip_interface_address_t *a =
568 pool_elt_at_index (lm->if_address_pool, addrs[i]);
569 ip6_address_t *address = ip_interface_address_get_address (lm, a);
570
571 s = format (s, "%U%U/%d\n",
572 format_white_space, 4,
573 format_ip6_address, address, a->address_length);
574 }
575
576 return (s);
577}
578
579static u8 *
580format_ip6_link (u8 * s, va_list * arg)
581{
582 const ip6_link_t *il = va_arg (*arg, ip6_link_t *);
583 ip_lookup_main_t *lm = &ip6_main.lookup_main;
584 vnet_main_t *vnm = vnet_get_main ();
585
586 if (!ip6_link_is_enabled_i (il))
587 return (s);
588
Vladislav Grishenkofb9d1ac2022-08-04 20:36:45 +0500589 s = format (
590 s, "%U is admin %s\n", format_vnet_sw_if_index_name, vnm,
591 il->il_sw_if_index,
592 (vnet_sw_interface_is_admin_up (vnm, il->il_sw_if_index) ? "up" : "down"));
Neale Rannscbe25aa2019-09-30 10:53:31 +0000593
594 u32 ai;
595 u32 *link_scope = 0, *global_scope = 0;
596 u32 *local_scope = 0, *unknown_scope = 0;
597 ip_interface_address_t *a;
598 const ip6_link_delegate_t *ild;
599
600 vec_validate_init_empty (lm->if_address_pool_index_by_sw_if_index,
601 il->il_sw_if_index, ~0);
602 ai = lm->if_address_pool_index_by_sw_if_index[il->il_sw_if_index];
603
604 while (ai != (u32) ~ 0)
605 {
606 a = pool_elt_at_index (lm->if_address_pool, ai);
607 ip6_address_t *address = ip_interface_address_get_address (lm, a);
608
609 if (ip6_address_is_link_local_unicast (address))
610 vec_add1 (link_scope, ai);
611 else if (ip6_address_is_global_unicast (address))
612 vec_add1 (global_scope, ai);
613 else if (ip6_address_is_local_unicast (address))
614 vec_add1 (local_scope, ai);
615 else
616 vec_add1 (unknown_scope, ai);
617
618 ai = a->next_this_sw_interface;
619 }
620
621 if (vec_len (link_scope))
622 {
623 s = format (s, "%ULink-local address(es):\n", format_white_space, 2);
624 s = ip6_print_addrs (s, link_scope);
625 vec_free (link_scope);
626 }
627
628 if (vec_len (local_scope))
629 {
630 s = format (s, "%ULocal unicast address(es):\n", format_white_space, 2);
631 s = ip6_print_addrs (s, local_scope);
632 vec_free (local_scope);
633 }
634
635 if (vec_len (global_scope))
636 {
637 s = format (s, "%UGlobal unicast address(es):\n",
638 format_white_space, 2);
639 s = ip6_print_addrs (s, global_scope);
640 vec_free (global_scope);
641 }
642
643 if (vec_len (unknown_scope))
644 {
645 s = format (s, "%UOther-scope address(es):\n", format_white_space, 2);
646 s = ip6_print_addrs (s, unknown_scope);
647 vec_free (unknown_scope);
648 }
649
650 s = format (s, "%ULink-local address(es):\n", format_white_space, 2);
651 s = format (s, "%U%U\n",
652 format_white_space, 4, format_ip6_address, &il->il_ll_addr);
653
Neale Rannscbe25aa2019-09-30 10:53:31 +0000654 FOREACH_IP6_LINK_DELEGATE(ild, il,
655 ({
656 s = format (s, "%U", il_delegate_vfts[ild->ild_type].ildv_format,
657 ild->ild_index, 2);
658 }));
Neale Rannscbe25aa2019-09-30 10:53:31 +0000659
660 return (s);
661}
662
663static clib_error_t *
664ip6_link_show (vlib_main_t * vm,
665 unformat_input_t * input, vlib_cli_command_t * cmd)
666{
667 const ip6_link_t *il;
668 vnet_main_t *vnm;
669 u32 sw_if_index;
670
671 vnm = vnet_get_main ();
672 sw_if_index = ~0;
673
674 if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
675 {
676 il = ip6_link_get (sw_if_index);
677
678 if (NULL == il)
679 {
680 vlib_cli_output (vm, "IP6 disabled");
681 return (NULL);
682 }
683 else
684 vlib_cli_output (vm, "%U", format_ip6_link, il);
685 }
686 else
687 {
688 vec_foreach (il, ip6_links)
689 vlib_cli_output (vm, "%U", format_ip6_link, il);
690 }
691
692 return (NULL);
693}
694
695/*?
696 * This command is used to display various IPv6 attributes on a given
697 * interface.
698 *
699 * @cliexpar
700 * Example of how to display IPv6 settings:
701 * @cliexstart{show ip6 interface GigabitEthernet2/0/0}
702 * GigabitEthernet2/0/0 is admin up
703 * Link-local address(es):
704 * fe80::ab8/64
705 * Joined group address(es):
706 * ff02::1
707 * ff02::2
708 * ff02::16
709 * ff02::1:ff00:ab8
710 * Advertised Prefixes:
711 * prefix fe80::fe:28ff:fe9c:75b3, length 64
712 * MTU is 1500
713 * ICMP error messages are unlimited
714 * ICMP redirects are disabled
715 * ICMP unreachables are not sent
716 * ND DAD is disabled
717 * ND advertised reachable time is 0
718 * ND advertised retransmit interval is 0 (msec)
719 * ND router advertisements are sent every 200 seconds (min interval is 150)
720 * ND router advertisements live for 600 seconds
721 * Hosts use stateless autoconfig for addresses
722 * ND router advertisements sent 19336
723 * ND router solicitations received 0
724 * ND router solicitations dropped 0
725 * @cliexend
726 * Example of output if IPv6 is not enabled on the interface:
727 * @cliexstart{show ip6 interface GigabitEthernet2/0/0}
728 * show ip6 interface: IPv6 not enabled on interface
729 * @cliexend
730?*/
Neale Rannscbe25aa2019-09-30 10:53:31 +0000731VLIB_CLI_COMMAND (ip6_link_show_command, static) =
732{
733 .path = "show ip6 interface",
734 .function = ip6_link_show,
735 .short_help = "show ip6 interface <interface>",
736};
Neale Rannscbe25aa2019-09-30 10:53:31 +0000737
738static clib_error_t *
739enable_ip6_interface_cmd (vlib_main_t * vm,
740 unformat_input_t * input, vlib_cli_command_t * cmd)
741{
742 vnet_main_t *vnm = vnet_get_main ();
743 clib_error_t *error = NULL;
744 u32 sw_if_index;
745
746 sw_if_index = ~0;
747
748 if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
749 {
Neale Rannsec40a7d2020-04-23 07:36:12 +0000750 if (ip6_link_enable (sw_if_index, NULL))
Neale Rannscbe25aa2019-09-30 10:53:31 +0000751 error = clib_error_return (0, "Failed\n");
752 }
753 else
754 {
755 error = clib_error_return (0, "unknown interface\n'",
756 format_unformat_error, input);
757
758 }
759 return error;
760}
761
762/*?
763 * This command is used to enable IPv6 on a given interface.
764 *
765 * @cliexpar
766 * Example of how enable IPv6 on a given interface:
767 * @cliexcmd{enable ip6 interface GigabitEthernet2/0/0}
768?*/
Neale Rannscbe25aa2019-09-30 10:53:31 +0000769VLIB_CLI_COMMAND (enable_ip6_interface_command, static) =
770{
771 .path = "enable ip6 interface",
772 .function = enable_ip6_interface_cmd,
773 .short_help = "enable ip6 interface <interface>",
774};
Neale Rannscbe25aa2019-09-30 10:53:31 +0000775
776static clib_error_t *
777disable_ip6_interface_cmd (vlib_main_t * vm,
778 unformat_input_t * input, vlib_cli_command_t * cmd)
779{
780 vnet_main_t *vnm = vnet_get_main ();
781 clib_error_t *error = NULL;
782 u32 sw_if_index;
783
784 sw_if_index = ~0;
785
786 if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
787 {
788 if (ip6_link_disable (sw_if_index))
789 error = clib_error_return (0, "Failed\n");
790 }
791 else
792 {
793 error = clib_error_return (0, "unknown interface\n'",
794 format_unformat_error, input);
795
796 }
797 return error;
798}
799
800/*?
801 * This command is used to disable IPv6 on a given interface.
802 *
803 * @cliexpar
804 * Example of how disable IPv6 on a given interface:
805 * @cliexcmd{disable ip6 interface GigabitEthernet2/0/0}
806?*/
Neale Rannscbe25aa2019-09-30 10:53:31 +0000807VLIB_CLI_COMMAND (disable_ip6_interface_command, static) =
808{
809 .path = "disable ip6 interface",
810 .function = disable_ip6_interface_cmd,
811 .short_help = "disable ip6 interface <interface>",
812};
Neale Rannscbe25aa2019-09-30 10:53:31 +0000813
814/*
815 * fd.io coding-style-patch-verification: ON
816 *
817 * Local Variables:
818 * eval: (c-set-style "gnu")
819 * End:
820 */