]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_ecommunity.h
bgpd: add flowspec feature
[mirror_frr.git] / bgpd / bgp_ecommunity.h
CommitLineData
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
718e3744 24/* High-order octet of the Extended Communities type field. */
25#define ECOMMUNITY_ENCODE_AS 0x00
26#define ECOMMUNITY_ENCODE_IP 0x01
0b2aa3a0 27#define ECOMMUNITY_ENCODE_AS4 0x02
0014c301 28#define ECOMMUNITY_ENCODE_OPAQUE 0x03
e82202b7 29#define ECOMMUNITY_ENCODE_EVPN 0x06
718e3744 30
0014c301 31/* Low-order octet of the Extended Communities type field. */
718e3744 32#define ECOMMUNITY_ROUTE_TARGET 0x02
33#define ECOMMUNITY_SITE_ORIGIN 0x03
34
128ea8ab 35/* Low-order octet of the Extended Communities type field for EVPN types */
1e27ef50
PG
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
128ea8ab 42#define ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY_FLAG_STICKY 0x01
43
0014c301
LB
44/* Low-order octet of the Extended Communities type field for OPAQUE types */
45#define ECOMMUNITY_OPAQUE_SUBTYPE_ENCAP 0x0c
46
718e3744 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
4372df71 55/* Extended Communities type flag. */
7c40bf39 56#define ECOMMUNITY_FLAG_NON_TRANSITIVE 0x40
4372df71 57
718e3744 58/* Extended Communities attribute. */
d62a17ae 59struct ecommunity {
60 /* Reference counter. */
61 unsigned long refcnt;
718e3744 62
d62a17ae 63 /* Size of Extended Communities attribute. */
64 int size;
718e3744 65
d62a17ae 66 /* Extended Communities value. */
d7c0a89a 67 uint8_t *val;
718e3744 68
d62a17ae 69 /* Human readable format string. */
70 char *str;
718e3744 71};
72
5a0ccebf
QY
73struct ecommunity_as {
74 as_t as;
75 uint32_t val;
76};
77
78struct ecommunity_ip {
79 struct in_addr ip;
80 uint16_t val;
81};
82
718e3744 83/* Extended community value is eight octet. */
d62a17ae 84struct ecommunity_val {
85 char val[ECOMMUNITY_SIZE];
718e3744 86};
87
88#define ecom_length(X) ((X)->size * ECOMMUNITY_SIZE)
89
c5900768 90/*
91 * Encode BGP Route Target AS:nn.
92 */
d7c0a89a 93static inline void encode_route_target_as(as_t as, uint32_t val,
d62a17ae 94 struct ecommunity_val *eval)
c5900768 95{
d62a17ae 96 eval->val[0] = ECOMMUNITY_ENCODE_AS;
97 eval->val[1] = ECOMMUNITY_ROUTE_TARGET;
98 eval->val[2] = (as >> 8) & 0xff;
99 eval->val[3] = as & 0xff;
100 eval->val[4] = (val >> 24) & 0xff;
101 eval->val[5] = (val >> 16) & 0xff;
102 eval->val[6] = (val >> 8) & 0xff;
103 eval->val[7] = val & 0xff;
c5900768 104}
105
106/*
107 * Encode BGP Route Target IP:nn.
108 */
d7c0a89a 109static inline void encode_route_target_ip(struct in_addr ip, uint16_t val,
d62a17ae 110 struct ecommunity_val *eval)
c5900768 111{
d62a17ae 112 eval->val[0] = ECOMMUNITY_ENCODE_IP;
113 eval->val[1] = ECOMMUNITY_ROUTE_TARGET;
114 memcpy(&eval->val[2], &ip, sizeof(struct in_addr));
115 eval->val[6] = (val >> 8) & 0xff;
116 eval->val[7] = val & 0xff;
c5900768 117}
118
119/*
120 * Encode BGP Route Target AS4:nn.
121 */
d7c0a89a 122static inline void encode_route_target_as4(as_t as, uint16_t val,
d62a17ae 123 struct ecommunity_val *eval)
c5900768 124{
d62a17ae 125 eval->val[0] = ECOMMUNITY_ENCODE_AS4;
126 eval->val[1] = ECOMMUNITY_ROUTE_TARGET;
127 eval->val[2] = (as >> 24) & 0xff;
128 eval->val[3] = (as >> 16) & 0xff;
129 eval->val[4] = (as >> 8) & 0xff;
130 eval->val[5] = as & 0xff;
131 eval->val[6] = (val >> 8) & 0xff;
132 eval->val[7] = val & 0xff;
c5900768 133}
134
d62a17ae 135extern void ecommunity_init(void);
136extern void ecommunity_finish(void);
137extern void ecommunity_free(struct ecommunity **);
d7c0a89a 138extern struct ecommunity *ecommunity_parse(uint8_t *, unsigned short);
d62a17ae 139extern struct ecommunity *ecommunity_dup(struct ecommunity *);
140extern struct ecommunity *ecommunity_merge(struct ecommunity *,
141 struct ecommunity *);
142extern struct ecommunity *ecommunity_uniq_sort(struct ecommunity *);
143extern struct ecommunity *ecommunity_intern(struct ecommunity *);
144extern int ecommunity_cmp(const void *, const void *);
145extern void ecommunity_unintern(struct ecommunity **);
146extern unsigned int ecommunity_hash_make(void *);
147extern struct ecommunity *ecommunity_str2com(const char *, int, int);
148extern char *ecommunity_ecom2str(struct ecommunity *, int, int);
149extern int ecommunity_match(const struct ecommunity *,
150 const struct ecommunity *);
151extern char *ecommunity_str(struct ecommunity *);
152extern struct ecommunity_val *ecommunity_lookup(const struct ecommunity *,
153 uint8_t, uint8_t);
154extern int ecommunity_add_val(struct ecommunity *ecom,
155 struct ecommunity_val *eval);
00d252cb 156
65efcfce 157/* for vpn */
d62a17ae 158extern struct ecommunity *ecommunity_new(void);
159extern int ecommunity_add_val(struct ecommunity *, struct ecommunity_val *);
160extern int ecommunity_strip(struct ecommunity *ecom, uint8_t type,
161 uint8_t subtype);
162extern struct ecommunity *ecommunity_new(void);
00d252cb 163#endif /* _QUAGGA_BGP_ECOMMUNITY_H */