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 si = vnet_get_sw_interface (vnm, n->key.sw_if_index);
239 s = format (s, "%=12U%=20U%=6s%=20U%=40U",
240 format_vlib_cpu_time, vm, n->cpu_time_last_updated,
241 format_ip6_address, &n->key.ip6_address,
242 flags ? (char *) flags : "",
243 format_ethernet_address, n->link_layer_address,
244 format_vnet_sw_interface_name, vnm, si);
250 static clib_error_t *
251 ip6_neighbor_sw_interface_up_down (vnet_main_t * vnm,
252 u32 sw_if_index, u32 flags)
254 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
257 if (!(flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP))
259 u32 i, *to_delete = 0;
262 pool_foreach (n, nm->neighbor_pool,
264 if (n->key.sw_if_index == sw_if_index)
265 vec_add1 (to_delete, n - nm->neighbor_pool);
269 for (i = 0; i < vec_len (to_delete); i++)
271 n = pool_elt_at_index (nm->neighbor_pool, to_delete[i]);
272 mhash_unset (&nm->neighbor_index_by_key, &n->key, 0);
273 fib_table_entry_delete_index (n->fib_entry_index, FIB_SOURCE_ADJ);
274 pool_put (nm->neighbor_pool, n);
277 vec_free (to_delete);
283 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (ip6_neighbor_sw_interface_up_down);
286 unset_random_neighbor_entry (void)
288 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
289 vnet_main_t *vnm = vnet_get_main ();
290 vlib_main_t *vm = vnm->vlib_main;
294 index = pool_next_index (nm->neighbor_pool, nm->neighbor_delete_rotor);
295 nm->neighbor_delete_rotor = index;
297 /* Try again from elt 0, could happen if an intfc goes down */
300 index = pool_next_index (nm->neighbor_pool, nm->neighbor_delete_rotor);
301 nm->neighbor_delete_rotor = index;
304 /* Nothing left in the pool */
308 e = pool_elt_at_index (nm->neighbor_pool, index);
310 vnet_unset_ip6_ethernet_neighbor (vm, e->key.sw_if_index,
312 e->link_layer_address,
320 u8 link_layer_address[6];
323 } ip6_neighbor_set_unset_rpc_args_t;
325 static void ip6_neighbor_set_unset_rpc_callback
326 (ip6_neighbor_set_unset_rpc_args_t * a);
328 static void set_unset_ip6_neighbor_rpc
331 ip6_address_t * a, u8 * link_layer_address, int is_add, int is_static)
333 ip6_neighbor_set_unset_rpc_args_t args;
334 void vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length);
336 args.sw_if_index = sw_if_index;
337 args.is_add = is_add;
338 args.is_static = is_static;
339 clib_memcpy (&args.addr, a, sizeof (*a));
340 if (NULL != link_layer_address)
341 clib_memcpy (args.link_layer_address, link_layer_address, 6);
343 vl_api_rpc_call_main_thread (ip6_neighbor_set_unset_rpc_callback,
344 (u8 *) & args, sizeof (args));
348 ip6_nbr_probe (ip_adjacency_t * adj)
350 icmp6_neighbor_solicitation_header_t *h;
351 vnet_main_t *vnm = vnet_get_main ();
352 ip6_main_t *im = &ip6_main;
353 ip_interface_address_t *ia;
354 ip6_address_t *dst, *src;
355 vnet_hw_interface_t *hi;
356 vnet_sw_interface_t *si;
362 vm = vlib_get_main ();
364 si = vnet_get_sw_interface (vnm, adj->rewrite_header.sw_if_index);
365 dst = &adj->sub_type.nbr.next_hop.ip6;
367 if (!(si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP))
371 src = ip6_interface_address_matching_destination (im, dst,
379 h = vlib_packet_template_get_packet (vm,
380 &im->discover_neighbor_packet_template,
383 hi = vnet_get_sup_hw_interface (vnm, adj->rewrite_header.sw_if_index);
385 h->ip.dst_address.as_u8[13] = dst->as_u8[13];
386 h->ip.dst_address.as_u8[14] = dst->as_u8[14];
387 h->ip.dst_address.as_u8[15] = dst->as_u8[15];
388 h->ip.src_address = src[0];
389 h->neighbor.target_address = dst[0];
391 clib_memcpy (h->link_layer_option.ethernet_address,
392 hi->hw_address, vec_len (hi->hw_address));
394 h->neighbor.icmp.checksum =
395 ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h->ip, &bogus_length);
396 ASSERT (bogus_length == 0);
398 b = vlib_get_buffer (vm, bi);
399 vnet_buffer (b)->sw_if_index[VLIB_RX] =
400 vnet_buffer (b)->sw_if_index[VLIB_TX] = adj->rewrite_header.sw_if_index;
402 /* Add encapsulation string for software interface (e.g. ethernet header). */
403 vnet_rewrite_one_header (adj[0], h, sizeof (ethernet_header_t));
404 vlib_buffer_advance (b, -adj->rewrite_header.data_bytes);
407 vlib_frame_t *f = vlib_get_frame_to_node (vm, hi->output_node_index);
408 u32 *to_next = vlib_frame_vector_args (f);
411 vlib_put_frame_to_node (vm, hi->output_node_index, f);
416 ip6_nd_mk_complete (adj_index_t ai, ip6_neighbor_t * nbr)
418 adj_nbr_update_rewrite (ai, ADJ_NBR_REWRITE_FLAG_COMPLETE,
419 ethernet_build_rewrite (vnet_get_main (),
420 nbr->key.sw_if_index,
421 adj_get_link_type (ai),
422 nbr->link_layer_address));
426 ip6_nd_mk_incomplete (adj_index_t ai)
428 ip_adjacency_t *adj = adj_get (ai);
430 adj_nbr_update_rewrite (ai,
431 ADJ_NBR_REWRITE_FLAG_INCOMPLETE,
432 ethernet_build_rewrite (vnet_get_main (),
435 adj_get_link_type (ai),
436 VNET_REWRITE_FOR_SW_INTERFACE_ADDRESS_BROADCAST));
439 #define IP6_NBR_MK_KEY(k, sw_if_index, addr) \
441 k.sw_if_index = sw_if_index; \
442 k.ip6_address = *addr; \
446 static ip6_neighbor_t *
447 ip6_nd_find (u32 sw_if_index, const ip6_address_t * addr)
449 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
450 ip6_neighbor_t *n = NULL;
451 ip6_neighbor_key_t k;
454 IP6_NBR_MK_KEY (k, sw_if_index, addr);
456 p = mhash_get (&nm->neighbor_index_by_key, &k);
459 n = pool_elt_at_index (nm->neighbor_pool, p[0]);
466 ip6_nd_mk_complete_walk (adj_index_t ai, void *ctx)
468 ip6_neighbor_t *nbr = ctx;
470 ip6_nd_mk_complete (ai, nbr);
472 return (ADJ_WALK_RC_CONTINUE);
476 ip6_nd_mk_incomplete_walk (adj_index_t ai, void *ctx)
478 ip6_nd_mk_incomplete (ai);
480 return (ADJ_WALK_RC_CONTINUE);
484 ip6_ethernet_update_adjacency (vnet_main_t * vnm, u32 sw_if_index, u32 ai)
491 nbr = ip6_nd_find (sw_if_index, &adj->sub_type.nbr.next_hop.ip6);
493 switch (adj->lookup_next_index)
495 case IP_LOOKUP_NEXT_ARP:
496 case IP_LOOKUP_NEXT_GLEAN:
499 adj_nbr_walk_nh6 (sw_if_index, &nbr->key.ip6_address,
500 ip6_nd_mk_complete_walk, nbr);
505 * no matching ND entry.
506 * construct the rewrite required to for an ND packet, and stick
507 * that in the adj's pipe to smoke.
509 adj_nbr_update_rewrite (ai,
510 ADJ_NBR_REWRITE_FLAG_INCOMPLETE,
511 ethernet_build_rewrite (vnm,
514 VNET_REWRITE_FOR_SW_INTERFACE_ADDRESS_BROADCAST));
517 * since the FIB has added this adj for a route, it makes sense it may
518 * want to forward traffic sometime soon. Let's send a speculative ND.
519 * just one. If we were to do periodically that wouldn't be bad either,
520 * but that's more code than i'm prepared to write at this time for
521 * relatively little reward.
526 case IP_LOOKUP_NEXT_MCAST:
528 * Construct a partial rewrite from the known ethernet mcast dest MAC
530 adj_mcast_update_rewrite
532 ethernet_build_rewrite (vnm,
535 ethernet_ip6_mcast_dst_addr ()));
538 * Complete the remaining fields of the adj's rewrite to direct the
539 * complete of the rewrite at switch time by copying in the IP
540 * dst address's bytes.
541 * Ofset is 12 bytes from the end of the MAC header - which is 2
542 * bytes into the desintation address. And we write 4 bytes.
544 adj->rewrite_header.dst_mcast_offset = 12;
545 adj->rewrite_header.dst_mcast_n_bytes = 4;
549 case IP_LOOKUP_NEXT_DROP:
550 case IP_LOOKUP_NEXT_PUNT:
551 case IP_LOOKUP_NEXT_LOCAL:
552 case IP_LOOKUP_NEXT_REWRITE:
553 case IP_LOOKUP_NEXT_LOAD_BALANCE:
554 case IP_LOOKUP_NEXT_MIDCHAIN:
555 case IP_LOOKUP_NEXT_ICMP_ERROR:
556 case IP_LOOKUP_N_NEXT:
563 vnet_set_ip6_ethernet_neighbor (vlib_main_t * vm,
566 u8 * link_layer_address,
567 uword n_bytes_link_layer_address,
570 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
571 ip6_neighbor_key_t k;
572 ip6_neighbor_t *n = 0;
573 int make_new_nd_cache_entry = 1;
576 pending_resolution_t *pr, *mc;
578 if (os_get_cpu_number ())
580 set_unset_ip6_neighbor_rpc (vm, sw_if_index, a, link_layer_address,
581 1 /* set new neighbor */ , is_static);
585 k.sw_if_index = sw_if_index;
586 k.ip6_address = a[0];
589 p = mhash_get (&nm->neighbor_index_by_key, &k);
592 n = pool_elt_at_index (nm->neighbor_pool, p[0]);
593 /* Refuse to over-write static neighbor entry. */
594 if (!is_static && (n->flags & IP6_NEIGHBOR_FLAG_STATIC))
596 make_new_nd_cache_entry = 0;
599 if (make_new_nd_cache_entry)
603 .fp_proto = FIB_PROTOCOL_IP6,
605 .ip6 = k.ip6_address,
611 pool_get (nm->neighbor_pool, n);
612 mhash_set (&nm->neighbor_index_by_key, &k, n - nm->neighbor_pool,
616 clib_memcpy (n->link_layer_address,
617 link_layer_address, n_bytes_link_layer_address);
620 * create the adj-fib. the entry in the FIB table for and to the peer.
622 fib_index = ip6_main.fib_index_by_sw_if_index[n->key.sw_if_index];
623 n->fib_entry_index = fib_table_entry_update_one_path (fib_index, &pfx, FIB_SOURCE_ADJ, FIB_ENTRY_FLAG_NONE, FIB_PROTOCOL_IP6, &pfx.fp_addr, n->key.sw_if_index, ~0, 1, NULL, // no label stack
624 FIB_ROUTE_PATH_FLAG_NONE);
629 * prevent a DoS attack from the data-plane that
630 * spams us with no-op updates to the MAC address
632 if (0 == memcmp (n->link_layer_address,
633 link_layer_address, n_bytes_link_layer_address))
636 clib_memcpy (n->link_layer_address,
637 link_layer_address, n_bytes_link_layer_address);
640 /* Update time stamp and flags. */
641 n->cpu_time_last_updated = clib_cpu_time_now ();
643 n->flags |= IP6_NEIGHBOR_FLAG_STATIC;
645 n->flags |= IP6_NEIGHBOR_FLAG_DYNAMIC;
647 adj_nbr_walk_nh6 (sw_if_index,
648 &n->key.ip6_address, ip6_nd_mk_complete_walk, n);
650 /* Customer(s) waiting for this address to be resolved? */
651 p = mhash_get (&nm->pending_resolutions_by_address, a);
656 while (next_index != (u32) ~ 0)
658 pr = pool_elt_at_index (nm->pending_resolutions, next_index);
659 vlib_process_signal_event (vm, pr->node_index,
660 pr->type_opaque, pr->data);
661 next_index = pr->next_index;
662 pool_put (nm->pending_resolutions, pr);
665 mhash_unset (&nm->pending_resolutions_by_address, a, 0);
668 /* Customer(s) requesting ND event for this address? */
669 p = mhash_get (&nm->mac_changes_by_address, a);
674 while (next_index != (u32) ~ 0)
676 int (*fp) (u32, u8 *, u32, ip6_address_t *);
678 mc = pool_elt_at_index (nm->mac_changes, next_index);
679 fp = mc->data_callback;
681 /* Call the user's data callback, return 1 to suppress dup events */
684 (*fp) (mc->data, link_layer_address, sw_if_index, &ip6a_zero);
686 * Signal the resolver process, as long as the user
687 * says they want to be notified
690 vlib_process_signal_event (vm, mc->node_index,
691 mc->type_opaque, mc->data);
692 next_index = mc->next_index;
700 vnet_unset_ip6_ethernet_neighbor (vlib_main_t * vm,
703 u8 * link_layer_address,
704 uword n_bytes_link_layer_address)
706 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
707 ip6_neighbor_key_t k;
712 if (os_get_cpu_number ())
714 set_unset_ip6_neighbor_rpc (vm, sw_if_index, a, link_layer_address,
719 k.sw_if_index = sw_if_index;
720 k.ip6_address = a[0];
723 p = mhash_get (&nm->neighbor_index_by_key, &k);
730 n = pool_elt_at_index (nm->neighbor_pool, p[0]);
731 mhash_unset (&nm->neighbor_index_by_key, &n->key, 0);
733 adj_nbr_walk_nh6 (sw_if_index,
734 &n->key.ip6_address, ip6_nd_mk_incomplete_walk, NULL);
736 fib_table_entry_delete_index (n->fib_entry_index, FIB_SOURCE_ADJ);
737 pool_put (nm->neighbor_pool, n);
743 static void ip6_neighbor_set_unset_rpc_callback
744 (ip6_neighbor_set_unset_rpc_args_t * a)
746 vlib_main_t *vm = vlib_get_main ();
748 vnet_set_ip6_ethernet_neighbor (vm, a->sw_if_index, &a->addr,
749 a->link_layer_address, 6, a->is_static);
751 vnet_unset_ip6_ethernet_neighbor (vm, a->sw_if_index, &a->addr,
752 a->link_layer_address, 6);
756 ip6_neighbor_sort (void *a1, void *a2)
758 vnet_main_t *vnm = vnet_get_main ();
759 ip6_neighbor_t *n1 = a1, *n2 = a2;
761 cmp = vnet_sw_interface_compare (vnm, n1->key.sw_if_index,
762 n2->key.sw_if_index);
764 cmp = ip6_address_compare (&n1->key.ip6_address, &n2->key.ip6_address);
769 ip6_neighbors_entries (u32 sw_if_index)
771 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
772 ip6_neighbor_t *n, *ns = 0;
775 pool_foreach (n, nm->neighbor_pool,
777 if (sw_if_index != ~0 && n->key.sw_if_index != sw_if_index)
784 vec_sort_with_function (ns, ip6_neighbor_sort);
788 static clib_error_t *
789 show_ip6_neighbors (vlib_main_t * vm,
790 unformat_input_t * input, vlib_cli_command_t * cmd)
792 vnet_main_t *vnm = vnet_get_main ();
793 ip6_neighbor_t *n, *ns;
794 clib_error_t *error = 0;
797 /* Filter entries by interface if given. */
799 (void) unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index);
801 ns = ip6_neighbors_entries (sw_if_index);
804 vlib_cli_output (vm, "%U", format_ip6_neighbor_ip6_entry, vm, 0);
807 vlib_cli_output (vm, "%U", format_ip6_neighbor_ip6_entry, vm, n);
816 * This command is used to display the adjacent IPv6 hosts found via
817 * neighbor discovery. Optionally, limit the output to the specified
821 * Example of how to display the IPv6 neighbor adjacency table:
822 * @cliexstart{show ip6 neighbors}
823 * Time Address Flags Link layer Interface
824 * 34.0910 ::a:1:1:0:7 02:fe:6a:07:39:6f GigabitEthernet2/0/0
825 * 173.2916 ::b:5:1:c:2 02:fe:50:62:3a:94 GigabitEthernet2/0/0
826 * 886.6654 ::1:1:c:0:9 S 02:fe:e4:45:27:5b GigabitEthernet3/0/0
828 * Example of how to display the IPv6 neighbor adjacency table for given interface:
829 * @cliexstart{show ip6 neighbors GigabitEthernet2/0/0}
830 * Time Address Flags Link layer Interface
831 * 34.0910 ::a:1:1:0:7 02:fe:6a:07:39:6f GigabitEthernet2/0/0
832 * 173.2916 ::b:5:1:c:2 02:fe:50:62:3a:94 GigabitEthernet2/0/0
836 VLIB_CLI_COMMAND (show_ip6_neighbors_command, static) = {
837 .path = "show ip6 neighbors",
838 .function = show_ip6_neighbors,
839 .short_help = "show ip6 neighbors [<interface>]",
843 static clib_error_t *
844 set_ip6_neighbor (vlib_main_t * vm,
845 unformat_input_t * input, vlib_cli_command_t * cmd)
847 vnet_main_t *vnm = vnet_get_main ();
855 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
857 /* intfc, ip6-address, mac-address */
858 if (unformat (input, "%U %U %U",
859 unformat_vnet_sw_interface, vnm, &sw_if_index,
860 unformat_ip6_address, &addr,
861 unformat_ethernet_address, mac_address))
864 else if (unformat (input, "delete") || unformat (input, "del"))
866 else if (unformat (input, "static"))
873 return clib_error_return (0, "Missing interface, ip6 or hw address");
876 vnet_set_ip6_ethernet_neighbor (vm, sw_if_index, &addr,
877 mac_address, sizeof (mac_address),
880 vnet_unset_ip6_ethernet_neighbor (vm, sw_if_index, &addr,
881 mac_address, sizeof (mac_address));
886 * This command is used to manually add an entry to the IPv6 neighbor
887 * adjacency table. Optionally, the entry can be added as static. It is
888 * also used to remove an entry from the table. Use the '<em>show ip6
889 * neighbors</em>' command to display all learned and manually entered entries.
892 * Example of how to add a static entry to the IPv6 neighbor adjacency table:
893 * @cliexcmd{set ip6 neighbor GigabitEthernet2/0/0 ::1:1:c:0:9 02:fe:e4:45:27:5b static}
894 * Example of how to delete an entry from the IPv6 neighbor adjacency table:
895 * @cliexcmd{set ip6 neighbor del GigabitEthernet2/0/0 ::1:1:c:0:9 02:fe:e4:45:27:5b}
898 VLIB_CLI_COMMAND (set_ip6_neighbor_command, static) =
900 .path = "set ip6 neighbor",
901 .function = set_ip6_neighbor,
902 .short_help = "set ip6 neighbor [del] <interface> <ip6-address> <mac-address> [static]",
908 ICMP6_NEIGHBOR_SOLICITATION_NEXT_DROP,
909 ICMP6_NEIGHBOR_SOLICITATION_NEXT_REPLY,
910 ICMP6_NEIGHBOR_SOLICITATION_N_NEXT,
911 } icmp6_neighbor_solicitation_or_advertisement_next_t;
913 static_always_inline uword
914 icmp6_neighbor_solicitation_or_advertisement (vlib_main_t * vm,
915 vlib_node_runtime_t * node,
916 vlib_frame_t * frame,
917 uword is_solicitation)
919 vnet_main_t *vnm = vnet_get_main ();
920 ip6_main_t *im = &ip6_main;
921 uword n_packets = frame->n_vectors;
923 u32 n_left_from, n_left_to_next, next_index, n_advertisements_sent;
924 icmp6_neighbor_discovery_option_type_t option_type;
925 vlib_node_runtime_t *error_node =
926 vlib_node_get_runtime (vm, ip6_icmp_input_node.index);
929 from = vlib_frame_vector_args (frame);
930 n_left_from = n_packets;
931 next_index = node->cached_next_index;
933 if (node->flags & VLIB_NODE_FLAG_TRACE)
934 vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors,
936 sizeof (icmp6_input_trace_t));
940 ? ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address
941 : ICMP6_NEIGHBOR_DISCOVERY_OPTION_target_link_layer_address);
942 n_advertisements_sent = 0;
944 while (n_left_from > 0)
946 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
948 while (n_left_from > 0 && n_left_to_next > 0)
952 icmp6_neighbor_solicitation_or_advertisement_header_t *h0;
953 icmp6_neighbor_discovery_ethernet_link_layer_address_option_t *o0;
954 u32 bi0, options_len0, sw_if_index0, next0, error0;
955 u32 ip6_sadd_link_local, ip6_sadd_unspecified;
959 bi0 = to_next[0] = from[0];
966 p0 = vlib_get_buffer (vm, bi0);
967 ip0 = vlib_buffer_get_current (p0);
968 h0 = ip6_next_header (ip0);
970 clib_net_to_host_u16 (ip0->payload_length) - sizeof (h0[0]);
972 error0 = ICMP6_ERROR_NONE;
973 sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX];
974 ip6_sadd_link_local =
975 ip6_address_is_link_local_unicast (&ip0->src_address);
976 ip6_sadd_unspecified =
977 ip6_address_is_unspecified (&ip0->src_address);
979 /* Check that source address is unspecified, link-local or else on-link. */
980 if (!ip6_sadd_unspecified && !ip6_sadd_link_local)
982 u32 src_adj_index0 = ip6_src_lookup_for_packet (im, p0, ip0);
984 if (ADJ_INDEX_INVALID != src_adj_index0)
986 ip_adjacency_t *adj0 =
987 ip_get_adjacency (&im->lookup_main, src_adj_index0);
989 /* Allow all realistic-looking rewrite adjacencies to pass */
990 ni0 = adj0->lookup_next_index;
991 is_rewrite0 = (ni0 >= IP_LOOKUP_NEXT_ARP) &&
992 (ni0 < IP6_LOOKUP_N_NEXT);
994 error0 = ((adj0->rewrite_header.sw_if_index != sw_if_index0
997 ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_NOT_ON_LINK
1003 ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_NOT_ON_LINK;
1007 o0 = (void *) (h0 + 1);
1008 o0 = ((options_len0 == 8 && o0->header.type == option_type
1009 && o0->header.n_data_u64s == 1) ? o0 : 0);
1011 /* If src address unspecified or link local, donot learn neighbor MAC */
1012 if (PREDICT_TRUE (error0 == ICMP6_ERROR_NONE && o0 != 0 &&
1013 !ip6_sadd_unspecified && !ip6_sadd_link_local))
1015 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
1016 if (nm->limit_neighbor_cache_size &&
1017 pool_elts (nm->neighbor_pool) >=
1018 nm->limit_neighbor_cache_size)
1019 unset_random_neighbor_entry ();
1020 vnet_set_ip6_ethernet_neighbor (vm, sw_if_index0,
1023 &h0->target_address,
1024 o0->ethernet_address,
1025 sizeof (o0->ethernet_address),
1029 if (is_solicitation && error0 == ICMP6_ERROR_NONE)
1031 /* Check that target address is local to this router. */
1032 fib_node_index_t fei;
1036 ip6_fib_table_get_index_for_sw_if_index (sw_if_index0);
1038 if (~0 == fib_index)
1040 error0 = ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_UNKNOWN;
1044 fei = ip6_fib_table_lookup_exact_match (fib_index,
1045 &h0->target_address,
1048 if (FIB_NODE_INDEX_INVALID == fei)
1050 /* The target address is not in the FIB */
1052 ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_UNKNOWN;
1056 if (FIB_ENTRY_FLAG_LOCAL &
1057 fib_entry_get_flags_for_source (fei,
1058 FIB_SOURCE_INTERFACE))
1060 /* It's an address that belongs to one of our interfaces
1064 if (fib_entry_is_sourced
1065 (fei, FIB_SOURCE_IP6_ND_PROXY))
1067 /* The address was added by IPv6 Proxy ND config.
1068 * We should only respond to these if the NS arrived on
1069 * the link that has a matching covering prefix */
1074 ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_UNKNOWN;
1080 if (is_solicitation)
1081 next0 = (error0 != ICMP6_ERROR_NONE
1082 ? ICMP6_NEIGHBOR_SOLICITATION_NEXT_DROP
1083 : ICMP6_NEIGHBOR_SOLICITATION_NEXT_REPLY);
1087 error0 = error0 == ICMP6_ERROR_NONE ?
1088 ICMP6_ERROR_NEIGHBOR_ADVERTISEMENTS_RX : error0;
1091 if (is_solicitation && error0 == ICMP6_ERROR_NONE)
1093 vnet_sw_interface_t *sw_if0;
1094 ethernet_interface_t *eth_if0;
1095 ethernet_header_t *eth0;
1097 /* dst address is either source address or the all-nodes mcast addr */
1098 if (!ip6_sadd_unspecified)
1099 ip0->dst_address = ip0->src_address;
1101 ip6_set_reserved_multicast_address (&ip0->dst_address,
1102 IP6_MULTICAST_SCOPE_link_local,
1103 IP6_MULTICAST_GROUP_ID_all_hosts);
1105 ip0->src_address = h0->target_address;
1106 ip0->hop_limit = 255;
1107 h0->icmp.type = ICMP6_neighbor_advertisement;
1109 sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index0);
1110 ASSERT (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE);
1112 ethernet_get_interface (ðernet_main, sw_if0->hw_if_index);
1115 clib_memcpy (o0->ethernet_address, eth_if0->address, 6);
1117 ICMP6_NEIGHBOR_DISCOVERY_OPTION_target_link_layer_address;
1120 h0->advertisement_flags = clib_host_to_net_u32
1121 (ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_SOLICITED
1122 | ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_OVERRIDE);
1124 h0->icmp.checksum = 0;
1126 ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip0,
1128 ASSERT (bogus_length == 0);
1130 /* Reuse current MAC header, copy SMAC to DMAC and
1131 * interface MAC to SMAC */
1132 vlib_buffer_advance (p0, -ethernet_buffer_header_size (p0));
1133 eth0 = vlib_buffer_get_current (p0);
1134 clib_memcpy (eth0->dst_address, eth0->src_address, 6);
1136 clib_memcpy (eth0->src_address, eth_if0->address, 6);
1138 /* Setup input and output sw_if_index for packet */
1139 ASSERT (vnet_buffer (p0)->sw_if_index[VLIB_RX] == sw_if_index0);
1140 vnet_buffer (p0)->sw_if_index[VLIB_TX] = sw_if_index0;
1141 vnet_buffer (p0)->sw_if_index[VLIB_RX] =
1142 vnet_main.local_interface_sw_if_index;
1144 n_advertisements_sent++;
1147 p0->error = error_node->errors[error0];
1149 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1150 to_next, n_left_to_next,
1154 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1157 /* Account for advertisements sent. */
1158 vlib_error_count (vm, error_node->node_index,
1159 ICMP6_ERROR_NEIGHBOR_ADVERTISEMENTS_TX,
1160 n_advertisements_sent);
1162 return frame->n_vectors;
1165 /* for "syslogging" - use elog for now */
1166 #define foreach_log_level \
1167 _ (DEBUG, "DEBUG") \
1168 _ (INFO, "INFORMATION") \
1169 _ (NOTICE, "NOTICE") \
1170 _ (WARNING, "WARNING") \
1172 _ (CRIT, "CRITICAL") \
1173 _ (ALERT, "ALERT") \
1174 _ (EMERG, "EMERGENCY")
1178 #define _(f,s) LOG_##f,
1183 static char *log_level_strings[] = {
1189 static int logmask = 1 << LOG_DEBUG;
1192 ip6_neighbor_syslog (vlib_main_t * vm, int priority, char *fmt, ...)
1194 /* just use elog for now */
1198 if ((priority > LOG_EMERG) || !(logmask & (1 << priority)))
1204 what = va_format (0, fmt, &va);
1206 ELOG_TYPE_DECLARE (e) =
1208 .format = "ip6 nd: (%s): %s",.format_args = "T4T4",};
1213 ed = ELOG_DATA (&vm->elog_main, e);
1214 ed->s[0] = elog_string (&vm->elog_main, log_level_strings[priority]);
1215 ed->s[1] = elog_string (&vm->elog_main, (char *) what);
1221 /* ipv6 neighbor discovery - router advertisements */
1224 ICMP6_ROUTER_SOLICITATION_NEXT_DROP,
1225 ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_RW,
1226 ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_TX,
1227 ICMP6_ROUTER_SOLICITATION_N_NEXT,
1228 } icmp6_router_solicitation_or_advertisement_next_t;
1230 static_always_inline uword
1231 icmp6_router_solicitation (vlib_main_t * vm,
1232 vlib_node_runtime_t * node, vlib_frame_t * frame)
1234 vnet_main_t *vnm = vnet_get_main ();
1235 ip6_main_t *im = &ip6_main;
1236 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
1237 uword n_packets = frame->n_vectors;
1238 u32 *from, *to_next;
1239 u32 n_left_from, n_left_to_next, next_index;
1240 u32 n_advertisements_sent = 0;
1243 icmp6_neighbor_discovery_option_type_t option_type;
1245 vlib_node_runtime_t *error_node =
1246 vlib_node_get_runtime (vm, ip6_icmp_input_node.index);
1248 from = vlib_frame_vector_args (frame);
1249 n_left_from = n_packets;
1250 next_index = node->cached_next_index;
1252 if (node->flags & VLIB_NODE_FLAG_TRACE)
1253 vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors,
1255 sizeof (icmp6_input_trace_t));
1257 /* source may append his LL address */
1258 option_type = ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address;
1260 while (n_left_from > 0)
1262 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1264 while (n_left_from > 0 && n_left_to_next > 0)
1268 ip6_radv_t *radv_info = 0;
1270 icmp6_neighbor_discovery_header_t *h0;
1271 icmp6_neighbor_discovery_ethernet_link_layer_address_option_t *o0;
1273 u32 bi0, options_len0, sw_if_index0, next0, error0;
1274 u32 is_solicitation = 1, is_dropped = 0;
1275 u32 is_unspecified, is_link_local;
1277 bi0 = to_next[0] = from[0];
1282 n_left_to_next -= 1;
1284 p0 = vlib_get_buffer (vm, bi0);
1285 ip0 = vlib_buffer_get_current (p0);
1286 h0 = ip6_next_header (ip0);
1288 clib_net_to_host_u16 (ip0->payload_length) - sizeof (h0[0]);
1289 is_unspecified = ip6_address_is_unspecified (&ip0->src_address);
1291 ip6_address_is_link_local_unicast (&ip0->src_address);
1293 error0 = ICMP6_ERROR_NONE;
1294 sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX];
1296 /* check if solicitation (not from nd_timer node) */
1297 if (ip6_address_is_unspecified (&ip0->dst_address))
1298 is_solicitation = 0;
1300 /* Check that source address is unspecified, link-local or else on-link. */
1301 if (!is_unspecified && !is_link_local)
1303 u32 src_adj_index0 = ip6_src_lookup_for_packet (im, p0, ip0);
1305 if (ADJ_INDEX_INVALID != src_adj_index0)
1307 ip_adjacency_t *adj0 = ip_get_adjacency (&im->lookup_main,
1310 error0 = (adj0->rewrite_header.sw_if_index != sw_if_index0
1312 ICMP6_ERROR_ROUTER_SOLICITATION_SOURCE_NOT_ON_LINK
1317 error0 = ICMP6_ERROR_ROUTER_SOLICITATION_SOURCE_NOT_ON_LINK;
1321 /* check for source LL option and process */
1322 o0 = (void *) (h0 + 1);
1323 o0 = ((options_len0 == 8
1324 && o0->header.type == option_type
1325 && o0->header.n_data_u64s == 1) ? o0 : 0);
1327 /* if src address unspecified IGNORE any options */
1328 if (PREDICT_TRUE (error0 == ICMP6_ERROR_NONE && o0 != 0 &&
1329 !is_unspecified && !is_link_local))
1331 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
1332 if (nm->limit_neighbor_cache_size &&
1333 pool_elts (nm->neighbor_pool) >=
1334 nm->limit_neighbor_cache_size)
1335 unset_random_neighbor_entry ();
1337 vnet_set_ip6_ethernet_neighbor (vm, sw_if_index0,
1339 o0->ethernet_address,
1340 sizeof (o0->ethernet_address),
1344 /* default is to drop */
1345 next0 = ICMP6_ROUTER_SOLICITATION_NEXT_DROP;
1347 if (error0 == ICMP6_ERROR_NONE)
1349 vnet_sw_interface_t *sw_if0;
1350 ethernet_interface_t *eth_if0;
1353 sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index0);
1354 ASSERT (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE);
1356 ethernet_get_interface (ðernet_main, sw_if0->hw_if_index);
1358 /* only support ethernet interface type for now */
1360 (!eth_if0) ? ICMP6_ERROR_ROUTER_SOLICITATION_UNSUPPORTED_INTF
1363 if (error0 == ICMP6_ERROR_NONE)
1367 /* adjust the sizeof the buffer to just include the ipv6 header */
1368 p0->current_length -=
1370 sizeof (icmp6_neighbor_discovery_header_t));
1372 /* look up the radv_t information for this interface */
1373 vec_validate_init_empty
1374 (nm->if_radv_pool_index_by_sw_if_index, sw_if_index0, ~0);
1376 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index0];
1379 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
1383 ICMP6_ERROR_ROUTER_SOLICITATION_RADV_NOT_CONFIG :
1386 if (error0 == ICMP6_ERROR_NONE)
1388 f64 now = vlib_time_now (vm);
1390 /* for solicited adverts - need to rate limit */
1391 if (is_solicitation)
1393 if (0 != radv_info->last_radv_time &&
1394 (now - radv_info->last_radv_time) <
1395 MIN_DELAY_BETWEEN_RAS)
1398 radv_info->last_radv_time = now;
1402 icmp6_router_advertisement_header_t rh;
1404 rh.icmp.type = ICMP6_router_advertisement;
1406 rh.icmp.checksum = 0;
1408 rh.current_hop_limit = radv_info->curr_hop_limit;
1409 rh.router_lifetime_in_sec =
1410 clib_host_to_net_u16
1411 (radv_info->adv_router_lifetime_in_sec);
1413 time_in_msec_between_retransmitted_neighbor_solicitations
1415 clib_host_to_net_u32 (radv_info->
1416 adv_time_in_msec_between_retransmitted_neighbor_solicitations);
1417 rh.neighbor_reachable_time_in_msec =
1418 clib_host_to_net_u32 (radv_info->
1419 adv_neighbor_reachable_time_in_msec);
1422 (radv_info->adv_managed_flag) ?
1423 ICMP6_ROUTER_DISCOVERY_FLAG_ADDRESS_CONFIG_VIA_DHCP :
1426 ((radv_info->adv_other_flag) ?
1427 ICMP6_ROUTER_DISCOVERY_FLAG_OTHER_CONFIG_VIA_DHCP :
1431 u16 payload_length =
1432 sizeof (icmp6_router_advertisement_header_t);
1434 vlib_buffer_add_data (vm,
1435 p0->free_list_index,
1439 (icmp6_router_advertisement_header_t));
1441 if (radv_info->adv_link_layer_address)
1443 icmp6_neighbor_discovery_ethernet_link_layer_address_option_t
1447 ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address;
1448 h.header.n_data_u64s = 1;
1450 /* copy ll address */
1451 clib_memcpy (&h.ethernet_address[0],
1452 eth_if0->address, 6);
1454 vlib_buffer_add_data (vm,
1455 p0->free_list_index,
1459 (icmp6_neighbor_discovery_ethernet_link_layer_address_option_t));
1463 (icmp6_neighbor_discovery_ethernet_link_layer_address_option_t);
1466 /* add MTU option */
1467 if (radv_info->adv_link_mtu)
1469 icmp6_neighbor_discovery_mtu_option_t h;
1473 clib_host_to_net_u32 (radv_info->adv_link_mtu);
1474 h.header.type = ICMP6_NEIGHBOR_DISCOVERY_OPTION_mtu;
1475 h.header.n_data_u64s = 1;
1478 sizeof (icmp6_neighbor_discovery_mtu_option_t);
1480 vlib_buffer_add_data (vm,
1481 p0->free_list_index,
1485 (icmp6_neighbor_discovery_mtu_option_t));
1488 /* add advertised prefix options */
1489 ip6_radv_prefix_t *pr_info;
1492 pool_foreach (pr_info, radv_info->adv_prefixes_pool,
1494 if(pr_info->enabled &&
1495 (!pr_info->decrement_lifetime_flag
1496 || (pr_info->pref_lifetime_expires >0)))
1498 /* advertise this prefix */
1499 icmp6_neighbor_discovery_prefix_information_option_t h;
1501 h.header.type = ICMP6_NEIGHBOR_DISCOVERY_OPTION_prefix_information;
1502 h.header.n_data_u64s = (sizeof(icmp6_neighbor_discovery_prefix_information_option_t) >> 3);
1504 h.dst_address_length = pr_info->prefix_len;
1506 h.flags = (pr_info->adv_on_link_flag) ? ICMP6_NEIGHBOR_DISCOVERY_PREFIX_INFORMATION_FLAG_ON_LINK : 0;
1507 h.flags |= (pr_info->adv_autonomous_flag) ? ICMP6_NEIGHBOR_DISCOVERY_PREFIX_INFORMATION_AUTO : 0;
1509 if(radv_info->cease_radv && pr_info->deprecated_prefix_flag)
1511 h.valid_time = clib_host_to_net_u32(MIN_ADV_VALID_LIFETIME);
1512 h.preferred_time = 0;
1516 if(pr_info->decrement_lifetime_flag)
1518 pr_info->adv_valid_lifetime_in_secs = ((pr_info->valid_lifetime_expires > now)) ?
1519 (pr_info->valid_lifetime_expires - now) : 0;
1521 pr_info->adv_pref_lifetime_in_secs = ((pr_info->pref_lifetime_expires > now)) ?
1522 (pr_info->pref_lifetime_expires - now) : 0;
1525 h.valid_time = clib_host_to_net_u32(pr_info->adv_valid_lifetime_in_secs);
1526 h.preferred_time = clib_host_to_net_u32(pr_info->adv_pref_lifetime_in_secs) ;
1530 clib_memcpy(&h.dst_address, &pr_info->prefix, sizeof(ip6_address_t));
1532 payload_length += sizeof( icmp6_neighbor_discovery_prefix_information_option_t);
1534 vlib_buffer_add_data (vm,
1535 p0->free_list_index,
1537 (void *)&h, sizeof(icmp6_neighbor_discovery_prefix_information_option_t));
1543 /* add additional options before here */
1545 /* finish building the router advertisement... */
1546 if (!is_unspecified && radv_info->send_unicast)
1548 ip0->dst_address = ip0->src_address;
1552 /* target address is all-nodes mcast addr */
1553 ip6_set_reserved_multicast_address
1555 IP6_MULTICAST_SCOPE_link_local,
1556 IP6_MULTICAST_GROUP_ID_all_hosts);
1559 /* source address MUST be the link-local address */
1560 ip0->src_address = radv_info->link_local_address;
1562 ip0->hop_limit = 255;
1563 ip0->payload_length =
1564 clib_host_to_net_u16 (payload_length);
1566 icmp6_router_advertisement_header_t *rh0 =
1567 (icmp6_router_advertisement_header_t *) (ip0 + 1);
1568 rh0->icmp.checksum =
1569 ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip0,
1571 ASSERT (bogus_length == 0);
1573 /* setup output if and adjacency */
1574 vnet_buffer (p0)->sw_if_index[VLIB_RX] =
1575 vnet_main.local_interface_sw_if_index;
1577 if (is_solicitation)
1579 ethernet_header_t *eth0;
1580 /* Reuse current MAC header, copy SMAC to DMAC and
1581 * interface MAC to SMAC */
1582 vlib_buffer_reset (p0);
1583 eth0 = vlib_buffer_get_current (p0);
1584 clib_memcpy (eth0->dst_address, eth0->src_address,
1586 clib_memcpy (eth0->src_address, eth_if0->address,
1589 is_dropped ? next0 :
1590 ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_TX;
1591 vnet_buffer (p0)->sw_if_index[VLIB_TX] =
1596 adj_index0 = radv_info->mcast_adj_index;
1597 if (adj_index0 == 0)
1598 error0 = ICMP6_ERROR_DST_LOOKUP_MISS;
1602 is_dropped ? next0 :
1603 ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_RW;
1604 vnet_buffer (p0)->ip.adj_index[VLIB_TX] =
1608 p0->flags |= VNET_BUFFER_LOCALLY_ORIGINATED;
1610 radv_info->n_solicitations_dropped += is_dropped;
1611 radv_info->n_solicitations_rcvd += is_solicitation;
1613 if ((error0 == ICMP6_ERROR_NONE) && !is_dropped)
1615 radv_info->n_advertisements_sent++;
1616 n_advertisements_sent++;
1622 p0->error = error_node->errors[error0];
1624 if (error0 != ICMP6_ERROR_NONE)
1625 vlib_error_count (vm, error_node->node_index, error0, 1);
1627 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1628 to_next, n_left_to_next,
1633 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1636 /* Account for router advertisements sent. */
1637 vlib_error_count (vm, error_node->node_index,
1638 ICMP6_ERROR_ROUTER_ADVERTISEMENTS_TX,
1639 n_advertisements_sent);
1641 return frame->n_vectors;
1644 /* validate advertised info for consistancy (see RFC-4861 section 6.2.7) - log any inconsistencies, packet will always be dropped */
1645 static_always_inline uword
1646 icmp6_router_advertisement (vlib_main_t * vm,
1647 vlib_node_runtime_t * node, vlib_frame_t * frame)
1649 vnet_main_t *vnm = vnet_get_main ();
1650 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
1651 uword n_packets = frame->n_vectors;
1652 u32 *from, *to_next;
1653 u32 n_left_from, n_left_to_next, next_index;
1654 u32 n_advertisements_rcvd = 0;
1656 vlib_node_runtime_t *error_node =
1657 vlib_node_get_runtime (vm, ip6_icmp_input_node.index);
1659 from = vlib_frame_vector_args (frame);
1660 n_left_from = n_packets;
1661 next_index = node->cached_next_index;
1663 if (node->flags & VLIB_NODE_FLAG_TRACE)
1664 vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors,
1666 sizeof (icmp6_input_trace_t));
1668 while (n_left_from > 0)
1670 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1672 while (n_left_from > 0 && n_left_to_next > 0)
1676 ip6_radv_t *radv_info = 0;
1677 icmp6_router_advertisement_header_t *h0;
1678 u32 bi0, options_len0, sw_if_index0, next0, error0;
1680 bi0 = to_next[0] = from[0];
1685 n_left_to_next -= 1;
1687 p0 = vlib_get_buffer (vm, bi0);
1688 ip0 = vlib_buffer_get_current (p0);
1689 h0 = ip6_next_header (ip0);
1691 clib_net_to_host_u16 (ip0->payload_length) - sizeof (h0[0]);
1693 error0 = ICMP6_ERROR_NONE;
1694 sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX];
1696 /* Check that source address is link-local */
1697 error0 = (!ip6_address_is_link_local_unicast (&ip0->src_address)) ?
1698 ICMP6_ERROR_ROUTER_ADVERTISEMENT_SOURCE_NOT_LINK_LOCAL : error0;
1700 /* default is to drop */
1701 next0 = ICMP6_ROUTER_SOLICITATION_NEXT_DROP;
1703 n_advertisements_rcvd++;
1705 if (error0 == ICMP6_ERROR_NONE)
1707 vnet_sw_interface_t *sw_if0;
1708 ethernet_interface_t *eth_if0;
1710 sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index0);
1711 ASSERT (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE);
1713 ethernet_get_interface (ðernet_main, sw_if0->hw_if_index);
1715 /* only support ethernet interface type for now */
1717 (!eth_if0) ? ICMP6_ERROR_ROUTER_SOLICITATION_UNSUPPORTED_INTF
1720 if (error0 == ICMP6_ERROR_NONE)
1724 /* look up the radv_t information for this interface */
1725 vec_validate_init_empty
1726 (nm->if_radv_pool_index_by_sw_if_index, sw_if_index0, ~0);
1728 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index0];
1731 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
1735 ICMP6_ERROR_ROUTER_SOLICITATION_RADV_NOT_CONFIG :
1738 if (error0 == ICMP6_ERROR_NONE)
1740 /* validate advertised information */
1741 if ((h0->current_hop_limit && radv_info->curr_hop_limit)
1742 && (h0->current_hop_limit !=
1743 radv_info->curr_hop_limit))
1745 ip6_neighbor_syslog (vm, LOG_WARNING,
1746 "our AdvCurHopLimit on %U doesn't agree with %U",
1747 format_vnet_sw_if_index_name,
1754 ICMP6_ROUTER_DISCOVERY_FLAG_ADDRESS_CONFIG_VIA_DHCP)
1755 != radv_info->adv_managed_flag)
1757 ip6_neighbor_syslog (vm, LOG_WARNING,
1758 "our AdvManagedFlag on %U doesn't agree with %U",
1759 format_vnet_sw_if_index_name,
1766 ICMP6_ROUTER_DISCOVERY_FLAG_OTHER_CONFIG_VIA_DHCP)
1767 != radv_info->adv_other_flag)
1769 ip6_neighbor_syslog (vm, LOG_WARNING,
1770 "our AdvOtherConfigFlag on %U doesn't agree with %U",
1771 format_vnet_sw_if_index_name,
1778 time_in_msec_between_retransmitted_neighbor_solicitations
1780 adv_time_in_msec_between_retransmitted_neighbor_solicitations)
1782 time_in_msec_between_retransmitted_neighbor_solicitations
1784 clib_host_to_net_u32 (radv_info->
1785 adv_time_in_msec_between_retransmitted_neighbor_solicitations)))
1787 ip6_neighbor_syslog (vm, LOG_WARNING,
1788 "our AdvRetransTimer on %U doesn't agree with %U",
1789 format_vnet_sw_if_index_name,
1795 if ((h0->neighbor_reachable_time_in_msec &&
1796 radv_info->adv_neighbor_reachable_time_in_msec) &&
1797 (h0->neighbor_reachable_time_in_msec !=
1798 clib_host_to_net_u32
1799 (radv_info->adv_neighbor_reachable_time_in_msec)))
1801 ip6_neighbor_syslog (vm, LOG_WARNING,
1802 "our AdvReachableTime on %U doesn't agree with %U",
1803 format_vnet_sw_if_index_name,
1809 /* check for MTU or prefix options or .. */
1810 u8 *opt_hdr = (u8 *) (h0 + 1);
1811 while (options_len0 > 0)
1813 icmp6_neighbor_discovery_option_header_t *o0 =
1814 (icmp6_neighbor_discovery_option_header_t *)
1816 int opt_len = o0->n_data_u64s << 3;
1817 icmp6_neighbor_discovery_option_type_t option_type =
1820 if (options_len0 < 2)
1822 ip6_neighbor_syslog (vm, LOG_ERR,
1823 "malformed RA packet on %U from %U",
1824 format_vnet_sw_if_index_name,
1833 ip6_neighbor_syslog (vm, LOG_ERR,
1834 " zero length option in RA on %U from %U",
1835 format_vnet_sw_if_index_name,
1841 else if (opt_len > options_len0)
1843 ip6_neighbor_syslog (vm, LOG_ERR,
1844 "option length in RA packet greater than total length on %U from %U",
1845 format_vnet_sw_if_index_name,
1852 options_len0 -= opt_len;
1855 switch (option_type)
1857 case ICMP6_NEIGHBOR_DISCOVERY_OPTION_mtu:
1859 icmp6_neighbor_discovery_mtu_option_t *h =
1860 (icmp6_neighbor_discovery_mtu_option_t
1863 if (opt_len < sizeof (*h))
1866 if ((h->mtu && radv_info->adv_link_mtu) &&
1868 clib_host_to_net_u32
1869 (radv_info->adv_link_mtu)))
1871 ip6_neighbor_syslog (vm, LOG_WARNING,
1872 "our AdvLinkMTU on %U doesn't agree with %U",
1873 format_vnet_sw_if_index_name,
1881 case ICMP6_NEIGHBOR_DISCOVERY_OPTION_prefix_information:
1883 icmp6_neighbor_discovery_prefix_information_option_t
1885 (icmp6_neighbor_discovery_prefix_information_option_t
1888 /* validate advertised prefix options */
1889 ip6_radv_prefix_t *pr_info;
1890 u32 preferred, valid;
1892 if (opt_len < sizeof (*h))
1896 clib_net_to_host_u32 (h->preferred_time);
1897 valid = clib_net_to_host_u32 (h->valid_time);
1899 /* look for matching prefix - if we our advertising it, it better be consistant */
1901 pool_foreach (pr_info, radv_info->adv_prefixes_pool,
1905 ip6_address_mask_from_width(&mask, pr_info->prefix_len);
1907 if(pr_info->enabled &&
1908 (pr_info->prefix_len == h->dst_address_length) &&
1909 ip6_address_is_equal_masked (&pr_info->prefix, &h->dst_address, &mask))
1912 if(!pr_info->decrement_lifetime_flag &&
1913 valid != pr_info->adv_valid_lifetime_in_secs)
1915 ip6_neighbor_syslog(vm, LOG_WARNING,
1916 "our ADV validlifetime on %U for %U does not agree with %U",
1917 format_vnet_sw_if_index_name, vnm, sw_if_index0,format_ip6_address, &pr_info->prefix,
1918 format_ip6_address, &h->dst_address);
1920 if(!pr_info->decrement_lifetime_flag &&
1921 preferred != pr_info->adv_pref_lifetime_in_secs)
1923 ip6_neighbor_syslog(vm, LOG_WARNING,
1924 "our ADV preferredlifetime on %U for %U does not agree with %U",
1925 format_vnet_sw_if_index_name, vnm, sw_if_index0,format_ip6_address, &pr_info->prefix,
1926 format_ip6_address, &h->dst_address);
1943 p0->error = error_node->errors[error0];
1945 if (error0 != ICMP6_ERROR_NONE)
1946 vlib_error_count (vm, error_node->node_index, error0, 1);
1948 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1949 to_next, n_left_to_next,
1953 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1956 /* Account for router advertisements sent. */
1957 vlib_error_count (vm, error_node->node_index,
1958 ICMP6_ERROR_ROUTER_ADVERTISEMENTS_RX,
1959 n_advertisements_rcvd);
1961 return frame->n_vectors;
1965 * @brief Add a multicast Address to the advertised MLD set
1968 ip6_neighbor_add_mld_prefix (ip6_radv_t * radv_info, ip6_address_t * addr)
1970 ip6_mldp_group_t *mcast_group_info;
1973 /* lookup mldp info for this interface */
1974 p = mhash_get (&radv_info->address_to_mldp_index, &addr);
1976 p ? pool_elt_at_index (radv_info->mldp_group_pool, p[0]) : 0;
1979 if (!mcast_group_info)
1983 pool_get (radv_info->mldp_group_pool, mcast_group_info);
1985 mi = mcast_group_info - radv_info->mldp_group_pool;
1986 mhash_set (&radv_info->address_to_mldp_index, &addr, mi, /* old_value */
1989 mcast_group_info->type = 4;
1990 mcast_group_info->mcast_source_address_pool = 0;
1991 mcast_group_info->num_sources = 0;
1992 clib_memcpy (&mcast_group_info->mcast_address, &addr,
1993 sizeof (ip6_address_t));
1998 * @brief Delete a multicast Address from the advertised MLD set
2001 ip6_neighbor_del_mld_prefix (ip6_radv_t * radv_info, ip6_address_t * addr)
2003 ip6_mldp_group_t *mcast_group_info;
2006 p = mhash_get (&radv_info->address_to_mldp_index, &addr);
2008 p ? pool_elt_at_index (radv_info->mldp_group_pool, p[0]) : 0;
2010 if (mcast_group_info)
2012 mhash_unset (&radv_info->address_to_mldp_index, &addr,
2014 pool_put (radv_info->mldp_group_pool, mcast_group_info);
2019 * @brief Add a multicast Address to the advertised MLD set
2022 ip6_neighbor_add_mld_grp (ip6_radv_t * a,
2023 ip6_multicast_address_scope_t scope,
2024 ip6_multicast_link_local_group_id_t group)
2028 ip6_set_reserved_multicast_address (&addr, scope, group);
2030 ip6_neighbor_add_mld_prefix (a, &addr);
2034 * @brief create and initialize router advertisement parameters with default
2035 * values for this intfc
2038 ip6_neighbor_sw_interface_add_del (vnet_main_t * vnm,
2039 u32 sw_if_index, u32 is_add)
2041 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
2044 vnet_sw_interface_t *sw_if0;
2045 ethernet_interface_t *eth_if0 = 0;
2047 /* lookup radv container - ethernet interfaces only */
2048 sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index);
2049 if (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE)
2050 eth_if0 = ethernet_get_interface (ðernet_main, sw_if0->hw_if_index);
2055 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index,
2057 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
2061 a = pool_elt_at_index (nm->if_radv_pool, ri);
2065 ip6_radv_prefix_t *p;
2066 ip6_mldp_group_t *m;
2068 /* release the lock on the interface's mcast adj */
2069 adj_unlock (a->mcast_adj_index);
2071 /* clean up prefix and MDP pools */
2073 pool_flush(p, a->adv_prefixes_pool,
2075 mhash_unset (&a->address_to_prefix_index, &p->prefix, 0);
2077 pool_flush (m, a->mldp_group_pool,
2079 mhash_unset (&a->address_to_mldp_index, &m->mcast_address, 0);
2083 pool_free (a->mldp_group_pool);
2084 pool_free (a->adv_prefixes_pool);
2086 mhash_free (&a->address_to_prefix_index);
2087 mhash_free (&a->address_to_mldp_index);
2089 pool_put (nm->if_radv_pool, a);
2090 nm->if_radv_pool_index_by_sw_if_index[sw_if_index] = ~0;
2098 vnet_hw_interface_t *hw_if0;
2100 hw_if0 = vnet_get_sup_hw_interface (vnm, sw_if_index);
2102 pool_get (nm->if_radv_pool, a);
2104 ri = a - nm->if_radv_pool;
2105 nm->if_radv_pool_index_by_sw_if_index[sw_if_index] = ri;
2107 /* initialize default values (most of which are zero) */
2108 memset (a, 0, sizeof (a[0]));
2110 a->sw_if_index = sw_if_index;
2111 a->max_radv_interval = DEF_MAX_RADV_INTERVAL;
2112 a->min_radv_interval = DEF_MIN_RADV_INTERVAL;
2113 a->curr_hop_limit = DEF_CURR_HOP_LIMIT;
2114 a->adv_router_lifetime_in_sec = DEF_DEF_RTR_LIFETIME;
2116 /* send ll address source address option */
2117 a->adv_link_layer_address = 1;
2119 a->min_delay_between_radv = MIN_DELAY_BETWEEN_RAS;
2120 a->max_delay_between_radv = MAX_DELAY_BETWEEN_RAS;
2121 a->max_rtr_default_lifetime = MAX_DEF_RTR_LIFETIME;
2122 a->seed = (u32) clib_cpu_time_now ();
2123 (void) random_u32 (&a->seed);
2124 a->randomizer = clib_cpu_time_now ();
2125 (void) random_u64 (&a->randomizer);
2127 a->initial_adverts_count = MAX_INITIAL_RTR_ADVERTISEMENTS;
2128 a->initial_adverts_sent = a->initial_adverts_count - 1;
2129 a->initial_adverts_interval = MAX_INITIAL_RTR_ADVERT_INTERVAL;
2131 /* deafult is to send */
2134 /* fill in radv_info for this interface that will be needed later */
2135 a->adv_link_mtu = hw_if0->max_l3_packet_bytes[VLIB_RX];
2137 clib_memcpy (a->link_layer_address, eth_if0->address, 6);
2139 /* fill in default link-local address (this may be overridden) */
2140 ip6_link_local_address_from_ethernet_address
2141 (&a->link_local_address, eth_if0->address);
2143 mhash_init (&a->address_to_prefix_index, sizeof (uword),
2144 sizeof (ip6_address_t));
2145 mhash_init (&a->address_to_mldp_index, sizeof (uword),
2146 sizeof (ip6_address_t));
2148 a->mcast_adj_index = adj_mcast_add_or_lock (FIB_PROTOCOL_IP6,
2152 /* add multicast groups we will always be reporting */
2153 ip6_neighbor_add_mld_grp (a,
2154 IP6_MULTICAST_SCOPE_link_local,
2155 IP6_MULTICAST_GROUP_ID_all_hosts);
2156 ip6_neighbor_add_mld_grp (a,
2157 IP6_MULTICAST_SCOPE_link_local,
2158 IP6_MULTICAST_GROUP_ID_all_routers);
2159 ip6_neighbor_add_mld_grp (a,
2160 IP6_MULTICAST_SCOPE_link_local,
2161 IP6_MULTICAST_GROUP_ID_mldv2_routers);
2167 /* send an mldpv2 report */
2169 ip6_neighbor_send_mldpv2_report (u32 sw_if_index)
2171 vnet_main_t *vnm = vnet_get_main ();
2172 vlib_main_t *vm = vnm->vlib_main;
2173 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
2174 vnet_sw_interface_t *sw_if0;
2175 ethernet_interface_t *eth_if0;
2179 ip6_radv_t *radv_info;
2189 icmp6_multicast_listener_report_header_t *rh0;
2190 icmp6_multicast_listener_report_packet_t *rp0;
2192 sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index);
2193 ASSERT (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE);
2194 eth_if0 = ethernet_get_interface (ðernet_main, sw_if0->hw_if_index);
2196 if (!eth_if0 || !vnet_sw_interface_is_admin_up (vnm, sw_if_index))
2199 /* look up the radv_t information for this interface */
2200 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index,
2203 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
2208 /* send report now - build a mldpv2 report packet */
2209 n_allocated = vlib_buffer_alloc_from_free_list (vm,
2212 VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
2213 if (PREDICT_FALSE (n_allocated == 0))
2215 clib_warning ("buffer allocation failure");
2219 b0 = vlib_get_buffer (vm, bo0);
2221 /* adjust the sizeof the buffer to just include the ipv6 header */
2222 b0->current_length = sizeof (icmp6_multicast_listener_report_packet_t);
2224 payload_length = sizeof (icmp6_multicast_listener_report_header_t);
2226 b0->error = ICMP6_ERROR_NONE;
2228 rp0 = vlib_buffer_get_current (b0);
2229 ip0 = (ip6_header_t *) & rp0->ip;
2230 rh0 = (icmp6_multicast_listener_report_header_t *) & rp0->report_hdr;
2232 memset (rp0, 0x0, sizeof (icmp6_multicast_listener_report_packet_t));
2234 ip0->ip_version_traffic_class_and_flow_label =
2235 clib_host_to_net_u32 (0x6 << 28);
2237 ip0->protocol = IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS;
2238 /* for DEBUG - vnet driver won't seem to emit router alerts */
2239 /* ip0->protocol = IP_PROTOCOL_ICMP6; */
2242 rh0->icmp.type = ICMP6_multicast_listener_report_v2;
2244 /* source address MUST be the link-local address */
2245 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
2246 ip0->src_address = radv_info->link_local_address;
2248 /* destination is all mldpv2 routers */
2249 ip6_set_reserved_multicast_address (&ip0->dst_address,
2250 IP6_MULTICAST_SCOPE_link_local,
2251 IP6_MULTICAST_GROUP_ID_mldv2_routers);
2253 /* add reports here */
2254 ip6_mldp_group_t *m;
2255 int num_addr_records = 0;
2256 icmp6_multicast_address_record_t rr;
2258 /* fill in the hop-by-hop extension header (router alert) info */
2259 rh0->ext_hdr.next_hdr = IP_PROTOCOL_ICMP6;
2260 rh0->ext_hdr.n_data_u64s = 0;
2262 rh0->alert.type = IP6_MLDP_ALERT_TYPE;
2264 rh0->alert.value = 0;
2269 rh0->icmp.checksum = 0;
2272 pool_foreach (m, radv_info->mldp_group_pool,
2275 rr.aux_data_len_u32s = 0;
2276 rr.num_sources = clib_host_to_net_u16 (m->num_sources);
2277 clib_memcpy(&rr.mcast_addr, &m->mcast_address, sizeof(ip6_address_t));
2281 vlib_buffer_add_data
2282 (vm, b0->free_list_index, bo0,
2283 (void *)&rr, sizeof(icmp6_multicast_address_record_t));
2285 payload_length += sizeof( icmp6_multicast_address_record_t);
2290 rh0->num_addr_records = clib_host_to_net_u16 (num_addr_records);
2292 /* update lengths */
2293 ip0->payload_length = clib_host_to_net_u16 (payload_length);
2295 rh0->icmp.checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip0,
2297 ASSERT (bogus_length == 0);
2300 * OK to override w/ no regard for actual FIB, because
2301 * ip6-rewrite only looks at the adjacency.
2303 vnet_buffer (b0)->sw_if_index[VLIB_RX] =
2304 vnet_main.local_interface_sw_if_index;
2306 vnet_buffer (b0)->ip.adj_index[VLIB_TX] = radv_info->mcast_adj_index;
2307 b0->flags |= VNET_BUFFER_LOCALLY_ORIGINATED;
2309 vlib_node_t *node = vlib_get_node_by_name (vm, (u8 *) "ip6-rewrite-mcast");
2311 f = vlib_get_frame_to_node (vm, node->index);
2312 to_next = vlib_frame_vector_args (f);
2316 vlib_put_frame_to_node (vm, node->index, f);
2321 VLIB_REGISTER_NODE (ip6_icmp_router_solicitation_node,static) =
2323 .function = icmp6_router_solicitation,
2324 .name = "icmp6-router-solicitation",
2326 .vector_size = sizeof (u32),
2328 .format_trace = format_icmp6_input_trace,
2330 .n_next_nodes = ICMP6_ROUTER_SOLICITATION_N_NEXT,
2332 [ICMP6_ROUTER_SOLICITATION_NEXT_DROP] = "error-drop",
2333 [ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_RW] = "ip6-rewrite-mcast",
2334 [ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_TX] = "interface-output",
2339 /* send a RA or update the timer info etc.. */
2341 ip6_neighbor_process_timer_event (vlib_main_t * vm,
2342 vlib_node_runtime_t * node,
2343 vlib_frame_t * frame)
2345 vnet_main_t *vnm = vnet_get_main ();
2346 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
2347 ip6_radv_t *radv_info;
2348 vlib_frame_t *f = 0;
2349 u32 n_this_frame = 0;
2350 u32 n_left_to_next = 0;
2353 icmp6_router_solicitation_header_t *h0;
2355 f64 now = vlib_time_now (vm);
2357 /* Interface ip6 radv info list */
2359 pool_foreach (radv_info, nm->if_radv_pool,
2361 if( !vnet_sw_interface_is_admin_up (vnm, radv_info->sw_if_index))
2363 radv_info->initial_adverts_sent = radv_info->initial_adverts_count-1;
2364 radv_info->next_multicast_time = now;
2365 radv_info->last_multicast_time = now;
2366 radv_info->last_radv_time = 0;
2367 radv_info->all_routers_mcast = 0;
2371 /* Make sure that we've joined the all-routers multicast group */
2372 if(!radv_info->all_routers_mcast)
2374 /* send MDLP_REPORT_EVENT message */
2375 ip6_neighbor_send_mldpv2_report(radv_info->sw_if_index);
2376 radv_info->all_routers_mcast = 1;
2379 /* is it time to send a multicast RA on this interface? */
2380 if(radv_info->send_radv && (now >= radv_info->next_multicast_time))
2385 f64 rfn = (radv_info->max_radv_interval - radv_info->min_radv_interval) *
2386 random_f64 (&radv_info->seed) + radv_info->min_radv_interval;
2388 /* multicast send - compute next multicast send time */
2389 if( radv_info->initial_adverts_sent > 0)
2391 radv_info->initial_adverts_sent--;
2392 if(rfn > radv_info-> initial_adverts_interval)
2393 rfn = radv_info-> initial_adverts_interval;
2395 /* check to see if we are ceasing to send */
2396 if( radv_info->initial_adverts_sent == 0)
2397 if(radv_info->cease_radv)
2398 radv_info->send_radv = 0;
2401 radv_info->next_multicast_time = rfn + now;
2402 radv_info->last_multicast_time = now;
2404 /* send advert now - build a "solicted" router advert with unspecified source address */
2405 n_allocated = vlib_buffer_alloc_from_free_list
2406 (vm, &bo0, n_to_alloc, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
2408 if (PREDICT_FALSE(n_allocated == 0))
2410 clib_warning ("buffer allocation failure");
2413 b0 = vlib_get_buffer (vm, bo0);
2414 b0->current_length = sizeof( icmp6_router_solicitation_header_t);
2415 b0->error = ICMP6_ERROR_NONE;
2416 vnet_buffer (b0)->sw_if_index[VLIB_RX] = radv_info->sw_if_index;
2418 h0 = vlib_buffer_get_current (b0);
2420 memset (h0, 0, sizeof (icmp6_router_solicitation_header_t));
2422 h0->ip.ip_version_traffic_class_and_flow_label = clib_host_to_net_u32 (0x6 << 28);
2423 h0->ip.payload_length = clib_host_to_net_u16 (sizeof (icmp6_router_solicitation_header_t)
2424 - STRUCT_OFFSET_OF (icmp6_router_solicitation_header_t, neighbor));
2425 h0->ip.protocol = IP_PROTOCOL_ICMP6;
2426 h0->ip.hop_limit = 255;
2428 /* set src/dst address as "unspecified" this marks this packet as internally generated rather than recieved */
2429 h0->ip.src_address.as_u64[0] = 0;
2430 h0->ip.src_address.as_u64[1] = 0;
2432 h0->ip.dst_address.as_u64[0] = 0;
2433 h0->ip.dst_address.as_u64[1] = 0;
2435 h0->neighbor.icmp.type = ICMP6_router_solicitation;
2437 if (PREDICT_FALSE(f == 0))
2439 f = vlib_get_frame_to_node (vm, ip6_icmp_router_solicitation_node.index);
2440 to_next = vlib_frame_vector_args (f);
2441 n_left_to_next = VLIB_FRAME_SIZE;
2450 if (PREDICT_FALSE(n_left_to_next == 0))
2452 f->n_vectors = n_this_frame;
2453 vlib_put_frame_to_node (vm, ip6_icmp_router_solicitation_node.index, f);
2462 ASSERT (n_this_frame);
2463 f->n_vectors = n_this_frame;
2464 vlib_put_frame_to_node (vm, ip6_icmp_router_solicitation_node.index, f);
2470 ip6_icmp_neighbor_discovery_event_process (vlib_main_t * vm,
2471 vlib_node_runtime_t * node,
2472 vlib_frame_t * frame)
2475 ip6_icmp_neighbor_discovery_event_data_t *event_data;
2477 /* init code here */
2481 vlib_process_wait_for_event_or_clock (vm, 1. /* seconds */ );
2483 event_data = vlib_process_get_event_data (vm, &event_type);
2487 /* No events found: timer expired. */
2488 /* process interface list and send RAs as appropriate, update timer info */
2489 ip6_neighbor_process_timer_event (vm, node, frame);
2496 case ICMP6_ND_EVENT_INIT:
2507 _vec_len (event_data) = 0;
2510 return frame->n_vectors;
2514 VLIB_REGISTER_NODE (ip6_icmp_router_advertisement_node,static) =
2516 .function = icmp6_router_advertisement,
2517 .name = "icmp6-router-advertisement",
2519 .vector_size = sizeof (u32),
2521 .format_trace = format_icmp6_input_trace,
2530 vlib_node_registration_t ip6_icmp_neighbor_discovery_event_node = {
2532 .function = ip6_icmp_neighbor_discovery_event_process,
2533 .name = "ip6-icmp-neighbor-discovery-event-process",
2534 .type = VLIB_NODE_TYPE_PROCESS,
2538 icmp6_neighbor_solicitation (vlib_main_t * vm,
2539 vlib_node_runtime_t * node, vlib_frame_t * frame)
2541 return icmp6_neighbor_solicitation_or_advertisement (vm, node, frame,
2542 /* is_solicitation */
2547 icmp6_neighbor_advertisement (vlib_main_t * vm,
2548 vlib_node_runtime_t * node,
2549 vlib_frame_t * frame)
2551 return icmp6_neighbor_solicitation_or_advertisement (vm, node, frame,
2552 /* is_solicitation */
2557 VLIB_REGISTER_NODE (ip6_icmp_neighbor_solicitation_node,static) =
2559 .function = icmp6_neighbor_solicitation,
2560 .name = "icmp6-neighbor-solicitation",
2562 .vector_size = sizeof (u32),
2564 .format_trace = format_icmp6_input_trace,
2566 .n_next_nodes = ICMP6_NEIGHBOR_SOLICITATION_N_NEXT,
2568 [ICMP6_NEIGHBOR_SOLICITATION_NEXT_DROP] = "error-drop",
2569 [ICMP6_NEIGHBOR_SOLICITATION_NEXT_REPLY] = "interface-output",
2575 VLIB_REGISTER_NODE (ip6_icmp_neighbor_advertisement_node,static) =
2577 .function = icmp6_neighbor_advertisement,
2578 .name = "icmp6-neighbor-advertisement",
2580 .vector_size = sizeof (u32),
2582 .format_trace = format_icmp6_input_trace,
2591 /* API support functions */
2593 ip6_neighbor_ra_config (vlib_main_t * vm, u32 sw_if_index,
2594 u8 suppress, u8 managed, u8 other,
2595 u8 ll_option, u8 send_unicast, u8 cease,
2596 u8 use_lifetime, u32 lifetime,
2597 u32 initial_count, u32 initial_interval,
2598 u32 max_interval, u32 min_interval, u8 is_no)
2600 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
2604 /* look up the radv_t information for this interface */
2605 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index,
2607 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
2608 error = (ri != ~0) ? 0 : VNET_API_ERROR_INVALID_SW_IF_INDEX;
2613 ip6_radv_t *radv_info;
2614 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
2616 if ((max_interval != 0) && (min_interval == 0))
2617 min_interval = .75 * max_interval;
2621 0) ? ((is_no) ? DEF_MAX_RADV_INTERVAL : max_interval) :
2622 radv_info->max_radv_interval;
2625 0) ? ((is_no) ? DEF_MIN_RADV_INTERVAL : min_interval) :
2626 radv_info->min_radv_interval;
2629 0) ? ((is_no) ? DEF_DEF_RTR_LIFETIME : lifetime) :
2630 radv_info->adv_router_lifetime_in_sec;
2634 if (lifetime > MAX_DEF_RTR_LIFETIME)
2635 lifetime = MAX_DEF_RTR_LIFETIME;
2637 if (lifetime <= max_interval)
2638 return VNET_API_ERROR_INVALID_VALUE;
2641 if (min_interval != 0)
2643 if ((min_interval > .75 * max_interval) || (min_interval < 3))
2644 return VNET_API_ERROR_INVALID_VALUE;
2647 if ((initial_count > MAX_INITIAL_RTR_ADVERTISEMENTS) ||
2648 (initial_interval > MAX_INITIAL_RTR_ADVERT_INTERVAL))
2649 return VNET_API_ERROR_INVALID_VALUE;
2652 if "flag" is set and is_no is true then restore default value else set value corresponding to "flag"
2653 if "flag" is clear don't change corresponding value
2655 radv_info->send_radv =
2656 (suppress != 0) ? ((is_no != 0) ? 1 : 0) : radv_info->send_radv;
2657 radv_info->adv_managed_flag =
2658 (managed != 0) ? ((is_no) ? 0 : 1) : radv_info->adv_managed_flag;
2659 radv_info->adv_other_flag =
2660 (other != 0) ? ((is_no) ? 0 : 1) : radv_info->adv_other_flag;
2661 radv_info->adv_link_layer_address =
2663 0) ? ((is_no) ? 1 : 0) : radv_info->adv_link_layer_address;
2664 radv_info->send_unicast =
2665 (send_unicast != 0) ? ((is_no) ? 0 : 1) : radv_info->send_unicast;
2666 radv_info->cease_radv =
2667 (cease != 0) ? ((is_no) ? 0 : 1) : radv_info->cease_radv;
2669 radv_info->min_radv_interval = min_interval;
2670 radv_info->max_radv_interval = max_interval;
2671 radv_info->adv_router_lifetime_in_sec = lifetime;
2673 radv_info->initial_adverts_count =
2675 0) ? ((is_no) ? MAX_INITIAL_RTR_ADVERTISEMENTS : initial_count) :
2676 radv_info->initial_adverts_count;
2677 radv_info->initial_adverts_interval =
2678 (initial_interval !=
2679 0) ? ((is_no) ? MAX_INITIAL_RTR_ADVERT_INTERVAL : initial_interval) :
2680 radv_info->initial_adverts_interval;
2683 if ((cease != 0) && (is_no))
2684 radv_info->send_radv = 1;
2686 radv_info->initial_adverts_sent = radv_info->initial_adverts_count - 1;
2687 radv_info->next_multicast_time = vlib_time_now (vm);
2688 radv_info->last_multicast_time = vlib_time_now (vm);
2689 radv_info->last_radv_time = 0;
2695 ip6_neighbor_ra_prefix (vlib_main_t * vm, u32 sw_if_index,
2696 ip6_address_t * prefix_addr, u8 prefix_len,
2697 u8 use_default, u32 val_lifetime, u32 pref_lifetime,
2698 u8 no_advertise, u8 off_link, u8 no_autoconfig,
2699 u8 no_onlink, u8 is_no)
2701 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
2706 /* look up the radv_t information for this interface */
2707 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index,
2710 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
2712 error = (ri != ~0) ? 0 : VNET_API_ERROR_INVALID_SW_IF_INDEX;
2716 f64 now = vlib_time_now (vm);
2717 ip6_radv_t *radv_info;
2718 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
2720 /* prefix info add, delete or update */
2721 ip6_radv_prefix_t *prefix;
2723 /* lookup prefix info for this address on this interface */
2724 uword *p = mhash_get (&radv_info->address_to_prefix_index, prefix_addr);
2726 prefix = p ? pool_elt_at_index (radv_info->adv_prefixes_pool, p[0]) : 0;
2732 return VNET_API_ERROR_INVALID_VALUE; /* invalid prefix */
2734 if (prefix->prefix_len != prefix_len)
2735 return VNET_API_ERROR_INVALID_VALUE_2;
2737 /* FIXME - Should the DP do this or the CP ? */
2738 /* do specific delete processing here before returning */
2739 /* try to remove from routing table */
2741 mhash_unset (&radv_info->address_to_prefix_index, prefix_addr,
2743 pool_put (radv_info->adv_prefixes_pool, prefix);
2745 radv_info->initial_adverts_sent =
2746 radv_info->initial_adverts_count - 1;
2747 radv_info->next_multicast_time = vlib_time_now (vm);
2748 radv_info->last_multicast_time = vlib_time_now (vm);
2749 radv_info->last_radv_time = 0;
2753 /* adding or changing */
2758 pool_get (radv_info->adv_prefixes_pool, prefix);
2759 pi = prefix - radv_info->adv_prefixes_pool;
2760 mhash_set (&radv_info->address_to_prefix_index, prefix_addr, pi,
2763 memset (prefix, 0x0, sizeof (ip6_radv_prefix_t));
2765 prefix->prefix_len = prefix_len;
2766 clib_memcpy (&prefix->prefix, prefix_addr, sizeof (ip6_address_t));
2768 /* initialize default values */
2769 prefix->adv_on_link_flag = 1; /* L bit set */
2770 prefix->adv_autonomous_flag = 1; /* A bit set */
2771 prefix->adv_valid_lifetime_in_secs = DEF_ADV_VALID_LIFETIME;
2772 prefix->adv_pref_lifetime_in_secs = DEF_ADV_PREF_LIFETIME;
2773 prefix->enabled = 1;
2774 prefix->decrement_lifetime_flag = 1;
2775 prefix->deprecated_prefix_flag = 1;
2779 /* FIXME - Should the DP do this or the CP ? */
2780 /* insert prefix into routing table as a connected prefix */
2789 if (prefix->prefix_len != prefix_len)
2790 return VNET_API_ERROR_INVALID_VALUE_2;
2794 /* FIXME - Should the DP do this or the CP ? */
2795 /* remove from routing table if already there */
2799 if ((val_lifetime == ~0) || (pref_lifetime == ~0))
2801 prefix->adv_valid_lifetime_in_secs = ~0;
2802 prefix->adv_pref_lifetime_in_secs = ~0;
2803 prefix->decrement_lifetime_flag = 0;
2807 prefix->adv_valid_lifetime_in_secs = val_lifetime;;
2808 prefix->adv_pref_lifetime_in_secs = pref_lifetime;
2811 /* copy remaining */
2812 prefix->enabled = !(no_advertise != 0);
2813 prefix->adv_on_link_flag = !((off_link != 0) || (no_onlink != 0));
2814 prefix->adv_autonomous_flag = !(no_autoconfig != 0);
2818 /* fill in the expiration times */
2819 prefix->valid_lifetime_expires =
2820 now + prefix->adv_valid_lifetime_in_secs;
2821 prefix->pref_lifetime_expires = now + prefix->adv_pref_lifetime_in_secs;
2823 radv_info->initial_adverts_sent = radv_info->initial_adverts_count - 1;
2824 radv_info->next_multicast_time = vlib_time_now (vm);
2825 radv_info->last_multicast_time = vlib_time_now (vm);
2826 radv_info->last_radv_time = 0;
2832 ip6_neighbor_cmd (vlib_main_t * vm, unformat_input_t * main_input,
2833 vlib_cli_command_t * cmd)
2835 vnet_main_t *vnm = vnet_get_main ();
2836 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
2837 clib_error_t *error = 0;
2839 u8 suppress = 0, managed = 0, other = 0;
2840 u8 suppress_ll_option = 0, send_unicast = 0, cease = 0;
2841 u8 use_lifetime = 0;
2842 u32 sw_if_index, ra_lifetime = 0, ra_initial_count =
2843 0, ra_initial_interval = 0;
2844 u32 ra_max_interval = 0, ra_min_interval = 0;
2846 unformat_input_t _line_input, *line_input = &_line_input;
2847 vnet_sw_interface_t *sw_if0;
2849 int add_radv_info = 1;
2850 __attribute__ ((unused)) ip6_radv_t *radv_info = 0;
2851 ip6_address_t ip6_addr;
2855 /* Get a line of input. */
2856 if (!unformat_user (main_input, unformat_line_input, line_input))
2859 /* get basic radv info for this interface */
2860 if (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2863 if (unformat_user (line_input,
2864 unformat_vnet_sw_interface, vnm, &sw_if_index))
2867 ethernet_interface_t *eth_if0 = 0;
2869 sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index);
2870 if (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE)
2872 ethernet_get_interface (ðernet_main, sw_if0->hw_if_index);
2877 clib_error_return (0, "Interface must be of ethernet type");
2881 /* look up the radv_t information for this interface */
2882 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index,
2885 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
2889 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
2893 error = clib_error_return (0, "unknown interface %U'",
2894 format_unformat_error, line_input);
2900 error = clib_error_return (0, "invalid interface name %U'",
2901 format_unformat_error, line_input);
2906 /* get the rest of the command */
2907 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2909 if (unformat (line_input, "no"))
2911 else if (unformat (line_input, "prefix %U/%d",
2912 unformat_ip6_address, &ip6_addr, &addr_len))
2917 else if (unformat (line_input, "ra-managed-config-flag"))
2922 else if (unformat (line_input, "ra-other-config-flag"))
2927 else if (unformat (line_input, "ra-suppress") ||
2928 unformat (line_input, "ra-surpress"))
2933 else if (unformat (line_input, "ra-suppress-link-layer") ||
2934 unformat (line_input, "ra-surpress-link-layer"))
2936 suppress_ll_option = 1;
2939 else if (unformat (line_input, "ra-send-unicast"))
2944 else if (unformat (line_input, "ra-lifetime"))
2946 if (!unformat (line_input, "%d", &ra_lifetime))
2948 error = unformat_parse_error (line_input);
2954 else if (unformat (line_input, "ra-initial"))
2957 (line_input, "%d %d", &ra_initial_count, &ra_initial_interval))
2959 error = unformat_parse_error (line_input);
2964 else if (unformat (line_input, "ra-interval"))
2966 if (!unformat (line_input, "%d", &ra_max_interval))
2968 error = unformat_parse_error (line_input);
2972 if (!unformat (line_input, "%d", &ra_min_interval))
2973 ra_min_interval = 0;
2976 else if (unformat (line_input, "ra-cease"))
2983 error = unformat_parse_error (line_input);
2990 ip6_neighbor_ra_config (vm, sw_if_index,
2991 suppress, managed, other,
2992 suppress_ll_option, send_unicast, cease,
2993 use_lifetime, ra_lifetime,
2994 ra_initial_count, ra_initial_interval,
2995 ra_max_interval, ra_min_interval, is_no);
2999 u32 valid_lifetime_in_secs = 0;
3000 u32 pref_lifetime_in_secs = 0;
3001 u8 use_prefix_default_values = 0;
3002 u8 no_advertise = 0;
3004 u8 no_autoconfig = 0;
3007 /* get the rest of the command */
3008 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
3010 if (unformat (line_input, "default"))
3012 use_prefix_default_values = 1;
3015 else if (unformat (line_input, "infinite"))
3017 valid_lifetime_in_secs = ~0;
3018 pref_lifetime_in_secs = ~0;
3021 else if (unformat (line_input, "%d %d", &valid_lifetime_in_secs,
3022 &pref_lifetime_in_secs))
3029 /* get the rest of the command */
3030 while (!use_prefix_default_values &&
3031 unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
3033 if (unformat (line_input, "no-advertise"))
3035 else if (unformat (line_input, "off-link"))
3037 else if (unformat (line_input, "no-autoconfig"))
3039 else if (unformat (line_input, "no-onlink"))
3043 error = unformat_parse_error (line_input);
3048 ip6_neighbor_ra_prefix (vm, sw_if_index,
3049 &ip6_addr, addr_len,
3050 use_prefix_default_values,
3051 valid_lifetime_in_secs,
3052 pref_lifetime_in_secs,
3054 off_link, no_autoconfig, no_onlink, is_no);
3058 unformat_free (line_input);
3064 ip6_print_addrs (vlib_main_t * vm, u32 * addrs)
3066 ip_lookup_main_t *lm = &ip6_main.lookup_main;
3069 for (i = 0; i < vec_len (addrs); i++)
3071 ip_interface_address_t *a =
3072 pool_elt_at_index (lm->if_address_pool, addrs[i]);
3073 ip6_address_t *address = ip_interface_address_get_address (lm, a);
3075 vlib_cli_output (vm, "\t\t%U/%d",
3076 format_ip6_address, address, a->address_length);
3080 static clib_error_t *
3081 show_ip6_interface_cmd (vlib_main_t * vm,
3082 unformat_input_t * input, vlib_cli_command_t * cmd)
3084 vnet_main_t *vnm = vnet_get_main ();
3085 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
3086 clib_error_t *error = 0;
3091 if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
3095 /* look up the radv_t information for this interface */
3096 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index,
3099 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
3103 ip_lookup_main_t *lm = &ip6_main.lookup_main;
3104 ip6_radv_t *radv_info;
3105 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
3107 vlib_cli_output (vm, "%U is admin %s\n",
3108 format_vnet_sw_interface_name, vnm,
3109 vnet_get_sw_interface (vnm, sw_if_index),
3110 (vnet_sw_interface_is_admin_up (vnm, sw_if_index) ?
3114 u32 *link_scope = 0, *global_scope = 0;
3115 u32 *local_scope = 0, *unknown_scope = 0;
3116 ip_interface_address_t *a;
3118 vec_validate_init_empty (lm->if_address_pool_index_by_sw_if_index,
3120 ai = lm->if_address_pool_index_by_sw_if_index[sw_if_index];
3122 while (ai != (u32) ~ 0)
3124 a = pool_elt_at_index (lm->if_address_pool, ai);
3125 ip6_address_t *address =
3126 ip_interface_address_get_address (lm, a);
3128 if (ip6_address_is_link_local_unicast (address))
3129 vec_add1 (link_scope, ai);
3130 else if (ip6_address_is_global_unicast (address))
3131 vec_add1 (global_scope, ai);
3132 else if (ip6_address_is_local_unicast (address))
3133 vec_add1 (local_scope, ai);
3135 vec_add1 (unknown_scope, ai);
3137 ai = a->next_this_sw_interface;
3140 if (vec_len (link_scope))
3142 vlib_cli_output (vm, "\tLink-local address(es):\n");
3143 ip6_print_addrs (vm, link_scope);
3144 vec_free (link_scope);
3147 if (vec_len (local_scope))
3149 vlib_cli_output (vm, "\tLocal unicast address(es):\n");
3150 ip6_print_addrs (vm, local_scope);
3151 vec_free (local_scope);
3154 if (vec_len (global_scope))
3156 vlib_cli_output (vm, "\tGlobal unicast address(es):\n");
3157 ip6_print_addrs (vm, global_scope);
3158 vec_free (global_scope);
3161 if (vec_len (unknown_scope))
3163 vlib_cli_output (vm, "\tOther-scope address(es):\n");
3164 ip6_print_addrs (vm, unknown_scope);
3165 vec_free (unknown_scope);
3168 vlib_cli_output (vm, "\tJoined group address(es):\n");
3169 ip6_mldp_group_t *m;
3171 pool_foreach (m, radv_info->mldp_group_pool,
3173 vlib_cli_output (vm, "\t\t%U\n", format_ip6_address,
3178 vlib_cli_output (vm, "\tAdvertised Prefixes:\n");
3179 ip6_radv_prefix_t *p;
3181 pool_foreach (p, radv_info->adv_prefixes_pool,
3183 vlib_cli_output (vm, "\t\tprefix %U, length %d\n",
3184 format_ip6_address, &p->prefix, p->prefix_len);
3188 vlib_cli_output (vm, "\tMTU is %d\n", radv_info->adv_link_mtu);
3189 vlib_cli_output (vm, "\tICMP error messages are unlimited\n");
3190 vlib_cli_output (vm, "\tICMP redirects are disabled\n");
3191 vlib_cli_output (vm, "\tICMP unreachables are not sent\n");
3192 vlib_cli_output (vm, "\tND DAD is disabled\n");
3193 //vlib_cli_output (vm, "\tND reachable time is %d milliseconds\n",);
3194 vlib_cli_output (vm, "\tND advertised reachable time is %d\n",
3195 radv_info->adv_neighbor_reachable_time_in_msec);
3196 vlib_cli_output (vm,
3197 "\tND advertised retransmit interval is %d (msec)\n",
3199 adv_time_in_msec_between_retransmitted_neighbor_solicitations);
3201 u32 ra_interval = radv_info->max_radv_interval;
3202 u32 ra_interval_min = radv_info->min_radv_interval;
3203 vlib_cli_output (vm,
3204 "\tND router advertisements are sent every %d seconds (min interval is %d)\n",
3205 ra_interval, ra_interval_min);
3206 vlib_cli_output (vm,
3207 "\tND router advertisements live for %d seconds\n",
3208 radv_info->adv_router_lifetime_in_sec);
3209 vlib_cli_output (vm,
3210 "\tHosts %s stateless autoconfig for addresses\n",
3211 (radv_info->adv_managed_flag) ? "use" :
3213 vlib_cli_output (vm, "\tND router advertisements sent %d\n",
3214 radv_info->n_advertisements_sent);
3215 vlib_cli_output (vm, "\tND router solicitations received %d\n",
3216 radv_info->n_solicitations_rcvd);
3217 vlib_cli_output (vm, "\tND router solicitations dropped %d\n",
3218 radv_info->n_solicitations_dropped);
3222 error = clib_error_return (0, "IPv6 not enabled on interface",
3223 format_unformat_error, input);
3231 * This command is used to display various IPv6 attributes on a given
3235 * Example of how to display IPv6 settings:
3236 * @cliexstart{show ip6 interface GigabitEthernet2/0/0}
3237 * GigabitEthernet2/0/0 is admin up
3238 * Link-local address(es):
3240 * Joined group address(es):
3245 * Advertised Prefixes:
3246 * prefix fe80::fe:28ff:fe9c:75b3, length 64
3248 * ICMP error messages are unlimited
3249 * ICMP redirects are disabled
3250 * ICMP unreachables are not sent
3251 * ND DAD is disabled
3252 * ND advertised reachable time is 0
3253 * ND advertised retransmit interval is 0 (msec)
3254 * ND router advertisements are sent every 200 seconds (min interval is 150)
3255 * ND router advertisements live for 600 seconds
3256 * Hosts use stateless autoconfig for addresses
3257 * ND router advertisements sent 19336
3258 * ND router solicitations received 0
3259 * ND router solicitations dropped 0
3261 * Example of output if IPv6 is not enabled on the interface:
3262 * @cliexstart{show ip6 interface GigabitEthernet2/0/0}
3263 * show ip6 interface: IPv6 not enabled on interface
3267 VLIB_CLI_COMMAND (show_ip6_interface_command, static) =
3269 .path = "show ip6 interface",
3270 .function = show_ip6_interface_cmd,
3271 .short_help = "show ip6 interface <interface>",
3276 disable_ip6_interface (vlib_main_t * vm, u32 sw_if_index)
3278 clib_error_t *error = 0;
3279 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
3282 /* look up the radv_t information for this interface */
3283 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index,
3285 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
3287 /* if not created - do nothing */
3290 vnet_main_t *vnm = vnet_get_main ();
3291 ip6_radv_t *radv_info;
3293 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
3295 /* check radv_info ref count for other ip6 addresses on this interface */
3296 /* This implicitly excludes the link local address */
3297 if (radv_info->ref_count == 0)
3299 /* essentially "disables" ipv6 on this interface */
3300 error = ip6_add_del_interface_address (vm, sw_if_index,
3302 link_local_address, 128,
3305 ip6_neighbor_sw_interface_add_del (vnm, sw_if_index,
3307 ip6_mfib_interface_enable_disable (sw_if_index, 0);
3314 ip6_interface_enabled (vlib_main_t * vm, u32 sw_if_index)
3316 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
3319 /* look up the radv_t information for this interface */
3320 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index,
3323 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
3329 enable_ip6_interface (vlib_main_t * vm, u32 sw_if_index)
3331 clib_error_t *error = 0;
3332 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
3336 /* look up the radv_t information for this interface */
3337 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index,
3340 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
3342 /* if not created yet */
3345 vnet_main_t *vnm = vnet_get_main ();
3346 vnet_sw_interface_t *sw_if0;
3348 sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index);
3349 if (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE)
3351 ethernet_interface_t *eth_if0;
3354 ethernet_get_interface (ðernet_main, sw_if0->hw_if_index);
3357 /* create radv_info. for this interface. This holds all the info needed for router adverts */
3359 ip6_neighbor_sw_interface_add_del (vnm, sw_if_index, is_add);
3363 ip6_radv_t *radv_info;
3364 ip6_address_t link_local_address;
3366 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
3368 ip6_link_local_address_from_ethernet_mac_address
3369 (&link_local_address, eth_if0->address);
3371 sw_if0 = vnet_get_sw_interface (vnm, sw_if_index);
3372 if (sw_if0->type == VNET_SW_INTERFACE_TYPE_SUB)
3374 /* make up an interface id */
3378 link_local_address.as_u64[0] = radv_info->randomizer;
3381 md5_add (&m, &link_local_address, 16);
3382 md5_finish (&m, digest);
3384 clib_memcpy (&link_local_address, digest, 16);
3386 radv_info->randomizer = link_local_address.as_u64[0];
3388 link_local_address.as_u64[0] =
3389 clib_host_to_net_u64 (0xFE80000000000000ULL);
3391 link_local_address.as_u8[8] &= 0xfd;
3394 ip6_mfib_interface_enable_disable (sw_if_index, 1);
3396 /* essentially "enables" ipv6 on this interface */
3397 error = ip6_add_del_interface_address (vm, sw_if_index,
3398 &link_local_address,
3400 /* address width */ ,
3404 ip6_neighbor_sw_interface_add_del (vnm, sw_if_index,
3408 radv_info->link_local_address = link_local_address;
3417 static clib_error_t *
3418 enable_ip6_interface_cmd (vlib_main_t * vm,
3419 unformat_input_t * input, vlib_cli_command_t * cmd)
3421 vnet_main_t *vnm = vnet_get_main ();
3422 clib_error_t *error = 0;
3427 if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
3429 enable_ip6_interface (vm, sw_if_index);
3433 error = clib_error_return (0, "unknown interface\n'",
3434 format_unformat_error, input);
3441 * This command is used to enable IPv6 on a given interface.
3444 * Example of how enable IPv6 on a given interface:
3445 * @cliexcmd{enable ip6 interface GigabitEthernet2/0/0}
3448 VLIB_CLI_COMMAND (enable_ip6_interface_command, static) =
3450 .path = "enable ip6 interface",
3451 .function = enable_ip6_interface_cmd,
3452 .short_help = "enable ip6 interface <interface>",
3456 static clib_error_t *
3457 disable_ip6_interface_cmd (vlib_main_t * vm,
3458 unformat_input_t * input, vlib_cli_command_t * cmd)
3460 vnet_main_t *vnm = vnet_get_main ();
3461 clib_error_t *error = 0;
3466 if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
3468 error = disable_ip6_interface (vm, sw_if_index);
3472 error = clib_error_return (0, "unknown interface\n'",
3473 format_unformat_error, input);
3480 * This command is used to disable IPv6 on a given interface.
3483 * Example of how disable IPv6 on a given interface:
3484 * @cliexcmd{disable ip6 interface GigabitEthernet2/0/0}
3487 VLIB_CLI_COMMAND (disable_ip6_interface_command, static) =
3489 .path = "disable ip6 interface",
3490 .function = disable_ip6_interface_cmd,
3491 .short_help = "disable ip6 interface <interface>",
3496 * This command is used to configure the neighbor discovery
3497 * parameters on a given interface. Use the '<em>show ip6 interface</em>'
3498 * command to display some of the current neighbor discovery parameters
3499 * on a given interface. This command has three formats:
3502 * <b>Format 1 - Router Advertisement Options:</b> (Only one can be entered in a single command)
3504 * '<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>'
3508 * <em>[no] ra-managed-config-flag</em> - Advertises in ICMPv6
3509 * router-advertisement messages to use stateful address
3510 * auto-configuration to obtain address information (sets the M-bit).
3511 * Default is the M-bit is not set and the '<em>no</em>' option
3512 * returns it to this default state.
3514 * <em>[no] ra-other-config-flag</em> - Indicates in ICMPv6
3515 * router-advertisement messages that hosts use stateful auto
3516 * configuration to obtain nonaddress related information (sets
3517 * the O-bit). Default is the O-bit is not set and the '<em>no</em>'
3518 * option returns it to this default state.
3520 * <em>[no] ra-suppress</em> - Disables sending ICMPv6 router-advertisement
3521 * messages. The '<em>no</em>' option implies to enable sending ICMPv6
3522 * router-advertisement messages.
3524 * <em>[no] ra-suppress-link-layer</em> - Indicates not to include the
3525 * optional source link-layer address in the ICMPv6 router-advertisement
3526 * messages. Default is to include the optional source link-layer address
3527 * and the '<em>no</em>' option returns it to this default state.
3529 * <em>[no] ra-send-unicast</em> - Use the source address of the
3530 * router-solicitation message if availiable. The default is to use
3531 * multicast address of all nodes, and the '<em>no</em>' option returns
3532 * it to this default state.
3534 * <em>[no] ra-lifetime <lifetime></em> - Advertises the lifetime of a
3535 * default router in ICMPv6 router-advertisement messages. The range is
3536 * from 0 to 9000 seconds. '<em><lifetime></em>' must be greater than
3537 * '<em><max-interval></em>'. The default value is 600 seconds and the
3538 * '<em>no</em>' option returns it to this default value.
3540 * <em>[no] ra-initial <cnt> <interval></em> - Number of initial ICMPv6
3541 * router-advertisement messages sent and the interval between each
3542 * message. Range for count is 1 - 3 and default is 3. Range for interval
3543 * is 1 to 16 seconds, and default is 16 seconds. The '<em>no</em>' option
3544 * returns both to their default value.
3546 * <em>[no] ra-interval <max-interval> [<min-interval>]</em> - Configures the
3547 * interval between sending ICMPv6 router-advertisement messages. The
3548 * range for max-interval is from 4 to 200 seconds. min-interval can not
3549 * be more than 75% of max-interval. If not set, min-interval will be
3550 * set to 75% of max-interval. The range for min-interval is from 3 to
3551 * 150 seconds. The '<em>no</em>' option returns both to their default
3554 * <em>[no] ra-cease</em> - Cease sending ICMPv6 router-advertisement messages.
3555 * The '<em>no</em>' options implies to start (or restart) sending
3556 * ICMPv6 router-advertisement messages.
3559 * <b>Format 2 - Prefix Options:</b>
3561 * '<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>'
3565 * <em>no</em> - All additional flags are ignored and the prefix is deleted.
3567 * <em><valid-lifetime> <pref-lifetime></em> - '<em><valid-lifetime></em>' is the
3568 * length of time in seconds during what the prefix is valid for the purpose of
3569 * on-link determination. Range is 7203 to 2592000 seconds and default is 2592000
3570 * seconds (30 days). '<em><pref-lifetime></em>' is the prefered-lifetime and is the
3571 * length of time in seconds during what addresses generated from the prefix remain
3572 * preferred. Range is 0 to 604800 seconds and default is 604800 seconds (7 days).
3574 * <em>infinite</em> - Both '<em><valid-lifetime></em>' and '<em><<pref-lifetime></em>'
3575 * are inifinte, no timeout.
3577 * <em>no-advertise</em> - Do not send full router address in prefix
3578 * advertisement. Default is to advertise (i.e. - This flag is off by default).
3580 * <em>off-link</em> - Prefix is off-link, clear L-bit in packet. Default is on-link
3581 * (i.e. - This flag is off and L-bit in packet is set by default and this prefix can
3582 * be used for on-link determination). '<em>no-onlink</em>' also controls the L-bit.
3584 * <em>no-autoconfig</em> - Do not use prefix for autoconfiguration, clear A-bit in packet.
3585 * Default is autoconfig (i.e. - This flag is off and A-bit in packet is set by default.
3587 * <em>no-onlink</em> - Do not use prefix for onlink determination, clear L-bit in packet.
3588 * Default is on-link (i.e. - This flag is off and L-bit in packet is set by default and
3589 * this prefix can be used for on-link determination). '<em>off-link</em>' also controls
3593 * <b>Format 3: - Default of Prefix:</b>
3595 * '<em><b>ip6 nd <interface> [no] prefix <ip6-address>/<width> default</b></em>'
3597 * When a new prefix is added (or existing one is being overwritten) <em>default</em>
3598 * uses default values for the prefix. If <em>no</em> is used, the <em>default</em>
3599 * is ignored and the prefix is deleted.
3603 * Example of how set a router advertisement option:
3604 * @cliexcmd{ip6 nd GigabitEthernet2/0/0 ra-interval 100 20}
3605 * Example of how to add a prefix:
3606 * @cliexcmd{ip6 nd GigabitEthernet2/0/0 prefix fe80::fe:28ff:fe9c:75b3/64 infinite no-advertise}
3607 * Example of how to delete a prefix:
3608 * @cliexcmd{ip6 nd GigabitEthernet2/0/0 no prefix fe80::fe:28ff:fe9c:75b3/64}
3611 VLIB_CLI_COMMAND (ip6_nd_command, static) =
3614 .short_help = "ip6 nd <interface> ...",
3615 .function = ip6_neighbor_cmd,
3620 set_ip6_link_local_address (vlib_main_t * vm,
3621 u32 sw_if_index, ip6_address_t * address)
3623 clib_error_t *error = 0;
3624 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
3626 ip6_radv_t *radv_info;
3627 vnet_main_t *vnm = vnet_get_main ();
3629 if (!ip6_address_is_link_local_unicast (address))
3631 vnm->api_errno = VNET_API_ERROR_ADDRESS_NOT_LINK_LOCAL;
3632 return (error = clib_error_return (0, "address not link-local",
3633 format_unformat_error));
3636 /* call enable ipv6 */
3637 enable_ip6_interface (vm, sw_if_index);
3639 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
3643 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
3645 /* save if link local address (overwrite default) */
3647 /* delete the old one */
3648 error = ip6_add_del_interface_address (vm, sw_if_index,
3649 &radv_info->link_local_address,
3650 128, 1 /* is_del */ );
3654 /* add the new one */
3655 error = ip6_add_del_interface_address (vm, sw_if_index,
3661 radv_info->link_local_address = *address;
3667 vnm->api_errno = VNET_API_ERROR_IP6_NOT_ENABLED;
3668 error = clib_error_return (0, "ip6 not enabled for interface",
3669 format_unformat_error);
3675 set_ip6_link_local_address_cmd (vlib_main_t * vm,
3676 unformat_input_t * input,
3677 vlib_cli_command_t * cmd)
3679 vnet_main_t *vnm = vnet_get_main ();
3680 clib_error_t *error = 0;
3682 ip6_address_t ip6_addr;
3684 if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
3686 /* get the rest of the command */
3687 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
3689 if (unformat (input, "%U", unformat_ip6_address, &ip6_addr))
3692 return (unformat_parse_error (input));
3695 error = set_ip6_link_local_address (vm, sw_if_index, &ip6_addr);
3700 * This command is used to assign an IPv6 Link-local address to an
3701 * interface. This command will enable IPv6 on an interface if it
3702 * is not already enabled. Use the '<em>show ip6 interface</em>' command
3703 * to display the assigned Link-local address.
3706 * Example of how to assign an IPv6 Link-local address to an interface:
3707 * @cliexcmd{set ip6 link-local address GigabitEthernet2/0/0 FE80::AB8}
3710 VLIB_CLI_COMMAND (set_ip6_link_local_address_command, static) =
3712 .path = "set ip6 link-local address",
3713 .short_help = "set ip6 link-local address <interface> <ip6-address>",
3714 .function = set_ip6_link_local_address_cmd,
3719 * @brief callback when an interface address is added or deleted
3722 ip6_neighbor_add_del_interface_address (ip6_main_t * im,
3725 ip6_address_t * address,
3727 u32 if_address_index, u32 is_delete)
3729 vnet_main_t *vnm = vnet_get_main ();
3730 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
3732 vlib_main_t *vm = vnm->vlib_main;
3733 ip6_radv_t *radv_info;
3736 /* create solicited node multicast address for this interface adddress */
3737 ip6_set_solicited_node_multicast_address (&a, 0);
3739 a.as_u8[0xd] = address->as_u8[0xd];
3740 a.as_u8[0xe] = address->as_u8[0xe];
3741 a.as_u8[0xf] = address->as_u8[0xf];
3745 /* try to create radv_info - does nothing if ipv6 already enabled */
3746 enable_ip6_interface (vm, sw_if_index);
3748 /* look up the radv_t information for this interface */
3749 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index,
3751 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
3755 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
3758 if (!ip6_address_is_link_local_unicast (address))
3759 radv_info->ref_count++;
3761 ip6_neighbor_add_mld_prefix (radv_info, &a);
3768 /* look up the radv_t information for this interface */
3769 vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index,
3771 ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
3776 radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
3778 ip6_neighbor_del_mld_prefix (radv_info, &a);
3780 /* if interface up send MLDP "report" */
3781 radv_info->all_routers_mcast = 0;
3784 if (!ip6_address_is_link_local_unicast (address))
3785 radv_info->ref_count--;
3787 /* Ensure that IPv6 is disabled, and LL removed after ref_count reaches 0 */
3788 disable_ip6_interface (vm, sw_if_index);
3793 ip6_set_neighbor_limit (u32 neighbor_limit)
3795 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
3797 nm->limit_neighbor_cache_size = neighbor_limit;
3801 static clib_error_t *
3802 ip6_neighbor_init (vlib_main_t * vm)
3804 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
3805 ip6_main_t *im = &ip6_main;
3807 mhash_init (&nm->neighbor_index_by_key,
3808 /* value size */ sizeof (uword),
3809 /* key size */ sizeof (ip6_neighbor_key_t));
3811 icmp6_register_type (vm, ICMP6_neighbor_solicitation,
3812 ip6_icmp_neighbor_solicitation_node.index);
3813 icmp6_register_type (vm, ICMP6_neighbor_advertisement,
3814 ip6_icmp_neighbor_advertisement_node.index);
3815 icmp6_register_type (vm, ICMP6_router_solicitation,
3816 ip6_icmp_router_solicitation_node.index);
3817 icmp6_register_type (vm, ICMP6_router_advertisement,
3818 ip6_icmp_router_advertisement_node.index);
3820 /* handler node for ip6 neighbor discovery events and timers */
3821 vlib_register_node (vm, &ip6_icmp_neighbor_discovery_event_node);
3823 /* add call backs */
3824 ip6_add_del_interface_address_callback_t cb;
3825 memset (&cb, 0x0, sizeof (ip6_add_del_interface_address_callback_t));
3827 /* when an interface address changes... */
3828 cb.function = ip6_neighbor_add_del_interface_address;
3829 cb.function_opaque = 0;
3830 vec_add1 (im->add_del_interface_address_callbacks, cb);
3832 mhash_init (&nm->pending_resolutions_by_address,
3833 /* value size */ sizeof (uword),
3834 /* key size */ sizeof (ip6_address_t));
3836 mhash_init (&nm->mac_changes_by_address,
3837 /* value size */ sizeof (uword),
3838 /* key size */ sizeof (ip6_address_t));
3840 /* default, configurable */
3841 nm->limit_neighbor_cache_size = 50000;
3844 /* $$$$ Hack fix for today */
3845 vec_validate_init_empty
3846 (im->discover_neighbor_next_index_by_hw_if_index, 32, 0 /* drop */ );
3852 VLIB_INIT_FUNCTION (ip6_neighbor_init);
3856 vnet_register_ip6_neighbor_resolution_event (vnet_main_t * vnm,
3859 uword type_opaque, uword data)
3861 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
3862 ip6_address_t *address = address_arg;
3864 pending_resolution_t *pr;
3866 pool_get (nm->pending_resolutions, pr);
3868 pr->next_index = ~0;
3869 pr->node_index = node_index;
3870 pr->type_opaque = type_opaque;
3873 p = mhash_get (&nm->pending_resolutions_by_address, address);
3876 /* Insert new resolution at the head of the list */
3877 pr->next_index = p[0];
3878 mhash_unset (&nm->pending_resolutions_by_address, address, 0);
3881 mhash_set (&nm->pending_resolutions_by_address, address,
3882 pr - nm->pending_resolutions, 0 /* old value */ );
3886 vnet_add_del_ip6_nd_change_event (vnet_main_t * vnm,
3887 void *data_callback,
3891 uword type_opaque, uword data, int is_add)
3893 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
3894 ip6_address_t *address = address_arg;
3896 pending_resolution_t *mc;
3897 void (*fp) (u32, u8 *) = data_callback;
3901 pool_get (nm->mac_changes, mc);
3903 mc->next_index = ~0;
3904 mc->node_index = node_index;
3905 mc->type_opaque = type_opaque;
3907 mc->data_callback = data_callback;
3910 p = mhash_get (&nm->mac_changes_by_address, address);
3913 /* Insert new resolution at the head of the list */
3914 mc->next_index = p[0];
3915 mhash_unset (&nm->mac_changes_by_address, address, 0);
3918 mhash_set (&nm->mac_changes_by_address, address,
3919 mc - nm->mac_changes, 0);
3925 pending_resolution_t *mc_last = 0;
3927 p = mhash_get (&nm->mac_changes_by_address, address);
3929 return VNET_API_ERROR_NO_SUCH_ENTRY;
3933 while (index != (u32) ~ 0)
3935 mc = pool_elt_at_index (nm->mac_changes, index);
3936 if (mc->node_index == node_index &&
3937 mc->type_opaque == type_opaque && mc->pid == pid)
3939 /* Clients may need to clean up pool entries, too */
3941 (*fp) (mc->data, 0 /* no new mac addrs */ );
3944 mhash_unset (&nm->mac_changes_by_address, address, 0);
3945 if (mc->next_index != ~0)
3946 mhash_set (&nm->mac_changes_by_address, address,
3948 pool_put (nm->mac_changes, mc);
3954 mc_last->next_index = mc->next_index;
3955 pool_put (nm->mac_changes, mc);
3960 index = mc->next_index;
3963 return VNET_API_ERROR_NO_SUCH_ENTRY;
3968 vnet_ip6_nd_term (vlib_main_t * vm,
3969 vlib_node_runtime_t * node,
3971 ethernet_header_t * eth,
3972 ip6_header_t * ip, u32 sw_if_index, u16 bd_index, u8 shg)
3974 ip6_neighbor_main_t *nm = &ip6_neighbor_main;
3975 icmp6_neighbor_solicitation_or_advertisement_header_t *ndh;
3976 pending_resolution_t *mc;
3979 ndh = ip6_next_header (ip);
3980 if (ndh->icmp.type != ICMP6_neighbor_solicitation &&
3981 ndh->icmp.type != ICMP6_neighbor_advertisement)
3984 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) &&
3985 (p0->flags & VLIB_BUFFER_IS_TRACED)))
3987 u8 *t0 = vlib_add_trace (vm, node, p0,
3988 sizeof (icmp6_input_trace_t));
3989 clib_memcpy (t0, ip, sizeof (icmp6_input_trace_t));
3992 /* Check if anyone want ND events for L2 BDs */
3993 p = mhash_get (&nm->mac_changes_by_address, &ip6a_zero);
3994 if (p && shg == 0 && /* Only SHG 0 interface which is more likely local */
3995 !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")