]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_ecommunity.h
bgpd: Fix peer determination from parent for imported routes
[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
a8d72b61 30#define ECOMMUNITY_ENCODE_TRANS_EXP 0x80 /* Flow Spec */
b72220fc 31#define ECOMMUNITY_ENCODE_REDIRECT_IP_NH 0x08 /* Flow Spec */
a8d72b61
PG
32/* RFC7674 */
33#define ECOMMUNITY_EXTENDED_COMMUNITY_PART_2 0x81
34#define ECOMMUNITY_EXTENDED_COMMUNITY_PART_3 0x82
718e3744 35
0014c301 36/* Low-order octet of the Extended Communities type field. */
718e3744 37#define ECOMMUNITY_ROUTE_TARGET 0x02
38#define ECOMMUNITY_SITE_ORIGIN 0x03
a8d72b61
PG
39#define ECOMMUNITY_TRAFFIC_RATE 0x06 /* Flow Spec */
40#define ECOMMUNITY_TRAFFIC_ACTION 0x07
41#define ECOMMUNITY_REDIRECT_VRF 0x08
42#define ECOMMUNITY_TRAFFIC_MARKING 0x09
43#define ECOMMUNITY_REDIRECT_IP_NH 0x00
718e3744 44
128ea8ab 45/* Low-order octet of the Extended Communities type field for EVPN types */
1e27ef50
PG
46#define ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY 0x00
47#define ECOMMUNITY_EVPN_SUBTYPE_ESI_LABEL 0x01
48#define ECOMMUNITY_EVPN_SUBTYPE_ES_IMPORT_RT 0x02
49#define ECOMMUNITY_EVPN_SUBTYPE_ROUTERMAC 0x03
50#define ECOMMUNITY_EVPN_SUBTYPE_DEF_GW 0x0d
51
128ea8ab 52#define ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY_FLAG_STICKY 0x01
53
0014c301
LB
54/* Low-order octet of the Extended Communities type field for OPAQUE types */
55#define ECOMMUNITY_OPAQUE_SUBTYPE_ENCAP 0x0c
56
718e3744 57/* Extended communities attribute string format. */
58#define ECOMMUNITY_FORMAT_ROUTE_MAP 0
59#define ECOMMUNITY_FORMAT_COMMUNITY_LIST 1
60#define ECOMMUNITY_FORMAT_DISPLAY 2
61
62/* Extended Communities value is eight octet long. */
63#define ECOMMUNITY_SIZE 8
64
4372df71 65/* Extended Communities type flag. */
7c40bf39 66#define ECOMMUNITY_FLAG_NON_TRANSITIVE 0x40
4372df71 67
718e3744 68/* Extended Communities attribute. */
d62a17ae 69struct ecommunity {
70 /* Reference counter. */
71 unsigned long refcnt;
718e3744 72
d62a17ae 73 /* Size of Extended Communities attribute. */
74 int size;
718e3744 75
d62a17ae 76 /* Extended Communities value. */
d7c0a89a 77 uint8_t *val;
718e3744 78
d62a17ae 79 /* Human readable format string. */
80 char *str;
718e3744 81};
82
5a0ccebf
QY
83struct ecommunity_as {
84 as_t as;
85 uint32_t val;
86};
87
88struct ecommunity_ip {
89 struct in_addr ip;
90 uint16_t val;
91};
92
718e3744 93/* Extended community value is eight octet. */
d62a17ae 94struct ecommunity_val {
95 char val[ECOMMUNITY_SIZE];
718e3744 96};
97
98#define ecom_length(X) ((X)->size * ECOMMUNITY_SIZE)
99
c5900768 100/*
101 * Encode BGP Route Target AS:nn.
102 */
d7c0a89a 103static inline void encode_route_target_as(as_t as, uint32_t val,
d62a17ae 104 struct ecommunity_val *eval)
c5900768 105{
d62a17ae 106 eval->val[0] = ECOMMUNITY_ENCODE_AS;
107 eval->val[1] = ECOMMUNITY_ROUTE_TARGET;
108 eval->val[2] = (as >> 8) & 0xff;
109 eval->val[3] = as & 0xff;
110 eval->val[4] = (val >> 24) & 0xff;
111 eval->val[5] = (val >> 16) & 0xff;
112 eval->val[6] = (val >> 8) & 0xff;
113 eval->val[7] = val & 0xff;
c5900768 114}
115
116/*
117 * Encode BGP Route Target IP:nn.
118 */
d7c0a89a 119static inline void encode_route_target_ip(struct in_addr ip, uint16_t val,
d62a17ae 120 struct ecommunity_val *eval)
c5900768 121{
d62a17ae 122 eval->val[0] = ECOMMUNITY_ENCODE_IP;
123 eval->val[1] = ECOMMUNITY_ROUTE_TARGET;
124 memcpy(&eval->val[2], &ip, sizeof(struct in_addr));
125 eval->val[6] = (val >> 8) & 0xff;
126 eval->val[7] = val & 0xff;
c5900768 127}
128
129/*
130 * Encode BGP Route Target AS4:nn.
131 */
d7c0a89a 132static inline void encode_route_target_as4(as_t as, uint16_t val,
d62a17ae 133 struct ecommunity_val *eval)
c5900768 134{
d62a17ae 135 eval->val[0] = ECOMMUNITY_ENCODE_AS4;
136 eval->val[1] = ECOMMUNITY_ROUTE_TARGET;
137 eval->val[2] = (as >> 24) & 0xff;
138 eval->val[3] = (as >> 16) & 0xff;
139 eval->val[4] = (as >> 8) & 0xff;
140 eval->val[5] = as & 0xff;
141 eval->val[6] = (val >> 8) & 0xff;
142 eval->val[7] = val & 0xff;
c5900768 143}
144
d62a17ae 145extern void ecommunity_init(void);
146extern void ecommunity_finish(void);
147extern void ecommunity_free(struct ecommunity **);
d7c0a89a 148extern struct ecommunity *ecommunity_parse(uint8_t *, unsigned short);
d62a17ae 149extern struct ecommunity *ecommunity_dup(struct ecommunity *);
150extern struct ecommunity *ecommunity_merge(struct ecommunity *,
151 struct ecommunity *);
152extern struct ecommunity *ecommunity_uniq_sort(struct ecommunity *);
153extern struct ecommunity *ecommunity_intern(struct ecommunity *);
154extern int ecommunity_cmp(const void *, const void *);
155extern void ecommunity_unintern(struct ecommunity **);
156extern unsigned int ecommunity_hash_make(void *);
157extern struct ecommunity *ecommunity_str2com(const char *, int, int);
158extern char *ecommunity_ecom2str(struct ecommunity *, int, int);
159extern int ecommunity_match(const struct ecommunity *,
160 const struct ecommunity *);
161extern char *ecommunity_str(struct ecommunity *);
162extern struct ecommunity_val *ecommunity_lookup(const struct ecommunity *,
163 uint8_t, uint8_t);
164extern int ecommunity_add_val(struct ecommunity *ecom,
165 struct ecommunity_val *eval);
00d252cb 166
65efcfce 167/* for vpn */
d62a17ae 168extern struct ecommunity *ecommunity_new(void);
169extern int ecommunity_add_val(struct ecommunity *, struct ecommunity_val *);
170extern int ecommunity_strip(struct ecommunity *ecom, uint8_t type,
171 uint8_t subtype);
172extern struct ecommunity *ecommunity_new(void);
44338987 173extern int ecommunity_del_val(struct ecommunity *ecom,
174 struct ecommunity_val *eval);
00d252cb 175#endif /* _QUAGGA_BGP_ECOMMUNITY_H */