FD.io VPP  v16.06
Vector Packet Processing
ip6_forward.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 /*
16  * ip/ip6_forward.c: IP v6 forwarding
17  *
18  * Copyright (c) 2008 Eliot Dresselhaus
19  *
20  * Permission is hereby granted, free of charge, to any person obtaining
21  * a copy of this software and associated documentation files (the
22  * "Software"), to deal in the Software without restriction, including
23  * without limitation the rights to use, copy, modify, merge, publish,
24  * distribute, sublicense, and/or sell copies of the Software, and to
25  * permit persons to whom the Software is furnished to do so, subject to
26  * the following conditions:
27  *
28  * The above copyright notice and this permission notice shall be
29  * included in all copies or substantial portions of the Software.
30  *
31  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38  */
39 
40 #include <vnet/vnet.h>
41 #include <vnet/ip/ip.h>
42 #include <vnet/ethernet/ethernet.h> /* for ethernet_header_t */
43 #include <vnet/srp/srp.h> /* for srp_hw_interface_class */
44 #include <vppinfra/cache.h>
45 
47 
49 {
50  int i;
52  /* Note: bitmap reversed so this is in fact a longest prefix match */
54  ({
55  int dst_address_length = 128 - i;
56  vec_add1 (im->prefix_lengths_in_search_order, dst_address_length);
57  }));
58 }
59 
60 u32
62 {
63  ip_lookup_main_t * lm = &im->lookup_main;
64  int i, len;
65  int rv;
66  BVT(clib_bihash_kv) kv, value;
67  u64 fib;
68 
70 
71  kv.key[0] = dst->as_u64[0];
72  kv.key[1] = dst->as_u64[1];
73  fib = ((u64)((fib_index))<<32);
74 
75  for (i = 0; i < len; i++)
76  {
77  int dst_address_length = im->prefix_lengths_in_search_order[i];
78  ip6_address_t * mask = &im->fib_masks[dst_address_length];
79 
80  ASSERT(dst_address_length >= 0 && dst_address_length <= 128);
81  //As lengths are decreasing, masks are increasingly specific.
82  kv.key[0] &= mask->as_u64[0];
83  kv.key[1] &= mask->as_u64[1];
84  kv.key[2] = fib | dst_address_length;
85 
86  rv = BV(clib_bihash_search_inline_2)(&im->ip6_lookup_table, &kv, &value);
87  if (rv == 0)
88  return value.value;
89  }
90 
91  return lm->miss_adj_index;
92 }
93 
94 u32 ip6_fib_lookup (ip6_main_t * im, u32 sw_if_index, ip6_address_t * dst)
95 {
96  u32 fib_index = vec_elt (im->fib_index_by_sw_if_index, sw_if_index);
97  return ip6_fib_lookup_with_table (im, fib_index, dst);
98 }
99 
100 void
102 {
103  ip_lookup_main_t * lm = &im->lookup_main;
105  ip_adjacency_t * adj;
106 
107  memset(&a, 0x0, sizeof(ip6_add_del_route_args_t));
108 
109  a.table_index_or_table_id = fib_index;
114 
115  /* Add ff02::1:ff00:0/104 via local route for all tables.
116  This is required for neighbor discovery to work. */
117  adj = ip_add_adjacency (lm, /* template */ 0, /* block size */ 1,
118  &a.adj_index);
120  adj->if_address_index = ~0;
121  adj->rewrite_header.data_bytes = 0;
122 
124 
125  a.dst_address_length = 104;
126  ip6_add_del_route (im, &a);
127 
128  /* Add all-routers multicast address via local route for all tables */
129  adj = ip_add_adjacency (lm, /* template */ 0, /* block size */ 1,
130  &a.adj_index);
132  adj->if_address_index = ~0;
133  adj->rewrite_header.data_bytes = 0;
134 
136  IP6_MULTICAST_SCOPE_link_local,
137  IP6_MULTICAST_GROUP_ID_all_routers);
138 
139  a.dst_address_length = 128;
140  ip6_add_del_route (im, &a);
141 
142  /* Add all-nodes multicast address via local route for all tables */
143  adj = ip_add_adjacency (lm, /* template */ 0, /* block size */ 1,
144  &a.adj_index);
146  adj->if_address_index = ~0;
147  adj->rewrite_header.data_bytes = 0;
148 
150  IP6_MULTICAST_SCOPE_link_local,
151  IP6_MULTICAST_GROUP_ID_all_hosts);
152 
153  a.dst_address_length = 128;
154  ip6_add_del_route (im, &a);
155 
156  /* Add all-mldv2 multicast address via local route for all tables */
157  adj = ip_add_adjacency (lm, /* template */ 0, /* block size */ 1,
158  &a.adj_index);
160  adj->if_address_index = ~0;
161  adj->rewrite_header.data_bytes = 0;
162 
164  IP6_MULTICAST_SCOPE_link_local,
165  IP6_MULTICAST_GROUP_ID_mldv2_routers);
166 
167  a.dst_address_length = 128;
168  ip6_add_del_route (im, &a);
169 }
170 
171 static ip6_fib_t *
173 {
174  ip6_fib_t * fib;
175  hash_set (im->fib_index_by_table_id, table_id, vec_len (im->fibs));
176  vec_add2 (im->fibs, fib, 1);
177  fib->table_id = table_id;
178  fib->index = fib - im->fibs;
180  vnet_ip6_fib_init (im, fib->index);
181  return fib;
182 }
183 
184 ip6_fib_t *
186 {
187  uword * p, fib_index;
188 
189  fib_index = table_index_or_id;
190  if (! (flags & IP6_ROUTE_FLAG_FIB_INDEX))
191  {
192  if (table_index_or_id == ~0) {
193  table_index_or_id = 0;
194  while (hash_get (im->fib_index_by_table_id, table_index_or_id)) {
195  table_index_or_id++;
196  }
197  return create_fib_with_table_id (im, table_index_or_id);
198  }
199 
200  p = hash_get (im->fib_index_by_table_id, table_index_or_id);
201  if (! p)
202  return create_fib_with_table_id (im, table_index_or_id);
203  fib_index = p[0];
204  }
205  return vec_elt_at_index (im->fibs, fib_index);
206 }
207 
209 {
210  ip_lookup_main_t * lm = &im->lookup_main;
211  ip6_fib_t * fib;
212  ip6_address_t dst_address;
213  u32 dst_address_length, adj_index;
214  uword is_del;
215  u32 old_adj_index = ~0;
216  BVT(clib_bihash_kv) kv, value;
217 
219 
220  is_del = (a->flags & IP6_ROUTE_FLAG_DEL) != 0;
221 
222  /* Either create new adjacency or use given one depending on arguments. */
223  if (a->n_add_adj > 0)
224  {
225  ip_add_adjacency (lm, a->add_adj, a->n_add_adj, &adj_index);
226  ip_call_add_del_adjacency_callbacks (lm, adj_index, /* is_del */ 0);
227  }
228  else
229  adj_index = a->adj_index;
230 
231  dst_address = a->dst_address;
232  dst_address_length = a->dst_address_length;
234  a->flags);
235 
236  ASSERT (dst_address_length < ARRAY_LEN (im->fib_masks));
237  ip6_address_mask (&dst_address, &im->fib_masks[dst_address_length]);
238 
239  /* refcount accounting */
240  if (is_del)
241  {
242  ASSERT (im->dst_address_length_refcounts[dst_address_length] > 0);
243  if (--im->dst_address_length_refcounts[dst_address_length] == 0)
244  {
247  128 - dst_address_length, 0);
249  }
250  }
251  else
252  {
253  im->dst_address_length_refcounts[dst_address_length]++;
254 
257  128 - dst_address_length, 1);
259  }
260 
261  kv.key[0] = dst_address.as_u64[0];
262  kv.key[1] = dst_address.as_u64[1];
263  kv.key[2] = ((u64)((fib - im->fibs))<<32) | dst_address_length;
264 
265  if (BV(clib_bihash_search)(&im->ip6_lookup_table, &kv, &value) == 0)
266  old_adj_index = value.value;
267 
268  if (is_del)
269  BV(clib_bihash_add_del) (&im->ip6_lookup_table, &kv, 0 /* is_add */);
270  else
271  {
272  /* Make sure adj index is valid. */
273  if (CLIB_DEBUG > 0)
274  (void) ip_get_adjacency (lm, adj_index);
275 
276  kv.value = adj_index;
277 
278  BV(clib_bihash_add_del) (&im->ip6_lookup_table, &kv, 1 /* is_add */);
279  }
280 
281  /* Avoid spurious reference count increments */
282  if (old_adj_index == adj_index
283  && adj_index != ~0
285  {
286  ip_adjacency_t * adj = ip_get_adjacency (lm, adj_index);
287  if (adj->share_count > 0)
288  adj->share_count --;
289  }
290 
291  /* Delete old adjacency index if present and changed. */
292  {
294  && old_adj_index != ~0
295  && old_adj_index != adj_index)
296  ip_del_adjacency (lm, old_adj_index);
297  }
298 }
299 
300 void
302  u32 flags,
303  ip6_address_t * dst_address,
304  u32 dst_address_length,
305  ip6_address_t * next_hop,
306  u32 next_hop_sw_if_index,
307  u32 next_hop_weight, u32 adj_index,
308  u32 explicit_fib_index)
309 {
310  vnet_main_t * vnm = vnet_get_main();
311  ip_lookup_main_t * lm = &im->lookup_main;
312  u32 fib_index;
313  ip6_fib_t * fib;
314  ip6_address_t masked_dst_address;
315  u32 old_mp_adj_index, new_mp_adj_index;
316  u32 dst_adj_index, nh_adj_index;
317  int rv;
318  ip_adjacency_t * dst_adj;
319  ip_multipath_adjacency_t * old_mp, * new_mp;
320  int is_del = (flags & IP6_ROUTE_FLAG_DEL) != 0;
321  int is_interface_next_hop;
322  clib_error_t * error = 0;
323  uword * nh_result;
324  BVT(clib_bihash_kv) kv, value;
325 
327 
328  if (explicit_fib_index == (u32)~0)
329  fib_index = vec_elt (im->fib_index_by_sw_if_index, next_hop_sw_if_index);
330  else
331  fib_index = explicit_fib_index;
332 
333  fib = vec_elt_at_index (im->fibs, fib_index);
334 
335  /* Lookup next hop to be added or deleted. */
336  is_interface_next_hop = ip6_address_is_zero (next_hop);
337  if (adj_index == (u32)~0)
338  {
339  if (is_interface_next_hop)
340  {
342  next_hop_sw_if_index);
343  if (nh_result)
344  nh_adj_index = *nh_result;
345  else
346  {
347  ip_adjacency_t * adj;
348  adj = ip_add_adjacency (lm, /* template */ 0, /* block size */ 1,
349  &nh_adj_index);
351  next_hop_sw_if_index, ~0);
353  (lm, next_hop_sw_if_index, /* is_del */ 0);
355  next_hop_sw_if_index, nh_adj_index);
356  }
357  }
358  else
359  {
360  /* Look for the interface /128 route */
361  kv.key[0] = next_hop->as_u64[0];
362  kv.key[1] = next_hop->as_u64[1];
363  kv.key[2] = ((u64)((fib - im->fibs))<<32) | 128;
364 
365  if (BV(clib_bihash_search)(&im->ip6_lookup_table, &kv, &value) < 0)
366  {
367  ip_adjacency_t * adj;
368  nh_adj_index = ip6_fib_lookup_with_table (im, fib_index, next_hop);
369  adj = ip_get_adjacency (lm, nh_adj_index);
370  /* if ND interface adjacencty is present, we need to
371  install ND adjaceny for specific next hop */
373  adj->arp.next_hop.ip6.as_u64[0] == 0 &&
374  adj->arp.next_hop.ip6.as_u64[1] == 0)
375  {
376  nh_adj_index = vnet_ip6_neighbor_glean_add(fib_index, next_hop);
377  }
378  else
379  {
380  ip_adjacency_t add_adj;
381  memset (&add_adj, 0, sizeof(add_adj));
382  add_adj.n_adj = 1;
384  add_adj.indirect.next_hop.ip6.as_u64[0] = next_hop->as_u64[0];
385  add_adj.indirect.next_hop.ip6.as_u64[1] = next_hop->as_u64[1];
386  add_adj.explicit_fib_index = explicit_fib_index;
387  ip_add_adjacency (lm, &add_adj, 1, &nh_adj_index);
388  }
389  }
390  else
391  nh_adj_index = value.value;
392 
393  }
394  }
395  else
396  {
397  /* Look for the interface /128 route */
398  kv.key[0] = next_hop->as_u64[0];
399  kv.key[1] = next_hop->as_u64[1];
400  kv.key[2] = ((u64)((fib - im->fibs))<<32) | 128;
401 
402  if (BV(clib_bihash_search)(&im->ip6_lookup_table, &kv, &value) < 0)
403  {
404  vnm->api_errno = VNET_API_ERROR_UNKNOWN_DESTINATION;
405  error = clib_error_return (0, "next-hop %U/128 not in FIB",
406  format_ip6_address, next_hop);
407  goto done;
408  }
409 
410  nh_adj_index = value.value;
411  }
412 
413  ASSERT (dst_address_length < ARRAY_LEN (im->fib_masks));
414  masked_dst_address = dst_address[0];
415  ip6_address_mask (&masked_dst_address, &im->fib_masks[dst_address_length]);
416 
417  kv.key[0] = masked_dst_address.as_u64[0];
418  kv.key[1] = masked_dst_address.as_u64[1];
419  kv.key[2] = ((u64)((fib - im->fibs))<<32) | dst_address_length;
420 
421  rv = BV(clib_bihash_search)(&im->ip6_lookup_table, &kv, &value);
422 
423  if (rv == 0)
424  {
425  dst_adj_index = value.value;
426  dst_adj = ip_get_adjacency (lm, dst_adj_index);
427  }
428  else
429  {
430  /* For deletes destination must be known. */
431  if (is_del)
432  {
433  vnm->api_errno = VNET_API_ERROR_UNKNOWN_DESTINATION;
434  error = clib_error_return (0, "unknown destination %U/%d",
435  format_ip6_address, dst_address,
436  dst_address_length);
437  goto done;
438  }
439 
440  dst_adj_index = ~0;
441  dst_adj = 0;
442  }
443 
444  /* Ignore adds of X/128 with next hop of X. */
445  if (! is_del
446  && dst_address_length == 128
447  && ip6_address_is_equal (dst_address, next_hop))
448  {
449  vnm->api_errno = VNET_API_ERROR_PREFIX_MATCHES_NEXT_HOP;
450  error = clib_error_return (0, "prefix matches next hop %U/%d",
451  format_ip6_address, dst_address,
452  dst_address_length);
453  goto done;
454  }
455 
456  /* Destination is not known and default weight is set so add route
457  to existing non-multipath adjacency */
458  if (dst_adj_index == ~0 && next_hop_weight == 1 && next_hop_sw_if_index == ~0)
459  {
460  /* create new adjacency */
462  a.table_index_or_table_id = fib_index;
468  a.dst_address = dst_address[0];
469  a.dst_address_length = dst_address_length;
470  a.adj_index = nh_adj_index;
471  a.add_adj = 0;
472  a.n_add_adj = 0;
473 
474  ip6_add_del_route (im, &a);
475  goto done;
476  }
477 
478  old_mp_adj_index = dst_adj ? dst_adj->heap_handle : ~0;
479 
481  (lm, is_del,
482  dst_adj ? dst_adj->heap_handle : ~0,
483  nh_adj_index,
484  next_hop_weight,
485  &new_mp_adj_index))
486  {
487  vnm->api_errno = VNET_API_ERROR_NEXT_HOP_NOT_FOUND_MP;
488  error = clib_error_return
489  (0, "requested deleting next-hop %U not found in multi-path",
490  format_ip6_address, next_hop);
491  goto done;
492  }
493 
494  old_mp = new_mp = 0;
495  if (old_mp_adj_index != ~0)
496  old_mp = vec_elt_at_index (lm->multipath_adjacencies, old_mp_adj_index);
497  if (new_mp_adj_index != ~0)
498  new_mp = vec_elt_at_index (lm->multipath_adjacencies, new_mp_adj_index);
499 
500  if (old_mp != new_mp)
501  {
503  a.table_index_or_table_id = fib_index;
507  | (flags & IP6_ROUTE_FLAG_NO_REDISTRIBUTE));
508  a.dst_address = dst_address[0];
509  a.dst_address_length = dst_address_length;
510  a.adj_index = new_mp ? new_mp->adj_index : dst_adj_index;
511  a.add_adj = 0;
512  a.n_add_adj = 0;
513 
514  ip6_add_del_route (im, &a);
515  }
516 
517  done:
518  if (error)
519  clib_error_report (error);
520 }
521 
522 u32
524  u32 table_index_or_table_id,
525  u32 flags,
526  ip6_address_t * address,
527  u32 address_length)
528 {
529  ip6_fib_t * fib = find_ip6_fib_by_table_index_or_id (im, table_index_or_table_id, flags);
530  ip6_address_t masked_address;
531  BVT(clib_bihash_kv) kv, value;
532 
533  ASSERT (address_length < ARRAY_LEN (im->fib_masks));
534  clib_memcpy (&masked_address, address, sizeof (masked_address));
535  ip6_address_mask (&masked_address, &im->fib_masks[address_length]);
536 
537  kv.key[0] = masked_address.as_u64[0];
538  kv.key[1] = masked_address.as_u64[1];
539  kv.key[2] = ((u64)((fib - im->fibs))<<32) | address_length;
540 
541  if (BV(clib_bihash_search)(&im->ip6_lookup_table, &kv, &value) == 0)
542  return (value.value);
543  return 0;
544 }
545 
546 void
548  u32 table_index_or_table_id,
549  u32 flags,
550  ip6_address_t * dst_address,
551  u32 address_length,
552  ip6_address_t ** results,
553  u8 ** result_lengths)
554 {
555  ip6_fib_t * fib =
556  find_ip6_fib_by_table_index_or_id (im, table_index_or_table_id, flags);
557  BVT(clib_bihash) * h = &im->ip6_lookup_table;
558  BVT(clib_bihash_value) * v;
560  int i, j, k;
561 
562  if (*results)
563  _vec_len (*results) = 0;
564  if (*result_lengths)
565  _vec_len (*result_lengths) = 0;
566 
567  /* Walk the table looking for routes which match the supplied address */
568  for (i = 0; i < h->nbuckets; i++)
569  {
570  b = &h->buckets [i];
571  if (b->offset == 0)
572  continue;
573 
574  v = BV(clib_bihash_get_value) (h, b->offset);
575  for (j = 0; j < (1<<b->log2_pages); j++)
576  {
577  for (k = 0; k < BIHASH_KVP_PER_PAGE; k++)
578  {
579  if (BV(clib_bihash_is_free)(&v->kvp[k]))
580  continue;
581 
582  if ((v->kvp[k].key[2]
583  == (((u64)((fib - im->fibs))<<32) | address_length))
585  (im, dst_address, (ip6_address_t *) &v->kvp[k],
586  address_length))
587  {
588  ip6_address_t * a;
589 
590  a = (ip6_address_t *)(&v->kvp[k]);
591 
592  vec_add1 (*results, a[0]);
593  vec_add1 (*result_lengths, address_length);
594  }
595  }
596  v++;
597  }
598  }
599 }
600 
602  u32 table_index_or_table_id,
603  u32 flags)
604 {
605 #if SOONE
606  ip6_fib_t * fib
607  = find_ip6_fib_by_table_index_or_id (im, table_index_or_table_id, flags);
608 #endif
609  ip_lookup_main_t * lm = &im->lookup_main;
610 
611  if (lm->n_adjacency_remaps == 0)
612  return;
613 
614  clib_warning ("unimplemented, please report to vpp-dev@cisco.com");
615 
616  /* All remaps have been performed. */
617  lm->n_adjacency_remaps = 0;
618 }
619 
621  u32 table_index_or_table_id,
622  u32 flags,
623  ip6_address_t * address,
624  u32 address_length)
625 {
626  /* $$$$ static may be OK - this should happen only on thread 0 */
627  static ip6_address_t * matching_addresses;
628  static u8 * matching_address_lengths;
629  u32 l, i;
631 
633 
635  a.table_index_or_table_id = table_index_or_table_id;
636  a.adj_index = ~0;
637  a.add_adj = 0;
638  a.n_add_adj = 0;
639 
640  for (l = address_length + 1; l <= 128; l++)
641  {
642  ip6_foreach_matching_route (im, table_index_or_table_id, flags,
643  address,
644  l,
645  &matching_addresses,
646  &matching_address_lengths);
647  for (i = 0; i < vec_len (matching_addresses); i++)
648  {
649  a.dst_address = matching_addresses[i];
650  a.dst_address_length = matching_address_lengths[i];
651  ip6_add_del_route (im, &a);
652  }
653  }
654 
655  ip6_maybe_remap_adjacencies (im, table_index_or_table_id, flags);
656 }
657 
658 void
660  vlib_node_runtime_t * node,
661  vlib_frame_t * frame,
662  vlib_rx_or_tx_t which_adj_index);
663 
666  vlib_node_runtime_t * node,
667  vlib_frame_t * frame,
668  int is_indirect)
669 {
670  ip6_main_t * im = &ip6_main;
671  ip_lookup_main_t * lm = &im->lookup_main;
673  u32 n_left_from, n_left_to_next, * from, * to_next;
674  ip_lookup_next_t next;
675  u32 cpu_index = os_get_cpu_number();
676 
677  from = vlib_frame_vector_args (frame);
678  n_left_from = frame->n_vectors;
679  next = node->cached_next_index;
680 
681  while (n_left_from > 0)
682  {
683  vlib_get_next_frame (vm, node, next,
684  to_next, n_left_to_next);
685 
686  while (n_left_from >= 4 && n_left_to_next >= 2)
687  {
688  vlib_buffer_t * p0, * p1;
689  u32 pi0, pi1, adj_index0, adj_index1, wrong_next;
690  ip_lookup_next_t next0, next1;
691  ip6_header_t * ip0, * ip1;
692  ip_adjacency_t * adj0, * adj1;
693  ip6_address_t * dst_addr0, * dst_addr1;
694  u32 fib_index0, fib_index1;
695  u32 flow_hash_config0, flow_hash_config1;
696 
697  /* Prefetch next iteration. */
698  {
699  vlib_buffer_t * p2, * p3;
700 
701  p2 = vlib_get_buffer (vm, from[2]);
702  p3 = vlib_get_buffer (vm, from[3]);
703 
704  vlib_prefetch_buffer_header (p2, LOAD);
705  vlib_prefetch_buffer_header (p3, LOAD);
706  CLIB_PREFETCH (p2->data, sizeof (ip0[0]), LOAD);
707  CLIB_PREFETCH (p3->data, sizeof (ip0[0]), LOAD);
708  }
709 
710  pi0 = to_next[0] = from[0];
711  pi1 = to_next[1] = from[1];
712 
713  p0 = vlib_get_buffer (vm, pi0);
714  p1 = vlib_get_buffer (vm, pi1);
715 
716  ip0 = vlib_buffer_get_current (p0);
717  ip1 = vlib_buffer_get_current (p1);
718 
719  if (is_indirect)
720  {
721  ip_adjacency_t * iadj0, * iadj1;
722  iadj0 = ip_get_adjacency (lm, vnet_buffer(p0)->ip.adj_index[VLIB_TX]);
723  iadj1 = ip_get_adjacency (lm, vnet_buffer(p1)->ip.adj_index[VLIB_TX]);
724  dst_addr0 = &iadj0->indirect.next_hop.ip6;
725  dst_addr1 = &iadj1->indirect.next_hop.ip6;
726  }
727  else
728  {
729  dst_addr0 = &ip0->dst_address;
730  dst_addr1 = &ip1->dst_address;
731  }
732 
733  fib_index0 = vec_elt (im->fib_index_by_sw_if_index, vnet_buffer (p0)->sw_if_index[VLIB_RX]);
734  fib_index1 = vec_elt (im->fib_index_by_sw_if_index, vnet_buffer (p1)->sw_if_index[VLIB_RX]);
735 
736  fib_index0 = (vnet_buffer(p0)->sw_if_index[VLIB_TX] == (u32)~0) ?
737  fib_index0 : vnet_buffer(p0)->sw_if_index[VLIB_TX];
738  fib_index1 = (vnet_buffer(p1)->sw_if_index[VLIB_TX] == (u32)~0) ?
739  fib_index1 : vnet_buffer(p1)->sw_if_index[VLIB_TX];
740 
741  adj_index0 = ip6_fib_lookup_with_table (im, fib_index0, dst_addr0);
742  adj_index1 = ip6_fib_lookup_with_table (im, fib_index1, dst_addr1);
743 
744  adj0 = ip_get_adjacency (lm, adj_index0);
745  adj1 = ip_get_adjacency (lm, adj_index1);
746 
747  if (PREDICT_FALSE (adj0->explicit_fib_index != ~0))
748  {
749  adj_index0 = ip6_fib_lookup_with_table
750  (im, adj0->explicit_fib_index, dst_addr0);
751  adj0 = ip_get_adjacency (lm, adj_index0);
752  }
753  if (PREDICT_FALSE (adj1->explicit_fib_index != ~0))
754  {
755  adj_index1 = ip6_fib_lookup_with_table
756  (im, adj1->explicit_fib_index, dst_addr1);
757  adj1 = ip_get_adjacency (lm, adj_index1);
758  }
759 
760  next0 = adj0->lookup_next_index;
761  next1 = adj1->lookup_next_index;
762 
763  /* Process hop-by-hop options if present */
764  next0 = (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS) ?
766  next1 = (ip1->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS) ?
768 
769  vnet_buffer (p0)->ip.flow_hash =
770  vnet_buffer(p1)->ip.flow_hash = 0;
771 
772  if (PREDICT_FALSE(adj0->n_adj > 1))
773  {
774  flow_hash_config0 =
775  vec_elt_at_index (im->fibs,fib_index0)->flow_hash_config;
776  vnet_buffer (p0)->ip.flow_hash =
777  ip6_compute_flow_hash (ip0, flow_hash_config0);
778  }
779 
780  if (PREDICT_FALSE(adj1->n_adj > 1))
781  {
782  flow_hash_config1 =
783  vec_elt_at_index (im->fibs,fib_index0)->flow_hash_config;
784 
785  vnet_buffer (p1)->ip.flow_hash =
786  ip6_compute_flow_hash (ip1, flow_hash_config1);
787  }
788 
789  ASSERT (adj0->n_adj > 0);
790  ASSERT (adj1->n_adj > 0);
791  ASSERT (is_pow2 (adj0->n_adj));
792  ASSERT (is_pow2 (adj1->n_adj));
793  adj_index0 += (vnet_buffer (p0)->ip.flow_hash & (adj0->n_adj - 1));
794  adj_index1 += (vnet_buffer (p1)->ip.flow_hash & (adj1->n_adj - 1));
795 
796  vnet_buffer (p0)->ip.adj_index[VLIB_TX] = adj_index0;
797  vnet_buffer (p1)->ip.adj_index[VLIB_TX] = adj_index1;
798 
800  (cm, cpu_index, adj_index0, 1,
801  vlib_buffer_length_in_chain (vm, p0));
803  (cm, cpu_index, adj_index1, 1,
804  vlib_buffer_length_in_chain (vm, p1));
805 
806  from += 2;
807  to_next += 2;
808  n_left_to_next -= 2;
809  n_left_from -= 2;
810 
811  wrong_next = (next0 != next) + 2*(next1 != next);
812  if (PREDICT_FALSE (wrong_next != 0))
813  {
814  switch (wrong_next)
815  {
816  case 1:
817  /* A B A */
818  to_next[-2] = pi1;
819  to_next -= 1;
820  n_left_to_next += 1;
821  vlib_set_next_frame_buffer (vm, node, next0, pi0);
822  break;
823 
824  case 2:
825  /* A A B */
826  to_next -= 1;
827  n_left_to_next += 1;
828  vlib_set_next_frame_buffer (vm, node, next1, pi1);
829  break;
830 
831  case 3:
832  /* A B C */
833  to_next -= 2;
834  n_left_to_next += 2;
835  vlib_set_next_frame_buffer (vm, node, next0, pi0);
836  vlib_set_next_frame_buffer (vm, node, next1, pi1);
837  if (next0 == next1)
838  {
839  /* A B B */
840  vlib_put_next_frame (vm, node, next, n_left_to_next);
841  next = next1;
842  vlib_get_next_frame (vm, node, next, to_next, n_left_to_next);
843  }
844  }
845  }
846  }
847 
848  while (n_left_from > 0 && n_left_to_next > 0)
849  {
850  vlib_buffer_t * p0;
851  ip6_header_t * ip0;
852  u32 pi0, adj_index0;
853  ip_lookup_next_t next0;
854  ip_adjacency_t * adj0;
855  ip6_address_t * dst_addr0;
856  u32 fib_index0, flow_hash_config0;
857 
858  pi0 = from[0];
859  to_next[0] = pi0;
860 
861  p0 = vlib_get_buffer (vm, pi0);
862 
863  ip0 = vlib_buffer_get_current (p0);
864 
865  if (is_indirect)
866  {
867  ip_adjacency_t * iadj0;
868  iadj0 = ip_get_adjacency (lm, vnet_buffer(p0)->ip.adj_index[VLIB_TX]);
869  dst_addr0 = &iadj0->indirect.next_hop.ip6;
870  }
871  else
872  {
873  dst_addr0 = &ip0->dst_address;
874  }
875 
876  fib_index0 = vec_elt (im->fib_index_by_sw_if_index, vnet_buffer (p0)->sw_if_index[VLIB_RX]);
877  fib_index0 = (vnet_buffer(p0)->sw_if_index[VLIB_TX] == (u32)~0) ?
878  fib_index0 : vnet_buffer(p0)->sw_if_index[VLIB_TX];
879 
880  flow_hash_config0 =
881  vec_elt_at_index (im->fibs,fib_index0)->flow_hash_config;
882 
883  adj_index0 = ip6_fib_lookup_with_table (im, fib_index0, dst_addr0);
884 
885  adj0 = ip_get_adjacency (lm, adj_index0);
886 
887  if (PREDICT_FALSE (adj0->explicit_fib_index != ~0))
888  {
889  adj_index0 = ip6_fib_lookup_with_table
890  (im, adj0->explicit_fib_index, dst_addr0);
891  adj0 = ip_get_adjacency (lm, adj_index0);
892  }
893 
894  next0 = adj0->lookup_next_index;
895  next0 = (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS) ?
897 
898  vnet_buffer (p0)->ip.flow_hash = 0;
899 
900  if (PREDICT_FALSE(adj0->n_adj > 1))
901  {
902  flow_hash_config0 =
903  vec_elt_at_index (im->fibs,fib_index0)->flow_hash_config;
904  vnet_buffer (p0)->ip.flow_hash =
905  ip6_compute_flow_hash (ip0, flow_hash_config0);
906  }
907 
908  ASSERT (adj0->n_adj > 0);
909  ASSERT (is_pow2 (adj0->n_adj));
910  adj_index0 += (vnet_buffer (p0)->ip.flow_hash & (adj0->n_adj - 1));
911 
912  vnet_buffer (p0)->ip.adj_index[VLIB_TX] = adj_index0;
913 
915  (cm, cpu_index, adj_index0, 1,
916  vlib_buffer_length_in_chain (vm, p0));
917 
918  from += 1;
919  to_next += 1;
920  n_left_to_next -= 1;
921  n_left_from -= 1;
922 
923  if (PREDICT_FALSE (next0 != next))
924  {
925  n_left_to_next += 1;
926  vlib_put_next_frame (vm, node, next, n_left_to_next);
927  next = next0;
928  vlib_get_next_frame (vm, node, next,
929  to_next, n_left_to_next);
930  to_next[0] = pi0;
931  to_next += 1;
932  n_left_to_next -= 1;
933  }
934  }
935 
936  vlib_put_next_frame (vm, node, next, n_left_to_next);
937  }
938 
939  if (node->flags & VLIB_NODE_FLAG_TRACE)
940  ip6_forward_next_trace(vm, node, frame, VLIB_TX);
941 
942  return frame->n_vectors;
943 }
944 
946  ip_adjacency_t * adj,
947  u32 sw_if_index,
948  u32 if_address_index)
949 {
950  vnet_hw_interface_t * hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
952  u32 node_index;
953 
955  || hw->hw_class_index == srp_hw_interface_class.index)
956  {
957  n = IP_LOOKUP_NEXT_ARP;
958  node_index = ip6_discover_neighbor_node.index;
959  adj->if_address_index = if_address_index;
960  adj->arp.next_hop.ip6.as_u64[0] = 0;
961  adj->arp.next_hop.ip6.as_u64[1] = 0;
962  }
963  else
964  {
966  node_index = ip6_rewrite_node.index;
967  }
968 
969  adj->lookup_next_index = n;
970  adj->explicit_fib_index = ~0;
971 
973  (vnm,
974  VNET_L3_PACKET_TYPE_IP6,
975  sw_if_index,
976  node_index,
978  &adj->rewrite_header,
979  sizeof (adj->rewrite_data));
980 }
981 
982 static void
984  ip6_main_t * im, u32 fib_index,
986 {
987  ip_lookup_main_t * lm = &im->lookup_main;
988  ip_adjacency_t * adj;
991  vnet_hw_interface_t * hw_if = vnet_get_sup_hw_interface (vnm, sw_if_index);
992  u32 classify_table_index;
993 
994  /* Add e.g. 1.0.0.0/8 as interface route (arp for Ethernet). */
995  x.table_index_or_table_id = fib_index;
999  x.dst_address = address[0];
1001  x.n_add_adj = 0;
1002  x.add_adj = 0;
1003 
1004  a->neighbor_probe_adj_index = ~0;
1005  if (a->address_length < 128)
1006  {
1007  adj = ip_add_adjacency (lm, /* template */ 0, /* block size */ 1,
1008  &x.adj_index);
1009  ip6_adjacency_set_interface_route (vnm, adj, sw_if_index, a - lm->if_address_pool);
1010  ip_call_add_del_adjacency_callbacks (lm, x.adj_index, /* is_del */ 0);
1011  ip6_add_del_route (im, &x);
1013  }
1014 
1015  /* Add e.g. ::1/128 as local to this host. */
1016  adj = ip_add_adjacency (lm, /* template */ 0, /* block size */ 1,
1017  &x.adj_index);
1018 
1019  classify_table_index = ~0;
1020  if (sw_if_index < vec_len (lm->classify_table_index_by_sw_if_index))
1021  classify_table_index = lm->classify_table_index_by_sw_if_index [sw_if_index];
1022  if (classify_table_index != (u32) ~0)
1023  {
1025  adj->classify.table_index = classify_table_index;
1026  }
1027  else
1029 
1030  adj->if_address_index = a - lm->if_address_pool;
1031  adj->rewrite_header.sw_if_index = sw_if_index;
1032  adj->rewrite_header.max_l3_packet_bytes = hw_if->max_l3_packet_bytes[VLIB_RX];
1033  adj->rewrite_header.data_bytes = 0;
1034  ip_call_add_del_adjacency_callbacks (lm, x.adj_index, /* is_del */ 0);
1035  x.dst_address_length = 128;
1036  ip6_add_del_route (im, &x);
1037 }
1038 
1039 static void
1041  ip6_address_t * address, u32 address_length)
1042 {
1044 
1045  /* Add e.g. 1.0.0.0/8 as interface route (arp for Ethernet). */
1046  x.table_index_or_table_id = fib_index;
1050  x.dst_address = address[0];
1051  x.dst_address_length = address_length;
1052  x.adj_index = ~0;
1053  x.n_add_adj = 0;
1054  x.add_adj = 0;
1055 
1056  if (address_length < 128)
1057  {
1058  /* Don't wipe out fe80::0/64 */
1059  if (address_length != 64 ||
1060  address[0].as_u64[0] != clib_net_to_host_u64(0xfe80000000000000ULL))
1061  ip6_add_del_route (im, &x);
1062  }
1063 
1064  x.dst_address_length = 128;
1065  ip6_add_del_route (im, &x);
1066 
1068  fib_index,
1070  address,
1071  address_length);
1072 }
1073 
1074 typedef struct {
1079 
1080 static clib_error_t *
1082  u32 sw_if_index,
1083  ip6_address_t * new_address,
1084  u32 new_length,
1085  u32 redistribute,
1086  u32 insert_routes,
1087  u32 is_del);
1088 
1089 static clib_error_t *
1091  u32 sw_if_index,
1092  ip6_address_t * address,
1093  u32 address_length,
1094  u32 redistribute,
1095  u32 insert_routes,
1096  u32 is_del)
1097 {
1098  vnet_main_t * vnm = vnet_get_main();
1099  ip6_main_t * im = &ip6_main;
1100  ip_lookup_main_t * lm = &im->lookup_main;
1101  clib_error_t * error;
1102  u32 if_address_index;
1103  ip6_address_fib_t ip6_af, * addr_fib = 0;
1104 
1105  vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1106  ip6_addr_fib_init (&ip6_af, address,
1107  vec_elt (im->fib_index_by_sw_if_index, sw_if_index));
1108  vec_add1 (addr_fib, ip6_af);
1109 
1110  {
1111  uword elts_before = pool_elts (lm->if_address_pool);
1112 
1114  (lm,
1115  sw_if_index,
1116  addr_fib,
1117  address_length,
1118  is_del,
1119  &if_address_index);
1120  if (error)
1121  goto done;
1122 
1123  /* Pool did not grow: add duplicate address. */
1124  if (elts_before == pool_elts (lm->if_address_pool))
1125  goto done;
1126  }
1127 
1128  if (vnet_sw_interface_is_admin_up (vnm, sw_if_index) && insert_routes)
1129  {
1130  if (is_del)
1131  ip6_del_interface_routes (im, ip6_af.fib_index, address,
1132  address_length);
1133 
1134  else
1135  ip6_add_interface_routes (vnm, sw_if_index,
1136  im, ip6_af.fib_index,
1137  pool_elt_at_index (lm->if_address_pool, if_address_index));
1138  }
1139 
1140  {
1143  cb->function (im, cb->function_opaque, sw_if_index,
1144  address, address_length,
1145  if_address_index,
1146  is_del);
1147  }
1148 
1149  done:
1150  vec_free (addr_fib);
1151  return error;
1152 }
1153 
1154 clib_error_t *
1156  ip6_address_t * address, u32 address_length,
1157  u32 is_del)
1158 {
1160  (vm, sw_if_index, address, address_length,
1161  /* redistribute */ 1,
1162  /* insert_routes */ 1,
1163  is_del);
1164 }
1165 
1166 clib_error_t *
1168  u32 sw_if_index,
1169  u32 flags)
1170 {
1171  ip6_main_t * im = &ip6_main;
1173  ip6_address_t * a;
1174  u32 is_admin_up, fib_index;
1175 
1176  /* Fill in lookup tables with default table (0). */
1177  vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
1178 
1180 
1181  is_admin_up = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) != 0;
1182 
1183  fib_index = vec_elt (im->fib_index_by_sw_if_index, sw_if_index);
1184 
1185  foreach_ip_interface_address (&im->lookup_main, ia, sw_if_index,
1186  0 /* honor unnumbered */,
1187  ({
1188  a = ip_interface_address_get_address (&im->lookup_main, ia);
1189  if (is_admin_up)
1190  ip6_add_interface_routes (vnm, sw_if_index,
1191  im, fib_index,
1192  ia);
1193  else
1194  ip6_del_interface_routes (im, fib_index,
1195  a, ia->address_length);
1196  }));
1197 
1198  return 0;
1199 }
1200 
1202 
1203 clib_error_t *
1205  u32 sw_if_index,
1206  u32 is_add)
1207 {
1208  vlib_main_t * vm = vnm->vlib_main;
1209  ip6_main_t * im = &ip6_main;
1210  ip_lookup_main_t * lm = &im->lookup_main;
1211  u32 ci, cast;
1212 
1213  for (cast = 0; cast < VNET_N_CAST; cast++)
1214  {
1215  ip_config_main_t * cm = &lm->rx_config_mains[cast];
1216  vnet_config_main_t * vcm = &cm->config_main;
1217 
1218  /* FIXME multicast. */
1219  if (! vcm->node_index_by_feature_index)
1220  {
1221  char * start_nodes[] = { "ip6-input", };
1222  char * feature_nodes[] = {
1223  [IP6_RX_FEATURE_CHECK_ACCESS] = "ip6-inacl",
1224  [IP6_RX_FEATURE_IPSEC] = "ipsec-input-ip6",
1225  [IP6_RX_FEATURE_L2TPV3] = "l2tp-decap",
1226  [IP6_RX_FEATURE_VPATH] = "vpath-input-ip6",
1227  [IP6_RX_FEATURE_LOOKUP] = "ip6-lookup",
1228  };
1229  vnet_config_init (vm, vcm,
1230  start_nodes, ARRAY_LEN (start_nodes),
1231  feature_nodes, ARRAY_LEN (feature_nodes));
1232  }
1233 
1235  ci = cm->config_index_by_sw_if_index[sw_if_index];
1236 
1237  if (is_add)
1238  ci = vnet_config_add_feature (vm, vcm,
1239  ci,
1241  /* config data */ 0,
1242  /* # bytes of config data */ 0);
1243  else
1244  ci = vnet_config_del_feature (vm, vcm,
1245  ci,
1247  /* config data */ 0,
1248  /* # bytes of config data */ 0);
1249 
1250  cm->config_index_by_sw_if_index[sw_if_index] = ci;
1251  }
1252  return /* no error */ 0;
1253 }
1254 
1256 
1257 static uword
1259  vlib_node_runtime_t * node,
1260  vlib_frame_t * frame)
1261 {
1262  return ip6_lookup_inline (vm, node, frame, /* is_indirect */ 0);
1263 }
1264 
1265 static u8 * format_ip6_lookup_trace (u8 * s, va_list * args);
1266 
1268  .function = ip6_lookup,
1269  .name = "ip6-lookup",
1270  .vector_size = sizeof (u32),
1271 
1272  .format_trace = format_ip6_lookup_trace,
1273 
1274  .n_next_nodes = IP_LOOKUP_N_NEXT,
1275  .next_nodes = IP6_LOOKUP_NEXT_NODES,
1276 };
1277 
1278 static uword
1280  vlib_node_runtime_t * node,
1281  vlib_frame_t * frame)
1282 {
1283  return ip6_lookup_inline (vm, node, frame, /* is_indirect */ 1);
1284 }
1285 
1286 
1288  .function = ip6_indirect,
1289  .name = "ip6-indirect",
1290  .vector_size = sizeof (u32),
1291 
1292  .format_trace = format_ip6_lookup_trace,
1293 
1294  .n_next_nodes = IP_LOOKUP_N_NEXT,
1295  .next_nodes = IP6_LOOKUP_NEXT_NODES,
1296 };
1297 
1298 typedef struct {
1299  /* Adjacency taken. */
1303 
1304  /* Packet data, possibly *after* rewrite. */
1305  u8 packet_data[128 - 1*sizeof(u32)];
1307 
1308 static u8 * format_ip6_forward_next_trace (u8 * s, va_list * args)
1309 {
1310  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1311  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1312  ip6_forward_next_trace_t * t = va_arg (*args, ip6_forward_next_trace_t *);
1313  uword indent = format_get_indent (s);
1314 
1315  s = format(s, "%U%U",
1316  format_white_space, indent,
1318  return s;
1319 }
1320 
1321 static u8 * format_ip6_lookup_trace (u8 * s, va_list * args)
1322 {
1323  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1324  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1325  ip6_forward_next_trace_t * t = va_arg (*args, ip6_forward_next_trace_t *);
1326  vnet_main_t * vnm = vnet_get_main();
1327  ip6_main_t * im = &ip6_main;
1328  uword indent = format_get_indent (s);
1329 
1330  s = format (s, "fib %d adj-idx %d : %U flow hash: 0x%08x",
1332  vnm, &im->lookup_main, t->adj_index, t->flow_hash);
1333  s = format(s, "\n%U%U",
1334  format_white_space, indent,
1336  return s;
1337 }
1338 
1339 
1340 static u8 * format_ip6_rewrite_trace (u8 * s, va_list * args)
1341 {
1342  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1343  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1344  ip6_forward_next_trace_t * t = va_arg (*args, ip6_forward_next_trace_t *);
1345  vnet_main_t * vnm = vnet_get_main();
1346  ip6_main_t * im = &ip6_main;
1347  uword indent = format_get_indent (s);
1348 
1349  s = format (s, "tx_sw_if_index %d adj-idx %d : %U flow hash: 0x%08x",
1351  vnm, &im->lookup_main, t->adj_index, t->flow_hash);
1352  s = format (s, "\n%U%U",
1353  format_white_space, indent,
1355  vnm, &im->lookup_main, t->adj_index,
1356  t->packet_data, sizeof (t->packet_data));
1357  return s;
1358 }
1359 
1360 /* Common trace function for all ip6-forward next nodes. */
1361 void
1363  vlib_node_runtime_t * node,
1364  vlib_frame_t * frame,
1365  vlib_rx_or_tx_t which_adj_index)
1366 {
1367  u32 * from, n_left;
1368  ip6_main_t * im = &ip6_main;
1369 
1370  n_left = frame->n_vectors;
1371  from = vlib_frame_vector_args (frame);
1372 
1373  while (n_left >= 4)
1374  {
1375  u32 bi0, bi1;
1376  vlib_buffer_t * b0, * b1;
1377  ip6_forward_next_trace_t * t0, * t1;
1378 
1379  /* Prefetch next iteration. */
1380  vlib_prefetch_buffer_with_index (vm, from[2], LOAD);
1381  vlib_prefetch_buffer_with_index (vm, from[3], LOAD);
1382 
1383  bi0 = from[0];
1384  bi1 = from[1];
1385 
1386  b0 = vlib_get_buffer (vm, bi0);
1387  b1 = vlib_get_buffer (vm, bi1);
1388 
1389  if (b0->flags & VLIB_BUFFER_IS_TRACED)
1390  {
1391  t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
1392  t0->adj_index = vnet_buffer (b0)->ip.adj_index[which_adj_index];
1393  t0->flow_hash = vnet_buffer (b0)->ip.flow_hash;
1394  t0->fib_index = (vnet_buffer(b0)->sw_if_index[VLIB_TX] != (u32)~0) ?
1395  vnet_buffer(b0)->sw_if_index[VLIB_TX] :
1397  vnet_buffer(b0)->sw_if_index[VLIB_RX]);
1398 
1399  clib_memcpy (t0->packet_data,
1401  sizeof (t0->packet_data));
1402  }
1403  if (b1->flags & VLIB_BUFFER_IS_TRACED)
1404  {
1405  t1 = vlib_add_trace (vm, node, b1, sizeof (t1[0]));
1406  t1->adj_index = vnet_buffer (b1)->ip.adj_index[which_adj_index];
1407  t1->flow_hash = vnet_buffer (b1)->ip.flow_hash;
1408  t1->fib_index = (vnet_buffer(b1)->sw_if_index[VLIB_TX] != (u32)~0) ?
1409  vnet_buffer(b1)->sw_if_index[VLIB_TX] :
1411  vnet_buffer(b1)->sw_if_index[VLIB_RX]);
1412 
1413  clib_memcpy (t1->packet_data,
1415  sizeof (t1->packet_data));
1416  }
1417  from += 2;
1418  n_left -= 2;
1419  }
1420 
1421  while (n_left >= 1)
1422  {
1423  u32 bi0;
1424  vlib_buffer_t * b0;
1426 
1427  bi0 = from[0];
1428 
1429  b0 = vlib_get_buffer (vm, bi0);
1430 
1431  if (b0->flags & VLIB_BUFFER_IS_TRACED)
1432  {
1433  t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
1434  t0->adj_index = vnet_buffer (b0)->ip.adj_index[which_adj_index];
1435  t0->flow_hash = vnet_buffer (b0)->ip.flow_hash;
1436  t0->fib_index = (vnet_buffer(b0)->sw_if_index[VLIB_TX] != (u32)~0) ?
1437  vnet_buffer(b0)->sw_if_index[VLIB_TX] :
1439  vnet_buffer(b0)->sw_if_index[VLIB_RX]);
1440 
1441  clib_memcpy (t0->packet_data,
1443  sizeof (t0->packet_data));
1444  }
1445  from += 1;
1446  n_left -= 1;
1447  }
1448 }
1449 
1450 static uword
1452  vlib_node_runtime_t * node,
1453  vlib_frame_t * frame,
1454  ip6_error_t error_code)
1455 {
1456  u32 * buffers = vlib_frame_vector_args (frame);
1457  uword n_packets = frame->n_vectors;
1458 
1459  vlib_error_drop_buffers (vm, node,
1460  buffers,
1461  /* stride */ 1,
1462  n_packets,
1463  /* next */ 0,
1464  ip6_input_node.index,
1465  error_code);
1466 
1467  if (node->flags & VLIB_NODE_FLAG_TRACE)
1468  ip6_forward_next_trace (vm, node, frame, VLIB_TX);
1469 
1470  return n_packets;
1471 }
1472 
1473 static uword
1475  vlib_node_runtime_t * node,
1476  vlib_frame_t * frame)
1477 { return ip6_drop_or_punt (vm, node, frame, IP6_ERROR_ADJACENCY_DROP); }
1478 
1479 static uword
1481  vlib_node_runtime_t * node,
1482  vlib_frame_t * frame)
1483 { return ip6_drop_or_punt (vm, node, frame, IP6_ERROR_ADJACENCY_PUNT); }
1484 
1485 static uword
1487  vlib_node_runtime_t * node,
1488  vlib_frame_t * frame)
1489 { return ip6_drop_or_punt (vm, node, frame, IP6_ERROR_DST_LOOKUP_MISS); }
1490 
1492  .function = ip6_drop,
1493  .name = "ip6-drop",
1494  .vector_size = sizeof (u32),
1495 
1496  .format_trace = format_ip6_forward_next_trace,
1497 
1498  .n_next_nodes = 1,
1499  .next_nodes = {
1500  [0] = "error-drop",
1501  },
1502 };
1503 
1505  .function = ip6_punt,
1506  .name = "ip6-punt",
1507  .vector_size = sizeof (u32),
1508 
1509  .format_trace = format_ip6_forward_next_trace,
1510 
1511  .n_next_nodes = 1,
1512  .next_nodes = {
1513  [0] = "error-punt",
1514  },
1515 };
1516 
1518  .function = ip6_miss,
1519  .name = "ip6-miss",
1520  .vector_size = sizeof (u32),
1521 
1522  .format_trace = format_ip6_forward_next_trace,
1523 
1524  .n_next_nodes = 1,
1525  .next_nodes = {
1526  [0] = "error-drop",
1527  },
1528 };
1529 
1531  .function = ip6_drop,
1532  .name = "ip6-multicast",
1533  .vector_size = sizeof (u32),
1534 
1535  .format_trace = format_ip6_forward_next_trace,
1536 
1537  .n_next_nodes = 1,
1538  .next_nodes = {
1539  [0] = "error-drop",
1540  },
1541 };
1542 
1543 /* Compute TCP/UDP/ICMP6 checksum in software. */
1545 {
1546  ip_csum_t sum0;
1547  u16 sum16, payload_length_host_byte_order;
1548  u32 i, n_this_buffer, n_bytes_left;
1549  u32 headers_size = sizeof(ip0[0]);
1550  void * data_this_buffer;
1551 
1552  ASSERT(bogus_lengthp);
1553  *bogus_lengthp = 0;
1554 
1555  /* Initialize checksum with ip header. */
1556  sum0 = ip0->payload_length + clib_host_to_net_u16 (ip0->protocol);
1557  payload_length_host_byte_order = clib_net_to_host_u16 (ip0->payload_length);
1558  data_this_buffer = (void *) (ip0 + 1);
1559 
1560  for (i = 0; i < ARRAY_LEN (ip0->src_address.as_uword); i++)
1561  {
1562  sum0 = ip_csum_with_carry (sum0,
1564  sum0 = ip_csum_with_carry (sum0,
1566  }
1567 
1568  /* some icmp packets may come with a "router alert" hop-by-hop extension header (e.g., mldv2 packets) */
1569  if (PREDICT_FALSE (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS))
1570  {
1571  u32 skip_bytes;
1572  ip6_hop_by_hop_ext_t *ext_hdr = (ip6_hop_by_hop_ext_t *)data_this_buffer;
1573 
1574  /* validate really icmp6 next */
1575  ASSERT(ext_hdr->next_hdr == IP_PROTOCOL_ICMP6);
1576 
1577  skip_bytes = 8* (1 + ext_hdr->n_data_u64s);
1578  data_this_buffer = (void *)((u8 *)data_this_buffer + skip_bytes);
1579 
1580  payload_length_host_byte_order -= skip_bytes;
1581  headers_size += skip_bytes;
1582  }
1583 
1584  n_bytes_left = n_this_buffer = payload_length_host_byte_order;
1585 #if DPDK > 0
1586  if (p0 && n_this_buffer + headers_size > p0->current_length)
1587  {
1588  struct rte_mbuf *mb = rte_mbuf_from_vlib_buffer(p0);
1589  u8 nb_segs = mb->nb_segs;
1590 
1591  n_this_buffer = (p0->current_length > headers_size ?
1592  p0->current_length - headers_size : 0);
1593  while (n_bytes_left)
1594  {
1595  sum0 = ip_incremental_checksum (sum0, data_this_buffer, n_this_buffer);
1596  n_bytes_left -= n_this_buffer;
1597 
1598  mb = mb->next;
1599  nb_segs--;
1600  if ((nb_segs == 0) || (mb == 0))
1601  break;
1602 
1603  data_this_buffer = rte_ctrlmbuf_data(mb);
1604  n_this_buffer = mb->data_len;
1605  }
1606  if (n_bytes_left || nb_segs)
1607  {
1608  *bogus_lengthp = 1;
1609  return 0xfefe;
1610  }
1611  }
1612  else sum0 = ip_incremental_checksum (sum0, data_this_buffer, n_this_buffer);
1613 #else
1614  if (p0 && n_this_buffer + headers_size > p0->current_length)
1615  n_this_buffer = p0->current_length > headers_size ? p0->current_length - headers_size : 0;
1616  while (1)
1617  {
1618  sum0 = ip_incremental_checksum (sum0, data_this_buffer, n_this_buffer);
1619  n_bytes_left -= n_this_buffer;
1620  if (n_bytes_left == 0)
1621  break;
1622 
1623  if (!(p0->flags & VLIB_BUFFER_NEXT_PRESENT))
1624  {
1625  *bogus_lengthp = 1;
1626  return 0xfefe;
1627  }
1628  p0 = vlib_get_buffer (vm, p0->next_buffer);
1629  data_this_buffer = vlib_buffer_get_current (p0);
1630  n_this_buffer = p0->current_length;
1631  }
1632 #endif /* DPDK */
1633 
1634  sum16 = ~ ip_csum_fold (sum0);
1635 
1636  return sum16;
1637 }
1638 
1640 {
1642  udp_header_t * udp0;
1643  u16 sum16;
1644  int bogus_length;
1645 
1646  /* some icmp packets may come with a "router alert" hop-by-hop extension header (e.g., mldv2 packets) */
1647  ASSERT (ip0->protocol == IP_PROTOCOL_TCP
1648  || ip0->protocol == IP_PROTOCOL_ICMP6
1649  || ip0->protocol == IP_PROTOCOL_UDP
1650  || ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS);
1651 
1652  udp0 = (void *) (ip0 + 1);
1653  if (ip0->protocol == IP_PROTOCOL_UDP && udp0->checksum == 0)
1654  {
1657  return p0->flags;
1658  }
1659 
1660  sum16 = ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip0, &bogus_length);
1661 
1663  | ((sum16 == 0) << LOG2_IP_BUFFER_L4_CHECKSUM_CORRECT));
1664 
1665  return p0->flags;
1666 }
1667 
1668 static uword
1670  vlib_node_runtime_t * node,
1671  vlib_frame_t * frame)
1672 {
1673  ip6_main_t * im = &ip6_main;
1674  ip_lookup_main_t * lm = &im->lookup_main;
1675  ip_local_next_t next_index;
1676  u32 * from, * to_next, n_left_from, n_left_to_next;
1677  vlib_node_runtime_t * error_node = vlib_node_get_runtime (vm, ip6_input_node.index);
1678 
1679  from = vlib_frame_vector_args (frame);
1680  n_left_from = frame->n_vectors;
1681  next_index = node->cached_next_index;
1682 
1683  if (node->flags & VLIB_NODE_FLAG_TRACE)
1684  ip6_forward_next_trace (vm, node, frame, VLIB_TX);
1685 
1686  while (n_left_from > 0)
1687  {
1688  vlib_get_next_frame (vm, node, next_index,
1689  to_next, n_left_to_next);
1690 
1691  while (n_left_from >= 4 && n_left_to_next >= 2)
1692  {
1693  vlib_buffer_t * p0, * p1;
1694  ip6_header_t * ip0, * ip1;
1695  udp_header_t * udp0, * udp1;
1696  u32 pi0, ip_len0, udp_len0, flags0, next0;
1697  u32 pi1, ip_len1, udp_len1, flags1, next1;
1698  i32 len_diff0, len_diff1;
1699  u8 error0, type0, good_l4_checksum0;
1700  u8 error1, type1, good_l4_checksum1;
1701 
1702  pi0 = to_next[0] = from[0];
1703  pi1 = to_next[1] = from[1];
1704  from += 2;
1705  n_left_from -= 2;
1706  to_next += 2;
1707  n_left_to_next -= 2;
1708 
1709  p0 = vlib_get_buffer (vm, pi0);
1710  p1 = vlib_get_buffer (vm, pi1);
1711 
1712  ip0 = vlib_buffer_get_current (p0);
1713  ip1 = vlib_buffer_get_current (p1);
1714 
1715  type0 = lm->builtin_protocol_by_ip_protocol[ip0->protocol];
1716  type1 = lm->builtin_protocol_by_ip_protocol[ip1->protocol];
1717 
1718  next0 = lm->local_next_by_ip_protocol[ip0->protocol];
1719  next1 = lm->local_next_by_ip_protocol[ip1->protocol];
1720 
1721  flags0 = p0->flags;
1722  flags1 = p1->flags;
1723 
1724  good_l4_checksum0 = (flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
1725  good_l4_checksum1 = (flags1 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
1726 
1727  udp0 = ip6_next_header (ip0);
1728  udp1 = ip6_next_header (ip1);
1729 
1730  /* Don't verify UDP checksum for packets with explicit zero checksum. */
1731  good_l4_checksum0 |= type0 == IP_BUILTIN_PROTOCOL_UDP && udp0->checksum == 0;
1732  good_l4_checksum1 |= type1 == IP_BUILTIN_PROTOCOL_UDP && udp1->checksum == 0;
1733 
1734  good_l4_checksum0 |= type0 == IP_BUILTIN_PROTOCOL_UNKNOWN;
1735  good_l4_checksum1 |= type1 == IP_BUILTIN_PROTOCOL_UNKNOWN;
1736 
1737  /* Verify UDP length. */
1738  ip_len0 = clib_net_to_host_u16 (ip0->payload_length);
1739  ip_len1 = clib_net_to_host_u16 (ip1->payload_length);
1740  udp_len0 = clib_net_to_host_u16 (udp0->length);
1741  udp_len1 = clib_net_to_host_u16 (udp1->length);
1742 
1743  len_diff0 = ip_len0 - udp_len0;
1744  len_diff1 = ip_len1 - udp_len1;
1745 
1746  len_diff0 = type0 == IP_BUILTIN_PROTOCOL_UDP ? len_diff0 : 0;
1747  len_diff1 = type1 == IP_BUILTIN_PROTOCOL_UDP ? len_diff1 : 0;
1748 
1750  && ! good_l4_checksum0
1751  && ! (flags0 & IP_BUFFER_L4_CHECKSUM_COMPUTED)))
1752  {
1753  flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, p0);
1754  good_l4_checksum0 =
1755  (flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
1756  }
1758  && ! good_l4_checksum1
1759  && ! (flags1 & IP_BUFFER_L4_CHECKSUM_COMPUTED)))
1760  {
1761  flags1 = ip6_tcp_udp_icmp_validate_checksum (vm, p1);
1762  good_l4_checksum1 =
1763  (flags1 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
1764  }
1765 
1766  error0 = error1 = IP6_ERROR_UNKNOWN_PROTOCOL;
1767 
1768  error0 = len_diff0 < 0 ? IP6_ERROR_UDP_LENGTH : error0;
1769  error1 = len_diff1 < 0 ? IP6_ERROR_UDP_LENGTH : error1;
1770 
1771  ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_UDP == IP6_ERROR_UDP_CHECKSUM);
1772  ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_ICMP == IP6_ERROR_ICMP_CHECKSUM);
1773  error0 = (! good_l4_checksum0
1774  ? IP6_ERROR_UDP_CHECKSUM + type0
1775  : error0);
1776  error1 = (! good_l4_checksum1
1777  ? IP6_ERROR_UDP_CHECKSUM + type1
1778  : error1);
1779 
1780  /* Drop packets from unroutable hosts. */
1781  /* If this is a neighbor solicitation (ICMP), skip source RPF check */
1782  if (error0 == IP6_ERROR_UNKNOWN_PROTOCOL && type0 != IP_BUILTIN_PROTOCOL_ICMP)
1783  {
1784  u32 src_adj_index0 = ip6_src_lookup_for_packet (im, p0, ip0);
1785  error0 = (lm->miss_adj_index == src_adj_index0
1786  ? IP6_ERROR_SRC_LOOKUP_MISS
1787  : error0);
1788  }
1789  if (error1 == IP6_ERROR_UNKNOWN_PROTOCOL && type1 != IP_BUILTIN_PROTOCOL_ICMP)
1790  {
1791  u32 src_adj_index1 = ip6_src_lookup_for_packet (im, p1, ip1);
1792  error1 = (lm->miss_adj_index == src_adj_index1
1793  ? IP6_ERROR_SRC_LOOKUP_MISS
1794  : error1);
1795  }
1796 
1797  next0 = error0 != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next0;
1798  next1 = error1 != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next1;
1799 
1800  p0->error = error_node->errors[error0];
1801  p1->error = error_node->errors[error1];
1802 
1803  vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
1804  to_next, n_left_to_next,
1805  pi0, pi1, next0, next1);
1806  }
1807 
1808  while (n_left_from > 0 && n_left_to_next > 0)
1809  {
1810  vlib_buffer_t * p0;
1811  ip6_header_t * ip0;
1812  udp_header_t * udp0;
1813  u32 pi0, ip_len0, udp_len0, flags0, next0;
1814  i32 len_diff0;
1815  u8 error0, type0, good_l4_checksum0;
1816 
1817  pi0 = to_next[0] = from[0];
1818  from += 1;
1819  n_left_from -= 1;
1820  to_next += 1;
1821  n_left_to_next -= 1;
1822 
1823  p0 = vlib_get_buffer (vm, pi0);
1824 
1825  ip0 = vlib_buffer_get_current (p0);
1826 
1827  type0 = lm->builtin_protocol_by_ip_protocol[ip0->protocol];
1828  next0 = lm->local_next_by_ip_protocol[ip0->protocol];
1829 
1830  flags0 = p0->flags;
1831 
1832  good_l4_checksum0 = (flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
1833 
1834  udp0 = ip6_next_header (ip0);
1835 
1836  /* Don't verify UDP checksum for packets with explicit zero checksum. */
1837  good_l4_checksum0 |= type0 == IP_BUILTIN_PROTOCOL_UDP && udp0->checksum == 0;
1838 
1839  good_l4_checksum0 |= type0 == IP_BUILTIN_PROTOCOL_UNKNOWN;
1840 
1841  /* Verify UDP length. */
1842  ip_len0 = clib_net_to_host_u16 (ip0->payload_length);
1843  udp_len0 = clib_net_to_host_u16 (udp0->length);
1844 
1845  len_diff0 = ip_len0 - udp_len0;
1846 
1847  len_diff0 = type0 == IP_BUILTIN_PROTOCOL_UDP ? len_diff0 : 0;
1848 
1850  && ! good_l4_checksum0
1851  && ! (flags0 & IP_BUFFER_L4_CHECKSUM_COMPUTED)))
1852  {
1853  flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, p0);
1854  good_l4_checksum0 =
1855  (flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
1856  }
1857 
1858  error0 = IP6_ERROR_UNKNOWN_PROTOCOL;
1859 
1860  error0 = len_diff0 < 0 ? IP6_ERROR_UDP_LENGTH : error0;
1861 
1862  ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_UDP == IP6_ERROR_UDP_CHECKSUM);
1863  ASSERT (IP6_ERROR_UDP_CHECKSUM + IP_BUILTIN_PROTOCOL_ICMP == IP6_ERROR_ICMP_CHECKSUM);
1864  error0 = (! good_l4_checksum0
1865  ? IP6_ERROR_UDP_CHECKSUM + type0
1866  : error0);
1867 
1868  /* If this is a neighbor solicitation (ICMP), skip source RPF check */
1869  if (error0 == IP6_ERROR_UNKNOWN_PROTOCOL && type0 != IP_BUILTIN_PROTOCOL_ICMP)
1870  {
1871  u32 src_adj_index0 = ip6_src_lookup_for_packet (im, p0, ip0);
1872  error0 = (lm->miss_adj_index == src_adj_index0
1873  ? IP6_ERROR_SRC_LOOKUP_MISS
1874  : error0);
1875  }
1876 
1877  next0 = error0 != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next0;
1878 
1879  p0->error = error_node->errors[error0];
1880 
1881  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1882  to_next, n_left_to_next,
1883  pi0, next0);
1884  }
1885 
1886  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1887  }
1888 
1889  return frame->n_vectors;
1890 }
1891 
1893  .function = ip6_local,
1894  .name = "ip6-local",
1895  .vector_size = sizeof (u32),
1896 
1897  .format_trace = format_ip6_forward_next_trace,
1898 
1899  .n_next_nodes = IP_LOCAL_N_NEXT,
1900  .next_nodes = {
1901  [IP_LOCAL_NEXT_DROP] = "error-drop",
1902  [IP_LOCAL_NEXT_PUNT] = "error-punt",
1903  [IP_LOCAL_NEXT_UDP_LOOKUP] = "ip6-udp-lookup",
1904  [IP_LOCAL_NEXT_ICMP] = "ip6-icmp-input",
1905  },
1906 };
1907 
1908 void ip6_register_protocol (u32 protocol, u32 node_index)
1909 {
1910  vlib_main_t * vm = vlib_get_main();
1911  ip6_main_t * im = &ip6_main;
1912  ip_lookup_main_t * lm = &im->lookup_main;
1913 
1914  ASSERT (protocol < ARRAY_LEN (lm->local_next_by_ip_protocol));
1915  lm->local_next_by_ip_protocol[protocol] = vlib_node_add_next (vm, ip6_local_node.index, node_index);
1916 }
1917 
1918 typedef enum {
1923 
1924 typedef enum {
1928 
1929 static uword
1931  vlib_node_runtime_t * node,
1932  vlib_frame_t * frame)
1933 {
1934  vnet_main_t * vnm = vnet_get_main();
1935  ip6_main_t * im = &ip6_main;
1936  ip_lookup_main_t * lm = &im->lookup_main;
1937  u32 * from, * to_next_drop;
1938  uword n_left_from, n_left_to_next_drop;
1939  static f64 time_last_seed_change = -1e100;
1940  static u32 hash_seeds[3];
1941  static uword hash_bitmap[256 / BITS (uword)];
1942  f64 time_now;
1943  int bogus_length;
1944 
1945  if (node->flags & VLIB_NODE_FLAG_TRACE)
1946  ip6_forward_next_trace (vm, node, frame, VLIB_TX);
1947 
1948  time_now = vlib_time_now (vm);
1949  if (time_now - time_last_seed_change > 1e-3)
1950  {
1951  uword i;
1953  sizeof (hash_seeds));
1954  for (i = 0; i < ARRAY_LEN (hash_seeds); i++)
1955  hash_seeds[i] = r[i];
1956 
1957  /* Mark all hash keys as been not-seen before. */
1958  for (i = 0; i < ARRAY_LEN (hash_bitmap); i++)
1959  hash_bitmap[i] = 0;
1960 
1961  time_last_seed_change = time_now;
1962  }
1963 
1964  from = vlib_frame_vector_args (frame);
1965  n_left_from = frame->n_vectors;
1966 
1967  while (n_left_from > 0)
1968  {
1970  to_next_drop, n_left_to_next_drop);
1971 
1972  while (n_left_from > 0 && n_left_to_next_drop > 0)
1973  {
1974  vlib_buffer_t * p0;
1975  ip6_header_t * ip0;
1976  u32 pi0, adj_index0, a0, b0, c0, m0, sw_if_index0, drop0;
1977  uword bm0;
1978  ip_adjacency_t * adj0;
1979  vnet_hw_interface_t * hw_if0;
1980  u32 next0;
1981 
1982  pi0 = from[0];
1983 
1984  p0 = vlib_get_buffer (vm, pi0);
1985 
1986  adj_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
1987 
1988  ip0 = vlib_buffer_get_current (p0);
1989 
1990  adj0 = ip_get_adjacency (lm, adj_index0);
1991 
1992  if (adj0->arp.next_hop.ip6.as_u64[0] ||
1993  adj0->arp.next_hop.ip6.as_u64[1]) {
1994  ip0->dst_address.as_u64[0] = adj0->arp.next_hop.ip6.as_u64[0];
1995  ip0->dst_address.as_u64[1] = adj0->arp.next_hop.ip6.as_u64[1];
1996  }
1997 
1998  a0 = hash_seeds[0];
1999  b0 = hash_seeds[1];
2000  c0 = hash_seeds[2];
2001 
2002  sw_if_index0 = adj0->rewrite_header.sw_if_index;
2003  vnet_buffer (p0)->sw_if_index[VLIB_TX] = sw_if_index0;
2004 
2005  a0 ^= sw_if_index0;
2006  b0 ^= ip0->dst_address.as_u32[0];
2007  c0 ^= ip0->dst_address.as_u32[1];
2008 
2009  hash_v3_mix32 (a0, b0, c0);
2010 
2011  b0 ^= ip0->dst_address.as_u32[2];
2012  c0 ^= ip0->dst_address.as_u32[3];
2013 
2014  hash_v3_finalize32 (a0, b0, c0);
2015 
2016  c0 &= BITS (hash_bitmap) - 1;
2017  c0 = c0 / BITS (uword);
2018  m0 = (uword) 1 << (c0 % BITS (uword));
2019 
2020  bm0 = hash_bitmap[c0];
2021  drop0 = (bm0 & m0) != 0;
2022 
2023  /* Mark it as seen. */
2024  hash_bitmap[c0] = bm0 | m0;
2025 
2026  from += 1;
2027  n_left_from -= 1;
2028  to_next_drop[0] = pi0;
2029  to_next_drop += 1;
2030  n_left_to_next_drop -= 1;
2031 
2032  hw_if0 = vnet_get_sup_hw_interface (vnm, sw_if_index0);
2033 
2034  /* If the interface is link-down, drop the pkt */
2035  if (!(hw_if0->flags & VNET_HW_INTERFACE_FLAG_LINK_UP))
2036  drop0 = 1;
2037 
2038  p0->error =
2041  if (drop0)
2042  continue;
2043 
2044  {
2045  u32 bi0 = 0;
2046  icmp6_neighbor_solicitation_header_t * h0;
2047  vlib_buffer_t * b0;
2048 
2050  (vm, &im->discover_neighbor_packet_template, &bi0);
2051 
2052  /*
2053  * Build ethernet header.
2054  * Choose source address based on destination lookup
2055  * adjacency.
2056  */
2057  ip6_src_address_for_packet (im, p0, &h0->ip.src_address,
2058  sw_if_index0);
2059 
2060  /*
2061  * Destination address is a solicited node multicast address.
2062  * We need to fill in
2063  * the low 24 bits with low 24 bits of target's address.
2064  */
2065  h0->ip.dst_address.as_u8[13] = ip0->dst_address.as_u8[13];
2066  h0->ip.dst_address.as_u8[14] = ip0->dst_address.as_u8[14];
2067  h0->ip.dst_address.as_u8[15] = ip0->dst_address.as_u8[15];
2068 
2069  h0->neighbor.target_address = ip0->dst_address;
2070 
2071  clib_memcpy (h0->link_layer_option.ethernet_address,
2072  hw_if0->hw_address, vec_len (hw_if0->hw_address));
2073 
2074  /* $$$$ appears we need this; why is the checksum non-zero? */
2075  h0->neighbor.icmp.checksum = 0;
2076  h0->neighbor.icmp.checksum =
2077  ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h0->ip,
2078  &bogus_length);
2079 
2080  ASSERT (bogus_length == 0);
2081 
2082  vlib_buffer_copy_trace_flag (vm, p0, bi0);
2083  b0 = vlib_get_buffer (vm, bi0);
2084  vnet_buffer (b0)->sw_if_index[VLIB_TX]
2085  = vnet_buffer (p0)->sw_if_index[VLIB_TX];
2086 
2087  /* Add rewrite/encap string. */
2088  vnet_rewrite_one_header (adj0[0], h0,
2089  sizeof (ethernet_header_t));
2090  vlib_buffer_advance (b0, -adj0->rewrite_header.data_bytes);
2091 
2093 
2094  vlib_set_next_frame_buffer (vm, node, next0, bi0);
2095  }
2096  }
2097 
2099  n_left_to_next_drop);
2100  }
2101 
2102  return frame->n_vectors;
2103 }
2104 
2106  [IP6_DISCOVER_NEIGHBOR_ERROR_DROP] = "address overflow drops",
2108  = "neighbor solicitations sent",
2109 };
2110 
2112  .function = ip6_discover_neighbor,
2113  .name = "ip6-discover-neighbor",
2114  .vector_size = sizeof (u32),
2115 
2116  .format_trace = format_ip6_forward_next_trace,
2117 
2119  .error_strings = ip6_discover_neighbor_error_strings,
2120 
2121  .n_next_nodes = IP6_DISCOVER_NEIGHBOR_N_NEXT,
2122  .next_nodes = {
2123  [IP6_DISCOVER_NEIGHBOR_NEXT_DROP] = "error-drop",
2124  [IP6_DISCOVER_NEIGHBOR_NEXT_REPLY_TX] = "interface-output",
2125  },
2126 };
2127 
2128 clib_error_t *
2130 {
2131  vnet_main_t * vnm = vnet_get_main();
2132  ip6_main_t * im = &ip6_main;
2133  icmp6_neighbor_solicitation_header_t * h;
2134  ip6_address_t * src;
2136  ip_adjacency_t * adj;
2138  vnet_sw_interface_t * si;
2139  vlib_buffer_t * b;
2140  u32 bi = 0;
2141  int bogus_length;
2142 
2143  si = vnet_get_sw_interface (vnm, sw_if_index);
2144 
2146  {
2147  return clib_error_return (0, "%U: interface %U down",
2148  format_ip6_address, dst,
2150  sw_if_index);
2151  }
2152 
2153  src = ip6_interface_address_matching_destination (im, dst, sw_if_index, &ia);
2154  if (! src)
2155  {
2156  vnm->api_errno = VNET_API_ERROR_NO_MATCHING_INTERFACE;
2157  return clib_error_return
2158  (0, "no matching interface address for destination %U (interface %U)",
2159  format_ip6_address, dst,
2160  format_vnet_sw_if_index_name, vnm, sw_if_index);
2161  }
2162 
2164 
2165  hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
2166 
2167  /* Destination address is a solicited node multicast address. We need to fill in
2168  the low 24 bits with low 24 bits of target's address. */
2169  h->ip.dst_address.as_u8[13] = dst->as_u8[13];
2170  h->ip.dst_address.as_u8[14] = dst->as_u8[14];
2171  h->ip.dst_address.as_u8[15] = dst->as_u8[15];
2172 
2173  h->ip.src_address = src[0];
2174  h->neighbor.target_address = dst[0];
2175 
2176  clib_memcpy (h->link_layer_option.ethernet_address, hi->hw_address, vec_len (hi->hw_address));
2177 
2178  h->neighbor.icmp.checksum =
2179  ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h->ip, &bogus_length);
2180  ASSERT(bogus_length == 0);
2181 
2182  b = vlib_get_buffer (vm, bi);
2183  vnet_buffer (b)->sw_if_index[VLIB_RX] = vnet_buffer (b)->sw_if_index[VLIB_TX] = sw_if_index;
2184 
2185  /* Add encapsulation string for software interface (e.g. ethernet header). */
2187  vnet_rewrite_one_header (adj[0], h, sizeof (ethernet_header_t));
2188  vlib_buffer_advance (b, -adj->rewrite_header.data_bytes);
2189 
2190  {
2192  u32 * to_next = vlib_frame_vector_args (f);
2193  to_next[0] = bi;
2194  f->n_vectors = 1;
2196  }
2197 
2198  return /* no error */ 0;
2199 }
2200 
2201 typedef enum {
2204 
2207  vlib_node_runtime_t * node,
2208  vlib_frame_t * frame,
2209  int rewrite_for_locally_received_packets)
2210 {
2211  ip_lookup_main_t * lm = &ip6_main.lookup_main;
2212  u32 * from = vlib_frame_vector_args (frame);
2213  u32 n_left_from, n_left_to_next, * to_next, next_index;
2214  vlib_node_runtime_t * error_node = vlib_node_get_runtime (vm, ip6_input_node.index);
2215  vlib_rx_or_tx_t adj_rx_tx = rewrite_for_locally_received_packets ? VLIB_RX : VLIB_TX;
2216 
2217  n_left_from = frame->n_vectors;
2218  next_index = node->cached_next_index;
2219  u32 cpu_index = os_get_cpu_number();
2220 
2221  while (n_left_from > 0)
2222  {
2223  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
2224 
2225  while (n_left_from >= 4 && n_left_to_next >= 2)
2226  {
2227  ip_adjacency_t * adj0, * adj1;
2228  vlib_buffer_t * p0, * p1;
2229  ip6_header_t * ip0, * ip1;
2230  u32 pi0, rw_len0, next0, error0, adj_index0;
2231  u32 pi1, rw_len1, next1, error1, adj_index1;
2232 
2233  /* Prefetch next iteration. */
2234  {
2235  vlib_buffer_t * p2, * p3;
2236 
2237  p2 = vlib_get_buffer (vm, from[2]);
2238  p3 = vlib_get_buffer (vm, from[3]);
2239 
2240  vlib_prefetch_buffer_header (p2, LOAD);
2241  vlib_prefetch_buffer_header (p3, LOAD);
2242 
2243  CLIB_PREFETCH (p2->pre_data, 32, STORE);
2244  CLIB_PREFETCH (p3->pre_data, 32, STORE);
2245 
2246  CLIB_PREFETCH (p2->data, sizeof (ip0[0]), STORE);
2247  CLIB_PREFETCH (p3->data, sizeof (ip0[0]), STORE);
2248  }
2249 
2250  pi0 = to_next[0] = from[0];
2251  pi1 = to_next[1] = from[1];
2252 
2253  from += 2;
2254  n_left_from -= 2;
2255  to_next += 2;
2256  n_left_to_next -= 2;
2257 
2258  p0 = vlib_get_buffer (vm, pi0);
2259  p1 = vlib_get_buffer (vm, pi1);
2260 
2261  adj_index0 = vnet_buffer (p0)->ip.adj_index[adj_rx_tx];
2262  adj_index1 = vnet_buffer (p1)->ip.adj_index[adj_rx_tx];
2263 
2264  /* We should never rewrite a pkt using the MISS adjacency */
2265  ASSERT(adj_index0 && adj_index1);
2266 
2267  ip0 = vlib_buffer_get_current (p0);
2268  ip1 = vlib_buffer_get_current (p1);
2269 
2270  error0 = error1 = IP6_ERROR_NONE;
2271 
2272  if (! rewrite_for_locally_received_packets)
2273  {
2274  i32 hop_limit0 = ip0->hop_limit, hop_limit1 = ip1->hop_limit;
2275 
2276  /* Input node should have reject packets with hop limit 0. */
2277  ASSERT (ip0->hop_limit > 0);
2278  ASSERT (ip1->hop_limit > 0);
2279 
2280  hop_limit0 -= 1;
2281  hop_limit1 -= 1;
2282 
2283  ip0->hop_limit = hop_limit0;
2284  ip1->hop_limit = hop_limit1;
2285 
2286  error0 = hop_limit0 <= 0 ? IP6_ERROR_TIME_EXPIRED : error0;
2287  error1 = hop_limit1 <= 0 ? IP6_ERROR_TIME_EXPIRED : error1;
2288  }
2289 
2290  adj0 = ip_get_adjacency (lm, adj_index0);
2291  adj1 = ip_get_adjacency (lm, adj_index1);
2292 
2293  if (rewrite_for_locally_received_packets)
2294  {
2295  /*
2296  * If someone sends e.g. an icmp6 w/ src = dst = interface addr,
2297  * we end up here with a local adjacency in hand
2298  */
2299  if (PREDICT_FALSE(adj0->lookup_next_index
2301  error0 = IP6_ERROR_SPOOFED_LOCAL_PACKETS;
2302  if (PREDICT_FALSE(adj1->lookup_next_index
2304  error1 = IP6_ERROR_SPOOFED_LOCAL_PACKETS;
2305  }
2306 
2307  rw_len0 = adj0[0].rewrite_header.data_bytes;
2308  rw_len1 = adj1[0].rewrite_header.data_bytes;
2309 
2311  cpu_index,
2312  adj_index0,
2313  /* packet increment */ 0,
2314  /* byte increment */ rw_len0);
2316  cpu_index,
2317  adj_index1,
2318  /* packet increment */ 0,
2319  /* byte increment */ rw_len1);
2320 
2321  /* Check MTU of outgoing interface. */
2322  error0 = (vlib_buffer_length_in_chain (vm, p0) > adj0[0].rewrite_header.max_l3_packet_bytes
2323  ? IP6_ERROR_MTU_EXCEEDED
2324  : error0);
2325  error1 = (vlib_buffer_length_in_chain (vm, p1) > adj1[0].rewrite_header.max_l3_packet_bytes
2326  ? IP6_ERROR_MTU_EXCEEDED
2327  : error1);
2328 
2329  p0->current_data -= rw_len0;
2330  p1->current_data -= rw_len1;
2331 
2332  p0->current_length += rw_len0;
2333  p1->current_length += rw_len1;
2334 
2335  vnet_buffer (p0)->sw_if_index[VLIB_TX] = adj0[0].rewrite_header.sw_if_index;
2336  vnet_buffer (p1)->sw_if_index[VLIB_TX] = adj1[0].rewrite_header.sw_if_index;
2337 
2338  next0 = (error0 == IP6_ERROR_NONE) ?
2339  adj0[0].rewrite_header.next_index : IP6_REWRITE_NEXT_DROP;
2340  next1 = (error1 == IP6_ERROR_NONE) ?
2341  adj1[0].rewrite_header.next_index : IP6_REWRITE_NEXT_DROP;
2342 
2343  /* Guess we are only writing on simple Ethernet header. */
2344  vnet_rewrite_two_headers (adj0[0], adj1[0],
2345  ip0, ip1,
2346  sizeof (ethernet_header_t));
2347 
2348  vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
2349  to_next, n_left_to_next,
2350  pi0, pi1, next0, next1);
2351  }
2352 
2353  while (n_left_from > 0 && n_left_to_next > 0)
2354  {
2355  ip_adjacency_t * adj0;
2356  vlib_buffer_t * p0;
2357  ip6_header_t * ip0;
2358  u32 pi0, rw_len0;
2359  u32 adj_index0, next0, error0;
2360 
2361  pi0 = to_next[0] = from[0];
2362 
2363  p0 = vlib_get_buffer (vm, pi0);
2364 
2365  adj_index0 = vnet_buffer (p0)->ip.adj_index[adj_rx_tx];
2366 
2367  /* We should never rewrite a pkt using the MISS adjacency */
2368  ASSERT(adj_index0);
2369 
2370  adj0 = ip_get_adjacency (lm, adj_index0);
2371 
2372  ip0 = vlib_buffer_get_current (p0);
2373 
2374  error0 = IP6_ERROR_NONE;
2375 
2376  /* Check hop limit */
2377  if (! rewrite_for_locally_received_packets)
2378  {
2379  i32 hop_limit0 = ip0->hop_limit;
2380 
2381  ASSERT (ip0->hop_limit > 0);
2382 
2383  hop_limit0 -= 1;
2384 
2385  ip0->hop_limit = hop_limit0;
2386 
2387  error0 = hop_limit0 <= 0 ? IP6_ERROR_TIME_EXPIRED : error0;
2388  }
2389 
2390  if (rewrite_for_locally_received_packets)
2391  {
2392  if (PREDICT_FALSE(adj0->lookup_next_index
2394  error0 = IP6_ERROR_SPOOFED_LOCAL_PACKETS;
2395  }
2396 
2397  /* Guess we are only writing on simple Ethernet header. */
2398  vnet_rewrite_one_header (adj0[0], ip0, sizeof (ethernet_header_t));
2399 
2400  /* Update packet buffer attributes/set output interface. */
2401  rw_len0 = adj0[0].rewrite_header.data_bytes;
2402 
2404  cpu_index,
2405  adj_index0,
2406  /* packet increment */ 0,
2407  /* byte increment */ rw_len0);
2408 
2409  /* Check MTU of outgoing interface. */
2410  error0 = (vlib_buffer_length_in_chain (vm, p0) > adj0[0].rewrite_header.max_l3_packet_bytes
2411  ? IP6_ERROR_MTU_EXCEEDED
2412  : error0);
2413 
2414  p0->current_data -= rw_len0;
2415  p0->current_length += rw_len0;
2416  vnet_buffer (p0)->sw_if_index[VLIB_TX] = adj0[0].rewrite_header.sw_if_index;
2417 
2418  next0 = (error0 == IP6_ERROR_NONE) ?
2419  adj0[0].rewrite_header.next_index : IP6_REWRITE_NEXT_DROP;
2420 
2421  p0->error = error_node->errors[error0];
2422 
2423  from += 1;
2424  n_left_from -= 1;
2425  to_next += 1;
2426  n_left_to_next -= 1;
2427 
2428  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
2429  to_next, n_left_to_next,
2430  pi0, next0);
2431  }
2432 
2433  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
2434  }
2435 
2436  /* Need to do trace after rewrites to pick up new packet data. */
2437  if (node->flags & VLIB_NODE_FLAG_TRACE)
2438  ip6_forward_next_trace (vm, node, frame, adj_rx_tx);
2439 
2440  return frame->n_vectors;
2441 }
2442 
2443 static uword
2445  vlib_node_runtime_t * node,
2446  vlib_frame_t * frame)
2447 {
2448  return ip6_rewrite_inline (vm, node, frame,
2449  /* rewrite_for_locally_received_packets */ 0);
2450 }
2451 
2452 static uword
2454  vlib_node_runtime_t * node,
2455  vlib_frame_t * frame)
2456 {
2457  return ip6_rewrite_inline (vm, node, frame,
2458  /* rewrite_for_locally_received_packets */ 1);
2459 }
2460 
2462  .function = ip6_rewrite_transit,
2463  .name = "ip6-rewrite",
2464  .vector_size = sizeof (u32),
2465 
2466  .format_trace = format_ip6_rewrite_trace,
2467 
2468  .n_next_nodes = 1,
2469  .next_nodes = {
2470  [IP6_REWRITE_NEXT_DROP] = "error-drop",
2471  },
2472 };
2473 
2475  .function = ip6_rewrite_local,
2476  .name = "ip6-rewrite-local",
2477  .vector_size = sizeof (u32),
2478 
2479  .sibling_of = "ip6-rewrite",
2480 
2481  .format_trace = format_ip6_rewrite_trace,
2482 
2483  .n_next_nodes = 1,
2484  .next_nodes = {
2485  [IP6_REWRITE_NEXT_DROP] = "error-drop",
2486  },
2487 };
2488 
2489 /* Global IP6 main. */
2491 
2492 static clib_error_t *
2494 {
2495  ip6_main_t * im = &ip6_main;
2496  uword i;
2497 
2498  for (i = 0; i < ARRAY_LEN (im->fib_masks); i++)
2499  {
2500  u32 j, i0, i1;
2501 
2502  i0 = i / 32;
2503  i1 = i % 32;
2504 
2505  for (j = 0; j < i0; j++)
2506  im->fib_masks[i].as_u32[j] = ~0;
2507 
2508  if (i1)
2509  im->fib_masks[i].as_u32[i0] = clib_host_to_net_u32 (pow2_mask (i1) << (32 - i1));
2510  }
2511 
2512  ip_lookup_init (&im->lookup_main, /* is_ip6 */ 1);
2513 
2514  if (im->lookup_table_nbuckets == 0)
2516 
2518 
2519  if (im->lookup_table_size == 0)
2521 
2522  BV(clib_bihash_init) (&im->ip6_lookup_table, "ip6 lookup table",
2524  im->lookup_table_size);
2525 
2526  /* Create FIB with index 0 and table id of 0. */
2528 
2529  {
2530  pg_node_t * pn;
2531  pn = pg_get_node (ip6_lookup_node.index);
2533  }
2534 
2535  {
2536  icmp6_neighbor_solicitation_header_t p;
2537 
2538  memset (&p, 0, sizeof (p));
2539 
2540  p.ip.ip_version_traffic_class_and_flow_label = clib_host_to_net_u32 (0x6 << 28);
2541  p.ip.payload_length = clib_host_to_net_u16 (sizeof (p)
2542  - STRUCT_OFFSET_OF (icmp6_neighbor_solicitation_header_t, neighbor));
2543  p.ip.protocol = IP_PROTOCOL_ICMP6;
2544  p.ip.hop_limit = 255;
2545  ip6_set_solicited_node_multicast_address (&p.ip.dst_address, 0);
2546 
2547  p.neighbor.icmp.type = ICMP6_neighbor_solicitation;
2548 
2549  p.link_layer_option.header.type = ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address;
2550  p.link_layer_option.header.n_data_u64s = sizeof (p.link_layer_option) / sizeof (u64);
2551 
2554  &p, sizeof (p),
2555  /* alloc chunk size */ 8,
2556  "ip6 neighbor discovery");
2557  }
2558 
2559  return 0;
2560 }
2561 
2563 
2564 static clib_error_t *
2566  unformat_input_t * input,
2567  vlib_cli_command_t * cmd)
2568 {
2569  vnet_main_t * vnm = vnet_get_main();
2570  clib_error_t * error = 0;
2571  u32 sw_if_index, table_id;
2572 
2573  sw_if_index = ~0;
2574 
2575  if (! unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
2576  {
2577  error = clib_error_return (0, "unknown interface `%U'",
2578  format_unformat_error, input);
2579  goto done;
2580  }
2581 
2582  if (unformat (input, "%d", &table_id))
2583  ;
2584  else
2585  {
2586  error = clib_error_return (0, "expected table id `%U'",
2587  format_unformat_error, input);
2588  goto done;
2589  }
2590 
2591  {
2592  ip6_main_t * im = &ip6_main;
2593  ip6_fib_t * fib =
2595 
2596  if (fib)
2597  {
2598  vec_validate (im->fib_index_by_sw_if_index, sw_if_index);
2599  im->fib_index_by_sw_if_index[sw_if_index] = fib->index;
2600  }
2601  }
2602 
2603  done:
2604  return error;
2605 }
2606 
2607 VLIB_CLI_COMMAND (set_interface_ip_table_command, static) = {
2608  .path = "set interface ip6 table",
2609  .function = add_del_ip6_interface_table,
2610  .short_help = "set interface ip6 table <intfc> <table-id>"
2611 };
2612 
2613 void
2615  u8 *mac)
2616 {
2617  ip->as_u64[0] = clib_host_to_net_u64 (0xFE80000000000000ULL);
2618  /* Invert the "u" bit */
2619  ip->as_u8 [8] = mac[0] ^ (1<<1);
2620  ip->as_u8 [9] = mac[1];
2621  ip->as_u8 [10] = mac[2];
2622  ip->as_u8 [11] = 0xFF;
2623  ip->as_u8 [12] = 0xFE;
2624  ip->as_u8 [13] = mac[3];
2625  ip->as_u8 [14] = mac[4];
2626  ip->as_u8 [15] = mac[5];
2627 }
2628 
2629 void
2631  ip6_address_t *ip)
2632 {
2633  /* Invert the previously inverted "u" bit */
2634  mac[0] = ip->as_u8 [8] ^ (1<<1);
2635  mac[1] = ip->as_u8 [9];
2636  mac[2] = ip->as_u8 [10];
2637  mac[3] = ip->as_u8 [13];
2638  mac[4] = ip->as_u8 [14];
2639  mac[5] = ip->as_u8 [15];
2640 }
2641 
2642 static clib_error_t *
2644  unformat_input_t * input,
2645  vlib_cli_command_t * cmd)
2646 {
2647  u8 mac[6];
2648  ip6_address_t _a, *a = &_a;
2649 
2650  if (unformat (input, "%U", unformat_ethernet_address, mac))
2651  {
2653  vlib_cli_output (vm, "Link local address: %U",
2654  format_ip6_address, a);
2656  vlib_cli_output (vm, "Original MAC address: %U",
2658  }
2659 
2660  return 0;
2661 }
2662 
2663 VLIB_CLI_COMMAND (test_link_command, static) = {
2664  .path = "test ip6 link",
2665  .function = test_ip6_link_command_fn,
2666  .short_help = "test ip6 link <mac-address>",
2667 };
2668 
2669 int vnet_set_ip6_flow_hash (u32 table_id, u32 flow_hash_config)
2670 {
2671  ip6_main_t * im6 = &ip6_main;
2672  ip6_fib_t * fib;
2673  uword * p = hash_get (im6->fib_index_by_table_id, table_id);
2674 
2675  if (p == 0)
2676  return -1;
2677 
2678  fib = vec_elt_at_index (im6->fibs, p[0]);
2679 
2680  fib->flow_hash_config = flow_hash_config;
2681  return 1;
2682 }
2683 
2684 static clib_error_t *
2686  unformat_input_t * input,
2687  vlib_cli_command_t * cmd)
2688 {
2689  int matched = 0;
2690  u32 table_id = 0;
2691  u32 flow_hash_config = 0;
2692  int rv;
2693 
2694  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
2695  if (unformat (input, "table %d", &table_id))
2696  matched = 1;
2697 #define _(a,v) \
2698  else if (unformat (input, #a)) { flow_hash_config |= v; matched=1;}
2700 #undef _
2701  else break;
2702  }
2703 
2704  if (matched == 0)
2705  return clib_error_return (0, "unknown input `%U'",
2706  format_unformat_error, input);
2707 
2708  rv = vnet_set_ip6_flow_hash (table_id, flow_hash_config);
2709  switch (rv)
2710  {
2711  case 1:
2712  break;
2713 
2714  case -1:
2715  return clib_error_return (0, "no such FIB table %d", table_id);
2716 
2717  default:
2718  clib_warning ("BUG: illegal flow hash config 0x%x", flow_hash_config);
2719  break;
2720  }
2721 
2722  return 0;
2723 }
2724 
2725 VLIB_CLI_COMMAND (set_ip6_flow_hash_command, static) = {
2726  .path = "set ip6 flow-hash",
2727  .short_help =
2728  "set ip table flow-hash table <fib-id> src dst sport dport proto reverse",
2729  .function = set_ip6_flow_hash_command_fn,
2730 };
2731 
2732 static clib_error_t *
2734  unformat_input_t * input,
2735  vlib_cli_command_t * cmd)
2736 {
2737  ip6_main_t * im = &ip6_main;
2738  ip_lookup_main_t * lm = &im->lookup_main;
2739  int i;
2740 
2741  vlib_cli_output (vm, "Protocols handled by ip6_local");
2742  for (i = 0; i < ARRAY_LEN(lm->local_next_by_ip_protocol); i++)
2743  {
2745  vlib_cli_output (vm, "%d", i);
2746  }
2747  return 0;
2748 }
2749 
2750 
2751 
2752 VLIB_CLI_COMMAND (show_ip_local, static) = {
2753  .path = "show ip6 local",
2754  .function = show_ip6_local_command_fn,
2755  .short_help = "Show ip6 local protocol table",
2756 };
2757 
2759  u32 table_index)
2760 {
2761  vnet_main_t * vnm = vnet_get_main();
2763  ip6_main_t * ipm = &ip6_main;
2764  ip_lookup_main_t * lm = &ipm->lookup_main;
2766 
2767  if (pool_is_free_index (im->sw_interfaces, sw_if_index))
2768  return VNET_API_ERROR_NO_MATCHING_INTERFACE;
2769 
2770  if (table_index != ~0 && pool_is_free_index (cm->tables, table_index))
2771  return VNET_API_ERROR_NO_SUCH_ENTRY;
2772 
2774  lm->classify_table_index_by_sw_if_index [sw_if_index] = table_index;
2775 
2776  return 0;
2777 }
2778 
2779 static clib_error_t *
2781  unformat_input_t * input,
2782  vlib_cli_command_t * cmd)
2783 {
2784  u32 table_index = ~0;
2785  int table_index_set = 0;
2786  u32 sw_if_index = ~0;
2787  int rv;
2788 
2789  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
2790  if (unformat (input, "table-index %d", &table_index))
2791  table_index_set = 1;
2792  else if (unformat (input, "intfc %U", unformat_vnet_sw_interface,
2793  vnet_get_main(), &sw_if_index))
2794  ;
2795  else
2796  break;
2797  }
2798 
2799  if (table_index_set == 0)
2800  return clib_error_return (0, "classify table-index must be specified");
2801 
2802  if (sw_if_index == ~0)
2803  return clib_error_return (0, "interface / subif must be specified");
2804 
2805  rv = vnet_set_ip6_classify_intfc (vm, sw_if_index, table_index);
2806 
2807  switch (rv)
2808  {
2809  case 0:
2810  break;
2811 
2812  case VNET_API_ERROR_NO_MATCHING_INTERFACE:
2813  return clib_error_return (0, "No such interface");
2814 
2815  case VNET_API_ERROR_NO_SUCH_ENTRY:
2816  return clib_error_return (0, "No such classifier table");
2817  }
2818  return 0;
2819 }
2820 
2821 VLIB_CLI_COMMAND (set_ip6_classify_command, static) = {
2822  .path = "set ip6 classify",
2823  .short_help =
2824  "set ip6 classify intfc <int> table-index <index>",
2825  .function = set_ip6_classify_command_fn,
2826 };
2827 
2828 static clib_error_t *
2830 {
2831  ip6_main_t * im = &ip6_main;
2832  uword heapsize = 0;
2833  u32 tmp;
2834  u32 nbuckets = 0;
2835 
2836  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
2837  if (unformat (input, "hash-buckets %d", &tmp))
2838  nbuckets = tmp;
2839  else if (unformat (input, "heap-size %dm", &tmp))
2840  heapsize = ((u64)tmp) << 20;
2841  else if (unformat (input, "heap-size %dM", &tmp))
2842  heapsize = ((u64)tmp) << 20;
2843  else if (unformat (input, "heap-size %dg", &tmp))
2844  heapsize = ((u64)tmp) << 30;
2845  else if (unformat (input, "heap-size %dG", &tmp))
2846  heapsize = ((u64)tmp) << 30;
2847  else
2848  return clib_error_return (0, "unknown input '%U'",
2849  format_unformat_error, input);
2850  }
2851 
2852  im->lookup_table_nbuckets = nbuckets;
2853  im->lookup_table_size = heapsize;
2854 
2855  return 0;
2856 }
2857 
2859 
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:394
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
#define foreach_ip_interface_address(lm, a, sw_if_index, loop, body)
Definition: lookup.h:534
#define vnet_rewrite_one_header(rw0, p0, most_likely_size)
Definition: rewrite.h:245
ip_lookup_next_t
Definition: lookup.h:49
always_inline void * clib_random_buffer_get_data(clib_random_buffer_t *b, uword n_bytes)
Definition: random_buffer.h:75
vmrglw vmrglh hi
#define VNET_REWRITE_FOR_SW_INTERFACE_ADDRESS_BROADCAST
Definition: rewrite.h:256
#define hash_set(h, key, value)
Definition: hash.h:237
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:267
uword vlib_error_drop_buffers(vlib_main_t *vm, vlib_node_runtime_t *node, u32 *buffers, u32 next_buffer_stride, u32 n_buffers, u32 next_index, u32 drop_error_node, u32 drop_error_code)
Definition: error.c:44
static u8 * format_ip6_lookup_trace(u8 *s, va_list *args)
Definition: ip6_forward.c:1321
#define CLIB_UNUSED(x)
Definition: clib.h:79
u32 * config_index_by_sw_if_index
Definition: lookup.h:345
uword unformat(unformat_input_t *i, char *fmt,...)
Definition: unformat.c:942
static void compute_prefix_lengths_in_search_order(ip6_main_t *im)
Definition: ip6_forward.c:48
#define IP6_LOOKUP_NEXT_NODES
Definition: lookup.h:110
void vnet_config_init(vlib_main_t *vm, vnet_config_main_t *cm, char *start_node_names[], int n_start_node_names, char *feature_node_names[], int n_feature_node_names)
Definition: config.c:161
static uword ip6_indirect(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: ip6_forward.c:1279
a
Definition: bitmap.h:393
always_inline pg_node_t * pg_get_node(uword node_index)
Definition: pg.h:335
void * vlib_packet_template_get_packet(vlib_main_t *vm, vlib_packet_template_t *t, u32 *bi_result)
Definition: buffer.c:1133
format_function_t format_ip6_address
Definition: format.h:87
uword lookup_table_size
Definition: ip6.h:168
static void(BVT(clib_bihash)*h, BVT(clib_bihash_value)*v)
ip_interface_address_t * if_address_pool
Definition: lookup.h:388
static clib_error_t * add_del_ip6_interface_table(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: ip6_forward.c:2565
static clib_error_t * set_ip6_classify_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: ip6_forward.c:2780
vnet_interface_main_t interface_main
Definition: vnet.h:62
vlib_node_registration_t ip6_rewrite_local_node
(constructor) VLIB_REGISTER_NODE (ip6_rewrite_local_node)
Definition: ip6_forward.c:2474
ip_lookup_next_t lookup_next_index
Definition: lookup.h:163
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
static uword ip6_rewrite_local(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: ip6_forward.c:2453
u8 as_u8[16]
Definition: ip6_packet.h:47
u64 as_u64[2]
Definition: ip6_packet.h:50
i32 dst_address_length_refcounts[129]
Definition: ip6.h:140
vlib_node_registration_t ip6_lookup_node
(constructor) VLIB_REGISTER_NODE (ip6_lookup_node)
Definition: ip6_forward.c:1267
#define UNFORMAT_END_OF_INPUT
Definition: format.h:142
u32 miss_adj_index
Definition: lookup.h:380
static u8 * format_ip6_rewrite_trace(u8 *s, va_list *args)
Definition: ip6_forward.c:1340
u32 vnet_config_del_feature(vlib_main_t *vm, vnet_config_main_t *cm, u32 config_string_heap_index, u32 feature_index, void *feature_config, u32 n_feature_config_bytes)
Definition: config.c:284
ip_config_main_t rx_config_mains[VNET_N_CAST]
Definition: lookup.h:401
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:480
u32 share_count
Definition: lookup.h:192
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 uword ip6_miss(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: ip6_forward.c:1486
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:519
static clib_error_t * ip6_config(vlib_main_t *vm, unformat_input_t *input)
Definition: ip6_forward.c:2829
always_inline uword max_log2(uword x)
Definition: clib.h:216
#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
uword ip_csum_t
Definition: ip_packet.h:86
static clib_error_t * test_ip6_link_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: ip6_forward.c:2643
vlib_node_registration_t ip6_multicast_node
(constructor) VLIB_REGISTER_NODE (ip6_multicast_node)
Definition: ip6_forward.c:1530
unformat_function_t unformat_vnet_sw_interface
#define clib_error_report(e)
Definition: error.h:126
static clib_error_t * ip6_add_del_interface_address_internal(vlib_main_t *vm, u32 sw_if_index, ip6_address_t *new_address, u32 new_length, u32 redistribute, u32 insert_routes, u32 is_del)
Definition: ip6_forward.c:1090
#define VNET_HW_INTERFACE_FLAG_LINK_UP
Definition: interface.h:241
void ip6_add_del_route(ip6_main_t *im, ip6_add_del_route_args_t *a)
Definition: ip6_forward.c:208
vlib_error_t * errors
Definition: node.h:378
u32 ip6_fib_lookup_with_table(ip6_main_t *im, u32 fib_index, ip6_address_t *dst)
Definition: ip6_forward.c:61
int BV() clib_bihash_add_del(BVT(clib_bihash)*h, BVT(clib_bihash_kv)*add_v, int is_add)
always_inline u32 ip6_compute_flow_hash(ip6_header_t *ip, u32 flow_hash_config)
Definition: ip6.h:494
u32 neighbor_probe_adj_index
Definition: lookup.h:313
always_inline uword ip6_rewrite_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, int rewrite_for_locally_received_packets)
Definition: ip6_forward.c:2206
ip6_address_t src_address
Definition: ip6_packet.h:293
#define hash_v3_mix32(a, b, c)
Definition: hash.h:487
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
uword as_uword[16/sizeof(uword)]
Definition: ip6_packet.h:51
u32 * node_index_by_feature_index
Definition: config.h:96
VNET_SW_INTERFACE_ADD_DEL_FUNCTION(ip6_sw_interface_add_del)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
always_inline void * ip_interface_address_get_address(ip_lookup_main_t *lm, ip_interface_address_t *a)
Definition: lookup.h:513
always_inline uword unformat_check_input(unformat_input_t *i)
Definition: format.h:168
vlib_node_registration_t ip6_drop_node
(constructor) VLIB_REGISTER_NODE (ip6_drop_node)
Definition: ip6_forward.c:1491
ip6_discover_neighbor_error_t
Definition: ip6_forward.c:1924
static uword ip6_drop(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: ip6_forward.c:1474
vlib_packet_template_t discover_neighbor_packet_template
Definition: ip6.h:164
u32 ip6_tcp_udp_icmp_validate_checksum(vlib_main_t *vm, vlib_buffer_t *p0)
Definition: ip6_forward.c:1639
always_inline uword ip6_address_is_zero(ip6_address_t *a)
Definition: ip6_packet.h:232
vlib_rx_or_tx_t
Definition: defs.h:44
vnet_main_t * vnet_get_main(void)
Definition: misc.c:45
vlib_node_registration_t ip6_indirect_node
(constructor) VLIB_REGISTER_NODE (ip6_indirect_node)
Definition: ip6_forward.c:1287
ip6_main_t ip6_main
Definition: ip6_forward.c:2490
clib_error_t * ip6_sw_interface_add_del(vnet_main_t *vnm, u32 sw_if_index, u32 is_add)
Definition: ip6_forward.c:1204
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
Definition: buffer.h:77
u8 * format_ethernet_address(u8 *s, va_list *args)
Definition: format.c:43
unformat_function_t unformat_pg_ip6_header
Definition: format.h:91
format_function_t format_ip_adjacency_packet_data
Definition: format.h:52
#define vlib_prefetch_buffer_with_index(vm, bi, type)
Prefetch buffer metadata by buffer index The first 64 bytes of buffer contains most header informatio...
Definition: buffer_funcs.h:181
static clib_error_t * show_ip6_local_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: ip6_forward.c:2733
ip_csum_t ip_incremental_checksum(ip_csum_t sum, void *_data, uword n_bytes)
Definition: ip_checksum.c:43
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:109
#define always_inline
Definition: clib.h:84
static clib_error_t * set_ip6_flow_hash_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: ip6_forward.c:2685
#define IP_BUFFER_L4_CHECKSUM_CORRECT
Definition: buffer.h:50
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:107
always_inline void vlib_increment_combined_counter(vlib_combined_counter_main_t *cm, u32 cpu_index, u32 index, u32 packet_increment, u32 byte_increment)
Definition: counter.h:210
int i32
Definition: types.h:81
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
#define IP6_FIB_DEFAULT_HASH_NUM_BUCKETS
Definition: ip6.h:53
u32 ip_multipath_adjacency_add_del_next_hop(ip_lookup_main_t *lm, u32 is_del, u32 old_mp_adj_index, u32 next_hop_adj_index, u32 next_hop_weight, u32 *new_mp_adj_index)
Definition: lookup.c:495
always_inline uword pool_elts(void *v)
Definition: pool.h:97
u8 pre_data[VLIB_BUFFER_PRE_DATA_SIZE]
Space for inserting data before buffer start.
Definition: buffer.h:142
always_inline uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
Definition: buffer_funcs.h:112
void BV() clib_bihash_init(BVT(clib_bihash)*h, char *name, u32 nbuckets, uword memory_size)
#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
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:953
always_inline void ip6_src_address_for_packet(ip6_main_t *im, vlib_buffer_t *p, ip6_address_t *src, u32 sw_if_index)
Definition: ip6.h:276
always_inline void * vlib_frame_vector_args(vlib_frame_t *f)
Definition: node_funcs.h:202
ip6_fib_t * fibs
Definition: ip6.h:143
void ip_del_adjacency(ip_lookup_main_t *lm, u32 adj_index)
Definition: lookup.c:285
#define VLIB_BUFFER_NEXT_PRESENT
Definition: buffer.h:93
u32 lookup_table_nbuckets
Definition: ip6.h:167
int BV() clib_bihash_search(BVT(clib_bihash)*h, BVT(clib_bihash_kv)*search_key, BVT(clib_bihash_kv)*valuep)
always_inline void vlib_buffer_copy_trace_flag(vlib_main_t *vm, vlib_buffer_t *b, u32 bi_target)
Definition: trace_funcs.h:136
u8 packet_data[128-1 *sizeof(u32)]
Definition: ip6_forward.c:1305
always_inline u16 ip_csum_fold(ip_csum_t c)
Definition: ip_packet.h:138
vnet_api_error_t api_errno
Definition: vnet.h:76
ip6_fib_t * find_ip6_fib_by_table_index_or_id(ip6_main_t *im, u32 table_index_or_id, u32 flags)
Get or create an IPv6 fib.
Definition: ip6_forward.c:185
ip6_address_t dst_address
Definition: ip6.h:346
#define hash_get(h, key)
Definition: hash.h:231
#define clib_bitmap_foreach(i, ai, body)
Definition: bitmap.h:308
#define pool_elt_at_index(p, i)
Definition: pool.h:346
vlib_main_t * vlib_main
Definition: vnet.h:78
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:81
u32 ip6_fib_lookup(ip6_main_t *im, u32 sw_if_index, ip6_address_t *dst)
Definition: ip6_forward.c:94
u32 * classify_table_index_by_sw_if_index
Definition: lookup.h:398
ip6_error_t
Definition: ip6_error.h:76
static void ip6_del_interface_routes(ip6_main_t *im, u32 fib_index, ip6_address_t *address, u32 address_length)
Definition: ip6_forward.c:1040
vlib_node_registration_t ip6_input_node
(constructor) VLIB_REGISTER_NODE (ip6_input_node)
Definition: ip6_input.c:289
#define BIHASH_KVP_PER_PAGE
Definition: bihash_24_8.h:18
#define IP6_FIB_DEFAULT_HASH_MEMORY_SIZE
Definition: ip6.h:54
uword os_get_cpu_number(void)
Definition: unix-misc.c:206
ip_adjacency_t * add_adj
Definition: ip6.h:355
vlib_node_registration_t ip6_punt_node
(constructor) VLIB_REGISTER_NODE (ip6_punt_node)
Definition: ip6_forward.c:1504
int vnet_set_ip6_flow_hash(u32 table_id, u32 flow_hash_config)
Definition: ip6_forward.c:2669
#define PREDICT_FALSE(x)
Definition: clib.h:97
u8 local_next_by_ip_protocol[256]
Definition: lookup.h:416
vnet_hw_interface_class_t srp_hw_interface_class
always_inline uword * clib_bitmap_set(uword *ai, uword i, uword value)
Definition: bitmap.h:132
u32 index
Definition: ip6.h:67
void vlib_put_frame_to_node(vlib_main_t *vm, u32 to_node_index, vlib_frame_t *f)
Definition: main.c:191
#define vlib_validate_buffer_enqueue_x2(vm, node, next_index, to_next, n_left_to_next, bi0, bi1, next0, next1)
Definition: buffer_node.h:43
static uword ip6_rewrite_transit(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: ip6_forward.c:2444
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Definition: buffer_node.h:83
#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
void ip6_forward_next_trace(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, vlib_rx_or_tx_t which_adj_index)
Definition: ip6_forward.c:1362
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:129
vnet_hw_interface_class_t ethernet_hw_interface_class
u32 ip6_get_route(ip6_main_t *im, u32 table_index_or_table_id, u32 flags, ip6_address_t *address, u32 address_length)
Definition: ip6_forward.c:523
uword * fib_index_by_table_id
Definition: ip6.h:152
void vnet_ip6_fib_init(ip6_main_t *im, u32 fib_index)
Definition: ip6_forward.c:101
static uword ip6_local(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: ip6_forward.c:1669
u32 as_u32[4]
Definition: ip6_packet.h:49
ip6_address_t fib_masks[129]
Definition: ip6.h:145
#define VLIB_EARLY_CONFIG_FUNCTION(x, n,...)
Definition: init.h:137
always_inline uword ip6_address_is_equal(ip6_address_t *a, ip6_address_t *b)
Definition: ip6_packet.h:174
u16 n_vectors
Definition: node.h:307
#define IP6_ROUTE_FLAG_KEEP_OLD_ADJACENCY
Definition: ip6.h:331
#define CLIB_PREFETCH(addr, size, type)
Definition: cache.h:82
uword * non_empty_dst_address_length_bitmap
Definition: ip6.h:138
static ip6_fib_t * create_fib_with_table_id(ip6_main_t *im, u32 table_id)
Definition: ip6_forward.c:172
void ip6_maybe_remap_adjacencies(ip6_main_t *im, u32 table_index_or_table_id, u32 flags)
Definition: ip6_forward.c:601
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:298
vlib_node_registration_t ip6_local_node
(constructor) VLIB_REGISTER_NODE (ip6_local_node)
Definition: ip6_forward.c:1892
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
Definition: ip6.h:62
clib_error_t * ip6_sw_interface_admin_up_down(vnet_main_t *vnm, u32 sw_if_index, u32 flags)
Definition: ip6_forward.c:1167
static u8 * format_ip6_forward_next_trace(u8 *s, va_list *args)
Definition: ip6_forward.c:1308
vlib_node_registration_t ip6_miss_node
(constructor) VLIB_REGISTER_NODE (ip6_miss_node)
Definition: ip6_forward.c:1517
clib_error_t * ip6_probe_neighbor(vlib_main_t *vm, ip6_address_t *dst, u32 sw_if_index)
Definition: ip6_forward.c:2129
#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)
static uword ip6_drop_or_punt(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, ip6_error_t error_code)
Definition: ip6_forward.c:1451
unformat_function_t * unformat_edit
Definition: pg.h:290
#define IP6_ROUTE_FLAG_DEL
Definition: ip6.h:328
always_inline uword ip6_lookup_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, int is_indirect)
Definition: ip6_forward.c:665
void ip_lookup_init(ip_lookup_main_t *lm, u32 is_ip6)
Definition: lookup.c:841
#define pool_is_free_index(P, I)
Definition: pool.h:197
#define ARRAY_LEN(x)
Definition: clib.h:59
void ip6_adjacency_set_interface_route(vnet_main_t *vnm, ip_adjacency_t *adj, u32 sw_if_index, u32 if_address_index)
Definition: ip6_forward.c:945
void ip6_ethernet_mac_address_from_link_local_address(u8 *mac, ip6_address_t *ip)
Definition: ip6_forward.c:2630
always_inline uword vnet_sw_interface_is_admin_up(vnet_main_t *vnm, u32 sw_if_index)
void ip6_delete_matching_routes(ip6_main_t *im, u32 table_index_or_table_id, u32 flags, ip6_address_t *address, u32 address_length)
Definition: ip6_forward.c:620
always_inline void ip6_set_solicited_node_multicast_address(ip6_address_t *a, u32 id)
Definition: ip6_packet.h:135
vlib_combined_counter_main_t adjacency_counters
Definition: lookup.h:353
u8 builtin_protocol_by_ip_protocol[256]
Definition: lookup.h:419
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:150
struct _vnet_classify_main vnet_classify_main_t
Definition: vnet_classify.h:50
#define foreach_flow_hash_bit
Definition: lookup.h:138
u32 * if_address_pool_index_by_sw_if_index
Definition: lookup.h:395
ip6_add_del_interface_address_function_t * function
Definition: ip6.h:101
always_inline uword is_pow2(uword x)
Definition: clib.h:252
u16 cached_next_index
Definition: node.h:422
void ip6_register_protocol(u32 protocol, u32 node_index)
Definition: ip6_forward.c:1908
#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
void vlib_packet_template_init(vlib_main_t *vm, vlib_packet_template_t *t, void *packet_data, uword n_packet_data_bytes, uword min_n_buffers_each_physmem_alloc, char *fmt,...)
Definition: buffer.c:1093
vlib_node_registration_t ip6_discover_neighbor_node
(constructor) VLIB_REGISTER_NODE (ip6_discover_neighbor_node)
Definition: ip6_forward.c:2111
#define ASSERT(truth)
unsigned int u32
Definition: types.h:88
VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION(ip6_sw_interface_admin_up_down)
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:87
#define vnet_buffer(b)
Definition: buffer.h:300
ip_lookup_main_t lookup_main
Definition: ip6.h:135
#define LOG2_IP_BUFFER_L4_CHECKSUM_CORRECT
Definition: buffer.h:48
#define IP6_ROUTE_FLAG_NOT_LAST_IN_GROUP
Definition: ip6.h:333
u8 * format(u8 *s, char *fmt,...)
Definition: format.c:405
#define hash_v3_finalize32(a, b, c)
Definition: hash.h:497
static uword ip6_discover_neighbor(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: ip6_forward.c:1930
#define BV(a)
u32 next_buffer
Next buffer for this linked-list of buffers.
Definition: buffer.h:112
u8 * prefix_lengths_in_search_order
Definition: ip6.h:139
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:225
u32 vnet_config_add_feature(vlib_main_t *vm, vnet_config_main_t *cm, u32 config_string_heap_index, u32 feature_index, void *feature_config, u32 n_feature_config_bytes)
Definition: config.c:233
vnet_classify_main_t vnet_classify_main
Definition: vnet_classify.c:21
int vnet_set_ip6_classify_intfc(vlib_main_t *vm, u32 sw_if_index, u32 table_index)
Definition: ip6_forward.c:2758
#define IP_FLOW_HASH_DEFAULT
Definition: lookup.h:136
u32 n_adjacency_remaps
Definition: lookup.h:373
static char * ip6_discover_neighbor_error_strings[]
Definition: ip6_forward.c:2105
always_inline uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
Definition: node_funcs.h:919
#define VLIB_BUFFER_IS_TRACED
Definition: buffer.h:91
static int BV() clib_bihash_search_inline_2(BVT(clib_bihash)*h, BVT(clib_bihash_kv)*search_key, BVT(clib_bihash_kv)*valuep)
#define IP6_ROUTE_FLAG_FIB_INDEX
Definition: ip6.h:330
vlib_node_registration_t ip6_rewrite_node
(constructor) VLIB_REGISTER_NODE (ip6_rewrite_node)
Definition: ip6_forward.c:2461
always_inline ip_adjacency_t * ip_get_adjacency(ip_lookup_main_t *lm, u32 adj_index)
Definition: lookup.h:423
always_inline ip_csum_t ip_csum_with_carry(ip_csum_t sum, ip_csum_t x)
Definition: ip_packet.h:89
always_inline uword format_get_indent(u8 *s)
Definition: format.h:72
u64 uword
Definition: types.h:112
#define vec_elt(v, i)
Get vector value at index i.
#define IP_BUFFER_L4_CHECKSUM_COMPUTED
Definition: buffer.h:49
Definition: defs.h:46
void ip6_foreach_matching_route(ip6_main_t *im, u32 table_index_or_table_id, u32 flags, ip6_address_t *dst_address, u32 address_length, ip6_address_t **results, u8 **result_lengths)
Definition: ip6_forward.c:547
unsigned short u16
Definition: types.h:57
struct ip_adjacency_t::@112::@114 arp
#define BVT(a)
u16 payload_length
Definition: ip6_packet.h:284
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
double f64
Definition: types.h:140
static void *BV() clib_bihash_get_value(BVT(clib_bihash)*h, uword offset)
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
void ip6_link_local_address_from_ethernet_mac_address(ip6_address_t *ip, u8 *mac)
Definition: ip6_forward.c:2614
vnet_sw_interface_t * sw_interfaces
Definition: interface.h:449
struct ip_adjacency_t::@112::@115 classify
always_inline void vlib_set_next_frame_buffer(vlib_main_t *vm, vlib_node_runtime_t *node, u32 next_index, u32 buffer_index)
Definition: node_funcs.h:292
u32 flow_hash_config
Definition: ip6.h:70
static void ip6_add_interface_routes(vnet_main_t *vnm, u32 sw_if_index, ip6_main_t *im, u32 fib_index, ip_interface_address_t *a)
Definition: ip6_forward.c:983
clib_error_t * ip_interface_address_add_del(ip_lookup_main_t *lm, u32 sw_if_index, void *addr_fib, u32 address_length, u32 is_del, u32 *result_if_address_index)
Definition: lookup.c:735
always_inline void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace_funcs.h:55
#define clib_mem_unaligned(pointer, type)
Definition: types.h:153
struct ip_adjacency_t::@112::@116 indirect
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
uword * interface_route_adj_index_by_sw_if_index
Definition: ip6.h:158
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
Definition: buffer.h:162
ip_multipath_adjacency_t * multipath_adjacencies
Definition: lookup.h:359
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:140
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
u32 vnet_ip6_neighbor_glean_add(u32 fib_index, void *next_hop_arg)
Definition: ip6_neighbor.c:518
always_inline void ip_call_add_del_adjacency_callbacks(ip_lookup_main_t *lm, u32 adj_index, u32 is_del)
Definition: lookup.h:449
u8 data[0]
Packet data.
Definition: buffer.h:150
#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
#define IP6_ROUTE_FLAG_NO_REDISTRIBUTE
Definition: ip6.h:332
ip_local_next_t
Definition: lookup.h:327
void ip6_add_del_route_next_hop(ip6_main_t *im, u32 flags, ip6_address_t *dst_address, u32 dst_address_length, ip6_address_t *next_hop, u32 next_hop_sw_if_index, u32 next_hop_weight, u32 adj_index, u32 explicit_fib_index)
Definition: ip6_forward.c:301
i16 explicit_fib_index
Definition: lookup.h:168
always_inline f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:182
u32 table_id
Definition: ip6.h:64
always_inline void ip6_address_mask(ip6_address_t *a, ip6_address_t *mask)
Definition: ip6_packet.h:201
#define clib_error_return(e, args...)
Definition: error.h:112
#define IP6_ROUTE_FLAG_TABLE_ID
Definition: ip6.h:329
struct _unformat_input_t unformat_input_t
always_inline uword pow2_mask(uword x)
Definition: clib.h:242
format_function_t format_ip6_header
Definition: format.h:90
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 vlib_smp_unsafe_warning(void)
Definition: threads.h:185
vlib_frame_t * vlib_get_frame_to_node(vlib_main_t *vm, u32 to_node_index)
Definition: main.c:184
static clib_error_t * ip6_lookup_init(vlib_main_t *vm)
Definition: ip6_forward.c:2493
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
static uword ip6_lookup(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: ip6_forward.c:1258
#define vnet_rewrite_two_headers(rw0, rw1, p0, p1, most_likely_size)
Definition: rewrite.h:250
always_inline uword ip6_destination_matches_route(ip6_main_t *im, ip6_address_t *key, ip6_address_t *dest, uword dest_length)
Definition: ip6.h:236
u32 flags
buffer flags: VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:84
#define BITS(x)
Definition: clib.h:58
ip6_discover_neighbor_next_t
Definition: ip6_forward.c:1918
always_inline ip6_address_t * ip6_interface_address_matching_destination(ip6_main_t *im, ip6_address_t *dst, u32 sw_if_index, ip_interface_address_t **result_ia)
Definition: ip6.h:296
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
clib_random_buffer_t random_buffer
Definition: main.h:153
Definition: pg.h:288
vnet_config_main_t config_main
Definition: lookup.h:343
static uword ip6_punt(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: ip6_forward.c:1480
Definition: defs.h:45
ip6_address_t dst_address
Definition: ip6_packet.h:293
format_function_t format_ip_adjacency
Definition: format.h:51
ip6_rewrite_next_t
Definition: ip6_forward.c:2201