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