FD.io VPP  v19.04.4-rc0-5-ge88582fac
Vector Packet Processing
gre.c
Go to the documentation of this file.
1 /*
2  * gre.c: gre
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/gre/gre.h>
20 #include <vnet/adj/adj_midchain.h>
21 
22 extern gre_main_t gre_main;
23 
24 #ifndef CLIB_MARCH_VARIANT
26 
27 typedef struct
28 {
29  union
30  {
31  ip4_and_gre_header_t ip4_and_gre;
32  u64 as_u64[3];
33  };
35 
36 typedef struct
37 {
38  union
39  {
40  ip6_and_gre_header_t ip6_and_gre;
41  u64 as_u64[3];
42  };
44 #endif /* CLIB_MARCH_VARIANT */
45 
46 
47 /* Packet trace structure */
48 typedef struct
49 {
50  /* Tunnel-id / index in tunnel vector */
52 
53  /* pkt length */
55 
56  /* tunnel ip addresses */
57  ip46_address_t src;
58  ip46_address_t dst;
60 
61 extern u8 *format_gre_tx_trace (u8 * s, va_list * args);
62 
63 #ifndef CLIB_MARCH_VARIANT
64 u8 *
65 format_gre_tx_trace (u8 * s, va_list * args)
66 {
67  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
68  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
69  gre_tx_trace_t *t = va_arg (*args, gre_tx_trace_t *);
70 
71  s = format (s, "GRE: tunnel %d len %d src %U dst %U",
72  t->tunnel_id, t->length,
75  return s;
76 }
77 
78 u8 *
79 format_gre_protocol (u8 * s, va_list * args)
80 {
81  gre_protocol_t p = va_arg (*args, u32);
84 
85  if (pi)
86  s = format (s, "%s", pi->name);
87  else
88  s = format (s, "0x%04x", p);
89 
90  return s;
91 }
92 
93 u8 *
94 format_gre_header_with_length (u8 * s, va_list * args)
95 {
97  gre_header_t *h = va_arg (*args, gre_header_t *);
98  u32 max_header_bytes = va_arg (*args, u32);
99  gre_protocol_t p = clib_net_to_host_u16 (h->protocol);
100  u32 indent, header_bytes;
101 
102  header_bytes = sizeof (h[0]);
103  if (max_header_bytes != 0 && header_bytes > max_header_bytes)
104  return format (s, "gre header truncated");
105 
106  indent = format_get_indent (s);
107 
108  s = format (s, "GRE %U", format_gre_protocol, p);
109 
110  if (max_header_bytes != 0 && header_bytes < max_header_bytes)
111  {
113  vlib_node_t *node = vlib_get_node (gm->vlib_main, pi->node_index);
114  if (node->format_buffer)
115  s = format (s, "\n%U%U",
116  format_white_space, indent,
117  node->format_buffer, (void *) (h + 1),
118  max_header_bytes - header_bytes);
119  }
120 
121  return s;
122 }
123 
124 u8 *
125 format_gre_header (u8 * s, va_list * args)
126 {
127  gre_header_t *h = va_arg (*args, gre_header_t *);
128  return format (s, "%U", format_gre_header_with_length, h, 0);
129 }
130 
131 /* Returns gre protocol as an int in host byte order. */
132 uword
134  va_list * args)
135 {
136  u16 *result = va_arg (*args, u16 *);
137  gre_main_t *gm = &gre_main;
138  int i;
139 
140  /* Named type. */
142  gm->protocol_info_by_name, &i))
143  {
145  *result = pi->protocol;
146  return 1;
147  }
148 
149  return 0;
150 }
151 
152 uword
154  va_list * args)
155 {
156  u16 *result = va_arg (*args, u16 *);
158  return 0;
159  *result = clib_host_to_net_u16 ((u16) * result);
160  return 1;
161 }
162 
163 uword
164 unformat_gre_header (unformat_input_t * input, va_list * args)
165 {
166  u8 **result = va_arg (*args, u8 **);
167  gre_header_t _h, *h = &_h;
168  u16 p;
169 
170  if (!unformat (input, "%U", unformat_gre_protocol_host_byte_order, &p))
171  return 0;
172 
173  h->protocol = clib_host_to_net_u16 (p);
174 
175  /* Add header to result. */
176  {
177  void *p;
178  u32 n_bytes = sizeof (h[0]);
179 
180  vec_add2 (*result, p, n_bytes);
181  clib_memcpy (p, h, n_bytes);
182  }
183 
184  return 1;
185 }
186 
187 static int
189 {
190  switch (link)
191  {
192  case VNET_LINK_IP4:
193  return (GRE_PROTOCOL_ip4);
194  case VNET_LINK_IP6:
195  return (GRE_PROTOCOL_ip6);
196  case VNET_LINK_MPLS:
197  return (GRE_PROTOCOL_mpls_unicast);
198  case VNET_LINK_ETHERNET:
199  return (GRE_PROTOCOL_teb);
200  case VNET_LINK_ARP:
201  return (GRE_PROTOCOL_arp);
202  case VNET_LINK_NSH:
203  ASSERT (0);
204  break;
205  }
206  ASSERT (0);
207  return (GRE_PROTOCOL_ip4);
208 }
209 
210 static u8 *
213  vnet_link_t link_type, const void *dst_address)
214 {
215  gre_main_t *gm = &gre_main;
216  ip4_and_gre_header_t *h4;
217  ip6_and_gre_header_t *h6;
218  gre_header_t *gre;
219  u8 *rewrite = NULL;
220  gre_tunnel_t *t;
221  u32 ti;
222  u8 is_ipv6;
223 
225 
226  if (~0 == ti)
227  /* not one of ours */
228  return (0);
229 
230  t = pool_elt_at_index (gm->tunnels, ti);
231 
232  is_ipv6 = t->tunnel_dst.fp_proto == FIB_PROTOCOL_IP6 ? 1 : 0;
233 
234  if (!is_ipv6)
235  {
236  vec_validate (rewrite, sizeof (*h4) - 1);
237  h4 = (ip4_and_gre_header_t *) rewrite;
238  gre = &h4->gre;
239  h4->ip4.ip_version_and_header_length = 0x45;
240  h4->ip4.ttl = 254;
241  h4->ip4.protocol = IP_PROTOCOL_GRE;
242  /* fixup ip4 header length and checksum after-the-fact */
243  h4->ip4.src_address.as_u32 = t->tunnel_src.ip4.as_u32;
244  h4->ip4.dst_address.as_u32 = t->tunnel_dst.fp_addr.ip4.as_u32;
245  h4->ip4.checksum = ip4_header_checksum (&h4->ip4);
246  }
247  else
248  {
249  vec_validate (rewrite, sizeof (*h6) - 1);
250  h6 = (ip6_and_gre_header_t *) rewrite;
251  gre = &h6->gre;
252  h6->ip6.ip_version_traffic_class_and_flow_label =
253  clib_host_to_net_u32 (6 << 28);
254  h6->ip6.hop_limit = 255;
255  h6->ip6.protocol = IP_PROTOCOL_GRE;
256  /* fixup ip6 header length and checksum after-the-fact */
257  h6->ip6.src_address.as_u64[0] = t->tunnel_src.ip6.as_u64[0];
258  h6->ip6.src_address.as_u64[1] = t->tunnel_src.ip6.as_u64[1];
259  h6->ip6.dst_address.as_u64[0] = t->tunnel_dst.fp_addr.ip6.as_u64[0];
260  h6->ip6.dst_address.as_u64[1] = t->tunnel_dst.fp_addr.ip6.as_u64[1];
261  }
262 
264  {
265  gre->protocol = clib_host_to_net_u16 (GRE_PROTOCOL_erspan);
266  gre->flags_and_version = clib_host_to_net_u16 (GRE_FLAGS_SEQUENCE);
267  }
268  else
269  gre->protocol =
270  clib_host_to_net_u16 (gre_proto_from_vnet_link (link_type));
271 
272  return (rewrite);
273 }
274 
275 #define is_v4_packet(_h) ((*(u8*) _h) & 0xF0) == 0x40
276 
277 static void
279  ip_adjacency_t * adj, vlib_buffer_t * b0, const void *data)
280 {
281  ip4_header_t *ip0;
282 
283  ip0 = vlib_buffer_get_current (b0);
284 
285  /* Fixup the checksum and len fields in the GRE tunnel encap
286  * that was applied at the midchain node */
287  ip0->length = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0));
288  ip0->checksum = ip4_header_checksum (ip0);
289 }
290 
291 static void
293  ip_adjacency_t * adj, vlib_buffer_t * b0, const void *data)
294 {
295  ip6_header_t *ip0;
296 
297  ip0 = vlib_buffer_get_current (b0);
298 
299  /* Fixup the payload length field in the GRE tunnel encap that was applied
300  * at the midchain node */
301  ip0->payload_length =
302  clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0) -
303  sizeof (*ip0));
304 }
305 
306 void
308 {
309  gre_main_t *gm = &gre_main;
310  gre_tunnel_t *t;
311  adj_flags_t af;
312  u8 is_ipv6;
313  u32 ti;
314 
316  t = pool_elt_at_index (gm->tunnels, ti);
317  is_ipv6 = t->tunnel_dst.fp_proto == FIB_PROTOCOL_IP6 ? 1 : 0;
319 
322 
324  (ai, !is_ipv6 ? gre4_fixup : gre6_fixup, NULL, af,
325  gre_build_rewrite (vnm, sw_if_index, adj_get_link_type (ai), NULL));
326 
327  gre_tunnel_stack (ai);
328 }
329 #endif /* CLIB_MARCH_VARIANT */
330 
331 typedef enum
332 {
336 
337 /**
338  * @brief TX function. Only called for L2 payload including TEB or ERSPAN.
339  * L3 traffic uses the adj-midchains.
340  */
342  vlib_frame_t * frame)
343 {
344  gre_main_t *gm = &gre_main;
345  u32 *from, n_left_from;
346  vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
347  u32 sw_if_index[2] = { ~0, ~0 };
348  const gre_tunnel_t *gt[2] = { 0 };
349  adj_index_t adj_index[2] = { ADJ_INDEX_INVALID, ADJ_INDEX_INVALID };
350 
351  from = vlib_frame_vector_args (frame);
352  n_left_from = frame->n_vectors;
353  vlib_get_buffers (vm, from, bufs, n_left_from);
354 
355  while (n_left_from >= 2)
356  {
357 
358  if (PREDICT_FALSE
359  (sw_if_index[0] != vnet_buffer (b[0])->sw_if_index[VLIB_TX]))
360  {
361  const vnet_hw_interface_t *hi;
362  sw_if_index[0] = vnet_buffer (b[0])->sw_if_index[VLIB_TX];
363  hi = vnet_get_sup_hw_interface (gm->vnet_main, sw_if_index[0]);
364  gt[0] = &gm->tunnels[hi->dev_instance];
365  adj_index[0] = gt[0]->l2_adj_index;
366  }
367  if (PREDICT_FALSE
368  (sw_if_index[1] != vnet_buffer (b[1])->sw_if_index[VLIB_TX]))
369  {
370  const vnet_hw_interface_t *hi;
371  sw_if_index[1] = vnet_buffer (b[1])->sw_if_index[VLIB_TX];
372  hi = vnet_get_sup_hw_interface (gm->vnet_main, sw_if_index[1]);
373  gt[1] = &gm->tunnels[hi->dev_instance];
374  adj_index[1] = gt[1]->l2_adj_index;
375  }
376 
377  vnet_buffer (b[0])->ip.adj_index[VLIB_TX] = adj_index[0];
378  vnet_buffer (b[1])->ip.adj_index[VLIB_TX] = adj_index[1];
379 
380  if (PREDICT_FALSE (gt[0]->type == GRE_TUNNEL_TYPE_ERSPAN))
381  {
382  /* Encap GRE seq# and ERSPAN type II header */
383  erspan_t2_t *h0;
384  u32 seq_num;
385  u64 hdr;
386  vlib_buffer_advance (b[0], -sizeof (erspan_t2_t));
387  h0 = vlib_buffer_get_current (b[0]);
388  seq_num = clib_atomic_fetch_add (&gt[0]->gre_sn->seq_num, 1);
389  hdr = clib_host_to_net_u64 (ERSPAN_HDR2);
390  h0->seq_num = clib_host_to_net_u32 (seq_num);
391  h0->t2_u64 = hdr;
392  h0->t2.cos_en_t_session |= clib_host_to_net_u16 (gt[0]->session_id);
393  }
394  if (PREDICT_FALSE (gt[1]->type == GRE_TUNNEL_TYPE_ERSPAN))
395  {
396  /* Encap GRE seq# and ERSPAN type II header */
397  erspan_t2_t *h0;
398  u32 seq_num;
399  u64 hdr;
400  vlib_buffer_advance (b[1], -sizeof (erspan_t2_t));
401  h0 = vlib_buffer_get_current (b[1]);
402  seq_num = clib_atomic_fetch_add (&gt[1]->gre_sn->seq_num, 1);
403  hdr = clib_host_to_net_u64 (ERSPAN_HDR2);
404  h0->seq_num = clib_host_to_net_u32 (seq_num);
405  h0->t2_u64 = hdr;
406  h0->t2.cos_en_t_session |= clib_host_to_net_u16 (gt[1]->session_id);
407  }
408 
409  if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
410  {
411  gre_tx_trace_t *tr = vlib_add_trace (vm, node,
412  b[0], sizeof (*tr));
413  tr->tunnel_id = gt[0] - gm->tunnels;
414  tr->src = gt[0]->tunnel_src;
415  tr->dst = gt[0]->tunnel_dst.fp_addr;
416  tr->length = vlib_buffer_length_in_chain (vm, b[0]);
417  }
418  if (PREDICT_FALSE (b[1]->flags & VLIB_BUFFER_IS_TRACED))
419  {
420  gre_tx_trace_t *tr = vlib_add_trace (vm, node,
421  b[1], sizeof (*tr));
422  tr->tunnel_id = gt[1] - gm->tunnels;
423  tr->src = gt[1]->tunnel_src;
424  tr->dst = gt[1]->tunnel_dst.fp_addr;
425  tr->length = vlib_buffer_length_in_chain (vm, b[1]);
426  }
427 
428  b += 2;
429  n_left_from -= 2;
430  }
431 
432  while (n_left_from >= 1)
433  {
434 
435  if (PREDICT_FALSE
436  (sw_if_index[0] != vnet_buffer (b[0])->sw_if_index[VLIB_TX]))
437  {
438  const vnet_hw_interface_t *hi;
439  sw_if_index[0] = vnet_buffer (b[0])->sw_if_index[VLIB_TX];
440  hi = vnet_get_sup_hw_interface (gm->vnet_main, sw_if_index[0]);
441  gt[0] = &gm->tunnels[hi->dev_instance];
442  adj_index[0] = gt[0]->l2_adj_index;
443  }
444 
445  vnet_buffer (b[0])->ip.adj_index[VLIB_TX] = adj_index[0];
446 
447  if (PREDICT_FALSE (gt[0]->type == GRE_TUNNEL_TYPE_ERSPAN))
448  {
449  /* Encap GRE seq# and ERSPAN type II header */
450  erspan_t2_t *h0;
451  u32 seq_num;
452  u64 hdr;
453  vlib_buffer_advance (b[0], -sizeof (erspan_t2_t));
454  h0 = vlib_buffer_get_current (b[0]);
455  seq_num = clib_atomic_fetch_add (&gt[0]->gre_sn->seq_num, 1);
456  hdr = clib_host_to_net_u64 (ERSPAN_HDR2);
457  h0->seq_num = clib_host_to_net_u32 (seq_num);
458  h0->t2_u64 = hdr;
459  h0->t2.cos_en_t_session |= clib_host_to_net_u16 (gt[0]->session_id);
460  }
461 
462  if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
463  {
464  gre_tx_trace_t *tr = vlib_add_trace (vm, node,
465  b[0], sizeof (*tr));
466  tr->tunnel_id = gt[0] - gm->tunnels;
467  tr->src = gt[0]->tunnel_src;
468  tr->dst = gt[0]->tunnel_dst.fp_addr;
469  tr->length = vlib_buffer_length_in_chain (vm, b[0]);
470  }
471 
472  b += 1;
473  n_left_from -= 1;
474  }
475 
476  vlib_buffer_enqueue_to_single_next (vm, node, from,
478  frame->n_vectors);
479 
480  vlib_node_increment_counter (vm, node->node_index,
481  GRE_ERROR_PKTS_ENCAP, frame->n_vectors);
482 
483  return frame->n_vectors;
484 }
485 
486 static char *gre_error_strings[] = {
487 #define gre_error(n,s) s,
488 #include "error.def"
489 #undef gre_error
490 };
491 
492 /* *INDENT-OFF* */
494 {
495  .name = "gre-encap",
496  .vector_size = sizeof (u32),
497  .format_trace = format_gre_tx_trace,
498  .type = VLIB_NODE_TYPE_INTERNAL,
499  .n_errors = GRE_N_ERROR,
500  .error_strings = gre_error_strings,
501  .n_next_nodes = GRE_ENCAP_N_NEXT,
502  .next_nodes = {
503  [GRE_ENCAP_NEXT_L2_MIDCHAIN] = "adj-l2-midchain",
504  },
505 };
506 /* *INDENT-ON* */
507 
508 #ifndef CLIB_MARCH_VARIANT
509 static u8 *
510 format_gre_tunnel_name (u8 * s, va_list * args)
511 {
512  u32 dev_instance = va_arg (*args, u32);
513  gre_main_t *gm = &gre_main;
514  gre_tunnel_t *t;
515 
516  if (dev_instance >= vec_len (gm->tunnels))
517  return format (s, "<improperly-referenced>");
518 
519  t = pool_elt_at_index (gm->tunnels, dev_instance);
520  return format (s, "gre%d", t->user_instance);
521 }
522 
523 static u8 *
524 format_gre_device (u8 * s, va_list * args)
525 {
526  u32 dev_instance = va_arg (*args, u32);
527  CLIB_UNUSED (int verbose) = va_arg (*args, int);
528 
529  s = format (s, "GRE tunnel: id %d\n", dev_instance);
530  return s;
531 }
532 
533 /* *INDENT-OFF* */
535  .name = "GRE tunnel device",
536  .format_device_name = format_gre_tunnel_name,
537  .format_device = format_gre_device,
538  .format_tx_trace = format_gre_tx_trace,
539  .admin_up_down_function = gre_interface_admin_up_down,
540 #ifdef SOON
541  .clear counter = 0;
542 #endif
543 };
544 
546  .name = "GRE",
547  .format_header = format_gre_header_with_length,
548  .unformat_header = unformat_gre_header,
549  .build_rewrite = gre_build_rewrite,
550  .update_adjacency = gre_update_adj,
552 };
553 /* *INDENT-ON* */
554 #endif /* CLIB_MARCH_VARIANT */
555 
556 static void
558 {
560  u32 i;
561 
562  vec_add2 (gm->protocol_infos, pi, 1);
563  i = pi - gm->protocol_infos;
564 
565  pi->name = protocol_name;
566  pi->protocol = protocol;
567  pi->next_index = pi->node_index = ~0;
568 
569  hash_set (gm->protocol_info_by_protocol, protocol, i);
571 }
572 
573 static clib_error_t *
575 {
576  gre_main_t *gm = &gre_main;
577  clib_error_t *error;
578  ip_main_t *im = &ip_main;
579  ip_protocol_info_t *pi;
580 
581  clib_memset (gm, 0, sizeof (gm[0]));
582  gm->vlib_main = vm;
583  gm->vnet_main = vnet_get_main ();
584 
585  if ((error = vlib_call_init_function (vm, ip_main_init)))
586  return error;
587 
588  if ((error = vlib_call_init_function (vm, ip4_lookup_init)))
589  return error;
590 
591  if ((error = vlib_call_init_function (vm, ip6_lookup_init)))
592  return error;
593 
594  /* Set up the ip packet generator */
595  pi = ip_get_protocol_info (im, IP_PROTOCOL_GRE);
598 
599  gm->protocol_info_by_name = hash_create_string (0, sizeof (uword));
600  gm->protocol_info_by_protocol = hash_create (0, sizeof (uword));
601  gm->tunnel_by_key4 =
602  hash_create_mem (0, sizeof (gre_tunnel_key4_t), sizeof (uword));
603  gm->tunnel_by_key6 =
604  hash_create_mem (0, sizeof (gre_tunnel_key6_t), sizeof (uword));
605  gm->seq_num_by_key =
606  hash_create_mem (0, sizeof (gre_sn_key_t), sizeof (uword));
607 
608 #define _(n,s) add_protocol (gm, GRE_PROTOCOL_##s, #s);
610 #undef _
612 }
613 
615 
616 /*
617  * fd.io coding-style-patch-verification: ON
618  *
619  * Local Variables:
620  * eval: (c-set-style "gnu")
621  * End:
622  */
vnet_main_t * vnet_main
Definition: gre.h:280
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:439
u32 sw_if_index
Definition: ipsec_gre.api:37
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:212
uword * seq_num_by_key
Hash mapping tunnel src/dst addr and fib-idx to sequence number.
Definition: gre.h:267
VNET_HW_INTERFACE_CLASS(gre_hw_interface_class)
ip46_address_t src
Definition: gre.c:57
vmrglw vmrglh hi
#define hash_set(h, key, value)
Definition: hash.h:255
uword * tunnel_by_key6
Hash mapping to tunnels with ipv6 src/dst addr.
Definition: gre.h:262
GRE related global data.
Definition: gre.h:237
u32 flags
Definition: vhost_user.h:115
#define CLIB_UNUSED(x)
Definition: clib.h:82
Key for a IPv6 GRE Tunnel We use a different type so that the V4 key hash is as small as possible...
Definition: gre.h:120
uword * protocol_info_by_protocol
Definition: gre.h:252
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
static clib_error_t * ip4_lookup_init(vlib_main_t *vm)
Definition: ip4_forward.c:909
u64 as_u64
Definition: bihash_doc.h:63
u32 tunnel_id
Definition: gre.c:51
unsigned long u64
Definition: types.h:89
vnet_link_t adj_get_link_type(adj_index_t ai)
Return the link type of the adjacency.
Definition: adj.c:468
#define NULL
Definition: clib.h:58
gre_protocol_t protocol
GRE protocol type in host byte order.
Definition: gre.h:77
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
char * name
Name (a c string).
Definition: gre.h:74
IP unicast adjacency.
Definition: adj.h:221
A GRE payload protocol registration.
Definition: gre.h:71
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:560
int i
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:983
format_function_t format_ip46_address
Definition: format.h:61
static u32 format_get_indent(u8 *s)
Definition: format.h:72
#define hash_set_mem(h, key, value)
Definition: hash.h:275
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
u8 data[128]
Definition: ipsec.api:248
Definition: ip.h:109
#define VLIB_NODE_FN(node)
Definition: node.h:201
static 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:366
unsigned char u8
Definition: types.h:56
u32 * tunnel_index_by_sw_if_index
Mapping from sw_if_index to tunnel index.
Definition: gre.h:272
VNET_DEVICE_CLASS(gre_device_class)
#define clib_memcpy(d, s, n)
Definition: string.h:180
Hash key for GRE header seq number generation for ERSPAN encap.
Definition: gre.h:166
unformat_function_t * unformat_pg_edit
Definition: ip.h:90
ip4_and_gre_header_t ip4_and_gre
Definition: gre.c:31
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:163
static void gre4_fixup(vlib_main_t *vm, ip_adjacency_t *adj, vlib_buffer_t *b0, const void *data)
Definition: gre.c:278
IPv4 and GRE header union.
Definition: gre.c:27
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:113
void gre_tunnel_stack(adj_index_t ai)
gre_tunnel_stack
Definition: interface.c:121
gre_encap_next_t
Definition: gre.c:331
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
static_always_inline void vlib_buffer_enqueue_to_single_next(vlib_main_t *vm, vlib_node_runtime_t *node, u32 *buffers, u16 next_index, u32 count)
Definition: buffer_node.h:452
ip6_and_gre_header_t ip6_and_gre
Definition: gre.c:40
unsigned int u32
Definition: types.h:88
adj_index_t l2_adj_index
an L2 tunnel always rquires an L2 midchain.
Definition: gre.h:208
#define vlib_call_init_function(vm, x)
Definition: init.h:260
ip46_address_t tunnel_src
The tunnel&#39;s source/local address.
Definition: gre.h:192
uword unformat_gre_header(unformat_input_t *input, va_list *args)
Definition: gre.c:164
#define VLIB_FRAME_SIZE
Definition: node.h:376
#define hash_create_string(elts, value_bytes)
Definition: hash.h:690
#define hash_create_mem(elts, key_bytes, value_bytes)
Definition: hash.h:661
uword * tunnel_by_key4
Hash mapping to tunnels with ipv4 src/dst addr.
Definition: gre.h:257
#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:514
A representation of a GRE tunnel.
Definition: gre.h:176
vlib_node_registration_t gre_encap_node
(constructor) VLIB_REGISTER_NODE (gre_encap_node)
Definition: gre.c:493
static ip_protocol_info_t * ip_get_protocol_info(ip_main_t *im, u32 protocol)
Definition: ip.h:136
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
Definition: fib_types.h:226
#define gm
Definition: dlmalloc.c:1217
format_function_t * format_header
Definition: ip.h:81
struct _unformat_input_t unformat_input_t
unsigned short u16
Definition: types.h:57
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:229
u32 node_index
Node which handles this type.
Definition: gre.h:83
void gre_update_adj(vnet_main_t *vnm, u32 sw_if_index, adj_index_t ai)
Definition: gre.c:307
#define PREDICT_FALSE(x)
Definition: clib.h:111
u8 * format_gre_tx_trace(u8 *s, va_list *args)
Definition: gre.c:65
format_function_t * format_buffer
Definition: node.h:356
u16 flags_and_version
Definition: packet.h:40
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1150
uword * protocol_info_by_name
Hash tables mapping name/protocol to protocol info index.
Definition: gre.h:252
static u8 * format_gre_tunnel_name(u8 *s, va_list *args)
Definition: gre.c:510
static clib_error_t * gre_input_init(vlib_main_t *vm)
Definition: node.c:539
static clib_error_t * gre_init(vlib_main_t *vm)
Definition: gre.c:574
Key for a IPv4 GRE Tunnel.
Definition: gre.h:92
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
clib_error_t * ip_main_init(vlib_main_t *vm)
Definition: ip_init.c:45
gre_tunnel_type_t type
Definition: gre.h:203
vlib_main_t * vm
Definition: buffer.c:312
static u8 * format_gre_device(u8 *s, va_list *args)
Definition: gre.c:524
ip_main_t ip_main
Definition: ip_init.c:42
u16 protocol
Definition: packet.h:55
void adj_nbr_midchain_update_rewrite(adj_index_t adj_index, adj_midchain_fixup_t fixup, const void *fixup_data, adj_flags_t flags, u8 *rewrite)
adj_nbr_midchain_update_rewrite
Definition: adj_midchain.c:500
gre_protocol_t
Definition: packet.h:30
u32 adj_index_t
An index for adjacencies.
Definition: adj_types.h:30
u8 * format_gre_header_with_length(u8 *s, va_list *args)
Definition: gre.c:94
#define hash_create(elts, value_bytes)
Definition: hash.h:696
#define ASSERT(truth)
static u8 * gre_build_rewrite(vnet_main_t *vnm, u32 sw_if_index, vnet_link_t link_type, const void *dst_address)
Definition: gre.c:211
u32 next_index
Next index for this type.
Definition: gre.h:86
static void gre6_fixup(vlib_main_t *vm, ip_adjacency_t *adj, vlib_buffer_t *b0, const void *data)
Definition: gre.c:292
#define ERSPAN_HDR2
Definition: packet.h:164
enum vnet_link_t_ vnet_link_t
Link Type: A description of the protocol of packets on the link.
static int gre_proto_from_vnet_link(vnet_link_t link)
Definition: gre.c:188
gre_tunnel_t * tunnels
pool of tunnel instances
Definition: gre.h:242
uword unformat_vlib_number_by_name(unformat_input_t *input, va_list *args)
Definition: format.c:157
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:248
vnet_hw_interface_class_t gre_hw_interface_class
u32 user_instance
Definition: gre.h:225
#define clib_atomic_fetch_add(a, b)
Definition: atomics.h:23
enum adj_flags_t_ adj_flags_t
Flags on an IP adjacency.
static 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:57
Definition: defs.h:47
vnet_device_class_t gre_device_class
clib_error_t * gre_interface_admin_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: interface.c:388
ip46_address_t dst
Definition: gre.c:58
u16 payload_length
Definition: ip6_packet.h:376
ERSPAN type 2 - the tunnel is for port mirror SPAN output.
Definition: gre.h:57
static void add_protocol(gre_main_t *gm, gre_protocol_t protocol, char *protocol_name)
Definition: gre.c:557
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
uword unformat_gre_protocol_host_byte_order(unformat_input_t *input, va_list *args)
Definition: gre.c:133
#define GRE_FLAGS_SEQUENCE
Definition: packet.h:47
VLIB buffer representation.
Definition: buffer.h:102
u64 uword
Definition: types.h:112
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:244
a point 2 point interface
Definition: interface.h:357
u8 * format_gre_header(u8 *s, va_list *args)
Definition: gre.c:125
unformat_function_t unformat_pg_gre_header
Definition: gre.h:338
u8 * format_gre_protocol(u8 *s, va_list *args)
Definition: gre.c:79
#define vnet_buffer(b)
Definition: buffer.h:369
fib_prefix_t tunnel_dst
The tunnel&#39;s destination/remote address.
Definition: gre.h:196
static vlib_node_t * vlib_get_node(vlib_main_t *vm, u32 i)
Get vlib node by index.
Definition: node_funcs.h:59
static gre_protocol_info_t * gre_get_protocol_info(gre_main_t *em, gre_protocol_t protocol)
Definition: gre.h:307
gre_protocol_info_t * protocol_infos
GRE payload protocol registrations.
Definition: gre.h:247
u32 length
Definition: gre.c:54
vlib_main_t * vlib_main
Definition: gre.h:279
static_always_inline void vlib_get_buffers(vlib_main_t *vm, u32 *bi, vlib_buffer_t **b, int count)
Translate array of buffer indices into buffer pointers.
Definition: buffer_funcs.h:244
static clib_error_t * ip6_lookup_init(vlib_main_t *vm)
Definition: ip6_forward.c:2692
uword unformat_gre_protocol_net_byte_order(unformat_input_t *input, va_list *args)
Definition: gre.c:153
static char * gre_error_strings[]
Definition: gre.c:486
gre_main_t gre_main
Definition: gre.c:25
static u16 ip4_header_checksum(ip4_header_t *i)
Definition: ip4_packet.h:247
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
u8 protocol
Definition: ipsec.api:96