]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* BGP Extended Communities Attribute. |
896014f4 DL |
2 | * Copyright (C) 2000 Kunihiro Ishiguro <kunihiro@zebra.org> |
3 | * | |
4 | * This file is part of GNU Zebra. | |
5 | * | |
6 | * GNU Zebra is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License as published by the | |
8 | * Free Software Foundation; either version 2, or (at your option) any | |
9 | * later version. | |
10 | * | |
11 | * GNU Zebra is distributed in the hope that it will be useful, but | |
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License along | |
17 | * with this program; see the file COPYING; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | */ | |
718e3744 | 20 | |
00d252cb | 21 | #ifndef _QUAGGA_BGP_ECOMMUNITY_H |
22 | #define _QUAGGA_BGP_ECOMMUNITY_H | |
23 | ||
5b820d9e | 24 | #include "bgpd/bgp_route.h" |
f4bd90c5 | 25 | #include "bgpd/bgpd.h" |
5b820d9e | 26 | |
7e3ebfd1 | 27 | /* Refer to rfc7153 for the IANA registry definitions. These are |
28 | * updated by other standards like rfc7674. | |
29 | */ | |
718e3744 | 30 | /* High-order octet of the Extended Communities type field. */ |
31 | #define ECOMMUNITY_ENCODE_AS 0x00 | |
32 | #define ECOMMUNITY_ENCODE_IP 0x01 | |
0b2aa3a0 | 33 | #define ECOMMUNITY_ENCODE_AS4 0x02 |
0014c301 | 34 | #define ECOMMUNITY_ENCODE_OPAQUE 0x03 |
e82202b7 | 35 | #define ECOMMUNITY_ENCODE_EVPN 0x06 |
b72220fc | 36 | #define ECOMMUNITY_ENCODE_REDIRECT_IP_NH 0x08 /* Flow Spec */ |
7e3ebfd1 | 37 | /* Generic Transitive Experimental */ |
38 | #define ECOMMUNITY_ENCODE_TRANS_EXP 0x80 | |
39 | ||
a8d72b61 PG |
40 | /* RFC7674 */ |
41 | #define ECOMMUNITY_EXTENDED_COMMUNITY_PART_2 0x81 | |
42 | #define ECOMMUNITY_EXTENDED_COMMUNITY_PART_3 0x82 | |
718e3744 | 43 | |
7e3ebfd1 | 44 | /* Non-transitive extended community types. */ |
45 | #define ECOMMUNITY_ENCODE_AS_NON_TRANS 0x40 | |
46 | #define ECOMMUNITY_ENCODE_IP_NON_TRANS 0x41 | |
47 | #define ECOMMUNITY_ENCODE_AS4_NON_TRANS 0x42 | |
48 | #define ECOMMUNITY_ENCODE_OPAQUE_NON_TRANS 0x43 | |
49 | ||
0014c301 | 50 | /* Low-order octet of the Extended Communities type field. */ |
7e3ebfd1 | 51 | /* Note: This really depends on the high-order octet. This means that |
52 | * multiple definitions for the same value are possible. | |
53 | */ | |
718e3744 | 54 | #define ECOMMUNITY_ROUTE_TARGET 0x02 |
55 | #define ECOMMUNITY_SITE_ORIGIN 0x03 | |
650b0511 | 56 | #define ECOMMUNITY_LINK_BANDWIDTH 0x04 |
a8d72b61 PG |
57 | #define ECOMMUNITY_TRAFFIC_RATE 0x06 /* Flow Spec */ |
58 | #define ECOMMUNITY_TRAFFIC_ACTION 0x07 | |
59 | #define ECOMMUNITY_REDIRECT_VRF 0x08 | |
60 | #define ECOMMUNITY_TRAFFIC_MARKING 0x09 | |
61 | #define ECOMMUNITY_REDIRECT_IP_NH 0x00 | |
2551b26e PG |
62 | /* from IANA: bgp-extended-communities/bgp-extended-communities.xhtml |
63 | * 0x0c Flow-spec Redirect to IPv4 - draft-ietf-idr-flowspec-redirect | |
64 | */ | |
65 | #define ECOMMUNITY_FLOWSPEC_REDIRECT_IPV4 0x0c | |
718e3744 | 66 | |
128ea8ab | 67 | /* Low-order octet of the Extended Communities type field for EVPN types */ |
1e27ef50 PG |
68 | #define ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY 0x00 |
69 | #define ECOMMUNITY_EVPN_SUBTYPE_ESI_LABEL 0x01 | |
70 | #define ECOMMUNITY_EVPN_SUBTYPE_ES_IMPORT_RT 0x02 | |
71 | #define ECOMMUNITY_EVPN_SUBTYPE_ROUTERMAC 0x03 | |
72 | #define ECOMMUNITY_EVPN_SUBTYPE_DEF_GW 0x0d | |
68e33151 | 73 | #define ECOMMUNITY_EVPN_SUBTYPE_ND 0x08 |
1e27ef50 | 74 | |
128ea8ab | 75 | #define ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY_FLAG_STICKY 0x01 |
68e33151 CS |
76 | #define ECOMMUNITY_EVPN_SUBTYPE_ND_ROUTER_FLAG 0x01 |
77 | #define ECOMMUNITY_EVPN_SUBTYPE_ND_OVERRIDE_FLAG 0x02 | |
128ea8ab | 78 | |
0014c301 LB |
79 | /* Low-order octet of the Extended Communities type field for OPAQUE types */ |
80 | #define ECOMMUNITY_OPAQUE_SUBTYPE_ENCAP 0x0c | |
81 | ||
718e3744 | 82 | /* Extended communities attribute string format. */ |
83 | #define ECOMMUNITY_FORMAT_ROUTE_MAP 0 | |
84 | #define ECOMMUNITY_FORMAT_COMMUNITY_LIST 1 | |
85 | #define ECOMMUNITY_FORMAT_DISPLAY 2 | |
86 | ||
87 | /* Extended Communities value is eight octet long. */ | |
88 | #define ECOMMUNITY_SIZE 8 | |
89 | ||
4372df71 | 90 | /* Extended Communities type flag. */ |
7c40bf39 | 91 | #define ECOMMUNITY_FLAG_NON_TRANSITIVE 0x40 |
4372df71 | 92 | |
718e3744 | 93 | /* Extended Communities attribute. */ |
d62a17ae | 94 | struct ecommunity { |
95 | /* Reference counter. */ | |
96 | unsigned long refcnt; | |
718e3744 | 97 | |
d62a17ae | 98 | /* Size of Extended Communities attribute. */ |
99 | int size; | |
718e3744 | 100 | |
d62a17ae | 101 | /* Extended Communities value. */ |
d7c0a89a | 102 | uint8_t *val; |
718e3744 | 103 | |
d62a17ae | 104 | /* Human readable format string. */ |
105 | char *str; | |
718e3744 | 106 | }; |
107 | ||
5a0ccebf QY |
108 | struct ecommunity_as { |
109 | as_t as; | |
110 | uint32_t val; | |
111 | }; | |
112 | ||
113 | struct ecommunity_ip { | |
114 | struct in_addr ip; | |
115 | uint16_t val; | |
116 | }; | |
117 | ||
718e3744 | 118 | /* Extended community value is eight octet. */ |
d62a17ae | 119 | struct ecommunity_val { |
120 | char val[ECOMMUNITY_SIZE]; | |
718e3744 | 121 | }; |
122 | ||
c5900768 | 123 | /* |
124 | * Encode BGP Route Target AS:nn. | |
125 | */ | |
d7c0a89a | 126 | static inline void encode_route_target_as(as_t as, uint32_t val, |
d62a17ae | 127 | struct ecommunity_val *eval) |
c5900768 | 128 | { |
d62a17ae | 129 | eval->val[0] = ECOMMUNITY_ENCODE_AS; |
130 | eval->val[1] = ECOMMUNITY_ROUTE_TARGET; | |
131 | eval->val[2] = (as >> 8) & 0xff; | |
132 | eval->val[3] = as & 0xff; | |
133 | eval->val[4] = (val >> 24) & 0xff; | |
134 | eval->val[5] = (val >> 16) & 0xff; | |
135 | eval->val[6] = (val >> 8) & 0xff; | |
136 | eval->val[7] = val & 0xff; | |
c5900768 | 137 | } |
138 | ||
139 | /* | |
140 | * Encode BGP Route Target IP:nn. | |
141 | */ | |
d7c0a89a | 142 | static inline void encode_route_target_ip(struct in_addr ip, uint16_t val, |
d62a17ae | 143 | struct ecommunity_val *eval) |
c5900768 | 144 | { |
d62a17ae | 145 | eval->val[0] = ECOMMUNITY_ENCODE_IP; |
146 | eval->val[1] = ECOMMUNITY_ROUTE_TARGET; | |
147 | memcpy(&eval->val[2], &ip, sizeof(struct in_addr)); | |
148 | eval->val[6] = (val >> 8) & 0xff; | |
149 | eval->val[7] = val & 0xff; | |
c5900768 | 150 | } |
151 | ||
152 | /* | |
153 | * Encode BGP Route Target AS4:nn. | |
154 | */ | |
d7c0a89a | 155 | static inline void encode_route_target_as4(as_t as, uint16_t val, |
d62a17ae | 156 | struct ecommunity_val *eval) |
c5900768 | 157 | { |
d62a17ae | 158 | eval->val[0] = ECOMMUNITY_ENCODE_AS4; |
159 | eval->val[1] = ECOMMUNITY_ROUTE_TARGET; | |
160 | eval->val[2] = (as >> 24) & 0xff; | |
161 | eval->val[3] = (as >> 16) & 0xff; | |
162 | eval->val[4] = (as >> 8) & 0xff; | |
163 | eval->val[5] = as & 0xff; | |
164 | eval->val[6] = (val >> 8) & 0xff; | |
165 | eval->val[7] = val & 0xff; | |
c5900768 | 166 | } |
167 | ||
ca9ac3ef | 168 | /* |
169 | * Encode BGP Link Bandwidth extended community | |
170 | * bandwidth (bw) is in bytes-per-sec | |
171 | */ | |
172 | static inline void encode_lb_extcomm(as_t as, uint32_t bw, bool non_trans, | |
173 | struct ecommunity_val *eval) | |
174 | { | |
175 | memset(eval, 0, sizeof(*eval)); | |
176 | eval->val[0] = ECOMMUNITY_ENCODE_AS; | |
177 | if (non_trans) | |
178 | eval->val[0] |= ECOMMUNITY_FLAG_NON_TRANSITIVE; | |
179 | eval->val[1] = ECOMMUNITY_LINK_BANDWIDTH; | |
180 | eval->val[2] = (as >> 8) & 0xff; | |
181 | eval->val[3] = as & 0xff; | |
182 | eval->val[4] = (bw >> 24) & 0xff; | |
183 | eval->val[5] = (bw >> 16) & 0xff; | |
184 | eval->val[6] = (bw >> 8) & 0xff; | |
185 | eval->val[7] = bw & 0xff; | |
186 | } | |
187 | ||
d62a17ae | 188 | extern void ecommunity_init(void); |
189 | extern void ecommunity_finish(void); | |
190 | extern void ecommunity_free(struct ecommunity **); | |
d7c0a89a | 191 | extern struct ecommunity *ecommunity_parse(uint8_t *, unsigned short); |
d62a17ae | 192 | extern struct ecommunity *ecommunity_dup(struct ecommunity *); |
193 | extern struct ecommunity *ecommunity_merge(struct ecommunity *, | |
194 | struct ecommunity *); | |
195 | extern struct ecommunity *ecommunity_uniq_sort(struct ecommunity *); | |
196 | extern struct ecommunity *ecommunity_intern(struct ecommunity *); | |
74df8d6d | 197 | extern bool ecommunity_cmp(const void *arg1, const void *arg2); |
d62a17ae | 198 | extern void ecommunity_unintern(struct ecommunity **); |
d8b87afe | 199 | extern unsigned int ecommunity_hash_make(const void *); |
d62a17ae | 200 | extern struct ecommunity *ecommunity_str2com(const char *, int, int); |
201 | extern char *ecommunity_ecom2str(struct ecommunity *, int, int); | |
c7ee6c35 | 202 | extern void ecommunity_strfree(char **s); |
3dc339cd DA |
203 | extern bool ecommunity_match(const struct ecommunity *, |
204 | const struct ecommunity *); | |
d62a17ae | 205 | extern char *ecommunity_str(struct ecommunity *); |
206 | extern struct ecommunity_val *ecommunity_lookup(const struct ecommunity *, | |
207 | uint8_t, uint8_t); | |
3dc339cd | 208 | extern bool ecommunity_add_val(struct ecommunity *ecom, |
1207a5bc | 209 | struct ecommunity_val *eval, |
210 | bool unique, bool overwrite); | |
00d252cb | 211 | |
65efcfce | 212 | /* for vpn */ |
d62a17ae | 213 | extern struct ecommunity *ecommunity_new(void); |
3dc339cd DA |
214 | extern bool ecommunity_strip(struct ecommunity *ecom, uint8_t type, |
215 | uint8_t subtype); | |
d62a17ae | 216 | extern struct ecommunity *ecommunity_new(void); |
3dc339cd DA |
217 | extern bool ecommunity_del_val(struct ecommunity *ecom, |
218 | struct ecommunity_val *eval); | |
dacf6ec1 PG |
219 | struct bgp_pbr_entry_action; |
220 | extern int ecommunity_fill_pbr_action(struct ecommunity_val *ecom_eval, | |
221 | struct bgp_pbr_entry_action *api); | |
222 | ||
5b820d9e NT |
223 | extern void bgp_compute_aggregate_ecommunity( |
224 | struct bgp_aggregate *aggregate, | |
225 | struct ecommunity *ecommunity); | |
4edd83f9 | 226 | |
227 | extern void bgp_compute_aggregate_ecommunity_hash( | |
228 | struct bgp_aggregate *aggregate, | |
229 | struct ecommunity *ecommunity); | |
230 | extern void bgp_compute_aggregate_ecommunity_val( | |
231 | struct bgp_aggregate *aggregate); | |
5b820d9e NT |
232 | extern void bgp_remove_ecommunity_from_aggregate( |
233 | struct bgp_aggregate *aggregate, | |
234 | struct ecommunity *ecommunity); | |
4edd83f9 | 235 | extern void bgp_remove_ecomm_from_aggregate_hash( |
236 | struct bgp_aggregate *aggregate, | |
237 | struct ecommunity *ecommunity); | |
5b820d9e | 238 | extern void bgp_aggr_ecommunity_remove(void *arg); |
d901dc13 | 239 | extern const uint8_t *ecommunity_linkbw_present(struct ecommunity *ecom, |
240 | uint32_t *bw); | |
7b651a32 | 241 | extern struct ecommunity *ecommunity_replace_linkbw(as_t as, |
242 | struct ecommunity *ecom, uint64_t cum_bw); | |
e8bfa90e | 243 | |
244 | static inline void ecommunity_strip_rts(struct ecommunity *ecom) | |
245 | { | |
246 | uint8_t subtype = ECOMMUNITY_ROUTE_TARGET; | |
247 | ||
248 | ecommunity_strip(ecom, ECOMMUNITY_ENCODE_AS, subtype); | |
249 | ecommunity_strip(ecom, ECOMMUNITY_ENCODE_IP, subtype); | |
250 | ecommunity_strip(ecom, ECOMMUNITY_ENCODE_AS4, subtype); | |
251 | } | |
00d252cb | 252 | #endif /* _QUAGGA_BGP_ECOMMUNITY_H */ |