summaryrefslogtreecommitdiffstats
path: root/bgpd/bgp_encap_types.h
blob: 8d1bf682ad1f10263f8fc22507ad2ac31a9b75ab (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
222
223
224
225
226
227
228
229
230
231
/*
 * Copyright 2015, LabN Consulting, L.L.C.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; see the file COPYING; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 */

#ifndef _QUAGGA_BGP_ENCAP_TYPES_H
#define _QUAGGA_BGP_ENCAP_TYPES_H

#include "bgpd/bgp_ecommunity.h"

/* from
 * http://www.iana.org/assignments/bgp-parameters/bgp-parameters.xhtml#tunnel-types
 */
typedef enum {
	BGP_ENCAP_TYPE_RESERVED = 0,
	BGP_ENCAP_TYPE_L2TPV3_OVER_IP = 1,
	BGP_ENCAP_TYPE_GRE = 2,
	BGP_ENCAP_TYPE_TRANSMIT_TUNNEL_ENDPOINT = 3,
	BGP_ENCAP_TYPE_IPSEC_IN_TUNNEL_MODE = 4,
	BGP_ENCAP_TYPE_IP_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE = 5,
	BGP_ENCAP_TYPE_MPLS_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE = 6,
	BGP_ENCAP_TYPE_IP_IN_IP = 7,
	BGP_ENCAP_TYPE_VXLAN = 8,
	BGP_ENCAP_TYPE_NVGRE = 9,
	BGP_ENCAP_TYPE_MPLS = 10, /* NOTE: Encap SAFI&Attribute not used */
	BGP_ENCAP_TYPE_MPLS_IN_GRE = 11,
	BGP_ENCAP_TYPE_VXLAN_GPE = 12,
	BGP_ENCAP_TYPE_MPLS_IN_UDP = 13,
	BGP_ENCAP_TYPE_PBB
} bgp_encap_types;

typedef enum {
	BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION = 1,
	BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE = 2,
	BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA = 3,
	BGP_ENCAP_SUBTLV_TYPE_COLOR = 4,
	BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT =
		6 /* speculative, IANA assignment TBD */
} bgp_encap_subtlv_types;

/*
 * Tunnel Encapsulation Attribute subtlvs
 */
struct bgp_tea_subtlv_encap_l2tpv3_over_ip {
	uint32_t sessionid;
	uint8_t cookie_length;
	uint8_t cookie[8];
};

struct bgp_tea_subtlv_encap_gre_key {
	uint32_t gre_key;
};

struct bgp_tea_subtlv_encap_pbb {
	uint32_t flag_isid : 1;
	uint32_t flag_vid : 1;
	uint32_t isid : 24;
	uint16_t vid : 12;
	uint8_t macaddr[6];
};

struct bgp_tea_subtlv_proto_type {
	uint16_t proto; /* ether-type */
};

struct bgp_tea_subtlv_color {
	uint32_t color;
};

/* per draft-rosen-idr-tunnel-encaps */
struct bgp_tea_subtlv_remote_endpoint {
	uint8_t family; /* IPv4 or IPv6 */
	union {
		struct in_addr v4;
		struct in6_addr v6;
	} ip_address;
	as_t as4; /* always 4 bytes */
};

/*
 * This is the length of the value part of the ipsec tunnel authenticator
 * subtlv. Currently we only support the length for authenticator type 1.
 */
#define BGP_ENCAP_SUBTLV_IPSEC_TA_SIZE	20

struct bgp_tea_subtlv_ipsec_ta {
	uint16_t authenticator_type;  /* only type 1 is supported so far */
	uint8_t authenticator_length; /* octets in value field */
	uint8_t value[BGP_ENCAP_SUBTLV_IPSEC_TA_SIZE];
};

/*
 * Subtlv valid flags
 * TBD change names to add "VALID"
 */
#define BGP_TEA_SUBTLV_ENCAP		0x00000001
#define BGP_TEA_SUBTLV_PROTO_TYPE	0x00000002
#define BGP_TEA_SUBTLV_COLOR		0x00000004
#define BGP_TEA_SUBTLV_IPSEC_TA		0x00000008
#define BGP_TEA_SUBTLV_REMOTE_ENDPOINT	0x00000010

#define CHECK_SUBTLV_FLAG(ptr, flag)  CHECK_FLAG((ptr)->valid_subtlvs, (flag))
#define SET_SUBTLV_FLAG(ptr, flag)      SET_FLAG((ptr)->valid_subtlvs, (flag))
#define UNSET_SUBTLV_FLAG(ptr, flag)  UNSET_FLAG((ptr)->valid_subtlvs, (flag))

/*
 * Tunnel Type-specific APIs
 */
struct bgp_encap_type_reserved {
	uint32_t valid_subtlvs;
	struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
};

struct bgp_encap_type_l2tpv3_over_ip {
	uint32_t valid_subtlvs;
	struct bgp_tea_subtlv_encap_l2tpv3_over_ip st_encap;
	struct bgp_tea_subtlv_proto_type st_proto;	 /* optional */
	struct bgp_tea_subtlv_color st_color;		   /* optional */
	struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
};

struct bgp_encap_type_gre {
	uint32_t valid_subtlvs;
	struct bgp_tea_subtlv_encap_gre_key st_encap;      /* optional */
	struct bgp_tea_subtlv_proto_type st_proto;	 /* optional */
	struct bgp_tea_subtlv_color st_color;		   /* optional */
	struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
};

struct bgp_encap_type_ip_in_ip {
	uint32_t valid_subtlvs;
	struct bgp_tea_subtlv_proto_type st_proto;	 /* optional */
	struct bgp_tea_subtlv_color st_color;		   /* optional */
	struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
};

struct bgp_encap_type_transmit_tunnel_endpoint {
	uint32_t valid_subtlvs;
	struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
	/* No subtlvs defined in spec? */
};

struct bgp_encap_type_ipsec_in_tunnel_mode {
	uint32_t valid_subtlvs;
	struct bgp_tea_subtlv_ipsec_ta st_ipsec_ta;	/* optional */
	struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
};

struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode {
	uint32_t valid_subtlvs;
	struct bgp_tea_subtlv_ipsec_ta st_ipsec_ta;	/* optional */
	struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
};

struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode {
	uint32_t valid_subtlvs;
	struct bgp_tea_subtlv_ipsec_ta st_ipsec_ta;	/* optional */
	struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
};

#define VXLAN_ENCAP_MASK_VNID_VALID 0x80000000
#define VXLAN_ENCAP_MASK_MAC_VALID  0x40000000

struct bgp_encap_type_vxlan {
	uint32_t valid_subtlvs;
	struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
	/* draft-ietf-idr-tunnel-encaps-02 */
	uint32_t vnid;	/* does not include V and M bit */
	uint8_t *mac_address; /* optional */
};

struct bgp_encap_type_nvgre {
	uint32_t valid_subtlvs;
	struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
	/* No subtlvs defined in spec? */
};

struct bgp_encap_type_mpls {
	uint32_t valid_subtlvs;
	struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
	/* No subtlvs defined in spec? */
};

struct bgp_encap_type_mpls_in_gre {
	uint32_t valid_subtlvs;
	struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
	/* No subtlvs defined in spec? */
};

struct bgp_encap_type_vxlan_gpe {
	uint32_t valid_subtlvs;
	struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
	/* No subtlvs defined in spec? */
};

struct bgp_encap_type_mpls_in_udp {
	uint32_t valid_subtlvs;
	struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
	/* No subtlvs defined in spec? */
};

struct bgp_encap_type_pbb {
	uint32_t valid_subtlvs;
	struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
	struct bgp_tea_subtlv_encap_pbb st_encap;
};

static inline void encode_encap_extcomm(bgp_encap_types tnl_type,
					struct ecommunity_val *eval)
{
	memset(eval, 0, sizeof(*eval));
	eval->val[0] = ECOMMUNITY_ENCODE_OPAQUE;
	eval->val[1] = ECOMMUNITY_OPAQUE_SUBTYPE_ENCAP;
	eval->val[6] = ((tnl_type) >> 8) & 0xff;
	eval->val[7] = (tnl_type)&0xff;
}

#endif /* _QUAGGA_BGP_ENCAP_TYPES_H */