]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_encap_types.h
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / bgpd / bgp_encap_types.h
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
f4c89855
LB
2/*
3 * Copyright 2015, LabN Consulting, L.L.C.
f4c89855
LB
4 */
5
6#ifndef _QUAGGA_BGP_ENCAP_TYPES_H
7#define _QUAGGA_BGP_ENCAP_TYPES_H
8
86f6f09e 9#include "bgpd/bgp_ecommunity.h"
10
d62a17ae 11/* from
12 * http://www.iana.org/assignments/bgp-parameters/bgp-parameters.xhtml#tunnel-types
13 */
f4c89855 14typedef enum {
d62a17ae 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
f4c89855
LB
30} bgp_encap_types;
31
32typedef enum {
d62a17ae 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 */
f4c89855
LB
39} bgp_encap_subtlv_types;
40
41/*
42 * Tunnel Encapsulation Attribute subtlvs
43 */
44struct bgp_tea_subtlv_encap_l2tpv3_over_ip {
d62a17ae 45 uint32_t sessionid;
46 uint8_t cookie_length;
47 uint8_t cookie[8];
f4c89855
LB
48};
49
50struct bgp_tea_subtlv_encap_gre_key {
d62a17ae 51 uint32_t gre_key;
f4c89855
LB
52};
53
54struct bgp_tea_subtlv_encap_pbb {
d62a17ae 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];
f4c89855
LB
60};
61
62struct bgp_tea_subtlv_proto_type {
d62a17ae 63 uint16_t proto; /* ether-type */
f4c89855
LB
64};
65
66struct bgp_tea_subtlv_color {
d62a17ae 67 uint32_t color;
f4c89855
LB
68};
69
587ff0fd
LB
70/* per draft-rosen-idr-tunnel-encaps */
71struct bgp_tea_subtlv_remote_endpoint {
d7c0a89a 72 uint8_t family; /* IPv4 or IPv6 */
d62a17ae 73 union {
74 struct in_addr v4;
75 struct in6_addr v6;
76 } ip_address;
77 as_t as4; /* always 4 bytes */
587ff0fd
LB
78};
79
f4c89855
LB
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
86struct bgp_tea_subtlv_ipsec_ta {
d62a17ae 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];
f4c89855
LB
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
587ff0fd 100#define BGP_TEA_SUBTLV_REMOTE_ENDPOINT 0x00000010
f4c89855 101
587ff0fd
LB
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))
f4c89855
LB
105
106/*
107 * Tunnel Type-specific APIs
108 */
109struct bgp_encap_type_reserved {
d62a17ae 110 uint32_t valid_subtlvs;
111 struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
f4c89855
LB
112};
113
114struct bgp_encap_type_l2tpv3_over_ip {
d62a17ae 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 */
f4c89855
LB
120};
121
122struct bgp_encap_type_gre {
d62a17ae 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 */
f4c89855
LB
128};
129
130struct bgp_encap_type_ip_in_ip {
d62a17ae 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 */
f4c89855
LB
135};
136
137struct bgp_encap_type_transmit_tunnel_endpoint {
d62a17ae 138 uint32_t valid_subtlvs;
139 struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
140 /* No subtlvs defined in spec? */
f4c89855
LB
141};
142
143struct bgp_encap_type_ipsec_in_tunnel_mode {
d62a17ae 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 */
f4c89855
LB
147};
148
149struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode {
d62a17ae 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 */
f4c89855
LB
153};
154
155struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode {
d62a17ae 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 */
f4c89855
LB
159};
160
aee875b5
PG
161#define VXLAN_ENCAP_MASK_VNID_VALID 0x80000000
162#define VXLAN_ENCAP_MASK_MAC_VALID 0x40000000
163
f4c89855 164struct bgp_encap_type_vxlan {
d62a17ae 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 */
f4c89855
LB
170};
171
172struct bgp_encap_type_nvgre {
d62a17ae 173 uint32_t valid_subtlvs;
174 struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
175 /* No subtlvs defined in spec? */
f4c89855
LB
176};
177
178struct bgp_encap_type_mpls {
d62a17ae 179 uint32_t valid_subtlvs;
180 struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
181 /* No subtlvs defined in spec? */
f4c89855
LB
182};
183
184struct bgp_encap_type_mpls_in_gre {
d62a17ae 185 uint32_t valid_subtlvs;
186 struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
187 /* No subtlvs defined in spec? */
f4c89855
LB
188};
189
190struct bgp_encap_type_vxlan_gpe {
d62a17ae 191 uint32_t valid_subtlvs;
192 struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
193 /* No subtlvs defined in spec? */
f4c89855
LB
194};
195
196struct bgp_encap_type_mpls_in_udp {
d62a17ae 197 uint32_t valid_subtlvs;
198 struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
199 /* No subtlvs defined in spec? */
f4c89855
LB
200};
201
202struct bgp_encap_type_pbb {
d62a17ae 203 uint32_t valid_subtlvs;
204 struct bgp_tea_subtlv_remote_endpoint st_endpoint; /* optional */
205 struct bgp_tea_subtlv_encap_pbb st_encap;
f4c89855
LB
206};
207
d62a17ae 208static inline void encode_encap_extcomm(bgp_encap_types tnl_type,
209 struct ecommunity_val *eval)
86f6f09e 210{
d62a17ae 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;
86f6f09e 216}
217
f4c89855 218#endif /* _QUAGGA_BGP_ENCAP_TYPES_H */