FD.io VPP  v16.06
Vector Packet Processing
vxlan.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_vxlan_h
16 #define included_vnet_vxlan_h
17 
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>
26 #include <vnet/ip/ip4_packet.h>
27 #include <vnet/ip/ip6_packet.h>
28 #include <vnet/ip/udp.h>
29 
30 typedef CLIB_PACKED (struct {
31  ip4_header_t ip4; /* 20 bytes */
32  udp_header_t udp; /* 8 bytes */
33  vxlan_header_t vxlan; /* 8 bytes */
34 }) ip4_vxlan_header_t;
35 
36 typedef CLIB_PACKED (struct {
37  ip6_header_t ip6; /* 40 bytes */
38  udp_header_t udp; /* 8 bytes */
39  vxlan_header_t vxlan; /* 8 bytes */
40 }) ip6_vxlan_header_t;
41 
42 typedef CLIB_PACKED(struct {
43  /*
44  * Key fields: ip src and vxlan vni on incoming VXLAN packet
45  * all fields in NET byte order
46  */
47  union {
48  struct {
49  u32 src;
50  u32 vni; /* shifted left 8 bits */
51  };
52  u64 as_u64;
53  };
54 }) vxlan4_tunnel_key_t;
55 
56 typedef CLIB_PACKED(struct {
57  /*
58  * Key fields: ip src and vxlan vni on incoming VXLAN packet
59  * all fields in NET byte order
60  */
61  ip6_address_t src;
62  u32 vni; /* shifted left 8 bits */
63 }) vxlan6_tunnel_key_t;
64 
65 typedef struct {
66  /* Rewrite string. $$$$ embed vnet_rewrite header */
68 
69  /* tunnel src and dst addresses */
70  ip46_address_t src;
71  ip46_address_t dst;
72 
73  /* vxlan VNI in HOST byte order */
75 
76  /* decap next index */
78 
79  /* L3 FIB index and L2 BD ID */
80  u16 encap_fib_index; /* tunnel partner IP lookup here */
81 
82  /* vnet intfc hw/sw_if_index */
85 
86  union { /* storage for the hash key */
87  vxlan4_tunnel_key_t *key4;
88  vxlan6_tunnel_key_t *key6;
89  };
90 
91  /* flags */
94 
95 /* Flags for vxlan_tunnel_t.flags */
96 #define VXLAN_TUNNEL_IS_IPV4 1
97 
98 #define foreach_vxlan_input_next \
99 _(DROP, "error-drop") \
100 _(L2_INPUT, "l2-input") \
101 _(IP4_INPUT, "ip4-input") \
102 _(IP6_INPUT, "ip6-input")
103 
104 typedef enum {
105 #define _(s,n) VXLAN_INPUT_NEXT_##s,
107 #undef _
110 
111 typedef enum {
112 #define vxlan_error(n,s) VXLAN_ERROR_##n,
114 #undef vxlan_error
117 
118 typedef struct {
119  /* vector of encap tunnel instances */
121 
122  /* lookup tunnel by key */
123  uword * vxlan4_tunnel_by_key; /* keyed on ipv4.dst + vni */
124  uword * vxlan6_tunnel_by_key; /* keyed on ipv6.dst + vni */
125 
126  /* Free vlib hw_if_indices */
128 
129  /* Dummy rewrite for deleted vxlan_tunnels with hw_if_indices as above */
130  u64 dummy4_str [sizeof(ip4_vxlan_header_t)/sizeof(u64) + 2];
131 #define vxlan4_dummy_rewrite ((u8 *) &vxlan_main.dummy4_str[1])
132 
133  u64 dummy6_str [sizeof(ip6_vxlan_header_t)/sizeof(u64) + 2];
134 #define vxlan6_dummy_rewrite ((u8 *) &vxlan_main.dummy6_str[1])
135 
136  /* Mapping from sw_if_index to tunnel index */
138 
139  /* convenience */
142 } vxlan_main_t;
143 
145 
149 
150 u8 * format_vxlan_encap_trace (u8 * s, va_list * args);
151 
152 typedef struct {
154 
155  /* we normally use is_ip4, but since this adds to the
156  * structure, this seems less of abreaking change */
158  ip46_address_t src, dst;
163 
165 (vnet_vxlan_add_del_tunnel_args_t *a, u32 * sw_if_indexp);
166 
167 #endif /* included_vnet_vxlan_h */
int vnet_vxlan_add_del_tunnel(vnet_vxlan_add_del_tunnel_args_t *a, u32 *sw_if_indexp)
Definition: vxlan.c:196
a
Definition: bitmap.h:393
#define foreach_vxlan_input_next
Definition: vxlan.h:98
ip46_address_t dst
Definition: vxlan.h:71
struct _vlib_node_registration vlib_node_registration_t
vlib_node_registration_t vxlan_encap_node
(constructor) VLIB_REGISTER_NODE (vxlan_encap_node)
Definition: encap.c:571
vlib_node_registration_t vxlan4_input_node
(constructor) VLIB_REGISTER_NODE (vxlan4_input_node)
Definition: decap.c:532
vxlan6_tunnel_key_t * key6
Definition: vxlan.h:88
u8 * format_vxlan_encap_trace(u8 *s, va_list *args)
Definition: encap.c:52
vnet_main_t * vnet_main
Definition: vxlan.h:141
vlib_main_t * vlib_main
Definition: vxlan.h:140
unsigned long u64
Definition: types.h:89
u8 * rewrite
Definition: vxlan.h:67
vlib_node_registration_t vxlan6_input_node
(constructor) VLIB_REGISTER_NODE (vxlan6_input_node)
Definition: decap.c:553
uword * vxlan4_tunnel_by_key
Definition: vxlan.h:123
u16 encap_fib_index
Definition: vxlan.h:80
u32 decap_next_index
Definition: vxlan.h:77
vxlan_input_next_t
Definition: vxlan.h:104
unsigned int u32
Definition: types.h:88
uword * vxlan6_tunnel_by_key
Definition: vxlan.h:124
u32 sw_if_index
Definition: vxlan.h:84
u64 uword
Definition: types.h:112
unsigned short u16
Definition: types.h:57
unsigned char u8
Definition: types.h:56
u16 hw_if_index
Definition: vxlan.h:83
u32 flags
Definition: vxlan.h:92
u32 * tunnel_index_by_sw_if_index
Definition: vxlan.h:137
typedef CLIB_PACKED(struct{ip4_header_t ip4;udp_header_t udp;vxlan_header_t vxlan;}) ip4_vxlan_header_t
vxlan4_tunnel_key_t * key4
Definition: vxlan.h:87
vxlan_input_error_t
Definition: vxlan.h:111
vxlan_tunnel_t * tunnels
Definition: vxlan.h:120
u32 * free_vxlan_tunnel_hw_if_indices
Definition: vxlan.h:127
ip46_address_t src
Definition: vxlan.h:70
vxlan_main_t vxlan_main
Definition: vxlan.h:144