FD.io VPP  v18.01.1-37-g7ea3975
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 u8 *
31 format_gre_tunnel_type (u8 * s, va_list * args)
32 {
33  gre_tunnel_type_t type = va_arg (*args, gre_tunnel_type_t);
34 
35  return (format (s, "%s", gre_tunnel_type_names[type]));
36 }
37 
38 static u8 *
39 format_gre_tunnel (u8 * s, va_list * args)
40 {
41  gre_tunnel_t *t = va_arg (*args, gre_tunnel_t *);
42  gre_main_t *gm = &gre_main;
43  u8 is_ipv6 = t->tunnel_dst.fp_proto == FIB_PROTOCOL_IP6 ? 1 : 0;
44 
45  if (!is_ipv6)
46  s = format (s,
47  "[%d] %U (src) %U (dst) payload %U outer_fib_index %d",
48  t - gm->tunnels,
52  else
53  s = format (s,
54  "[%d] %U (src) %U (dst) payload %U outer_fib_index %d",
55  t - gm->tunnels,
59 
60  return s;
61 }
62 
63 static gre_tunnel_t *
64 gre_tunnel_db_find (const ip46_address_t * src,
65  const ip46_address_t * dst,
66  u32 out_fib_index, u8 is_ipv6, gre_tunnel_key_t * key)
67 {
68  gre_main_t *gm = &gre_main;
69  uword *p;
70 
71  if (!is_ipv6)
72  {
73  gre_mk_key4 (&src->ip4, &dst->ip4, out_fib_index, &key->gtk_v4);
74  p = hash_get_mem (gm->tunnel_by_key4, &key->gtk_v4);
75  }
76  else
77  {
78  gre_mk_key6 (&src->ip6, &dst->ip6, out_fib_index, &key->gtk_v6);
79  p = hash_get_mem (gm->tunnel_by_key6, &key->gtk_v6);
80  }
81 
82  if (NULL == p)
83  return (NULL);
84 
85  return (pool_elt_at_index (gm->tunnels, p[0]));
86 }
87 
88 static void
90 {
91  gre_main_t *gm = &gre_main;
92 
93  t->key = clib_mem_alloc (sizeof (*t->key));
94  clib_memcpy (t->key, key, sizeof (*key));
95 
97  {
98  hash_set_mem (gm->tunnel_by_key6, &t->key->gtk_v6, t - gm->tunnels);
99  }
100  else
101  {
102  hash_set_mem (gm->tunnel_by_key4, &t->key->gtk_v4, t - gm->tunnels);
103  }
104 }
105 
106 static void
108 {
109  gre_main_t *gm = &gre_main;
110 
112  {
114  }
115  else
116  {
118  }
119 
120  clib_mem_free (t->key);
121  t->key = NULL;
122 }
123 
124 static gre_tunnel_t *
126 {
128  return ((gre_tunnel_t *) (((char *) node) -
129  STRUCT_OFFSET_OF (gre_tunnel_t, node)));
130 }
131 
132 /**
133  * gre_tunnel_stack
134  *
135  * 'stack' (resolve the recursion for) the tunnel's midchain adjacency
136  */
137 void
139 {
140  gre_main_t *gm = &gre_main;
141  ip_adjacency_t *adj;
142  gre_tunnel_t *gt;
143  u32 sw_if_index;
144 
145  adj = adj_get (ai);
146  sw_if_index = adj->rewrite_header.sw_if_index;
147 
148  if ((vec_len (gm->tunnel_index_by_sw_if_index) < sw_if_index) ||
149  (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index]))
150  return;
151 
152  gt = pool_elt_at_index (gm->tunnels,
153  gm->tunnel_index_by_sw_if_index[sw_if_index]);
154 
155  /*
156  * find the adjacency that is contributed by the FIB entry
157  * that this tunnel resovles via, and use it as the next adj
158  * in the midchain
159  */
161  gt->hw_if_index) &
163  {
166  (gt->fib_entry_index));
167  }
168  else
169  {
171  }
172 }
173 
174 /**
175  * @brief Call back when restacking all adjacencies on a GRE interface
176  */
177 static adj_walk_rc_t
179 {
180  gre_tunnel_stack (ai);
181 
182  return (ADJ_WALK_RC_CONTINUE);
183 }
184 
185 static void
187 {
188  fib_protocol_t proto;
189 
190  /*
191  * walk all the adjacencies on th GRE interface and restack them
192  */
194  {
196  }
197 }
198 
199 /**
200  * Function definition to backwalk a FIB node
201  */
204 {
206 
208 }
209 
210 /**
211  * Function definition to get a FIB node from its index
212  */
213 static fib_node_t *
215 {
216  gre_tunnel_t *gt;
217  gre_main_t *gm;
218 
219  gm = &gre_main;
220  gt = pool_elt_at_index (gm->tunnels, index);
221 
222  return (&gt->node);
223 }
224 
225 /**
226  * Function definition to inform the FIB node that its last lock has gone.
227  */
228 static void
230 {
231  /*
232  * The MPLS GRE tunnel is a root of the graph. As such
233  * it never has children and thus is never locked.
234  */
235  ASSERT (0);
236 }
237 
238 /*
239  * Virtual function table registered by MPLS GRE tunnels
240  * for participation in the FIB object graph.
241  */
242 const static fib_node_vft_t gre_vft = {
244  .fnv_last_lock = gre_tunnel_last_lock_gone,
245  .fnv_back_walk = gre_tunnel_back_walk,
246 };
247 
248 static int
250 {
251  gre_main_t *gm = &gre_main;
252  vnet_main_t *vnm = gm->vnet_main;
253  ip4_main_t *im4 = &ip4_main;
254  ip6_main_t *im6 = &ip6_main;
255  gre_tunnel_t *t;
257  u32 hw_if_index, sw_if_index;
258  u32 outer_fib_index;
259  u8 address[6];
260  clib_error_t *error;
261  u8 is_ipv6 = a->is_ipv6;
262  gre_tunnel_key_t key;
263 
264  if (!is_ipv6)
265  outer_fib_index = ip4_fib_index_from_table_id (a->outer_fib_id);
266  else
267  outer_fib_index = ip6_fib_index_from_table_id (a->outer_fib_id);
268 
269  if (~0 == outer_fib_index)
270  return VNET_API_ERROR_NO_SUCH_FIB;
271 
272  t =
273  gre_tunnel_db_find (&a->src, &a->dst, outer_fib_index, a->is_ipv6, &key);
274 
275  if (NULL != t)
276  return VNET_API_ERROR_INVALID_VALUE;
277 
279  memset (t, 0, sizeof (*t));
281 
282  if (a->teb)
284  else
286 
287  if (vec_len (gm->free_gre_tunnel_hw_if_indices[t->type]) > 0)
288  {
290 
291  hw_if_index = gm->free_gre_tunnel_hw_if_indices[t->type]
293  _vec_len (gm->free_gre_tunnel_hw_if_indices[t->type]) -= 1;
294 
295  hi = vnet_get_hw_interface (vnm, hw_if_index);
296  hi->dev_instance = t - gm->tunnels;
297  hi->hw_instance = hi->dev_instance;
298 
299  /* clear old stats of freed tunnel before reuse */
300  sw_if_index = hi->sw_if_index;
304  sw_if_index);
306  [VNET_INTERFACE_COUNTER_RX], sw_if_index);
308  [VNET_INTERFACE_COUNTER_DROP], sw_if_index);
310  if (GRE_TUNNEL_TYPE_TEB == t->type)
311  {
313  hi->tx_node_index,
314  "adj-l2-midchain");
315  }
316  }
317  else
318  {
319  if (GRE_TUNNEL_TYPE_TEB == t->type)
320  {
321  /* Default MAC address (d00b:eed0:0000 + sw_if_index) */
322  memset (address, 0, sizeof (address));
323  address[0] = 0xd0;
324  address[1] = 0x0b;
325  address[2] = 0xee;
326  address[3] = 0xd0;
327  address[4] = t - gm->tunnels;
328 
329  error = ethernet_register_interface (vnm,
330  gre_device_teb_class.index,
331  t - gm->tunnels, address,
332  &hw_if_index, 0);
333 
334  if (error)
335  {
336  clib_error_report (error);
337  return VNET_API_ERROR_INVALID_REGISTRATION;
338  }
339  hi = vnet_get_hw_interface (vnm, hw_if_index);
340 
342  hi->tx_node_index,
343  "adj-l2-midchain");
344  }
345  else
346  {
347  hw_if_index = vnet_register_interface (vnm,
348  gre_device_class.index,
349  t - gm->tunnels,
351  t - gm->tunnels);
352  }
353  hi = vnet_get_hw_interface (vnm, hw_if_index);
354  sw_if_index = hi->sw_if_index;
355  }
356 
357  t->hw_if_index = hw_if_index;
358  t->outer_fib_index = outer_fib_index;
359  t->sw_if_index = sw_if_index;
361 
363  gm->tunnel_index_by_sw_if_index[sw_if_index] = t - gm->tunnels;
364 
365  if (!is_ipv6)
366  {
367  vec_validate (im4->fib_index_by_sw_if_index, sw_if_index);
368  hi->min_packet_bytes =
369  64 + sizeof (gre_header_t) + sizeof (ip4_header_t);
370  }
371  else
372  {
373  vec_validate (im6->fib_index_by_sw_if_index, sw_if_index);
374  hi->min_packet_bytes =
375  64 + sizeof (gre_header_t) + sizeof (ip6_header_t);
376  }
377 
379  /* preamble */ 8 + /* inter frame gap */ 12;
380 
381  /* Standard default gre MTU. */
383 
384  /*
385  * source the FIB entry for the tunnel's destination
386  * and become a child thereof. The tunnel will then get poked
387  * when the forwarding for the entry updates, and the tunnel can
388  * re-stack accordingly
389  */
390 
391  clib_memcpy (&t->tunnel_src, &a->src, sizeof (t->tunnel_src));
392  t->tunnel_dst.fp_len = !is_ipv6 ? 32 : 128;
394  t->tunnel_dst.fp_addr = a->dst;
395 
396  gre_tunnel_db_add (t, &key);
397 
398  t->fib_entry_index =
399  fib_table_entry_special_add (outer_fib_index,
400  &t->tunnel_dst,
402  t->sibling_index =
405 
406  if (GRE_TUNNEL_TYPE_TEB == t->type)
407  {
410  &zero_addr, sw_if_index);
412  }
413 
414  if (sw_if_indexp)
415  *sw_if_indexp = sw_if_index;
416 
417  return 0;
418 }
419 
420 static int
422  u32 * sw_if_indexp)
423 {
424  gre_main_t *gm = &gre_main;
425  vnet_main_t *vnm = gm->vnet_main;
426  gre_tunnel_t *t;
427  gre_tunnel_key_t key;
428  u32 sw_if_index;
429  u32 outer_fib_index;
430 
431  if (!a->is_ipv6)
432  outer_fib_index = ip4_fib_index_from_table_id (a->outer_fib_id);
433  else
434  outer_fib_index = ip6_fib_index_from_table_id (a->outer_fib_id);
435 
436  if (~0 == outer_fib_index)
437  return VNET_API_ERROR_NO_SUCH_FIB;
438 
439  t =
440  gre_tunnel_db_find (&a->src, &a->dst, outer_fib_index, a->is_ipv6, &key);
441 
442  if (NULL == t)
443  return VNET_API_ERROR_NO_SUCH_ENTRY;
444 
445  sw_if_index = t->sw_if_index;
446  vnet_sw_interface_set_flags (vnm, sw_if_index, 0 /* down */ );
447  /* make sure tunnel is removed from l2 bd or xconnect */
448  set_int_l2_mode (gm->vlib_main, vnm, MODE_L3, sw_if_index, 0, 0, 0, 0);
450  gm->tunnel_index_by_sw_if_index[sw_if_index] = ~0;
451 
452  if (GRE_TUNNEL_TYPE_TEB == t->type)
454 
457 
460 
462  fib_node_deinit (&t->node);
463  pool_put (gm->tunnels, t);
464 
465  if (sw_if_indexp)
466  *sw_if_indexp = sw_if_index;
467 
468  return 0;
469 }
470 
471 int
473  u32 * sw_if_indexp)
474 {
475  if (a->is_add)
476  return (vnet_gre_tunnel_add (a, sw_if_indexp));
477  else
478  return (vnet_gre_tunnel_delete (a, sw_if_indexp));
479 }
480 
481 clib_error_t *
483 {
484  gre_main_t *gm = &gre_main;
486  gre_tunnel_t *t;
487  u32 ti;
488 
489  hi = vnet_get_hw_interface (vnm, hw_if_index);
490 
491  if (NULL == gm->tunnel_index_by_sw_if_index ||
493  return (NULL);
494 
496 
497  if (~0 == ti)
498  /* not one of ours */
499  return (NULL);
500 
501  t = pool_elt_at_index (gm->tunnels, ti);
502 
504  vnet_hw_interface_set_flags (vnm, hw_if_index,
506  else
507  vnet_hw_interface_set_flags (vnm, hw_if_index, 0 /* down */ );
508 
509  gre_tunnel_restack (t);
510 
511  return /* no error */ 0;
512 }
513 
514 static clib_error_t *
516  unformat_input_t * input,
517  vlib_cli_command_t * cmd)
518 {
519  unformat_input_t _line_input, *line_input = &_line_input;
521  ip46_address_t src, dst;
522  u32 outer_fib_id = 0;
523  u8 teb = 0;
524  int rv;
525  u32 num_m_args = 0;
526  u8 is_add = 1;
527  u32 sw_if_index;
528  clib_error_t *error = NULL;
529  u8 ipv4_set = 0;
530  u8 ipv6_set = 0;
531 
532  /* Get a line of input. */
533  if (!unformat_user (input, unformat_line_input, line_input))
534  return 0;
535 
536  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
537  {
538  if (unformat (line_input, "del"))
539  is_add = 0;
540  else
541  if (unformat (line_input, "src %U", unformat_ip4_address, &src.ip4))
542  {
543  num_m_args++;
544  ipv4_set = 1;
545  }
546  else
547  if (unformat (line_input, "dst %U", unformat_ip4_address, &dst.ip4))
548  {
549  num_m_args++;
550  ipv4_set = 1;
551  }
552  else
553  if (unformat (line_input, "src %U", unformat_ip6_address, &src.ip6))
554  {
555  num_m_args++;
556  ipv6_set = 1;
557  }
558  else
559  if (unformat (line_input, "dst %U", unformat_ip6_address, &dst.ip6))
560  {
561  num_m_args++;
562  ipv6_set = 1;
563  }
564  else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
565  ;
566  else if (unformat (line_input, "teb"))
567  teb = 1;
568  else
569  {
570  error = clib_error_return (0, "unknown input `%U'",
571  format_unformat_error, line_input);
572  goto done;
573  }
574  }
575 
576  if (num_m_args < 2)
577  {
578  error = clib_error_return (0, "mandatory argument(s) missing");
579  goto done;
580  }
581 
582  if ((ipv4_set && memcmp (&src.ip4, &dst.ip4, sizeof (src.ip4)) == 0) ||
583  (ipv6_set && memcmp (&src.ip6, &dst.ip6, sizeof (src.ip6)) == 0))
584  {
585  error = clib_error_return (0, "src and dst are identical");
586  goto done;
587  }
588 
589  if (ipv4_set && ipv6_set)
590  return clib_error_return (0, "both IPv4 and IPv6 addresses specified");
591 
592  if ((ipv4_set && memcmp (&dst.ip4, &zero_addr.ip4, sizeof (dst.ip4)) == 0)
593  || (ipv6_set
594  && memcmp (&dst.ip6, &zero_addr.ip6, sizeof (dst.ip6)) == 0))
595  {
596  error = clib_error_return (0, "dst address cannot be zero");
597  goto done;
598  }
599 
600  memset (a, 0, sizeof (*a));
601  a->outer_fib_id = outer_fib_id;
602  a->teb = teb;
603  a->is_ipv6 = ipv6_set;
604  if (!ipv6_set)
605  {
606  clib_memcpy (&a->src.ip4, &src.ip4, sizeof (src.ip4));
607  clib_memcpy (&a->dst.ip4, &dst.ip4, sizeof (dst.ip4));
608  }
609  else
610  {
611  clib_memcpy (&a->src.ip6, &src.ip6, sizeof (src.ip6));
612  clib_memcpy (&a->dst.ip6, &dst.ip6, sizeof (dst.ip6));
613  }
614 
615  if (is_add)
616  rv = vnet_gre_tunnel_add (a, &sw_if_index);
617  else
618  rv = vnet_gre_tunnel_delete (a, &sw_if_index);
619 
620  switch (rv)
621  {
622  case 0:
624  vnet_get_main (), sw_if_index);
625  break;
626  case VNET_API_ERROR_INVALID_VALUE:
627  error = clib_error_return (0, "GRE tunnel already exists...");
628  goto done;
629  case VNET_API_ERROR_NO_SUCH_FIB:
630  error = clib_error_return (0, "outer fib ID %d doesn't exist\n",
631  outer_fib_id);
632  goto done;
633  default:
634  error =
635  clib_error_return (0, "vnet_gre_add_del_tunnel returned %d", rv);
636  goto done;
637  }
638 
639 done:
640  unformat_free (line_input);
641 
642  return error;
643 }
644 
645 /* *INDENT-OFF* */
646 VLIB_CLI_COMMAND (create_gre_tunnel_command, static) = {
647  .path = "create gre tunnel",
648  .short_help = "create gre tunnel src <addr> dst <addr> "
649  "[outer-fib-id <fib>] [teb] [del]",
650  .function = create_gre_tunnel_command_fn,
651 };
652 /* *INDENT-ON* */
653 
654 static clib_error_t *
656  unformat_input_t * input,
657  vlib_cli_command_t * cmd)
658 {
659  gre_main_t *gm = &gre_main;
660  gre_tunnel_t *t;
661  u32 ti = ~0;
662 
663  if (pool_elts (gm->tunnels) == 0)
664  vlib_cli_output (vm, "No GRE tunnels configured...");
665 
667  {
668  if (unformat (input, "%d", &ti))
669  ;
670  else
671  break;
672  }
673 
674  if (~0 == ti)
675  {
676  /* *INDENT-OFF* */
677  pool_foreach (t, gm->tunnels,
678  ({
679  vlib_cli_output (vm, "%U", format_gre_tunnel, t);
680  }));
681  /* *INDENT-ON* */
682  }
683  else
684  {
685  t = pool_elt_at_index (gm->tunnels, ti);
686 
687  vlib_cli_output (vm, "%U", format_gre_tunnel, t);
688  }
689 
690  return 0;
691 }
692 
693 /* *INDENT-OFF* */
694 VLIB_CLI_COMMAND (show_gre_tunnel_command, static) = {
695  .path = "show gre tunnel",
696  .function = show_gre_tunnel_command_fn,
697 };
698 /* *INDENT-ON* */
699 
700 /* force inclusion from application's main.c */
701 clib_error_t *
703 {
705 
706  return 0;
707 }
708 
710 
711 /*
712  * fd.io coding-style-patch-verification: ON
713  *
714  * Local Variables:
715  * eval: (c-set-style "gnu")
716  * End:
717  */
vnet_main_t * vnet_main
Definition: gre.h:237
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:432
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:181
void gre_tunnel_stack(adj_index_t ai)
gre_tunnel_stack
Definition: interface.c:138
vmrglw vmrglh hi
static void gre_tunnel_db_add(gre_tunnel_t *t, gre_tunnel_key_t *key)
Definition: interface.c:89
Recursive resolution source.
Definition: fib_entry.h:117
uword * tunnel_by_key6
Hash mapping ipv6 src/dst addr pair to tunnel.
Definition: gre.h:217
GRE related global data.
Definition: gre.h:192
fib_node_index_t fib_entry_index
The FIB entry sourced by the tunnel for its destination prefix.
Definition: gre.h:168
u32 hw_if_index
Definition: gre.h:161
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: interface.c:538
a
Definition: bitmap.h:516
static u8 * format_gre_tunnel(u8 *s, va_list *args)
Definition: interface.c:39
static int vnet_gre_tunnel_add(vnet_gre_add_del_tunnel_args_t *a, u32 *sw_if_indexp)
Definition: interface.c:249
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
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:185
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:503
static void gre_mk_key4(const ip4_address_t *src, const ip4_address_t *dst, u32 fib_index, gre_tunnel_key4_t *key)
Definition: gre.h:320
static uword vlib_node_add_named_next(vlib_main_t *vm, uword node, char *name)
Definition: node_funcs.h:1120
static void gre_tunnel_restack(gre_tunnel_t *gt)
Definition: interface.c:186
#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:459
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:160
static void gre_mk_key6(const ip6_address_t *src, const ip6_address_t *dst, u32 fib_index, gre_tunnel_key6_t *key)
Definition: gre.h:338
void fib_entry_child_remove(fib_node_index_t fib_entry_index, u32 sibling_index)
Definition: fib_entry.c:514
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:518
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:178
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:197
u32 * fib_index_by_sw_if_index
Table index indexed by software interface.
Definition: ip4.h:111
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
#define VNET_HW_INTERFACE_FLAG_LINK_UP
Definition: interface.h:394
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:229
void fib_node_register_type(fib_node_type_t type, const fib_node_vft_t *vft)
fib_node_register_type
Definition: fib_node.c:60
static void gre_tunnel_db_remove(gre_tunnel_t *t)
Definition: interface.c:107
u32 sibling_index
The tunnel is a child of the FIB entry for its desintion.
Definition: gre.h:176
L3 GRE (i.e.
Definition: gre.h:64
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:162
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:438
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:672
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:702
#define clib_error_return(e, args...)
Definition: error.h:99
void adj_unlock(adj_index_t adj_index)
Release a reference counting lock on the adjacency.
Definition: adj.c:239
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:214
adj_index_t l2_adj_index
an L2 tunnel always rquires an L2 midchain.
Definition: gre.h:186
u16 fp_len
The mask length.
Definition: fib_types.h:176
ip46_address_t tunnel_src
The tunnel&#39;s source/local address.
Definition: gre.h:152
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:689
#define GRE_TUNNEL_TYPE_NAMES
Definition: gre.h:71
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:565
Definition: fib_entry.h:238
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:515
uword * tunnel_by_key4
Hash mapping ipv4 src/dst addr pair to tunnel.
Definition: gre.h:212
#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:459
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:136
#define hash_unset_mem(h, key)
Definition: hash.h:290
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:195
u32 * free_gre_tunnel_hw_if_indices[GRE_TUNNEL_N_TYPES]
Free vlib hw_if_indices.
Definition: gre.h:224
static u32 ip6_fib_index_from_table_id(u32 table_id)
Definition: ip6_fib.h:161
struct _unformat_input_t unformat_input_t
static gre_tunnel_t * gre_tunnel_from_fib_node(fib_node_t *node)
Definition: interface.c:125
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:271
gre_tunnel_key4_t gtk_v4
Definition: gre.h:129
void gre_update_adj(vnet_main_t *vnm, u32 sw_if_index, adj_index_t ai)
Definition: gre.c:292
vnet_device_class_t gre_device_teb_class
vlib_simple_counter_main_t * sw_if_counters
Definition: interface.h:671
fib_node_type_t fn_type
The node&#39;s type.
Definition: fib_node.h:290
An node in the FIB graph.
Definition: fib_node.h:286
clib_error_t * gre_interface_admin_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: interface.c:482
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:188
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:655
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:163
#define UNFORMAT_END_OF_INPUT
Definition: format.h:143
format_function_t format_ip6_address
Definition: format.h:95
vlib_main_t * vm
Definition: buffer.c:283
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:860
gre_tunnel_key6_t gtk_v6
Definition: gre.h:130
fib_node_get_t fnv_get
Definition: fib_node.h:274
#define clib_memcpy(a, b, c)
Definition: string.h:75
static void vnet_interface_counter_unlock(vnet_interface_main_t *im)
Definition: interface.h:697
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:29
static u32 ip4_fib_index_from_table_id(u32 table_id)
Definition: ip4_fib.h:137
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:199
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:154
static u8 * format_gre_tunnel_type(u8 *s, va_list *args)
Definition: interface.c:31
static void vnet_interface_counter_lock(vnet_interface_main_t *im)
Definition: interface.h:689
#define VNET_SW_INTERFACE_FLAG_ADMIN_UP
Definition: interface.h:576
u32 max_l3_packet_bytes[VLIB_N_RX_TX]
Definition: interface.h:472
#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:203
void adj_nbr_midchain_stack(adj_index_t adj_index, const dpo_id_t *next)
adj_nbr_midchain_stack
Definition: adj_midchain.c:565
unsigned int u32
Definition: types.h:88
ip6_main_t ip6_main
Definition: ip6_forward.c:3009
long ctx[MAX_CONNS]
Definition: main.c:122
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:273
gre_tunnel_t * tunnels
pool of tunnel instances
Definition: gre.h:197
IPv4 main type.
Definition: ip4.h:95
static void clib_mem_free(void *p)
Definition: mem.h:179
#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:543
Union of the two possible key types.
Definition: gre.h:127
static void * clib_mem_alloc(uword size)
Definition: mem.h:112
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:181
fib_node_t node
Linkage into the FIB object graph.
Definition: gre.h:141
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
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, gre_tunnel_key_t *key)
Definition: interface.c:64
Transparent Ethernet Bridging - the tunnel is in L2 mode.
Definition: gre.h:68
static void unformat_free(unformat_input_t *i)
Definition: format.h:161
#define FOR_EACH_FIB_IP_PROTOCOL(_item)
Definition: fib_types.h:69
#define hash_get_mem(h, key)
Definition: hash.h:268
A FIB graph nodes virtual function table.
Definition: fib_node.h:273
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
gre_tunnel_key_t * key
The hash table&#39;s key stored in separate memory since the tunnel_t memory can realloc.
Definition: gre.h:147
ip46_address_t dst
Definition: gre.h:310
ip4_main_t ip4_main
Global ip4 main structure.
Definition: ip4_forward.c:1181
fib_prefix_t tunnel_dst
The tunnel&#39;s destination/remote address.
Definition: gre.h:156
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:546
vlib_main_t * vlib_main
Definition: gre.h:236
u32 per_packet_overhead_bytes
Definition: interface.h:469
u32 flags
Definition: vhost-user.h:77
#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:481
#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:472
u32 * fib_index_by_sw_if_index
Definition: ip6.h:173
gre_main_t gre_main
Definition: gre.c:22
ip46_address_t src
Definition: gre.h:310
static int vnet_gre_tunnel_delete(vnet_gre_add_del_tunnel_args_t *a, u32 *sw_if_indexp)
Definition: interface.c:421
static const char * gre_tunnel_type_names[]
Definition: interface.c:28
const ip46_address_t zero_addr
Definition: lookup.c:359
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:202
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:229
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:128