FD.io VPP  v17.07.01-10-g3be13f0
Vector Packet Processing
interface.c
Go to the documentation of this file.
1 /*
2  * gre_interface.c: gre interfaces
3  *
4  * Copyright (c) 2012 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include <vnet/vnet.h>
19 #include <vnet/pg/pg.h>
20 #include <vnet/gre/gre.h>
21 #include <vnet/ip/format.h>
22 #include <vnet/fib/ip4_fib.h>
23 #include <vnet/fib/ip6_fib.h>
24 #include <vnet/adj/adj_midchain.h>
25 #include <vnet/adj/adj_nbr.h>
26 #include <vnet/mpls/mpls.h>
27 
29 
30 static inline u64
32  const ip4_address_t *dst,
33  u32 out_fib_index)
34 {
35  // FIXME. the fib index should be part of the key
36  return ((u64)src->as_u32 << 32 | (u64)dst->as_u32);
37 }
38 
39 static u8 *
40 format_gre_tunnel_type (u8 * s, va_list * args)
41 {
42  gre_tunnel_type_t type = va_arg (*args, gre_tunnel_type_t);
43 
44  return (format(s, "%s", gre_tunnel_type_names[type]));
45 }
46 
47 static u8 *
48 format_gre_tunnel (u8 * s, va_list * args)
49 {
50  gre_tunnel_t * t = va_arg (*args, gre_tunnel_t *);
51  gre_main_t * gm = &gre_main;
52  u8 is_ipv6 = t->tunnel_dst.fp_proto == FIB_PROTOCOL_IP6 ? 1 : 0;
53 
54  if (!is_ipv6)
55  s = format (s,
56  "[%d] %U (src) %U (dst) payload %U outer_fib_index %d",
57  t - gm->tunnels,
61  t->outer_fib_index);
62  else
63  s = format (s,
64  "[%d] %U (src) %U (dst) payload %U outer_fib_index %d",
65  t - gm->tunnels,
69  t->outer_fib_index);
70 
71  return s;
72 }
73 
74 static gre_tunnel_t *
75 gre_tunnel_db_find (const ip46_address_t *src,
76  const ip46_address_t *dst,
77  u32 out_fib_index,
78  u8 is_ipv6)
79 {
80  gre_main_t * gm = &gre_main;
81  uword * p;
82  u64 key4, key6[4];
83 
84  if (!is_ipv6)
85  {
86  key4 = gre4_mk_key(&src->ip4, &dst->ip4, out_fib_index);
87  p = hash_get (gm->tunnel_by_key4, key4);
88  }
89  else
90  {
91  key6[0] = src->ip6.as_u64[0];
92  key6[1] = src->ip6.as_u64[1];
93  key6[2] = dst->ip6.as_u64[0];
94  key6[3] = dst->ip6.as_u64[1];
95  p = hash_get_mem (gm->tunnel_by_key6, key6);
96  }
97 
98  if (NULL == p)
99  return (NULL);
100 
101  return (pool_elt_at_index (gm->tunnels, p[0]));
102 }
103 
104 static void
106 {
107  gre_main_t * gm = &gre_main;
108  u64 key4, key6[4], *key6_copy;
109  u8 is_ipv6 = t->tunnel_dst.fp_proto == FIB_PROTOCOL_IP6 ? 1 : 0;
110 
111  if (!is_ipv6)
112  {
113  key4 = gre4_mk_key(&t->tunnel_src.ip4, &t->tunnel_dst.fp_addr.ip4,
114  t->outer_fib_index);
115  hash_set (gm->tunnel_by_key4, key4, t - gm->tunnels);
116  }
117  else
118  {
119  key6[0] = t->tunnel_src.ip6.as_u64[0];
120  key6[1] = t->tunnel_src.ip6.as_u64[1];
121  key6[2] = t->tunnel_dst.fp_addr.ip6.as_u64[0];
122  key6[3] = t->tunnel_dst.fp_addr.ip6.as_u64[1];
123  key6_copy = clib_mem_alloc (sizeof (key6));
124  clib_memcpy (key6_copy, key6, sizeof (key6));
125  hash_set_mem (gm->tunnel_by_key6, key6_copy, t - gm->tunnels);
126  }
127 }
128 
129 static void
131 {
132  gre_main_t * gm = &gre_main;
133  u64 key4, key6[4];
134  u8 is_ipv6 = t->tunnel_dst.fp_proto == FIB_PROTOCOL_IP6 ? 1 : 0;
135 
136  if (!is_ipv6)
137  {
138  key4 = gre4_mk_key(&t->tunnel_src.ip4, &t->tunnel_dst.fp_addr.ip4,
139  t->outer_fib_index);
140  hash_unset (gm->tunnel_by_key4, key4);
141  }
142  else
143  {
144  key6[0] = t->tunnel_src.ip6.as_u64[0];
145  key6[1] = t->tunnel_src.ip6.as_u64[1];
146  key6[2] = t->tunnel_dst.fp_addr.ip6.as_u64[0];
147  key6[3] = t->tunnel_dst.fp_addr.ip6.as_u64[1];
148  hash_unset_mem (gm->tunnel_by_key6, key6);
149  }
150 
151 }
152 
153 static gre_tunnel_t *
155 {
156 #if (CLIB_DEBUG > 0)
158 #endif
159  return ((gre_tunnel_t*) (((char*)node) -
161 }
162 
163 /**
164  * gre_tunnel_stack
165  *
166  * 'stack' (resolve the recursion for) the tunnel's midchain adjacency
167  */
168 void
170 {
171  gre_main_t * gm = &gre_main;
172  ip_adjacency_t *adj;
173  gre_tunnel_t *gt;
174  u32 sw_if_index;
175 
176  adj = adj_get(ai);
177  sw_if_index = adj->rewrite_header.sw_if_index;
178 
179  if ((vec_len(gm->tunnel_index_by_sw_if_index) < sw_if_index) ||
180  (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index]))
181  return;
182 
183  gt = pool_elt_at_index(gm->tunnels,
184  gm->tunnel_index_by_sw_if_index[sw_if_index]);
185 
186  /*
187  * find the adjacency that is contributed by the FIB entry
188  * that this tunnel resovles via, and use it as the next adj
189  * in the midchain
190  */
192  gt->hw_if_index) &
194  {
196  ai,
198  }
199  else
200  {
202  }
203 }
204 
205 /**
206  * @brief Call back when restacking all adjacencies on a GRE interface
207  */
208 static adj_walk_rc_t
210  void *ctx)
211 {
212  gre_tunnel_stack(ai);
213 
214  return (ADJ_WALK_RC_CONTINUE);
215 }
216 
217 static void
219 {
220  fib_protocol_t proto;
221 
222  /*
223  * walk all the adjacencies on th GRE interface and restack them
224  */
226  {
228  proto,
230  NULL);
231  }
232 }
233 
234 /**
235  * Function definition to backwalk a FIB node
236  */
240 {
242 
244 }
245 
246 /**
247  * Function definition to get a FIB node from its index
248  */
249 static fib_node_t*
251 {
252  gre_tunnel_t * gt;
253  gre_main_t * gm;
254 
255  gm = &gre_main;
256  gt = pool_elt_at_index(gm->tunnels, index);
257 
258  return (&gt->node);
259 }
260 
261 /**
262  * Function definition to inform the FIB node that its last lock has gone.
263  */
264 static void
266 {
267  /*
268  * The MPLS GRE tunnel is a root of the graph. As such
269  * it never has children and thus is never locked.
270  */
271  ASSERT(0);
272 }
273 
274 /*
275  * Virtual function table registered by MPLS GRE tunnels
276  * for participation in the FIB object graph.
277  */
278 const static fib_node_vft_t gre_vft = {
280  .fnv_last_lock = gre_tunnel_last_lock_gone,
281  .fnv_back_walk = gre_tunnel_back_walk,
282 };
283 
284 static int
286  u32 * sw_if_indexp)
287 {
288  gre_main_t * gm = &gre_main;
289  vnet_main_t * vnm = gm->vnet_main;
290  ip4_main_t * im4 = &ip4_main;
291  ip6_main_t * im6 = &ip6_main;
292  gre_tunnel_t * t;
294  u32 hw_if_index, sw_if_index;
295  u32 outer_fib_index;
296  u8 address[6];
297  clib_error_t *error;
298  u8 is_ipv6 = a->is_ipv6;
299 
300  if (!is_ipv6)
301  outer_fib_index = ip4_fib_index_from_table_id(a->outer_fib_id);
302  else
303  outer_fib_index = ip6_fib_index_from_table_id(a->outer_fib_id);
304 
305  if (~0 == outer_fib_index)
306  return VNET_API_ERROR_NO_SUCH_FIB;
307 
308  t = gre_tunnel_db_find(&a->src, &a->dst, a->outer_fib_id, a->is_ipv6);
309 
310  if (NULL != t)
311  return VNET_API_ERROR_INVALID_VALUE;
312 
314  memset (t, 0, sizeof (*t));
316 
317  if (a->teb)
319  else
321 
322  if (vec_len (gm->free_gre_tunnel_hw_if_indices[t->type]) > 0) {
324 
325  hw_if_index = gm->free_gre_tunnel_hw_if_indices[t->type]
327  _vec_len (gm->free_gre_tunnel_hw_if_indices[t->type]) -= 1;
328 
329  hi = vnet_get_hw_interface (vnm, hw_if_index);
330  hi->dev_instance = t - gm->tunnels;
331  hi->hw_instance = hi->dev_instance;
332 
333  /* clear old stats of freed tunnel before reuse */
334  sw_if_index = hi->sw_if_index;
341  (&im->sw_if_counters[VNET_INTERFACE_COUNTER_DROP], sw_if_index);
343  if (GRE_TUNNEL_TYPE_TEB == t->type)
344  {
346  hi->tx_node_index,
347  "adj-l2-midchain");
348  }
349  } else {
350  if (GRE_TUNNEL_TYPE_TEB == t->type)
351  {
352  /* Default MAC address (d00b:eed0:0000 + sw_if_index) */
353  memset (address, 0, sizeof (address));
354  address[0] = 0xd0;
355  address[1] = 0x0b;
356  address[2] = 0xee;
357  address[3] = 0xd0;
358  address[4] = t - gm->tunnels;
359 
360  error = ethernet_register_interface(vnm,
361  gre_device_teb_class.index,
362  t - gm->tunnels, address,
363  &hw_if_index,
364  0);
365 
366  if (error)
367  {
368  clib_error_report (error);
369  return VNET_API_ERROR_INVALID_REGISTRATION;
370  }
371  hi = vnet_get_hw_interface (vnm, hw_if_index);
372 
374  hi->tx_node_index,
375  "adj-l2-midchain");
376  } else {
377  hw_if_index = vnet_register_interface(vnm,
378  gre_device_class.index,
379  t - gm->tunnels,
381  t - gm->tunnels);
382  }
383  hi = vnet_get_hw_interface (vnm, hw_if_index);
384  sw_if_index = hi->sw_if_index;
385  }
386 
387  t->hw_if_index = hw_if_index;
388  t->outer_fib_index = outer_fib_index;
389  t->sw_if_index = sw_if_index;
391 
393  gm->tunnel_index_by_sw_if_index[sw_if_index] = t - gm->tunnels;
394 
395  if (!is_ipv6)
396  {
397  vec_validate (im4->fib_index_by_sw_if_index, sw_if_index);
398  hi->min_packet_bytes = 64 + sizeof (gre_header_t) + sizeof (ip4_header_t);
399  }
400  else
401  {
402  vec_validate (im6->fib_index_by_sw_if_index, sw_if_index);
403  hi->min_packet_bytes = 64 + sizeof (gre_header_t) + sizeof (ip6_header_t);
404  }
405 
407  /* preamble */ 8 + /* inter frame gap */ 12;
408 
409  /* Standard default gre MTU. */
411 
412  /*
413  * source the FIB entry for the tunnel's destination
414  * and become a child thereof. The tunnel will then get poked
415  * when the forwarding for the entry updates, and the tunnel can
416  * re-stack accordingly
417  */
418 
419  clib_memcpy (&t->tunnel_src, &a->src, sizeof (t->tunnel_src));
420  t->tunnel_dst.fp_len = !is_ipv6 ? 32 : 128;
422  t->tunnel_dst.fp_addr = a->dst;
423 
425 
426  t->fib_entry_index =
427  fib_table_entry_special_add(outer_fib_index,
428  &t->tunnel_dst,
431  t->sibling_index =
434  t - gm->tunnels);
435 
436  if (GRE_TUNNEL_TYPE_TEB == t->type)
437  {
440  &zero_addr,
441  sw_if_index);
443  }
444 
445  if (sw_if_indexp)
446  *sw_if_indexp = sw_if_index;
447 
448  return 0;
449 }
450 
451 static int
453  u32 * sw_if_indexp)
454 {
455  gre_main_t * gm = &gre_main;
456  vnet_main_t * vnm = gm->vnet_main;
457  gre_tunnel_t * t;
458  u32 sw_if_index;
459 
460  t = gre_tunnel_db_find(&a->src, &a->dst, a->outer_fib_id, a->is_ipv6);
461 
462  if (NULL == t)
463  return VNET_API_ERROR_NO_SUCH_ENTRY;
464 
465  sw_if_index = t->sw_if_index;
466  vnet_sw_interface_set_flags (vnm, sw_if_index, 0 /* down */);
467  /* make sure tunnel is removed from l2 bd or xconnect */
468  set_int_l2_mode(gm->vlib_main, vnm, MODE_L3, sw_if_index, 0, 0, 0, 0);
470  gm->tunnel_index_by_sw_if_index[sw_if_index] = ~0;
471 
472  if (GRE_TUNNEL_TYPE_TEB == t->type)
474 
477 
479  t->sibling_index);
481  FIB_SOURCE_RR);
482 
484  fib_node_deinit(&t->node);
485  pool_put (gm->tunnels, t);
486 
487  if (sw_if_indexp)
488  *sw_if_indexp = sw_if_index;
489 
490  return 0;
491 }
492 
493 int
495  u32 * sw_if_indexp)
496 {
497  if (a->is_add)
498  return (vnet_gre_tunnel_add(a, sw_if_indexp));
499  else
500  return (vnet_gre_tunnel_delete(a, sw_if_indexp));
501 }
502 
503 clib_error_t *
505 {
506  gre_main_t * gm = &gre_main;
508  gre_tunnel_t *t;
509  u32 ti;
510 
511  hi = vnet_get_hw_interface (vnm, hw_if_index);
512 
513  if (NULL == gm->tunnel_index_by_sw_if_index ||
515  return (NULL);
516 
518 
519  if (~0 == ti)
520  /* not one of ours */
521  return (NULL);
522 
523  t = pool_elt_at_index(gm->tunnels, ti);
524 
527  else
528  vnet_hw_interface_set_flags (vnm, hw_if_index, 0 /* down */);
529 
531 
532  return /* no error */ 0;
533 }
534 
535 static clib_error_t *
537  unformat_input_t * input,
538  vlib_cli_command_t * cmd)
539 {
540  unformat_input_t _line_input, * line_input = &_line_input;
541  vnet_gre_add_del_tunnel_args_t _a, * a = &_a;
542  ip46_address_t src, dst;
543  u32 outer_fib_id = 0;
544  u8 teb = 0;
545  int rv;
546  u32 num_m_args = 0;
547  u8 is_add = 1;
548  u32 sw_if_index;
549  clib_error_t *error = NULL;
550  u8 ipv4_set = 0;
551  u8 ipv6_set = 0;
552 
553  /* Get a line of input. */
554  if (! unformat_user (input, unformat_line_input, line_input))
555  return 0;
556 
557  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
558  if (unformat (line_input, "del"))
559  is_add = 0;
560  else if (unformat (line_input, "src %U", unformat_ip4_address, &src.ip4)) {
561  num_m_args++;
562  ipv4_set = 1;
563  } else if (unformat (line_input, "dst %U", unformat_ip4_address, &dst.ip4)) {
564  num_m_args++;
565  ipv4_set = 1;
566  } else if (unformat (line_input, "src %U", unformat_ip6_address, &src.ip6)) {
567  num_m_args++;
568  ipv6_set = 1;
569  } else if (unformat (line_input, "dst %U", unformat_ip6_address, &dst.ip6)) {
570  num_m_args++;
571  ipv6_set = 1;
572  } else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
573  ;
574  else if (unformat (line_input, "teb"))
575  teb = 1;
576  else
577  {
578  error = clib_error_return (0, "unknown input `%U'",
579  format_unformat_error, line_input);
580  goto done;
581  }
582  }
583 
584  if (num_m_args < 2)
585  {
586  error = clib_error_return (0, "mandatory argument(s) missing");
587  goto done;
588  }
589 
590  if ((ipv4_set && memcmp (&src.ip4, &dst.ip4, sizeof(src.ip4)) == 0) ||
591  (ipv6_set && memcmp (&src.ip6, &dst.ip6, sizeof(src.ip6)) == 0))
592  {
593  error = clib_error_return (0, "src and dst are identical");
594  goto done;
595  }
596 
597  if (ipv4_set && ipv6_set)
598  return clib_error_return (0, "both IPv4 and IPv6 addresses specified");
599 
600  if ((ipv4_set && memcmp (&dst.ip4, &zero_addr.ip4, sizeof(dst.ip4)) == 0) ||
601  (ipv6_set && memcmp (&dst.ip6, &zero_addr.ip6, sizeof(dst.ip6)) == 0))
602  {
603  error = clib_error_return (0, "dst address cannot be zero");
604  goto done;
605  }
606 
607  memset (a, 0, sizeof (*a));
608  a->outer_fib_id = outer_fib_id;
609  a->teb = teb;
610  a->is_ipv6 = ipv6_set;
611  if (!ipv6_set)
612  {
613  clib_memcpy(&a->src.ip4, &src.ip4, sizeof(src.ip4));
614  clib_memcpy(&a->dst.ip4, &dst.ip4, sizeof(dst.ip4));
615  }
616  else
617  {
618  clib_memcpy(&a->src.ip6, &src.ip6, sizeof(src.ip6));
619  clib_memcpy(&a->dst.ip6, &dst.ip6, sizeof(dst.ip6));
620  }
621 
622  if (is_add)
623  rv = vnet_gre_tunnel_add(a, &sw_if_index);
624  else
625  rv = vnet_gre_tunnel_delete(a, &sw_if_index);
626 
627  switch(rv)
628  {
629  case 0:
630  vlib_cli_output(vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main(), sw_if_index);
631  break;
632  case VNET_API_ERROR_INVALID_VALUE:
633  error = clib_error_return (0, "GRE tunnel already exists...");
634  goto done;
635  case VNET_API_ERROR_NO_SUCH_FIB:
636  error = clib_error_return (0, "outer fib ID %d doesn't exist\n",
637  outer_fib_id);
638  goto done;
639  default:
640  error = clib_error_return (0, "vnet_gre_add_del_tunnel returned %d", rv);
641  goto done;
642  }
643 
644 done:
645  unformat_free (line_input);
646 
647  return error;
648 }
649 
650 VLIB_CLI_COMMAND (create_gre_tunnel_command, static) = {
651  .path = "create gre tunnel",
652  .short_help = "create gre tunnel src <addr> dst <addr> "
653  "[outer-fib-id <fib>] [teb] [del]",
654  .function = create_gre_tunnel_command_fn,
655 };
656 
657 static clib_error_t *
659  unformat_input_t * input,
660  vlib_cli_command_t * cmd)
661 {
662  gre_main_t * gm = &gre_main;
663  gre_tunnel_t * t;
664  u32 ti = ~0;
665 
666  if (pool_elts (gm->tunnels) == 0)
667  vlib_cli_output (vm, "No GRE tunnels configured...");
668 
670  {
671  if (unformat (input, "%d", &ti))
672  ;
673  else
674  break;
675  }
676 
677  if (~0 == ti)
678  {
679  pool_foreach (t, gm->tunnels,
680  ({
681  vlib_cli_output (vm, "%U", format_gre_tunnel, t);
682  }));
683  }
684  else
685  {
686  t = pool_elt_at_index(gm->tunnels, ti);
687 
688  vlib_cli_output (vm, "%U", format_gre_tunnel, t);
689  }
690 
691  return 0;
692 }
693 
694 VLIB_CLI_COMMAND (show_gre_tunnel_command, static) = {
695  .path = "show gre tunnel",
696  .function = show_gre_tunnel_command_fn,
697 };
698 
699 /* force inclusion from application's main.c */
701 {
703 
704  return 0;
705 }
vnet_main_t * vnet_main
Definition: gre.h:172
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:436
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:169
static u64 gre4_mk_key(const ip4_address_t *src, const ip4_address_t *dst, u32 out_fib_index)
Definition: interface.c:31
void gre_tunnel_stack(adj_index_t ai)
gre_tunnel_stack
Definition: interface.c:169
static void gre_tunnel_db_add(const gre_tunnel_t *t)
Definition: interface.c:105
vmrglw vmrglh hi
Recursive resolution source.
Definition: fib_entry.h:109
#define hash_set(h, key, value)
Definition: hash.h:254
uword * tunnel_by_key6
Hash mapping ipv6 src/dst addr pair to tunnel.
Definition: gre.h:152
GRE related global data.
Definition: gre.h:128
fib_node_index_t fib_entry_index
The FIB entry sourced by the tunnel for its destination prefix.
Definition: gre.h:104
u32 hw_if_index
Definition: gre.h:97
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: interface.c:537
#define hash_unset(h, key)
Definition: hash.h:260
a
Definition: bitmap.h:516
static u8 * format_gre_tunnel(u8 *s, va_list *args)
Definition: interface.c:48
static int vnet_gre_tunnel_add(vnet_gre_add_del_tunnel_args_t *a, u32 *sw_if_indexp)
Definition: interface.c:285
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
vnet_interface_main_t interface_main
Definition: vnet.h:56
void fib_node_init(fib_node_t *node, fib_node_type_t type)
Definition: fib_node.c:183
u32 fib_entry_child_add(fib_node_index_t fib_entry_index, fib_node_type_t child_type, fib_node_index_t child_index)
Definition: fib_entry.c:489
static uword vlib_node_add_named_next(vlib_main_t *vm, uword node, char *name)
Definition: node_funcs.h:1093
static void gre_tunnel_restack(gre_tunnel_t *gt)
Definition: interface.c:218
#define NULL
Definition: clib.h:55
IP unicast adjacency.
Definition: adj.h:174
enum fib_node_back_walk_rc_t_ fib_node_back_walk_rc_t
Return code from a back walk function.
const dpo_id_t * fib_entry_contribute_ip_forwarding(fib_node_index_t fib_entry_index)
Definition: fib_entry.c:445
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
u32 outer_fib_index
The FIB in which the src.dst address are present.
Definition: gre.h:96
void fib_entry_child_remove(fib_node_index_t fib_entry_index, u32 sibling_index)
Definition: fib_entry.c:500
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:522
static adj_walk_rc_t gre_adj_walk_cb(adj_index_t ai, void *ctx)
Call back when restacking all adjacencies on a GRE interface.
Definition: interface.c:209
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:983
#define hash_set_mem(h, key, value)
Definition: hash.h:274
#define STRUCT_OFFSET_OF(t, f)
Definition: clib.h:62
void fib_node_deinit(fib_node_t *node)
Definition: fib_node.c:198
u32 * fib_index_by_sw_if_index
Table index indexed by software interface.
Definition: ip4.h:99
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
#define VNET_HW_INTERFACE_FLAG_LINK_UP
Definition: interface.h:397
format_function_t format_vnet_sw_if_index_name
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
u32 * tunnel_index_by_sw_if_index
Mapping from sw_if_index to tunnel index.
Definition: gre.h:164
void fib_node_register_type(fib_node_type_t type, const fib_node_vft_t *vft)
fib_node_register_type
Definition: fib_node.c:58
u32 sibling_index
The tunnel is a child of the FIB entry for its desintion.
Definition: gre.h:112
L3 GRE (i.e.
Definition: gre.h:62
format_function_t format_ip4_address
Definition: format.h:79
static ip_adjacency_t * adj_get(adj_index_t adj_index)
Get a pointer to an adjacency object from its index.
Definition: adj.h:365
u32 sw_if_index
Definition: gre.h:98
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:376
unformat_function_t unformat_ip4_address
Definition: format.h:76
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
vlib_combined_counter_main_t * combined_sw_if_counters
Definition: interface.h:653
enum adj_walk_rc_t_ adj_walk_rc_t
return codes from a adjacency walker callback function
clib_error_t * gre_interface_init(vlib_main_t *vm)
Definition: interface.c:700
#define clib_error_return(e, args...)
Definition: error.h:99
unsigned long u64
Definition: types.h:89
void adj_unlock(adj_index_t adj_index)
Release a reference counting lock on the adjacency.
Definition: adj.c:229
enum gre_tunnel_tyoe_t_ gre_tunnel_type_t
The GRE tunnel type.
static fib_node_t * gre_tunnel_fib_node_get(fib_node_index_t index)
Function definition to get a FIB node from its index.
Definition: interface.c:250
adj_index_t l2_adj_index
an L2 tunnel always rquires an L2 midchain.
Definition: gre.h:122
u16 fp_len
The mask length.
Definition: fib_types.h:164
ip46_address_t tunnel_src
The tunnel&#39;s source/local address.
Definition: gre.h:88
u32 vnet_register_interface(vnet_main_t *vnm, u32 dev_class_index, u32 dev_instance, u32 hw_class_index, u32 hw_instance)
Definition: interface.c:688
#define GRE_TUNNEL_TYPE_NAMES
Definition: gre.h:69
u32 set_int_l2_mode(vlib_main_t *vm, vnet_main_t *vnet_main, u32 mode, u32 sw_if_index, u32 bd_index, u32 bvi, u32 shg, u32 xc_sw_if_index)
Set the subinterface to run in l2 or l3 mode.
Definition: l2_input.c:517
Definition: fib_entry.h:233
unformat_function_t unformat_line_input
Definition: format.h:281
static clib_error_t * create_gre_tunnel_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: interface.c:536
#define hash_get(h, key)
Definition: hash.h:248
uword * tunnel_by_key4
Hash mapping ipv4 src/dst addr pair to tunnel.
Definition: gre.h:147
#define ADJ_INDEX_INVALID
Invalid ADJ index - used when no adj is known likewise blazoned capitals INVALID speak volumes where ...
Definition: adj_types.h:36
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:397
static void vlib_zero_combined_counter(vlib_combined_counter_main_t *cm, u32 index)
Clear a combined counter Clears the set of per-thread counters.
Definition: counter.h:276
A representation of a GRE tunnel.
Definition: gre.h:79
#define hash_unset_mem(h, key)
Definition: hash.h:280
static uword vnet_hw_interface_get_flags(vnet_main_t *vnm, u32 hw_if_index)
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
Definition: fib_types.h:183
u32 * free_gre_tunnel_hw_if_indices[GRE_TUNNEL_N_TYPES]
Free vlib hw_if_indices.
Definition: gre.h:159
static void gre_tunnel_db_remove(const gre_tunnel_t *t)
Definition: interface.c:130
static u32 ip6_fib_index_from_table_id(u32 table_id)
Definition: ip6_fib.h:158
struct _unformat_input_t unformat_input_t
static gre_tunnel_t * gre_tunnel_from_fib_node(fib_node_t *node)
Definition: interface.c:154
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:241
void gre_update_adj(vnet_main_t *vnm, u32 sw_if_index, adj_index_t ai)
Definition: gre.c:286
vnet_device_class_t gre_device_teb_class
vlib_simple_counter_main_t * sw_if_counters
Definition: interface.h:652
fib_node_type_t fn_type
The node&#39;s type.
Definition: fib_node.h:284
An node in the FIB graph.
Definition: fib_node.h:279
clib_error_t * gre_interface_admin_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: interface.c:504
unformat_function_t unformat_ip6_address
Definition: format.h:94
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P (general version).
Definition: pool.h:169
static clib_error_t * show_gre_tunnel_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: interface.c:658
fib_node_index_t fib_table_entry_special_add(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags)
Add a &#39;special&#39; entry to the FIB.
Definition: fib_table.c:371
gre_tunnel_type_t type
Definition: gre.h:99
#define UNFORMAT_END_OF_INPUT
Definition: format.h:143
format_function_t format_ip6_address
Definition: format.h:95
void fib_table_entry_delete_index(fib_node_index_t fib_entry_index, fib_source_t source)
Delete a FIB entry.
Definition: fib_table.c:858
fib_node_get_t fnv_get
Definition: fib_node.h:267
#define clib_memcpy(a, b, c)
Definition: string.h:69
static void vnet_interface_counter_unlock(vnet_interface_main_t *im)
Definition: interface.h:678
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:28
static u32 ip4_fib_index_from_table_id(u32 table_id)
Definition: ip4_fib.h:135
u32 adj_index_t
An index for adjacencies.
Definition: adj_types.h:30
void adj_nbr_walk(u32 sw_if_index, fib_protocol_t adj_nh_proto, adj_walk_cb_t cb, void *ctx)
Walk the neighbour Adjacencies on a given interface.
Definition: adj_nbr.c:567
Context passed between object during a back walk.
Definition: fib_node.h:192
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:154
static u8 * format_gre_tunnel_type(u8 *s, va_list *args)
Definition: interface.c:40
static void vnet_interface_counter_lock(vnet_interface_main_t *im)
Definition: interface.h:670
#define VNET_SW_INTERFACE_FLAG_ADMIN_UP
Definition: interface.h:560
u32 max_l3_packet_bytes[VLIB_N_RX_TX]
Definition: interface.h:468
#define ASSERT(truth)
static fib_node_back_walk_rc_t gre_tunnel_back_walk(fib_node_t *node, fib_node_back_walk_ctx_t *ctx)
Function definition to backwalk a FIB node.
Definition: interface.c:238
void adj_nbr_midchain_stack(adj_index_t adj_index, const dpo_id_t *next)
adj_nbr_midchain_stack
Definition: adj_midchain.c:509
unsigned int u32
Definition: types.h:88
ip6_main_t ip6_main
Definition: ip6_forward.c:2926
clib_error_t * ethernet_register_interface(vnet_main_t *vnm, u32 dev_class_index, u32 dev_instance, u8 *address, u32 *hw_if_index_return, ethernet_flag_change_function_t flag_change)
Definition: interface.c:246
gre_tunnel_t * tunnels
pool of tunnel instances
Definition: gre.h:132
IPv4 main type.
Definition: ip4.h:83
static gre_tunnel_t * gre_tunnel_db_find(const ip46_address_t *src, const ip46_address_t *dst, u32 out_fib_index, u8 is_ipv6)
Definition: interface.c:75
#define clib_error_report(e)
Definition: error.h:113
static void vlib_zero_simple_counter(vlib_simple_counter_main_t *cm, u32 index)
Clear a simple counter Clears the set of per-thread u16 counters, and the u64 counter.
Definition: counter.h:123
void adj_nbr_midchain_unstack(adj_index_t adj_index)
adj_nbr_midchain_unstack
Definition: adj_midchain.c:486
static void * clib_mem_alloc(uword size)
Definition: mem.h:109
vnet_hw_interface_class_t gre_hw_interface_class
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
u64 uword
Definition: types.h:112
u32 l2_tx_arc
on a L2 tunnel this is the VLIB arc from the L2-tx to the l2-midchain
Definition: gre.h:117
fib_node_t node
Linkage into the FIB object graph.
Definition: gre.h:83
Definition: defs.h:47
vnet_device_class_t gre_device_class
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
unsigned char u8
Definition: types.h:56
Transparent Ethernet Bridging - the tunnel is in L2 mode.
Definition: gre.h:66
static void unformat_free(unformat_input_t *i)
Definition: format.h:161
#define FOR_EACH_FIB_IP_PROTOCOL(_item)
Definition: fib_types.h:62
#define hash_get_mem(h, key)
Definition: hash.h:268
A FIB graph nodes virtual function table.
Definition: fib_node.h:266
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
ip46_address_t dst
Definition: gre.h:244
ip4_main_t ip4_main
Global ip4 main structure.
Definition: ip4_forward.c:1168
fib_prefix_t tunnel_dst
The tunnel&#39;s destination/remote address.
Definition: gre.h:92
adj_index_t adj_nbr_add_or_lock(fib_protocol_t nh_proto, vnet_link_t link_type, const ip46_address_t *nh_addr, u32 sw_if_index)
Neighbour Adjacency sub-type.
Definition: adj_nbr.c:214
clib_error_t * vnet_sw_interface_set_flags(vnet_main_t *vnm, u32 sw_if_index, u32 flags)
Definition: interface.c:545
vlib_main_t * vlib_main
Definition: gre.h:171
u32 per_packet_overhead_bytes
Definition: interface.h:465
u32 flags
Definition: vhost-user.h:76
#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:485
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:67
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:680
int vnet_gre_add_del_tunnel(vnet_gre_add_del_tunnel_args_t *a, u32 *sw_if_indexp)
Definition: interface.c:494
u32 * fib_index_by_sw_if_index
Definition: ip6.h:163
gre_main_t gre_main
Definition: gre.c:22
ip46_address_t src
Definition: gre.h:244
static int vnet_gre_tunnel_delete(vnet_gre_add_del_tunnel_args_t *a, u32 *sw_if_indexp)
Definition: interface.c:452
static const char * gre_tunnel_type_names[]
Definition: interface.c:28
const ip46_address_t zero_addr
Definition: lookup.c:348
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
Definition: defs.h:46
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:169
#define MODE_L3
Definition: l2_input.h:198
static void gre_tunnel_last_lock_gone(fib_node_t *node)
Function definition to inform the FIB node that its last lock has gone.
Definition: interface.c:265
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:109