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_bd.h>
24 #include <vnet/ethernet/ethernet.h>
25 #include <vnet/vxlan/vxlan_packet.h>
26 #include <vnet/ip/ip4_packet.h>
27 #include <vnet/ip/udp.h>
29 typedef CLIB_PACKED (struct {
30 ip4_header_t ip4; /* 20 bytes */
31 udp_header_t udp; /* 8 bytes */
32 vxlan_header_t vxlan; /* 8 bytes */
33 }) ip4_vxlan_header_t;
35 typedef CLIB_PACKED(struct {
37 * Key fields: ip src and vxlan vni on incoming VXLAN packet
38 * all fields in NET byte order
43 u32 vni; /* shifted left 8 bits */
47 }) vxlan_tunnel_key_t;
50 /* Rewrite string. $$$$ embed vnet_rewrite header */
53 /* decap next index */
56 /* tunnel src and dst addresses */
60 /* vxlan VNI in HOST byte order */
63 /* L3 FIB index and L2 BD ID */
64 u16 encap_fib_index; /* tunnel partner IP lookup here */
66 /* vnet intfc hw/sw_if_index */
71 #define foreach_vxlan_input_next \
72 _(DROP, "error-drop") \
73 _(L2_INPUT, "l2-input") \
74 _(IP4_INPUT, "ip4-input") \
75 _(IP6_INPUT, "ip6-input")
78 #define _(s,n) VXLAN_INPUT_NEXT_##s,
79 foreach_vxlan_input_next
85 #define vxlan_error(n,s) VXLAN_ERROR_##n,
86 #include <vnet/vxlan/vxlan_error.def>
89 } vxlan_input_error_t;
92 /* vector of encap tunnel instances */
93 vxlan_tunnel_t *tunnels;
95 /* lookup tunnel by key */
96 uword * vxlan_tunnel_by_key;
98 /* Free vlib hw_if_indices */
99 u32 * free_vxlan_tunnel_hw_if_indices;
101 /* Dummy rewrite for deleted vxlan_tunnels with hw_if_indices as above */
102 u64 dummy_str [sizeof(ip4_vxlan_header_t)/sizeof(u64) + 2];
103 #define vxlan_dummy_rewrite ((u8 *) &vxlan_main.dummy_str[1])
105 /* Mapping from sw_if_index to tunnel index */
106 u32 * tunnel_index_by_sw_if_index;
109 vlib_main_t * vlib_main;
110 vnet_main_t * vnet_main;
113 vxlan_main_t vxlan_main;
115 extern vlib_node_registration_t vxlan_input_node;
116 extern vlib_node_registration_t vxlan_encap_node;
118 u8 * format_vxlan_encap_trace (u8 * s, va_list * args);
122 ip4_address_t src, dst;
124 u32 decap_next_index;
126 } vnet_vxlan_add_del_tunnel_args_t;
128 int vnet_vxlan_add_del_tunnel
129 (vnet_vxlan_add_del_tunnel_args_t *a, u32 * sw_if_indexp);
131 #endif /* included_vnet_vxlan_h */