FD.io VPP  v16.06
Vector Packet Processing
ip6_neighbor.c
Go to the documentation of this file.
1 /*
2  * ip/ip6_neighbor.c: IP6 neighbor handling
3  *
4  * Copyright (c) 2010 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include <vnet/ip/ip.h>
19 #include <vnet/ethernet/ethernet.h>
20 #include <vppinfra/mhash.h>
21 #include <vppinfra/md5.h>
22 
23 #if DPDK==1
24 #include <vnet/devices/dpdk/dpdk.h>
25 #endif
26 
27 typedef struct {
32 
33 /* can't use sizeof link_layer_address, that's 8 */
34 #define ETHER_MAC_ADDR_LEN 6
35 
36 typedef struct {
38  u8 link_layer_address[8];
40 #define IP6_NEIGHBOR_FLAG_STATIC (1 << 0)
41 #define IP6_NEIGHBOR_FLAG_GLEAN (2 << 0)
45 
46 /* advertised prefix option */
47 typedef struct {
48  /* basic advertised information */
55 
56  /* advertised values are computed from these times if decrementing */
59 
60  /* local information */
61  int enabled;
64 
65 #define MIN_ADV_VALID_LIFETIME 7203 /* seconds */
66 #define DEF_ADV_VALID_LIFETIME 2592000
67 #define DEF_ADV_PREF_LIFETIME 604800
68 
69  /* extensions are added here, mobile, DNS etc.. */
71 
72 
73 typedef struct {
74  /* group information */
80 
81 /* configured router advertisement information per ipv6 interface */
82 typedef struct {
83 
84  /* advertised config information, zero means unspecified */
91 
92  /* mtu option */
94 
95  /* source link layer option */
96  u8 link_layer_address[8];
98 
99  /* prefix option */
101 
102  /* Hash table mapping address to index in interface advertised prefix pool. */
104 
105  /* MLDP group information */
107 
108  /* Hash table mapping address to index in mldp address pool. */
110 
111  /* local information */
114  int send_radv; /* radv on/off on this interface - set by config */
115  int cease_radv; /* we are ceasing to send - set byf config */
127 
128  /* timing information */
129 #define DEF_MAX_RADV_INTERVAL 200
130 #define DEF_MIN_RADV_INTERVAL .75 * DEF_MAX_RADV_INTERVAL
131 #define DEF_CURR_HOP_LIMIT 64
132 #define DEF_DEF_RTR_LIFETIME 3 * DEF_MAX_RADV_INTERVAL
133 #define MAX_DEF_RTR_LIFETIME 9000
134 
135 #define MAX_INITIAL_RTR_ADVERT_INTERVAL 16 /* seconds */
136 #define MAX_INITIAL_RTR_ADVERTISEMENTS 3 /*transmissions */
137 #define MIN_DELAY_BETWEEN_RAS 3 /* seconds */
138 #define MAX_DELAY_BETWEEN_RAS 1800 /* seconds */
139 #define MAX_RA_DELAY_TIME .5 /* seconds */
140 
146 
150 
151 
155 
156  /* stats */
160 
161  /* Link local address to use (defaults to underlying physical for logical interfaces */
164 
165 } ip6_radv_t;
166 
167 typedef struct {
168  u32 next_index;
169  uword node_index;
170  uword type_opaque;
171  uword data;
173 
174 
175 typedef struct {
176  /* Hash tables mapping name to opcode. */
178 
179  /* lite beer "glean" adjacency handling */
182 
184 
186 
188 
190 
192 
193  /* Neighbor attack mitigation */
196 
198 
200 
201 static u8 * format_ip6_neighbor_ip6_entry (u8 * s, va_list * va)
202 {
203  vlib_main_t * vm = va_arg (*va, vlib_main_t *);
204  ip6_neighbor_t * n = va_arg (*va, ip6_neighbor_t *);
205  vnet_main_t * vnm = vnet_get_main();
206  vnet_sw_interface_t * si;
207  u8 * flags = 0;
208 
209  if (! n)
210  return format (s, "%=12s%=20s%=6s%=20s%=40s", "Time", "Address", "Flags", "Link layer", "Interface");
211 
213  flags = format(flags, "G");
214 
216  flags = format(flags, "S");
217 
218  si = vnet_get_sw_interface (vnm, n->key.sw_if_index);
219  s = format (s, "%=12U%=20U%=6s%=20U%=40U",
222  flags ? (char *)flags : "",
225 
226  vec_free(flags);
227  return s;
228 }
229 
230 static clib_error_t *
232  u32 sw_if_index,
233  u32 flags)
234 {
236  ip6_neighbor_t * n;
237 
238  if (! (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP))
239  {
240  u32 i, * to_delete = 0;
241 
242  pool_foreach (n, nm->neighbor_pool, ({
243  if (n->key.sw_if_index == sw_if_index)
244  vec_add1 (to_delete, n - nm->neighbor_pool);
245  }));
246 
247  for (i = 0; i < vec_len (to_delete); i++)
248  {
249  n = pool_elt_at_index (nm->neighbor_pool, to_delete[i]);
250  mhash_unset (&nm->neighbor_index_by_key, &n->key, 0);
251  pool_put (nm->neighbor_pool, n);
252  }
253 
254  vec_free (to_delete);
255  }
256 
257  return 0;
258 }
259 
261 
262 static void unset_random_neighbor_entry (void)
263 {
265  vnet_main_t * vnm = vnet_get_main();
266  vlib_main_t * vm = vnm->vlib_main;
267  ip6_neighbor_t * e;
268  u32 index;
269 
271  nm->neighbor_delete_rotor = index;
272 
273  /* Try again from elt 0, could happen if an intfc goes down */
274  if (index == ~0)
275  {
277  nm->neighbor_delete_rotor = index;
278  }
279 
280  /* Nothing left in the pool */
281  if (index == ~0)
282  return;
283 
284  e = pool_elt_at_index (nm->neighbor_pool, index);
285 
287  &e->key.ip6_address,
290 }
291 
292 typedef struct {
295  u8 link_layer_address[6];
299 
300 #if DPDK > 0
301 static void ip6_neighbor_set_unset_rpc_callback
303 
304 static void set_unset_ip6_neighbor_rpc
305 (vlib_main_t * vm,
306  u32 sw_if_index,
307  ip6_address_t * a,
308  u8 *link_layer_addreess,
309  int is_add, int is_static)
310 {
312  void vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length);
313 
314  args.sw_if_index = sw_if_index;
315  args.is_add = is_add;
316  args.is_static = is_static;
317  clib_memcpy (&args.addr, a, sizeof (*a));
318  clib_memcpy (args.link_layer_address, link_layer_addreess, 6);
319 
320  vl_api_rpc_call_main_thread (ip6_neighbor_set_unset_rpc_callback,
321  (u8 *) &args, sizeof (args));
322 }
323 #endif
324 
325 int
327  u32 sw_if_index,
328  ip6_address_t * a,
329  u8 * link_layer_address,
330  uword n_bytes_link_layer_address,
331  int is_static)
332 {
333  vnet_main_t * vnm = vnet_get_main();
336  ip6_neighbor_t * n = 0;
337  ip6_main_t * im = &ip6_main;
338  ip_lookup_main_t * lm = &im->lookup_main;
339  int make_new_nd_cache_entry=1;
340  uword * p;
341  u32 next_index;
342  u32 adj_index;
343  ip_adjacency_t *existing_adj;
345 
346 #if DPDK > 0
347  if (os_get_cpu_number())
348  {
349  set_unset_ip6_neighbor_rpc (vm, sw_if_index, a, link_layer_address,
350  1 /* set new neighbor */, is_static);
351  return 0;
352  }
353 #endif
354 
355  k.sw_if_index = sw_if_index;
356  k.ip6_address = a[0];
357  k.pad = 0;
358 
360 
361  p = mhash_get (&nm->neighbor_index_by_key, &k);
362  if (p) {
363  n = pool_elt_at_index (nm->neighbor_pool, p[0]);
364  /* Refuse to over-write static neighbor entry. */
365  if (!is_static &&
367  return -2;
368  make_new_nd_cache_entry = 0;
369  }
370 
371  /* Note: always install the route. It might have been deleted */
373  ip_adjacency_t adj;
374 
375  memset (&adj, 0, sizeof(adj));
377  adj.explicit_fib_index = ~0;
378 
380  (vnm,
381  VNET_L3_PACKET_TYPE_IP6,
382  sw_if_index,
383  ip6_rewrite_node.index,
384  link_layer_address,
385  &adj.rewrite_header,
386  sizeof (adj.rewrite_data));
387 
388  /* result of this lookup should be next-hop adjacency */
389  adj_index = ip6_fib_lookup_with_table (im, im->fib_index_by_sw_if_index[sw_if_index], a);
390  existing_adj = ip_get_adjacency(lm, adj_index);
391 
392  if (existing_adj->lookup_next_index == IP_LOOKUP_NEXT_ARP &&
393  existing_adj->arp.next_hop.ip6.as_u64[0] == a->as_u64[0] &&
394  existing_adj->arp.next_hop.ip6.as_u64[1] == a->as_u64[1])
395  {
396  u32 * ai;
397  u32 * adjs = vec_dup(n->adjacencies);
398  /* Update all adj assigned to this arp entry */
399  vec_foreach(ai, adjs)
400  {
401  int i;
402  ip_adjacency_t * uadj = ip_get_adjacency(lm, *ai);
403  for (i = 0; i < uadj->n_adj; i++)
404  if (uadj[i].lookup_next_index == IP_LOOKUP_NEXT_ARP &&
405  uadj[i].arp.next_hop.ip6.as_u64[0] == a->as_u64[0] &&
406  uadj[i].arp.next_hop.ip6.as_u64[1] == a->as_u64[1])
407  ip_update_adjacency (lm, *ai + i, &adj);
408  }
409  vec_free(adjs);
410  }
411  else
412  {
413  /* create new adj */
414  args.table_index_or_table_id = im->fib_index_by_sw_if_index[sw_if_index];
416  args.dst_address = a[0];
417  args.dst_address_length = 128;
418  args.adj_index = ~0;
419  args.add_adj = &adj;
420  args.n_add_adj = 1;
421  ip6_add_del_route (im, &args);
422  }
423 
424  if (make_new_nd_cache_entry) {
425  pool_get (nm->neighbor_pool, n);
426  mhash_set (&nm->neighbor_index_by_key, &k, n - nm->neighbor_pool,
427  /* old value */ 0);
428  n->key = k;
429  }
430 
431  /* Update time stamp and ethernet address. */
432  clib_memcpy (n->link_layer_address, link_layer_address, n_bytes_link_layer_address);
434  if (is_static)
436 
437  /* Customer(s) waiting for this address to be resolved? */
439  if (p == 0)
440  goto out;
441 
442  next_index = p[0];
443 
444  while (next_index != (u32)~0)
445  {
446  pr = pool_elt_at_index (nm->pending_resolutions, next_index);
448  pr->type_opaque,
449  pr->data);
450  next_index = pr->next_index;
451  pool_put (nm->pending_resolutions, pr);
452  }
453 
455 
456 out:
458  return 0;
459 }
460 
461 int
463  u32 sw_if_index,
464  ip6_address_t * a,
465  u8 * link_layer_address,
466  uword n_bytes_link_layer_address)
467 {
470  ip6_neighbor_t * n;
471  ip6_main_t * im = &ip6_main;
473  uword * p;
474  int rv = 0;
475 
476 #if DPDK > 0
477  if (os_get_cpu_number())
478  {
479  set_unset_ip6_neighbor_rpc (vm, sw_if_index, a, link_layer_address,
480  0 /* unset */, 0);
481  return 0;
482  }
483 #endif
484 
485  k.sw_if_index = sw_if_index;
486  k.ip6_address = a[0];
487  k.pad = 0;
488 
490 
491  p = mhash_get (&nm->neighbor_index_by_key, &k);
492  if (p == 0)
493  {
494  rv = -1;
495  goto out;
496  }
497 
498  n = pool_elt_at_index (nm->neighbor_pool, p[0]);
499  mhash_unset (&nm->neighbor_index_by_key, &n->key, 0);
500  pool_put (nm->neighbor_pool, n);
501 
502  args.table_index_or_table_id = im->fib_index_by_sw_if_index[sw_if_index];
505  args.dst_address = a[0];
506  args.dst_address_length = 128;
507  args.adj_index = ~0;
508  args.add_adj = NULL;
509  args.n_add_adj = 0;
510  ip6_add_del_route (im, &args);
511  out:
513  return rv;
514 }
515 
516 
517 u32
518 vnet_ip6_neighbor_glean_add(u32 fib_index, void * next_hop_arg)
519 {
521  ip6_main_t * im = &ip6_main;
522  ip_lookup_main_t * lm = &im->lookup_main;
523  ip6_address_t * next_hop = next_hop_arg;
524  ip_adjacency_t add_adj, *adj;
526  ip6_neighbor_t * n;
528  u32 adj_index;
529 
530  adj_index = ip6_fib_lookup_with_table(im, fib_index, next_hop);
531  adj = ip_get_adjacency(lm, adj_index);
532 
533  if (!adj || adj->lookup_next_index != IP_LOOKUP_NEXT_ARP)
534  return ~0;
535 
536  if (adj->arp.next_hop.ip6.as_u64[0] ||
537  adj->arp.next_hop.ip6.as_u64[1])
538  return adj_index;
539 
540  k.sw_if_index = adj->rewrite_header.sw_if_index;
541  k.ip6_address = *next_hop;
542  k.pad = 0;
543  if (mhash_get (&nm->neighbor_index_by_key, &k))
544  return adj_index;
545 
546  pool_get (nm->neighbor_pool, n);
547  mhash_set (&nm->neighbor_index_by_key, &k, n - nm->neighbor_pool, /* old value */ 0);
548  n->key = k;
551 
552  memset(&args, 0, sizeof(args));
553  memcpy(&add_adj, adj, sizeof(add_adj));
554  add_adj.arp.next_hop.ip6 = *next_hop; /* install neighbor /128 route */
555  args.table_index_or_table_id = fib_index;
557  args.dst_address = *next_hop;
558  args.dst_address_length = 128;
559  args.adj_index = ~0;
560  args.add_adj = &add_adj;
561  args.n_add_adj = 1;
562  ip6_add_del_route (im, &args);
563  return ip6_fib_lookup_with_table (im, fib_index, next_hop);
564 }
565 
566 #if DPDK > 0
567 static void ip6_neighbor_set_unset_rpc_callback
569 {
570  vlib_main_t * vm = vlib_get_main();
571  if (a->is_add)
573  a->link_layer_address, 6, a->is_static);
574  else
576  a->link_layer_address, 6);
577 }
578 #endif
579 
580 static int
581 ip6_neighbor_sort (void *a1, void *a2)
582 {
583  vnet_main_t * vnm = vnet_get_main();
584  ip6_neighbor_t * n1 = a1, * n2 = a2;
585  int cmp;
586  cmp = vnet_sw_interface_compare (vnm, n1->key.sw_if_index,
587  n2->key.sw_if_index);
588  if (! cmp)
589  cmp = ip6_address_compare (&n1->key.ip6_address, &n2->key.ip6_address);
590  return cmp;
591 }
592 
593 static clib_error_t *
595  unformat_input_t * input,
596  vlib_cli_command_t * cmd)
597 {
598  vnet_main_t * vnm = vnet_get_main();
600  ip6_neighbor_t * n, * ns;
601  clib_error_t * error = 0;
602  u32 sw_if_index;
603 
604  /* Filter entries by interface if given. */
605  sw_if_index = ~0;
606  (void) unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index);
607 
608  ns = 0;
609  pool_foreach (n, nm->neighbor_pool, ({ vec_add1 (ns, n[0]); }));
612  vec_foreach (n, ns) {
613  if (sw_if_index != ~0 && n->key.sw_if_index != sw_if_index)
614  continue;
616  }
617  vec_free (ns);
618 
619  return error;
620 }
621 
623  .path = "show ip6 neighbors",
624  .function = show_ip6_neighbors,
625  .short_help = "Show ip6 neighbors",
626 };
627 
628 static clib_error_t *
630  unformat_input_t * input,
631  vlib_cli_command_t * cmd)
632 {
633  vnet_main_t * vnm = vnet_get_main();
635  u8 mac_address[6];
636  int addr_valid = 0;
637  int is_del = 0;
638  int is_static = 0;
639  u32 sw_if_index;
640 
641  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
642  {
643  /* intfc, ip6-address, mac-address */
644  if (unformat (input, "%U %U %U",
645  unformat_vnet_sw_interface, vnm, &sw_if_index,
646  unformat_ip6_address, &addr,
647  unformat_ethernet_address, mac_address))
648  addr_valid = 1;
649 
650  else if (unformat (input, "delete") || unformat (input, "del"))
651  is_del = 1;
652  else if (unformat (input, "static"))
653  is_static = 1;
654  else
655  break;
656  }
657 
658  if (!addr_valid)
659  return clib_error_return (0, "Missing interface, ip6 or hw address");
660 
661  if (!is_del)
662  vnet_set_ip6_ethernet_neighbor (vm, sw_if_index, &addr,
663  mac_address, sizeof(mac_address), is_static);
664  else
665  vnet_unset_ip6_ethernet_neighbor (vm, sw_if_index, &addr,
666  mac_address, sizeof(mac_address));
667  return 0;
668 }
669 
671  .path = "set ip6 neighbor",
672  .function = set_ip6_neighbor,
673  .short_help = "set ip6 neighbor [del] <intfc> <ip6-address> <mac-address> [static]",
674 };
675 
676 typedef enum {
681 
684  vlib_node_runtime_t * node,
685  vlib_frame_t * frame,
686  uword is_solicitation)
687 {
688  vnet_main_t * vnm = vnet_get_main();
689  ip6_main_t * im = &ip6_main;
690  ip_lookup_main_t * lm = &im->lookup_main;
691  uword n_packets = frame->n_vectors;
692  u32 * from, * to_next;
693  u32 n_left_from, n_left_to_next, next_index, n_advertisements_sent;
696  int bogus_length;
697 
698  from = vlib_frame_vector_args (frame);
699  n_left_from = n_packets;
700  next_index = node->cached_next_index;
701 
702  if (node->flags & VLIB_NODE_FLAG_TRACE)
703  vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors,
704  /* stride */ 1,
705  sizeof (icmp6_input_trace_t));
706 
707  option_type =
708  (is_solicitation
709  ? ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address
710  : ICMP6_NEIGHBOR_DISCOVERY_OPTION_target_link_layer_address);
711  n_advertisements_sent = 0;
712 
713  while (n_left_from > 0)
714  {
715  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
716 
717  while (n_left_from > 0 && n_left_to_next > 0)
718  {
719  vlib_buffer_t * p0;
720  ip6_header_t * ip0;
721  icmp6_neighbor_solicitation_or_advertisement_header_t * h0;
722  icmp6_neighbor_discovery_ethernet_link_layer_address_option_t * o0;
723  u32 bi0, options_len0, sw_if_index0, next0, error0;
724  u32 ip6_sadd_link_local, ip6_sadd_unspecified;
725  int is_rewrite0;
726  u32 ni0;
727 
728  bi0 = to_next[0] = from[0];
729 
730  from += 1;
731  to_next += 1;
732  n_left_from -= 1;
733  n_left_to_next -= 1;
734 
735  p0 = vlib_get_buffer (vm, bi0);
736  ip0 = vlib_buffer_get_current (p0);
737  h0 = ip6_next_header (ip0);
738  options_len0 = clib_net_to_host_u16 (ip0->payload_length) - sizeof (h0[0]);
739 
740  error0 = ICMP6_ERROR_NONE;
741  sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX];
742  ip6_sadd_link_local = ip6_address_is_link_local_unicast(&ip0->src_address);
743  ip6_sadd_unspecified = ip6_address_is_unspecified (&ip0->src_address);
744 
745  /* Check that source address is unspecified, link-local or else on-link. */
746  if (!ip6_sadd_unspecified && !ip6_sadd_link_local)
747  {
748  u32 src_adj_index0 = ip6_src_lookup_for_packet (im, p0, ip0);
749  ip_adjacency_t * adj0 = ip_get_adjacency (&im->lookup_main, src_adj_index0);
750 
751  /* Allow all realistic-looking rewrite adjacencies to pass */
752  ni0 = adj0->lookup_next_index;
753  is_rewrite0 = (ni0 >= IP_LOOKUP_NEXT_ARP) &&
754  (ni0 < IP_LOOKUP_N_NEXT);
755 
756  error0 = ((adj0->rewrite_header.sw_if_index != sw_if_index0
757  || ! is_rewrite0)
758  ? ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_NOT_ON_LINK
759  : error0);
760  }
761 
762  o0 = (void *) (h0 + 1);
763  o0 = ((options_len0 == 8 && o0->header.type == option_type
764  && o0->header.n_data_u64s == 1) ? o0 : 0);
765 
766  /* If src address unspecified or link local, donot learn neighbor MAC */
767  if (PREDICT_TRUE (error0 == ICMP6_ERROR_NONE && o0 != 0 &&
768  !ip6_sadd_unspecified && !ip6_sadd_link_local))
769  {
771  if (nm->limit_neighbor_cache_size &&
775  vm, sw_if_index0,
776  is_solicitation ? &ip0->src_address : &h0->target_address,
777  o0->ethernet_address, sizeof (o0->ethernet_address), 0);
778  }
779 
780  if (is_solicitation && error0 == ICMP6_ERROR_NONE)
781  {
782  /* Check that target address is one that we know about. */
784  ip6_address_fib_t ip6_af0;
785  void * oldheap;
786 
787  ip6_addr_fib_init (&ip6_af0, &h0->target_address,
789  sw_if_index0));
790 
791  /* Gross kludge, "thank you" MJ, don't even ask */
792  oldheap = clib_mem_set_heap (clib_per_cpu_mheaps[0]);
793  ia0 = ip_get_interface_address (lm, &ip6_af0);
794  clib_mem_set_heap (oldheap);
795  error0 = ia0 == 0 ?
796  ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_UNKNOWN : error0;
797  }
798 
799  if (is_solicitation)
800  next0 = (error0 != ICMP6_ERROR_NONE
803  else
804  {
805  next0 = 0;
806  error0 = error0 == ICMP6_ERROR_NONE ?
807  ICMP6_ERROR_NEIGHBOR_ADVERTISEMENTS_RX : error0;
808  }
809 
810  if (is_solicitation && error0 == ICMP6_ERROR_NONE)
811  {
812  vnet_sw_interface_t * sw_if0;
813  ethernet_interface_t * eth_if0;
814  ethernet_header_t *eth0;
815 
816  /* dst address is either source address or the all-nodes mcast addr */
817  if(!ip6_sadd_unspecified)
818  ip0->dst_address = ip0->src_address;
819  else
821  IP6_MULTICAST_SCOPE_link_local,
822  IP6_MULTICAST_GROUP_ID_all_hosts);
823 
824  ip0->src_address = h0->target_address;
825  ip0->hop_limit = 255;
826  h0->icmp.type = ICMP6_neighbor_advertisement;
827 
828  sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index0);
830  eth_if0 = ethernet_get_interface (&ethernet_main, sw_if0->hw_if_index);
831  if (eth_if0 && o0)
832  {
833  clib_memcpy (o0->ethernet_address, eth_if0->address, 6);
834  o0->header.type =
835  ICMP6_NEIGHBOR_DISCOVERY_OPTION_target_link_layer_address;
836  }
837 
838  h0->advertisement_flags = clib_host_to_net_u32
841 
842  h0->icmp.checksum = 0;
843  h0->icmp.checksum =
844  ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip0,
845  &bogus_length);
846  ASSERT(bogus_length == 0);
847 
848  /* Reuse current MAC header, copy SMAC to DMAC and
849  * interface MAC to SMAC */
851  eth0 = vlib_buffer_get_current(p0);
852  clib_memcpy(eth0->dst_address, eth0->src_address, 6);
853  clib_memcpy(eth0->src_address, eth_if0->address, 6);
854 
855  /* Setup input and output sw_if_index for packet */
856  ASSERT(vnet_buffer(p0)->sw_if_index[VLIB_RX] == sw_if_index0);
857  vnet_buffer(p0)->sw_if_index[VLIB_TX] = sw_if_index0;
858  vnet_buffer(p0)->sw_if_index[VLIB_RX] =
860 
861  n_advertisements_sent++;
862  }
863 
864  p0->error = error_node->errors[error0];
865 
866  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
867  to_next, n_left_to_next,
868  bi0, next0);
869  }
870 
871  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
872  }
873 
874  /* Account for advertisements sent. */
875  vlib_error_count (vm, error_node->node_index, ICMP6_ERROR_NEIGHBOR_ADVERTISEMENTS_TX, n_advertisements_sent);
876 
877  return frame->n_vectors;
878 }
879 
880 /* for "syslogging" - use elog for now */
881 #define foreach_log_level \
882  _ (DEBUG, "DEBUG") \
883  _ (INFO, "INFORMATION") \
884  _ (NOTICE, "NOTICE") \
885  _ (WARNING, "WARNING") \
886  _ (ERR, "ERROR") \
887  _ (CRIT, "CRITICAL") \
888  _ (ALERT, "ALERT") \
889  _ (EMERG, "EMERGENCY")
890 
891 typedef enum {
892 #define _(f,s) LOG_##f,
894 #undef _
895 } log_level_t;
896 
897 static char * log_level_strings[] = {
898 #define _(f,s) s,
900 #undef _
901 };
902 
903 static int logmask = 1 << LOG_DEBUG;
904 
905 static void
906 ip6_neighbor_syslog(vlib_main_t *vm, int priority, char * fmt, ...)
907 {
908  /* just use elog for now */
909  u8 *what;
910  va_list va;
911 
912  if( (priority > LOG_EMERG) ||
913  !(logmask & (1 << priority)))
914  return;
915 
916  va_start (va, fmt);
917  if(fmt)
918  {
919  what = va_format (0, fmt, &va);
920 
921  ELOG_TYPE_DECLARE (e) = {
922  .format = "ip6 nd: (%s): %s",
923  .format_args = "T4T4",
924  };
925  struct { u32 s[2]; } * ed;
926  ed = ELOG_DATA (&vm->elog_main, e);
927  ed->s[0] = elog_string(&vm->elog_main, log_level_strings[priority]);
928  ed->s[1] = elog_string(&vm->elog_main, (char *)what);
929  }
930  va_end (va);
931  return;
932 }
933 
934 /* ipv6 neighbor discovery - router advertisements */
935 typedef enum {
941 
944  vlib_node_runtime_t * node,
945  vlib_frame_t * frame)
946 {
947  vnet_main_t * vnm = vnet_get_main();
948  ip6_main_t * im = &ip6_main;
950  uword n_packets = frame->n_vectors;
951  u32 * from, * to_next;
952  u32 n_left_from, n_left_to_next, next_index;
953  u32 n_advertisements_sent = 0;
954  int bogus_length;
955 
957 
959 
960  from = vlib_frame_vector_args (frame);
961  n_left_from = n_packets;
962  next_index = node->cached_next_index;
963 
964  if (node->flags & VLIB_NODE_FLAG_TRACE)
965  vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors,
966  /* stride */ 1,
967  sizeof (icmp6_input_trace_t));
968 
969  /* source may append his LL address */
970  option_type = ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address;
971 
972  while (n_left_from > 0)
973  {
974  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
975 
976  while (n_left_from > 0 && n_left_to_next > 0)
977  {
978  vlib_buffer_t * p0;
979  ip6_header_t * ip0;
980  ip6_radv_t *radv_info = 0;
981 
982  icmp6_neighbor_discovery_header_t * h0;
983  icmp6_neighbor_discovery_ethernet_link_layer_address_option_t * o0;
984 
985  u32 bi0, options_len0, sw_if_index0, next0, error0;
986  u32 is_solicitation = 1, is_dropped = 0;
987  u32 is_unspecified, is_link_local;
988 
989  bi0 = to_next[0] = from[0];
990 
991  from += 1;
992  to_next += 1;
993  n_left_from -= 1;
994  n_left_to_next -= 1;
995 
996  p0 = vlib_get_buffer (vm, bi0);
997  ip0 = vlib_buffer_get_current (p0);
998  h0 = ip6_next_header (ip0);
999  options_len0 = clib_net_to_host_u16 (ip0->payload_length) - sizeof (h0[0]);
1000  is_unspecified = ip6_address_is_unspecified (&ip0->src_address);
1001  is_link_local = ip6_address_is_link_local_unicast (&ip0->src_address);
1002 
1003  error0 = ICMP6_ERROR_NONE;
1004  sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX];
1005 
1006  /* check if solicitation (not from nd_timer node) */
1008  is_solicitation = 0;
1009 
1010  /* Check that source address is unspecified, link-local or else on-link. */
1011  if (!is_unspecified && !is_link_local)
1012  {
1013  u32 src_adj_index0 = ip6_src_lookup_for_packet (im, p0, ip0);
1014  ip_adjacency_t * adj0 = ip_get_adjacency (&im->lookup_main, src_adj_index0);
1015 
1016  error0 = ((adj0->rewrite_header.sw_if_index != sw_if_index0
1019  ? ICMP6_ERROR_ROUTER_SOLICITATION_SOURCE_NOT_ON_LINK
1020  : error0);
1021  }
1022 
1023  /* check for source LL option and process */
1024  o0 = (void *) (h0 + 1);
1025  o0 = ((options_len0 == 8
1026  && o0->header.type == option_type
1027  && o0->header.n_data_u64s == 1)
1028  ? o0
1029  : 0);
1030 
1031  /* if src address unspecified IGNORE any options */
1032  if (PREDICT_TRUE (error0 == ICMP6_ERROR_NONE && o0 != 0 &&
1033  !is_unspecified && !is_link_local)) {
1035  if (nm->limit_neighbor_cache_size &&
1038 
1039  vnet_set_ip6_ethernet_neighbor (vm, sw_if_index0,
1040  &ip0->src_address,
1041  o0->ethernet_address,
1042  sizeof (o0->ethernet_address), 0);
1043  }
1044 
1045  /* default is to drop */
1047 
1048  if (error0 == ICMP6_ERROR_NONE)
1049  {
1050  vnet_sw_interface_t * sw_if0;
1051  ethernet_interface_t * eth_if0;
1052  u32 adj_index0;
1053 
1054  sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index0);
1056  eth_if0 = ethernet_get_interface (&ethernet_main, sw_if0->hw_if_index);
1057 
1058  /* only support ethernet interface type for now */
1059  error0 = (!eth_if0) ? ICMP6_ERROR_ROUTER_SOLICITATION_UNSUPPORTED_INTF : error0;
1060 
1061  if (error0 == ICMP6_ERROR_NONE)
1062  {
1063  u32 ri;
1064 
1065  /* adjust the sizeof the buffer to just include the ipv6 header */
1066  p0->current_length -= (options_len0 + sizeof(icmp6_neighbor_discovery_header_t));
1067 
1068  /* look up the radv_t information for this interface */
1070 
1071  ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index0];
1072 
1073  if(ri != ~0)
1074  radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
1075 
1076  error0 = ((!radv_info) ? ICMP6_ERROR_ROUTER_SOLICITATION_RADV_NOT_CONFIG : error0);
1077 
1078  if (error0 == ICMP6_ERROR_NONE)
1079  {
1080  f64 now = vlib_time_now (vm);
1081 
1082  /* for solicited adverts - need to rate limit */
1083  if(is_solicitation)
1084  {
1085  if( (now - radv_info->last_radv_time) < MIN_DELAY_BETWEEN_RAS )
1086  is_dropped = 1;
1087  else
1088  radv_info->last_radv_time = now;
1089  }
1090 
1091  /* send now */
1092  icmp6_router_advertisement_header_t rh;
1093 
1094  rh.icmp.type = ICMP6_router_advertisement;
1095  rh.icmp.code = 0;
1096  rh.icmp.checksum = 0;
1097 
1098  rh.current_hop_limit = radv_info->curr_hop_limit;
1099  rh.router_lifetime_in_sec = clib_host_to_net_u16(radv_info->adv_router_lifetime_in_sec);
1100  rh.time_in_msec_between_retransmitted_neighbor_solicitations =
1101  clib_host_to_net_u32(radv_info->adv_time_in_msec_between_retransmitted_neighbor_solicitations);
1102  rh.neighbor_reachable_time_in_msec =
1103  clib_host_to_net_u32(radv_info->adv_neighbor_reachable_time_in_msec);
1104 
1106  rh.flags |= ( (radv_info->adv_other_flag) ? ICMP6_ROUTER_DISCOVERY_FLAG_OTHER_CONFIG_VIA_DHCP : 0);
1107 
1108 
1109  u16 payload_length = sizeof(icmp6_router_advertisement_header_t);
1110 
1112  p0->free_list_index,
1113  bi0,
1114  (void *)&rh, sizeof(icmp6_router_advertisement_header_t));
1115 
1116  if(radv_info->adv_link_layer_address)
1117  {
1118  icmp6_neighbor_discovery_ethernet_link_layer_address_option_t h;
1119 
1120  h.header.type = ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address;
1121  h.header.n_data_u64s = 1;
1122 
1123  /* copy ll address */
1124  clib_memcpy(&h.ethernet_address[0], eth_if0->address, 6);
1125 
1127  p0->free_list_index,
1128  bi0,
1129  (void *)&h, sizeof(icmp6_neighbor_discovery_ethernet_link_layer_address_option_t));
1130 
1131  payload_length += sizeof(icmp6_neighbor_discovery_ethernet_link_layer_address_option_t);
1132  }
1133 
1134  /* add MTU option */
1135  if(radv_info->adv_link_mtu)
1136  {
1137  icmp6_neighbor_discovery_mtu_option_t h;
1138 
1139  h.unused = 0;
1140  h.mtu = clib_host_to_net_u32(radv_info->adv_link_mtu);
1141  h.header.type = ICMP6_NEIGHBOR_DISCOVERY_OPTION_mtu;
1142  h.header.n_data_u64s = 1;
1143 
1144  payload_length += sizeof( icmp6_neighbor_discovery_mtu_option_t);
1145 
1147  p0->free_list_index,
1148  bi0,
1149  (void *)&h, sizeof(icmp6_neighbor_discovery_mtu_option_t));
1150  }
1151 
1152  /* add advertised prefix options */
1153  ip6_radv_prefix_t *pr_info;
1154 
1155  pool_foreach (pr_info, radv_info->adv_prefixes_pool, ({
1156 
1157  if(pr_info->enabled &&
1158  (!pr_info->decrement_lifetime_flag || (pr_info->pref_lifetime_expires >0)))
1159  {
1160  /* advertise this prefix */
1161  icmp6_neighbor_discovery_prefix_information_option_t h;
1162 
1163  h.header.type = ICMP6_NEIGHBOR_DISCOVERY_OPTION_prefix_information;
1164  h.header.n_data_u64s = (sizeof(icmp6_neighbor_discovery_prefix_information_option_t) >> 3);
1165 
1166  h.dst_address_length = pr_info->prefix_len;
1167 
1168  h.flags = (pr_info->adv_on_link_flag) ? ICMP6_NEIGHBOR_DISCOVERY_PREFIX_INFORMATION_FLAG_ON_LINK : 0;
1169  h.flags |= (pr_info->adv_autonomous_flag) ? ICMP6_NEIGHBOR_DISCOVERY_PREFIX_INFORMATION_AUTO : 0;
1170 
1171  if(radv_info->cease_radv && pr_info->deprecated_prefix_flag)
1172  {
1173  h.valid_time = clib_host_to_net_u32(MIN_ADV_VALID_LIFETIME);
1174  h.preferred_time = 0;
1175  }
1176  else
1177  {
1178  if(pr_info->decrement_lifetime_flag)
1179  {
1180  pr_info->adv_valid_lifetime_in_secs = ((pr_info->valid_lifetime_expires > now)) ?
1181  (pr_info->valid_lifetime_expires - now) : 0;
1182 
1183  pr_info->adv_pref_lifetime_in_secs = ((pr_info->pref_lifetime_expires > now)) ?
1184  (pr_info->pref_lifetime_expires - now) : 0;
1185  }
1186 
1187  h.valid_time = clib_host_to_net_u32(pr_info->adv_valid_lifetime_in_secs);
1188  h.preferred_time = clib_host_to_net_u32(pr_info->adv_pref_lifetime_in_secs) ;
1189  }
1190  h.unused = 0;
1191 
1192  clib_memcpy(&h.dst_address, &pr_info->prefix, sizeof(ip6_address_t));
1193 
1194  payload_length += sizeof( icmp6_neighbor_discovery_prefix_information_option_t);
1195 
1196  vlib_buffer_add_data (vm,
1197  p0->free_list_index,
1198  bi0,
1199  (void *)&h, sizeof(icmp6_neighbor_discovery_prefix_information_option_t));
1200 
1201  }
1202  }));
1203 
1204  /* add additional options before here */
1205 
1206  /* finish building the router advertisement... */
1207  if(!is_unspecified && radv_info->send_unicast)
1208  {
1209  ip0->dst_address = ip0->src_address;
1210  }
1211  else
1212  {
1213  /* target address is all-nodes mcast addr */
1215  IP6_MULTICAST_SCOPE_link_local,
1216  IP6_MULTICAST_GROUP_ID_all_hosts);
1217  }
1218 
1219  /* source address MUST be the link-local address */
1220  ip0->src_address = radv_info->link_local_address;
1221 
1222  ip0->hop_limit = 255;
1223  ip0->payload_length = clib_host_to_net_u16 (payload_length);
1224 
1225  icmp6_router_advertisement_header_t * rh0 = (icmp6_router_advertisement_header_t *)(ip0 + 1);
1226  rh0->icmp.checksum =
1227  ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip0,
1228  &bogus_length);
1229  ASSERT(bogus_length == 0);
1230 
1231  /* setup output if and adjacency */
1232  vnet_buffer (p0)->sw_if_index[VLIB_RX] =
1234 
1235  if (is_solicitation)
1236  {
1237  ethernet_header_t *eth0;
1238  /* Reuse current MAC header, copy SMAC to DMAC and
1239  * interface MAC to SMAC */
1240  vlib_buffer_reset (p0);
1241  eth0 = vlib_buffer_get_current(p0);
1242  clib_memcpy(eth0->dst_address, eth0->src_address, 6);
1243  clib_memcpy(eth0->src_address, eth_if0->address, 6);
1244  next0 = is_dropped ?
1246  vnet_buffer(p0)->sw_if_index[VLIB_TX] = sw_if_index0;
1247  }
1248  else
1249  {
1250  adj_index0 = radv_info->all_nodes_adj_index;
1251  if (adj_index0 == 0)
1252  error0 = ICMP6_ERROR_DST_LOOKUP_MISS;
1253  else
1254  {
1255  ip_adjacency_t * adj0 = ip_get_adjacency (&im->lookup_main, adj_index0);
1256  error0 =
1257  ((adj0->rewrite_header.sw_if_index != sw_if_index0
1259  ? ICMP6_ERROR_ROUTER_SOLICITATION_DEST_UNKNOWN
1260  : error0);
1261  next0 = is_dropped ?
1263  vnet_buffer (p0)->ip.adj_index[VLIB_RX] = adj_index0;
1264  }
1265  }
1266 
1267  radv_info->n_solicitations_dropped += is_dropped;
1268  radv_info->n_solicitations_rcvd += is_solicitation;
1269 
1270  if((error0 == ICMP6_ERROR_NONE) && !is_dropped)
1271  {
1272  radv_info->n_advertisements_sent++;
1273  n_advertisements_sent++;
1274  }
1275  }
1276  }
1277  }
1278 
1279  p0->error = error_node->errors[error0];
1280 
1281  if(error0 != ICMP6_ERROR_NONE)
1282  vlib_error_count (vm, error_node->node_index, error0, 1);
1283 
1284  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1285  to_next, n_left_to_next,
1286  bi0, next0);
1287 
1288  }
1289 
1290  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1291  }
1292 
1293  /* Account for router advertisements sent. */
1294  vlib_error_count (vm, error_node->node_index, ICMP6_ERROR_ROUTER_ADVERTISEMENTS_TX, n_advertisements_sent);
1295 
1296  return frame->n_vectors;
1297 }
1298 
1299  /* validate advertised info for consistancy (see RFC-4861 section 6.2.7) - log any inconsistencies, packet will always be dropped */
1302  vlib_node_runtime_t * node,
1303  vlib_frame_t * frame)
1304 {
1305  vnet_main_t * vnm = vnet_get_main();
1307  uword n_packets = frame->n_vectors;
1308  u32 * from, * to_next;
1309  u32 n_left_from, n_left_to_next, next_index;
1310  u32 n_advertisements_rcvd = 0;
1311 
1313 
1314  from = vlib_frame_vector_args (frame);
1315  n_left_from = n_packets;
1316  next_index = node->cached_next_index;
1317 
1318  if (node->flags & VLIB_NODE_FLAG_TRACE)
1319  vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors,
1320  /* stride */ 1,
1321  sizeof (icmp6_input_trace_t));
1322 
1323  while (n_left_from > 0)
1324  {
1325  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1326 
1327  while (n_left_from > 0 && n_left_to_next > 0)
1328  {
1329  vlib_buffer_t * p0;
1330  ip6_header_t * ip0;
1331  ip6_radv_t *radv_info = 0;
1332  icmp6_router_advertisement_header_t * h0;
1333  u32 bi0, options_len0, sw_if_index0, next0, error0;
1334 
1335  bi0 = to_next[0] = from[0];
1336 
1337  from += 1;
1338  to_next += 1;
1339  n_left_from -= 1;
1340  n_left_to_next -= 1;
1341 
1342  p0 = vlib_get_buffer (vm, bi0);
1343  ip0 = vlib_buffer_get_current (p0);
1344  h0 = ip6_next_header (ip0);
1345  options_len0 = clib_net_to_host_u16 (ip0->payload_length) - sizeof (h0[0]);
1346 
1347  error0 = ICMP6_ERROR_NONE;
1348  sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX];
1349 
1350  /* Check that source address is link-local*/
1351  error0 = (!ip6_address_is_link_local_unicast (&ip0->src_address)) ?
1352  ICMP6_ERROR_ROUTER_ADVERTISEMENT_SOURCE_NOT_LINK_LOCAL : error0;
1353 
1354  /* default is to drop */
1356 
1357  n_advertisements_rcvd++;
1358 
1359  if (error0 == ICMP6_ERROR_NONE)
1360  {
1361  vnet_sw_interface_t * sw_if0;
1362  ethernet_interface_t * eth_if0;
1363 
1364  sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index0);
1366  eth_if0 = ethernet_get_interface (&ethernet_main, sw_if0->hw_if_index);
1367 
1368  /* only support ethernet interface type for now */
1369  error0 = (!eth_if0) ? ICMP6_ERROR_ROUTER_SOLICITATION_UNSUPPORTED_INTF : error0;
1370 
1371  if (error0 == ICMP6_ERROR_NONE)
1372  {
1373  u32 ri;
1374 
1375  /* look up the radv_t information for this interface */
1377 
1378  ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index0];
1379 
1380  if(ri != ~0)
1381  radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
1382 
1383  error0 = ((!radv_info) ? ICMP6_ERROR_ROUTER_SOLICITATION_RADV_NOT_CONFIG : error0);
1384 
1385  if (error0 == ICMP6_ERROR_NONE)
1386  {
1387  /* validate advertised information */
1388  if((h0->current_hop_limit && radv_info->curr_hop_limit) &&
1389  (h0->current_hop_limit != radv_info->curr_hop_limit))
1390  {
1391  ip6_neighbor_syslog(vm, LOG_WARNING,
1392  "our AdvCurHopLimit on %U doesn't agree with %U",
1393  format_vnet_sw_if_index_name, vnm, sw_if_index0, format_ip6_address, &ip0->src_address);
1394  }
1395 
1397  radv_info->adv_managed_flag)
1398  {
1399  ip6_neighbor_syslog(vm, LOG_WARNING,
1400  "our AdvManagedFlag on %U doesn't agree with %U",
1401  format_vnet_sw_if_index_name, vnm, sw_if_index0, format_ip6_address, &ip0->src_address);
1402  }
1403 
1405  radv_info->adv_other_flag)
1406  {
1407  ip6_neighbor_syslog(vm, LOG_WARNING,
1408  "our AdvOtherConfigFlag on %U doesn't agree with %U",
1409  format_vnet_sw_if_index_name, vnm, sw_if_index0, format_ip6_address, &ip0->src_address);
1410  }
1411 
1412  if((h0->time_in_msec_between_retransmitted_neighbor_solicitations &&
1414  (h0->time_in_msec_between_retransmitted_neighbor_solicitations !=
1415  clib_host_to_net_u32(radv_info->adv_time_in_msec_between_retransmitted_neighbor_solicitations)))
1416  {
1417  ip6_neighbor_syslog(vm, LOG_WARNING,
1418  "our AdvRetransTimer on %U doesn't agree with %U",
1419  format_vnet_sw_if_index_name, vnm, sw_if_index0, format_ip6_address, &ip0->src_address);
1420  }
1421 
1422  if((h0->neighbor_reachable_time_in_msec &&
1424  (h0->neighbor_reachable_time_in_msec !=
1425  clib_host_to_net_u32(radv_info->adv_neighbor_reachable_time_in_msec)))
1426  {
1427  ip6_neighbor_syslog(vm, LOG_WARNING,
1428  "our AdvReachableTime on %U doesn't agree with %U",
1429  format_vnet_sw_if_index_name, vnm, sw_if_index0, format_ip6_address, &ip0->src_address);
1430  }
1431 
1432  /* check for MTU or prefix options or .. */
1433  u8 * opt_hdr = (u8 *)(h0 + 1);
1434  while( options_len0 > 0)
1435  {
1436  icmp6_neighbor_discovery_option_header_t *o0 = ( icmp6_neighbor_discovery_option_header_t *)opt_hdr;
1437  int opt_len = o0->n_data_u64s << 3;
1438  icmp6_neighbor_discovery_option_type_t option_type = o0->type;
1439 
1440  if(options_len0 < 2)
1441  {
1442  ip6_neighbor_syslog(vm, LOG_ERR,
1443  "malformed RA packet on %U from %U",
1444  format_vnet_sw_if_index_name, vnm, sw_if_index0, format_ip6_address, &ip0->src_address);
1445  break;
1446  }
1447 
1448  if(opt_len == 0)
1449  {
1450  ip6_neighbor_syslog(vm, LOG_ERR,
1451  " zero length option in RA on %U from %U",
1452  format_vnet_sw_if_index_name, vnm, sw_if_index0, format_ip6_address, &ip0->src_address);
1453  break;
1454  }
1455  else if( opt_len > options_len0)
1456  {
1457  ip6_neighbor_syslog(vm, LOG_ERR,
1458  "option length in RA packet greater than total length on %U from %U",
1459  format_vnet_sw_if_index_name, vnm, sw_if_index0, format_ip6_address, &ip0->src_address);
1460  break;
1461  }
1462 
1463  options_len0 -= opt_len;
1464  opt_hdr += opt_len;
1465 
1466  switch(option_type)
1467  {
1468  case ICMP6_NEIGHBOR_DISCOVERY_OPTION_mtu:
1469  {
1470  icmp6_neighbor_discovery_mtu_option_t *h =
1471  (icmp6_neighbor_discovery_mtu_option_t *)(o0);
1472 
1473  if(opt_len < sizeof(*h))
1474  break;
1475 
1476  if((h->mtu && radv_info->adv_link_mtu) &&
1477  (h->mtu != clib_host_to_net_u32(radv_info->adv_link_mtu)))
1478  {
1479  ip6_neighbor_syslog(vm, LOG_WARNING,
1480  "our AdvLinkMTU on %U doesn't agree with %U",
1481  format_vnet_sw_if_index_name, vnm, sw_if_index0, format_ip6_address, &ip0->src_address);
1482  }
1483  }
1484  break;
1485 
1486  case ICMP6_NEIGHBOR_DISCOVERY_OPTION_prefix_information:
1487  {
1488  icmp6_neighbor_discovery_prefix_information_option_t *h =
1489  (icmp6_neighbor_discovery_prefix_information_option_t *)(o0);
1490 
1491  /* validate advertised prefix options */
1492  ip6_radv_prefix_t *pr_info;
1493  u32 preferred, valid;
1494 
1495  if(opt_len < sizeof(*h))
1496  break;
1497 
1498  preferred = clib_net_to_host_u32(h->preferred_time);
1499  valid = clib_net_to_host_u32(h->valid_time);
1500 
1501  /* look for matching prefix - if we our advertising it, it better be consistant */
1502  pool_foreach (pr_info, radv_info->adv_prefixes_pool, ({
1503 
1504  ip6_address_t mask;
1505  ip6_address_mask_from_width(&mask, pr_info->prefix_len);
1506 
1507  if(pr_info->enabled &&
1508  (pr_info->prefix_len == h->dst_address_length) &&
1509  ip6_address_is_equal_masked (&pr_info->prefix, &h->dst_address, &mask))
1510  {
1511  /* found it */
1512  if(!pr_info->decrement_lifetime_flag &&
1513  valid != pr_info->adv_valid_lifetime_in_secs)
1514  {
1515  ip6_neighbor_syslog(vm, LOG_WARNING,
1516  "our ADV validlifetime on %U for %U does not agree with %U",
1517  format_vnet_sw_if_index_name, vnm, sw_if_index0,format_ip6_address, &pr_info->prefix,
1518  format_ip6_address, &h->dst_address);
1519  }
1520  if(!pr_info->decrement_lifetime_flag &&
1521  preferred != pr_info->adv_pref_lifetime_in_secs)
1522  {
1523  ip6_neighbor_syslog(vm, LOG_WARNING,
1524  "our ADV preferredlifetime on %U for %U does not agree with %U",
1525  format_vnet_sw_if_index_name, vnm, sw_if_index0,format_ip6_address, &pr_info->prefix,
1526  format_ip6_address, &h->dst_address);
1527  }
1528  }
1529  break;
1530  }));
1531  break;
1532  }
1533  default:
1534  /* skip this one */
1535  break;
1536  }
1537  }
1538  }
1539  }
1540  }
1541 
1542  p0->error = error_node->errors[error0];
1543 
1544  if(error0 != ICMP6_ERROR_NONE)
1545  vlib_error_count (vm, error_node->node_index, error0, 1);
1546 
1547  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1548  to_next, n_left_to_next,
1549  bi0, next0);
1550  }
1551 
1552  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1553  }
1554 
1555  /* Account for router advertisements sent. */
1556  vlib_error_count (vm, error_node->node_index, ICMP6_ERROR_ROUTER_ADVERTISEMENTS_RX, n_advertisements_rcvd);
1557 
1558  return frame->n_vectors;
1559 }
1560 
1561 /* create and initialize router advertisement parameters with default values for this intfc */
1562 static u32
1564  u32 sw_if_index,
1565  u32 is_add)
1566 {
1567  ip6_main_t * im = &ip6_main;
1569  ip_lookup_main_t * lm = &im->lookup_main;
1570  ip6_radv_t * a= 0;
1571  u32 ri = ~0;;
1572  vnet_sw_interface_t * sw_if0;
1573  ethernet_interface_t * eth_if0 = 0;
1574 
1575  /* lookup radv container - ethernet interfaces only */
1576  sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index);
1577  if(sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE)
1578  eth_if0 = ethernet_get_interface (&ethernet_main, sw_if0->hw_if_index);
1579 
1580  if(!eth_if0)
1581  return ri;
1582 
1584  ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
1585 
1586  if(ri != ~0)
1587  {
1588  a = pool_elt_at_index (nm->if_radv_pool, ri);
1589 
1590  if(!is_add)
1591  {
1592  u32 i, * to_delete = 0;
1593  ip6_radv_prefix_t *p;
1594  ip6_mldp_group_t *m;
1595 
1596  /* remove adjacencies */
1600 
1601  /* clean up prefix_pool */
1602  pool_foreach (p, a->adv_prefixes_pool, ({
1603  vec_add1 (to_delete, p - a->adv_prefixes_pool);
1604  }));
1605 
1606  for (i = 0; i < vec_len (to_delete); i++)
1607  {
1608  p = pool_elt_at_index (a->adv_prefixes_pool, to_delete[i]);
1610  pool_put (a->adv_prefixes_pool, p);
1611  }
1612 
1613  vec_free (to_delete);
1614  to_delete = 0;
1615 
1616  /* clean up mldp group pool */
1617  pool_foreach (m, a->mldp_group_pool, ({
1618  vec_add1 (to_delete, m - a->mldp_group_pool);
1619  }));
1620 
1621  for (i = 0; i < vec_len (to_delete); i++)
1622  {
1623  m = pool_elt_at_index (a->mldp_group_pool, to_delete[i]);
1625  pool_put (a->mldp_group_pool, m);
1626  }
1627 
1628  vec_free (to_delete);
1629 
1630  pool_put (nm->if_radv_pool, a);
1631  nm->if_radv_pool_index_by_sw_if_index[sw_if_index] = ~0;
1632  ri = ~0;
1633  }
1634  }
1635  else
1636  {
1637  if(is_add)
1638  {
1639  vnet_hw_interface_t * hw_if0;
1640 
1641  hw_if0 = vnet_get_sup_hw_interface (vnm, sw_if_index);
1642 
1643  pool_get (nm->if_radv_pool, a);
1644 
1645  ri = a - nm->if_radv_pool;
1646  nm->if_radv_pool_index_by_sw_if_index[sw_if_index] = ri;
1647 
1648  /* initialize default values (most of which are zero) */
1649  memset (a, 0, sizeof (a[0]));
1650 
1651  a->sw_if_index = sw_if_index;
1652  a->fib_index = ~0;
1657 
1658  a->adv_link_layer_address = 1; /* send ll address source address option */
1659 
1663  a->seed = random_default_seed();
1664 
1665  /* for generating random interface ids */
1666  a->randomizer = 0x1119194911191949;
1667  a->randomizer = random_u64 ((u32 *)&a->randomizer);
1668 
1672 
1673  /* deafult is to send */
1674  a->send_radv = 1;
1675 
1676  /* fill in radv_info for this interface that will be needed later */
1678 
1679  clib_memcpy (a->link_layer_address, eth_if0->address, 6);
1680 
1681  /* fill in default link-local address (this may be overridden) */
1683  a->link_local_prefix_len = 64;
1684 
1685  mhash_init (&a->address_to_prefix_index, sizeof (uword), sizeof (ip6_address_t));
1686  mhash_init (&a->address_to_mldp_index, sizeof (uword), sizeof (ip6_address_t));
1687 
1688  {
1689  ip_adjacency_t *adj;
1690  u8 link_layer_address[6] =
1691  {0x33, 0x33, 0x00, 0x00, 0x00, IP6_MULTICAST_GROUP_ID_all_hosts};
1692 
1693  adj = ip_add_adjacency (lm, /* template */ 0, /* block size */ 1,
1694  &a->all_nodes_adj_index);
1695 
1697  adj->if_address_index = ~0;
1698 
1700  (vnm,
1701  VNET_L3_PACKET_TYPE_IP6,
1702  sw_if_index,
1703  ip6_rewrite_node.index,
1704  link_layer_address,
1705  &adj->rewrite_header,
1706  sizeof (adj->rewrite_data));
1707  }
1708 
1709  {
1710  ip_adjacency_t *adj;
1711  u8 link_layer_address[6] =
1712  {0x33, 0x33, 0x00, 0x00, 0x00, IP6_MULTICAST_GROUP_ID_all_routers};
1713 
1714  adj = ip_add_adjacency (lm, /* template */ 0, /* block size */ 1,
1715  &a->all_routers_adj_index);
1716 
1718  adj->if_address_index = ~0;
1719 
1721  (vnm,
1722  VNET_L3_PACKET_TYPE_IP6,
1723  sw_if_index,
1724  ip6_rewrite_node.index,
1725  link_layer_address,
1726  &adj->rewrite_header,
1727  sizeof (adj->rewrite_data));
1728  }
1729 
1730  {
1731  ip_adjacency_t *adj;
1732  u8 link_layer_address[6] =
1733  {0x33, 0x33, 0x00, 0x00, 0x00, IP6_MULTICAST_GROUP_ID_mldv2_routers};
1734 
1735  adj = ip_add_adjacency (lm, /* template */ 0, /* block size */ 1,
1737 
1739  adj->if_address_index = ~0;
1740 
1742  (vnm,
1743  VNET_L3_PACKET_TYPE_IP6,
1744  sw_if_index,
1745  ip6_rewrite_node.index,
1746  link_layer_address,
1747  &adj->rewrite_header,
1748  sizeof (adj->rewrite_data));
1749  }
1750 
1751  /* add multicast groups we will always be reporting */
1753  ip6_mldp_group_t *mcast_group_info;
1754 
1756  IP6_MULTICAST_SCOPE_link_local,
1757  IP6_MULTICAST_GROUP_ID_all_hosts);
1758 
1759  /* lookup mldp info for this interface */
1760 
1761  uword * p = mhash_get (&a->address_to_mldp_index, &addr);
1762  mcast_group_info = p ? pool_elt_at_index (a->mldp_group_pool, p[0]) : 0;
1763 
1764  /* add address */
1765  if(!mcast_group_info)
1766  {
1767  /* add */
1768  u32 mi;
1769  pool_get (a->mldp_group_pool, mcast_group_info);
1770 
1771  mi = mcast_group_info - a->mldp_group_pool;
1772  mhash_set (&a->address_to_mldp_index, &addr, mi, /* old_value */ 0);
1773 
1774  mcast_group_info->type = 4;
1775  mcast_group_info->mcast_source_address_pool = 0;
1776  mcast_group_info->num_sources = 0;
1777  clib_memcpy(&mcast_group_info->mcast_address, &addr, sizeof(ip6_address_t));
1778  }
1779 
1781  IP6_MULTICAST_SCOPE_link_local,
1782  IP6_MULTICAST_GROUP_ID_all_routers);
1783 
1784  p = mhash_get (&a->address_to_mldp_index, &addr);
1785  mcast_group_info = p ? pool_elt_at_index (a->mldp_group_pool, p[0]) : 0;
1786 
1787  if(!mcast_group_info)
1788  {
1789  /* add */
1790  u32 mi;
1791  pool_get (a->mldp_group_pool, mcast_group_info);
1792 
1793  mi = mcast_group_info - a->mldp_group_pool;
1794  mhash_set (&a->address_to_mldp_index, &addr, mi, /* old_value */ 0);
1795 
1796  mcast_group_info->type = 4;
1797  mcast_group_info->mcast_source_address_pool = 0;
1798  mcast_group_info->num_sources = 0;
1799  clib_memcpy(&mcast_group_info->mcast_address, &addr, sizeof(ip6_address_t));
1800  }
1801 
1803  IP6_MULTICAST_SCOPE_link_local,
1804  IP6_MULTICAST_GROUP_ID_mldv2_routers);
1805 
1806  p = mhash_get (&a->address_to_mldp_index, &addr);
1807  mcast_group_info = p ? pool_elt_at_index (a->mldp_group_pool, p[0]) : 0;
1808 
1809  if(!mcast_group_info)
1810  {
1811  /* add */
1812  u32 mi;
1813  pool_get (a->mldp_group_pool, mcast_group_info);
1814 
1815  mi = mcast_group_info - a->mldp_group_pool;
1816  mhash_set (&a->address_to_mldp_index, &addr, mi, /* old_value */ 0);
1817 
1818  mcast_group_info->type = 4;
1819  mcast_group_info->mcast_source_address_pool = 0;
1820  mcast_group_info->num_sources = 0;
1821  clib_memcpy(&mcast_group_info->mcast_address, &addr, sizeof(ip6_address_t));
1822  }
1823  }
1824  }
1825  return ri;
1826 }
1827 
1828 /* send an mldpv2 report */
1829 static void
1831 {
1832  vnet_main_t * vnm = vnet_get_main();
1833  vlib_main_t * vm = vnm->vlib_main;
1835  vnet_sw_interface_t * sw_if0;
1836  ethernet_interface_t * eth_if0;
1837  u32 ri;
1838  int bogus_length;
1839 
1840  ip6_radv_t *radv_info;
1841  u16 payload_length;
1842  vlib_buffer_t * b0;
1843  ip6_header_t * ip0;
1844  u32 * to_next;
1845  vlib_frame_t * f;
1846  u32 bo0;
1847  u32 n_to_alloc = 1;
1848  u32 n_allocated;
1849 
1850  icmp6_multicast_listener_report_header_t *rh0;
1851  icmp6_multicast_listener_report_packet_t *rp0;
1852 
1853  sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index);
1855  eth_if0 = ethernet_get_interface (&ethernet_main, sw_if0->hw_if_index);
1856 
1857  if (!eth_if0 || !vnet_sw_interface_is_admin_up (vnm, sw_if_index))
1858  return;
1859 
1860  /* look up the radv_t information for this interface */
1862 
1863  ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
1864 
1865  if(ri == ~0)
1866  return;
1867 
1868  /* send report now - build a mldpv2 report packet */
1869  n_allocated = vlib_buffer_alloc_from_free_list(vm,
1870  &bo0,
1871  n_to_alloc,
1873  if (PREDICT_FALSE(n_allocated == 0))
1874  {
1875  clib_warning ("buffer allocation failure");
1876  return;
1877  }
1878 
1879  b0 = vlib_get_buffer (vm, bo0);
1880 
1881  /* adjust the sizeof the buffer to just include the ipv6 header */
1882  b0->current_length = sizeof(icmp6_multicast_listener_report_packet_t);
1883 
1884  payload_length = sizeof(icmp6_multicast_listener_report_header_t);
1885 
1886  b0->error = ICMP6_ERROR_NONE;
1887 
1888  rp0 = vlib_buffer_get_current (b0);
1889  ip0 = (ip6_header_t *)&rp0-> ip;
1890  rh0 = (icmp6_multicast_listener_report_header_t *)&rp0-> report_hdr;
1891 
1892  memset (rp0 , 0x0, sizeof (icmp6_multicast_listener_report_packet_t));
1893 
1894  ip0->ip_version_traffic_class_and_flow_label = clib_host_to_net_u32 (0x6 << 28);
1895 
1896  ip0->protocol = IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS;
1897  /* for DEBUG - vnet driver won't seem to emit router alerts */
1898  /* ip0->protocol = IP_PROTOCOL_ICMP6; */
1899  ip0->hop_limit = 1;
1900 
1901  rh0->icmp.type = ICMP6_multicast_listener_report_v2;
1902 
1903  /* source address MUST be the link-local address */
1904  radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
1905  ip0->src_address = radv_info->link_local_address;
1906 
1907  /* destination is all mldpv2 routers */
1909  IP6_MULTICAST_SCOPE_link_local,
1910  IP6_MULTICAST_GROUP_ID_mldv2_routers);
1911 
1912  /* add reports here */
1913  ip6_mldp_group_t *m;
1914  int num_addr_records = 0;
1915  icmp6_multicast_address_record_t rr;
1916 
1917  /* fill in the hop-by-hop extension header (router alert) info */
1918  rh0->ext_hdr.next_hdr = IP_PROTOCOL_ICMP6;
1919  rh0->ext_hdr.n_data_u64s = 0;
1920 
1921  rh0->alert.type = IP6_MLDP_ALERT_TYPE;
1922  rh0->alert.len = 2;
1923  rh0->alert.value = 0;
1924 
1925  rh0->pad.type = 1;
1926  rh0->pad.len = 0;
1927 
1928  rh0->icmp.checksum = 0;
1929 
1930  pool_foreach (m, radv_info->mldp_group_pool, ({
1931 
1932  rr.type = m->type;
1933  rr.aux_data_len_u32s = 0;
1934  rr.num_sources = clib_host_to_net_u16 (m->num_sources);
1935  clib_memcpy(&rr.mcast_addr, &m->mcast_address, sizeof(ip6_address_t));
1936 
1937  num_addr_records++;
1938 
1939  vlib_buffer_add_data (vm,
1940  b0->free_list_index,
1941  bo0,
1942  (void *)&rr, sizeof(icmp6_multicast_address_record_t));
1943 
1944  payload_length += sizeof( icmp6_multicast_address_record_t);
1945  }));
1946 
1947  rh0->rsvd = 0;
1948  rh0->num_addr_records = clib_host_to_net_u16(num_addr_records);
1949 
1950  /* update lengths */
1951  ip0->payload_length = clib_host_to_net_u16 (payload_length);
1952 
1953  rh0->icmp.checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip0,
1954  &bogus_length);
1955  ASSERT(bogus_length == 0);
1956 
1957  /*
1958  * OK to override w/ no regard for actual FIB, because
1959  * ip6-rewrite-local only looks at the adjacency.
1960  */
1961  vnet_buffer (b0)->sw_if_index[VLIB_RX] =
1963 
1964  vnet_buffer (b0)->ip.adj_index[VLIB_RX] =
1965  radv_info->all_mldv2_routers_adj_index;
1966 
1967  vlib_node_t * node = vlib_get_node_by_name (vm, (u8 *) "ip6-rewrite-local");
1968 
1969  f = vlib_get_frame_to_node (vm, node->index);
1970  to_next = vlib_frame_vector_args (f);
1971  to_next[0] = bo0;
1972  f->n_vectors = 1;
1973 
1974  vlib_put_frame_to_node (vm, node->index, f);
1975  return;
1976 }
1977 
1979  .function = icmp6_router_solicitation,
1980  .name = "icmp6-router-solicitation",
1981 
1982  .vector_size = sizeof (u32),
1983 
1984  .format_trace = format_icmp6_input_trace,
1985 
1986  .n_next_nodes = ICMP6_ROUTER_SOLICITATION_N_NEXT,
1987  .next_nodes = {
1988  [ICMP6_ROUTER_SOLICITATION_NEXT_DROP] = "error-drop",
1989  [ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_RW] = "ip6-rewrite-local",
1990  [ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_TX] = "interface-output",
1991  },
1992 };
1993 
1994 /* send a RA or update the timer info etc.. */
1995 static uword
1997  vlib_node_runtime_t * node,
1998  vlib_frame_t * frame)
1999 {
2000  vnet_main_t * vnm = vnet_get_main();
2002  ip6_radv_t *radv_info;
2003  vlib_frame_t * f = 0;
2004  u32 n_this_frame = 0;
2005  u32 n_left_to_next = 0;
2006  u32 * to_next = 0;
2007  u32 bo0;
2008  icmp6_router_solicitation_header_t * h0;
2009  vlib_buffer_t * b0;
2010  f64 now = vlib_time_now (vm);
2011 
2012  /* Interface ip6 radv info list */
2013  pool_foreach (radv_info, nm->if_radv_pool, ({
2014 
2015  if( !vnet_sw_interface_is_admin_up (vnm, radv_info->sw_if_index))
2016  {
2017  radv_info->initial_adverts_sent = radv_info->initial_adverts_count-1;
2018  radv_info->next_multicast_time = now;
2019  radv_info->last_multicast_time = now;
2020  radv_info->last_radv_time = 0;
2021  radv_info->all_routers_mcast = 0;
2022  continue;
2023  }
2024 
2025  /* Make sure that we've joined the all-routers multicast group */
2026  if(!radv_info->all_routers_mcast)
2027  {
2028  /* send MDLP_REPORT_EVENT message */
2029  ip6_neighbor_send_mldpv2_report(radv_info->sw_if_index);
2030  radv_info->all_routers_mcast = 1;
2031  }
2032 
2033  /* is it time to send a multicast RA on this interface? */
2034  if(radv_info->send_radv && (now >= radv_info->next_multicast_time))
2035  {
2036  u32 n_to_alloc = 1;
2037  u32 n_allocated;
2038 
2039  f64 rfn = (radv_info->max_radv_interval - radv_info->min_radv_interval) *
2040  random_f64 (&radv_info->seed) + radv_info->min_radv_interval;
2041 
2042  /* multicast send - compute next multicast send time */
2043  if( radv_info->initial_adverts_sent > 0)
2044  {
2045  radv_info->initial_adverts_sent--;
2046  if(rfn > radv_info-> initial_adverts_interval)
2047  rfn = radv_info-> initial_adverts_interval;
2048 
2049  /* check to see if we are ceasing to send */
2050  if( radv_info->initial_adverts_sent == 0)
2051  if(radv_info->cease_radv)
2052  radv_info->send_radv = 0;
2053  }
2054 
2055  radv_info->next_multicast_time = rfn + now;
2056  radv_info->last_multicast_time = now;
2057 
2058  /* send advert now - build a "solicted" router advert with unspecified source address */
2059  n_allocated = vlib_buffer_alloc_from_free_list(vm,
2060  &bo0,
2061  n_to_alloc,
2063 
2064  if (PREDICT_FALSE(n_allocated == 0))
2065  {
2066  clib_warning ("buffer allocation failure");
2067  continue;
2068  }
2069  b0 = vlib_get_buffer (vm, bo0);
2070  b0->current_length = sizeof( icmp6_router_solicitation_header_t);
2071  b0->error = ICMP6_ERROR_NONE;
2072  vnet_buffer (b0)->sw_if_index[VLIB_RX] = radv_info->sw_if_index;
2073 
2074  h0 = vlib_buffer_get_current (b0);
2075 
2076  memset (h0, 0, sizeof (icmp6_router_solicitation_header_t));
2077 
2078  h0->ip.ip_version_traffic_class_and_flow_label = clib_host_to_net_u32 (0x6 << 28);
2079  h0->ip.payload_length = clib_host_to_net_u16 (sizeof (icmp6_router_solicitation_header_t)
2080  - STRUCT_OFFSET_OF (icmp6_router_solicitation_header_t, neighbor));
2081  h0->ip.protocol = IP_PROTOCOL_ICMP6;
2082  h0->ip.hop_limit = 255;
2083 
2084  /* set src/dst address as "unspecified" this marks this packet as internally generated rather than recieved */
2085  h0->ip.src_address.as_u64[0] = 0;
2086  h0->ip.src_address.as_u64[1] = 0;
2087 
2088  h0->ip.dst_address.as_u64[0] = 0;
2089  h0->ip.dst_address.as_u64[1] = 0;
2090 
2091  h0->neighbor.icmp.type = ICMP6_router_solicitation;
2092 
2093  if (PREDICT_FALSE(f == 0))
2094  {
2096  to_next = vlib_frame_vector_args (f);
2097  n_left_to_next = VLIB_FRAME_SIZE;
2098  n_this_frame = 0;
2099  }
2100 
2101  n_this_frame++;
2102  n_left_to_next--;
2103  to_next[0] = bo0;
2104  to_next += 1;
2105 
2106  if (PREDICT_FALSE(n_left_to_next == 0))
2107  {
2108  f->n_vectors = n_this_frame;
2110  f = 0;
2111  }
2112  }
2113  }));
2114 
2115  if (f)
2116  {
2117  ASSERT(n_this_frame);
2118  f->n_vectors = n_this_frame;
2120  }
2121  return 0;
2122 }
2123 
2124 static uword
2126  vlib_node_runtime_t * node,
2127  vlib_frame_t * frame)
2128 {
2129  uword event_type;
2131 
2132  /* init code here */
2133 
2134  while (1)
2135  {
2136  vlib_process_wait_for_event_or_clock (vm, 1. /* seconds */);
2137 
2138  event_data = vlib_process_get_event_data (vm, &event_type);
2139 
2140  if(!event_data)
2141  {
2142  /* No events found: timer expired. */
2143  /* process interface list and send RAs as appropriate, update timer info */
2144  ip6_neighbor_process_timer_event (vm, node, frame);
2145  }
2146  else
2147  {
2148  switch (event_type) {
2149 
2150  case ICMP6_ND_EVENT_INIT:
2151  break;
2152 
2153  case ~0:
2154  break;
2155 
2156  default:
2157  ASSERT (0);
2158  }
2159 
2160  if (event_data)
2161  _vec_len (event_data) = 0;
2162  }
2163  }
2164  return frame->n_vectors;
2165 }
2166 
2168  .function = icmp6_router_advertisement,
2169  .name = "icmp6-router-advertisement",
2170 
2171  .vector_size = sizeof (u32),
2172 
2173  .format_trace = format_icmp6_input_trace,
2174 
2175  .n_next_nodes = 1,
2176  .next_nodes = {
2177  [0] = "error-drop",
2178  },
2179 };
2180 
2182 
2184  .name = "ip6-icmp-neighbor-discovery-event-process",
2185  .type = VLIB_NODE_TYPE_PROCESS,
2186 };
2187 
2188 static uword
2190  vlib_node_runtime_t * node,
2191  vlib_frame_t * frame)
2192 { return icmp6_neighbor_solicitation_or_advertisement (vm, node, frame, /* is_solicitation */ 1); }
2193 
2194 static uword
2196  vlib_node_runtime_t * node,
2197  vlib_frame_t * frame)
2198 { return icmp6_neighbor_solicitation_or_advertisement (vm, node, frame, /* is_solicitation */ 0); }
2199 
2201  .function = icmp6_neighbor_solicitation,
2202  .name = "icmp6-neighbor-solicitation",
2203 
2204  .vector_size = sizeof (u32),
2205 
2206  .format_trace = format_icmp6_input_trace,
2207 
2208  .n_next_nodes = ICMP6_NEIGHBOR_SOLICITATION_N_NEXT,
2209  .next_nodes = {
2210  [ICMP6_NEIGHBOR_SOLICITATION_NEXT_DROP] = "error-drop",
2211  [ICMP6_NEIGHBOR_SOLICITATION_NEXT_REPLY] = "interface-output",
2212  },
2213 };
2214 
2216  .function = icmp6_neighbor_advertisement,
2217  .name = "icmp6-neighbor-advertisement",
2218 
2219  .vector_size = sizeof (u32),
2220 
2221  .format_trace = format_icmp6_input_trace,
2222 
2223  .n_next_nodes = 1,
2224  .next_nodes = {
2225  [0] = "error-drop",
2226  },
2227 };
2228 
2229 /* API support functions */
2230 int
2232  u8 surpress, u8 managed, u8 other,
2233  u8 ll_option, u8 send_unicast, u8 cease,
2234  u8 use_lifetime, u32 lifetime,
2235  u32 initial_count, u32 initial_interval,
2236  u32 max_interval, u32 min_interval,
2237  u8 is_no)
2238 {
2240  int error;
2241  u32 ri;
2242 
2243  /* look up the radv_t information for this interface */
2245  ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
2246  error = (ri != ~0) ? 0 : VNET_API_ERROR_INVALID_SW_IF_INDEX;
2247 
2248  if(!error)
2249  {
2250 
2251  ip6_radv_t * radv_info;
2252  radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
2253 
2254  if((max_interval != 0) && (min_interval ==0))
2255  min_interval = .75 * max_interval;
2256 
2257  max_interval = (max_interval != 0) ? ( (is_no) ? DEF_MAX_RADV_INTERVAL : max_interval) : radv_info->max_radv_interval;
2258  min_interval = (min_interval != 0) ? ( (is_no) ? DEF_MIN_RADV_INTERVAL : min_interval) : radv_info->min_radv_interval;
2259  lifetime = (use_lifetime != 0) ? ( (is_no) ? DEF_DEF_RTR_LIFETIME : lifetime) : radv_info->adv_router_lifetime_in_sec;
2260 
2261  if(lifetime)
2262  {
2263  if(lifetime > MAX_DEF_RTR_LIFETIME)
2264  lifetime = MAX_DEF_RTR_LIFETIME;
2265 
2266  if(lifetime <= max_interval)
2267  return VNET_API_ERROR_INVALID_VALUE;
2268  }
2269 
2270  if(min_interval != 0)
2271  {
2272  if((min_interval > .75 * max_interval) ||
2273  (min_interval < 3))
2274  return VNET_API_ERROR_INVALID_VALUE;
2275  }
2276 
2277  if((initial_count > MAX_INITIAL_RTR_ADVERTISEMENTS) ||
2278  (initial_interval > MAX_INITIAL_RTR_ADVERT_INTERVAL))
2279  return VNET_API_ERROR_INVALID_VALUE;
2280 
2281  /*
2282  if "flag" is set and is_no is true then restore default value else set value corresponding to "flag"
2283  if "flag" is clear don't change corresponding value
2284  */
2285  radv_info->send_radv = (surpress != 0) ? ( (is_no != 0) ? 1 : 0 ) : radv_info->send_radv;
2286  radv_info->adv_managed_flag = ( managed != 0) ? ( (is_no) ? 0 : 1) : radv_info->adv_managed_flag;
2287  radv_info->adv_other_flag = (other != 0) ? ( (is_no) ? 0: 1) : radv_info->adv_other_flag;
2288  radv_info->adv_link_layer_address = ( ll_option != 0) ? ( (is_no) ? 1 : 0) : radv_info->adv_link_layer_address;
2289  radv_info->send_unicast = (send_unicast != 0) ? ( (is_no) ? 0 : 1) : radv_info->send_unicast;
2290  radv_info->cease_radv = ( cease != 0) ? ( (is_no) ? 0 : 1) : radv_info->cease_radv;
2291 
2292  radv_info->min_radv_interval = min_interval;
2293  radv_info->max_radv_interval = max_interval;
2294  radv_info->adv_router_lifetime_in_sec = lifetime;
2295 
2296  radv_info->initial_adverts_count =
2297  (initial_count != 0) ? ( (is_no) ? MAX_INITIAL_RTR_ADVERTISEMENTS : initial_count) : radv_info->initial_adverts_count ;
2298  radv_info->initial_adverts_interval =
2299  (initial_interval != 0) ? ( (is_no) ? MAX_INITIAL_RTR_ADVERT_INTERVAL : initial_interval) : radv_info->initial_adverts_interval;
2300 
2301  /* restart */
2302  if((cease != 0) && (is_no))
2303  radv_info-> send_radv = 1;
2304 
2305  radv_info->initial_adverts_sent = radv_info->initial_adverts_count -1;
2306  radv_info->next_multicast_time = vlib_time_now (vm);
2307  radv_info->last_multicast_time = vlib_time_now (vm);
2308  radv_info->last_radv_time = 0;
2309  }
2310  return(error);
2311 }
2312 
2313 int
2315  ip6_address_t *prefix_addr, u8 prefix_len,
2316  u8 use_default, u32 val_lifetime, u32 pref_lifetime,
2317  u8 no_advertise, u8 off_link, u8 no_autoconfig, u8 no_onlink,
2318  u8 is_no)
2319 {
2321  int error;
2322 
2323  u32 ri;
2324 
2325  /* look up the radv_t information for this interface */
2327 
2328  ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
2329 
2330  error = (ri != ~0) ? 0 : VNET_API_ERROR_INVALID_SW_IF_INDEX;
2331 
2332  if(!error)
2333  {
2334  f64 now = vlib_time_now (vm);
2335  ip6_radv_t * radv_info;
2336  radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
2337 
2338  /* prefix info add, delete or update */
2339  ip6_radv_prefix_t * prefix;
2340 
2341  /* lookup prefix info for this address on this interface */
2342  uword * p = mhash_get (&radv_info->address_to_prefix_index, prefix_addr);
2343 
2344  prefix = p ? pool_elt_at_index (radv_info->adv_prefixes_pool, p[0]) : 0;
2345 
2346  if(is_no)
2347  {
2348  /* delete */
2349  if(!prefix)
2350  return VNET_API_ERROR_INVALID_VALUE; /* invalid prefix */
2351 
2352  if(prefix->prefix_len != prefix_len)
2353  return VNET_API_ERROR_INVALID_VALUE_2;
2354 
2355  /* FIXME - Should the DP do this or the CP ?*/
2356  /* do specific delete processing here before returning */
2357  /* try to remove from routing table */
2358 
2359  mhash_unset (&radv_info->address_to_prefix_index, prefix_addr,/* old_value */ 0);
2360  pool_put (radv_info->adv_prefixes_pool, prefix);
2361 
2362  radv_info->initial_adverts_sent = radv_info->initial_adverts_count -1;
2363  radv_info->next_multicast_time = vlib_time_now (vm);
2364  radv_info->last_multicast_time = vlib_time_now (vm);
2365  radv_info->last_radv_time = 0;
2366  return(error);
2367  }
2368 
2369  /* adding or changing */
2370  if(!prefix)
2371  {
2372  /* add */
2373  u32 pi;
2374  pool_get (radv_info->adv_prefixes_pool, prefix);
2375  pi = prefix - radv_info->adv_prefixes_pool;
2376  mhash_set (&radv_info->address_to_prefix_index, prefix_addr, pi, /* old_value */ 0);
2377 
2378  memset(prefix, 0x0, sizeof(ip6_radv_prefix_t));
2379 
2380  prefix->prefix_len = prefix_len;
2381  clib_memcpy(&prefix->prefix, prefix_addr, sizeof(ip6_address_t));
2382 
2383  /* initialize default values */
2384  prefix->adv_on_link_flag = 1; /* L bit set */
2385  prefix->adv_autonomous_flag = 1; /* A bit set */
2388  prefix->enabled = 1;
2389  prefix->decrement_lifetime_flag = 1;
2390  prefix->deprecated_prefix_flag = 1;
2391 
2392  if(off_link == 0)
2393  {
2394  /* FIXME - Should the DP do this or the CP ?*/
2395  /* insert prefix into routing table as a connected prefix */
2396  }
2397 
2398  if(use_default)
2399  goto restart;
2400  }
2401  else
2402  {
2403 
2404  if(prefix->prefix_len != prefix_len)
2405  return VNET_API_ERROR_INVALID_VALUE_2;
2406 
2407  if(off_link != 0)
2408  {
2409  /* FIXME - Should the DP do this or the CP ?*/
2410  /* remove from routing table if already there */
2411  }
2412  }
2413 
2414  if((val_lifetime == ~0) || (pref_lifetime == ~0))
2415  {
2416  prefix->adv_valid_lifetime_in_secs = ~0;
2417  prefix->adv_pref_lifetime_in_secs = ~0;
2418  prefix->decrement_lifetime_flag = 0;
2419  }
2420  else
2421  {
2422  prefix->adv_valid_lifetime_in_secs = val_lifetime;;
2423  prefix->adv_pref_lifetime_in_secs = pref_lifetime;
2424  }
2425 
2426  /* copy remaining */
2427  prefix->enabled = !(no_advertise != 0);
2428  prefix->adv_on_link_flag = !((off_link != 0) || (no_onlink != 0));
2429  prefix->adv_autonomous_flag = !(no_autoconfig != 0);
2430 
2431  restart:
2432  /* restart */
2433  /* fill in the expiration times */
2434  prefix->valid_lifetime_expires = now + prefix->adv_valid_lifetime_in_secs;
2435  prefix->pref_lifetime_expires = now + prefix->adv_pref_lifetime_in_secs;
2436 
2437  radv_info->initial_adverts_sent = radv_info->initial_adverts_count -1;
2438  radv_info->next_multicast_time = vlib_time_now (vm);
2439  radv_info->last_multicast_time = vlib_time_now (vm);
2440  radv_info->last_radv_time = 0;
2441  }
2442  return(error);
2443 }
2444 
2445 clib_error_t *
2447 {
2448  vnet_main_t * vnm = vnet_get_main();
2450  clib_error_t * error = 0;
2451  u8 is_no = 0;
2452  u8 surpress = 0, managed = 0, other = 0;
2453  u8 surpress_ll_option = 0, send_unicast = 0, cease= 0;
2454  u8 use_lifetime = 0;
2455  u32 sw_if_index, ra_lifetime = 0, ra_initial_count = 0, ra_initial_interval = 0;
2456  u32 ra_max_interval = 0 , ra_min_interval = 0;
2457 
2458  unformat_input_t _line_input, * line_input = &_line_input;
2459  vnet_sw_interface_t * sw_if0;
2460 
2461  int add_radv_info = 1;
2462  __attribute__((unused)) ip6_radv_t * radv_info = 0;
2463  ip6_address_t ip6_addr;
2464  u32 addr_len;
2465 
2466 
2467  /* Get a line of input. */
2468  if (! unformat_user (main_input, unformat_line_input, line_input))
2469  return 0;
2470 
2471  /* get basic radv info for this interface */
2472  if(unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2473  {
2474 
2475  if (unformat_user (line_input,
2476  unformat_vnet_sw_interface, vnm, &sw_if_index))
2477  {
2478  u32 ri;
2479  ethernet_interface_t * eth_if0 = 0;
2480 
2481  sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index);
2482  if(sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE)
2483  eth_if0 = ethernet_get_interface (&ethernet_main, sw_if0->hw_if_index);
2484 
2485  if(!eth_if0)
2486  {
2487  error = clib_error_return (0, "Interface must be of ethernet type");
2488  goto done;
2489  }
2490 
2491  /* look up the radv_t information for this interface */
2493 
2494  ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
2495 
2496  if(ri != ~0)
2497  {
2498  radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
2499  }
2500  else
2501  {
2502  error = clib_error_return (0, "unknown interface %U'",
2503  format_unformat_error, line_input);
2504  goto done;
2505  }
2506  }
2507  else
2508  {
2509  error = clib_error_return (0, "invalid interface name %U'",
2510  format_unformat_error, line_input);
2511  goto done;
2512  }
2513  }
2514 
2515  /* get the rest of the command */
2516  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2517  {
2518  if (unformat (line_input, "no"))
2519  is_no = 1;
2520  else if(unformat (line_input, "prefix %U/%d",
2521  unformat_ip6_address, &ip6_addr,
2522  &addr_len))
2523  {
2524  add_radv_info = 0;
2525  break;
2526  }
2527  else if (unformat (line_input, "ra-managed-config-flag"))
2528  {
2529  managed = 1;
2530  break;
2531  }
2532  else if (unformat (line_input, "ra-other-config-flag"))
2533  {
2534  other = 1;
2535  break;
2536  }
2537  else if (unformat (line_input, "ra-surpress"))
2538  {
2539  surpress = 1;
2540  break;
2541  }
2542  else if (unformat (line_input, "ra-surpress-link-layer"))
2543  {
2544  surpress_ll_option = 1;
2545  break;
2546  }
2547  else if (unformat (line_input, "ra-send-unicast"))
2548  {
2549  send_unicast = 1;
2550  break;
2551  }
2552  else if (unformat (line_input, "ra-lifetime"))
2553  {
2554  if (!unformat (line_input, "%d", &ra_lifetime))
2555  return(error = unformat_parse_error (line_input));
2556  use_lifetime = 1;
2557  break;
2558  }
2559  else if (unformat (line_input, "ra-initial"))
2560  {
2561  if (!unformat (line_input, "%d %d", &ra_initial_count, &ra_initial_interval))
2562  return(error = unformat_parse_error (line_input));
2563  break;
2564  }
2565  else if (unformat (line_input, "ra-interval"))
2566  {
2567  if (!unformat (line_input, "%d", &ra_max_interval))
2568  return(error = unformat_parse_error (line_input));
2569 
2570  if (!unformat (line_input, "%d", &ra_min_interval))
2571  ra_min_interval = 0;
2572  break;
2573  }
2574  else if(unformat (line_input, "ra-cease"))
2575  {
2576  cease = 1;
2577  break;
2578  }
2579  else
2580  return(unformat_parse_error (line_input));
2581  }
2582 
2583  if(add_radv_info)
2584  {
2585  ip6_neighbor_ra_config(vm, sw_if_index,
2586  surpress, managed, other,
2587  surpress_ll_option, send_unicast, cease,
2588  use_lifetime, ra_lifetime,
2589  ra_initial_count, ra_initial_interval,
2590  ra_max_interval, ra_min_interval,
2591  is_no);
2592  }
2593  else
2594  {
2595  u32 valid_lifetime_in_secs = 0;
2596  u32 pref_lifetime_in_secs = 0;
2597  u8 use_prefix_default_values = 0;
2598  u8 no_advertise = 0;
2599  u8 off_link= 0;
2600  u8 no_autoconfig = 0;
2601  u8 no_onlink= 0;
2602 
2603  /* get the rest of the command */
2604  while(unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2605  {
2606  if(unformat (line_input, "default"))
2607  {
2608  use_prefix_default_values = 1;
2609  break;
2610  }
2611  else if(unformat (line_input, "infinite"))
2612  {
2613  valid_lifetime_in_secs = ~0;
2614  pref_lifetime_in_secs = ~0;
2615  break;
2616  }
2617  else if(unformat (line_input, "%d %d", &valid_lifetime_in_secs,
2618  &pref_lifetime_in_secs))
2619  break;
2620  else
2621  break;
2622  }
2623 
2624 
2625  /* get the rest of the command */
2626  while (!use_prefix_default_values &&
2628  {
2629  if(unformat (line_input, "no-advertise"))
2630  no_advertise = 1;
2631  else if(unformat (line_input, "off-link"))
2632  off_link = 1;
2633  else if(unformat (line_input, "no-autoconfig"))
2634  no_autoconfig = 1;
2635  else if(unformat (line_input, "no-onlink"))
2636  no_onlink = 1;
2637  else
2638  return(unformat_parse_error (line_input));
2639  }
2640 
2641  ip6_neighbor_ra_prefix(vm, sw_if_index,
2642  &ip6_addr, addr_len,
2643  use_prefix_default_values,
2644  valid_lifetime_in_secs,
2645  pref_lifetime_in_secs,
2646  no_advertise,
2647  off_link,
2648  no_autoconfig,
2649  no_onlink,
2650  is_no);
2651  }
2652 
2653  unformat_free (line_input);
2654 
2655  done:
2656  return error;
2657 }
2658 
2659 static clib_error_t *
2661  unformat_input_t * input,
2662  vlib_cli_command_t * cmd)
2663 {
2664  vnet_main_t * vnm = vnet_get_main();
2666  clib_error_t * error = 0;
2667  u32 sw_if_index;
2668 
2669  sw_if_index = ~0;
2670 
2671  if (unformat_user (input,
2672  unformat_vnet_sw_interface, vnm, &sw_if_index))
2673  {
2674  u32 ri;
2675 
2676  /* look up the radv_t information for this interface */
2678 
2679  ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
2680 
2681  if(ri != ~0)
2682  {
2684  ip6_radv_t * radv_info;
2685  radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
2686 
2687  vlib_cli_output (vm, "%U is admin %s\n", format_vnet_sw_interface_name, vnm,
2688  vnet_get_sw_interface (vnm, sw_if_index),
2689  (vnet_sw_interface_is_admin_up (vnm, sw_if_index) ? "up" : "down"));
2690 
2691  u32 ai;
2692  u32 *global_scope = 0,i;
2694 
2696  ai = lm->if_address_pool_index_by_sw_if_index[sw_if_index];
2697 
2698  while (ai != (u32)~0)
2699  {
2700  a = pool_elt_at_index(lm->if_address_pool, ai);
2701  ip6_address_t * address = ip_interface_address_get_address (lm, a);
2702 
2703  if( ip6_address_is_link_local_unicast (address))
2704  vlib_cli_output (vm, "\tIPv6 is enabled, link-local address is %U\n", format_ip6_address,
2705  address);
2706 
2707  if((address->as_u8[0] & 0xe0) == 0x20)
2708  vec_add1 (global_scope, ai);
2709 
2710  ai = a->next_this_sw_interface;
2711  }
2712 
2713  vlib_cli_output (vm, "\tGlobal unicast address(es):\n");
2714  for (i = 0; i < vec_len (global_scope); i++)
2715  {
2716  a = pool_elt_at_index(lm->if_address_pool, global_scope[i]);
2717  ip6_address_t * address = ip_interface_address_get_address (lm, a);
2718  ip6_address_t mask, subnet;
2719 
2720  subnet = *address;
2722  ip6_address_mask(&subnet, &mask);
2723 
2724  vlib_cli_output (vm, "\t\t%U, subnet is %U/%d",
2725  format_ip6_address, address,
2726  format_ip6_address,&subnet,
2727  a->address_length);
2728  }
2729  vec_free (global_scope);
2730  vlib_cli_output (vm, "\tJoined group address(es):\n");
2731  ip6_mldp_group_t *m;
2732  pool_foreach (m, radv_info->mldp_group_pool, ({
2733  vlib_cli_output (vm, "\t\t%U\n", format_ip6_address, &m->mcast_address);
2734  }));
2735 
2736  vlib_cli_output (vm, "\tAdvertised Prefixes:\n");
2737  ip6_radv_prefix_t * p;
2738  pool_foreach (p, radv_info->adv_prefixes_pool, ({
2739  vlib_cli_output (vm, "\t\tprefix %U, length %d\n",
2740  format_ip6_address, &p->prefix, p->prefix_len);
2741  }));
2742 
2743  vlib_cli_output (vm, "\tMTU is %d\n", radv_info->adv_link_mtu);
2744  vlib_cli_output (vm, "\tICMP error messages are unlimited\n");
2745  vlib_cli_output (vm, "\tICMP redirects are disabled\n");
2746  vlib_cli_output (vm, "\tICMP unreachables are not sent\n");
2747  vlib_cli_output (vm, "\tND DAD is disabled\n");
2748  //vlib_cli_output (vm, "\tND reachable time is %d milliseconds\n",);
2749  vlib_cli_output (vm, "\tND advertised reachable time is %d\n",
2751  vlib_cli_output (vm, "\tND advertised retransmit interval is %d (msec)\n",
2753 
2754  u32 ra_interval = radv_info->max_radv_interval;
2755  u32 ra_interval_min = radv_info->min_radv_interval;
2756  vlib_cli_output (vm, "\tND router advertisements are sent every %d seconds (min interval is %d)\n",
2757  ra_interval, ra_interval_min);
2758  vlib_cli_output (vm, "\tND router advertisements live for %d seconds\n",
2759  radv_info->adv_router_lifetime_in_sec);
2760  vlib_cli_output (vm, "\tHosts %s stateless autoconfig for addresses\n",
2761  (radv_info->adv_managed_flag) ? "use" :" don't use");
2762  vlib_cli_output (vm, "\tND router advertisements sent %d\n", radv_info->n_advertisements_sent);
2763  vlib_cli_output (vm, "\tND router solicitations received %d\n", radv_info->n_solicitations_rcvd);
2764  vlib_cli_output (vm, "\tND router solicitations dropped %d\n", radv_info->n_solicitations_dropped);
2765  }
2766  else
2767  {
2768  error = clib_error_return (0, "Ipv6 not enabled on interface",
2769  format_unformat_error, input);
2770 
2771  }
2772  }
2773  return error;
2774 }
2775 
2776 VLIB_CLI_COMMAND (show_ip6_interface_command, static) = {
2777  .path = "show ip6 interface",
2778  .function = show_ip6_interface_cmd,
2779  .short_help = "Show ip6 interface <iface name>",
2780 };
2781 
2782 clib_error_t *
2784  u32 sw_if_index)
2785 {
2786  clib_error_t * error = 0;
2788  u32 ri;
2789 
2790  /* look up the radv_t information for this interface */
2792  ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
2793 
2794  /* if not created - do nothing */
2795  if(ri != ~0)
2796  {
2797  vnet_main_t * vnm = vnet_get_main();
2798  ip6_radv_t * radv_info;
2799 
2800  radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
2801 
2802  /* check radv_info ref count for other ip6 addresses on this interface */
2803  if(radv_info->ref_count == 0 )
2804  {
2805  /* essentially "disables" ipv6 on this interface */
2806  error = ip6_add_del_interface_address (vm, sw_if_index,
2807  &radv_info->link_local_address,
2808  radv_info->link_local_prefix_len,
2809  1 /* is_del */);
2810 
2811  ip6_neighbor_sw_interface_add_del (vnm, sw_if_index, 0/* is_add */);
2812  }
2813  }
2814  return error;
2815 }
2816 
2817 int
2819  u32 sw_if_index)
2820 {
2822  u32 ri = ~0;
2823 
2824  /* look up the radv_t information for this interface */
2826 
2827  ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
2828 
2829  return ri != ~0;
2830 }
2831 
2832 clib_error_t *
2834  u32 sw_if_index)
2835 {
2836  clib_error_t * error = 0;
2838  u32 ri;
2839  int is_add = 1;
2840 
2841  /* look up the radv_t information for this interface */
2843 
2844  ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
2845 
2846  /* if not created yet */
2847  if(ri == ~0)
2848  {
2849  vnet_main_t * vnm = vnet_get_main();
2850  vnet_sw_interface_t * sw_if0;
2851 
2852  sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index);
2853  if(sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE)
2854  {
2855  ethernet_interface_t * eth_if0;
2856 
2857  eth_if0 = ethernet_get_interface (&ethernet_main, sw_if0->hw_if_index);
2858  if(eth_if0)
2859  {
2860  /* create radv_info. for this interface. This holds all the info needed for router adverts */
2861  ri = ip6_neighbor_sw_interface_add_del (vnm, sw_if_index, is_add);
2862 
2863  if(ri != ~0)
2864  {
2865  ip6_radv_t * radv_info;
2866  ip6_address_t link_local_address;
2867 
2868  radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
2869 
2871  eth_if0->address);
2872 
2873  sw_if0 = vnet_get_sw_interface (vnm, sw_if_index);
2874  if(sw_if0->type == VNET_SW_INTERFACE_TYPE_SUB)
2875  {
2876  /* make up an interface id */
2877  md5_context_t m;
2878  u8 digest[16];
2879 
2880  link_local_address.as_u64[0] = radv_info->randomizer;
2881 
2882  md5_init (&m);
2883  md5_add (&m, &link_local_address, 16);
2884  md5_finish (&m, digest);
2885 
2886  clib_memcpy(&link_local_address, digest, 16);
2887 
2888  radv_info->randomizer = link_local_address.as_u64[0];
2889 
2890  link_local_address.as_u64[0] = clib_host_to_net_u64 (0xFE80000000000000ULL);
2891  /* clear u bit */
2892  link_local_address.as_u8[8] &= 0xfd;
2893  }
2894 
2895  /* essentially "enables" ipv6 on this interface */
2896  error = ip6_add_del_interface_address (vm, sw_if_index,
2897  &link_local_address, 64 /* address width */,
2898  0 /* is_del */);
2899 
2900  if(error)
2901  ip6_neighbor_sw_interface_add_del (vnm, sw_if_index, !is_add);
2902  else
2903  {
2904  radv_info->link_local_address = link_local_address;
2905  radv_info->link_local_prefix_len = 64;
2906  }
2907  }
2908  }
2909  }
2910  }
2911  return error;
2912 }
2913 
2914 static clib_error_t *
2916  unformat_input_t * input,
2917  vlib_cli_command_t * cmd)
2918 {
2919  vnet_main_t * vnm = vnet_get_main();
2920  clib_error_t * error = 0;
2921  u32 sw_if_index;
2922 
2923  sw_if_index = ~0;
2924 
2925  if (unformat_user (input,
2926  unformat_vnet_sw_interface, vnm, &sw_if_index))
2927  {
2928  enable_ip6_interface(vm, sw_if_index);
2929  }
2930  else
2931  {
2932  error = clib_error_return (0, "unknown interface\n'",
2933  format_unformat_error, input);
2934 
2935  }
2936  return error;
2937 }
2938 
2939 VLIB_CLI_COMMAND (enable_ip6_interface_command, static) = {
2940  .path = "enable ip6 interface",
2941  .function = enable_ip6_interface_cmd,
2942  .short_help = "enable ip6 interface <iface name>",
2943 };
2944 
2945 static clib_error_t *
2947  unformat_input_t * input,
2948  vlib_cli_command_t * cmd)
2949 {
2950  vnet_main_t * vnm = vnet_get_main();
2951  clib_error_t * error = 0;
2952  u32 sw_if_index;
2953 
2954  sw_if_index = ~0;
2955 
2956  if (unformat_user (input,
2957  unformat_vnet_sw_interface, vnm, &sw_if_index))
2958  {
2959  error = disable_ip6_interface(vm, sw_if_index);
2960  }
2961  else
2962  {
2963  error = clib_error_return (0, "unknown interface\n'",
2964  format_unformat_error, input);
2965 
2966  }
2967  return error;
2968 }
2969 
2970 VLIB_CLI_COMMAND (disable_ip6_interface_command, static) = {
2971  .path = "disable ip6 interface",
2972  .function = disable_ip6_interface_cmd,
2973  .short_help = "disable ip6 interface <iface name>",
2974 };
2975 
2976 VLIB_CLI_COMMAND (ip6_nd_command, static) = {
2977  .path = "ip6 nd",
2978  .short_help = "Set ip6 neighbor discovery parameters",
2979  .function = ip6_neighbor_cmd,
2980 };
2981 
2982 clib_error_t *
2984  u32 sw_if_index,
2985  ip6_address_t *address,
2986  u8 address_length)
2987 {
2988  clib_error_t * error = 0;
2990  u32 ri;
2991  ip6_radv_t * radv_info;
2992  vnet_main_t * vnm = vnet_get_main();
2993 
2994  if( !ip6_address_is_link_local_unicast (address))
2995  {
2996  vnm->api_errno = VNET_API_ERROR_ADDRESS_NOT_LINK_LOCAL;
2997  return(error = clib_error_return (0, "address not link-local",
2999  }
3000 
3001  /* call enable ipv6 */
3002  enable_ip6_interface(vm, sw_if_index);
3003 
3004  ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
3005 
3006  if(ri != ~0)
3007  {
3008  radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
3009 
3010  /* save if link local address (overwrite default) */
3011 
3012  /* delete the old one */
3013  error = ip6_add_del_interface_address (vm, sw_if_index,
3014  &radv_info->link_local_address,
3015  radv_info->link_local_prefix_len /* address width */,
3016  1 /* is_del */);
3017 
3018  if(!error)
3019  {
3020  /* add the new one */
3021  error = ip6_add_del_interface_address (vm, sw_if_index,
3022  address ,
3023  address_length /* address width */,
3024  0/* is_del */);
3025 
3026  if(!error)
3027  {
3028  radv_info->link_local_address = *address;
3029  radv_info->link_local_prefix_len = address_length;
3030  }
3031  }
3032  }
3033  else
3034  {
3035  vnm->api_errno = VNET_API_ERROR_IP6_NOT_ENABLED;
3036  error = clib_error_return (0, "ip6 not enabled for interface",
3038  }
3039  return error;
3040 }
3041 
3042 clib_error_t *
3044  unformat_input_t * input,
3045  vlib_cli_command_t * cmd)
3046 {
3047  vnet_main_t * vnm = vnet_get_main();
3048  clib_error_t * error = 0;
3049  u32 sw_if_index;
3050  ip6_address_t ip6_addr;
3051  u32 addr_len = 0;
3052 
3053  if (unformat_user (input,
3054  unformat_vnet_sw_interface, vnm, &sw_if_index))
3055  {
3056  /* get the rest of the command */
3057  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
3058  {
3059  if(unformat (input, "%U/%d",
3060  unformat_ip6_address, &ip6_addr,
3061  &addr_len))
3062  break;
3063  else
3064  return(unformat_parse_error (input));
3065  }
3066  }
3067  error = set_ip6_link_local_address(vm,
3068  sw_if_index,
3069  &ip6_addr,
3070  addr_len);
3071  return error;
3072 }
3073 
3074 VLIB_CLI_COMMAND (set_ip6_link_local_address_command, static) = {
3075  .path = "set ip6 link-local address",
3076  .short_help = "Set ip6 interface link-local address <intfc> <address.>",
3077  .function = set_ip6_link_local_address_cmd,
3078 };
3079 
3080 /* callback when an interface address is added or deleted */
3081 static void
3083  uword opaque,
3084  u32 sw_if_index,
3085  ip6_address_t * address,
3086  u32 address_length,
3087  u32 if_address_index,
3088  u32 is_delete)
3089 {
3090  vnet_main_t * vnm = vnet_get_main();
3092  u32 ri;
3093  vlib_main_t * vm = vnm->vlib_main;
3094  ip6_radv_t * radv_info;
3095  ip6_address_t a;
3096  ip6_mldp_group_t *mcast_group_info;
3097 
3098  /* create solicited node multicast address for this interface adddress */
3100 
3101  a.as_u8[0xd] = address->as_u8[0xd];
3102  a.as_u8[0xe] = address->as_u8[0xe];
3103  a.as_u8[0xf] = address->as_u8[0xf];
3104 
3105  if(!is_delete)
3106  {
3107  /* try to create radv_info - does nothing if ipv6 already enabled */
3108  enable_ip6_interface(vm, sw_if_index);
3109 
3110  /* look up the radv_t information for this interface */
3112  ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
3113  if(ri != ~0)
3114  {
3115  /* get radv_info */
3116  radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
3117 
3118  /* add address */
3119  if( !ip6_address_is_link_local_unicast (address))
3120  radv_info->ref_count++;
3121 
3122  /* lookup prefix info for this address on this interface */
3123  uword * p = mhash_get (&radv_info->address_to_mldp_index, &a);
3124  mcast_group_info = p ? pool_elt_at_index (radv_info->mldp_group_pool, p[0]) : 0;
3125 
3126  /* add -solicted node multicast address */
3127  if(!mcast_group_info)
3128  {
3129  /* add */
3130  u32 mi;
3131  pool_get (radv_info->mldp_group_pool, mcast_group_info);
3132 
3133  mi = mcast_group_info - radv_info->mldp_group_pool;
3134  mhash_set (&radv_info->address_to_mldp_index, &a, mi, /* old_value */ 0);
3135 
3136  mcast_group_info->type = 4;
3137  mcast_group_info->mcast_source_address_pool = 0;
3138  mcast_group_info->num_sources = 0;
3139  clib_memcpy(&mcast_group_info->mcast_address, &a, sizeof(ip6_address_t));
3140  }
3141  }
3142  }
3143  else
3144  {
3145 
3146  /* delete */
3147  /* look up the radv_t information for this interface */
3149  ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index];
3150  if(ri != ~0)
3151  {
3152  /* get radv_info */
3153  radv_info = pool_elt_at_index (nm->if_radv_pool, ri);
3154 
3155  /* lookup prefix info for this address on this interface */
3156  uword * p = mhash_get (&radv_info->address_to_mldp_index, &a);
3157  mcast_group_info = p ? pool_elt_at_index (radv_info->mldp_group_pool, p[0]) : 0;
3158 
3159  if(mcast_group_info)
3160  {
3161  mhash_unset (&radv_info->address_to_mldp_index, &a,/* old_value */ 0);
3162  pool_put (radv_info->mldp_group_pool, mcast_group_info);
3163  }
3164 
3165  /* if interface up send MLDP "report" */
3166  radv_info->all_routers_mcast = 0;
3167 
3168  /* add address */
3169  if( !ip6_address_is_link_local_unicast (address))
3170  radv_info->ref_count--;
3171  }
3172  }
3173 }
3174 
3176 {
3178 
3179  nm->limit_neighbor_cache_size = neighbor_limit;
3180  return 0;
3181 }
3182 
3183 
3184 static void
3186 {
3187  int done = 0;
3188  int i;
3189  while (!done)
3190  {
3192  if (vec_elt(n->adjacencies, i) == adj_index)
3193  {
3194  vec_del1(n->adjacencies, i);
3195  continue;
3196  }
3197  done = 1;
3198  }
3199 }
3200 
3201 static void
3203 {
3204  int i;
3206  if (vec_elt(n->adjacencies, i) == adj_index)
3207  return;
3208  vec_add1(n->adjacencies, adj_index);
3209 }
3210 
3211 static void
3213  u32 adj_index,
3214  ip_adjacency_t * adj,
3215  u32 is_del)
3216 {
3219  ip6_neighbor_t *n = 0;
3220  uword * p;
3221  u32 ai;
3222 
3223  for(ai = adj->heap_handle; ai < adj->heap_handle + adj->n_adj ; ai++)
3224  {
3225  adj = ip_get_adjacency (lm, ai);
3226  if (adj->lookup_next_index == IP_LOOKUP_NEXT_ARP &&
3227  (adj->arp.next_hop.ip6.as_u64[0] || adj->arp.next_hop.ip6.as_u64[1]))
3228  {
3229  k.sw_if_index = adj->rewrite_header.sw_if_index;
3230  k.ip6_address.as_u64[0] = adj->arp.next_hop.ip6.as_u64[0];
3231  k.ip6_address.as_u64[1] = adj->arp.next_hop.ip6.as_u64[1];
3232  k.pad = 0;
3233  p = mhash_get (&nm->neighbor_index_by_key, &k);
3234  if (p)
3235  n = pool_elt_at_index (nm->neighbor_pool, p[0]);
3236  }
3237  else
3238  continue;
3239 
3240  if (is_del)
3241  {
3242  if (!n)
3243  clib_warning("Adjacency contains unknown ND next hop %U (del)",
3244  format_ip46_address, &adj->arp.next_hop);
3245  else
3247  }
3248  else /* add */
3249  {
3250  if (!n)
3251  clib_warning("Adjacency contains unknown ND next hop %U (add)",
3252  format_ip46_address, &adj->arp.next_hop);
3253  else
3255  }
3256  }
3257 }
3258 
3260 {
3262  ip6_main_t * im = &ip6_main;
3263  ip_lookup_main_t * lm = &im->lookup_main;
3264 
3266  /* value size */ sizeof (uword),
3267  /* key size */ sizeof (ip6_neighbor_key_t));
3268 
3269  icmp6_register_type (vm, ICMP6_neighbor_solicitation, ip6_icmp_neighbor_solicitation_node.index);
3270  icmp6_register_type (vm, ICMP6_neighbor_advertisement, ip6_icmp_neighbor_advertisement_node.index);
3271  icmp6_register_type (vm, ICMP6_router_solicitation, ip6_icmp_router_solicitation_node.index);
3272  icmp6_register_type (vm, ICMP6_router_advertisement, ip6_icmp_router_advertisement_node.index);
3273 
3274  /* handler node for ip6 neighbor discovery events and timers */
3276 
3277  /* add call backs */
3279  memset(&cb, 0x0, sizeof(ip6_add_del_interface_address_callback_t));
3280 
3281  /* when an interface address changes... */
3283  cb.function_opaque = 0;
3285 
3287  /* value size */ sizeof (uword),
3288  /* key size */ sizeof (ip6_address_t));
3289 
3290  /* default, configurable */
3291  nm->limit_neighbor_cache_size = 50000;
3292 
3293 #if 0
3294  /* $$$$ Hack fix for today */
3296  (im->discover_neighbor_next_index_by_hw_if_index, 32, 0 /* drop */);
3297 #endif
3298 
3300 
3301  return 0;
3302 }
3303 
3305 
3306 
3308  void * address_arg,
3309  uword node_index,
3310  uword type_opaque,
3311  uword data)
3312 {
3314  ip6_address_t * address = address_arg;
3315  uword * p;
3316  pending_resolution_t * pr;
3317 
3318  pool_get (nm->pending_resolutions, pr);
3319 
3320  pr->next_index = ~0;
3321  pr->node_index = node_index;
3322  pr->type_opaque = type_opaque;
3323  pr->data = data;
3324 
3325  p = mhash_get (&nm->pending_resolutions_by_address, address);
3326  if (p)
3327  {
3328  /* Insert new resolution at the head of the list */
3329  pr->next_index = p[0];
3330  mhash_unset (&nm->pending_resolutions_by_address, address, 0);
3331  }
3332 
3333  mhash_set (&nm->pending_resolutions_by_address, address,
3334  pr - nm->pending_resolutions, 0 /* old value */);
3335 }
3336 
format_function_t format_ip46_address
Definition: format.h:54
#define ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_SOLICITED
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Definition: main.c:459
ip6_radv_t * if_radv_pool
Definition: ip6_neighbor.c:191
#define MIN_DELAY_BETWEEN_RAS
Definition: ip6_neighbor.c:137
#define DEF_DEF_RTR_LIFETIME
Definition: ip6_neighbor.c:132
#define pool_next_index(P, I)
Definition: pool.h:354
Definition: mhash.h:46
always_inline void vlib_error_count(vlib_main_t *vm, uword node_index, uword counter, uword increment)
Definition: error_funcs.h:54
always_inline void ip6_address_mask_from_width(ip6_address_t *a, u32 width)
Definition: ip6_packet.h:217
#define IP6_ROUTE_FLAG_NEIGHBOR
Definition: ip6.h:335
#define vec_foreach_index(var, v)
Iterate over vector indices.
void md5_finish(md5_context_t *c, u8 *digest)
Definition: md5.c:287
icmp6_router_solicitation_or_advertisement_next_t
Definition: ip6_neighbor.c:935
u32 n_solicitations_rcvd
Definition: ip6_neighbor.c:158
static void unset_random_neighbor_entry(void)
Definition: ip6_neighbor.c:262
static void ip6_neighbor_syslog(vlib_main_t *vm, int priority, char *fmt,...)
Definition: ip6_neighbor.c:906
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:267
void * clib_per_cpu_mheaps[CLIB_MAX_MHEAPS]
Definition: mem_mheap.c:53
#define ICMP6_ROUTER_DISCOVERY_FLAG_OTHER_CONFIG_VIA_DHCP
uword unformat(unformat_input_t *i, char *fmt,...)
Definition: unformat.c:942
int ip6_neighbor_ra_config(vlib_main_t *vm, u32 sw_if_index, u8 surpress, u8 managed, u8 other, u8 ll_option, u8 send_unicast, u8 cease, u8 use_lifetime, u32 lifetime, u32 initial_count, u32 initial_interval, u32 max_interval, u32 min_interval, u8 is_no)
vlib_node_registration_t ip6_icmp_neighbor_solicitation_node
(constructor) VLIB_REGISTER_NODE (ip6_icmp_neighbor_solicitation_node)
a
Definition: bitmap.h:393
int ip6_neighbor_ra_prefix(vlib_main_t *vm, u32 sw_if_index, ip6_address_t *prefix_addr, u8 prefix_len, u8 use_default, u32 val_lifetime, u32 pref_lifetime, u8 no_advertise, u8 off_link, u8 no_autoconfig, u8 no_onlink, u8 is_no)
u8 link_local_prefix_len
Definition: ip6_neighbor.c:163
format_function_t format_ip6_address
Definition: format.h:87
static clib_error_t * ip6_neighbor_init(vlib_main_t *vm)
f64 last_radv_time
Definition: ip6_neighbor.c:147
static void(BVT(clib_bihash)*h, BVT(clib_bihash_value)*v)
ip_interface_address_t * if_address_pool
Definition: lookup.h:388
static char * log_level_strings[]
Definition: ip6_neighbor.c:897
always_inline uword ip6_address_is_unspecified(ip6_address_t *a)
Definition: ip6_packet.h:243
mhash_t neighbor_index_by_key
Definition: ip6_neighbor.c:187
u32 free_list_index
Buffer free list that this buffer was allocated from and will be freed to.
Definition: buffer.h:102
ip_lookup_next_t lookup_next_index
Definition: lookup.h:163
#define PREDICT_TRUE(x)
Definition: clib.h:98
always_inline void ip6_set_reserved_multicast_address(ip6_address_t *a, ip6_multicast_address_scope_t scope, u16 id)
Definition: ip6_packet.h:125
u8 as_u8[16]
Definition: ip6_packet.h:47
u64 as_u64[2]
Definition: ip6_packet.h:50
int send_unicast
Definition: ip6_neighbor.c:116
ip6_address_t prefix
Definition: ip6_neighbor.c:49
always_inline void unformat_free(unformat_input_t *i)
Definition: format.h:160
f64 last_multicast_time
Definition: ip6_neighbor.c:148
#define UNFORMAT_END_OF_INPUT
Definition: format.h:142
void md5_init(md5_context_t *c)
Definition: md5.c:212
#define NULL
Definition: clib.h:55
uword mhash_unset(mhash_t *h, void *key, uword *old_value)
Definition: mhash.c:350
u32 index
Definition: node.h:203
ip6_radv_prefix_t * adv_prefixes_pool
Definition: ip6_neighbor.c:100
static void ip6_neighbor_entry_add_adj(ip6_neighbor_t *n, u32 adj_index)
always_inline uword ip6_address_is_link_local_unicast(ip6_address_t *a)
Definition: ip6_packet.h:260
#define ethernet_buffer_header_size(b)
Determine the size of the Ethernet headers of the current frame in the buffer.
Definition: ethernet.h:350
u8 src_address[6]
Definition: packet.h:52
pending_resolution_t * pending_resolutions
Definition: ip6_neighbor.c:181
vlib_cli_command_t set_ip6_neighbor_command
(constructor) VLIB_CLI_COMMAND (set_ip6_neighbor_command)
Definition: ip6_neighbor.c:670
#define ETHER_MAC_ADDR_LEN
Definition: ip6_neighbor.c:34
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:480
word vnet_sw_interface_compare(vnet_main_t *vnm, uword sw_if_index0, uword sw_if_index1)
Definition: interface.c:908
vlib_node_registration_t ip6_rewrite_node
(constructor) VLIB_REGISTER_NODE (ip6_rewrite_node)
Definition: ip6_forward.c:2461
ip_adjacency_t * ip_add_adjacency(ip_lookup_main_t *lm, ip_adjacency_t *copy_adj, u32 n_adj, u32 *adj_index_return)
Definition: lookup.c:139
static int logmask
Definition: ip6_neighbor.c:903
always_inline uword mhash_set(mhash_t *h, void *key, uword new_value, uword *old_value)
Definition: mhash.h:111
struct _vlib_node_registration vlib_node_registration_t
always_inline void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:789
#define STRUCT_OFFSET_OF(t, f)
Definition: clib.h:62
always_inline void * ip6_next_header(ip6_header_t *i)
Definition: ip6_packet.h:297
u32 adv_pref_lifetime_in_secs
Definition: ip6_neighbor.c:54
#define DEF_ADV_PREF_LIFETIME
Definition: ip6_neighbor.c:67
format_function_t format_vlib_cpu_time
Definition: node_funcs.h:964
unformat_function_t unformat_vnet_sw_interface
u32 adv_neighbor_reachable_time_in_msec
Definition: ip6_neighbor.c:89
vlib_error_t * errors
Definition: node.h:378
#define pool_get(P, E)
Definition: pool.h:186
ip6_address_t src_address
Definition: ip6_packet.h:293
format_function_t format_vnet_sw_if_index_name
always_inline void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:184
always_inline vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
clib_error_t * disable_ip6_interface(vlib_main_t *vm, u32 sw_if_index)
always_inline void * ip_interface_address_get_address(ip_lookup_main_t *lm, ip_interface_address_t *a)
Definition: lookup.h:513
u32 vlib_register_node(vlib_main_t *vm, vlib_node_registration_t *r)
Definition: node.c:449
always_inline uword unformat_check_input(unformat_input_t *i)
Definition: format.h:168
static uword ip6_neighbor_process_timer_event(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
ethernet_main_t ethernet_main
Definition: ethernet.h:226
vnet_main_t * vnet_get_main(void)
Definition: misc.c:45
#define static_always_inline
Definition: clib.h:85
u8 * format_ethernet_address(u8 *s, va_list *args)
Definition: format.c:43
#define pool_foreach(VAR, POOL, BODY)
Definition: pool.h:328
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:109
u32 local_interface_sw_if_index
Definition: vnet.h:60
VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION(ip6_neighbor_sw_interface_up_down)
u8 link_layer_addr_len
Definition: ip6_neighbor.c:97
#define ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_OVERRIDE
u8 dst_address[6]
Definition: packet.h:51
static clib_error_t * disable_ip6_interface_cmd(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static u8 * format_ip6_neighbor_ip6_entry(u8 *s, va_list *va)
Definition: ip6_neighbor.c:201
u32 vnet_ip6_neighbor_glean_add(u32 fib_index, void *next_hop_arg)
Definition: ip6_neighbor.c:518
static uword ip6_icmp_neighbor_discovery_event_process(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static clib_error_t * show_ip6_neighbors(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: ip6_neighbor.c:594
#define DEF_ADV_VALID_LIFETIME
Definition: ip6_neighbor.c:66
mhash_t address_to_mldp_index
Definition: ip6_neighbor.c:109
#define IP6_NEIGHBOR_FLAG_STATIC
Definition: ip6_neighbor.c:40
always_inline uword pool_elts(void *v)
Definition: pool.h:97
void vl_api_rpc_call_main_thread(void *fp, u8 *data, u32 data_length)
Definition: memory_vlib.c:1173
#define clib_warning(format, args...)
Definition: error.h:59
u32 table_index_or_table_id
Definition: ip6.h:343
unsigned long u64
Definition: types.h:89
f64 max_radv_interval
Definition: ip6_neighbor.c:141
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:953
static clib_error_t * set_ip6_neighbor(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: ip6_neighbor.c:629
u32 * neighbor_input_next_index_by_hw_if_index
Definition: ip6_neighbor.c:183
always_inline void * vlib_frame_vector_args(vlib_frame_t *f)
Definition: node_funcs.h:202
void ip6_add_del_route(ip6_main_t *im, ip6_add_del_route_args_t *args)
Definition: ip6_forward.c:208
void ip_del_adjacency(ip_lookup_main_t *lm, u32 adj_index)
Definition: lookup.c:285
#define MAX_DELAY_BETWEEN_RAS
Definition: ip6_neighbor.c:138
f64 max_delay_between_radv
Definition: ip6_neighbor.c:144
u32 adv_time_in_msec_between_retransmitted_neighbor_solicitations
Definition: ip6_neighbor.c:90
vnet_api_error_t api_errno
Definition: vnet.h:76
ip6_address_t dst_address
Definition: ip6.h:346
format_function_t format_vnet_sw_interface_name
#define pool_elt_at_index(p, i)
Definition: pool.h:346
static void ip6_neighbor_entry_del_adj(ip6_neighbor_t *n, u32 adj_index)
vlib_main_t * vlib_main
Definition: vnet.h:78
f64 min_radv_interval
Definition: ip6_neighbor.c:142
void vnet_register_ip6_neighbor_resolution_event(vnet_main_t *vnm, void *address_arg, uword node_index, uword type_opaque, uword data)
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:81
static void ip6_neighbor_add_del_adj_cb(struct ip_lookup_main_t *lm, u32 adj_index, ip_adjacency_t *adj, u32 is_del)
uword type_opaque
Definition: arp.c:54
int vnet_unset_ip6_ethernet_neighbor(vlib_main_t *vm, u32 sw_if_index, ip6_address_t *a, u8 *link_layer_address, uword n_bytes_link_layer_address)
Definition: ip6_neighbor.c:462
int all_routers_mcast
Definition: ip6_neighbor.c:120
always_inline uword random_default_seed(void)
Default random seed (unix/linux user-mode)
Definition: random.h:85
u32 all_nodes_adj_index
Definition: ip6_neighbor.c:124
static clib_error_t * enable_ip6_interface_cmd(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
uword os_get_cpu_number(void)
Definition: unix-misc.c:206
#define DEF_MAX_RADV_INTERVAL
Definition: ip6_neighbor.c:129
ip_adjacency_t * add_adj
Definition: ip6.h:355
#define IP6_MLDP_ALERT_TYPE
u8 link_layer_address[8]
Definition: ip6_neighbor.c:96
f64 next_multicast_time
Definition: ip6_neighbor.c:149
#define pool_put(P, E)
Definition: pool.h:200
#define foreach_log_level
Definition: ip6_neighbor.c:881
#define vec_dup(V)
Return copy of vector (no header, no alignment)
Definition: vec.h:332
enum icmp6_neighbor_discovery_option_type icmp6_neighbor_discovery_option_type_t
always_inline f64 vlib_process_wait_for_event_or_clock(vlib_main_t *vm, f64 dt)
Definition: node_funcs.h:551
#define ELOG_DATA(em, f)
Definition: elog.h:386
u32 vlib_buffer_alloc_from_free_list(vlib_main_t *vm, u32 *buffers, u32 n_buffers, u32 free_list_index)
Allocate buffers from specific freelist into supplied array.
Definition: buffer.c:782
#define unformat_parse_error(input)
Definition: format.h:265
int ip6_address_compare(ip6_address_t *a1, ip6_address_t *a2)
Definition: ip46_cli.c:45
#define PREDICT_FALSE(x)
Definition: clib.h:97
#define vec_del1(v, i)
Delete the element at index I.
Definition: vec.h:763
vnet_main_t vnet_main
Definition: misc.c:42
always_inline void * clib_mem_set_heap(void *heap)
Definition: mem.h:190
#define VLIB_FRAME_SIZE
Definition: node.h:292
int adv_other_flag
Definition: ip6_neighbor.c:87
void vlib_put_frame_to_node(vlib_main_t *vm, u32 to_node_index, vlib_frame_t *f)
Definition: main.c:191
u32 vlib_buffer_add_data(vlib_main_t *vm, u32 free_list_index, u32 buffer_index, void *data, u32 n_data_bytes)
Definition: buffer.c:1169
mhash_t address_to_prefix_index
Definition: ip6_neighbor.c:103
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Definition: buffer_node.h:83
always_inline void vlib_buffer_reset(vlib_buffer_t *b)
Reset current header & length to state they were in when packet was received.
Definition: buffer.h:211
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Definition: node_funcs.h:265
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:538
ip6_add_del_interface_address_callback_t * add_del_interface_address_callbacks
Definition: ip6.h:161
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:129
void ip6_link_local_address_from_ethernet_mac_address(ip6_address_t *ip, u8 *mac)
Definition: ip6_forward.c:2614
unformat_function_t unformat_ip6_address
Definition: format.h:86
int failed_device_check
Definition: ip6_neighbor.c:119
vlib_node_registration_t ip6_icmp_input_node
(constructor) VLIB_REGISTER_NODE (ip6_icmp_input_node)
Definition: icmp6.c:226
ip6_mldp_group_t * mldp_group_pool
Definition: ip6_neighbor.c:106
static_always_inline uword icmp6_neighbor_solicitation_or_advertisement(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, uword is_solicitation)
Definition: ip6_neighbor.c:683
clib_error_t * enable_ip6_interface(vlib_main_t *vm, u32 sw_if_index)
icmp6_neighbor_solicitation_or_advertisement_next_t
Definition: ip6_neighbor.c:676
int adv_managed_flag
Definition: ip6_neighbor.c:86
static uword icmp6_neighbor_advertisement(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
u32 n_solicitations_dropped
Definition: ip6_neighbor.c:159
void mhash_init(mhash_t *h, uword n_value_bytes, uword n_key_bytes)
Definition: mhash.c:169
u16 n_vectors
Definition: node.h:307
u8 * va_format(u8 *s, char *fmt, va_list *va)
Definition: format.c:374
ip6_address_t mcast_address
Definition: ip6_neighbor.c:76
log_level_t
Definition: ip6_neighbor.c:891
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:298
void vnet_rewrite_for_sw_interface(vnet_main_t *vnm, vnet_l3_packet_type_t packet_type, u32 sw_if_index, u32 node_index, void *dst_address, vnet_rewrite_header_t *rw, u32 max_rewrite_bytes)
Definition: rewrite.c:187
always_inline void ip6_link_local_address_from_ethernet_address(ip6_address_t *a, u8 *ethernet_address)
Definition: ip6_packet.h:147
u8 curr_hop_limit
Definition: ip6_neighbor.c:85
ip6_address_t * mcast_source_address_pool
Definition: ip6_neighbor.c:78
#define clib_memcpy(a, b, c)
Definition: string.h:63
always_inline vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
u32 ip6_fib_lookup_with_table(ip6_main_t *im, u32 fib_index, ip6_address_t *dst)
Definition: ip6_forward.c:61
#define DEF_CURR_HOP_LIMIT
Definition: ip6_neighbor.c:131
#define IP6_ROUTE_FLAG_DEL
Definition: ip6.h:328
elog_main_t elog_main
Definition: main.h:141
int adv_link_layer_address
Definition: ip6_neighbor.c:117
vlib_cli_command_t show_ip6_neighbors_command
(constructor) VLIB_CLI_COMMAND (show_ip6_neighbors_command)
Definition: ip6_neighbor.c:622
#define ELOG_TYPE_DECLARE(f)
Definition: elog.h:344
always_inline uword vnet_sw_interface_is_admin_up(vnet_main_t *vnm, u32 sw_if_index)
void md5_add(md5_context_t *c, void *data, int data_bytes)
Definition: md5.c:236
u64 cpu_time_last_updated
Definition: ip6_neighbor.c:42
always_inline vnet_sw_interface_t * vnet_get_sup_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
always_inline void ip6_set_solicited_node_multicast_address(ip6_address_t *a, u32 id)
Definition: ip6_packet.h:135
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:150
#define VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX
Definition: buffer.h:296
u32 initial_adverts_count
Definition: ip6_neighbor.c:152
u32 * if_address_pool_index_by_sw_if_index
Definition: lookup.h:395
u16 ip6_tcp_udp_icmp_compute_checksum(vlib_main_t *vm, vlib_buffer_t *p0, ip6_header_t *ip0, int *bogus_lengthp)
Definition: ip6_forward.c:1544
ip6_add_del_interface_address_function_t * function
Definition: ip6.h:101
#define MAX_INITIAL_RTR_ADVERTISEMENTS
Definition: ip6_neighbor.c:136
u16 cached_next_index
Definition: node.h:422
ip6_address_t link_local_address
Definition: ip6_neighbor.c:162
#define VNET_SW_INTERFACE_FLAG_ADMIN_UP
Definition: interface.h:373
u32 max_l3_packet_bytes[VLIB_N_RX_TX]
Definition: interface.h:313
uword unformat_ethernet_address(unformat_input_t *input, va_list *args)
Definition: format.c:187
static void ip_register_add_del_adjacency_callback(ip_lookup_main_t *lm, ip_add_del_adjacency_callback_t cb)
Definition: lookup.h:442
#define ASSERT(truth)
void vlib_worker_thread_barrier_sync(vlib_main_t *vm)
Definition: threads.c:1100
unsigned int u32
Definition: types.h:88
always_inline u64 random_u64(u32 *seed)
64-bit random number generator
Definition: random.h:112
int prefix_option
Definition: ip6_neighbor.c:118
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:87
#define vnet_buffer(b)
Definition: buffer.h:300
ip6_address_t ip6_address
Definition: ip6_neighbor.c:28
ip6_main_t ip6_main
Definition: ip6_forward.c:2490
ip_lookup_main_t lookup_main
Definition: ip6.h:135
u32 n_advertisements_sent
Definition: ip6_neighbor.c:157
static clib_error_t * show_ip6_interface_cmd(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
u8 * format(u8 *s, char *fmt,...)
Definition: format.c:405
f64 min_delay_between_radv
Definition: ip6_neighbor.c:143
#define DEF_MIN_RADV_INTERVAL
Definition: ip6_neighbor.c:130
static_always_inline uword icmp6_router_solicitation(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: ip6_neighbor.c:943
static int ip6_neighbor_sort(void *a1, void *a2)
Definition: ip6_neighbor.c:581
u32 * if_radv_pool_index_by_sw_if_index
Definition: ip6_neighbor.c:189
u16 adv_router_lifetime_in_sec
Definition: ip6_neighbor.c:88
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:225
void vlib_worker_thread_barrier_release(vlib_main_t *vm)
Definition: threads.c:1131
void ip_update_adjacency(ip_lookup_main_t *lm, u32 adj_index, ip_adjacency_t *copy_adj)
Definition: lookup.c:234
mhash_t pending_resolutions_by_address
Definition: ip6_neighbor.c:180
static uword icmp6_neighbor_solicitation(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
#define IP6_ROUTE_FLAG_FIB_INDEX
Definition: ip6.h:330
always_inline ip_adjacency_t * ip_get_adjacency(ip_lookup_main_t *lm, u32 adj_index)
Definition: lookup.h:423
u64 uword
Definition: types.h:112
#define vec_elt(v, i)
Get vector value at index i.
int vnet_set_ip6_ethernet_neighbor(vlib_main_t *vm, u32 sw_if_index, ip6_address_t *a, u8 *link_layer_address, uword n_bytes_link_layer_address, int is_static)
Definition: ip6_neighbor.c:326
u32 ip_version_traffic_class_and_flow_label
Definition: ip6_packet.h:280
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:44
vlib_node_registration_t ip6_icmp_router_solicitation_node
(constructor) VLIB_REGISTER_NODE (ip6_icmp_router_solicitation_node)
#define IP6_NEIGHBOR_FLAG_GLEAN
Definition: ip6_neighbor.c:41
Definition: defs.h:46
void vlib_trace_frame_buffers_only(vlib_main_t *vm, vlib_node_runtime_t *node, u32 *buffers, uword n_buffers, uword next_buffer_stride, uword n_buffer_data_bytes_in_trace)
Definition: trace.c:45
clib_error_t * set_ip6_link_local_address_cmd(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static void ip6_neighbor_send_mldpv2_report(u32 sw_if_index)
unsigned short u16
Definition: types.h:57
vlib_node_registration_t ip6_icmp_neighbor_discovery_event_node
struct ip_adjacency_t::@112::@114 arp
u16 payload_length
Definition: ip6_packet.h:284
ethernet_interface_t * ethernet_get_interface(ethernet_main_t *em, u32 hw_if_index)
Definition: interface.c:451
ip6_neighbor_key_t key
Definition: ip6_neighbor.c:37
always_inline ip_interface_address_t * ip_get_interface_address(ip_lookup_main_t *lm, void *addr_fib)
Definition: lookup.h:506
always_inline void * vlib_process_get_event_data(vlib_main_t *vm, uword *return_event_type_opaque)
Definition: node_funcs.h:366
u32 elog_string(elog_main_t *em, char *fmt,...)
Definition: elog.c:496
void icmp6_register_type(vlib_main_t *vm, icmp6_type_t type, u32 node_index)
Definition: icmp6.c:778
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
double f64
Definition: types.h:140
ip46_address_t next_hop
Definition: lookup.h:177
always_inline void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:197
unsigned char u8
Definition: types.h:56
always_inline vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
u32 heap_handle
Definition: lookup.h:150
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
Definition: vec.h:898
static void ip6_neighbor_add_del_interface_address(ip6_main_t *im, uword opaque, u32 sw_if_index, ip6_address_t *address, u32 address_length, u32 if_address_index, u32 is_delete)
#define ICMP6_ROUTER_DISCOVERY_FLAG_ADDRESS_CONFIG_VIA_DHCP
clib_error_t * set_ip6_link_local_address(vlib_main_t *vm, u32 sw_if_index, ip6_address_t *address, u8 address_length)
static u32 ip6_neighbor_sw_interface_add_del(vnet_main_t *vnm, u32 sw_if_index, u32 is_add)
vlib_node_registration_t ip6_icmp_neighbor_advertisement_node
(constructor) VLIB_REGISTER_NODE (ip6_icmp_neighbor_advertisement_node)
static clib_error_t * ip6_neighbor_sw_interface_up_down(vnet_main_t *vnm, u32 sw_if_index, u32 flags)
Definition: ip6_neighbor.c:231
f64 initial_adverts_interval
Definition: ip6_neighbor.c:153
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:140
vnet_sw_interface_type_t type
Definition: interface.h:368
always_inline vlib_node_runtime_t * vlib_node_get_runtime(vlib_main_t *vm, u32 node_index)
Definition: node_funcs.h:61
always_inline u32 ip6_src_lookup_for_packet(ip6_main_t *im, vlib_buffer_t *b, ip6_header_t *i)
Definition: ip6.h:285
uword node_index
Definition: arp.c:53
#define IP6_ROUTE_FLAG_ADD
Definition: ip6.h:327
u32 if_address_index
Definition: lookup.h:155
#define vec_foreach(var, vec)
Vector iterator.
always_inline void ip6_addr_fib_init(ip6_address_fib_t *addr_fib, ip6_address_t *address, u32 fib_index)
Definition: ip6_packet.h:75
i16 explicit_fib_index
Definition: lookup.h:168
always_inline f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:182
u32 adv_valid_lifetime_in_secs
Definition: ip6_neighbor.c:53
clib_error_t * ip6_add_del_interface_address(vlib_main_t *vm, u32 sw_if_index, ip6_address_t *address, u32 address_length, u32 is_del)
Definition: ip6_forward.c:1155
always_inline void ip6_address_mask(ip6_address_t *a, ip6_address_t *mask)
Definition: ip6_packet.h:201
vhost_vring_addr_t addr
Definition: vhost-user.h:78
#define clib_error_return(e, args...)
Definition: error.h:112
struct _unformat_input_t unformat_input_t
u32 initial_adverts_sent
Definition: ip6_neighbor.c:154
vlib_frame_t * vlib_get_frame_to_node(vlib_main_t *vm, u32 to_node_index)
Definition: main.c:184
#define MAX_INITIAL_RTR_ADVERT_INTERVAL
Definition: ip6_neighbor.c:135
u32 flags
Definition: vhost-user.h:73
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header, unspecified alignment)
Definition: vec.h:443
u32 all_mldv2_routers_adj_index
Definition: ip6_neighbor.c:126
always_inline u64 clib_cpu_time_now(void)
Definition: time.h:71
clib_error_t * ip6_neighbor_cmd(vlib_main_t *vm, unformat_input_t *main_input, vlib_cli_command_t *cmd)
f64 max_rtr_default_lifetime
Definition: ip6_neighbor.c:145
unformat_function_t unformat_line_input
Definition: format.h:279
vlib_node_registration_t ip6_icmp_router_advertisement_node
(constructor) VLIB_REGISTER_NODE (ip6_icmp_router_advertisement_node)
ip6_neighbor_t * neighbor_pool
Definition: ip6_neighbor.c:185
u32 * fib_index_by_sw_if_index
Definition: ip6.h:148
always_inline vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:69
u32 all_routers_adj_index
Definition: ip6_neighbor.c:125
u8 link_layer_address[8]
Definition: ip6_neighbor.c:38
static_always_inline uword icmp6_router_advertisement(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
always_inline uword * mhash_get(mhash_t *h, void *key)
Definition: mhash.h:104
#define MAX_DEF_RTR_LIFETIME
Definition: ip6_neighbor.c:133
u32 adv_link_mtu
Definition: ip6_neighbor.c:93
Definition: defs.h:45
static ip6_neighbor_main_t ip6_neighbor_main
Definition: ip6_neighbor.c:199
ip6_address_t dst_address
Definition: ip6_packet.h:293
int ip6_interface_enabled(vlib_main_t *vm, u32 sw_if_index)
clib_error_t * ip6_set_neighbor_limit(u32 neighbor_limit)
format_function_t format_icmp6_input_trace
Definition: icmp6.h:66