]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_encap_types.h
Merge pull request #806 from dwalton76/bgpd-set-ipv4-vpn-nexthop
[mirror_frr.git] / bgpd / bgp_encap_types.h
1 /*
2 * Copyright 2015, LabN Consulting, L.L.C.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; see the file COPYING; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #ifndef _QUAGGA_BGP_ENCAP_TYPES_H
20 #define _QUAGGA_BGP_ENCAP_TYPES_H
21
22 #include "bgpd/bgp_ecommunity.h"
23
24 /* from http://www.iana.org/assignments/bgp-parameters/bgp-parameters.xhtml#tunnel-types */
25 typedef enum {
26 BGP_ENCAP_TYPE_RESERVED=0,
27 BGP_ENCAP_TYPE_L2TPV3_OVER_IP=1,
28 BGP_ENCAP_TYPE_GRE=2,
29 BGP_ENCAP_TYPE_TRANSMIT_TUNNEL_ENDPOINT=3,
30 BGP_ENCAP_TYPE_IPSEC_IN_TUNNEL_MODE=4,
31 BGP_ENCAP_TYPE_IP_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE=5,
32 BGP_ENCAP_TYPE_MPLS_IN_IP_TUNNEL_WITH_IPSEC_TRANSPORT_MODE=6,
33 BGP_ENCAP_TYPE_IP_IN_IP=7,
34 BGP_ENCAP_TYPE_VXLAN=8,
35 BGP_ENCAP_TYPE_NVGRE=9,
36 BGP_ENCAP_TYPE_MPLS=10, /* NOTE: Encap SAFI&Attribute not used */
37 BGP_ENCAP_TYPE_MPLS_IN_GRE=11,
38 BGP_ENCAP_TYPE_VXLAN_GPE=12,
39 BGP_ENCAP_TYPE_MPLS_IN_UDP=13,
40 BGP_ENCAP_TYPE_PBB
41 } bgp_encap_types;
42
43 typedef enum {
44 BGP_ENCAP_SUBTLV_TYPE_ENCAPSULATION=1,
45 BGP_ENCAP_SUBTLV_TYPE_PROTO_TYPE=2,
46 BGP_ENCAP_SUBTLV_TYPE_IPSEC_TA=3,
47 BGP_ENCAP_SUBTLV_TYPE_COLOR=4,
48 BGP_ENCAP_SUBTLV_TYPE_REMOTE_ENDPOINT=6 /* speculative, IANA assignment TBD */
49 } bgp_encap_subtlv_types;
50
51 /*
52 * Tunnel Encapsulation Attribute subtlvs
53 */
54 struct bgp_tea_subtlv_encap_l2tpv3_over_ip {
55 uint32_t sessionid;
56 uint8_t cookie_length;
57 uint8_t cookie[8];
58 };
59
60 struct bgp_tea_subtlv_encap_gre_key {
61 uint32_t gre_key;
62 };
63
64 struct bgp_tea_subtlv_encap_pbb {
65 uint32_t flag_isid:1;
66 uint32_t flag_vid:1;
67 uint32_t isid:24;
68 uint16_t vid:12;
69 uint8_t macaddr[6];
70 };
71
72 struct bgp_tea_subtlv_proto_type {
73 uint16_t proto; /* ether-type */
74 };
75
76 struct bgp_tea_subtlv_color {
77 uint32_t color;
78 };
79
80 /* per draft-rosen-idr-tunnel-encaps */
81 struct bgp_tea_subtlv_remote_endpoint {
82 u_char family; /* IPv4 or IPv6 */
83 union {
84 struct in_addr v4;
85 struct in6_addr v6;
86 } ip_address;
87 as_t as4; /* always 4 bytes */
88 };
89
90 /*
91 * This is the length of the value part of the ipsec tunnel authenticator
92 * subtlv. Currently we only support the length for authenticator type 1.
93 */
94 #define BGP_ENCAP_SUBTLV_IPSEC_TA_SIZE 20
95
96 struct bgp_tea_subtlv_ipsec_ta {
97 uint16_t authenticator_type; /* only type 1 is supported so far */
98 uint8_t authenticator_length; /* octets in value field */
99 uint8_t value[BGP_ENCAP_SUBTLV_IPSEC_TA_SIZE];
100 };
101
102 /*
103 * Subtlv valid flags
104 * TBD change names to add "VALID"
105 */
106 #define BGP_TEA_SUBTLV_ENCAP 0x00000001
107 #define BGP_TEA_SUBTLV_PROTO_TYPE 0x00000002
108 #define BGP_TEA_SUBTLV_COLOR 0x00000004
109 #define BGP_TEA_SUBTLV_IPSEC_TA 0x00000008
110 #define BGP_TEA_SUBTLV_REMOTE_ENDPOINT 0x00000010
111
112 #define CHECK_SUBTLV_FLAG(ptr, flag) CHECK_FLAG((ptr)->valid_subtlvs, (flag))
113 #define SET_SUBTLV_FLAG(ptr, flag) SET_FLAG((ptr)->valid_subtlvs, (flag))
114 #define UNSET_SUBTLV_FLAG(ptr, flag) UNSET_FLAG((ptr)->valid_subtlvs, (flag))
115
116 /*
117 * Tunnel Type-specific APIs
118 */
119 struct bgp_encap_type_reserved {
120 uint32_t valid_subtlvs;
121 struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
122 };
123
124 struct bgp_encap_type_l2tpv3_over_ip {
125 uint32_t valid_subtlvs;
126 struct bgp_tea_subtlv_encap_l2tpv3_over_ip st_encap;
127 struct bgp_tea_subtlv_proto_type st_proto; /* optional */
128 struct bgp_tea_subtlv_color st_color; /* optional */
129 struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
130 };
131
132 struct bgp_encap_type_gre {
133 uint32_t valid_subtlvs;
134 struct bgp_tea_subtlv_encap_gre_key st_encap; /* optional */
135 struct bgp_tea_subtlv_proto_type st_proto; /* optional */
136 struct bgp_tea_subtlv_color st_color; /* optional */
137 struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
138 };
139
140 struct bgp_encap_type_ip_in_ip {
141 uint32_t valid_subtlvs;
142 struct bgp_tea_subtlv_proto_type st_proto; /* optional */
143 struct bgp_tea_subtlv_color st_color; /* optional */
144 struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
145 };
146
147 struct bgp_encap_type_transmit_tunnel_endpoint {
148 uint32_t valid_subtlvs;
149 struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
150 /* No subtlvs defined in spec? */
151 };
152
153 struct bgp_encap_type_ipsec_in_tunnel_mode {
154 uint32_t valid_subtlvs;
155 struct bgp_tea_subtlv_ipsec_ta st_ipsec_ta; /* optional */
156 struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
157 };
158
159 struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode {
160 uint32_t valid_subtlvs;
161 struct bgp_tea_subtlv_ipsec_ta st_ipsec_ta; /* optional */
162 struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
163 };
164
165 struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode {
166 uint32_t valid_subtlvs;
167 struct bgp_tea_subtlv_ipsec_ta st_ipsec_ta; /* optional */
168 struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
169 };
170
171 #define VXLAN_ENCAP_MASK_VNID_VALID 0x80000000
172 #define VXLAN_ENCAP_MASK_MAC_VALID 0x40000000
173
174 struct bgp_encap_type_vxlan {
175 uint32_t valid_subtlvs;
176 struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
177 /* draft-ietf-idr-tunnel-encaps-02 */
178 uint32_t vnid; /* does not include V and M bit */
179 uint8_t *mac_address; /* optional */
180 };
181
182 struct bgp_encap_type_nvgre {
183 uint32_t valid_subtlvs;
184 struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
185 /* No subtlvs defined in spec? */
186 };
187
188 struct bgp_encap_type_mpls {
189 uint32_t valid_subtlvs;
190 struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
191 /* No subtlvs defined in spec? */
192 };
193
194 struct bgp_encap_type_mpls_in_gre {
195 uint32_t valid_subtlvs;
196 struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
197 /* No subtlvs defined in spec? */
198 };
199
200 struct bgp_encap_type_vxlan_gpe {
201 uint32_t valid_subtlvs;
202 struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
203 /* No subtlvs defined in spec? */
204 };
205
206 struct bgp_encap_type_mpls_in_udp {
207 uint32_t valid_subtlvs;
208 struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
209 /* No subtlvs defined in spec? */
210 };
211
212 struct bgp_encap_type_pbb {
213 uint32_t valid_subtlvs;
214 struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
215 struct bgp_tea_subtlv_encap_pbb st_encap;
216 };
217
218 static inline void
219 encode_encap_extcomm (bgp_encap_types tnl_type,
220 struct ecommunity_val *eval)
221 {
222 memset (eval, 0, sizeof (*eval));
223 eval->val[0] = ECOMMUNITY_ENCODE_OPAQUE;
224 eval->val[1] = ECOMMUNITY_OPAQUE_SUBTYPE_ENCAP;
225 eval->val[6] = ((tnl_type) >> 8) & 0xff;
226 eval->val[7] = (tnl_type) & 0xff;
227 }
228
229 #endif /* _QUAGGA_BGP_ENCAP_TYPES_H */