]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_community.h
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / bgpd / bgp_community.h
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
718e3744 2/* Community attribute related functions.
896014f4 3 * Copyright (C) 1998 Kunihiro Ishiguro
896014f4 4 */
718e3744 5
00d252cb 6#ifndef _QUAGGA_BGP_COMMUNITY_H
7#define _QUAGGA_BGP_COMMUNITY_H
8
f1aa5d8a 9#include "lib/json.h"
c0d7a6cc 10#include "bgpd/bgp_route.h"
46dbf9d0 11#include "bgpd/bgp_attr.h"
f1aa5d8a 12
718e3744 13/* Communities attribute. */
d62a17ae 14struct community {
15 /* Reference count of communities value. */
16 unsigned long refcnt;
718e3744 17
d62a17ae 18 /* Communities value size. */
19 int size;
718e3744 20
d62a17ae 21 /* Communities value. */
d7c0a89a 22 uint32_t *val;
718e3744 23
d62a17ae 24 /* Communities as a json object */
25 json_object *json;
f1aa5d8a 26
d62a17ae 27 /* String of community attribute. This sring is used by vty output
28 and expanded community-list for regular expression match. */
29 char *str;
718e3744 30};
31
32/* Well-known communities value. */
81a57d81
DA
33#if CONFDATE > 20230801
34CPP_NOTICE("Deprecate COMMUNITY_INTERNET BGP community")
35#endif
aa861c10
C
36#define COMMUNITY_INTERNET 0x0
37#define COMMUNITY_GSHUT 0xFFFF0000
38#define COMMUNITY_ACCEPT_OWN 0xFFFF0001
39#define COMMUNITY_ROUTE_FILTER_TRANSLATED_v4 0xFFFF0002
40#define COMMUNITY_ROUTE_FILTER_v4 0xFFFF0003
41#define COMMUNITY_ROUTE_FILTER_TRANSLATED_v6 0xFFFF0004
42#define COMMUNITY_ROUTE_FILTER_v6 0xFFFF0005
43#define COMMUNITY_LLGR_STALE 0xFFFF0006
44#define COMMUNITY_NO_LLGR 0xFFFF0007
45#define COMMUNITY_ACCEPT_OWN_NEXTHOP 0xFFFF0008
46#define COMMUNITY_BLACKHOLE 0xFFFF029A
47#define COMMUNITY_NO_EXPORT 0xFFFFFF01
48#define COMMUNITY_NO_ADVERTISE 0xFFFFFF02
49#define COMMUNITY_NO_EXPORT_SUBCONFED 0xFFFFFF03
50#define COMMUNITY_LOCAL_AS 0xFFFFFF03
51#define COMMUNITY_NO_PEER 0xFFFFFF04
718e3744 52
11400e73
DA
53#define COMMUNITY_SIZE 4
54
718e3744 55/* Macros of community attribute. */
11400e73 56#define com_length(X) ((X)->size * COMMUNITY_SIZE)
718e3744 57#define com_lastval(X) ((X)->val + (X)->size - 1)
58#define com_nthval(X,n) ((X)->val + (n))
59
60/* Prototypes of communities attribute functions. */
d62a17ae 61extern void community_init(void);
62extern void community_finish(void);
3c1f53de 63extern void community_free(struct community **comm);
4627226d
DS
64extern struct community *community_uniq_sort(struct community *com);
65extern struct community *community_parse(uint32_t *pnt, unsigned short length);
66extern struct community *community_intern(struct community *com);
67extern void community_unintern(struct community **com);
68extern char *community_str(struct community *com, bool make_json,
c0945b78 69 bool translate_alias);
4627226d
DS
70extern unsigned int community_hash_make(const struct community *com);
71extern struct community *community_str2com(const char *str);
72extern bool community_match(const struct community *com1,
73 const struct community *com2);
74df8d6d
DS
74extern bool community_cmp(const struct community *c1,
75 const struct community *c2);
4627226d
DS
76extern struct community *community_merge(struct community *com1,
77 struct community *com2);
78extern struct community *community_delete(struct community *com1,
79 struct community *com2);
80extern struct community *community_dup(struct community *com);
81extern bool community_include(struct community *com, uint32_t val);
2721dd61 82extern void community_add_val(struct community *com, uint32_t val);
4627226d 83extern void community_del_val(struct community *com, uint32_t *val);
d62a17ae 84extern unsigned long community_count(void);
85extern struct hash *community_hash(void);
d7c0a89a 86extern uint32_t community_val_get(struct community *com, int i);
c0d7a6cc
NT
87extern void bgp_compute_aggregate_community(struct bgp_aggregate *aggregate,
88 struct community *community);
21fec674 89
90extern void bgp_compute_aggregate_community_val(
91 struct bgp_aggregate *aggregate);
92extern void bgp_compute_aggregate_community_hash(
93 struct bgp_aggregate *aggregate,
94 struct community *community);
c0d7a6cc
NT
95extern void bgp_remove_community_from_aggregate(struct bgp_aggregate *aggregate,
96 struct community *community);
21fec674 97extern void bgp_remove_comm_from_aggregate_hash(struct bgp_aggregate *aggregate,
98 struct community *community);
c0d7a6cc 99extern void bgp_aggr_community_remove(void *arg);
00d252cb 100
46dbf9d0
DA
101/* This implies that when propagating routes into a VRF, the ACCEPT_OWN
102 * community SHOULD NOT be propagated.
103 */
104static inline void community_strip_accept_own(struct attr *attr)
105{
106 struct community *old_com = bgp_attr_get_community(attr);
107 struct community *new_com = NULL;
108 uint32_t val = COMMUNITY_ACCEPT_OWN;
109
110 if (old_com && community_include(old_com, val)) {
111 new_com = community_dup(old_com);
112 val = htonl(val);
113 community_del_val(new_com, &val);
114
115 if (!old_com->refcnt)
116 community_free(&old_com);
117
118 if (!new_com->size) {
119 community_free(&new_com);
120 bgp_attr_set_community(attr, NULL);
121 } else {
122 bgp_attr_set_community(attr, new_com);
123 }
124 }
125}
126
00d252cb 127#endif /* _QUAGGA_BGP_COMMUNITY_H */