FD.io VPP  v16.06
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
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-classify */
100 
101  /* convenience */
104 } mpls_main_t;
105 
107 
115 
118 
120 
121 /* Parse mpls protocol as 0xXXXX or protocol name.
122  In either host or network byte order. */
128 
129 /* Parse mpls header. */
132 
133 /* manually added to the interface output node in mpls.c */
134 #define MPLS_GRE_OUTPUT_NEXT_LOOKUP 1
135 #define MPLS_GRE_OUTPUT_NEXT_DROP VNET_INTERFACE_TX_NEXT_DROP
136 
137 mpls_encap_t *
138 mpls_encap_by_fib_and_dest (mpls_main_t * mm, u32 rx_fib, u32 dst_address);
139 
141  u32 dst_address, u32 *labelp);
142 
144  ip4_address_t *dst,
145  ip4_address_t *intfc,
146  u32 mask_width,
147  u32 inner_fib_id, u32 outer_fib_id,
148  u32 * tunnel_intfc_sw_if_index,
149  u8 l2_only,
150  u8 is_add);
151 
153  ip4_address_t *intfc,
154  u32 mask_width,
155  u32 inner_fib_id,
156  u32 tx_sw_if_index,
157  u32 * tunnel_sw_if_index,
158  u8 l2_only,
159  u8 is_add);
160 
162 
163 int mpls_fib_reset_labels (u32 fib_id);
164 
165 int vnet_mpls_add_del_decap (u32 rx_fib_id,
166  u32 tx_fib_id,
167  u32 label_host_byte_order,
168  int s_bit, int next_index, int is_add);
169 
170 int vnet_mpls_add_del_encap (ip4_address_t *dest, u32 fib_id,
171  u32 *labels_host_byte_order,
172  u32 policy_tunnel_index,
173  int no_dst_hash, u32 * indexp, int is_add);
174 
176  mpls_encap_t * e,
177  u32 policy_tunnel_index);
178 typedef struct {
180 
181  /* Tunnel-id / index in tunnel vector */
183 
184  /* mpls encap index */
186 
187  /* pkt length */
189 
190  /* tunnel ip4 addresses */
194 
195 u8 * format_mpls_gre_tx_trace (u8 * s, va_list * args);
196 u8 * format_mpls_gre_header (u8 * s, va_list * args);
197 
198 #define foreach_mpls_input_next \
199 _(DROP, "error-drop") \
200 _(IP4_INPUT, "ip4-input") \
201 _(L2_OUTPUT, "l2-output")
202 
203 typedef enum {
204 #define _(s,n) MPLS_INPUT_NEXT_##s,
206 #undef _
209 
210 
211 typedef struct {
213 
214  /* Tunnel-id / index in tunnel vector */
216 
217  /* output interface */
219 
220  /* mpls encap index */
222 
223  /* pkt length */
225 
226  u8 dst[6];
228 
229 u8 * format_mpls_eth_tx_trace (u8 * s, va_list * args);
230 
231 #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:110
uword( unformat_function_t)(unformat_input_t *input, va_list *args)
Definition: format.h:229
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:109
u32 mask_width
Definition: mpls.h:62
format_function_t format_mpls_eth_header_with_length
Definition: mpls.h:112
ip4_address_t intfc_address
Definition: mpls.h:47
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:108
struct _vlib_node_registration vlib_node_registration_t
u32 ip_classify_mpls_policy_encap_next_index
Definition: mpls.h:99
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:721
unformat_function_t unformat_pg_mpls_gre_header
Definition: mpls.h:127
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:198
ip4_address_t dst
Definition: mpls.h:192
mpls_decap_t * decaps
Definition: mpls.h:95
ip4_address_t src
Definition: mpls.h:191
u32 outer_fib_index
Definition: mpls.h:50
mpls_gre_tunnel_t * gre_tunnels
Definition: mpls.h:83
u32 hw_if_index
Definition: mpls.h:52
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:111
vlib_node_registration_t mpls_policy_encap_node
(constructor) VLIB_REGISTER_NODE (mpls_policy_encap_node)
Definition: policy_encap.c:135
int mpls_fib_reset_labels(u32 fib_id)
Definition: mpls.c:711
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:103
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:106
u32 mask_width
Definition: mpls.h:48
u32 * free_eth_sw_if_indices
Definition: mpls.h:88
unformat_function_t unformat_mpls_protocol_net_byte_order
Definition: mpls.h:124
u8 * rewrite
Definition: mpls.h:72
unformat_function_t unformat_mpls_header
Definition: mpls.h:130
unformat_function_t unformat_mpls_protocol_host_byte_order
Definition: mpls.h:123
u8 * rewrite_data
Definition: mpls.h:53
unformat_function_t unformat_pg_mpls_header
Definition: mpls.h:131
u8 * format_mpls_gre_header(u8 *s, va_list *args)
Definition: mpls.c:101
u8 * rewrite_data
Definition: mpls.h:65
mpls_eth_tunnel_t * eth_tunnels
Definition: mpls.h:87
u32 mpls_encap_index
Definition: mpls.h:221
unsigned int u32
Definition: types.h:88
u32 tx_fib_index
Definition: mpls.h:77
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:1267
int vnet_mpls_gre_delete_fib_tunnels(u32 fib_id)
Definition: interface.c:957
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:113
u64 uword
Definition: types.h:112
mpls_input_next_t
Definition: mpls.h:203
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:126
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:102
u32 mpls_encap_index
Definition: mpls.h:185
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:1592
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:125
format_function_t format_mpls_encap_index
Definition: mpls.h:114
u32 tx_sw_if_index
Definition: mpls.h:218
mpls_unicast_header_t * labels
Definition: mpls.h:70
mpls_encap_t * encaps
Definition: mpls.h:91