aboutsummaryrefslogtreecommitdiffstats
path: root/vnet/vnet/lisp-gpe/lisp_gpe.h
blob: 1452b7984feadbed1e074162bb16c21df987d4e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
 * Copyright (c) 2016 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef included_vnet_lisp_gpe_h
#define included_vnet_lisp_gpe_h

#include <vppinfra/error.h>
#include <vppinfra/mhash.h>
#include <vnet/vnet.h>
#include <vnet/ip/ip.h>
#include <vnet/l2/l2_input.h>
#include <vnet/ethernet/ethernet.h>
#include <vnet/ip/ip4_packet.h>
#include <vnet/ip/udp.h>
#include <vnet/lisp-cp/lisp_types.h>
#include <vnet/lisp-gpe/lisp_gpe_packet.h>

#define IP_UDP_HDR_LEN (word) (sizeof(udp_header_t) + sizeof(ip4_header_t))

typedef CLIB_PACKED (struct {
  ip4_header_t ip4;             /* 20 bytes */
  udp_header_t udp;             /* 8 bytes */
  lisp_gpe_header_t lisp;       /* 8 bytes */
}) ip4_udp_lisp_gpe_header_t;

typedef struct
{
  union
  {
    struct
      {
	gid_address_t eid;
	u32 dst_loc;
	u32 iid;
      };
    u8 as_u8[6];
  };
} lisp_gpe_tunnel_key_t;

typedef struct
{
  /* Rewrite string. $$$$ embed vnet_rewrite header */
  u8 * rewrite;

  /* decap next index */
  u32 decap_next_index;

  /* tunnel src and dst addresses */
  ip4_address_t src;
  ip4_address_t dst;

  /* FIB indices */
  u32 encap_fib_index;          /* tunnel partner lookup here */
  u32 decap_fib_index;          /* inner IP lookup here */

  /* vnet intfc hw/sw_if_index */
  u32 hw_if_index;
  u32 sw_if_index;

  /* LISP header fields in HOST byte order */
  u8 flags;
  u8 ver_res;
  u8 res;
  u8 next_protocol;
  u32 vni;
} lisp_gpe_tunnel_t;

#define foreach_lisp_gpe_input_next             \
_(DROP, "error-drop")                           \
_(IP4_INPUT, "ip4-input")                       \
_(IP6_INPUT, "ip6-input")                       \
_(ETHERNET_INPUT, "ethernet-input")

typedef enum {
#define _(s,n) LISP_GPE_INPUT_NEXT_##s,
  foreach_lisp_gpe_input_next
#undef _
  LISP_GPE_INPUT_N_NEXT,
} lisp_gpe_input_next_t;

typedef enum {
#define lisp_gpe_error(n,s) LISP_GPE_ERROR_##n,
#include <vnet/lisp-gpe/lisp_gpe_error.def>
#undef lisp_gpe_error
  LISP_GPE_N_ERROR,
} lisp_gpe_error_t;

/* As a first step, reuse v4 fib. The goal of the typedef is to shield
 * consumers from future updates that may result in the lisp ip4 fib diverging
 * from ip4 fib */
typedef ip4_fib_t lisp_ip4_fib_t;

typedef struct lisp_gpe_main
{
  /* Pool of src fibs that are paired with dst fibs */
  ip4_fib_t * src_fibs;

  /* vector of encap tunnel instances */
  lisp_gpe_tunnel_t * tunnels;

  /* lookup tunnel by key */
  mhash_t lisp_gpe_tunnel_by_key;

  /* lookup decap tunnel termination sw_if_index by vni and vice versa */
  uword * tunnel_term_sw_if_index_by_vni;
  uword * vni_by_tunnel_term_sw_if_index;

  /* Free vlib hw_if_indices */
  u32 * free_lisp_gpe_tunnel_hw_if_indices;

  /* Lookup lisp-gpe interfaces by vrf */
  uword * lisp_gpe_hw_if_index_by_table_id;

  /* Lookup lgpe_ip4_lookup_next by vrf */
  uword * lgpe_ip4_lookup_next_index_by_table_id;

  /* next node indexes that points ip4 lookup to lisp gpe lookup and lisp cp */
  u32 ip4_lookup_next_lgpe_ip4_lookup;

  /* convenience */
  vlib_main_t * vlib_main;
  vnet_main_t * vnet_main;
  ip_lookup_main_t * lookup_main;
  ip4_main_t * im4;
} lisp_gpe_main_t;

lisp_gpe_main_t lisp_gpe_main;

extern vlib_node_registration_t lgpe_ip4_lookup_node;
extern vlib_node_registration_t lisp_gpe_input_node;

u8 *
format_lisp_gpe_tx_trace (u8 * s, va_list * args);
u8 *
format_lisp_gpe_header_with_length (u8 * s, va_list * args);

typedef struct
{
  u8 is_add;
  ip4_address_t src, dst;
  u32 encap_fib_index;
  u32 decap_fib_index;
  u32 decap_next_index;
  u8 flags;
  u8 ver_res;
  u8 res;
  u8 next_protocol;
  u32 vni; /* host byte order */
} vnet_lisp_gpe_add_del_tunnel_args_t;

int
vnet_lisp_gpe_add_del_tunnel (vnet_lisp_gpe_add_del_tunnel_args_t *a,
			      u32 * sw_if_indexp);

typedef struct
{
  u8 is_add;
  u32 table_id; /* vrf */
  u32 vni;      /* host byte order */
} vnet_lisp_gpe_add_del_iface_args_t;

void
vnet_lisp_gpe_add_del_iface (vnet_lisp_gpe_add_del_iface_args_t *a,
			     u32 * hw_if_indexp);

typedef struct
{
  u8 is_en;
} vnet_lisp_gpe_enable_disable_args_t;

clib_error_t *
vnet_lisp_gpe_enable_disable (vnet_lisp_gpe_enable_disable_args_t *a);

typedef enum
{
  NO_ACTION,
  FORWARD_NATIVE,
  SEND_MAP_REQUEST,
  DROP
} negative_fwd_actions_e;

typedef struct
{
  u8 is_add;
  u8 is_negative;
  negative_fwd_actions_e action;
  gid_address_t seid; /* TODO convert to ip4, ip6, mac ? */
  gid_address_t deid;
  ip_address_t slocator;
  ip_address_t dlocator;
  u32 encap_fib_index;
  u32 decap_fib_index;
  u32 decap_next_index;
  u8 flags;
  u8 ver_res;
  u8 res;
  u8 next_protocol;
  u32 vni; /* host byte order */
  u32 table_id;
} vnet_lisp_gpe_add_del_fwd_entry_args_t;

int
vnet_lisp_gpe_add_del_fwd_entry (vnet_lisp_gpe_add_del_fwd_entry_args_t *a,
				 u32 * hw_if_indexp);

u8 *
format_lisp_gpe_header_with_length (u8 * s, va_list * args);

#endif /* included_vnet_lisp_gpe_h */