ip: IP6 incorrectly disabled on removing first ip6 prefix
[vpp.git] / src / vnet / ip / ip6_link.c
1 /*
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
23 typedef 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
30 const static ip6_link_delegate_t ip6_link_delegate_uninit = {
31   .ild_sw_if_index = ~0,
32 };
33
34 typedef 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 */
66 static ip6_link_delegate_id_t il_delegate_id;
67
68 /** VFT registered per-delegate type */
69 static ip6_link_delegate_vft_t *il_delegate_vfts;
70
71 /** Per interface configs */
72 static ip6_link_t *ip6_links;
73
74 /** Randomizer */
75 static u64 il_randomizer;
76
77 /** Logging */
78 static 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
86 static bool
87 ip6_link_delegate_is_init (const ip6_link_delegate_t * ild)
88 {
89   return (~0 != ild->ild_sw_if_index);
90 }
91
92 static bool
93 ip6_link_is_enabled_i (const ip6_link_t * il)
94 {
95   return (!ip6_address_is_zero (&il->il_ll_addr));
96 }
97
98 static void
99 ip6_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
113 static void
114 ip6_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
125 static ip6_link_t *
126 ip6_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
141 bool
142 ip6_link_is_enabled (u32 sw_if_index)
143 {
144   return (NULL != ip6_link_get (sw_if_index));
145 }
146
147
148 int
149 ip6_link_enable (u32 sw_if_index, const ip6_address_t * link_local_addr)
150 {
151   ip6_link_t *il;
152   int rv;
153
154   il = ip6_link_get (sw_if_index);
155
156   if (NULL == il)
157     {
158       const vnet_sw_interface_t *sw, *sw_sup;
159       const ethernet_interface_t *eth;
160       vnet_main_t *vnm;
161
162       vnm = vnet_get_main ();
163
164       IP6_LINK_INFO ("enable: %U",
165                      format_vnet_sw_if_index_name, vnm, sw_if_index);
166
167       sw_sup = vnet_get_sup_sw_interface (vnm, sw_if_index);
168       if (sw_sup->type != VNET_SW_INTERFACE_TYPE_HARDWARE)
169         {
170           rv = VNET_API_ERROR_UNSUPPORTED;
171           goto out;
172         }
173
174       eth = ethernet_get_interface (&ethernet_main, sw_sup->hw_if_index);
175
176       if (NULL == eth)
177         {
178           rv = VNET_API_ERROR_UNSUPPORTED;
179           goto out;
180         }
181
182       vec_validate (ip6_links, sw_if_index);
183
184       il = &ip6_links[sw_if_index];
185       il->il_locks = 0;
186       il->il_sw_if_index = sw_if_index;
187
188       sw = vnet_get_sup_sw_interface (vnm, sw_if_index);
189
190       if (NULL != link_local_addr)
191         ip6_address_copy (&il->il_ll_addr, link_local_addr);
192       else if (sw->type == VNET_SW_INTERFACE_TYPE_SUB ||
193                sw->type == VNET_SW_INTERFACE_TYPE_PIPE ||
194                sw->type == VNET_SW_INTERFACE_TYPE_P2P)
195         {
196           il->il_ll_addr.as_u64[0] =
197             clib_host_to_net_u64 (0xFE80000000000000ULL);
198
199           /* make up an interface id */
200           il->il_ll_addr.as_u64[1] = random_u64 (&il_randomizer);
201
202           /* clear u bit */
203           il->il_ll_addr.as_u8[8] &= 0xfd;
204         }
205       else
206         {
207           ip6_link_local_address_from_mac (&il->il_ll_addr, eth->address);
208         }
209
210       {
211         ip6_ll_prefix_t ilp = {
212           .ilp_addr = il->il_ll_addr,
213           .ilp_sw_if_index = sw_if_index,
214         };
215
216         ip6_ll_table_entry_update (&ilp, FIB_ROUTE_PATH_LOCAL);
217       }
218
219       /* essentially "enables" ipv6 on this interface */
220       ip6_mfib_interface_enable_disable (sw_if_index, 1);
221       ip6_sw_interface_enable_disable (sw_if_index, 1);
222
223       il->il_mcast_adj = adj_mcast_add_or_lock (FIB_PROTOCOL_IP6,
224                                                 VNET_LINK_IP6, sw_if_index);
225
226       /* inform all register clients */
227       ip6_link_delegate_id_t id;
228       FOREACH_IP6_LINK_DELEGATE_ID (id)
229       {
230         if (NULL != il_delegate_vfts[id].ildv_enable)
231           il_delegate_vfts[id].ildv_enable (il->il_sw_if_index);
232       }
233
234       rv = 0;
235     }
236   else
237     {
238       rv = VNET_API_ERROR_VALUE_EXIST;
239     }
240
241   il->il_locks++;
242
243 out:
244   return (rv);
245 }
246
247 static void
248 ip6_link_delegate_flush (ip6_link_t * il)
249 {
250   ip6_link_delegate_t *ild;
251
252   /* *INDENT-OFF* */
253   FOREACH_IP6_LINK_DELEGATE (ild, il,
254   ({
255     il_delegate_vfts[ild->ild_type].ildv_disable(ild->ild_index);
256   }));
257   /* *INDENT-ON* */
258
259   vec_free (il->il_delegates);
260   il->il_delegates = NULL;
261 }
262
263 static void
264 ip6_link_last_lock_gone (ip6_link_t * il)
265 {
266   ip6_ll_prefix_t ilp = {
267     .ilp_addr = il->il_ll_addr,
268     .ilp_sw_if_index = il->il_sw_if_index,
269   };
270
271   IP6_LINK_INFO ("last-lock: %U",
272                  format_vnet_sw_if_index_name,
273                  vnet_get_main (), il->il_sw_if_index);
274
275   ip6_link_delegate_flush (il);
276   ip6_ll_table_entry_delete (&ilp);
277
278   ip6_mfib_interface_enable_disable (il->il_sw_if_index, 0);
279   ip6_sw_interface_enable_disable (il->il_sw_if_index, 0);
280
281   ip6_address_set_zero (&il->il_ll_addr);
282   adj_unlock (il->il_mcast_adj);
283   il->il_mcast_adj = ADJ_INDEX_INVALID;
284 }
285
286 static void
287 ip6_link_unlock (ip6_link_t * il)
288 {
289   if (NULL == il)
290     return;
291
292   il->il_locks--;
293
294   if (0 == il->il_locks)
295     ip6_link_last_lock_gone (il);
296 }
297
298 int
299 ip6_link_disable (u32 sw_if_index)
300 {
301   ip6_link_t *il;
302
303   il = ip6_link_get (sw_if_index);
304
305   if (NULL == il)
306     return (VNET_API_ERROR_IP6_NOT_ENABLED);
307
308   IP6_LINK_INFO ("disable: %U",
309                  format_vnet_sw_if_index_name, vnet_get_main (), sw_if_index);
310
311   ip6_link_unlock (il);
312
313   return (0);
314 }
315
316 const ip6_address_t *
317 ip6_get_link_local_address (u32 sw_if_index)
318 {
319   const ip6_link_t *il;
320
321   vec_validate (ip6_links, sw_if_index);
322
323   il = &ip6_links[sw_if_index];
324
325   return (&il->il_ll_addr);
326 }
327
328 adj_index_t
329 ip6_link_get_mcast_adj (u32 sw_if_index)
330 {
331   const ip6_link_t *il;
332
333   il = &ip6_links[sw_if_index];
334
335   return (il->il_mcast_adj);
336 }
337
338 int
339 ip6_src_address_for_packet (u32 sw_if_index,
340                             const ip6_address_t * dst, ip6_address_t * src)
341 {
342   ip_lookup_main_t *lm;
343
344   lm = &ip6_main.lookup_main;
345
346   if (ip6_address_is_link_local_unicast (dst))
347     {
348       ip6_address_copy (src, ip6_get_link_local_address (sw_if_index));
349
350       return (!0);
351     }
352   else
353     {
354       u32 if_add_index =
355         lm->if_address_pool_index_by_sw_if_index[sw_if_index];
356       if (PREDICT_TRUE (if_add_index != ~0))
357         {
358           ip_interface_address_t *if_add =
359             pool_elt_at_index (lm->if_address_pool, if_add_index);
360           ip6_address_t *if_ip =
361             ip_interface_address_get_address (lm, if_add);
362           *src = *if_ip;
363           return (!0);
364         }
365     }
366
367   src->as_u64[0] = 0;
368   src->as_u64[1] = 0;
369
370   return (0);
371 }
372
373 int
374 ip6_link_set_local_address (u32 sw_if_index, const ip6_address_t * address)
375 {
376   ip6_link_delegate_t *ild;
377   ip6_link_t *il;
378
379   il = ip6_link_get (sw_if_index);
380
381   if (NULL == il)
382     return ip6_link_enable (sw_if_index, address);
383
384   ip6_ll_prefix_t ilp = {
385     .ilp_addr = il->il_ll_addr,
386     .ilp_sw_if_index = sw_if_index,
387   };
388
389   IP6_LINK_INFO ("set-ll: %U -> %U",
390                  format_vnet_sw_if_index_name, vnet_get_main (), sw_if_index,
391                  format_ip6_address, address);
392
393   ip6_ll_table_entry_delete (&ilp);
394   ip6_address_copy (&il->il_ll_addr, address);
395   ip6_address_copy (&ilp.ilp_addr, address);
396   ip6_ll_table_entry_update (&ilp, FIB_ROUTE_PATH_LOCAL);
397
398   /* *INDENT-OFF* */
399   FOREACH_IP6_LINK_DELEGATE (ild, il,
400   ({
401     if (NULL != il_delegate_vfts[ild->ild_type].ildv_ll_change)
402       il_delegate_vfts[ild->ild_type].ildv_ll_change(ild->ild_index,
403                                                      &il->il_ll_addr);
404   }));
405   /* *INDENT-ON* */
406
407   return (0);
408 }
409
410 ip6_link_delegate_id_t
411 ip6_link_delegate_register (const ip6_link_delegate_vft_t * vft)
412 {
413   ip6_link_delegate_id_t rc = il_delegate_id++;
414
415   ASSERT (vft->ildv_disable);
416
417   vec_validate (il_delegate_vfts, rc);
418
419   il_delegate_vfts[rc] = *vft;
420
421   return (rc);
422 }
423
424 index_t
425 ip6_link_delegate_get (u32 sw_if_index, ip6_link_delegate_id_t id)
426 {
427   ip6_link_t *il;
428
429   il = ip6_link_get (sw_if_index);
430
431   if (NULL == il)
432     return (INDEX_INVALID);
433
434   vec_validate_init_empty (il->il_delegates, id, ip6_link_delegate_uninit);
435
436   if (!ip6_link_delegate_is_init (&il->il_delegates[id]))
437     return (INDEX_INVALID);
438
439   return (il->il_delegates[id].ild_index);
440 }
441
442 bool
443 ip6_link_delegate_update (u32 sw_if_index,
444                           ip6_link_delegate_id_t id, index_t ii)
445 {
446   ip6_link_t *il;
447
448   il = ip6_link_get (sw_if_index);
449
450   if (NULL == il)
451     return (false);
452
453   vec_validate_init_empty (il->il_delegates, id, ip6_link_delegate_uninit);
454
455   il->il_delegates[id].ild_sw_if_index = sw_if_index;
456   il->il_delegates[id].ild_type = id;
457   il->il_delegates[id].ild_index = ii;
458
459   return (true);
460 }
461
462 void
463 ip6_link_delegate_remove (u32 sw_if_index,
464                           ip6_link_delegate_id_t id, index_t ii)
465 {
466   ip6_link_t *il;
467
468   il = ip6_link_get (sw_if_index);
469
470   if (NULL != il)
471     {
472       if (vec_len (il->il_delegates) > id)
473         {
474           clib_memcpy (&il->il_delegates[id],
475                        &ip6_link_delegate_uninit,
476                        sizeof (il->il_delegates[0]));
477         }
478     }
479 }
480
481 static void
482 ip6_link_add_del_address (ip6_main_t * im,
483                           uword opaque,
484                           u32 sw_if_index,
485                           ip6_address_t * address,
486                           u32 address_length,
487                           u32 if_address_index, u32 is_delete)
488 {
489   const ip6_link_delegate_t *ild;
490   ip6_link_t *il;
491
492   if (ip6_address_is_link_local_unicast (address))
493     // only interested in global addresses here
494     return;
495
496   IP6_LINK_INFO ("addr-%s: %U -> %U",
497                  (is_delete ? "del" : "add"),
498                  format_vnet_sw_if_index_name, vnet_get_main (), sw_if_index,
499                  format_ip6_address, address);
500
501   il = ip6_link_get (sw_if_index);
502
503   if (NULL == il)
504     return;
505
506   /* *INDENT-OFF* */
507   FOREACH_IP6_LINK_DELEGATE (ild, il,
508   ({
509       if (is_delete)
510         {
511           if (NULL != il_delegate_vfts[ild->ild_type].ildv_addr_del)
512             il_delegate_vfts[ild->ild_type].ildv_addr_del(ild->ild_index,
513                                                           address, address_length);
514         }
515       else
516         {
517           if (NULL != il_delegate_vfts[ild->ild_type].ildv_addr_add)
518             il_delegate_vfts[ild->ild_type].ildv_addr_add(ild->ild_index,
519                                                           address, address_length);
520         }
521   }));
522   /* *INDENT-ON* */
523 }
524
525 static clib_error_t *
526 ip6_link_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add)
527 {
528   if (!is_add)
529     {
530       ip6_link_t *il;
531
532       il = ip6_link_get (sw_if_index);
533
534       IP6_LINK_DBG ("link-del: %U",
535                     format_vnet_sw_if_index_name, vnet_get_main (),
536                     sw_if_index);
537
538       if (NULL != il)
539         /* force cleanup */
540         ip6_link_last_lock_gone (il);
541     }
542
543   return (NULL);
544 }
545
546 VNET_SW_INTERFACE_ADD_DEL_FUNCTION (ip6_link_interface_add_del);
547
548 static clib_error_t *
549 ip6_link_init (vlib_main_t * vm)
550 {
551   il_randomizer = clib_cpu_time_now ();
552   ip6_link_logger = vlib_log_register_class ("ip6", "link");
553
554   {
555     ip6_add_del_interface_address_callback_t cb = {
556       .function = ip6_link_add_del_address,
557     };
558     vec_add1 (ip6_main.add_del_interface_address_callbacks, cb);
559   }
560   return (NULL);
561 }
562
563 VLIB_INIT_FUNCTION (ip6_link_init);
564
565
566 static clib_error_t *
567 test_ip6_link_command_fn (vlib_main_t * vm,
568                           unformat_input_t * input, vlib_cli_command_t * cmd)
569 {
570   u8 mac[6];
571   ip6_address_t _a, *a = &_a;
572
573   if (unformat (input, "%U", unformat_ethernet_address, mac))
574     {
575       ip6_link_local_address_from_mac (a, mac);
576       vlib_cli_output (vm, "Link local address: %U", format_ip6_address, a);
577       ip6_mac_address_from_link_local (mac, a);
578       vlib_cli_output (vm, "Original MAC address: %U",
579                        format_ethernet_address, mac);
580     }
581
582   return 0;
583 }
584
585 /*?
586  * This command converts the given MAC Address into an IPv6 link-local
587  * address.
588  *
589  * @cliexpar
590  * Example of how to create an IPv6 link-local address:
591  * @cliexstart{test ip6 link 16:d9:e0:91:79:86}
592  * Link local address: fe80::14d9:e0ff:fe91:7986
593  * Original MAC address: 16:d9:e0:91:79:86
594  * @cliexend
595 ?*/
596 /* *INDENT-OFF* */
597 VLIB_CLI_COMMAND (test_link_command, static) =
598 {
599   .path = "test ip6 link",
600   .function = test_ip6_link_command_fn,
601   .short_help = "test ip6 link <mac-address>",
602 };
603 /* *INDENT-ON* */
604
605 static u8 *
606 ip6_print_addrs (u8 * s, u32 * addrs)
607 {
608   ip_lookup_main_t *lm = &ip6_main.lookup_main;
609   u32 i;
610
611   for (i = 0; i < vec_len (addrs); i++)
612     {
613       ip_interface_address_t *a =
614         pool_elt_at_index (lm->if_address_pool, addrs[i]);
615       ip6_address_t *address = ip_interface_address_get_address (lm, a);
616
617       s = format (s, "%U%U/%d\n",
618                   format_white_space, 4,
619                   format_ip6_address, address, a->address_length);
620     }
621
622   return (s);
623 }
624
625 static u8 *
626 format_ip6_link (u8 * s, va_list * arg)
627 {
628   const ip6_link_t *il = va_arg (*arg, ip6_link_t *);
629   ip_lookup_main_t *lm = &ip6_main.lookup_main;
630   vnet_main_t *vnm = vnet_get_main ();
631
632   if (!ip6_link_is_enabled_i (il))
633     return (s);
634
635   s = format (s, "%U is admin %s\n",
636               format_vnet_sw_interface_name, vnm,
637               vnet_get_sw_interface (vnm, il->il_sw_if_index),
638               (vnet_sw_interface_is_admin_up (vnm, il->il_sw_if_index) ?
639                "up" : "down"));
640
641   u32 ai;
642   u32 *link_scope = 0, *global_scope = 0;
643   u32 *local_scope = 0, *unknown_scope = 0;
644   ip_interface_address_t *a;
645   const ip6_link_delegate_t *ild;
646
647   vec_validate_init_empty (lm->if_address_pool_index_by_sw_if_index,
648                            il->il_sw_if_index, ~0);
649   ai = lm->if_address_pool_index_by_sw_if_index[il->il_sw_if_index];
650
651   while (ai != (u32) ~ 0)
652     {
653       a = pool_elt_at_index (lm->if_address_pool, ai);
654       ip6_address_t *address = ip_interface_address_get_address (lm, a);
655
656       if (ip6_address_is_link_local_unicast (address))
657         vec_add1 (link_scope, ai);
658       else if (ip6_address_is_global_unicast (address))
659         vec_add1 (global_scope, ai);
660       else if (ip6_address_is_local_unicast (address))
661         vec_add1 (local_scope, ai);
662       else
663         vec_add1 (unknown_scope, ai);
664
665       ai = a->next_this_sw_interface;
666     }
667
668   if (vec_len (link_scope))
669     {
670       s = format (s, "%ULink-local address(es):\n", format_white_space, 2);
671       s = ip6_print_addrs (s, link_scope);
672       vec_free (link_scope);
673     }
674
675   if (vec_len (local_scope))
676     {
677       s = format (s, "%ULocal unicast address(es):\n", format_white_space, 2);
678       s = ip6_print_addrs (s, local_scope);
679       vec_free (local_scope);
680     }
681
682   if (vec_len (global_scope))
683     {
684       s = format (s, "%UGlobal unicast address(es):\n",
685                   format_white_space, 2);
686       s = ip6_print_addrs (s, global_scope);
687       vec_free (global_scope);
688     }
689
690   if (vec_len (unknown_scope))
691     {
692       s = format (s, "%UOther-scope address(es):\n", format_white_space, 2);
693       s = ip6_print_addrs (s, unknown_scope);
694       vec_free (unknown_scope);
695     }
696
697   s = format (s, "%ULink-local address(es):\n", format_white_space, 2);
698   s = format (s, "%U%U\n",
699               format_white_space, 4, format_ip6_address, &il->il_ll_addr);
700
701   /* *INDENT-OFF* */
702   FOREACH_IP6_LINK_DELEGATE(ild, il,
703   ({
704     s = format (s, "%U", il_delegate_vfts[ild->ild_type].ildv_format,
705                      ild->ild_index, 2);
706   }));
707   /* *INDENT-ON* */
708
709   return (s);
710 }
711
712 static clib_error_t *
713 ip6_link_show (vlib_main_t * vm,
714                unformat_input_t * input, vlib_cli_command_t * cmd)
715 {
716   const ip6_link_t *il;
717   vnet_main_t *vnm;
718   u32 sw_if_index;
719
720   vnm = vnet_get_main ();
721   sw_if_index = ~0;
722
723   if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
724     {
725       il = ip6_link_get (sw_if_index);
726
727       if (NULL == il)
728         {
729           vlib_cli_output (vm, "IP6 disabled");
730           return (NULL);
731         }
732       else
733         vlib_cli_output (vm, "%U", format_ip6_link, il);
734     }
735   else
736     {
737       vec_foreach (il, ip6_links)
738         vlib_cli_output (vm, "%U", format_ip6_link, il);
739     }
740
741   return (NULL);
742 }
743
744 /*?
745  * This command is used to display various IPv6 attributes on a given
746  * interface.
747  *
748  * @cliexpar
749  * Example of how to display IPv6 settings:
750  * @cliexstart{show ip6 interface GigabitEthernet2/0/0}
751  * GigabitEthernet2/0/0 is admin up
752  *         Link-local address(es):
753  *                 fe80::ab8/64
754  *         Joined group address(es):
755  *                 ff02::1
756  *                 ff02::2
757  *                 ff02::16
758  *                 ff02::1:ff00:ab8
759  *         Advertised Prefixes:
760  *                 prefix fe80::fe:28ff:fe9c:75b3,  length 64
761  *         MTU is 1500
762  *         ICMP error messages are unlimited
763  *         ICMP redirects are disabled
764  *         ICMP unreachables are not sent
765  *         ND DAD is disabled
766  *         ND advertised reachable time is 0
767  *         ND advertised retransmit interval is 0 (msec)
768  *         ND router advertisements are sent every 200 seconds (min interval is 150)
769  *         ND router advertisements live for 600 seconds
770  *         Hosts use stateless autoconfig for addresses
771  *         ND router advertisements sent 19336
772  *         ND router solicitations received 0
773  *         ND router solicitations dropped 0
774  * @cliexend
775  * Example of output if IPv6 is not enabled on the interface:
776  * @cliexstart{show ip6 interface GigabitEthernet2/0/0}
777  * show ip6 interface: IPv6 not enabled on interface
778  * @cliexend
779 ?*/
780 /* *INDENT-OFF* */
781 VLIB_CLI_COMMAND (ip6_link_show_command, static) =
782 {
783   .path = "show ip6 interface",
784   .function = ip6_link_show,
785   .short_help = "show ip6 interface <interface>",
786 };
787 /* *INDENT-ON* */
788
789 static clib_error_t *
790 enable_ip6_interface_cmd (vlib_main_t * vm,
791                           unformat_input_t * input, vlib_cli_command_t * cmd)
792 {
793   vnet_main_t *vnm = vnet_get_main ();
794   clib_error_t *error = NULL;
795   u32 sw_if_index;
796
797   sw_if_index = ~0;
798
799   if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
800     {
801       if (ip6_link_enable (sw_if_index, NULL))
802         error = clib_error_return (0, "Failed\n");
803     }
804   else
805     {
806       error = clib_error_return (0, "unknown interface\n'",
807                                  format_unformat_error, input);
808
809     }
810   return error;
811 }
812
813 /*?
814  * This command is used to enable IPv6 on a given interface.
815  *
816  * @cliexpar
817  * Example of how enable IPv6 on a given interface:
818  * @cliexcmd{enable ip6 interface GigabitEthernet2/0/0}
819 ?*/
820 /* *INDENT-OFF* */
821 VLIB_CLI_COMMAND (enable_ip6_interface_command, static) =
822 {
823   .path = "enable ip6 interface",
824   .function = enable_ip6_interface_cmd,
825   .short_help = "enable ip6 interface <interface>",
826 };
827 /* *INDENT-ON* */
828
829 static clib_error_t *
830 disable_ip6_interface_cmd (vlib_main_t * vm,
831                            unformat_input_t * input, vlib_cli_command_t * cmd)
832 {
833   vnet_main_t *vnm = vnet_get_main ();
834   clib_error_t *error = NULL;
835   u32 sw_if_index;
836
837   sw_if_index = ~0;
838
839   if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
840     {
841       if (ip6_link_disable (sw_if_index))
842         error = clib_error_return (0, "Failed\n");
843     }
844   else
845     {
846       error = clib_error_return (0, "unknown interface\n'",
847                                  format_unformat_error, input);
848
849     }
850   return error;
851 }
852
853 /*?
854  * This command is used to disable IPv6 on a given interface.
855  *
856  * @cliexpar
857  * Example of how disable IPv6 on a given interface:
858  * @cliexcmd{disable ip6 interface GigabitEthernet2/0/0}
859 ?*/
860 /* *INDENT-OFF* */
861 VLIB_CLI_COMMAND (disable_ip6_interface_command, static) =
862 {
863   .path = "disable ip6 interface",
864   .function = disable_ip6_interface_cmd,
865   .short_help = "disable ip6 interface <interface>",
866 };
867 /* *INDENT-ON* */
868
869 /*
870  * fd.io coding-style-patch-verification: ON
871  *
872  * Local Variables:
873  * eval: (c-set-style "gnu")
874  * End:
875  */