]>
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 | |
718e3744 | 27 | /* High-order octet of the Extended Communities type field. */ |
28 | #define ECOMMUNITY_ENCODE_AS 0x00 | |
29 | #define ECOMMUNITY_ENCODE_IP 0x01 | |
0b2aa3a0 | 30 | #define ECOMMUNITY_ENCODE_AS4 0x02 |
0014c301 | 31 | #define ECOMMUNITY_ENCODE_OPAQUE 0x03 |
e82202b7 | 32 | #define ECOMMUNITY_ENCODE_EVPN 0x06 |
a8d72b61 | 33 | #define ECOMMUNITY_ENCODE_TRANS_EXP 0x80 /* Flow Spec */ |
b72220fc | 34 | #define ECOMMUNITY_ENCODE_REDIRECT_IP_NH 0x08 /* Flow Spec */ |
a8d72b61 PG |
35 | /* RFC7674 */ |
36 | #define ECOMMUNITY_EXTENDED_COMMUNITY_PART_2 0x81 | |
37 | #define ECOMMUNITY_EXTENDED_COMMUNITY_PART_3 0x82 | |
718e3744 | 38 | |
0014c301 | 39 | /* Low-order octet of the Extended Communities type field. */ |
718e3744 | 40 | #define ECOMMUNITY_ROUTE_TARGET 0x02 |
41 | #define ECOMMUNITY_SITE_ORIGIN 0x03 | |
a8d72b61 PG |
42 | #define ECOMMUNITY_TRAFFIC_RATE 0x06 /* Flow Spec */ |
43 | #define ECOMMUNITY_TRAFFIC_ACTION 0x07 | |
44 | #define ECOMMUNITY_REDIRECT_VRF 0x08 | |
45 | #define ECOMMUNITY_TRAFFIC_MARKING 0x09 | |
46 | #define ECOMMUNITY_REDIRECT_IP_NH 0x00 | |
2551b26e PG |
47 | /* from IANA: bgp-extended-communities/bgp-extended-communities.xhtml |
48 | * 0x0c Flow-spec Redirect to IPv4 - draft-ietf-idr-flowspec-redirect | |
49 | */ | |
50 | #define ECOMMUNITY_FLOWSPEC_REDIRECT_IPV4 0x0c | |
718e3744 | 51 | |
128ea8ab | 52 | /* Low-order octet of the Extended Communities type field for EVPN types */ |
1e27ef50 PG |
53 | #define ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY 0x00 |
54 | #define ECOMMUNITY_EVPN_SUBTYPE_ESI_LABEL 0x01 | |
55 | #define ECOMMUNITY_EVPN_SUBTYPE_ES_IMPORT_RT 0x02 | |
56 | #define ECOMMUNITY_EVPN_SUBTYPE_ROUTERMAC 0x03 | |
57 | #define ECOMMUNITY_EVPN_SUBTYPE_DEF_GW 0x0d | |
68e33151 | 58 | #define ECOMMUNITY_EVPN_SUBTYPE_ND 0x08 |
1e27ef50 | 59 | |
128ea8ab | 60 | #define ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY_FLAG_STICKY 0x01 |
68e33151 CS |
61 | #define ECOMMUNITY_EVPN_SUBTYPE_ND_ROUTER_FLAG 0x01 |
62 | #define ECOMMUNITY_EVPN_SUBTYPE_ND_OVERRIDE_FLAG 0x02 | |
128ea8ab | 63 | |
0014c301 LB |
64 | /* Low-order octet of the Extended Communities type field for OPAQUE types */ |
65 | #define ECOMMUNITY_OPAQUE_SUBTYPE_ENCAP 0x0c | |
66 | ||
718e3744 | 67 | /* Extended communities attribute string format. */ |
68 | #define ECOMMUNITY_FORMAT_ROUTE_MAP 0 | |
69 | #define ECOMMUNITY_FORMAT_COMMUNITY_LIST 1 | |
70 | #define ECOMMUNITY_FORMAT_DISPLAY 2 | |
71 | ||
72 | /* Extended Communities value is eight octet long. */ | |
73 | #define ECOMMUNITY_SIZE 8 | |
74 | ||
4372df71 | 75 | /* Extended Communities type flag. */ |
7c40bf39 | 76 | #define ECOMMUNITY_FLAG_NON_TRANSITIVE 0x40 |
4372df71 | 77 | |
718e3744 | 78 | /* Extended Communities attribute. */ |
d62a17ae | 79 | struct ecommunity { |
80 | /* Reference counter. */ | |
81 | unsigned long refcnt; | |
718e3744 | 82 | |
d62a17ae | 83 | /* Size of Extended Communities attribute. */ |
84 | int size; | |
718e3744 | 85 | |
d62a17ae | 86 | /* Extended Communities value. */ |
d7c0a89a | 87 | uint8_t *val; |
718e3744 | 88 | |
d62a17ae | 89 | /* Human readable format string. */ |
90 | char *str; | |
718e3744 | 91 | }; |
92 | ||
5a0ccebf QY |
93 | struct ecommunity_as { |
94 | as_t as; | |
95 | uint32_t val; | |
96 | }; | |
97 | ||
98 | struct ecommunity_ip { | |
99 | struct in_addr ip; | |
100 | uint16_t val; | |
101 | }; | |
102 | ||
718e3744 | 103 | /* Extended community value is eight octet. */ |
d62a17ae | 104 | struct ecommunity_val { |
105 | char val[ECOMMUNITY_SIZE]; | |
718e3744 | 106 | }; |
107 | ||
108 | #define ecom_length(X) ((X)->size * ECOMMUNITY_SIZE) | |
109 | ||
c5900768 | 110 | /* |
111 | * Encode BGP Route Target AS:nn. | |
112 | */ | |
d7c0a89a | 113 | static inline void encode_route_target_as(as_t as, uint32_t val, |
d62a17ae | 114 | struct ecommunity_val *eval) |
c5900768 | 115 | { |
d62a17ae | 116 | eval->val[0] = ECOMMUNITY_ENCODE_AS; |
117 | eval->val[1] = ECOMMUNITY_ROUTE_TARGET; | |
118 | eval->val[2] = (as >> 8) & 0xff; | |
119 | eval->val[3] = as & 0xff; | |
120 | eval->val[4] = (val >> 24) & 0xff; | |
121 | eval->val[5] = (val >> 16) & 0xff; | |
122 | eval->val[6] = (val >> 8) & 0xff; | |
123 | eval->val[7] = val & 0xff; | |
c5900768 | 124 | } |
125 | ||
126 | /* | |
127 | * Encode BGP Route Target IP:nn. | |
128 | */ | |
d7c0a89a | 129 | static inline void encode_route_target_ip(struct in_addr ip, uint16_t val, |
d62a17ae | 130 | struct ecommunity_val *eval) |
c5900768 | 131 | { |
d62a17ae | 132 | eval->val[0] = ECOMMUNITY_ENCODE_IP; |
133 | eval->val[1] = ECOMMUNITY_ROUTE_TARGET; | |
134 | memcpy(&eval->val[2], &ip, sizeof(struct in_addr)); | |
135 | eval->val[6] = (val >> 8) & 0xff; | |
136 | eval->val[7] = val & 0xff; | |
c5900768 | 137 | } |
138 | ||
139 | /* | |
140 | * Encode BGP Route Target AS4:nn. | |
141 | */ | |
d7c0a89a | 142 | static inline void encode_route_target_as4(as_t as, uint16_t val, |
d62a17ae | 143 | struct ecommunity_val *eval) |
c5900768 | 144 | { |
d62a17ae | 145 | eval->val[0] = ECOMMUNITY_ENCODE_AS4; |
146 | eval->val[1] = ECOMMUNITY_ROUTE_TARGET; | |
147 | eval->val[2] = (as >> 24) & 0xff; | |
148 | eval->val[3] = (as >> 16) & 0xff; | |
149 | eval->val[4] = (as >> 8) & 0xff; | |
150 | eval->val[5] = as & 0xff; | |
151 | eval->val[6] = (val >> 8) & 0xff; | |
152 | eval->val[7] = val & 0xff; | |
c5900768 | 153 | } |
154 | ||
d62a17ae | 155 | extern void ecommunity_init(void); |
156 | extern void ecommunity_finish(void); | |
157 | extern void ecommunity_free(struct ecommunity **); | |
d7c0a89a | 158 | extern struct ecommunity *ecommunity_parse(uint8_t *, unsigned short); |
d62a17ae | 159 | extern struct ecommunity *ecommunity_dup(struct ecommunity *); |
160 | extern struct ecommunity *ecommunity_merge(struct ecommunity *, | |
161 | struct ecommunity *); | |
162 | extern struct ecommunity *ecommunity_uniq_sort(struct ecommunity *); | |
163 | extern struct ecommunity *ecommunity_intern(struct ecommunity *); | |
74df8d6d | 164 | extern bool ecommunity_cmp(const void *arg1, const void *arg2); |
d62a17ae | 165 | extern void ecommunity_unintern(struct ecommunity **); |
d8b87afe | 166 | extern unsigned int ecommunity_hash_make(const void *); |
d62a17ae | 167 | extern struct ecommunity *ecommunity_str2com(const char *, int, int); |
168 | extern char *ecommunity_ecom2str(struct ecommunity *, int, int); | |
c7ee6c35 | 169 | extern void ecommunity_strfree(char **s); |
d62a17ae | 170 | extern int ecommunity_match(const struct ecommunity *, |
171 | const struct ecommunity *); | |
172 | extern char *ecommunity_str(struct ecommunity *); | |
173 | extern struct ecommunity_val *ecommunity_lookup(const struct ecommunity *, | |
174 | uint8_t, uint8_t); | |
175 | extern int ecommunity_add_val(struct ecommunity *ecom, | |
176 | struct ecommunity_val *eval); | |
00d252cb | 177 | |
65efcfce | 178 | /* for vpn */ |
d62a17ae | 179 | extern struct ecommunity *ecommunity_new(void); |
180 | extern int ecommunity_add_val(struct ecommunity *, struct ecommunity_val *); | |
181 | extern int ecommunity_strip(struct ecommunity *ecom, uint8_t type, | |
182 | uint8_t subtype); | |
183 | extern struct ecommunity *ecommunity_new(void); | |
44338987 | 184 | extern int ecommunity_del_val(struct ecommunity *ecom, |
185 | struct ecommunity_val *eval); | |
dacf6ec1 PG |
186 | struct bgp_pbr_entry_action; |
187 | extern int ecommunity_fill_pbr_action(struct ecommunity_val *ecom_eval, | |
188 | struct bgp_pbr_entry_action *api); | |
189 | ||
5b820d9e NT |
190 | extern void bgp_compute_aggregate_ecommunity( |
191 | struct bgp_aggregate *aggregate, | |
192 | struct ecommunity *ecommunity); | |
4edd83f9 | 193 | |
194 | extern void bgp_compute_aggregate_ecommunity_hash( | |
195 | struct bgp_aggregate *aggregate, | |
196 | struct ecommunity *ecommunity); | |
197 | extern void bgp_compute_aggregate_ecommunity_val( | |
198 | struct bgp_aggregate *aggregate); | |
5b820d9e NT |
199 | extern void bgp_remove_ecommunity_from_aggregate( |
200 | struct bgp_aggregate *aggregate, | |
201 | struct ecommunity *ecommunity); | |
4edd83f9 | 202 | extern void bgp_remove_ecomm_from_aggregate_hash( |
203 | struct bgp_aggregate *aggregate, | |
204 | struct ecommunity *ecommunity); | |
5b820d9e NT |
205 | extern void bgp_aggr_ecommunity_remove(void *arg); |
206 | ||
00d252cb | 207 | #endif /* _QUAGGA_BGP_ECOMMUNITY_H */ |