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-gre/packet.h>
21 #include <vnet/ip/ip4_packet.h>
22 #include <vnet/ethernet/ethernet.h>
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;
30 extern vnet_hw_interface_class_t mpls_gre_hw_interface_class;
33 #define mpls_error(n,s) MPLS_ERROR_##n,
34 #include <vnet/mpls-gre/error.def>
40 * No protocol info, MPLS labels don't have a next-header field
41 * presumably the label field tells all...
45 ip4_address_t tunnel_src;
46 ip4_address_t tunnel_dst;
47 ip4_address_t intfc_address;
52 u32 hw_if_index; /* L2 x-connect capable tunnel intfc */
59 ip4_address_t intfc_address;
70 mpls_unicast_header_t *labels;
71 /* only for policy tunnels */
73 u32 output_next_index;
78 u32 next_index; /* e.g. ip4/6-input, l2-input */
82 /* pool of gre tunnel instances */
83 mpls_gre_tunnel_t *gre_tunnels;
84 u32 * free_gre_sw_if_indices;
86 /* pool of ethernet tunnel instances */
87 mpls_eth_tunnel_t *eth_tunnels;
88 u32 * free_eth_sw_if_indices;
90 /* Encap side: map (fib, dst_address) to mpls label stack */
91 mpls_encap_t * encaps;
92 uword * mpls_encap_by_fib_and_dest;
94 /* Decap side: map rx label to FIB */
95 mpls_decap_t * decaps;
96 uword * mpls_decap_by_rx_fib_and_label;
98 /* mpls-o-e policy tunnel next index for ip4-classify */
99 u32 ip_classify_mpls_policy_encap_next_index;
102 vlib_main_t * vlib_main;
103 vnet_main_t * vnet_main;
106 mpls_main_t mpls_main;
108 format_function_t format_mpls_protocol;
109 format_function_t format_mpls_header;
110 format_function_t format_mpls_header_with_length;
111 format_function_t format_mpls_gre_header_with_length;
112 format_function_t format_mpls_eth_header_with_length;
113 format_function_t format_mpls_unicast_label;
114 format_function_t format_mpls_encap_index;
116 extern vlib_node_registration_t mpls_input_node;
117 extern vlib_node_registration_t mpls_policy_encap_node;
119 extern vnet_device_class_t mpls_gre_device_class;
121 /* Parse mpls protocol as 0xXXXX or protocol name.
122 In either host or network byte order. */
123 unformat_function_t unformat_mpls_protocol_host_byte_order;
124 unformat_function_t unformat_mpls_protocol_net_byte_order;
125 unformat_function_t unformat_mpls_label_net_byte_order;
126 unformat_function_t unformat_mpls_gre_header;
127 unformat_function_t unformat_pg_mpls_gre_header;
129 /* Parse mpls header. */
130 unformat_function_t unformat_mpls_header;
131 unformat_function_t unformat_pg_mpls_header;
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
138 mpls_encap_by_fib_and_dest (mpls_main_t * mm, u32 rx_fib, u32 dst_address);
140 int mpls_label_from_fib_id_and_dest (mpls_main_t *gm, u32 fib_id,
141 u32 dst_address, u32 *labelp);
143 int vnet_mpls_gre_add_del_tunnel (ip4_address_t *src,
145 ip4_address_t *intfc,
147 u32 inner_fib_id, u32 outer_fib_id,
148 u32 * tunnel_intfc_sw_if_index,
152 int vnet_mpls_ethernet_add_del_tunnel (u8 *dst,
153 ip4_address_t *intfc,
157 u32 * tunnel_sw_if_index,
161 int vnet_mpls_gre_delete_fib_tunnels (u32 fib_id);
163 int mpls_fib_reset_labels (u32 fib_id);
165 int vnet_mpls_add_del_decap (u32 rx_fib_id,
167 u32 label_host_byte_order,
168 int s_bit, int next_index, int is_add);
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);
175 int vnet_mpls_policy_tunnel_add_rewrite (mpls_main_t * mm,
177 u32 policy_tunnel_index);
181 /* Tunnel-id / index in tunnel vector */
184 /* mpls encap index */
185 u32 mpls_encap_index;
190 /* tunnel ip4 addresses */
193 } mpls_gre_tx_trace_t;
195 u8 * format_mpls_gre_tx_trace (u8 * s, va_list * args);
196 u8 * format_mpls_gre_header (u8 * s, va_list * args);
198 #define foreach_mpls_input_next \
199 _(DROP, "error-drop") \
200 _(IP4_INPUT, "ip4-input") \
201 _(L2_OUTPUT, "l2-output")
204 #define _(s,n) MPLS_INPUT_NEXT_##s,
205 foreach_mpls_input_next
214 /* Tunnel-id / index in tunnel vector */
217 /* output interface */
220 /* mpls encap index */
221 u32 mpls_encap_index;
227 } mpls_eth_tx_trace_t;
229 u8 * format_mpls_eth_tx_trace (u8 * s, va_list * args);
231 #endif /* included_vnet_mpls_gre_h */