FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
nsh.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 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 #ifndef included_nsh_h
16 #define included_nsh_h
17 
18 #include <vnet/vnet.h>
19 #include <nsh/nsh_packet.h>
20 #include <vnet/ip/ip4_packet.h>
21 
22 typedef struct {
23  u16 class;
27 
28 typedef struct {
31 
32 #define MAX_METADATA_LEN 62
33 /** Note:
34  * rewrite and rewrite_size used to support varied nsh header
35  */
36 typedef struct {
37  /* Required for pool_get_aligned */
38  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
39 
40  nsh_base_header_t nsh_base;
41  union {
42  nsh_md1_data_t md1_data;
44  } md;
45  u8 tlvs_len; /* configured md2 metadata's length, unit: byte */
46  u8 * tlvs_data; /* configured md2 metadata, network order */
47 
48  /** Rewrite string. network order
49  * contains base header and metadata */
51  u8 rewrite_size; /* unit: byte */
52 } nsh_entry_t;
53 
54 typedef struct {
58 
59 typedef struct {
60  /* Required for pool_get_aligned */
61  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
62 
63  /** Key for nsh_header_t entry: 24bit NSP 8bit NSI */
65  /** Key for nsh_header_t entry to map to. : 24bit NSP 8bit NSI
66  * This may be ~0 if next action is to decap to NSH next protocol
67  * Note the following heuristic:
68  * if nsp_nsi == mapped_nsp_nsi then use-case is like SFC SFF
69  * if nsp_nsi != mapped_nsp_nsi then use-case is like SFC SF
70  * Note: these are heuristics. Rules about NSI decrement are out of scope
71  */
73  /* NSH Header action: swap, push and pop */
75 
76  /** vnet intfc hw_if_index */
78  /* vnet intfc sw_if_index */
80 
81  /* encap if index */
86 } nsh_map_t;
87 
88 typedef struct {
92 
93 typedef struct {
94  u32 transport_type; /* 1:vxlan; */
95  u32 transport_index; /* transport's sw_if_index */
97 
98 typedef struct {
99  /* 24bit NSP 8bit NSI */
102 
103 #define MAX_MD2_OPTIONS 256
104 
105 typedef struct {
106  /* API message ID base */
108 
109  /* vector of nsh_header entry instances */
111 
112  /* hash lookup nsh header by key: {u32: nsp_nsi} */
114 
115  /* vector of nsh_mappings */
117 
118  /* hash lookup nsh mapping by key: {u32: nsp_nsi} */
120  uword * nsh_mapping_by_mapped_key; // for use in NSHSFC
121 
122  /* vector of nsh_proxy */
124 
125  /* hash lookup nsh_proxy by key */
127 
128  /** Free vlib hw_if_indices */
130  /** Mapping from sw_if_index to tunnel index */
132 
133  /* vector of nsh_option_map */
135  /* hash lookup nsh_option_map by key */
137 
138  /* Array of function pointers to process MD-Type 2 handling routines */
139  /*
140  * For API or CLI configuration and construct the rewrite buffer, invokes add_options() function.
141  * In the encap node, i.e. when performing PUSH nsh header, invokes options() function.
142  * In the swap node, i.e. when performing SWAP nsh header, invokes swap_options() function.
143  * In the decap node, i.e. when performing POP nsh header, invokes pop_options() function.
144  */
145  u8 options_size[MAX_MD2_OPTIONS]; /* sum of header and metadata */
146  int (*add_options[MAX_MD2_OPTIONS]) (u8 * opt,
147  u8 * opt_size);
149  nsh_tlv_header_t * opt);
150  int (*swap_options[MAX_MD2_OPTIONS]) (vlib_buffer_t * b,
151  nsh_tlv_header_t * old_opt,
152  nsh_tlv_header_t * new_opt);
153  int (*pop_options[MAX_MD2_OPTIONS]) (vlib_buffer_t * b,
154  nsh_tlv_header_t * opt);
155  u8 *(*trace[MAX_MD2_OPTIONS]) (u8 * s, nsh_tlv_header_t * opt);
157 
158  /* Feature arc indices */
161 
165 
166  /* convenience */
169 } nsh_main_t;
170 
171 extern nsh_main_t nsh_main;
174 
175 typedef struct {
176  u8 trace_data[256];
178 
179 u8 * format_nsh_input_map_trace (u8 * s, va_list * args);
180 u8 * format_nsh_header_with_length (u8 * s, va_list * args);
181 
182 /* Helper macros used in nsh.c and nsh_test.c */
183 #define foreach_copy_nsh_base_hdr_field \
184 _(ver_o_c) \
185 _(length) \
186 _(md_type) \
187 _(next_protocol) \
188 _(nsp_nsi)
189 
190 /* Statistics (not really errors) */
191 #define foreach_nsh_node_error \
192 _(MAPPED, "NSH header found and mapped") \
193 _(NO_MAPPING, "no mapping for nsh key") \
194 _(NO_ENTRY, "no entry for nsh key") \
195 _(NO_PROXY, "no proxy for transport key") \
196 _(INVALID_NEXT_PROTOCOL, "invalid next protocol") \
197 _(INVALID_OPTIONS, "invalid md2 options") \
198 _(INVALID_TTL, "ttl equals zero") \
199 
200 typedef enum {
201 #define _(sym,str) NSH_NODE_ERROR_##sym,
203 #undef _
205 
207 
208 #define foreach_nsh_node_next \
209  _(DROP, "error-drop") \
210  _(ENCAP_GRE4, "gre4-input" ) \
211  _(ENCAP_GRE6, "gre6-input" ) \
212  _(ENCAP_VXLANGPE, "vxlan-gpe-encap" ) \
213  _(ENCAP_VXLAN4, "vxlan4-encap" ) \
214  _(ENCAP_VXLAN6, "vxlan6-encap" ) \
215  _(DECAP_ETH_INPUT, "ethernet-input" ) \
216  _(ENCAP_LISP_GPE, "interface-output" ) \
217  _(ENCAP_ETHERNET, "nsh-eth-output") \
218 /* _(DECAP_IP4_INPUT, "ip4-input") \ */
219 /* _(DECAP_IP6_INPUT, "ip6-input" ) \ */
220 
221 typedef enum {
222 #define _(s,n) NSH_NODE_NEXT_##s,
224 #undef _
227 
228 typedef enum {
233 
234 typedef enum {
240 
241 #define VNET_SW_INTERFACE_FLAG_ADMIN_DOWN 0
242 
243 /* md2 class and type definition */
244 #define NSH_MD2_IOAM_CLASS 0x9
245 #define NSH_MD2_IOAM_OPTION_TYPE_TRACE 0x3B
246 #define NSH_MD2_IOAM_OPTION_TYPE_PROOF_OF_TRANSIT 0x3C
247 
248 #define NSH_MD2_IOAM_TRACE_DUMMY_LEN 0x8
249 
250 #define MAX_NSH_HEADER_LEN 256
251 #define MAX_NSH_OPTION_LEN 128
252 
253 int
255  u8 type,
256  u8 option_size,
257  int add_options (u8 * opt,
258  u8 * opt_size),
259  int options(vlib_buffer_t * b,
260  nsh_tlv_header_t * opt),
261  int swap_options (vlib_buffer_t * b,
262  nsh_tlv_header_t * old_opt,
263  nsh_tlv_header_t * new_opt),
264  int pop_options (vlib_buffer_t * b,
265  nsh_tlv_header_t * opt),
266  u8 * trace (u8 * s,
267  nsh_tlv_header_t * opt));
268 
269 typedef struct _nsh_main_placeholder
270 {
271  u8 output_feature_arc_index;
273 
274 int
275 nsh_add_del_map (nsh_add_del_map_args_t * a, u32 * map_indexp);
276 
277 int
279 
282 
283 int
284 nsh_add_del_entry (nsh_add_del_entry_args_t * a, u32 * entry_indexp);
285 
286 u8 *
287 format_nsh_node_map_trace (u8 * s, va_list * args);
288 
289 u8 *
290 format_nsh_header (u8 * s, va_list * args);
291 
292 clib_error_t *
294 
295 #endif /* included_nsh_h */
nsh_input_error_t
nsh_input_error_t
Definition: nsh.h:200
trace
static vlib_cli_command_t trace
(constructor) VLIB_CLI_COMMAND (trace)
Definition: vlib_api_cli.c:899
nsh_main_t::nsh_proxy_node_index
u32 nsh_proxy_node_index
Definition: nsh.h:163
NSH_ACTION_PUSH
@ NSH_ACTION_PUSH
Definition: nsh.h:230
NSH_ACTION_POP
@ NSH_ACTION_POP
Definition: nsh.h:231
nsh_proxy_session_by_key_t::transport_type
u32 transport_type
Definition: nsh.h:94
nsh_api_init
clib_error_t * nsh_api_init(vlib_main_t *vm, nsh_main_t *nm)
Definition: nsh_api.c:698
nsh_main_t::input_feature_arc_index
u8 input_feature_arc_index
Definition: nsh.h:159
format_nsh_header_with_length
u8 * format_nsh_header_with_length(u8 *s, va_list *args)
nsh_entry_t
Note: rewrite and rewrite_size used to support varied nsh header.
Definition: nsh.h:36
nsh_eth_output_node
vlib_node_registration_t nsh_eth_output_node
(constructor) VLIB_REGISTER_NODE (nsh_eth_output_node)
Definition: nsh_output.c:330
CLIB_CACHE_LINE_ALIGN_MARK
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
nsh_main_t::nsh_input_node_index
u32 nsh_input_node_index
Definition: nsh.h:162
NSH_INPUT_TYPE
@ NSH_INPUT_TYPE
Definition: nsh.h:235
nsh_add_del_entry
int nsh_add_del_entry(nsh_add_del_entry_args_t *a, u32 *entry_indexp)
Action function for adding an NSH entry nsh_add_del_entry_args_t *a: host order.
Definition: nsh_api.c:509
nsh_map_t::nsp_nsi
u32 nsp_nsi
Key for nsh_header_t entry: 24bit NSP 8bit NSI.
Definition: nsh.h:64
nsh_map_t::rx_sw_if_index
u32 rx_sw_if_index
Definition: nsh.h:83
u16
unsigned short u16
Definition: types.h:57
nsh_proxy_session_by_key_t::transport_index
u32 transport_index
Definition: nsh.h:95
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
nsh_option_map_by_key_t::type
u8 type
Definition: nsh.h:24
nsh_map_t::adj_index
u32 adj_index
Definition: nsh.h:85
nsh_add_del_entry_args_t
Definition: nsh.h:54
MAX_MD2_OPTIONS
#define MAX_MD2_OPTIONS
Definition: nsh.h:103
nsh_main_t
Definition: nsh.h:105
nsh_main_t::output_feature_arc_index
u8 output_feature_arc_index
Definition: nsh.h:160
nsh_add_del_map_args_t::map
nsh_map_t map
Definition: nsh.h:90
nsh_add_del_entry_args_t::nsh_entry
nsh_entry_t nsh_entry
Definition: nsh.h:56
nsh_md2_data_t
nsh_tlv_header_t nsh_md2_data_t
Definition: nsh_packet.h:93
nsh_main_t::vlib_main
vlib_main_t * vlib_main
Definition: nsh.h:167
nsh_option_map_by_key_t::pad
u8 pad
Definition: nsh.h:25
nsh_input_trace_t
Definition: nsh.h:175
nsh_map_t::next_node
u32 next_node
Definition: nsh.h:84
nsh_main
nsh_main_t nsh_main
Definition: nsh.c:28
nsh_main_t::nsh_classifier_node_index
u32 nsh_classifier_node_index
Definition: nsh.h:164
NSH_PROXY_TYPE
@ NSH_PROXY_TYPE
Definition: nsh.h:236
nsh_main_t::nsh_mappings
nsh_map_t * nsh_mappings
Definition: nsh.h:116
uword
u64 uword
Definition: types.h:112
format_nsh_header
u8 * format_nsh_header(u8 *s, va_list *args)
Definition: nsh_cli.c:509
nsh_md2_lookup_option
nsh_option_map_t * nsh_md2_lookup_option(u16 class, u8 type)
Definition: nsh.c:88
nsh_main_t::nsh_option_map_by_key
uword * nsh_option_map_by_key
Definition: nsh.h:136
nsh_add_del_map_args_t
Definition: nsh.h:88
nsh_entry_t::tlvs_data
u8 * tlvs_data
Definition: nsh.h:46
nsh_add_del_entry_args_t::is_add
u8 is_add
Definition: nsh.h:55
nsh_main_t::nsh_entries
nsh_entry_t * nsh_entries
Definition: nsh.h:110
nsh_add_del_map
int nsh_add_del_map(nsh_add_del_map_args_t *a, u32 *map_indexp)
Action function to add or del an nsh map.
Definition: nsh_api.c:345
nsh_map_t
Definition: nsh.h:59
nsh_entry_t::md2_data
nsh_md2_data_t md2_data
Definition: nsh.h:43
nsh_proxy_session_by_key_t
Definition: nsh.h:93
nsh_map_t::nsh_action
u32 nsh_action
Definition: nsh.h:74
nsh_main_t::nsh_mapping_by_key
uword * nsh_mapping_by_key
Definition: nsh.h:119
nsh_entry_t::md1_data
nsh_md1_data_t md1_data
Definition: nsh.h:42
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
nsh_main_t::nsh_proxy_session_by_key
uword * nsh_proxy_session_by_key
Definition: nsh.h:126
nsh_map_t::nsh_sw_if
u32 nsh_sw_if
Definition: nsh.h:79
ip4_packet.h
nsh_proxy_session_t
Definition: nsh.h:98
nsh_option_map_t::option_id
u32 option_id
Definition: nsh.h:29
vnet_main_t
Definition: vnet.h:76
nsh_entry_t::nsh_base
nsh_base_header_t nsh_base
Definition: nsh.h:40
nsh_option_map_by_key_t
Definition: nsh.h:22
NSH_NODE_N_ERROR
@ NSH_NODE_N_ERROR
Definition: nsh.h:204
nsh_add_del_proxy_session
int nsh_add_del_proxy_session(nsh_add_del_map_args_t *a)
Action function to add or del an nsh-proxy-session.
Definition: nsh_api.c:447
u32
unsigned int u32
Definition: types.h:88
nsh_main_t::nsh_proxy_sessions
nsh_proxy_session_t * nsh_proxy_sessions
Definition: nsh.h:123
options
static struct option options[]
Definition: main.c:52
nsh_main_t::nsh_option_mappings
nsh_option_map_t * nsh_option_mappings
Definition: nsh.h:134
nsh_main_t::nsh_mapping_by_mapped_key
uword * nsh_mapping_by_mapped_key
Definition: nsh.h:120
nsh_main_t::decap_v4_next_override
uword decap_v4_next_override
Definition: nsh.h:156
nsh_entry_t::rewrite
u8 * rewrite
Rewrite string.
Definition: nsh.h:50
nsh_map_t::nsh_hw_if
u32 nsh_hw_if
vnet intfc hw_if_index
Definition: nsh.h:77
nsh_map_t::sw_if_index
u32 sw_if_index
Definition: nsh.h:82
nsh_main_t::vnet_main
vnet_main_t * vnet_main
Definition: nsh.h:168
nsh_add_del_map_args_t::is_add
u8 is_add
Definition: nsh.h:89
nsh_proxy_session_t::nsp_nsi
u32 nsp_nsi
Definition: nsh.h:100
nm
nat44_ei_main_t * nm
Definition: nat44_ei_hairpinning.c:413
nsh_packet.h
nsh_md2_register_option
int nsh_md2_register_option(u16 class, u8 type, u8 option_size, int add_options(u8 *opt, u8 *opt_size), int options(vlib_buffer_t *b, nsh_tlv_header_t *opt), int swap_options(vlib_buffer_t *b, nsh_tlv_header_t *old_opt, nsh_tlv_header_t *new_opt), int pop_options(vlib_buffer_t *b, nsh_tlv_header_t *opt), u8 *trace(u8 *s, nsh_tlv_header_t *opt))
Definition: nsh.c:32
nsh_action_type
nsh_action_type
Definition: nsh.h:228
nsh_node_next_t
nsh_node_next_t
Definition: nsh.h:221
vlib_main_t
Definition: main.h:102
nsh_entity_type
nsh_entity_type
Definition: nsh.h:234
nsh_main_t::nsh_entry_by_key
uword * nsh_entry_by_key
Definition: nsh.h:113
b
vlib_buffer_t ** b
Definition: nat44_ei_out2in.c:717
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
a
a
Definition: bitmap.h:544
nsh_entry_t::rewrite_size
u8 rewrite_size
Definition: nsh.h:51
nsh_entry_t::tlvs_len
u8 tlvs_len
Definition: nsh.h:45
nsh_main_t::msg_id_base
u16 msg_id_base
Definition: nsh.h:107
nsh_map_t::mapped_nsp_nsi
u32 mapped_nsp_nsi
Key for nsh_header_t entry to map to.
Definition: nsh.h:72
foreach_nsh_node_next
#define foreach_nsh_node_next
Definition: nsh.h:208
foreach_nsh_node_error
#define foreach_nsh_node_error
Definition: nsh.h:191
format_nsh_input_map_trace
u8 * format_nsh_input_map_trace(u8 *s, va_list *args)
NSH_NODE_N_NEXT
@ NSH_NODE_N_NEXT
Definition: nsh.h:225
NSH_CLASSIFIER_TYPE
@ NSH_CLASSIFIER_TYPE
Definition: nsh.h:237
nsh_option_map_t
Definition: nsh.h:28
nsh_aware_vnf_proxy_node
vlib_node_registration_t nsh_aware_vnf_proxy_node
(constructor) VLIB_REGISTER_NODE (nsh_aware_vnf_proxy_node)
Definition: nsh_node.c:965
vnet.h
nsh_main_t::tunnel_index_by_sw_if_index
u32 * tunnel_index_by_sw_if_index
Mapping from sw_if_index to tunnel index.
Definition: nsh.h:131
nsh_main_placeholder_t
struct _nsh_main_placeholder nsh_main_placeholder_t
format_nsh_node_map_trace
u8 * format_nsh_node_map_trace(u8 *s, va_list *args)
Definition: nsh_cli.c:594
nsh_main_t::free_nsh_tunnel_hw_if_indices
u32 * free_nsh_tunnel_hw_if_indices
Free vlib hw_if_indices.
Definition: nsh.h:129
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
NSH_AWARE_VNF_PROXY_TYPE
@ NSH_AWARE_VNF_PROXY_TYPE
Definition: nsh.h:238
NSH_ACTION_SWAP
@ NSH_ACTION_SWAP
Definition: nsh.h:229
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111