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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
15 #ifndef included_vnet_mpls_gre_h
16 #define included_vnet_mpls_gre_h
18 #include <vnet/vnet.h>
19 #include <vnet/gre/gre.h>
20 #include <vnet/mpls/packet.h>
21 #include <vnet/mpls/mpls_types.h>
22 #include <vnet/ip/ip4_packet.h>
23 #include <vnet/ethernet/ethernet.h>
24 #include <vnet/fib/fib_node.h>
25 #include <vnet/adj/adj.h>
27 typedef CLIB_PACKED (struct {
28 ip4_header_t ip4; /* 20 bytes */
29 gre_header_t gre; /* 4 bytes */
30 mpls_unicast_header_t labels[0]; /* 4 bytes each */
31 }) ip4_gre_and_mpls_header_t;
33 extern vnet_hw_interface_class_t mpls_gre_hw_interface_class;
36 #define mpls_error(n,s) MPLS_ERROR_##n,
37 #include <vnet/mpls/error.def>
43 * No protocol info, MPLS labels don't have a next-header field
44 * presumably the label field tells all...
49 ip4_address_t tunnel_src;
50 ip4_address_t tunnel_dst;
51 ip4_address_t intfc_address;
56 u32 hw_if_index; /* L2 x-connect capable tunnel intfc */
59 fib_node_index_t fei; /* FIB Entry index for the tunnel's destination */
60 adj_index_t adj_index; /* The midchain adj this tunnel creates */
66 ip4_address_t intfc_address;
78 mpls_unicast_header_t *labels;
79 /* only for policy tunnels */
81 u32 output_next_index;
86 u32 next_index; /* e.g. ip4/6-input, l2-input */
89 #define MPLS_FIB_DEFAULT_TABLE_ID 0
92 * Type exposure is to allow the DP fast/inlined access
94 #define MPLS_FIB_KEY_SIZE 21
95 #define MPLS_FIB_DB_SIZE (1 << (MPLS_FIB_KEY_SIZE-1))
97 typedef struct mpls_fib_t_
100 * A hash table of entries. 21 bit key
101 * Hash table for reduced memory footprint
106 * The load-balance indeices keyed by 21 bit label+eos bit.
107 * A flat array for maximum lookup performace.
109 index_t mf_lbs[MPLS_FIB_DB_SIZE];
113 * @brief Definition of a callback for receiving MPLS interface state change
116 typedef void (*mpls_interface_state_change_callback_t)(u32 sw_if_index,
120 /* MPLS FIB index for each software interface */
121 u32 *fib_index_by_sw_if_index;
123 /** A pool of all the MPLS FIBs */
124 struct fib_table_t_ *fibs;
126 /** A hash table to lookup the mpls_fib by table ID */
127 uword *fib_index_by_table_id;
129 /* rx/tx interface/feature configuration. */
130 ip_config_main_t feature_config_mains[VNET_N_IP_FEAT];
132 /* Built-in unicast feature path indices, see vnet_feature_arc_init(...) */
133 u32 mpls_rx_feature_lookup;
134 u32 mpls_rx_feature_not_enabled;
135 u32 mpls_tx_feature_interface_output;
137 /* pool of gre tunnel instances */
138 mpls_gre_tunnel_t *gre_tunnels;
139 u32 * free_gre_sw_if_indices;
141 /* pool of ethernet tunnel instances */
142 mpls_eth_tunnel_t *eth_tunnels;
143 u32 * free_eth_sw_if_indices;
145 /* Encap side: map (fib, dst_address) to mpls label stack */
146 mpls_encap_t * encaps;
147 uword * mpls_encap_by_fib_and_dest;
149 /* Decap side: map rx label to FIB */
150 mpls_decap_t * decaps;
151 uword * mpls_decap_by_rx_fib_and_label;
153 /* mpls-o-e policy tunnel next index for ip4/ip6-classify */
154 u32 ip4_classify_mpls_policy_encap_next_index;
155 u32 ip6_classify_mpls_policy_encap_next_index;
157 /* feature path configuration lists */
158 vnet_feature_registration_t * next_feature[VNET_N_IP_FEAT];
160 /* Save feature results for show command */
161 char **feature_nodes[VNET_N_IP_FEAT];
163 /* IP4 enabled count by software interface */
164 u8 * mpls_enabled_by_sw_if_index;
167 vlib_main_t * vlib_main;
168 vnet_main_t * vnet_main;
171 extern mpls_main_t mpls_main;
173 #define VNET_MPLS_FEATURE_INIT(x,...) \
174 __VA_ARGS__ vnet_feature_registration_t uc_##x; \
175 static void __vnet_add_feature_registration_uc_##x (void) \
176 __attribute__((__constructor__)) ; \
177 static void __vnet_add_feature_registration_uc_##x (void) \
179 mpls_main_t * mm = &mpls_main; \
180 uc_##x.next = mm->next_feature[VNET_IP_RX_UNICAST_FEAT]; \
181 mm->next_feature[VNET_IP_RX_UNICAST_FEAT] = &uc_##x; \
183 __VA_ARGS__ vnet_feature_registration_t uc_##x
185 #define VNET_MPLS_TX_FEATURE_INIT(x,...) \
186 __VA_ARGS__ vnet_feature_registration_t tx_##x; \
187 static void __vnet_add_feature_registration_tx_##x (void) \
188 __attribute__((__constructor__)) ; \
189 static void __vnet_add_feature_registration_tx_##x (void) \
191 mpls_main_t * mm = &mpls_main; \
192 tx_##x.next = mm->next_feature[VNET_IP_TX_FEAT]; \
193 mm->next_feature[VNET_IP_TX_FEAT] = &tx_##x; \
195 __VA_ARGS__ vnet_feature_registration_t tx_##x
197 extern clib_error_t * mpls_feature_init(vlib_main_t * vm);
199 format_function_t format_mpls_protocol;
200 format_function_t format_mpls_gre_header_with_length;
201 format_function_t format_mpls_eth_header_with_length;
202 format_function_t format_mpls_encap_index;
204 format_function_t format_mpls_eos_bit;
205 format_function_t format_mpls_unicast_header_net_byte_order;
206 format_function_t format_mpls_unicast_label;
207 format_function_t format_mpls_header;
209 extern vlib_node_registration_t mpls_input_node;
210 extern vlib_node_registration_t mpls_policy_encap_node;
211 extern vlib_node_registration_t mpls_output_node;
212 extern vlib_node_registration_t mpls_midchain_node;
214 extern vnet_device_class_t mpls_gre_device_class;
216 /* Parse mpls protocol as 0xXXXX or protocol name.
217 In either host or network byte order. */
218 unformat_function_t unformat_mpls_protocol_host_byte_order;
219 unformat_function_t unformat_mpls_protocol_net_byte_order;
220 unformat_function_t unformat_mpls_label_net_byte_order;
221 unformat_function_t unformat_mpls_gre_header;
222 unformat_function_t unformat_pg_mpls_gre_header;
223 unformat_function_t unformat_mpls_unicast_label;
225 /* Parse mpls header. */
226 unformat_function_t unformat_mpls_header;
227 unformat_function_t unformat_pg_mpls_header;
229 /* manually added to the interface output node in mpls.c */
230 #define MPLS_GRE_OUTPUT_NEXT_LOOKUP 1
231 #define MPLS_GRE_OUTPUT_NEXT_DROP VNET_INTERFACE_TX_NEXT_DROP
233 void mpls_sw_interface_enable_disable (mpls_main_t * mm,
237 u8 mpls_sw_interface_is_enabled (u32 sw_if_index);
240 mpls_encap_by_fib_and_dest (mpls_main_t * mm, u32 rx_fib, u32 dst_address);
242 int mpls_label_from_fib_id_and_dest (mpls_main_t *gm, u32 fib_id,
243 u32 dst_address, u32 *labelp);
245 int vnet_mpls_gre_add_del_tunnel (ip4_address_t *src,
247 ip4_address_t *intfc,
249 u32 inner_fib_id, u32 outer_fib_id,
250 u32 * tunnel_intfc_sw_if_index,
254 int vnet_mpls_ethernet_add_del_tunnel (u8 *dst,
255 ip4_address_t *intfc,
259 u32 * tunnel_sw_if_index,
263 int vnet_mpls_gre_delete_fib_tunnels (u32 fib_id);
265 int mpls_fib_reset_labels (u32 fib_id);
267 int vnet_mpls_add_del_decap (u32 rx_fib_id,
269 u32 label_host_byte_order,
270 int s_bit, int next_index, int is_add);
272 int vnet_mpls_add_del_encap (ip4_address_t *dest, u32 fib_id,
273 u32 *labels_host_byte_order,
274 u32 policy_tunnel_index,
275 int no_dst_hash, u32 * indexp, int is_add);
277 int vnet_mpls_policy_tunnel_add_rewrite (mpls_main_t * mm,
279 u32 policy_tunnel_index);
284 /* Tunnel-id / index in tunnel vector */
287 /* mpls encap index */
288 u32 mpls_encap_index;
293 /* tunnel ip4 addresses */
296 } mpls_gre_tx_trace_t;
298 u8 * format_mpls_gre_tx_trace (u8 * s, va_list * args);
299 u8 * format_mpls_gre_header (u8 * s, va_list * args);
301 #define foreach_mpls_input_next \
302 _(DROP, "error-drop") \
303 _(LOOKUP, "mpls-lookup")
306 #define _(s,n) MPLS_INPUT_NEXT_##s,
307 foreach_mpls_input_next
312 #define foreach_mpls_lookup_next \
313 _(DROP, "error-drop") \
314 _(IP4_INPUT, "ip4-input") \
315 _(L2_OUTPUT, "l2-output")
319 #define _(s,n) MPLS_LOOKUP_NEXT_##s,
320 foreach_mpls_lookup_next
323 } mpls_lookup_next_t;
325 #define foreach_mpls_output_next \
326 _(DROP, "error-drop")
329 #define _(s,n) MPLS_OUTPUT_NEXT_##s,
330 foreach_mpls_output_next
333 } mpls_output_next_t;
338 /* Tunnel-id / index in tunnel vector */
341 /* output interface */
344 /* mpls encap index */
345 u32 mpls_encap_index;
351 } mpls_eth_tx_trace_t;
353 u8 * format_mpls_eth_tx_trace (u8 * s, va_list * args);
364 mpls_dest_cmp(void * a1, void * a2);
367 mpls_fib_index_cmp(void * a1, void * a2);
370 mpls_label_cmp(void * a1, void * a2);
372 #endif /* included_vnet_mpls_gre_h */