FD.io VPP  v16.09
Vector Packet Processing
mpls.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_vnet_mpls_gre_h
16 #define included_vnet_mpls_gre_h
17 
18 #include <vnet/vnet.h>
19 #include <vnet/gre/gre.h>
20 #include <vnet/mpls-gre/packet.h>
21 #include <vnet/ip/ip4_packet.h>
22 #include <vnet/ethernet/ethernet.h>
23 
24 typedef CLIB_PACKED (struct {
25  ip4_header_t ip4; /* 20 bytes */
26  gre_header_t gre; /* 4 bytes */
27  mpls_unicast_header_t labels[0]; /* 4 bytes each */
28 }) ip4_gre_and_mpls_header_t;
29 
31 
32 typedef enum {
33 #define mpls_error(n,s) MPLS_ERROR_##n,
34 #include <vnet/mpls-gre/error.def>
35 #undef mpls_error
36  MPLS_N_ERROR,
38 
39 /*
40  * No protocol info, MPLS labels don't have a next-header field
41  * presumably the label field tells all...
42  */
43 
44 typedef struct {
52  u32 hw_if_index; /* L2 x-connect capable tunnel intfc */
56 
57 typedef struct {
58  u8 tunnel_dst[6];
68 
69 typedef struct {
71  /* only for policy tunnels */
74 } mpls_encap_t;
75 
76 typedef struct {
78  u32 next_index; /* e.g. ip4/6-input, l2-input */
79 } mpls_decap_t;
80 
81 typedef struct {
82  /* pool of gre tunnel instances */
85 
86  /* pool of ethernet tunnel instances */
89 
90  /* Encap side: map (fib, dst_address) to mpls label stack */
93 
94  /* Decap side: map rx label to FIB */
97 
98  /* mpls-o-e policy tunnel next index for ip4/ip6-classify */
101 
102  /* convenience */
105 } mpls_main_t;
106 
108 
116 
119 
121 
122 /* Parse mpls protocol as 0xXXXX or protocol name.
123  In either host or network byte order. */
129 
130 /* Parse mpls header. */
133 
134 /* manually added to the interface output node in mpls.c */
135 #define MPLS_GRE_OUTPUT_NEXT_LOOKUP 1
136 #define MPLS_GRE_OUTPUT_NEXT_DROP VNET_INTERFACE_TX_NEXT_DROP
137 
138 mpls_encap_t *
139 mpls_encap_by_fib_and_dest (mpls_main_t * mm, u32 rx_fib, u32 dst_address);
140 
142  u32 dst_address, u32 *labelp);
143 
145  ip4_address_t *dst,
146  ip4_address_t *intfc,
147  u32 mask_width,
148  u32 inner_fib_id, u32 outer_fib_id,
149  u32 * tunnel_intfc_sw_if_index,
150  u8 l2_only,
151  u8 is_add);
152 
154  ip4_address_t *intfc,
155  u32 mask_width,
156  u32 inner_fib_id,
157  u32 tx_sw_if_index,
158  u32 * tunnel_sw_if_index,
159  u8 l2_only,
160  u8 is_add);
161 
163 
164 int mpls_fib_reset_labels (u32 fib_id);
165 
166 int vnet_mpls_add_del_decap (u32 rx_fib_id,
167  u32 tx_fib_id,
168  u32 label_host_byte_order,
169  int s_bit, int next_index, int is_add);
170 
171 int vnet_mpls_add_del_encap (ip4_address_t *dest, u32 fib_id,
172  u32 *labels_host_byte_order,
173  u32 policy_tunnel_index,
174  int no_dst_hash, u32 * indexp, int is_add);
175 
177  mpls_encap_t * e,
178  u32 policy_tunnel_index);
179 typedef struct {
181 
182  /* Tunnel-id / index in tunnel vector */
184 
185  /* mpls encap index */
187 
188  /* pkt length */
190 
191  /* tunnel ip4 addresses */
195 
196 u8 * format_mpls_gre_tx_trace (u8 * s, va_list * args);
197 u8 * format_mpls_gre_header (u8 * s, va_list * args);
198 
199 #define foreach_mpls_input_next \
200 _(DROP, "error-drop") \
201 _(IP4_INPUT, "ip4-input") \
202 _(L2_OUTPUT, "l2-output")
203 
204 typedef enum {
205 #define _(s,n) MPLS_INPUT_NEXT_##s,
207 #undef _
210 
211 
212 typedef struct {
214 
215  /* Tunnel-id / index in tunnel vector */
217 
218  /* output interface */
220 
221  /* mpls encap index */
223 
224  /* pkt length */
226 
227  u8 dst[6];
229 
230 u8 * format_mpls_eth_tx_trace (u8 * s, va_list * args);
231 
232 typedef struct {
239 
240 int
241 mpls_dest_cmp(void * a1, void * a2);
242 
243 int
244 mpls_fib_index_cmp(void * a1, void * a2);
245 
246 int
247 mpls_label_cmp(void * a1, void * a2);
248 
249 #endif /* included_vnet_mpls_gre_h */
int mpls_label_from_fib_id_and_dest(mpls_main_t *gm, u32 fib_id, u32 dst_address, u32 *labelp)
format_function_t format_mpls_header_with_length
Definition: mpls.h:111
uword( unformat_function_t)(unformat_input_t *input, va_list *args)
Definition: format.h:231
u32 * free_gre_sw_if_indices
Definition: mpls.h:84
mpls_gre_error_t
Definition: mpls.h:32
u8 * format_mpls_eth_tx_trace(u8 *s, va_list *args)
Definition: mpls.c:44
format_function_t format_mpls_header
Definition: mpls.h:110
u32 mask_width
Definition: mpls.h:62
format_function_t format_mpls_eth_header_with_length
Definition: mpls.h:113
ip4_address_t intfc_address
Definition: mpls.h:47
int mpls_label_cmp(void *a1, void *a2)
Definition: mpls.c:599
u32 inner_fib_index
Definition: mpls.h:49
u32 next_index
Definition: mpls.h:78
u32 hw_if_index
Definition: mpls.h:64
format_function_t format_mpls_protocol
Definition: mpls.h:109
struct _vlib_node_registration vlib_node_registration_t
int vnet_mpls_gre_add_del_tunnel(ip4_address_t *src, ip4_address_t *dst, ip4_address_t *intfc, u32 mask_width, u32 inner_fib_id, u32 outer_fib_id, u32 *tunnel_intfc_sw_if_index, u8 l2_only, u8 is_add)
Definition: interface.c:728
unformat_function_t unformat_pg_mpls_gre_header
Definition: mpls.h:128
uword * mpls_encap_by_fib_and_dest
Definition: mpls.h:92
struct _vnet_device_class vnet_device_class_t
u32 encap_index
Definition: mpls.h:51
#define foreach_mpls_input_next
Definition: mpls.h:199
ip4_address_t dst
Definition: mpls.h:193
mpls_decap_t * decaps
Definition: mpls.h:95
ip4_address_t src
Definition: mpls.h:192
u32 outer_fib_index
Definition: mpls.h:50
mpls_gre_tunnel_t * gre_tunnels
Definition: mpls.h:83
typedef CLIB_PACKED(struct{ip4_header_t ip4;gre_header_t gre;mpls_unicast_header_t labels[0];}) ip4_gre_and_mpls_header_t
ip4_address_t intfc_address
Definition: mpls.h:59
format_function_t format_mpls_gre_header_with_length
Definition: mpls.h:112
vlib_node_registration_t mpls_policy_encap_node
(constructor) VLIB_REGISTER_NODE (mpls_policy_encap_node)
Definition: policy_encap.c:135
u32 entry_index
Definition: mpls.h:234
int mpls_fib_reset_labels(u32 fib_id)
Definition: mpls.c:703
vlib_node_registration_t mpls_input_node
(constructor) VLIB_REGISTER_NODE (mpls_input_node)
Definition: node.c:258
vnet_main_t * vnet_main
Definition: mpls.h:104
u32 tx_sw_if_index
Definition: mpls.h:60
vnet_device_class_t mpls_gre_device_class
u32 output_next_index
Definition: mpls.h:73
mpls_main_t mpls_main
Definition: mpls.h:107
u32 mask_width
Definition: mpls.h:48
u32 * free_eth_sw_if_indices
Definition: mpls.h:88
int mpls_fib_index_cmp(void *a1, void *a2)
Definition: mpls.c:590
unformat_function_t unformat_mpls_protocol_net_byte_order
Definition: mpls.h:125
u8 * rewrite
Definition: mpls.h:72
unformat_function_t unformat_mpls_header
Definition: mpls.h:131
unformat_function_t unformat_mpls_protocol_host_byte_order
Definition: mpls.h:124
u8 * rewrite_data
Definition: mpls.h:53
unformat_function_t unformat_pg_mpls_header
Definition: mpls.h:132
u8 * format_mpls_gre_header(u8 *s, va_list *args)
Definition: mpls.c:101
u32 ip4_classify_mpls_policy_encap_next_index
Definition: mpls.h:99
u8 * rewrite_data
Definition: mpls.h:65
mpls_eth_tunnel_t * eth_tunnels
Definition: mpls.h:87
u32 mpls_encap_index
Definition: mpls.h:222
u32 fib_index
Definition: mpls.h:233
unsigned int u32
Definition: types.h:88
u32 tx_fib_index
Definition: mpls.h:77
u32 ip6_classify_mpls_policy_encap_next_index
Definition: mpls.h:100
int vnet_mpls_ethernet_add_del_tunnel(u8 *dst, ip4_address_t *intfc, u32 mask_width, u32 inner_fib_id, u32 tx_sw_if_index, u32 *tunnel_sw_if_index, u8 l2_only, u8 is_add)
Definition: interface.c:1276
int vnet_mpls_gre_delete_fib_tunnels(u32 fib_id)
Definition: interface.c:964
uword * mpls_decap_by_rx_fib_and_label
Definition: mpls.h:96
u8 * format_mpls_gre_tx_trace(u8 *s, va_list *args)
Definition: mpls.c:23
u8 *( format_function_t)(u8 *s, va_list *args)
Definition: format.h:48
int vnet_mpls_add_del_decap(u32 rx_fib_id, u32 tx_fib_id, u32 label_host_byte_order, int s_bit, int next_index, int is_add)
Definition: mpls.c:369
format_function_t format_mpls_unicast_label
Definition: mpls.h:114
u64 uword
Definition: types.h:112
mpls_input_next_t
Definition: mpls.h:204
vnet_hw_interface_class_t mpls_gre_hw_interface_class
struct _vnet_hw_interface_class vnet_hw_interface_class_t
unsigned char u8
Definition: types.h:56
unformat_function_t unformat_mpls_gre_header
Definition: mpls.h:127
ip4_address_t tunnel_src
Definition: mpls.h:45
u32 inner_fib_index
Definition: mpls.h:61
int vnet_mpls_add_del_encap(ip4_address_t *dest, u32 fib_id, u32 *labels_host_byte_order, u32 policy_tunnel_index, int no_dst_hash, u32 *indexp, int is_add)
Definition: mpls.c:172
u32 encap_index
Definition: mpls.h:63
vlib_main_t * vlib_main
Definition: mpls.h:103
u32 mpls_encap_index
Definition: mpls.h:186
ip4_address_t tunnel_dst
Definition: mpls.h:46
int vnet_mpls_policy_tunnel_add_rewrite(mpls_main_t *mm, mpls_encap_t *e, u32 policy_tunnel_index)
Definition: interface.c:1607
mpls_encap_t * mpls_encap_by_fib_and_dest(mpls_main_t *mm, u32 rx_fib, u32 dst_address)
Definition: mpls.c:156
unformat_function_t unformat_mpls_label_net_byte_order
Definition: mpls.h:126
format_function_t format_mpls_encap_index
Definition: mpls.h:115
u32 tx_sw_if_index
Definition: mpls.h:219
mpls_unicast_header_t * labels
Definition: mpls.h:70
mpls_encap_t * encaps
Definition: mpls.h:91
int mpls_dest_cmp(void *a1, void *a2)
Definition: mpls.c:581