]>
git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_ecommunity.h
1 /* BGP Extended Communities Attribute.
2 * Copyright (C) 2000 Kunihiro Ishiguro <kunihiro@zebra.org>
4 * This file is part of GNU Zebra.
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
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.
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
21 #ifndef _QUAGGA_BGP_ECOMMUNITY_H
22 #define _QUAGGA_BGP_ECOMMUNITY_H
24 #include "bgpd/bgp_route.h"
25 #include "bgpd/bgpd.h"
27 /* High-order octet of the Extended Communities type field. */
28 #define ECOMMUNITY_ENCODE_AS 0x00
29 #define ECOMMUNITY_ENCODE_IP 0x01
30 #define ECOMMUNITY_ENCODE_AS4 0x02
31 #define ECOMMUNITY_ENCODE_OPAQUE 0x03
32 #define ECOMMUNITY_ENCODE_EVPN 0x06
33 #define ECOMMUNITY_ENCODE_TRANS_EXP 0x80 /* Flow Spec */
34 #define ECOMMUNITY_ENCODE_REDIRECT_IP_NH 0x08 /* Flow Spec */
36 #define ECOMMUNITY_EXTENDED_COMMUNITY_PART_2 0x81
37 #define ECOMMUNITY_EXTENDED_COMMUNITY_PART_3 0x82
39 /* Low-order octet of the Extended Communities type field. */
40 #define ECOMMUNITY_ROUTE_TARGET 0x02
41 #define ECOMMUNITY_SITE_ORIGIN 0x03
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
47 /* from IANA: bgp-extended-communities/bgp-extended-communities.xhtml
48 * 0x0c Flow-spec Redirect to IPv4 - draft-ietf-idr-flowspec-redirect
50 #define ECOMMUNITY_FLOWSPEC_REDIRECT_IPV4 0x0c
52 /* Low-order octet of the Extended Communities type field for EVPN types */
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
58 #define ECOMMUNITY_EVPN_SUBTYPE_ND 0x08
60 #define ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY_FLAG_STICKY 0x01
61 #define ECOMMUNITY_EVPN_SUBTYPE_ND_ROUTER_FLAG 0x01
62 #define ECOMMUNITY_EVPN_SUBTYPE_ND_OVERRIDE_FLAG 0x02
64 /* Low-order octet of the Extended Communities type field for OPAQUE types */
65 #define ECOMMUNITY_OPAQUE_SUBTYPE_ENCAP 0x0c
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
72 /* Extended Communities value is eight octet long. */
73 #define ECOMMUNITY_SIZE 8
75 /* Extended Communities type flag. */
76 #define ECOMMUNITY_FLAG_NON_TRANSITIVE 0x40
78 /* Extended Communities attribute. */
80 /* Reference counter. */
83 /* Size of Extended Communities attribute. */
86 /* Extended Communities value. */
89 /* Human readable format string. */
93 struct ecommunity_as
{
98 struct ecommunity_ip
{
103 /* Extended community value is eight octet. */
104 struct ecommunity_val
{
105 char val
[ECOMMUNITY_SIZE
];
109 * Encode BGP Route Target AS:nn.
111 static inline void encode_route_target_as(as_t as
, uint32_t val
,
112 struct ecommunity_val
*eval
)
114 eval
->val
[0] = ECOMMUNITY_ENCODE_AS
;
115 eval
->val
[1] = ECOMMUNITY_ROUTE_TARGET
;
116 eval
->val
[2] = (as
>> 8) & 0xff;
117 eval
->val
[3] = as
& 0xff;
118 eval
->val
[4] = (val
>> 24) & 0xff;
119 eval
->val
[5] = (val
>> 16) & 0xff;
120 eval
->val
[6] = (val
>> 8) & 0xff;
121 eval
->val
[7] = val
& 0xff;
125 * Encode BGP Route Target IP:nn.
127 static inline void encode_route_target_ip(struct in_addr ip
, uint16_t val
,
128 struct ecommunity_val
*eval
)
130 eval
->val
[0] = ECOMMUNITY_ENCODE_IP
;
131 eval
->val
[1] = ECOMMUNITY_ROUTE_TARGET
;
132 memcpy(&eval
->val
[2], &ip
, sizeof(struct in_addr
));
133 eval
->val
[6] = (val
>> 8) & 0xff;
134 eval
->val
[7] = val
& 0xff;
138 * Encode BGP Route Target AS4:nn.
140 static inline void encode_route_target_as4(as_t as
, uint16_t val
,
141 struct ecommunity_val
*eval
)
143 eval
->val
[0] = ECOMMUNITY_ENCODE_AS4
;
144 eval
->val
[1] = ECOMMUNITY_ROUTE_TARGET
;
145 eval
->val
[2] = (as
>> 24) & 0xff;
146 eval
->val
[3] = (as
>> 16) & 0xff;
147 eval
->val
[4] = (as
>> 8) & 0xff;
148 eval
->val
[5] = as
& 0xff;
149 eval
->val
[6] = (val
>> 8) & 0xff;
150 eval
->val
[7] = val
& 0xff;
153 extern void ecommunity_init(void);
154 extern void ecommunity_finish(void);
155 extern void ecommunity_free(struct ecommunity
**);
156 extern struct ecommunity
*ecommunity_parse(uint8_t *, unsigned short);
157 extern struct ecommunity
*ecommunity_dup(struct ecommunity
*);
158 extern struct ecommunity
*ecommunity_merge(struct ecommunity
*,
159 struct ecommunity
*);
160 extern struct ecommunity
*ecommunity_uniq_sort(struct ecommunity
*);
161 extern struct ecommunity
*ecommunity_intern(struct ecommunity
*);
162 extern bool ecommunity_cmp(const void *arg1
, const void *arg2
);
163 extern void ecommunity_unintern(struct ecommunity
**);
164 extern unsigned int ecommunity_hash_make(const void *);
165 extern struct ecommunity
*ecommunity_str2com(const char *, int, int);
166 extern char *ecommunity_ecom2str(struct ecommunity
*, int, int);
167 extern void ecommunity_strfree(char **s
);
168 extern bool ecommunity_match(const struct ecommunity
*,
169 const struct ecommunity
*);
170 extern char *ecommunity_str(struct ecommunity
*);
171 extern struct ecommunity_val
*ecommunity_lookup(const struct ecommunity
*,
173 extern bool ecommunity_add_val(struct ecommunity
*ecom
,
174 struct ecommunity_val
*eval
);
177 extern struct ecommunity
*ecommunity_new(void);
178 extern bool ecommunity_add_val(struct ecommunity
*, struct ecommunity_val
*);
179 extern bool ecommunity_strip(struct ecommunity
*ecom
, uint8_t type
,
181 extern struct ecommunity
*ecommunity_new(void);
182 extern bool ecommunity_del_val(struct ecommunity
*ecom
,
183 struct ecommunity_val
*eval
);
184 struct bgp_pbr_entry_action
;
185 extern int ecommunity_fill_pbr_action(struct ecommunity_val
*ecom_eval
,
186 struct bgp_pbr_entry_action
*api
);
188 extern void bgp_compute_aggregate_ecommunity(
189 struct bgp_aggregate
*aggregate
,
190 struct ecommunity
*ecommunity
);
192 extern void bgp_compute_aggregate_ecommunity_hash(
193 struct bgp_aggregate
*aggregate
,
194 struct ecommunity
*ecommunity
);
195 extern void bgp_compute_aggregate_ecommunity_val(
196 struct bgp_aggregate
*aggregate
);
197 extern void bgp_remove_ecommunity_from_aggregate(
198 struct bgp_aggregate
*aggregate
,
199 struct ecommunity
*ecommunity
);
200 extern void bgp_remove_ecomm_from_aggregate_hash(
201 struct bgp_aggregate
*aggregate
,
202 struct ecommunity
*ecommunity
);
203 extern void bgp_aggr_ecommunity_remove(void *arg
);
206 static inline void ecommunity_strip_rts(struct ecommunity
*ecom
)
208 uint8_t subtype
= ECOMMUNITY_ROUTE_TARGET
;
210 ecommunity_strip(ecom
, ECOMMUNITY_ENCODE_AS
, subtype
);
211 ecommunity_strip(ecom
, ECOMMUNITY_ENCODE_IP
, subtype
);
212 ecommunity_strip(ecom
, ECOMMUNITY_ENCODE_AS4
, subtype
);
214 #endif /* _QUAGGA_BGP_ECOMMUNITY_H */