2 * ip/ip6_neighbor.c: IP6 neighbor handling
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <vnet/ip/ip.h>
19 #include <vnet/ip/ip6_neighbor.h>
20 #include <vnet/ethernet/ethernet.h>
21 #include <vppinfra/mhash.h>
22 #include <vppinfra/md5.h>
23 #include <vnet/adj/adj.h>
24 #include <vnet/adj/adj_mcast.h>
25 #include <vnet/fib/fib_table.h>
26 #include <vnet/fib/ip6_fib.h>
27 #include <vnet/mfib/ip6_mfib.h>
31 * @brief IPv6 Neighbor Adjacency and Neighbor Discovery.
33 * The files contains the API and CLI code for managing IPv6 neighbor
34 * adjacency tables and neighbor discovery logic.
37 /* can't use sizeof link_layer_address, that's 8 */
38 #define ETHER_MAC_ADDR_LEN 6
40 /* advertised prefix option */
43 /* basic advertised information */
47 int adv_autonomous_flag;
48 u32 adv_valid_lifetime_in_secs;
49 u32 adv_pref_lifetime_in_secs;
51 /* advertised values are computed from these times if decrementing */
52 f64 valid_lifetime_expires;
53 f64 pref_lifetime_expires;
55 /* local information */
57 int deprecated_prefix_flag;
58 int decrement_lifetime_flag;
60 #define MIN_ADV_VALID_LIFETIME 7203 /* seconds */
61 #define DEF_ADV_VALID_LIFETIME 2592000
62 #define DEF_ADV_PREF_LIFETIME 604800
64 /* extensions are added here, mobile, DNS etc.. */
70 /* group information */
72 ip6_address_t mcast_address;
74 ip6_address_t *mcast_source_address_pool;
77 /* configured router advertisement information per ipv6 interface */
81 /* advertised config information, zero means unspecified */
85 u16 adv_router_lifetime_in_sec;
86 u32 adv_neighbor_reachable_time_in_msec;
87 u32 adv_time_in_msec_between_retransmitted_neighbor_solicitations;
92 /* source link layer option */
93 u8 link_layer_address[8];
94 u8 link_layer_addr_len;
97 ip6_radv_prefix_t *adv_prefixes_pool;
99 /* Hash table mapping address to index in interface advertised prefix pool. */
100 mhash_t address_to_prefix_index;
102 /* MLDP group information */
103 ip6_mldp_group_t *mldp_group_pool;
105 /* Hash table mapping address to index in mldp address pool. */
106 mhash_t address_to_mldp_index;
108 /* local information */
110 int send_radv; /* radv on/off on this interface - set by config */
111 int cease_radv; /* we are ceasing to send - set byf config */
113 int adv_link_layer_address;
115 int failed_device_check;
116 int all_routers_mcast;
120 adj_index_t mcast_adj_index;
122 /* timing information */
123 #define DEF_MAX_RADV_INTERVAL 200
124 #define DEF_MIN_RADV_INTERVAL .75 * DEF_MAX_RADV_INTERVAL
125 #define DEF_CURR_HOP_LIMIT 64
126 #define DEF_DEF_RTR_LIFETIME 3 * DEF_MAX_RADV_INTERVAL
127 #define MAX_DEF_RTR_LIFETIME 9000
129 #define MAX_INITIAL_RTR_ADVERT_INTERVAL 16 /* seconds */
130 #define MAX_INITIAL_RTR_ADVERTISEMENTS 3 /*transmissions */
131 #define MIN_DELAY_BETWEEN_RAS 3 /* seconds */
132 #define MAX_DELAY_BETWEEN_RAS 1800 /* seconds */
133 #define MAX_RA_DELAY_TIME .5 /* seconds */
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;
142 f64 last_multicast_time;
143 f64 next_multicast_time;
146 u32 initial_adverts_count;
147 f64 initial_adverts_interval;
148 u32 initial_adverts_sent;
151 u32 n_advertisements_sent;
152 u32 n_solicitations_rcvd;
153 u32 n_solicitations_dropped;
155 /* Link local address to use (defaults to underlying physical for logical interfaces */
156 ip6_address_t link_local_address;
165 /* Used for nd event notification only */
168 } pending_resolution_t;
173 /* Hash tables mapping name to opcode. */
174 uword *opcode_by_name;
176 /* lite beer "glean" adjacency handling */
177 mhash_t pending_resolutions_by_address;
178 pending_resolution_t *pending_resolutions;
180 /* Mac address change notification */
181 mhash_t mac_changes_by_address;
182 pending_resolution_t *mac_changes;
184 u32 *neighbor_input_next_index_by_hw_if_index;
186 ip6_neighbor_t *neighbor_pool;
188 mhash_t neighbor_index_by_key;
190 u32 *if_radv_pool_index_by_sw_if_index;
192 ip6_radv_t *if_radv_pool;
194 /* Neighbor attack mitigation */
195 u32 limit_neighbor_cache_size;
196 u32 neighbor_delete_rotor;
198 } ip6_neighbor_main_t;
200 /* ipv6 neighbor discovery - timer/event types */
204 } ip6_icmp_neighbor_discovery_event_type_t;
214 } ip6_icmp_neighbor_discovery_event_data_t;
216 static ip6_neighbor_main_t ip6_neighbor_main;
217 static ip6_address_t ip6a_zero; /* ip6 address 0 */
220 format_ip6_neighbor_ip6_entry (u8 * s, va_list * va)
222 vlib_main_t *vm = va_arg (*va, vlib_main_t *);
223 ip6_neighbor_t *n = va_arg (*va, ip6_neighbor_t *);
224 vnet_main_t *vnm = vnet_get_main ();
225 vnet_sw_interface_t *si;
229 return format (s, "%=12s%=20s%=6s%=20s%=40s", "Time", "Address", "Flags",
230 "Link layer", "Interface");
232 if (n->flags & IP6_NEIGHBOR_FLAG_DYNAMIC)
233 flags = format (flags, "D");
235 if (n->flags & IP6_NEIGHBOR_FLAG_STATIC)
236 flags = format (flags, "S");
238 if (n->flags & IP6_NEIGHBOR_FLAG_NO_FIB_ENTRY)
239 flags = format (flags, "N");
241 si = vnet_get_sw_interface (vnm, n->key.sw_if_index);
242 s = format (s, "%=12U%=20U%=6s%=20U%=40U",
243 format_vlib_cpu_time, vm, n->cpu_time_last_updated,
244 format_ip6_address, &n->key.ip6_address,
245 flags ? (char *) flags : "",
246 format_ethernet_address, n->link_layer_address,
247 format_vnet_sw_interface_name, vnm, si);
253 static clib_error_t *
254 ip6_neighbor_sw_interface_up_down (vnet_main_t * vnm,
255 u32 sw_if_index, u32 flags)
257 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
260 if (!(flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP))
262 u32 i, *to_delete = 0;
265 pool_foreach (n, nm->neighbor_pool,
267 if (n->key.sw_if_index == sw_if_index)
268 vec_add1 (to_delete, n - nm->neighbor_pool);
272 for (i = 0; i < vec_len (to_delete); i++)
274 n = pool_elt_at_index (nm->neighbor_pool, to_delete[i]);
275 mhash_unset (&nm->neighbor_index_by_key, &n->key, 0);
276 fib_table_entry_delete_index (n->fib_entry_index, FIB_SOURCE_ADJ);
277 pool_put (nm->neighbor_pool, n);
280 vec_free (to_delete);
286 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (ip6_neighbor_sw_interface_up_down);
289 unset_random_neighbor_entry (void)
291 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
292 vnet_main_t *vnm = vnet_get_main ();
293 vlib_main_t *vm = vnm->vlib_main;
297 index = pool_next_index (nm->neighbor_pool, nm->neighbor_delete_rotor);
298 nm->neighbor_delete_rotor = index;
300 /* Try again from elt 0, could happen if an intfc goes down */
303 index = pool_next_index (nm->neighbor_pool, nm->neighbor_delete_rotor);
304 nm->neighbor_delete_rotor = index;
307 /* Nothing left in the pool */
311 e = pool_elt_at_index (nm->neighbor_pool, index);
313 vnet_unset_ip6_ethernet_neighbor (vm, e->key.sw_if_index,
315 e->link_layer_address,
324 u8 link_layer_address[6];
327 } ip6_neighbor_set_unset_rpc_args_t;
329 static void ip6_neighbor_set_unset_rpc_callback
330 (ip6_neighbor_set_unset_rpc_args_t * a);
332 static void set_unset_ip6_neighbor_rpc
335 ip6_address_t * a, u8 * link_layer_address, int is_add, int is_static,
338 ip6_neighbor_set_unset_rpc_args_t args;
339 void vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length);
341 args.sw_if_index = sw_if_index;
342 args.is_add = is_add;
343 args.is_static = is_static;
344 args.is_no_fib_entry = is_no_fib_entry;
345 clib_memcpy (&args.addr, a, sizeof (*a));
346 if (NULL != link_layer_address)
347 clib_memcpy (args.link_layer_address, link_layer_address, 6);
349 vl_api_rpc_call_main_thread (ip6_neighbor_set_unset_rpc_callback,
350 (u8 *) & args, sizeof (args));
354 ip6_nbr_probe (ip_adjacency_t * adj)
356 icmp6_neighbor_solicitation_header_t *h;
357 vnet_main_t *vnm = vnet_get_main ();
358 ip6_main_t *im = &ip6_main;
359 ip_interface_address_t *ia;
360 ip6_address_t *dst, *src;
361 vnet_hw_interface_t *hi;
362 vnet_sw_interface_t *si;
368 vm = vlib_get_main ();
370 si = vnet_get_sw_interface (vnm, adj->rewrite_header.sw_if_index);
371 dst = &adj->sub_type.nbr.next_hop.ip6;
373 if (!(si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP))
377 src = ip6_interface_address_matching_destination (im, dst,
385 h = vlib_packet_template_get_packet (vm,
386 &im->discover_neighbor_packet_template,
389 hi = vnet_get_sup_hw_interface (vnm, adj->rewrite_header.sw_if_index);
391 h->ip.dst_address.as_u8[13] = dst->as_u8[13];
392 h->ip.dst_address.as_u8[14] = dst->as_u8[14];
393 h->ip.dst_address.as_u8[15] = dst->as_u8[15];
394 h->ip.src_address = src[0];
395 h->neighbor.target_address = dst[0];
397 clib_memcpy (h->link_layer_option.ethernet_address,
398 hi->hw_address, vec_len (hi->hw_address));
400 h->neighbor.icmp.checksum =
401 ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h->ip, &bogus_length);
402 ASSERT (bogus_length == 0);
404 b = vlib_get_buffer (vm, bi);
405 vnet_buffer (b)->sw_if_index[VLIB_RX] =
406 vnet_buffer (b)->sw_if_index[VLIB_TX] = adj->rewrite_header.sw_if_index;
408 /* Add encapsulation string for software interface (e.g. ethernet header). */
409 vnet_rewrite_one_header (adj[0], h, sizeof (ethernet_header_t));
410 vlib_buffer_advance (b, -adj->rewrite_header.data_bytes);
413 vlib_frame_t *f = vlib_get_frame_to_node (vm, hi->output_node_index);
414 u32 *to_next = vlib_frame_vector_args (f);
417 vlib_put_frame_to_node (vm, hi->output_node_index, f);
422 ip6_nd_mk_complete (adj_index_t ai, ip6_neighbor_t * nbr)
424 adj_nbr_update_rewrite (ai, ADJ_NBR_REWRITE_FLAG_COMPLETE,
425 ethernet_build_rewrite (vnet_get_main (),
426 nbr->key.sw_if_index,
427 adj_get_link_type (ai),
428 nbr->link_layer_address));
432 ip6_nd_mk_incomplete (adj_index_t ai)
434 ip_adjacency_t *adj = adj_get (ai);
436 adj_nbr_update_rewrite (ai,
437 ADJ_NBR_REWRITE_FLAG_INCOMPLETE,
438 ethernet_build_rewrite (vnet_get_main (),
441 adj_get_link_type (ai),
442 VNET_REWRITE_FOR_SW_INTERFACE_ADDRESS_BROADCAST));
445 #define IP6_NBR_MK_KEY(k, sw_if_index, addr) \
447 k.sw_if_index = sw_if_index; \
448 k.ip6_address = *addr; \
452 static ip6_neighbor_t *
453 ip6_nd_find (u32 sw_if_index, const ip6_address_t * addr)
455 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
456 ip6_neighbor_t *n = NULL;
457 ip6_neighbor_key_t k;
460 IP6_NBR_MK_KEY (k, sw_if_index, addr);
462 p = mhash_get (&nm->neighbor_index_by_key, &k);
465 n = pool_elt_at_index (nm->neighbor_pool, p[0]);
472 ip6_nd_mk_complete_walk (adj_index_t ai, void *ctx)
474 ip6_neighbor_t *nbr = ctx;
476 ip6_nd_mk_complete (ai, nbr);
478 return (ADJ_WALK_RC_CONTINUE);
482 ip6_nd_mk_incomplete_walk (adj_index_t ai, void *ctx)
484 ip6_nd_mk_incomplete (ai);
486 return (ADJ_WALK_RC_CONTINUE);
490 ip6_ethernet_update_adjacency (vnet_main_t * vnm, u32 sw_if_index, u32 ai)
497 nbr = ip6_nd_find (sw_if_index, &adj->sub_type.nbr.next_hop.ip6);
499 switch (adj->lookup_next_index)
501 case IP_LOOKUP_NEXT_ARP:
502 case IP_LOOKUP_NEXT_GLEAN:
505 adj_nbr_walk_nh6 (sw_if_index, &nbr->key.ip6_address,
506 ip6_nd_mk_complete_walk, nbr);
511 * no matching ND entry.
512 * construct the rewrite required to for an ND packet, and stick
513 * that in the adj's pipe to smoke.
515 adj_nbr_update_rewrite (ai,
516 ADJ_NBR_REWRITE_FLAG_INCOMPLETE,
517 ethernet_build_rewrite (vnm,
520 VNET_REWRITE_FOR_SW_INTERFACE_ADDRESS_BROADCAST));
523 * since the FIB has added this adj for a route, it makes sense it may
524 * want to forward traffic sometime soon. Let's send a speculative ND.
525 * just one. If we were to do periodically that wouldn't be bad either,
526 * but that's more code than i'm prepared to write at this time for
527 * relatively little reward.
532 case IP_LOOKUP_NEXT_MCAST:
535 * Construct a partial rewrite from the known ethernet mcast dest MAC
540 rewrite = ethernet_build_rewrite (vnm,
543 ethernet_ip6_mcast_dst_addr ());
546 * Complete the remaining fields of the adj's rewrite to direct the
547 * complete of the rewrite at switch time by copying in the IP
548 * dst address's bytes.
549 * Ofset is 2 bytes into the desintation address. And we write 4 bytes.
551 offset = vec_len (rewrite) - 2;
552 adj_mcast_update_rewrite (ai, rewrite, offset, 0xffffffff);
556 case IP_LOOKUP_NEXT_DROP:
557 case IP_LOOKUP_NEXT_PUNT:
558 case IP_LOOKUP_NEXT_LOCAL:
559 case IP_LOOKUP_NEXT_REWRITE:
560 case IP_LOOKUP_NEXT_MCAST_MIDCHAIN:
561 case IP_LOOKUP_NEXT_MIDCHAIN:
562 case IP_LOOKUP_NEXT_ICMP_ERROR:
563 case IP_LOOKUP_N_NEXT:
570 vnet_set_ip6_ethernet_neighbor (vlib_main_t * vm,
573 u8 * link_layer_address,
574 uword n_bytes_link_layer_address,
575 int is_static, int is_no_fib_entry)
577 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
578 ip6_neighbor_key_t k;
579 ip6_neighbor_t *n = 0;
580 int make_new_nd_cache_entry = 1;
583 pending_resolution_t *pr, *mc;
585 if (vlib_get_thread_index ())
587 set_unset_ip6_neighbor_rpc (vm, sw_if_index, a, link_layer_address,
588 1 /* set new neighbor */ , is_static,
593 k.sw_if_index = sw_if_index;
594 k.ip6_address = a[0];
597 p = mhash_get (&nm->neighbor_index_by_key, &k);
600 n = pool_elt_at_index (nm->neighbor_pool, p[0]);
601 /* Refuse to over-write static neighbor entry. */
602 if (!is_static && (n->flags & IP6_NEIGHBOR_FLAG_STATIC))
604 make_new_nd_cache_entry = 0;
607 if (make_new_nd_cache_entry)
609 pool_get (nm->neighbor_pool, n);
610 mhash_set (&nm->neighbor_index_by_key, &k, n - nm->neighbor_pool,
614 clib_memcpy (n->link_layer_address,
615 link_layer_address, n_bytes_link_layer_address);
618 * create the adj-fib. the entry in the FIB table for and to the peer.
620 if (!is_no_fib_entry)
624 .fp_proto = FIB_PROTOCOL_IP6,
625 .fp_addr.ip6 = k.ip6_address,
629 fib_index = ip6_main.fib_index_by_sw_if_index[n->key.sw_if_index];
631 fib_table_entry_update_one_path (fib_index, &pfx,
633 FIB_ENTRY_FLAG_ATTACHED,
634 FIB_PROTOCOL_IP6, &pfx.fp_addr,
635 n->key.sw_if_index, ~0, 1, NULL,
636 FIB_ROUTE_PATH_FLAG_NONE);
640 n->flags |= IP6_NEIGHBOR_FLAG_NO_FIB_ENTRY;
646 * prevent a DoS attack from the data-plane that
647 * spams us with no-op updates to the MAC address
649 if (0 == memcmp (n->link_layer_address,
650 link_layer_address, n_bytes_link_layer_address))
653 clib_memcpy (n->link_layer_address,
654 link_layer_address, n_bytes_link_layer_address);
657 /* Update time stamp and flags. */
658 n->cpu_time_last_updated = clib_cpu_time_now ();
660 n->flags |= IP6_NEIGHBOR_FLAG_STATIC;
662 n->flags |= IP6_NEIGHBOR_FLAG_DYNAMIC;
664 adj_nbr_walk_nh6 (sw_if_index,
665 &n->key.ip6_address, ip6_nd_mk_complete_walk, n);
667 /* Customer(s) waiting for this address to be resolved? */
668 p = mhash_get (&nm->pending_resolutions_by_address, a);
673 while (next_index != (u32) ~ 0)
675 pr = pool_elt_at_index (nm->pending_resolutions, next_index);
676 vlib_process_signal_event (vm, pr->node_index,
677 pr->type_opaque, pr->data);
678 next_index = pr->next_index;
679 pool_put (nm->pending_resolutions, pr);
682 mhash_unset (&nm->pending_resolutions_by_address, a, 0);
685 /* Customer(s) requesting ND event for this address? */
686 p = mhash_get (&nm->mac_changes_by_address, a);
691 while (next_index != (u32) ~ 0)
693 int (*fp) (u32, u8 *, u32, ip6_address_t *);
695 mc = pool_elt_at_index (nm->mac_changes, next_index);
696 fp = mc->data_callback;
698 /* Call the user's data callback, return 1 to suppress dup events */
701 (*fp) (mc->data, link_layer_address, sw_if_index, &ip6a_zero);
703 * Signal the resolver process, as long as the user
704 * says they want to be notified
707 vlib_process_signal_event (vm, mc->node_index,
708 mc->type_opaque, mc->data);
709 next_index = mc->next_index;
717 vnet_unset_ip6_ethernet_neighbor (vlib_main_t * vm,
720 u8 * link_layer_address,
721 uword n_bytes_link_layer_address)
723 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
724 ip6_neighbor_key_t k;
729 if (vlib_get_thread_index ())
731 set_unset_ip6_neighbor_rpc (vm, sw_if_index, a, link_layer_address,
732 0 /* unset */ , 0, 0);
736 k.sw_if_index = sw_if_index;
737 k.ip6_address = a[0];
740 p = mhash_get (&nm->neighbor_index_by_key, &k);
747 n = pool_elt_at_index (nm->neighbor_pool, p[0]);
748 mhash_unset (&nm->neighbor_index_by_key, &n->key, 0);
750 adj_nbr_walk_nh6 (sw_if_index,
751 &n->key.ip6_address, ip6_nd_mk_incomplete_walk, NULL);
753 fib_table_entry_delete_index (n->fib_entry_index, FIB_SOURCE_ADJ);
754 pool_put (nm->neighbor_pool, n);
760 static void ip6_neighbor_set_unset_rpc_callback
761 (ip6_neighbor_set_unset_rpc_args_t * a)
763 vlib_main_t *vm = vlib_get_main ();
765 vnet_set_ip6_ethernet_neighbor (vm, a->sw_if_index, &a->addr,
766 a->link_layer_address, 6, a->is_static,
769 vnet_unset_ip6_ethernet_neighbor (vm, a->sw_if_index, &a->addr,
770 a->link_layer_address, 6);
774 ip6_neighbor_sort (void *a1, void *a2)
776 vnet_main_t *vnm = vnet_get_main ();
777 ip6_neighbor_t *n1 = a1, *n2 = a2;
779 cmp = vnet_sw_interface_compare (vnm, n1->key.sw_if_index,
780 n2->key.sw_if_index);
782 cmp = ip6_address_compare (&n1->key.ip6_address, &n2->key.ip6_address);
787 ip6_neighbors_entries (u32 sw_if_index)
789 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
790 ip6_neighbor_t *n, *ns = 0;
793 pool_foreach (n, nm->neighbor_pool,
795 if (sw_if_index != ~0 && n->key.sw_if_index != sw_if_index)
802 vec_sort_with_function (ns, ip6_neighbor_sort);
806 static clib_error_t *
807 show_ip6_neighbors (vlib_main_t * vm,
808 unformat_input_t * input, vlib_cli_command_t * cmd)
810 vnet_main_t *vnm = vnet_get_main ();
811 ip6_neighbor_t *n, *ns;
812 clib_error_t *error = 0;
815 /* Filter entries by interface if given. */
817 (void) unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index);
819 ns = ip6_neighbors_entries (sw_if_index);
822 vlib_cli_output (vm, "%U", format_ip6_neighbor_ip6_entry, vm, 0);
825 vlib_cli_output (vm, "%U", format_ip6_neighbor_ip6_entry, vm, n);
834 * This command is used to display the adjacent IPv6 hosts found via
835 * neighbor discovery. Optionally, limit the output to the specified
839 * Example of how to display the IPv6 neighbor adjacency table:
840 * @cliexstart{show ip6 neighbors}
841 * Time Address Flags Link layer Interface
842 * 34.0910 ::a:1:1:0:7 02:fe:6a:07:39:6f GigabitEthernet2/0/0
843 * 173.2916 ::b:5:1:c:2 02:fe:50:62:3a:94 GigabitEthernet2/0/0
844 * 886.6654 ::1:1:c:0:9 S 02:fe:e4:45:27:5b GigabitEthernet3/0/0
846 * Example of how to display the IPv6 neighbor adjacency table for given interface:
847 * @cliexstart{show ip6 neighbors GigabitEthernet2/0/0}
848 * Time Address Flags Link layer Interface
849 * 34.0910 ::a:1:1:0:7 02:fe:6a:07:39:6f GigabitEthernet2/0/0
850 * 173.2916 ::b:5:1:c:2 02:fe:50:62:3a:94 GigabitEthernet2/0/0
854 VLIB_CLI_COMMAND (show_ip6_neighbors_command, static) = {
855 .path = "show ip6 neighbors",
856 .function = show_ip6_neighbors,
857 .short_help = "show ip6 neighbors [<interface>]",
861 static clib_error_t *
862 set_ip6_neighbor (vlib_main_t * vm,
863 unformat_input_t * input, vlib_cli_command_t * cmd)
865 vnet_main_t *vnm = vnet_get_main ();
871 int is_no_fib_entry = 0;
874 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
876 /* intfc, ip6-address, mac-address */
877 if (unformat (input, "%U %U %U",
878 unformat_vnet_sw_interface, vnm, &sw_if_index,
879 unformat_ip6_address, &addr,
880 unformat_ethernet_address, mac_address))
883 else if (unformat (input, "delete") || unformat (input, "del"))
885 else if (unformat (input, "static"))
887 else if (unformat (input, "no-fib-entry"))
894 return clib_error_return (0, "Missing interface, ip6 or hw address");
897 vnet_set_ip6_ethernet_neighbor (vm, sw_if_index, &addr,
898 mac_address, sizeof (mac_address),
899 is_static, is_no_fib_entry);
901 vnet_unset_ip6_ethernet_neighbor (vm, sw_if_index, &addr,
902 mac_address, sizeof (mac_address));
907 * This command is used to manually add an entry to the IPv6 neighbor
908 * adjacency table. Optionally, the entry can be added as static. It is
909 * also used to remove an entry from the table. Use the '<em>show ip6
910 * neighbors</em>' command to display all learned and manually entered entries.
913 * Example of how to add a static entry to the IPv6 neighbor adjacency table:
914 * @cliexcmd{set ip6 neighbor GigabitEthernet2/0/0 ::1:1:c:0:9 02:fe:e4:45:27:5b static}
915 * Example of how to delete an entry from the IPv6 neighbor adjacency table:
916 * @cliexcmd{set ip6 neighbor del GigabitEthernet2/0/0 ::1:1:c:0:9 02:fe:e4:45:27:5b}
919 VLIB_CLI_COMMAND (set_ip6_neighbor_command, static) =
921 .path = "set ip6 neighbor",
922 .function = set_ip6_neighbor,
923 .short_help = "set ip6 neighbor [del] <interface> <ip6-address> <mac-address> [static]",
929 ICMP6_NEIGHBOR_SOLICITATION_NEXT_DROP,
930 ICMP6_NEIGHBOR_SOLICITATION_NEXT_REPLY,
931 ICMP6_NEIGHBOR_SOLICITATION_N_NEXT,
932 } icmp6_neighbor_solicitation_or_advertisement_next_t;
934 static_always_inline uword
935 icmp6_neighbor_solicitation_or_advertisement (vlib_main_t * vm,
936 vlib_node_runtime_t * node,
937 vlib_frame_t * frame,
938 uword is_solicitation)
940 vnet_main_t *vnm = vnet_get_main ();
941 ip6_main_t *im = &ip6_main;
942 uword n_packets = frame->n_vectors;
944 u32 n_left_from, n_left_to_next, next_index, n_advertisements_sent;
945 icmp6_neighbor_discovery_option_type_t option_type;
946 vlib_node_runtime_t *error_node =
947 vlib_node_get_runtime (vm, ip6_icmp_input_node.index);
950 from = vlib_frame_vector_args (frame);
951 n_left_from = n_packets;
952 next_index = node->cached_next_index;
954 if (node->flags & VLIB_NODE_FLAG_TRACE)
955 vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors,
957 sizeof (icmp6_input_trace_t));
961 ? ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address
962 : ICMP6_NEIGHBOR_DISCOVERY_OPTION_target_link_layer_address);
963 n_advertisements_sent = 0;
965 while (n_left_from > 0)
967 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
969 while (n_left_from > 0 && n_left_to_next > 0)
973 icmp6_neighbor_solicitation_or_advertisement_header_t *h0;
974 icmp6_neighbor_discovery_ethernet_link_layer_address_option_t *o0;
975 u32 bi0, options_len0, sw_if_index0, next0, error0;
976 u32 ip6_sadd_link_local, ip6_sadd_unspecified;
980 bi0 = to_next[0] = from[0];
987 p0 = vlib_get_buffer (vm, bi0);
988 ip0 = vlib_buffer_get_current (p0);
989 h0 = ip6_next_header (ip0);
991 clib_net_to_host_u16 (ip0->payload_length) - sizeof (h0[0]);
993 error0 = ICMP6_ERROR_NONE;
994 sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX];
995 ip6_sadd_link_local =
996 ip6_address_is_link_local_unicast (&ip0->src_address);
997 ip6_sadd_unspecified =
998 ip6_address_is_unspecified (&ip0->src_address);
1000 /* Check that source address is unspecified, link-local or else on-link. */
1001 if (!ip6_sadd_unspecified && !ip6_sadd_link_local)
1003 u32 src_adj_index0 = ip6_src_lookup_for_packet (im, p0, ip0);
1005 if (ADJ_INDEX_INVALID != src_adj_index0)
1007 ip_adjacency_t *adj0 = adj_get (src_adj_index0);
1009 /* Allow all realistic-looking rewrite adjacencies to pass */
1010 ni0 = adj0->lookup_next_index;
1011 is_rewrite0 = (ni0 >= IP_LOOKUP_NEXT_ARP) &&
1012 (ni0 < IP6_LOOKUP_N_NEXT);
1014 error0 = ((adj0->rewrite_header.sw_if_index != sw_if_index0
1017 ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_NOT_ON_LINK
1023 ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_NOT_ON_LINK;
1027 o0 = (void *) (h0 + 1);
1028 o0 = ((options_len0 == 8 && o0->header.type == option_type
1029 && o0->header.n_data_u64s == 1) ? o0 : 0);
1031 /* If src address unspecified or link local, donot learn neighbor MAC */
1032 if (PREDICT_TRUE (error0 == ICMP6_ERROR_NONE && o0 != 0 &&
1033 !ip6_sadd_unspecified))
1035 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
1036 if (nm->limit_neighbor_cache_size &&
1037 pool_elts (nm->neighbor_pool) >=
1038 nm->limit_neighbor_cache_size)
1039 unset_random_neighbor_entry ();
1040 vnet_set_ip6_ethernet_neighbor (vm, sw_if_index0,
1043 &h0->target_address,
1044 o0->ethernet_address,
1045 sizeof (o0->ethernet_address),
1046 0, ip6_sadd_link_local);
1049 if (is_solicitation && error0 == ICMP6_ERROR_NONE)
1051 /* Check that target address is local to this router. */
1052 fib_node_index_t fei;
1056 ip6_fib_table_get_index_for_sw_if_index (sw_if_index0);
1058 if (~0 == fib_index)
1060 error0 = ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_UNKNOWN;
1064 fei = ip6_fib_table_lookup_exact_match (fib_index,
1065 &h0->target_address,
1068 if (FIB_NODE_INDEX_INVALID == fei)
1070 /* The target address is not in the FIB */
1072 ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_UNKNOWN;
1076 if (FIB_ENTRY_FLAG_LOCAL &
1077 fib_entry_get_flags_for_source (fei,
1078 FIB_SOURCE_INTERFACE))
1080 /* It's an address that belongs to one of our interfaces
1084 if (fib_entry_is_sourced
1085 (fei, FIB_SOURCE_IP6_ND_PROXY))
1087 /* The address was added by IPv6 Proxy ND config.
1088 * We should only respond to these if the NS arrived on
1089 * the link that has a matching covering prefix */
1094 ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_UNKNOWN;
1100 if (is_solicitation)
1101 next0 = (error0 != ICMP6_ERROR_NONE
1102 ? ICMP6_NEIGHBOR_SOLICITATION_NEXT_DROP
1103 : ICMP6_NEIGHBOR_SOLICITATION_NEXT_REPLY);
1107 error0 = error0 == ICMP6_ERROR_NONE ?
1108 ICMP6_ERROR_NEIGHBOR_ADVERTISEMENTS_RX : error0;
1111 if (is_solicitation && error0 == ICMP6_ERROR_NONE)
1113 vnet_sw_interface_t *sw_if0;
1114 ethernet_interface_t *eth_if0;
1115 ethernet_header_t *eth0;
1117 /* dst address is either source address or the all-nodes mcast addr */
1118 if (!ip6_sadd_unspecified)
1119 ip0->dst_address = ip0->src_address;
1121 ip6_set_reserved_multicast_address (&ip0->dst_address,
1122 IP6_MULTICAST_SCOPE_link_local,
1123 IP6_MULTICAST_GROUP_ID_all_hosts);
1125 ip0->src_address = h0->target_address;
1126 ip0->hop_limit = 255;
1127 h0->icmp.type = ICMP6_neighbor_advertisement;
1129 sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index0);
1130 ASSERT (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE);
1132 ethernet_get_interface (ðernet_main, sw_if0->hw_if_index);
1135 clib_memcpy (o0->ethernet_address, eth_if0->address, 6);
1137 ICMP6_NEIGHBOR_DISCOVERY_OPTION_target_link_layer_address;
1140 h0->advertisement_flags = clib_host_to_net_u32
1141 (ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_SOLICITED
1142 | ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_OVERRIDE);
1144 h0->icmp.checksum = 0;
1146 ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip0,
1148 ASSERT (bogus_length == 0);
1150 /* Reuse current MAC header, copy SMAC to DMAC and
1151 * interface MAC to SMAC */
1152 vlib_buffer_advance (p0, -ethernet_buffer_header_size (p0));
1153 eth0 = vlib_buffer_get_current (p0);
1154 clib_memcpy (eth0->dst_address, eth0->src_address, 6);
1156 clib_memcpy (eth0->src_address, eth_if0->address, 6);
1158 /* Setup input and output sw_if_index for packet */
1159 ASSERT (vnet_buffer (p0)->sw_if_index[VLIB_RX] == sw_if_index0);
1160 vnet_buffer (p0)->sw_if_index[VLIB_TX] = sw_if_index0;
1161 vnet_buffer (p0)->sw_if_index[VLIB_RX] =
1162 vnet_main.local_interface_sw_if_index;
1164 n_advertisements_sent++;
1167 p0->error = error_node->errors[error0];
1169 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1170 to_next, n_left_to_next,
1174 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1177 /* Account for advertisements sent. */
1178 vlib_error_count (vm, error_node->node_index,
1179 ICMP6_ERROR_NEIGHBOR_ADVERTISEMENTS_TX,
1180 n_advertisements_sent);
1182 return frame->n_vectors;
1185 /* for "syslogging" - use elog for now */
1186 #define foreach_log_level \
1187 _ (DEBUG, "DEBUG") \
1188 _ (INFO, "INFORMATION") \
1189 _ (NOTICE, "NOTICE") \
1190 _ (WARNING, "WARNING") \
1192 _ (CRIT, "CRITICAL") \
1193 _ (ALERT, "ALERT") \
1194 _ (EMERG, "EMERGENCY")
1198 #define _(f,s) LOG_##f,
1203 static char *log_level_strings[] = {
1209 static int logmask = 1 << LOG_DEBUG;
1212 ip6_neighbor_syslog (vlib_main_t * vm, int priority, char *fmt, ...)
1214 /* just use elog for now */
1218 if ((priority > LOG_EMERG) || !(logmask & (1 << priority)))
1224 what = va_format (0, fmt, &va);
1226 ELOG_TYPE_DECLARE (e) =
1228 .format = "ip6 nd: (%s): %s",.format_args = "T4T4",};
1233 ed = ELOG_DATA (&vm->elog_main, e);
1234 ed->s[0] = elog_string (&vm->elog_main, log_level_strings[priority]);
1235 ed->s[1] = elog_string (&vm->elog_main, (char *) what);
1241 /* ipv6 neighbor discovery - router advertisements */
1244 ICMP6_ROUTER_SOLICITATION_NEXT_DROP,
1245 ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_RW,
1246 ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_TX,
1247 ICMP6_ROUTER_SOLICITATION_N_NEXT,
1248 } icmp6_router_solicitation_or_advertisement_next_t;
1250 static_always_inline uword
1251 icmp6_router_solicitation (vlib_main_t * vm,
1252 vlib_node_runtime_t * node, vlib_frame_t * frame)
1254 vnet_main_t *vnm = vnet_get_main ();
1255 ip6_main_t *im = &ip6_main;
1256 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
1257 uword n_packets = frame->n_vectors;
1258 u32 *from, *to_next;
1259 u32 n_left_from, n_left_to_next, next_index;
1260 u32 n_advertisements_sent = 0;
1263 icmp6_neighbor_discovery_option_type_t option_type;
1265 vlib_node_runtime_t *error_node =
1266 vlib_node_get_runtime (vm, ip6_icmp_input_node.index);
1268 from = vlib_frame_vector_args (frame);
1269 n_left_from = n_packets;
1270 next_index = node->cached_next_index;
1272 if (node->flags & VLIB_NODE_FLAG_TRACE)
1273 vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors,
1275 sizeof (icmp6_input_trace_t));
1277 /* source may append his LL address */
1278 option_type = ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address;
1280 while (n_left_from > 0)
1282 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1284 while (n_left_from > 0 && n_left_to_next > 0)
1288 ip6_radv_t *radv_info = 0;
1290 icmp6_neighbor_discovery_header_t *h0;
1291 icmp6_neighbor_discovery_ethernet_link_layer_address_option_t *o0;
1293 u32 bi0, options_len0, sw_if_index0, next0, error0;
1294 u32 is_solicitation = 1, is_dropped = 0;
1295 u32 is_unspecified, is_link_local;
1297 bi0 = to_next[0] = from[0];
1302 n_left_to_next -= 1;
1304 p0 = vlib_get_buffer (vm, bi0);
1305 ip0 = vlib_buffer_get_current (p0);
1306 h0 = ip6_next_header (ip0);
1308 clib_net_to_host_u16 (ip0->payload_length) - sizeof (h0[0]);
1309 is_unspecified = ip6_address_is_unspecified (&ip0->src_address);
1311 ip6_address_is_link_local_unicast (&ip0->src_address);
1313 error0 = ICMP6_ERROR_NONE;
1314 sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX];
1316 /* check if solicitation (not from nd_timer node) */
1317 if (ip6_address_is_unspecified (&ip0->dst_address))
1318 is_solicitation = 0;
1320 /* Check that source address is unspecified, link-local or else on-link. */
1321 if (!is_unspecified && !is_link_local)
1323 u32 src_adj_index0 = ip6_src_lookup_for_packet (im, p0, ip0);
1325 if (ADJ_INDEX_INVALID != src_adj_index0)
1327 ip_adjacency_t *adj0 = adj_get (src_adj_index0);
1329 error0 = (adj0->rewrite_header.sw_if_index != sw_if_index0
1331 ICMP6_ERROR_ROUTER_SOLICITATION_SOURCE_NOT_ON_LINK
1336 error0 = ICMP6_ERROR_ROUTER_SOLICITATION_SOURCE_NOT_ON_LINK;
1340 /* check for source LL option and process */
1341 o0 = (void *) (h0 + 1);
1342 o0 = ((options_len0 == 8
1343 && o0->header.type == option_type
1344 && o0->header.n_data_u64s == 1) ? o0 : 0);
1346 /* if src address unspecified IGNORE any options */
1347 if (PREDICT_TRUE (error0 == ICMP6_ERROR_NONE && o0 != 0 &&
1348 !is_unspecified && !is_link_local))
1350 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
1351 if (nm->limit_neighbor_cache_size &&
1352 pool_elts (nm->neighbor_pool) >=
1353 nm->limit_neighbor_cache_size)
1354 unset_random_neighbor_entry ();
1356 vnet_set_ip6_ethernet_neighbor (vm, sw_if_index0,
1358 o0->ethernet_address,
1359 sizeof (o0->ethernet_address),
1363 /* default is to drop */
1364 next0 = ICMP6_ROUTER_SOLICITATION_NEXT_DROP;
1366 if (error0 == ICMP6_ERROR_NONE)
1368 vnet_sw_interface_t *sw_if0;
1369 ethernet_interface_t *eth_if0;
1372 sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index0);
1373 ASSERT (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE);
1375 ethernet_get_interface (ðernet_main, sw_if0->hw_if_index);
1377 /* only support ethernet interface type for now */
1379 (!eth_if0) ? ICMP6_ERROR_ROUTER_SOLICITATION_UNSUPPORTED_INTF
1382 if (error0 == ICMP6_ERROR_NONE)
1386 /* adjust the sizeof the buffer to just include the ipv6 header */
1387 p0->current_length -=
1389 sizeof (icmp6_neighbor_discovery_header_t));
1391 /* look up the radv_t information for this interface */
1392 vec_validate_init_empty
1393 (nm->if_radv_pool_index_by_sw_if_index, sw_if_index0, ~0);
1395 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index0];
1398 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
1402 ICMP6_ERROR_ROUTER_SOLICITATION_RADV_NOT_CONFIG :
1405 if (error0 == ICMP6_ERROR_NONE)
1407 f64 now = vlib_time_now (vm);
1409 /* for solicited adverts - need to rate limit */
1410 if (is_solicitation)
1412 if (0 != radv_info->last_radv_time &&
1413 (now - radv_info->last_radv_time) <
1414 MIN_DELAY_BETWEEN_RAS)
1417 radv_info->last_radv_time = now;
1421 icmp6_router_advertisement_header_t rh;
1423 rh.icmp.type = ICMP6_router_advertisement;
1425 rh.icmp.checksum = 0;
1427 rh.current_hop_limit = radv_info->curr_hop_limit;
1428 rh.router_lifetime_in_sec =
1429 clib_host_to_net_u16
1430 (radv_info->adv_router_lifetime_in_sec);
1432 time_in_msec_between_retransmitted_neighbor_solicitations
1434 clib_host_to_net_u32 (radv_info->
1435 adv_time_in_msec_between_retransmitted_neighbor_solicitations);
1436 rh.neighbor_reachable_time_in_msec =
1437 clib_host_to_net_u32 (radv_info->
1438 adv_neighbor_reachable_time_in_msec);
1441 (radv_info->adv_managed_flag) ?
1442 ICMP6_ROUTER_DISCOVERY_FLAG_ADDRESS_CONFIG_VIA_DHCP :
1445 ((radv_info->adv_other_flag) ?
1446 ICMP6_ROUTER_DISCOVERY_FLAG_OTHER_CONFIG_VIA_DHCP :
1450 u16 payload_length =
1451 sizeof (icmp6_router_advertisement_header_t);
1453 vlib_buffer_add_data (vm,
1454 p0->free_list_index,
1458 (icmp6_router_advertisement_header_t));
1460 if (radv_info->adv_link_layer_address)
1462 icmp6_neighbor_discovery_ethernet_link_layer_address_option_t
1466 ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address;
1467 h.header.n_data_u64s = 1;
1469 /* copy ll address */
1470 clib_memcpy (&h.ethernet_address[0],
1471 eth_if0->address, 6);
1473 vlib_buffer_add_data (vm,
1474 p0->free_list_index,
1478 (icmp6_neighbor_discovery_ethernet_link_layer_address_option_t));
1482 (icmp6_neighbor_discovery_ethernet_link_layer_address_option_t);
1485 /* add MTU option */
1486 if (radv_info->adv_link_mtu)
1488 icmp6_neighbor_discovery_mtu_option_t h;
1492 clib_host_to_net_u32 (radv_info->adv_link_mtu);
1493 h.header.type = ICMP6_NEIGHBOR_DISCOVERY_OPTION_mtu;
1494 h.header.n_data_u64s = 1;
1497 sizeof (icmp6_neighbor_discovery_mtu_option_t);
1499 vlib_buffer_add_data (vm,
1500 p0->free_list_index,
1504 (icmp6_neighbor_discovery_mtu_option_t));
1507 /* add advertised prefix options */
1508 ip6_radv_prefix_t *pr_info;
1511 pool_foreach (pr_info, radv_info->adv_prefixes_pool,
1513 if(pr_info->enabled &&
1514 (!pr_info->decrement_lifetime_flag
1515 || (pr_info->pref_lifetime_expires >0)))
1517 /* advertise this prefix */
1518 icmp6_neighbor_discovery_prefix_information_option_t h;
1520 h.header.type = ICMP6_NEIGHBOR_DISCOVERY_OPTION_prefix_information;
1521 h.header.n_data_u64s = (sizeof(icmp6_neighbor_discovery_prefix_information_option_t) >> 3);
1523 h.dst_address_length = pr_info->prefix_len;
1525 h.flags = (pr_info->adv_on_link_flag) ? ICMP6_NEIGHBOR_DISCOVERY_PREFIX_INFORMATION_FLAG_ON_LINK : 0;
1526 h.flags |= (pr_info->adv_autonomous_flag) ? ICMP6_NEIGHBOR_DISCOVERY_PREFIX_INFORMATION_AUTO : 0;
1528 if(radv_info->cease_radv && pr_info->deprecated_prefix_flag)
1530 h.valid_time = clib_host_to_net_u32(MIN_ADV_VALID_LIFETIME);
1531 h.preferred_time = 0;
1535 if(pr_info->decrement_lifetime_flag)
1537 pr_info->adv_valid_lifetime_in_secs = ((pr_info->valid_lifetime_expires > now)) ?
1538 (pr_info->valid_lifetime_expires - now) : 0;
1540 pr_info->adv_pref_lifetime_in_secs = ((pr_info->pref_lifetime_expires > now)) ?
1541 (pr_info->pref_lifetime_expires - now) : 0;
1544 h.valid_time = clib_host_to_net_u32(pr_info->adv_valid_lifetime_in_secs);
1545 h.preferred_time = clib_host_to_net_u32(pr_info->adv_pref_lifetime_in_secs) ;
1549 clib_memcpy(&h.dst_address, &pr_info->prefix, sizeof(ip6_address_t));
1551 payload_length += sizeof( icmp6_neighbor_discovery_prefix_information_option_t);
1553 vlib_buffer_add_data (vm,
1554 p0->free_list_index,
1556 (void *)&h, sizeof(icmp6_neighbor_discovery_prefix_information_option_t));
1562 /* add additional options before here */
1564 /* finish building the router advertisement... */
1565 if (!is_unspecified && radv_info->send_unicast)
1567 ip0->dst_address = ip0->src_address;
1571 /* target address is all-nodes mcast addr */
1572 ip6_set_reserved_multicast_address
1574 IP6_MULTICAST_SCOPE_link_local,
1575 IP6_MULTICAST_GROUP_ID_all_hosts);
1578 /* source address MUST be the link-local address */
1579 ip0->src_address = radv_info->link_local_address;
1581 ip0->hop_limit = 255;
1582 ip0->payload_length =
1583 clib_host_to_net_u16 (payload_length);
1585 icmp6_router_advertisement_header_t *rh0 =
1586 (icmp6_router_advertisement_header_t *) (ip0 + 1);
1587 rh0->icmp.checksum =
1588 ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip0,
1590 ASSERT (bogus_length == 0);
1592 /* setup output if and adjacency */
1593 vnet_buffer (p0)->sw_if_index[VLIB_RX] =
1594 vnet_main.local_interface_sw_if_index;
1596 if (is_solicitation)
1598 ethernet_header_t *eth0;
1599 /* Reuse current MAC header, copy SMAC to DMAC and
1600 * interface MAC to SMAC */
1601 vlib_buffer_reset (p0);
1602 eth0 = vlib_buffer_get_current (p0);
1603 clib_memcpy (eth0->dst_address, eth0->src_address,
1605 clib_memcpy (eth0->src_address, eth_if0->address,
1608 is_dropped ? next0 :
1609 ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_TX;
1610 vnet_buffer (p0)->sw_if_index[VLIB_TX] =
1615 adj_index0 = radv_info->mcast_adj_index;
1616 if (adj_index0 == 0)
1617 error0 = ICMP6_ERROR_DST_LOOKUP_MISS;
1621 is_dropped ? next0 :
1622 ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_RW;
1623 vnet_buffer (p0)->ip.adj_index[VLIB_TX] =
1627 p0->flags |= VNET_BUFFER_LOCALLY_ORIGINATED;
1629 radv_info->n_solicitations_dropped += is_dropped;
1630 radv_info->n_solicitations_rcvd += is_solicitation;
1632 if ((error0 == ICMP6_ERROR_NONE) && !is_dropped)
1634 radv_info->n_advertisements_sent++;
1635 n_advertisements_sent++;
1641 p0->error = error_node->errors[error0];
1643 if (error0 != ICMP6_ERROR_NONE)
1644 vlib_error_count (vm, error_node->node_index, error0, 1);
1646 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1647 to_next, n_left_to_next,
1652 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1655 /* Account for router advertisements sent. */
1656 vlib_error_count (vm, error_node->node_index,
1657 ICMP6_ERROR_ROUTER_ADVERTISEMENTS_TX,
1658 n_advertisements_sent);
1660 return frame->n_vectors;
1663 /* validate advertised info for consistancy (see RFC-4861 section 6.2.7) - log any inconsistencies, packet will always be dropped */
1664 static_always_inline uword
1665 icmp6_router_advertisement (vlib_main_t * vm,
1666 vlib_node_runtime_t * node, vlib_frame_t * frame)
1668 vnet_main_t *vnm = vnet_get_main ();
1669 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
1670 uword n_packets = frame->n_vectors;
1671 u32 *from, *to_next;
1672 u32 n_left_from, n_left_to_next, next_index;
1673 u32 n_advertisements_rcvd = 0;
1675 vlib_node_runtime_t *error_node =
1676 vlib_node_get_runtime (vm, ip6_icmp_input_node.index);
1678 from = vlib_frame_vector_args (frame);
1679 n_left_from = n_packets;
1680 next_index = node->cached_next_index;
1682 if (node->flags & VLIB_NODE_FLAG_TRACE)
1683 vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors,
1685 sizeof (icmp6_input_trace_t));
1687 while (n_left_from > 0)
1689 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1691 while (n_left_from > 0 && n_left_to_next > 0)
1695 ip6_radv_t *radv_info = 0;
1696 icmp6_router_advertisement_header_t *h0;
1697 u32 bi0, options_len0, sw_if_index0, next0, error0;
1699 bi0 = to_next[0] = from[0];
1704 n_left_to_next -= 1;
1706 p0 = vlib_get_buffer (vm, bi0);
1707 ip0 = vlib_buffer_get_current (p0);
1708 h0 = ip6_next_header (ip0);
1710 clib_net_to_host_u16 (ip0->payload_length) - sizeof (h0[0]);
1712 error0 = ICMP6_ERROR_NONE;
1713 sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX];
1715 /* Check that source address is link-local */
1716 error0 = (!ip6_address_is_link_local_unicast (&ip0->src_address)) ?
1717 ICMP6_ERROR_ROUTER_ADVERTISEMENT_SOURCE_NOT_LINK_LOCAL : error0;
1719 /* default is to drop */
1720 next0 = ICMP6_ROUTER_SOLICITATION_NEXT_DROP;
1722 n_advertisements_rcvd++;
1724 if (error0 == ICMP6_ERROR_NONE)
1726 vnet_sw_interface_t *sw_if0;
1727 ethernet_interface_t *eth_if0;
1729 sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index0);
1730 ASSERT (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE);
1732 ethernet_get_interface (ðernet_main, sw_if0->hw_if_index);
1734 /* only support ethernet interface type for now */
1736 (!eth_if0) ? ICMP6_ERROR_ROUTER_SOLICITATION_UNSUPPORTED_INTF
1739 if (error0 == ICMP6_ERROR_NONE)
1743 /* look up the radv_t information for this interface */
1744 vec_validate_init_empty
1745 (nm->if_radv_pool_index_by_sw_if_index, sw_if_index0, ~0);
1747 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index0];
1750 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
1754 ICMP6_ERROR_ROUTER_SOLICITATION_RADV_NOT_CONFIG :
1757 if (error0 == ICMP6_ERROR_NONE)
1759 /* validate advertised information */
1760 if ((h0->current_hop_limit && radv_info->curr_hop_limit)
1761 && (h0->current_hop_limit !=
1762 radv_info->curr_hop_limit))
1764 ip6_neighbor_syslog (vm, LOG_WARNING,
1765 "our AdvCurHopLimit on %U doesn't agree with %U",
1766 format_vnet_sw_if_index_name,
1773 ICMP6_ROUTER_DISCOVERY_FLAG_ADDRESS_CONFIG_VIA_DHCP)
1774 != radv_info->adv_managed_flag)
1776 ip6_neighbor_syslog (vm, LOG_WARNING,
1777 "our AdvManagedFlag on %U doesn't agree with %U",
1778 format_vnet_sw_if_index_name,
1785 ICMP6_ROUTER_DISCOVERY_FLAG_OTHER_CONFIG_VIA_DHCP)
1786 != radv_info->adv_other_flag)
1788 ip6_neighbor_syslog (vm, LOG_WARNING,
1789 "our AdvOtherConfigFlag on %U doesn't agree with %U",
1790 format_vnet_sw_if_index_name,
1797 time_in_msec_between_retransmitted_neighbor_solicitations
1799 adv_time_in_msec_between_retransmitted_neighbor_solicitations)
1801 time_in_msec_between_retransmitted_neighbor_solicitations
1803 clib_host_to_net_u32 (radv_info->
1804 adv_time_in_msec_between_retransmitted_neighbor_solicitations)))
1806 ip6_neighbor_syslog (vm, LOG_WARNING,
1807 "our AdvRetransTimer on %U doesn't agree with %U",
1808 format_vnet_sw_if_index_name,
1814 if ((h0->neighbor_reachable_time_in_msec &&
1815 radv_info->adv_neighbor_reachable_time_in_msec) &&
1816 (h0->neighbor_reachable_time_in_msec !=
1817 clib_host_to_net_u32
1818 (radv_info->adv_neighbor_reachable_time_in_msec)))
1820 ip6_neighbor_syslog (vm, LOG_WARNING,
1821 "our AdvReachableTime on %U doesn't agree with %U",
1822 format_vnet_sw_if_index_name,
1828 /* check for MTU or prefix options or .. */
1829 u8 *opt_hdr = (u8 *) (h0 + 1);
1830 while (options_len0 > 0)
1832 icmp6_neighbor_discovery_option_header_t *o0 =
1833 (icmp6_neighbor_discovery_option_header_t *)
1835 int opt_len = o0->n_data_u64s << 3;
1836 icmp6_neighbor_discovery_option_type_t option_type =
1839 if (options_len0 < 2)
1841 ip6_neighbor_syslog (vm, LOG_ERR,
1842 "malformed RA packet on %U from %U",
1843 format_vnet_sw_if_index_name,
1852 ip6_neighbor_syslog (vm, LOG_ERR,
1853 " zero length option in RA on %U from %U",
1854 format_vnet_sw_if_index_name,
1860 else if (opt_len > options_len0)
1862 ip6_neighbor_syslog (vm, LOG_ERR,
1863 "option length in RA packet greater than total length on %U from %U",
1864 format_vnet_sw_if_index_name,
1871 options_len0 -= opt_len;
1874 switch (option_type)
1876 case ICMP6_NEIGHBOR_DISCOVERY_OPTION_mtu:
1878 icmp6_neighbor_discovery_mtu_option_t *h =
1879 (icmp6_neighbor_discovery_mtu_option_t
1882 if (opt_len < sizeof (*h))
1885 if ((h->mtu && radv_info->adv_link_mtu) &&
1887 clib_host_to_net_u32
1888 (radv_info->adv_link_mtu)))
1890 ip6_neighbor_syslog (vm, LOG_WARNING,
1891 "our AdvLinkMTU on %U doesn't agree with %U",
1892 format_vnet_sw_if_index_name,
1900 case ICMP6_NEIGHBOR_DISCOVERY_OPTION_prefix_information:
1902 icmp6_neighbor_discovery_prefix_information_option_t
1904 (icmp6_neighbor_discovery_prefix_information_option_t
1907 /* validate advertised prefix options */
1908 ip6_radv_prefix_t *pr_info;
1909 u32 preferred, valid;
1911 if (opt_len < sizeof (*h))
1915 clib_net_to_host_u32 (h->preferred_time);
1916 valid = clib_net_to_host_u32 (h->valid_time);
1918 /* look for matching prefix - if we our advertising it, it better be consistant */
1920 pool_foreach (pr_info, radv_info->adv_prefixes_pool,
1924 ip6_address_mask_from_width(&mask, pr_info->prefix_len);
1926 if(pr_info->enabled &&
1927 (pr_info->prefix_len == h->dst_address_length) &&
1928 ip6_address_is_equal_masked (&pr_info->prefix, &h->dst_address, &mask))
1931 if(!pr_info->decrement_lifetime_flag &&
1932 valid != pr_info->adv_valid_lifetime_in_secs)
1934 ip6_neighbor_syslog(vm, LOG_WARNING,
1935 "our ADV validlifetime on %U for %U does not agree with %U",
1936 format_vnet_sw_if_index_name, vnm, sw_if_index0,format_ip6_address, &pr_info->prefix,
1937 format_ip6_address, &h->dst_address);
1939 if(!pr_info->decrement_lifetime_flag &&
1940 preferred != pr_info->adv_pref_lifetime_in_secs)
1942 ip6_neighbor_syslog(vm, LOG_WARNING,
1943 "our ADV preferredlifetime on %U for %U does not agree with %U",
1944 format_vnet_sw_if_index_name, vnm, sw_if_index0,format_ip6_address, &pr_info->prefix,
1945 format_ip6_address, &h->dst_address);
1962 p0->error = error_node->errors[error0];
1964 if (error0 != ICMP6_ERROR_NONE)
1965 vlib_error_count (vm, error_node->node_index, error0, 1);
1967 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1968 to_next, n_left_to_next,
1972 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1975 /* Account for router advertisements sent. */
1976 vlib_error_count (vm, error_node->node_index,
1977 ICMP6_ERROR_ROUTER_ADVERTISEMENTS_RX,
1978 n_advertisements_rcvd);
1980 return frame->n_vectors;
1984 * @brief Add a multicast Address to the advertised MLD set
1987 ip6_neighbor_add_mld_prefix (ip6_radv_t * radv_info, ip6_address_t * addr)
1989 ip6_mldp_group_t *mcast_group_info;
1992 /* lookup mldp info for this interface */
1993 p = mhash_get (&radv_info->address_to_mldp_index, &addr);
1995 p ? pool_elt_at_index (radv_info->mldp_group_pool, p[0]) : 0;
1998 if (!mcast_group_info)
2002 pool_get (radv_info->mldp_group_pool, mcast_group_info);
2004 mi = mcast_group_info - radv_info->mldp_group_pool;
2005 mhash_set (&radv_info->address_to_mldp_index, &addr, mi, /* old_value */
2008 mcast_group_info->type = 4;
2009 mcast_group_info->mcast_source_address_pool = 0;
2010 mcast_group_info->num_sources = 0;
2011 clib_memcpy (&mcast_group_info->mcast_address, &addr,
2012 sizeof (ip6_address_t));
2017 * @brief Delete a multicast Address from the advertised MLD set
2020 ip6_neighbor_del_mld_prefix (ip6_radv_t * radv_info, ip6_address_t * addr)
2022 ip6_mldp_group_t *mcast_group_info;
2025 p = mhash_get (&radv_info->address_to_mldp_index, &addr);
2027 p ? pool_elt_at_index (radv_info->mldp_group_pool, p[0]) : 0;
2029 if (mcast_group_info)
2031 mhash_unset (&radv_info->address_to_mldp_index, &addr,
2033 pool_put (radv_info->mldp_group_pool, mcast_group_info);
2038 * @brief Add a multicast Address to the advertised MLD set
2041 ip6_neighbor_add_mld_grp (ip6_radv_t * a,
2042 ip6_multicast_address_scope_t scope,
2043 ip6_multicast_link_local_group_id_t group)
2047 ip6_set_reserved_multicast_address (&addr, scope, group);
2049 ip6_neighbor_add_mld_prefix (a, &addr);
2053 * @brief create and initialize router advertisement parameters with default
2054 * values for this intfc
2057 ip6_neighbor_sw_interface_add_del (vnet_main_t * vnm,
2058 u32 sw_if_index, u32 is_add)
2060 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
2063 vnet_sw_interface_t *sw_if0;
2064 ethernet_interface_t *eth_if0 = 0;
2066 /* lookup radv container - ethernet interfaces only */
2067 sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index);
2068 if (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE)
2069 eth_if0 = ethernet_get_interface (ðernet_main, sw_if0->hw_if_index);
2074 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index,
2076 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
2080 a = pool_elt_at_index (nm->if_radv_pool, ri);
2084 ip6_radv_prefix_t *p;
2085 ip6_mldp_group_t *m;
2087 /* release the lock on the interface's mcast adj */
2088 adj_unlock (a->mcast_adj_index);
2090 /* clean up prefix and MDP pools */
2092 pool_flush(p, a->adv_prefixes_pool,
2094 mhash_unset (&a->address_to_prefix_index, &p->prefix, 0);
2096 pool_flush (m, a->mldp_group_pool,
2098 mhash_unset (&a->address_to_mldp_index, &m->mcast_address, 0);
2102 pool_free (a->mldp_group_pool);
2103 pool_free (a->adv_prefixes_pool);
2105 mhash_free (&a->address_to_prefix_index);
2106 mhash_free (&a->address_to_mldp_index);
2108 pool_put (nm->if_radv_pool, a);
2109 nm->if_radv_pool_index_by_sw_if_index[sw_if_index] = ~0;
2117 vnet_hw_interface_t *hw_if0;
2119 hw_if0 = vnet_get_sup_hw_interface (vnm, sw_if_index);
2121 pool_get (nm->if_radv_pool, a);
2123 ri = a - nm->if_radv_pool;
2124 nm->if_radv_pool_index_by_sw_if_index[sw_if_index] = ri;
2126 /* initialize default values (most of which are zero) */
2127 memset (a, 0, sizeof (a[0]));
2129 a->sw_if_index = sw_if_index;
2130 a->max_radv_interval = DEF_MAX_RADV_INTERVAL;
2131 a->min_radv_interval = DEF_MIN_RADV_INTERVAL;
2132 a->curr_hop_limit = DEF_CURR_HOP_LIMIT;
2133 a->adv_router_lifetime_in_sec = DEF_DEF_RTR_LIFETIME;
2135 /* send ll address source address option */
2136 a->adv_link_layer_address = 1;
2138 a->min_delay_between_radv = MIN_DELAY_BETWEEN_RAS;
2139 a->max_delay_between_radv = MAX_DELAY_BETWEEN_RAS;
2140 a->max_rtr_default_lifetime = MAX_DEF_RTR_LIFETIME;
2141 a->seed = (u32) clib_cpu_time_now ();
2142 (void) random_u32 (&a->seed);
2143 a->randomizer = clib_cpu_time_now ();
2144 (void) random_u64 (&a->randomizer);
2146 a->initial_adverts_count = MAX_INITIAL_RTR_ADVERTISEMENTS;
2147 a->initial_adverts_sent = a->initial_adverts_count - 1;
2148 a->initial_adverts_interval = MAX_INITIAL_RTR_ADVERT_INTERVAL;
2150 /* deafult is to send */
2153 /* fill in radv_info for this interface that will be needed later */
2154 a->adv_link_mtu = hw_if0->max_l3_packet_bytes[VLIB_RX];
2156 clib_memcpy (a->link_layer_address, eth_if0->address, 6);
2158 /* fill in default link-local address (this may be overridden) */
2159 ip6_link_local_address_from_ethernet_address
2160 (&a->link_local_address, eth_if0->address);
2162 mhash_init (&a->address_to_prefix_index, sizeof (uword),
2163 sizeof (ip6_address_t));
2164 mhash_init (&a->address_to_mldp_index, sizeof (uword),
2165 sizeof (ip6_address_t));
2167 a->mcast_adj_index = adj_mcast_add_or_lock (FIB_PROTOCOL_IP6,
2171 /* add multicast groups we will always be reporting */
2172 ip6_neighbor_add_mld_grp (a,
2173 IP6_MULTICAST_SCOPE_link_local,
2174 IP6_MULTICAST_GROUP_ID_all_hosts);
2175 ip6_neighbor_add_mld_grp (a,
2176 IP6_MULTICAST_SCOPE_link_local,
2177 IP6_MULTICAST_GROUP_ID_all_routers);
2178 ip6_neighbor_add_mld_grp (a,
2179 IP6_MULTICAST_SCOPE_link_local,
2180 IP6_MULTICAST_GROUP_ID_mldv2_routers);
2186 /* send an mldpv2 report */
2188 ip6_neighbor_send_mldpv2_report (u32 sw_if_index)
2190 vnet_main_t *vnm = vnet_get_main ();
2191 vlib_main_t *vm = vnm->vlib_main;
2192 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
2193 vnet_sw_interface_t *sw_if0;
2194 ethernet_interface_t *eth_if0;
2198 ip6_radv_t *radv_info;
2208 icmp6_multicast_listener_report_header_t *rh0;
2209 icmp6_multicast_listener_report_packet_t *rp0;
2211 sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index);
2212 ASSERT (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE);
2213 eth_if0 = ethernet_get_interface (ðernet_main, sw_if0->hw_if_index);
2215 if (!eth_if0 || !vnet_sw_interface_is_admin_up (vnm, sw_if_index))
2218 /* look up the radv_t information for this interface */
2219 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index,
2222 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
2227 /* send report now - build a mldpv2 report packet */
2228 n_allocated = vlib_buffer_alloc_from_free_list (vm,
2231 VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
2232 if (PREDICT_FALSE (n_allocated == 0))
2234 clib_warning ("buffer allocation failure");
2238 b0 = vlib_get_buffer (vm, bo0);
2240 /* adjust the sizeof the buffer to just include the ipv6 header */
2241 b0->current_length = sizeof (icmp6_multicast_listener_report_packet_t);
2243 payload_length = sizeof (icmp6_multicast_listener_report_header_t);
2245 b0->error = ICMP6_ERROR_NONE;
2247 rp0 = vlib_buffer_get_current (b0);
2248 ip0 = (ip6_header_t *) & rp0->ip;
2249 rh0 = (icmp6_multicast_listener_report_header_t *) & rp0->report_hdr;
2251 memset (rp0, 0x0, sizeof (icmp6_multicast_listener_report_packet_t));
2253 ip0->ip_version_traffic_class_and_flow_label =
2254 clib_host_to_net_u32 (0x6 << 28);
2256 ip0->protocol = IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS;
2257 /* for DEBUG - vnet driver won't seem to emit router alerts */
2258 /* ip0->protocol = IP_PROTOCOL_ICMP6; */
2261 rh0->icmp.type = ICMP6_multicast_listener_report_v2;
2263 /* source address MUST be the link-local address */
2264 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
2265 ip0->src_address = radv_info->link_local_address;
2267 /* destination is all mldpv2 routers */
2268 ip6_set_reserved_multicast_address (&ip0->dst_address,
2269 IP6_MULTICAST_SCOPE_link_local,
2270 IP6_MULTICAST_GROUP_ID_mldv2_routers);
2272 /* add reports here */
2273 ip6_mldp_group_t *m;
2274 int num_addr_records = 0;
2275 icmp6_multicast_address_record_t rr;
2277 /* fill in the hop-by-hop extension header (router alert) info */
2278 rh0->ext_hdr.next_hdr = IP_PROTOCOL_ICMP6;
2279 rh0->ext_hdr.n_data_u64s = 0;
2281 rh0->alert.type = IP6_MLDP_ALERT_TYPE;
2283 rh0->alert.value = 0;
2288 rh0->icmp.checksum = 0;
2291 pool_foreach (m, radv_info->mldp_group_pool,
2294 rr.aux_data_len_u32s = 0;
2295 rr.num_sources = clib_host_to_net_u16 (m->num_sources);
2296 clib_memcpy(&rr.mcast_addr, &m->mcast_address, sizeof(ip6_address_t));
2300 vlib_buffer_add_data
2301 (vm, b0->free_list_index, bo0,
2302 (void *)&rr, sizeof(icmp6_multicast_address_record_t));
2304 payload_length += sizeof( icmp6_multicast_address_record_t);
2309 rh0->num_addr_records = clib_host_to_net_u16 (num_addr_records);
2311 /* update lengths */
2312 ip0->payload_length = clib_host_to_net_u16 (payload_length);
2314 rh0->icmp.checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip0,
2316 ASSERT (bogus_length == 0);
2319 * OK to override w/ no regard for actual FIB, because
2320 * ip6-rewrite only looks at the adjacency.
2322 vnet_buffer (b0)->sw_if_index[VLIB_RX] =
2323 vnet_main.local_interface_sw_if_index;
2325 vnet_buffer (b0)->ip.adj_index[VLIB_TX] = radv_info->mcast_adj_index;
2326 b0->flags |= VNET_BUFFER_LOCALLY_ORIGINATED;
2328 vlib_node_t *node = vlib_get_node_by_name (vm, (u8 *) "ip6-rewrite-mcast");
2330 f = vlib_get_frame_to_node (vm, node->index);
2331 to_next = vlib_frame_vector_args (f);
2335 vlib_put_frame_to_node (vm, node->index, f);
2340 VLIB_REGISTER_NODE (ip6_icmp_router_solicitation_node,static) =
2342 .function = icmp6_router_solicitation,
2343 .name = "icmp6-router-solicitation",
2345 .vector_size = sizeof (u32),
2347 .format_trace = format_icmp6_input_trace,
2349 .n_next_nodes = ICMP6_ROUTER_SOLICITATION_N_NEXT,
2351 [ICMP6_ROUTER_SOLICITATION_NEXT_DROP] = "error-drop",
2352 [ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_RW] = "ip6-rewrite-mcast",
2353 [ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_TX] = "interface-output",
2358 /* send a RA or update the timer info etc.. */
2360 ip6_neighbor_process_timer_event (vlib_main_t * vm,
2361 vlib_node_runtime_t * node,
2362 vlib_frame_t * frame)
2364 vnet_main_t *vnm = vnet_get_main ();
2365 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
2366 ip6_radv_t *radv_info;
2367 vlib_frame_t *f = 0;
2368 u32 n_this_frame = 0;
2369 u32 n_left_to_next = 0;
2372 icmp6_router_solicitation_header_t *h0;
2374 f64 now = vlib_time_now (vm);
2376 /* Interface ip6 radv info list */
2378 pool_foreach (radv_info, nm->if_radv_pool,
2380 if( !vnet_sw_interface_is_admin_up (vnm, radv_info->sw_if_index))
2382 radv_info->initial_adverts_sent = radv_info->initial_adverts_count-1;
2383 radv_info->next_multicast_time = now;
2384 radv_info->last_multicast_time = now;
2385 radv_info->last_radv_time = 0;
2386 radv_info->all_routers_mcast = 0;
2390 /* Make sure that we've joined the all-routers multicast group */
2391 if(!radv_info->all_routers_mcast)
2393 /* send MDLP_REPORT_EVENT message */
2394 ip6_neighbor_send_mldpv2_report(radv_info->sw_if_index);
2395 radv_info->all_routers_mcast = 1;
2398 /* is it time to send a multicast RA on this interface? */
2399 if(radv_info->send_radv && (now >= radv_info->next_multicast_time))
2404 f64 rfn = (radv_info->max_radv_interval - radv_info->min_radv_interval) *
2405 random_f64 (&radv_info->seed) + radv_info->min_radv_interval;
2407 /* multicast send - compute next multicast send time */
2408 if( radv_info->initial_adverts_sent > 0)
2410 radv_info->initial_adverts_sent--;
2411 if(rfn > radv_info-> initial_adverts_interval)
2412 rfn = radv_info-> initial_adverts_interval;
2414 /* check to see if we are ceasing to send */
2415 if( radv_info->initial_adverts_sent == 0)
2416 if(radv_info->cease_radv)
2417 radv_info->send_radv = 0;
2420 radv_info->next_multicast_time = rfn + now;
2421 radv_info->last_multicast_time = now;
2423 /* send advert now - build a "solicted" router advert with unspecified source address */
2424 n_allocated = vlib_buffer_alloc_from_free_list
2425 (vm, &bo0, n_to_alloc, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
2427 if (PREDICT_FALSE(n_allocated == 0))
2429 clib_warning ("buffer allocation failure");
2432 b0 = vlib_get_buffer (vm, bo0);
2433 b0->current_length = sizeof( icmp6_router_solicitation_header_t);
2434 b0->error = ICMP6_ERROR_NONE;
2435 vnet_buffer (b0)->sw_if_index[VLIB_RX] = radv_info->sw_if_index;
2437 h0 = vlib_buffer_get_current (b0);
2439 memset (h0, 0, sizeof (icmp6_router_solicitation_header_t));
2441 h0->ip.ip_version_traffic_class_and_flow_label = clib_host_to_net_u32 (0x6 << 28);
2442 h0->ip.payload_length = clib_host_to_net_u16 (sizeof (icmp6_router_solicitation_header_t)
2443 - STRUCT_OFFSET_OF (icmp6_router_solicitation_header_t, neighbor));
2444 h0->ip.protocol = IP_PROTOCOL_ICMP6;
2445 h0->ip.hop_limit = 255;
2447 /* set src/dst address as "unspecified" this marks this packet as internally generated rather than recieved */
2448 h0->ip.src_address.as_u64[0] = 0;
2449 h0->ip.src_address.as_u64[1] = 0;
2451 h0->ip.dst_address.as_u64[0] = 0;
2452 h0->ip.dst_address.as_u64[1] = 0;
2454 h0->neighbor.icmp.type = ICMP6_router_solicitation;
2456 if (PREDICT_FALSE(f == 0))
2458 f = vlib_get_frame_to_node (vm, ip6_icmp_router_solicitation_node.index);
2459 to_next = vlib_frame_vector_args (f);
2460 n_left_to_next = VLIB_FRAME_SIZE;
2469 if (PREDICT_FALSE(n_left_to_next == 0))
2471 f->n_vectors = n_this_frame;
2472 vlib_put_frame_to_node (vm, ip6_icmp_router_solicitation_node.index, f);
2481 ASSERT (n_this_frame);
2482 f->n_vectors = n_this_frame;
2483 vlib_put_frame_to_node (vm, ip6_icmp_router_solicitation_node.index, f);
2489 ip6_icmp_neighbor_discovery_event_process (vlib_main_t * vm,
2490 vlib_node_runtime_t * node,
2491 vlib_frame_t * frame)
2494 ip6_icmp_neighbor_discovery_event_data_t *event_data;
2496 /* init code here */
2500 vlib_process_wait_for_event_or_clock (vm, 1. /* seconds */ );
2502 event_data = vlib_process_get_event_data (vm, &event_type);
2506 /* No events found: timer expired. */
2507 /* process interface list and send RAs as appropriate, update timer info */
2508 ip6_neighbor_process_timer_event (vm, node, frame);
2515 case ICMP6_ND_EVENT_INIT:
2526 _vec_len (event_data) = 0;
2529 return frame->n_vectors;
2533 VLIB_REGISTER_NODE (ip6_icmp_router_advertisement_node,static) =
2535 .function = icmp6_router_advertisement,
2536 .name = "icmp6-router-advertisement",
2538 .vector_size = sizeof (u32),
2540 .format_trace = format_icmp6_input_trace,
2549 vlib_node_registration_t ip6_icmp_neighbor_discovery_event_node = {
2551 .function = ip6_icmp_neighbor_discovery_event_process,
2552 .name = "ip6-icmp-neighbor-discovery-event-process",
2553 .type = VLIB_NODE_TYPE_PROCESS,
2557 icmp6_neighbor_solicitation (vlib_main_t * vm,
2558 vlib_node_runtime_t * node, vlib_frame_t * frame)
2560 return icmp6_neighbor_solicitation_or_advertisement (vm, node, frame,
2561 /* is_solicitation */
2566 icmp6_neighbor_advertisement (vlib_main_t * vm,
2567 vlib_node_runtime_t * node,
2568 vlib_frame_t * frame)
2570 return icmp6_neighbor_solicitation_or_advertisement (vm, node, frame,
2571 /* is_solicitation */
2576 VLIB_REGISTER_NODE (ip6_icmp_neighbor_solicitation_node,static) =
2578 .function = icmp6_neighbor_solicitation,
2579 .name = "icmp6-neighbor-solicitation",
2581 .vector_size = sizeof (u32),
2583 .format_trace = format_icmp6_input_trace,
2585 .n_next_nodes = ICMP6_NEIGHBOR_SOLICITATION_N_NEXT,
2587 [ICMP6_NEIGHBOR_SOLICITATION_NEXT_DROP] = "error-drop",
2588 [ICMP6_NEIGHBOR_SOLICITATION_NEXT_REPLY] = "interface-output",
2594 VLIB_REGISTER_NODE (ip6_icmp_neighbor_advertisement_node,static) =
2596 .function = icmp6_neighbor_advertisement,
2597 .name = "icmp6-neighbor-advertisement",
2599 .vector_size = sizeof (u32),
2601 .format_trace = format_icmp6_input_trace,
2610 /* API support functions */
2612 ip6_neighbor_ra_config (vlib_main_t * vm, u32 sw_if_index,
2613 u8 suppress, u8 managed, u8 other,
2614 u8 ll_option, u8 send_unicast, u8 cease,
2615 u8 use_lifetime, u32 lifetime,
2616 u32 initial_count, u32 initial_interval,
2617 u32 max_interval, u32 min_interval, u8 is_no)
2619 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
2623 /* look up the radv_t information for this interface */
2624 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index,
2626 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
2627 error = (ri != ~0) ? 0 : VNET_API_ERROR_INVALID_SW_IF_INDEX;
2632 ip6_radv_t *radv_info;
2633 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
2635 if ((max_interval != 0) && (min_interval == 0))
2636 min_interval = .75 * max_interval;
2640 0) ? ((is_no) ? DEF_MAX_RADV_INTERVAL : max_interval) :
2641 radv_info->max_radv_interval;
2644 0) ? ((is_no) ? DEF_MIN_RADV_INTERVAL : min_interval) :
2645 radv_info->min_radv_interval;
2648 0) ? ((is_no) ? DEF_DEF_RTR_LIFETIME : lifetime) :
2649 radv_info->adv_router_lifetime_in_sec;
2653 if (lifetime > MAX_DEF_RTR_LIFETIME)
2654 lifetime = MAX_DEF_RTR_LIFETIME;
2656 if (lifetime <= max_interval)
2657 return VNET_API_ERROR_INVALID_VALUE;
2660 if (min_interval != 0)
2662 if ((min_interval > .75 * max_interval) || (min_interval < 3))
2663 return VNET_API_ERROR_INVALID_VALUE;
2666 if ((initial_count > MAX_INITIAL_RTR_ADVERTISEMENTS) ||
2667 (initial_interval > MAX_INITIAL_RTR_ADVERT_INTERVAL))
2668 return VNET_API_ERROR_INVALID_VALUE;
2671 if "flag" is set and is_no is true then restore default value else set value corresponding to "flag"
2672 if "flag" is clear don't change corresponding value
2674 radv_info->send_radv =
2675 (suppress != 0) ? ((is_no != 0) ? 1 : 0) : radv_info->send_radv;
2676 radv_info->adv_managed_flag =
2677 (managed != 0) ? ((is_no) ? 0 : 1) : radv_info->adv_managed_flag;
2678 radv_info->adv_other_flag =
2679 (other != 0) ? ((is_no) ? 0 : 1) : radv_info->adv_other_flag;
2680 radv_info->adv_link_layer_address =
2682 0) ? ((is_no) ? 1 : 0) : radv_info->adv_link_layer_address;
2683 radv_info->send_unicast =
2684 (send_unicast != 0) ? ((is_no) ? 0 : 1) : radv_info->send_unicast;
2685 radv_info->cease_radv =
2686 (cease != 0) ? ((is_no) ? 0 : 1) : radv_info->cease_radv;
2688 radv_info->min_radv_interval = min_interval;
2689 radv_info->max_radv_interval = max_interval;
2690 radv_info->adv_router_lifetime_in_sec = lifetime;
2692 radv_info->initial_adverts_count =
2694 0) ? ((is_no) ? MAX_INITIAL_RTR_ADVERTISEMENTS : initial_count) :
2695 radv_info->initial_adverts_count;
2696 radv_info->initial_adverts_interval =
2697 (initial_interval !=
2698 0) ? ((is_no) ? MAX_INITIAL_RTR_ADVERT_INTERVAL : initial_interval) :
2699 radv_info->initial_adverts_interval;
2702 if ((cease != 0) && (is_no))
2703 radv_info->send_radv = 1;
2705 radv_info->initial_adverts_sent = radv_info->initial_adverts_count - 1;
2706 radv_info->next_multicast_time = vlib_time_now (vm);
2707 radv_info->last_multicast_time = vlib_time_now (vm);
2708 radv_info->last_radv_time = 0;
2714 ip6_neighbor_ra_prefix (vlib_main_t * vm, u32 sw_if_index,
2715 ip6_address_t * prefix_addr, u8 prefix_len,
2716 u8 use_default, u32 val_lifetime, u32 pref_lifetime,
2717 u8 no_advertise, u8 off_link, u8 no_autoconfig,
2718 u8 no_onlink, u8 is_no)
2720 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
2725 /* look up the radv_t information for this interface */
2726 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index,
2729 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
2731 error = (ri != ~0) ? 0 : VNET_API_ERROR_INVALID_SW_IF_INDEX;
2735 f64 now = vlib_time_now (vm);
2736 ip6_radv_t *radv_info;
2737 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
2739 /* prefix info add, delete or update */
2740 ip6_radv_prefix_t *prefix;
2742 /* lookup prefix info for this address on this interface */
2743 uword *p = mhash_get (&radv_info->address_to_prefix_index, prefix_addr);
2745 prefix = p ? pool_elt_at_index (radv_info->adv_prefixes_pool, p[0]) : 0;
2751 return VNET_API_ERROR_INVALID_VALUE; /* invalid prefix */
2753 if (prefix->prefix_len != prefix_len)
2754 return VNET_API_ERROR_INVALID_VALUE_2;
2756 /* FIXME - Should the DP do this or the CP ? */
2757 /* do specific delete processing here before returning */
2758 /* try to remove from routing table */
2760 mhash_unset (&radv_info->address_to_prefix_index, prefix_addr,
2762 pool_put (radv_info->adv_prefixes_pool, prefix);
2764 radv_info->initial_adverts_sent =
2765 radv_info->initial_adverts_count - 1;
2766 radv_info->next_multicast_time = vlib_time_now (vm);
2767 radv_info->last_multicast_time = vlib_time_now (vm);
2768 radv_info->last_radv_time = 0;
2772 /* adding or changing */
2777 pool_get (radv_info->adv_prefixes_pool, prefix);
2778 pi = prefix - radv_info->adv_prefixes_pool;
2779 mhash_set (&radv_info->address_to_prefix_index, prefix_addr, pi,
2782 memset (prefix, 0x0, sizeof (ip6_radv_prefix_t));
2784 prefix->prefix_len = prefix_len;
2785 clib_memcpy (&prefix->prefix, prefix_addr, sizeof (ip6_address_t));
2787 /* initialize default values */
2788 prefix->adv_on_link_flag = 1; /* L bit set */
2789 prefix->adv_autonomous_flag = 1; /* A bit set */
2790 prefix->adv_valid_lifetime_in_secs = DEF_ADV_VALID_LIFETIME;
2791 prefix->adv_pref_lifetime_in_secs = DEF_ADV_PREF_LIFETIME;
2792 prefix->enabled = 1;
2793 prefix->decrement_lifetime_flag = 1;
2794 prefix->deprecated_prefix_flag = 1;
2798 /* FIXME - Should the DP do this or the CP ? */
2799 /* insert prefix into routing table as a connected prefix */
2808 if (prefix->prefix_len != prefix_len)
2809 return VNET_API_ERROR_INVALID_VALUE_2;
2813 /* FIXME - Should the DP do this or the CP ? */
2814 /* remove from routing table if already there */
2818 if ((val_lifetime == ~0) || (pref_lifetime == ~0))
2820 prefix->adv_valid_lifetime_in_secs = ~0;
2821 prefix->adv_pref_lifetime_in_secs = ~0;
2822 prefix->decrement_lifetime_flag = 0;
2826 prefix->adv_valid_lifetime_in_secs = val_lifetime;;
2827 prefix->adv_pref_lifetime_in_secs = pref_lifetime;
2830 /* copy remaining */
2831 prefix->enabled = !(no_advertise != 0);
2832 prefix->adv_on_link_flag = !((off_link != 0) || (no_onlink != 0));
2833 prefix->adv_autonomous_flag = !(no_autoconfig != 0);
2837 /* fill in the expiration times */
2838 prefix->valid_lifetime_expires =
2839 now + prefix->adv_valid_lifetime_in_secs;
2840 prefix->pref_lifetime_expires = now + prefix->adv_pref_lifetime_in_secs;
2842 radv_info->initial_adverts_sent = radv_info->initial_adverts_count - 1;
2843 radv_info->next_multicast_time = vlib_time_now (vm);
2844 radv_info->last_multicast_time = vlib_time_now (vm);
2845 radv_info->last_radv_time = 0;
2851 ip6_neighbor_cmd (vlib_main_t * vm, unformat_input_t * main_input,
2852 vlib_cli_command_t * cmd)
2854 vnet_main_t *vnm = vnet_get_main ();
2855 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
2856 clib_error_t *error = 0;
2858 u8 suppress = 0, managed = 0, other = 0;
2859 u8 suppress_ll_option = 0, send_unicast = 0, cease = 0;
2860 u8 use_lifetime = 0;
2861 u32 sw_if_index, ra_lifetime = 0, ra_initial_count =
2862 0, ra_initial_interval = 0;
2863 u32 ra_max_interval = 0, ra_min_interval = 0;
2865 unformat_input_t _line_input, *line_input = &_line_input;
2866 vnet_sw_interface_t *sw_if0;
2868 int add_radv_info = 1;
2869 __attribute__ ((unused)) ip6_radv_t *radv_info = 0;
2870 ip6_address_t ip6_addr;
2874 /* Get a line of input. */
2875 if (!unformat_user (main_input, unformat_line_input, line_input))
2878 /* get basic radv info for this interface */
2879 if (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2882 if (unformat_user (line_input,
2883 unformat_vnet_sw_interface, vnm, &sw_if_index))
2886 ethernet_interface_t *eth_if0 = 0;
2888 sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index);
2889 if (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE)
2891 ethernet_get_interface (ðernet_main, sw_if0->hw_if_index);
2896 clib_error_return (0, "Interface must be of ethernet type");
2900 /* look up the radv_t information for this interface */
2901 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index,
2904 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
2908 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
2912 error = clib_error_return (0, "unknown interface %U'",
2913 format_unformat_error, line_input);
2919 error = clib_error_return (0, "invalid interface name %U'",
2920 format_unformat_error, line_input);
2925 /* get the rest of the command */
2926 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2928 if (unformat (line_input, "no"))
2930 else if (unformat (line_input, "prefix %U/%d",
2931 unformat_ip6_address, &ip6_addr, &addr_len))
2936 else if (unformat (line_input, "ra-managed-config-flag"))
2941 else if (unformat (line_input, "ra-other-config-flag"))
2946 else if (unformat (line_input, "ra-suppress") ||
2947 unformat (line_input, "ra-surpress"))
2952 else if (unformat (line_input, "ra-suppress-link-layer") ||
2953 unformat (line_input, "ra-surpress-link-layer"))
2955 suppress_ll_option = 1;
2958 else if (unformat (line_input, "ra-send-unicast"))
2963 else if (unformat (line_input, "ra-lifetime"))
2965 if (!unformat (line_input, "%d", &ra_lifetime))
2967 error = unformat_parse_error (line_input);
2973 else if (unformat (line_input, "ra-initial"))
2976 (line_input, "%d %d", &ra_initial_count, &ra_initial_interval))
2978 error = unformat_parse_error (line_input);
2983 else if (unformat (line_input, "ra-interval"))
2985 if (!unformat (line_input, "%d", &ra_max_interval))
2987 error = unformat_parse_error (line_input);
2991 if (!unformat (line_input, "%d", &ra_min_interval))
2992 ra_min_interval = 0;
2995 else if (unformat (line_input, "ra-cease"))
3002 error = unformat_parse_error (line_input);
3009 ip6_neighbor_ra_config (vm, sw_if_index,
3010 suppress, managed, other,
3011 suppress_ll_option, send_unicast, cease,
3012 use_lifetime, ra_lifetime,
3013 ra_initial_count, ra_initial_interval,
3014 ra_max_interval, ra_min_interval, is_no);
3018 u32 valid_lifetime_in_secs = 0;
3019 u32 pref_lifetime_in_secs = 0;
3020 u8 use_prefix_default_values = 0;
3021 u8 no_advertise = 0;
3023 u8 no_autoconfig = 0;
3026 /* get the rest of the command */
3027 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
3029 if (unformat (line_input, "default"))
3031 use_prefix_default_values = 1;
3034 else if (unformat (line_input, "infinite"))
3036 valid_lifetime_in_secs = ~0;
3037 pref_lifetime_in_secs = ~0;
3040 else if (unformat (line_input, "%d %d", &valid_lifetime_in_secs,
3041 &pref_lifetime_in_secs))
3048 /* get the rest of the command */
3049 while (!use_prefix_default_values &&
3050 unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
3052 if (unformat (line_input, "no-advertise"))
3054 else if (unformat (line_input, "off-link"))
3056 else if (unformat (line_input, "no-autoconfig"))
3058 else if (unformat (line_input, "no-onlink"))
3062 error = unformat_parse_error (line_input);
3067 ip6_neighbor_ra_prefix (vm, sw_if_index,
3068 &ip6_addr, addr_len,
3069 use_prefix_default_values,
3070 valid_lifetime_in_secs,
3071 pref_lifetime_in_secs,
3073 off_link, no_autoconfig, no_onlink, is_no);
3077 unformat_free (line_input);
3083 ip6_print_addrs (vlib_main_t * vm, u32 * addrs)
3085 ip_lookup_main_t *lm = &ip6_main.lookup_main;
3088 for (i = 0; i < vec_len (addrs); i++)
3090 ip_interface_address_t *a =
3091 pool_elt_at_index (lm->if_address_pool, addrs[i]);
3092 ip6_address_t *address = ip_interface_address_get_address (lm, a);
3094 vlib_cli_output (vm, "\t\t%U/%d",
3095 format_ip6_address, address, a->address_length);
3099 static clib_error_t *
3100 show_ip6_interface_cmd (vlib_main_t * vm,
3101 unformat_input_t * input, vlib_cli_command_t * cmd)
3103 vnet_main_t *vnm = vnet_get_main ();
3104 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
3105 clib_error_t *error = 0;
3110 if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
3114 /* look up the radv_t information for this interface */
3115 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index,
3118 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
3122 ip_lookup_main_t *lm = &ip6_main.lookup_main;
3123 ip6_radv_t *radv_info;
3124 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
3126 vlib_cli_output (vm, "%U is admin %s\n",
3127 format_vnet_sw_interface_name, vnm,
3128 vnet_get_sw_interface (vnm, sw_if_index),
3129 (vnet_sw_interface_is_admin_up (vnm, sw_if_index) ?
3133 u32 *link_scope = 0, *global_scope = 0;
3134 u32 *local_scope = 0, *unknown_scope = 0;
3135 ip_interface_address_t *a;
3137 vec_validate_init_empty (lm->if_address_pool_index_by_sw_if_index,
3139 ai = lm->if_address_pool_index_by_sw_if_index[sw_if_index];
3141 while (ai != (u32) ~ 0)
3143 a = pool_elt_at_index (lm->if_address_pool, ai);
3144 ip6_address_t *address =
3145 ip_interface_address_get_address (lm, a);
3147 if (ip6_address_is_link_local_unicast (address))
3148 vec_add1 (link_scope, ai);
3149 else if (ip6_address_is_global_unicast (address))
3150 vec_add1 (global_scope, ai);
3151 else if (ip6_address_is_local_unicast (address))
3152 vec_add1 (local_scope, ai);
3154 vec_add1 (unknown_scope, ai);
3156 ai = a->next_this_sw_interface;
3159 if (vec_len (link_scope))
3161 vlib_cli_output (vm, "\tLink-local address(es):\n");
3162 ip6_print_addrs (vm, link_scope);
3163 vec_free (link_scope);
3166 if (vec_len (local_scope))
3168 vlib_cli_output (vm, "\tLocal unicast address(es):\n");
3169 ip6_print_addrs (vm, local_scope);
3170 vec_free (local_scope);
3173 if (vec_len (global_scope))
3175 vlib_cli_output (vm, "\tGlobal unicast address(es):\n");
3176 ip6_print_addrs (vm, global_scope);
3177 vec_free (global_scope);
3180 if (vec_len (unknown_scope))
3182 vlib_cli_output (vm, "\tOther-scope address(es):\n");
3183 ip6_print_addrs (vm, unknown_scope);
3184 vec_free (unknown_scope);
3187 vlib_cli_output (vm, "\tJoined group address(es):\n");
3188 ip6_mldp_group_t *m;
3190 pool_foreach (m, radv_info->mldp_group_pool,
3192 vlib_cli_output (vm, "\t\t%U\n", format_ip6_address,
3197 vlib_cli_output (vm, "\tAdvertised Prefixes:\n");
3198 ip6_radv_prefix_t *p;
3200 pool_foreach (p, radv_info->adv_prefixes_pool,
3202 vlib_cli_output (vm, "\t\tprefix %U, length %d\n",
3203 format_ip6_address, &p->prefix, p->prefix_len);
3207 vlib_cli_output (vm, "\tMTU is %d\n", radv_info->adv_link_mtu);
3208 vlib_cli_output (vm, "\tICMP error messages are unlimited\n");
3209 vlib_cli_output (vm, "\tICMP redirects are disabled\n");
3210 vlib_cli_output (vm, "\tICMP unreachables are not sent\n");
3211 vlib_cli_output (vm, "\tND DAD is disabled\n");
3212 //vlib_cli_output (vm, "\tND reachable time is %d milliseconds\n",);
3213 vlib_cli_output (vm, "\tND advertised reachable time is %d\n",
3214 radv_info->adv_neighbor_reachable_time_in_msec);
3215 vlib_cli_output (vm,
3216 "\tND advertised retransmit interval is %d (msec)\n",
3218 adv_time_in_msec_between_retransmitted_neighbor_solicitations);
3220 u32 ra_interval = radv_info->max_radv_interval;
3221 u32 ra_interval_min = radv_info->min_radv_interval;
3222 vlib_cli_output (vm,
3223 "\tND router advertisements are sent every %d seconds (min interval is %d)\n",
3224 ra_interval, ra_interval_min);
3225 vlib_cli_output (vm,
3226 "\tND router advertisements live for %d seconds\n",
3227 radv_info->adv_router_lifetime_in_sec);
3228 vlib_cli_output (vm,
3229 "\tHosts %s stateless autoconfig for addresses\n",
3230 (radv_info->adv_managed_flag) ? "use" :
3232 vlib_cli_output (vm, "\tND router advertisements sent %d\n",
3233 radv_info->n_advertisements_sent);
3234 vlib_cli_output (vm, "\tND router solicitations received %d\n",
3235 radv_info->n_solicitations_rcvd);
3236 vlib_cli_output (vm, "\tND router solicitations dropped %d\n",
3237 radv_info->n_solicitations_dropped);
3241 error = clib_error_return (0, "IPv6 not enabled on interface",
3242 format_unformat_error, input);
3250 * This command is used to display various IPv6 attributes on a given
3254 * Example of how to display IPv6 settings:
3255 * @cliexstart{show ip6 interface GigabitEthernet2/0/0}
3256 * GigabitEthernet2/0/0 is admin up
3257 * Link-local address(es):
3259 * Joined group address(es):
3264 * Advertised Prefixes:
3265 * prefix fe80::fe:28ff:fe9c:75b3, length 64
3267 * ICMP error messages are unlimited
3268 * ICMP redirects are disabled
3269 * ICMP unreachables are not sent
3270 * ND DAD is disabled
3271 * ND advertised reachable time is 0
3272 * ND advertised retransmit interval is 0 (msec)
3273 * ND router advertisements are sent every 200 seconds (min interval is 150)
3274 * ND router advertisements live for 600 seconds
3275 * Hosts use stateless autoconfig for addresses
3276 * ND router advertisements sent 19336
3277 * ND router solicitations received 0
3278 * ND router solicitations dropped 0
3280 * Example of output if IPv6 is not enabled on the interface:
3281 * @cliexstart{show ip6 interface GigabitEthernet2/0/0}
3282 * show ip6 interface: IPv6 not enabled on interface
3286 VLIB_CLI_COMMAND (show_ip6_interface_command, static) =
3288 .path = "show ip6 interface",
3289 .function = show_ip6_interface_cmd,
3290 .short_help = "show ip6 interface <interface>",
3295 disable_ip6_interface (vlib_main_t * vm, u32 sw_if_index)
3297 clib_error_t *error = 0;
3298 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
3301 /* look up the radv_t information for this interface */
3302 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index,
3304 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
3306 /* if not created - do nothing */
3309 vnet_main_t *vnm = vnet_get_main ();
3310 ip6_radv_t *radv_info;
3312 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
3314 /* check radv_info ref count for other ip6 addresses on this interface */
3315 /* This implicitly excludes the link local address */
3316 if (radv_info->ref_count == 0)
3318 /* essentially "disables" ipv6 on this interface */
3319 error = ip6_add_del_interface_address (vm, sw_if_index,
3321 link_local_address, 128,
3324 ip6_neighbor_sw_interface_add_del (vnm, sw_if_index,
3326 ip6_mfib_interface_enable_disable (sw_if_index, 0);
3333 ip6_interface_enabled (vlib_main_t * vm, u32 sw_if_index)
3335 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
3338 /* look up the radv_t information for this interface */
3339 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index,
3342 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
3348 enable_ip6_interface (vlib_main_t * vm, u32 sw_if_index)
3350 clib_error_t *error = 0;
3351 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
3355 /* look up the radv_t information for this interface */
3356 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index,
3359 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
3361 /* if not created yet */
3364 vnet_main_t *vnm = vnet_get_main ();
3365 vnet_sw_interface_t *sw_if0;
3367 sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index);
3368 if (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE)
3370 ethernet_interface_t *eth_if0;
3373 ethernet_get_interface (ðernet_main, sw_if0->hw_if_index);
3376 /* create radv_info. for this interface. This holds all the info needed for router adverts */
3378 ip6_neighbor_sw_interface_add_del (vnm, sw_if_index, is_add);
3382 ip6_radv_t *radv_info;
3383 ip6_address_t link_local_address;
3385 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
3387 ip6_link_local_address_from_ethernet_mac_address
3388 (&link_local_address, eth_if0->address);
3390 sw_if0 = vnet_get_sw_interface (vnm, sw_if_index);
3391 if (sw_if0->type == VNET_SW_INTERFACE_TYPE_SUB)
3393 /* make up an interface id */
3397 link_local_address.as_u64[0] = radv_info->randomizer;
3400 md5_add (&m, &link_local_address, 16);
3401 md5_finish (&m, digest);
3403 clib_memcpy (&link_local_address, digest, 16);
3405 radv_info->randomizer = link_local_address.as_u64[0];
3407 link_local_address.as_u64[0] =
3408 clib_host_to_net_u64 (0xFE80000000000000ULL);
3410 link_local_address.as_u8[8] &= 0xfd;
3413 ip6_mfib_interface_enable_disable (sw_if_index, 1);
3415 /* essentially "enables" ipv6 on this interface */
3416 error = ip6_add_del_interface_address (vm, sw_if_index,
3417 &link_local_address,
3419 /* address width */ ,
3423 ip6_neighbor_sw_interface_add_del (vnm, sw_if_index,
3427 radv_info->link_local_address = link_local_address;
3436 static clib_error_t *
3437 enable_ip6_interface_cmd (vlib_main_t * vm,
3438 unformat_input_t * input, vlib_cli_command_t * cmd)
3440 vnet_main_t *vnm = vnet_get_main ();
3441 clib_error_t *error = 0;
3446 if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
3448 enable_ip6_interface (vm, sw_if_index);
3452 error = clib_error_return (0, "unknown interface\n'",
3453 format_unformat_error, input);
3460 * This command is used to enable IPv6 on a given interface.
3463 * Example of how enable IPv6 on a given interface:
3464 * @cliexcmd{enable ip6 interface GigabitEthernet2/0/0}
3467 VLIB_CLI_COMMAND (enable_ip6_interface_command, static) =
3469 .path = "enable ip6 interface",
3470 .function = enable_ip6_interface_cmd,
3471 .short_help = "enable ip6 interface <interface>",
3475 static clib_error_t *
3476 disable_ip6_interface_cmd (vlib_main_t * vm,
3477 unformat_input_t * input, vlib_cli_command_t * cmd)
3479 vnet_main_t *vnm = vnet_get_main ();
3480 clib_error_t *error = 0;
3485 if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
3487 error = disable_ip6_interface (vm, sw_if_index);
3491 error = clib_error_return (0, "unknown interface\n'",
3492 format_unformat_error, input);
3499 * This command is used to disable IPv6 on a given interface.
3502 * Example of how disable IPv6 on a given interface:
3503 * @cliexcmd{disable ip6 interface GigabitEthernet2/0/0}
3506 VLIB_CLI_COMMAND (disable_ip6_interface_command, static) =
3508 .path = "disable ip6 interface",
3509 .function = disable_ip6_interface_cmd,
3510 .short_help = "disable ip6 interface <interface>",
3515 * This command is used to configure the neighbor discovery
3516 * parameters on a given interface. Use the '<em>show ip6 interface</em>'
3517 * command to display some of the current neighbor discovery parameters
3518 * on a given interface. This command has three formats:
3521 * <b>Format 1 - Router Advertisement Options:</b> (Only one can be entered in a single command)
3523 * '<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>'
3527 * <em>[no] ra-managed-config-flag</em> - Advertises in ICMPv6
3528 * router-advertisement messages to use stateful address
3529 * auto-configuration to obtain address information (sets the M-bit).
3530 * Default is the M-bit is not set and the '<em>no</em>' option
3531 * returns it to this default state.
3533 * <em>[no] ra-other-config-flag</em> - Indicates in ICMPv6
3534 * router-advertisement messages that hosts use stateful auto
3535 * configuration to obtain nonaddress related information (sets
3536 * the O-bit). Default is the O-bit is not set and the '<em>no</em>'
3537 * option returns it to this default state.
3539 * <em>[no] ra-suppress</em> - Disables sending ICMPv6 router-advertisement
3540 * messages. The '<em>no</em>' option implies to enable sending ICMPv6
3541 * router-advertisement messages.
3543 * <em>[no] ra-suppress-link-layer</em> - Indicates not to include the
3544 * optional source link-layer address in the ICMPv6 router-advertisement
3545 * messages. Default is to include the optional source link-layer address
3546 * and the '<em>no</em>' option returns it to this default state.
3548 * <em>[no] ra-send-unicast</em> - Use the source address of the
3549 * router-solicitation message if availiable. The default is to use
3550 * multicast address of all nodes, and the '<em>no</em>' option returns
3551 * it to this default state.
3553 * <em>[no] ra-lifetime <lifetime></em> - Advertises the lifetime of a
3554 * default router in ICMPv6 router-advertisement messages. The range is
3555 * from 0 to 9000 seconds. '<em><lifetime></em>' must be greater than
3556 * '<em><max-interval></em>'. The default value is 600 seconds and the
3557 * '<em>no</em>' option returns it to this default value.
3559 * <em>[no] ra-initial <cnt> <interval></em> - Number of initial ICMPv6
3560 * router-advertisement messages sent and the interval between each
3561 * message. Range for count is 1 - 3 and default is 3. Range for interval
3562 * is 1 to 16 seconds, and default is 16 seconds. The '<em>no</em>' option
3563 * returns both to their default value.
3565 * <em>[no] ra-interval <max-interval> [<min-interval>]</em> - Configures the
3566 * interval between sending ICMPv6 router-advertisement messages. The
3567 * range for max-interval is from 4 to 200 seconds. min-interval can not
3568 * be more than 75% of max-interval. If not set, min-interval will be
3569 * set to 75% of max-interval. The range for min-interval is from 3 to
3570 * 150 seconds. The '<em>no</em>' option returns both to their default
3573 * <em>[no] ra-cease</em> - Cease sending ICMPv6 router-advertisement messages.
3574 * The '<em>no</em>' options implies to start (or restart) sending
3575 * ICMPv6 router-advertisement messages.
3578 * <b>Format 2 - Prefix Options:</b>
3580 * '<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>'
3584 * <em>no</em> - All additional flags are ignored and the prefix is deleted.
3586 * <em><valid-lifetime> <pref-lifetime></em> - '<em><valid-lifetime></em>' is the
3587 * length of time in seconds during what the prefix is valid for the purpose of
3588 * on-link determination. Range is 7203 to 2592000 seconds and default is 2592000
3589 * seconds (30 days). '<em><pref-lifetime></em>' is the prefered-lifetime and is the
3590 * length of time in seconds during what addresses generated from the prefix remain
3591 * preferred. Range is 0 to 604800 seconds and default is 604800 seconds (7 days).
3593 * <em>infinite</em> - Both '<em><valid-lifetime></em>' and '<em><<pref-lifetime></em>'
3594 * are inifinte, no timeout.
3596 * <em>no-advertise</em> - Do not send full router address in prefix
3597 * advertisement. Default is to advertise (i.e. - This flag is off by default).
3599 * <em>off-link</em> - Prefix is off-link, clear L-bit in packet. Default is on-link
3600 * (i.e. - This flag is off and L-bit in packet is set by default and this prefix can
3601 * be used for on-link determination). '<em>no-onlink</em>' also controls the L-bit.
3603 * <em>no-autoconfig</em> - Do not use prefix for autoconfiguration, clear A-bit in packet.
3604 * Default is autoconfig (i.e. - This flag is off and A-bit in packet is set by default.
3606 * <em>no-onlink</em> - Do not use prefix for onlink determination, clear L-bit in packet.
3607 * Default is on-link (i.e. - This flag is off and L-bit in packet is set by default and
3608 * this prefix can be used for on-link determination). '<em>off-link</em>' also controls
3612 * <b>Format 3: - Default of Prefix:</b>
3614 * '<em><b>ip6 nd <interface> [no] prefix <ip6-address>/<width> default</b></em>'
3616 * When a new prefix is added (or existing one is being overwritten) <em>default</em>
3617 * uses default values for the prefix. If <em>no</em> is used, the <em>default</em>
3618 * is ignored and the prefix is deleted.
3622 * Example of how set a router advertisement option:
3623 * @cliexcmd{ip6 nd GigabitEthernet2/0/0 ra-interval 100 20}
3624 * Example of how to add a prefix:
3625 * @cliexcmd{ip6 nd GigabitEthernet2/0/0 prefix fe80::fe:28ff:fe9c:75b3/64 infinite no-advertise}
3626 * Example of how to delete a prefix:
3627 * @cliexcmd{ip6 nd GigabitEthernet2/0/0 no prefix fe80::fe:28ff:fe9c:75b3/64}
3630 VLIB_CLI_COMMAND (ip6_nd_command, static) =
3633 .short_help = "ip6 nd <interface> ...",
3634 .function = ip6_neighbor_cmd,
3639 set_ip6_link_local_address (vlib_main_t * vm,
3640 u32 sw_if_index, ip6_address_t * address)
3642 clib_error_t *error = 0;
3643 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
3645 ip6_radv_t *radv_info;
3646 vnet_main_t *vnm = vnet_get_main ();
3648 if (!ip6_address_is_link_local_unicast (address))
3650 vnm->api_errno = VNET_API_ERROR_ADDRESS_NOT_LINK_LOCAL;
3651 return (error = clib_error_return (0, "address not link-local",
3652 format_unformat_error));
3655 /* call enable ipv6 */
3656 enable_ip6_interface (vm, sw_if_index);
3658 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
3662 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
3664 /* save if link local address (overwrite default) */
3666 /* delete the old one */
3667 error = ip6_add_del_interface_address (vm, sw_if_index,
3668 &radv_info->link_local_address,
3669 128, 1 /* is_del */ );
3673 /* add the new one */
3674 error = ip6_add_del_interface_address (vm, sw_if_index,
3680 radv_info->link_local_address = *address;
3686 vnm->api_errno = VNET_API_ERROR_IP6_NOT_ENABLED;
3687 error = clib_error_return (0, "ip6 not enabled for interface",
3688 format_unformat_error);
3694 set_ip6_link_local_address_cmd (vlib_main_t * vm,
3695 unformat_input_t * input,
3696 vlib_cli_command_t * cmd)
3698 vnet_main_t *vnm = vnet_get_main ();
3699 clib_error_t *error = 0;
3701 ip6_address_t ip6_addr;
3703 if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
3705 /* get the rest of the command */
3706 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
3708 if (unformat (input, "%U", unformat_ip6_address, &ip6_addr))
3711 return (unformat_parse_error (input));
3714 error = set_ip6_link_local_address (vm, sw_if_index, &ip6_addr);
3719 * This command is used to assign an IPv6 Link-local address to an
3720 * interface. This command will enable IPv6 on an interface if it
3721 * is not already enabled. Use the '<em>show ip6 interface</em>' command
3722 * to display the assigned Link-local address.
3725 * Example of how to assign an IPv6 Link-local address to an interface:
3726 * @cliexcmd{set ip6 link-local address GigabitEthernet2/0/0 FE80::AB8}
3729 VLIB_CLI_COMMAND (set_ip6_link_local_address_command, static) =
3731 .path = "set ip6 link-local address",
3732 .short_help = "set ip6 link-local address <interface> <ip6-address>",
3733 .function = set_ip6_link_local_address_cmd,
3738 * @brief callback when an interface address is added or deleted
3741 ip6_neighbor_add_del_interface_address (ip6_main_t * im,
3744 ip6_address_t * address,
3746 u32 if_address_index, u32 is_delete)
3748 vnet_main_t *vnm = vnet_get_main ();
3749 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
3751 vlib_main_t *vm = vnm->vlib_main;
3752 ip6_radv_t *radv_info;
3755 /* create solicited node multicast address for this interface adddress */
3756 ip6_set_solicited_node_multicast_address (&a, 0);
3758 a.as_u8[0xd] = address->as_u8[0xd];
3759 a.as_u8[0xe] = address->as_u8[0xe];
3760 a.as_u8[0xf] = address->as_u8[0xf];
3764 /* try to create radv_info - does nothing if ipv6 already enabled */
3765 enable_ip6_interface (vm, sw_if_index);
3767 /* look up the radv_t information for this interface */
3768 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index,
3770 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
3774 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
3777 if (!ip6_address_is_link_local_unicast (address))
3778 radv_info->ref_count++;
3780 ip6_neighbor_add_mld_prefix (radv_info, &a);
3787 /* look up the radv_t information for this interface */
3788 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index,
3790 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
3795 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
3797 ip6_neighbor_del_mld_prefix (radv_info, &a);
3799 /* if interface up send MLDP "report" */
3800 radv_info->all_routers_mcast = 0;
3803 if (!ip6_address_is_link_local_unicast (address))
3804 radv_info->ref_count--;
3806 /* Ensure that IPv6 is disabled, and LL removed after ref_count reaches 0 */
3807 disable_ip6_interface (vm, sw_if_index);
3812 ip6_set_neighbor_limit (u32 neighbor_limit)
3814 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
3816 nm->limit_neighbor_cache_size = neighbor_limit;
3820 static clib_error_t *
3821 ip6_neighbor_init (vlib_main_t * vm)
3823 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
3824 ip6_main_t *im = &ip6_main;
3826 mhash_init (&nm->neighbor_index_by_key,
3827 /* value size */ sizeof (uword),
3828 /* key size */ sizeof (ip6_neighbor_key_t));
3830 icmp6_register_type (vm, ICMP6_neighbor_solicitation,
3831 ip6_icmp_neighbor_solicitation_node.index);
3832 icmp6_register_type (vm, ICMP6_neighbor_advertisement,
3833 ip6_icmp_neighbor_advertisement_node.index);
3834 icmp6_register_type (vm, ICMP6_router_solicitation,
3835 ip6_icmp_router_solicitation_node.index);
3836 icmp6_register_type (vm, ICMP6_router_advertisement,
3837 ip6_icmp_router_advertisement_node.index);
3839 /* handler node for ip6 neighbor discovery events and timers */
3840 vlib_register_node (vm, &ip6_icmp_neighbor_discovery_event_node);
3842 /* add call backs */
3843 ip6_add_del_interface_address_callback_t cb;
3844 memset (&cb, 0x0, sizeof (ip6_add_del_interface_address_callback_t));
3846 /* when an interface address changes... */
3847 cb.function = ip6_neighbor_add_del_interface_address;
3848 cb.function_opaque = 0;
3849 vec_add1 (im->add_del_interface_address_callbacks, cb);
3851 mhash_init (&nm->pending_resolutions_by_address,
3852 /* value size */ sizeof (uword),
3853 /* key size */ sizeof (ip6_address_t));
3855 mhash_init (&nm->mac_changes_by_address,
3856 /* value size */ sizeof (uword),
3857 /* key size */ sizeof (ip6_address_t));
3859 /* default, configurable */
3860 nm->limit_neighbor_cache_size = 50000;
3863 /* $$$$ Hack fix for today */
3864 vec_validate_init_empty
3865 (im->discover_neighbor_next_index_by_hw_if_index, 32, 0 /* drop */ );
3871 VLIB_INIT_FUNCTION (ip6_neighbor_init);
3875 vnet_register_ip6_neighbor_resolution_event (vnet_main_t * vnm,
3878 uword type_opaque, uword data)
3880 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
3881 ip6_address_t *address = address_arg;
3883 pending_resolution_t *pr;
3885 pool_get (nm->pending_resolutions, pr);
3887 pr->next_index = ~0;
3888 pr->node_index = node_index;
3889 pr->type_opaque = type_opaque;
3892 p = mhash_get (&nm->pending_resolutions_by_address, address);
3895 /* Insert new resolution at the head of the list */
3896 pr->next_index = p[0];
3897 mhash_unset (&nm->pending_resolutions_by_address, address, 0);
3900 mhash_set (&nm->pending_resolutions_by_address, address,
3901 pr - nm->pending_resolutions, 0 /* old value */ );
3905 vnet_add_del_ip6_nd_change_event (vnet_main_t * vnm,
3906 void *data_callback,
3910 uword type_opaque, uword data, int is_add)
3912 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
3913 ip6_address_t *address = address_arg;
3915 /* Try to find an existing entry */
3916 u32 *first = (u32 *) mhash_get (&nm->mac_changes_by_address, address);
3918 pending_resolution_t *mc;
3919 while (p && *p != ~0)
3921 mc = pool_elt_at_index (nm->mac_changes, *p);
3922 if (mc->node_index == node_index && mc->type_opaque == type_opaque
3925 p = &mc->next_index;
3928 int found = p && *p != ~0;
3932 return VNET_API_ERROR_ENTRY_ALREADY_EXISTS;
3934 pool_get (nm->mac_changes, mc);
3935 *mc = (pending_resolution_t)
3937 .next_index = ~0,.node_index = node_index,.type_opaque =
3938 type_opaque,.data = data,.data_callback = data_callback,.pid =
3941 /* Insert new resolution at the end of the list */
3942 u32 new_idx = mc - nm->mac_changes;
3946 mhash_set (&nm->mac_changes_by_address, address, new_idx, 0);
3951 return VNET_API_ERROR_NO_SUCH_ENTRY;
3953 /* Clients may need to clean up pool entries, too */
3954 void (*fp) (u32, u8 *) = data_callback;
3956 (*fp) (mc->data, 0 /* no new mac addrs */ );
3958 /* Remove the entry from the list and delete the entry */
3959 *p = mc->next_index;
3960 pool_put (nm->mac_changes, mc);
3962 /* Remove from hash if we deleted the last entry */
3963 if (*p == ~0 && p == first)
3964 mhash_unset (&nm->mac_changes_by_address, address, 0);
3970 vnet_ip6_nd_term (vlib_main_t * vm,
3971 vlib_node_runtime_t * node,
3973 ethernet_header_t * eth,
3974 ip6_header_t * ip, u32 sw_if_index, u16 bd_index)
3976 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
3977 icmp6_neighbor_solicitation_or_advertisement_header_t *ndh;
3978 pending_resolution_t *mc;
3980 ndh = ip6_next_header (ip);
3981 if (ndh->icmp.type != ICMP6_neighbor_solicitation &&
3982 ndh->icmp.type != ICMP6_neighbor_advertisement)
3985 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) &&
3986 (p0->flags & VLIB_BUFFER_IS_TRACED)))
3988 u8 *t0 = vlib_add_trace (vm, node, p0,
3989 sizeof (icmp6_input_trace_t));
3990 clib_memcpy (t0, ip, sizeof (icmp6_input_trace_t));
3993 /* Check if anyone want ND events for L2 BDs */
3994 uword *p = mhash_get (&nm->mac_changes_by_address, &ip6a_zero);
3995 if (p && !ip6_address_is_link_local_unicast (&ip->src_address))
3997 u32 next_index = p[0];
3998 while (next_index != (u32) ~ 0)
4000 int (*fp) (u32, u8 *, u32, ip6_address_t *);
4002 mc = pool_elt_at_index (nm->mac_changes, next_index);
4003 fp = mc->data_callback;
4004 /* Call the callback, return 1 to suppress dup events */
4006 rv = (*fp) (mc->data,
4007 eth->src_address, sw_if_index, &ip->src_address);
4008 /* Signal the resolver process */
4010 vlib_process_signal_event (vm, mc->node_index,
4011 mc->type_opaque, mc->data);
4012 next_index = mc->next_index;
4016 /* Check if MAC entry exsist for solicited target IP */
4017 if (ndh->icmp.type == ICMP6_neighbor_solicitation)
4019 icmp6_neighbor_discovery_ethernet_link_layer_address_option_t *opt;
4020 l2_bridge_domain_t *bd_config;
4023 opt = (void *) (ndh + 1);
4024 if ((opt->header.type !=
4025 ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address) ||
4026 (opt->header.n_data_u64s != 1))
4027 return 0; /* source link layer address option not present */
4029 bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index);
4031 (u8 *) hash_get_mem (bd_config->mac_by_ip6, &ndh->target_address);
4033 { /* found ip-mac entry, generate eighbor advertisement response */
4035 vlib_node_runtime_t *error_node =
4036 vlib_node_get_runtime (vm, ip6_icmp_input_node.index);
4037 ip->dst_address = ip->src_address;
4038 ip->src_address = ndh->target_address;
4039 ip->hop_limit = 255;
4041 ICMP6_NEIGHBOR_DISCOVERY_OPTION_target_link_layer_address;
4042 clib_memcpy (opt->ethernet_address, macp, 6);
4043 ndh->icmp.type = ICMP6_neighbor_advertisement;
4044 ndh->advertisement_flags = clib_host_to_net_u32
4045 (ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_SOLICITED |
4046 ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_OVERRIDE);
4047 ndh->icmp.checksum = 0;
4048 ndh->icmp.checksum =
4049 ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip, &bogus_length);
4050 clib_memcpy (eth->dst_address, eth->src_address, 6);
4051 clib_memcpy (eth->src_address, macp, 6);
4052 vlib_error_count (vm, error_node->node_index,
4053 ICMP6_ERROR_NEIGHBOR_ADVERTISEMENTS_TX, 1);
4063 ip6_neighbor_proxy_add_del (u32 sw_if_index, ip6_address_t * addr, u8 is_del)
4067 fib_prefix_t pfx = {
4069 .fp_proto = FIB_PROTOCOL_IP6,
4074 ip46_address_t nh = {
4078 fib_index = ip6_fib_table_get_index_for_sw_if_index (sw_if_index);
4080 if (~0 == fib_index)
4081 return VNET_API_ERROR_NO_SUCH_FIB;
4085 fib_table_entry_path_remove (fib_index,
4087 FIB_SOURCE_IP6_ND_PROXY,
4091 ~0, 1, FIB_ROUTE_PATH_FLAG_NONE);
4092 /* flush the ND cache of this address if it's there */
4093 vnet_unset_ip6_ethernet_neighbor (vlib_get_main (),
4094 sw_if_index, addr, NULL, 0);
4098 fib_table_entry_path_add (fib_index,
4100 FIB_SOURCE_IP6_ND_PROXY,
4101 FIB_ENTRY_FLAG_NONE,
4105 ~0, 1, NULL, FIB_ROUTE_PATH_FLAG_NONE);
4110 static clib_error_t *
4111 set_ip6_nd_proxy_cmd (vlib_main_t * vm,
4112 unformat_input_t * input, vlib_cli_command_t * cmd)
4114 vnet_main_t *vnm = vnet_get_main ();
4115 clib_error_t *error = 0;
4120 if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
4122 /* get the rest of the command */
4123 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
4125 if (unformat (input, "%U", unformat_ip6_address, &addr))
4127 else if (unformat (input, "delete") || unformat (input, "del"))
4130 return (unformat_parse_error (input));
4134 ip6_neighbor_proxy_add_del (sw_if_index, &addr, is_del);
4140 VLIB_CLI_COMMAND (set_ip6_nd_proxy_command, static) =
4142 .path = "set ip6 nd proxy",
4143 .short_help = "set ip6 nd proxy <HOST> <INTERFACE>",
4144 .function = set_ip6_nd_proxy_cmd,
4149 ethernet_ndp_change_mac (u32 sw_if_index)
4151 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
4155 pool_foreach (n, nm->neighbor_pool,
4157 if (n->key.sw_if_index == sw_if_index)
4159 adj_nbr_walk_nh6 (sw_if_index,
4160 &n->key.ip6_address,
4161 ip6_nd_mk_complete_walk, n);
4168 * fd.io coding-style-patch-verification: ON
4171 * eval: (c-set-style "gnu")