FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
gbp_vxlan_node.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 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 #include <plugins/gbp/gbp_vxlan.h>
16 #include <plugins/gbp/gbp_itf.h>
17 #include <plugins/gbp/gbp_learn.h>
20 
22 #include <vlibmemory/api.h>
23 #include <vnet/fib/fib_table.h>
24 
25 extern uword *gv_db;
26 
27 typedef struct gbp_vxlan_trace_t_
28 {
35 
36 #define foreach_gbp_vxlan_input_next \
37  _(DROP, "error-drop") \
38  _(L2_INPUT, "l2-input") \
39  _(IP4_INPUT, "ip4-input") \
40  _(IP6_INPUT, "ip6-input")
41 
42 typedef enum
43 {
44 #define _(s,n) GBP_VXLAN_INPUT_NEXT_##s,
46 #undef _
49 
50 
51 #define foreach_gbp_vxlan_error \
52  _(DECAPPED, "decapped") \
53  _(LEARNED, "learned")
54 
55 typedef enum
56 {
57 #define _(s,n) GBP_VXLAN_ERROR_##s,
59 #undef _
62 
63 static char *gbp_vxlan_error_strings[] = {
64 #define _(n,s) s,
66 #undef _
67 };
68 
69 static uword
72  vlib_frame_t * from_frame, u8 is_ip4)
73 {
74  u32 n_left_to_next, n_left_from, next_index, *to_next, *from;
75 
76  next_index = 0;
78  n_left_from = from_frame->n_vectors;
79 
80  while (n_left_from > 0)
81  {
82 
83  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
84 
85  while (n_left_from > 0 && n_left_to_next > 0)
86  {
87  vxlan_gbp_header_t *vxlan_gbp0;
89  gbp_vxlan_tunnel_t *gt0;
90  vlib_buffer_t *b0;
91  u32 bi0, vni0;
92  uword *p;
93 
94  bi0 = to_next[0] = from[0];
95  from += 1;
96  to_next += 1;
97  n_left_from -= 1;
98  n_left_to_next -= 1;
99  next0 = GBP_VXLAN_INPUT_NEXT_DROP;
100 
101  b0 = vlib_get_buffer (vm, bi0);
102  vxlan_gbp0 =
104 
105  vni0 = vxlan_gbp_get_vni (vxlan_gbp0);
106  p = hash_get (gv_db, vni0);
107 
108  if (PREDICT_FALSE (NULL == p))
109  {
110  gt0 = NULL;
111  next0 = GBP_VXLAN_INPUT_NEXT_DROP;
112  }
113  else
114  {
115  gt0 = gbp_vxlan_tunnel_get (p[0]);
116 
117  vnet_buffer (b0)->sw_if_index[VLIB_RX] = gt0->gt_sw_if_index;
118 
119  if (GBP_VXLAN_TUN_L2 == gt0->gt_layer)
120  /*
121  * An L2 layer tunnel goes into the BD
122  */
123  next0 = GBP_VXLAN_INPUT_NEXT_L2_INPUT;
124  else
125  {
126  /*
127  * An L3 layer tunnel needs to strip the L2 header
128  * an inject into the RD
129  */
130  ethernet_header_t *e0;
131  u16 type0;
132 
133  e0 = vlib_buffer_get_current (b0);
134  type0 = clib_net_to_host_u16 (e0->type);
135  switch (type0)
136  {
137  case ETHERNET_TYPE_IP4:
138  next0 = GBP_VXLAN_INPUT_NEXT_IP4_INPUT;
139  break;
140  case ETHERNET_TYPE_IP6:
141  next0 = GBP_VXLAN_INPUT_NEXT_IP6_INPUT;
142  break;
143  default:
144  goto trace;
145  }
146  vlib_buffer_advance (b0, sizeof (*e0));
147  }
148  }
149 
150  trace:
151  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
152  {
153  gbp_vxlan_trace_t *tr;
154 
155  tr = vlib_add_trace (vm, node, b0, sizeof (*tr));
156  tr->dropped = (next0 == GBP_VXLAN_INPUT_NEXT_DROP);
157  tr->vni = vni0;
158  tr->sw_if_index = (gt0 ? gt0->gt_sw_if_index : ~0);
159  tr->flags = vxlan_gbp_get_gpflags (vxlan_gbp0);
160  tr->sclass = vxlan_gbp_get_sclass (vxlan_gbp0);
161  }
162 
164  to_next, n_left_to_next,
165  bi0, next0);
166  }
167 
168  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
169  }
170 
171  return from_frame->n_vectors;
172 }
173 
177 {
178  return gbp_vxlan_decap (vm, node, from_frame, 1);
179 }
180 
181 static u8 *
182 format_gbp_vxlan_rx_trace (u8 * s, va_list * args)
183 {
184  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
185  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
186  gbp_vxlan_trace_t *t = va_arg (*args, gbp_vxlan_trace_t *);
187 
188  s = format (s, "vni:%d dropped:%d rx:%d sclass:%d flags:%U",
189  t->vni, t->dropped, t->sw_if_index,
191 
192  return (s);
193 }
194 
195 /* *INDENT-OFF* */
197 {
198  .name = "gbp-vxlan4",
199  .vector_size = sizeof (u32),
200  .n_errors = GBP_VXLAN_N_ERROR,
201  .error_strings = gbp_vxlan_error_strings,
202  .n_next_nodes = GBP_VXLAN_INPUT_N_NEXT,
203  .format_trace = format_gbp_vxlan_rx_trace,
204  .next_nodes = {
205 #define _(s,n) [GBP_VXLAN_INPUT_NEXT_##s] = n,
207 #undef _
208  },
209 };
210 /* *INDENT-ON* */
211 
212 /*
213  * fd.io coding-style-patch-verification: ON
214  *
215  * Local Variables:
216  * eval: (c-set-style "gnu")
217  * End:
218  */
gbp_learn.h
trace
static vlib_cli_command_t trace
(constructor) VLIB_CLI_COMMAND (trace)
Definition: vlib_api_cli.c:870
api.h
vxlan_gbp_get_gpflags
static vxlan_gbp_gpflags_t vxlan_gbp_get_gpflags(vxlan_gbp_header_t *h)
Definition: vxlan_gbp_packet.h:143
gbp_vxlan4_input_node
vlib_node_registration_t gbp_vxlan4_input_node
(constructor) VLIB_REGISTER_NODE (gbp_vxlan4_input_node)
Definition: gbp_vxlan_node.c:196
next_index
nat44_ei_hairpin_src_next_t next_index
Definition: nat44_ei_hairpinning.c:412
vlib_get_buffer
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:111
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
fib_table.h
u16
unsigned short u16
Definition: types.h:57
ethernet_header_t::type
u16 type
Definition: packet.h:59
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
VLIB_RX
@ VLIB_RX
Definition: defs.h:46
from_frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * from_frame
Definition: esp_encrypt.c:1328
vlib_frame_t
Definition: node.h:372
foreach_gbp_vxlan_input_next
#define foreach_gbp_vxlan_input_next
Definition: gbp_vxlan_node.c:36
gbp_vxlan_trace_t_::sw_if_index
u32 sw_if_index
Definition: gbp_vxlan_node.c:31
vlib_buffer_advance
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:276
gbp_vxlan_decap
static uword gbp_vxlan_decap(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame, u8 is_ip4)
Definition: gbp_vxlan_node.c:70
VLIB_NODE_FN
#define VLIB_NODE_FN(node)
Definition: node.h:202
gbp_vxlan.h
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:441
gbp_vxlan_trace_t_::sclass
u16 sclass
Definition: gbp_vxlan_node.c:32
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
hash_get
#define hash_get(h, key)
Definition: hash.h:249
vlib_frame_vector_args
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:301
uword
u64 uword
Definition: types.h:112
ethernet_header_t
Definition: packet.h:52
gbp_itf.h
gbp_vxlan_tunnel_t_::gt_sw_if_index
u32 gt_sw_if_index
Definition: gbp_vxlan.h:42
gbp_vxlan_tunnel_t_::gt_layer
gbp_vxlan_tunnel_layer_t gt_layer
Definition: gbp_vxlan.h:49
GBP_VXLAN_N_ERROR
@ GBP_VXLAN_N_ERROR
Definition: gbp_vxlan_node.c:60
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
gbp_bridge_domain.h
gbp_vxlan_trace_t_::vni
u32 vni
Definition: gbp_vxlan_node.c:30
GBP_VXLAN_INPUT_N_NEXT
@ GBP_VXLAN_INPUT_N_NEXT
Definition: gbp_vxlan_node.c:47
gbp_vxlan_tunnel_t_
GBP VXLAN (template) tunnel.
Definition: gbp_vxlan.h:39
vlib_validate_buffer_enqueue_x1
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
Definition: buffer_node.h:224
gbp_vxlan_trace_t_::dropped
u8 dropped
Definition: gbp_vxlan_node.c:29
gbp_vxlan_input_error_t
gbp_vxlan_input_error_t
Definition: gbp_vxlan_node.c:55
vxlan_gbp_header_t
Definition: vxlan_gbp_packet.h:73
gbp_vxlan_error_strings
static char * gbp_vxlan_error_strings[]
Definition: gbp_vxlan_node.c:63
format_gbp_vxlan_rx_trace
static u8 * format_gbp_vxlan_rx_trace(u8 *s, va_list *args)
Definition: gbp_vxlan_node.c:182
format
description fragment has unexpected format
Definition: map.api:433
vlib_put_next_frame
vlib_put_next_frame(vm, node, next_index, 0)
u32
unsigned int u32
Definition: types.h:88
gbp_vxlan_trace_t_
Definition: gbp_vxlan_node.c:27
gbp_vxlan_trace_t_::flags
u8 flags
Definition: gbp_vxlan_node.c:33
vlib_main_t
Definition: main.h:102
vlib_node_t
Definition: node.h:247
vlib_add_trace
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace.c:628
u8
unsigned char u8
Definition: types.h:56
vlib_buffer_get_current
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:257
gbp_vxlan_trace_t
struct gbp_vxlan_trace_t_ gbp_vxlan_trace_t
gbp_route_domain.h
format_vxlan_gbp_header_gpflags
u8 * format_vxlan_gbp_header_gpflags(u8 *s, va_list *args)
Definition: vxlan_gbp_packet.c:37
gbp_vxlan_input_next_t
gbp_vxlan_input_next_t
Definition: gbp_vxlan_node.c:42
vlib_node_runtime_t
Definition: node.h:454
from
from
Definition: nat44_ei_hairpinning.c:415
vxlan_gbp_get_sclass
static u16 vxlan_gbp_get_sclass(vxlan_gbp_header_t *h)
Definition: vxlan_gbp_packet.h:134
gv_db
uword * gv_db
DB of added tunnels.
Definition: gbp_vxlan.c:41
vlib_get_next_frame
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
Definition: node_funcs.h:395
vxlan_gbp_get_vni
static u32 vxlan_gbp_get_vni(vxlan_gbp_header_t *h)
Definition: vxlan_gbp_packet.h:125
n_left_from
n_left_from
Definition: nat44_ei_hairpinning.c:416
gbp_vxlan_tunnel_get
gbp_vxlan_tunnel_t * gbp_vxlan_tunnel_get(index_t gti)
Definition: gbp_vxlan.c:84
foreach_gbp_vxlan_error
#define foreach_gbp_vxlan_error
Definition: gbp_vxlan_node.c:51
vxlan_gbp.h
vlib_buffer_t::flags
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index,...
Definition: buffer.h:133
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
VLIB_REGISTER_NODE
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169