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_vxlan_h
16 #define included_vnet_vxlan_h
18 #include <vppinfra/error.h>
19 #include <vppinfra/hash.h>
20 #include <vnet/vnet.h>
21 #include <vnet/ip/ip.h>
22 #include <vnet/l2/l2_input.h>
23 #include <vnet/l2/l2_output.h>
24 #include <vnet/l2/l2_bd.h>
25 #include <vnet/ethernet/ethernet.h>
26 #include <vnet/vxlan/vxlan_packet.h>
27 #include <vnet/ip/ip4_packet.h>
28 #include <vnet/ip/ip6_packet.h>
29 #include <vnet/ip/udp.h>
31 typedef CLIB_PACKED (struct {
32 ip4_header_t ip4; /* 20 bytes */
33 udp_header_t udp; /* 8 bytes */
34 vxlan_header_t vxlan; /* 8 bytes */
35 }) ip4_vxlan_header_t;
37 typedef CLIB_PACKED (struct {
38 ip6_header_t ip6; /* 40 bytes */
39 udp_header_t udp; /* 8 bytes */
40 vxlan_header_t vxlan; /* 8 bytes */
41 }) ip6_vxlan_header_t;
43 typedef CLIB_PACKED(struct {
45 * Key fields: ip src and vxlan vni on incoming VXLAN packet
46 * all fields in NET byte order
51 u32 vni; /* shifted left 8 bits */
55 }) vxlan4_tunnel_key_t;
57 typedef CLIB_PACKED(struct {
59 * Key fields: ip src and vxlan vni on incoming VXLAN packet
60 * all fields in NET byte order
63 u32 vni; /* shifted left 8 bits */
64 }) vxlan6_tunnel_key_t;
67 /* Rewrite string. $$$$ embed vnet_rewrite header */
70 /* tunnel src and dst addresses */
74 /* vxlan VNI in HOST byte order */
77 /* decap next index */
80 /* L3 FIB index and L2 BD ID */
81 u16 encap_fib_index; /* tunnel partner IP lookup here */
83 /* vnet intfc hw/sw_if_index */
87 union { /* storage for the hash key */
88 vxlan4_tunnel_key_t *key4;
89 vxlan6_tunnel_key_t *key6;
96 /* Flags for vxlan_tunnel_t.flags */
97 #define VXLAN_TUNNEL_IS_IPV4 1
99 #define foreach_vxlan_input_next \
100 _(DROP, "error-drop") \
101 _(L2_INPUT, "l2-input") \
102 _(IP4_INPUT, "ip4-input") \
103 _(IP6_INPUT, "ip6-input")
106 #define _(s,n) VXLAN_INPUT_NEXT_##s,
107 foreach_vxlan_input_next
110 } vxlan_input_next_t;
113 #define vxlan_error(n,s) VXLAN_ERROR_##n,
114 #include <vnet/vxlan/vxlan_error.def>
117 } vxlan_input_error_t;
120 /* vector of encap tunnel instances */
121 vxlan_tunnel_t *tunnels;
123 /* lookup tunnel by key */
124 uword * vxlan4_tunnel_by_key; /* keyed on ipv4.dst + vni */
125 uword * vxlan6_tunnel_by_key; /* keyed on ipv6.dst + vni */
127 /* Free vlib hw_if_indices */
128 u32 * free_vxlan_tunnel_hw_if_indices;
130 /* Mapping from sw_if_index to tunnel index */
131 u32 * tunnel_index_by_sw_if_index;
134 vlib_main_t * vlib_main;
135 vnet_main_t * vnet_main;
138 vxlan_main_t vxlan_main;
140 extern vlib_node_registration_t vxlan4_input_node;
141 extern vlib_node_registration_t vxlan6_input_node;
142 extern vlib_node_registration_t vxlan_encap_node;
144 u8 * format_vxlan_encap_trace (u8 * s, va_list * args);
149 /* we normally use is_ip4, but since this adds to the
150 * structure, this seems less of abreaking change */
152 ip46_address_t src, dst;
154 u32 decap_next_index;
156 } vnet_vxlan_add_del_tunnel_args_t;
158 int vnet_vxlan_add_del_tunnel
159 (vnet_vxlan_add_del_tunnel_args_t *a, u32 * sw_if_indexp);
161 #endif /* included_vnet_vxlan_h */