]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_ecommunity.h
Merge remote-tracking branch 'origin/master' into evpn_plus_struct_attr
[mirror_frr.git] / bgpd / bgp_ecommunity.h
1 /* BGP Extended Communities Attribute.
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 */
20
21 #ifndef _QUAGGA_BGP_ECOMMUNITY_H
22 #define _QUAGGA_BGP_ECOMMUNITY_H
23
24 /* High-order octet of the Extended Communities type field. */
25 #define ECOMMUNITY_ENCODE_AS 0x00
26 #define ECOMMUNITY_ENCODE_IP 0x01
27 #define ECOMMUNITY_ENCODE_AS4 0x02
28 #define ECOMMUNITY_ENCODE_OPAQUE 0x03
29 #define ECOMMUNITY_ENCODE_EVPN 0x06
30
31 /* Low-order octet of the Extended Communities type field. */
32 #define ECOMMUNITY_ROUTE_TARGET 0x02
33 #define ECOMMUNITY_SITE_ORIGIN 0x03
34
35 /* Low-order octet of the Extended Communities type field for EVPN types */
36 #define ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY 0x00
37 #define ECOMMUNITY_EVPN_SUBTYPE_ESI_LABEL 0x01
38 #define ECOMMUNITY_EVPN_SUBTYPE_ES_IMPORT_RT 0x02
39 #define ECOMMUNITY_EVPN_SUBTYPE_ROUTERMAC 0x03
40 #define ECOMMUNITY_EVPN_SUBTYPE_DEF_GW 0x0d
41
42 #define ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY_FLAG_STICKY 0x01
43
44 /* Low-order octet of the Extended Communities type field for OPAQUE types */
45 #define ECOMMUNITY_OPAQUE_SUBTYPE_ENCAP 0x0c
46
47 /* Extended communities attribute string format. */
48 #define ECOMMUNITY_FORMAT_ROUTE_MAP 0
49 #define ECOMMUNITY_FORMAT_COMMUNITY_LIST 1
50 #define ECOMMUNITY_FORMAT_DISPLAY 2
51
52 /* Extended Communities value is eight octet long. */
53 #define ECOMMUNITY_SIZE 8
54
55 /* Extended Communities type flag. */
56 #define ECOMMUNITY_FLAG_NON_TRANSITIVE 0x40
57
58 /* Extended Communities attribute. */
59 struct ecommunity
60 {
61 /* Reference counter. */
62 unsigned long refcnt;
63
64 /* Size of Extended Communities attribute. */
65 int size;
66
67 /* Extended Communities value. */
68 u_int8_t *val;
69
70 /* Human readable format string. */
71 char *str;
72 };
73
74 /* Extended community value is eight octet. */
75 struct ecommunity_val
76 {
77 char val[ECOMMUNITY_SIZE];
78 };
79
80 #define ecom_length(X) ((X)->size * ECOMMUNITY_SIZE)
81
82 /*
83 * Encode BGP Route Target AS:nn.
84 */
85 static inline void
86 encode_route_target_as (as_t as, u_int32_t val,
87 struct ecommunity_val *eval)
88 {
89 eval->val[0] = ECOMMUNITY_ENCODE_AS;
90 eval->val[1] = ECOMMUNITY_ROUTE_TARGET;
91 eval->val[2] = (as >> 8) & 0xff;
92 eval->val[3] = as & 0xff;
93 eval->val[4] = (val >> 24) & 0xff;
94 eval->val[5] = (val >> 16) & 0xff;
95 eval->val[6] = (val >> 8) & 0xff;
96 eval->val[7] = val & 0xff;
97 }
98
99 /*
100 * Encode BGP Route Target IP:nn.
101 */
102 static inline void
103 encode_route_target_ip (struct in_addr ip, u_int16_t val,
104 struct ecommunity_val *eval)
105 {
106 eval->val[0] = ECOMMUNITY_ENCODE_IP;
107 eval->val[1] = ECOMMUNITY_ROUTE_TARGET;
108 memcpy (&eval->val[2], &ip, sizeof (struct in_addr));
109 eval->val[6] = (val >> 8) & 0xff;
110 eval->val[7] = val & 0xff;
111 }
112
113 /*
114 * Encode BGP Route Target AS4:nn.
115 */
116 static inline void
117 encode_route_target_as4 (as_t as, u_int16_t val,
118 struct ecommunity_val *eval)
119 {
120 eval->val[0] = ECOMMUNITY_ENCODE_AS4;
121 eval->val[1] = ECOMMUNITY_ROUTE_TARGET;
122 eval->val[2] = (as >> 24) & 0xff;
123 eval->val[3] = (as >> 16) & 0xff;
124 eval->val[4] = (as >> 8) & 0xff;
125 eval->val[5] = as & 0xff;
126 eval->val[6] = (val >> 8) & 0xff;
127 eval->val[7] = val & 0xff;
128 }
129
130 extern void ecommunity_init (void);
131 extern void ecommunity_finish (void);
132 extern void ecommunity_free (struct ecommunity **);
133 extern struct ecommunity *ecommunity_parse (u_int8_t *, u_short);
134 extern struct ecommunity *ecommunity_dup (struct ecommunity *);
135 extern struct ecommunity *ecommunity_merge (struct ecommunity *, struct ecommunity *);
136 extern struct ecommunity *ecommunity_uniq_sort (struct ecommunity *);
137 extern struct ecommunity *ecommunity_intern (struct ecommunity *);
138 extern int ecommunity_cmp (const void *, const void *);
139 extern void ecommunity_unintern (struct ecommunity **);
140 extern unsigned int ecommunity_hash_make (void *);
141 extern struct ecommunity *ecommunity_str2com (const char *, int, int);
142 extern char *ecommunity_ecom2str (struct ecommunity *, int, int);
143 extern int ecommunity_match (const struct ecommunity *, const struct ecommunity *);
144 extern char *ecommunity_str (struct ecommunity *);
145 extern struct ecommunity_val *ecommunity_lookup (const struct ecommunity *, uint8_t, uint8_t );
146 extern int ecommunity_add_val (struct ecommunity *ecom, struct ecommunity_val *eval);
147
148 /* for vpn */
149 extern struct ecommunity *ecommunity_new (void);
150 extern int ecommunity_add_val (struct ecommunity *, struct ecommunity_val *);
151 extern int ecommunity_strip (struct ecommunity *ecom, uint8_t type, uint8_t subtype);
152 extern struct ecommunity *ecommunity_new (void);
153 #endif /* _QUAGGA_BGP_ECOMMUNITY_H */