FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
md2_ioam_transit.c
Go to the documentation of this file.
1  /*
2  * Copyright (c) 2017 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 <vppinfra/error.h>
16 #include <vppinfra/hash.h>
17 #include <vnet/vnet.h>
18 #include <vnet/ip/ip.h>
19 #include <vnet/udp/udp_local.h>
20 #include <vnet/ethernet/ethernet.h>
22 #include <nsh/nsh.h>
23 #include <nsh/nsh_packet.h>
26 #include <vnet/fib/ip6_fib.h>
27 #include <vnet/fib/ip4_fib.h>
28 #include <vnet/fib/fib_entry.h>
29 
30 /* Statistics (not really errors) */
31 #define foreach_nsh_md2_ioam_encap_transit_error \
32 _(ENCAPSULATED, "good packets encapsulated")
33 
35 #define _(sym,string) string,
37 #undef _
38 };
39 
40 typedef enum
41 {
42 #define _(sym,str) NSH_MD2_IOAM_ENCAP_TRANSIT_IOAM_ERROR_##sym,
44 #undef _
47 
48 typedef enum
49 {
54 
55 
56 /* *INDENT-OFF* */
58 {
59  .arc_name = "ip4-output",
60  .node_name = "nsh-md2-ioam-encap-transit",
61 };
62 /* *INDENT-ON* */
63 
64 
65 static uword
69 {
70  u32 n_left_from, next_index, *from, *to_next;
71 
73  n_left_from = from_frame->n_vectors;
74 
75  next_index = node->cached_next_index;
76 
77  while (n_left_from > 0)
78  {
79  u32 n_left_to_next;
80 
81  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
82 
83 
84  while (n_left_from > 0 && n_left_to_next > 0)
85  {
86  u32 bi0;
87  vlib_buffer_t *b0;
89 
90  bi0 = from[0];
91  to_next[0] = bi0;
92  from += 1;
93  to_next += 1;
94  n_left_from -= 1;
95  n_left_to_next -= 1;
96  ip4_header_t *ip0;
97  u32 iph_offset = 0;
98 
99  b0 = vlib_get_buffer (vm, bi0);
100  iph_offset = vnet_buffer (b0)->ip.save_rewrite_length;
101  ip0 = (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b0)
102  + iph_offset);
103 
104  /* just forward non ipv4 packets */
105  if (PREDICT_FALSE
106  ((ip0->ip_version_and_header_length & 0xF0) == 0x40))
107  {
108  /* ipv4 packets */
109  udp_header_t *udp_hdr0 = (udp_header_t *) (ip0 + 1);
110  if (PREDICT_FALSE
111  ((ip0->protocol == IP_PROTOCOL_UDP) &&
112  (clib_net_to_host_u16 (udp_hdr0->dst_port) ==
113  UDP_DST_PORT_lisp_gpe)))
114  {
115 
116  /* Check the iOAM header */
117  lisp_gpe_header_t *lisp_gpe_hdr0 =
118  (lisp_gpe_header_t *) (udp_hdr0 + 1);
119  nsh_base_header_t *nsh_hdr =
120  (nsh_base_header_t *) (lisp_gpe_hdr0 + 1);
121 
122  if (PREDICT_FALSE
123  (lisp_gpe_hdr0->next_protocol ==
124  LISP_GPE_NEXT_PROTO_NSH) && (nsh_hdr->md_type == 2))
125  {
126  uword *t = NULL;
128  fib_prefix_t key4;
129  clib_memset (&key4, 0, sizeof (key4));
130  key4.fp_proto = FIB_PROTOCOL_IP4;
131  key4.fp_addr.ip4.as_u32 = ip0->dst_address.as_u32;
132  t = hash_get_mem (hm->dst_by_ip4, &key4);
133  if (t)
134  {
136  (word) (sizeof
137  (ethernet_header_t)));
139  node,
140  b0,
141  &next0,
143  1
144  /* use_adj */
145  );
147  -(word) (sizeof
148  (ethernet_header_t)));
149  }
150  }
151  }
152  }
153 
155  n_left_to_next, bi0, next0);
156  }
157 
158  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
159  }
160 
161  return from_frame->n_vectors;
162 }
163 
164 extern u8 *format_nsh_node_map_trace (u8 * s, va_list * args);
165 /* *INDENT-OFF* */
167  .function = nsh_md2_ioam_encap_transit,
168  .name = "nsh-md2-ioam-encap-transit",
169  .vector_size = sizeof (u32),
170  .format_trace = format_nsh_node_map_trace,
172 
175 
177 
178  .next_nodes = {
179  [NSH_MD2_IOAM_ENCAP_TRANSIT_IOAM_NEXT_OUTPUT] = "interface-output",
181  },
182 
183 };
184 /* *INDENT-ON* */
185 
186 
187 /*
188  * fd.io coding-style-patch-verification: ON
189  *
190  * Local Variables:
191  * eval: (c-set-style "gnu")
192  * End:
193  */
NSH_MD2_IOAM_ENCAP_TRANSIT_IOAM_NEXT_OUTPUT
@ NSH_MD2_IOAM_ENCAP_TRANSIT_IOAM_NEXT_OUTPUT
Definition: md2_ioam_transit.c:50
fib_entry.h
format_nsh_node_map_trace
u8 * format_nsh_node_map_trace(u8 *s, va_list *args)
Definition: nsh_cli.c:594
next_index
nat44_ei_hairpin_src_next_t next_index
Definition: nat44_ei_hairpinning.c:412
VNET_FEATURE_INIT
VNET_FEATURE_INIT(nsh_md2_ioam_encap_transit, static)
nsh_md2_ioam.h
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
nsh_md2_ioam_util.h
VLIB_NODE_TYPE_INTERNAL
@ VLIB_NODE_TYPE_INTERNAL
Definition: node.h:72
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
ip4_address_t::as_u32
u32 as_u32
Definition: ip4_packet.h:57
nsh_md2_ioam_encap_transit_next_t
nsh_md2_ioam_encap_transit_next_t
Definition: md2_ioam_transit.c:48
LISP_GPE_NEXT_PROTO_NSH
@ LISP_GPE_NEXT_PROTO_NSH
Definition: lisp_gpe_packet.h:137
foreach_nsh_md2_ioam_encap_transit_error
#define foreach_nsh_md2_ioam_encap_transit_error
Definition: md2_ioam_transit.c:31
NSH_MD2_IOAM_ENCAP_TRANSIT_IOAM_NEXT_DROP
@ NSH_MD2_IOAM_ENCAP_TRANSIT_IOAM_NEXT_DROP
Definition: md2_ioam_transit.c:51
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
nsh_md2_ioam_main_::dst_by_ip4
uword * dst_by_ip4
Definition: nsh_md2_ioam.h:84
from_frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * from_frame
Definition: esp_encrypt.c:1328
nsh_md2_ioam_encap_transit
static uword nsh_md2_ioam_encap_transit(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
Definition: md2_ioam_transit.c:66
vlib_frame_t
Definition: node.h:372
NSH_MD2_IOAM_ENCAP_TRANSIT_IOAM_N_NEXT
@ NSH_MD2_IOAM_ENCAP_TRANSIT_IOAM_N_NEXT
Definition: md2_ioam_transit.c:52
udp_header_t
Definition: udp_packet.h:45
ip4_header_t
Definition: ip4_packet.h:87
ethernet.h
nsh_md2_ioam_encap_decap_ioam_v4_one_inline
static void nsh_md2_ioam_encap_decap_ioam_v4_one_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_buffer_t *b0, u32 *next0, u32 drop_node_val, u8 use_adj)
Definition: nsh_md2_ioam_util.h:34
hash.h
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
error.h
nsh_md2_ioam_main
nsh_md2_ioam_main_t nsh_md2_ioam_main
Definition: nsh_md2_ioam.c:42
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:441
nsh_md2_ioam_encap_transit_node
vlib_node_registration_t nsh_md2_ioam_encap_transit_node
(constructor) VLIB_REGISTER_NODE (nsh_md2_ioam_encap_transit_node)
Definition: md2_ioam_transit.c:166
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
ARRAY_LEN
#define ARRAY_LEN(x)
Definition: clib.h:70
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
nsh_md2_ioam_main_
Definition: nsh_md2_ioam.h:39
udp_local.h
uword
u64 uword
Definition: types.h:112
ethernet_header_t
Definition: packet.h:52
lisp_gpe_header_t::next_protocol
u8 next_protocol
Definition: lisp_gpe_packet.h:105
FIB_PROTOCOL_IP4
@ FIB_PROTOCOL_IP4
Definition: fib_types.h:36
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
ip4_header_t::dst_address
ip4_address_t dst_address
Definition: ip4_packet.h:125
fib_prefix_t_::fp_addr
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
Definition: fib_types.h:225
hash_get_mem
#define hash_get_mem(h, key)
Definition: hash.h:269
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
nsh.h
vlib_put_next_frame
vlib_put_next_frame(vm, node, next_index, 0)
lisp_gpe_packet.h
LISP-GPE packet header structure.
ip.h
u32
unsigned int u32
Definition: types.h:88
udp_header_t::dst_port
u16 dst_port
Definition: udp_packet.h:48
lisp_gpe_header_t
LISP-GPE header.
Definition: lisp_gpe_packet.h:100
nsh_md2_ioam_encap_transit_error_strings
static char * nsh_md2_ioam_encap_transit_error_strings[]
Definition: md2_ioam_transit.c:34
fib_prefix_t_::fp_proto
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:211
nsh_packet.h
ip4_fib.h
ip6_fib.h
NSH_MD2_IOAM_ENCAP_TRANSIT_IOAM_N_ERROR
@ NSH_MD2_IOAM_ENCAP_TRANSIT_IOAM_N_ERROR
Definition: md2_ioam_transit.c:45
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
ip4_header_t::ip_version_and_header_length
u8 ip_version_and_header_length
Definition: ip4_packet.h:93
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
word
i64 word
Definition: types.h:111
vnet.h
vlib_node_runtime_t
Definition: node.h:454
from
from
Definition: nat44_ei_hairpinning.c:415
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
n_left_from
n_left_from
Definition: nat44_ei_hairpinning.c:416
nsh_md2_ioam_encap_transit_error_t
nsh_md2_ioam_encap_transit_error_t
Definition: md2_ioam_transit.c:40
fib_prefix_t_
Aggregate type for a prefix.
Definition: fib_types.h:202
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
ip4_header_t::protocol
u8 protocol
Definition: ip4_packet.h:115
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
VLIB_REGISTER_NODE
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169