]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_aspath.h
bgpd: Refactor subgroup_announce_table() to reuse an existing helpers
[mirror_frr.git] / bgpd / bgp_aspath.h
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
718e3744 2/* AS path related definitions.
896014f4 3 * Copyright (C) 1997, 98, 99 Kunihiro Ishiguro
896014f4 4 */
718e3744 5
00d252cb 6#ifndef _QUAGGA_BGP_ASPATH_H
7#define _QUAGGA_BGP_ASPATH_H
8
f1aa5d8a 9#include "lib/json.h"
e00d8008 10#include "bgpd/bgp_route.h"
f1aa5d8a 11
718e3744 12/* AS path segment type. */
13#define AS_SET 1
14#define AS_SEQUENCE 2
15#define AS_CONFED_SEQUENCE 3
16#define AS_CONFED_SET 4
17
18/* Private AS range defined in RFC2270. */
fd79ac91 19#define BGP_PRIVATE_AS_MIN 64512U
48e1932b 20#define BGP_PRIVATE_AS_MAX UINT16_MAX
fd79ac91 21
2e8142b2
DS
22/* Private 4 byte AS range defined in RFC6996. */
23#define BGP_PRIVATE_AS4_MIN 4200000000U
24#define BGP_PRIVATE_AS4_MAX 4294967294U
25
0b2aa3a0 26/* we leave BGP_AS_MAX as the 16bit AS MAX number. */
33d022bc 27#define BGP_AS_ZERO 0
48e1932b 28#define BGP_AS_MAX UINT16_MAX
0b2aa3a0
PJ
29#define BGP_AS4_MAX 4294967295U
30/* Transition 16Bit AS as defined by IANA */
31#define BGP_AS_TRANS 23456U
718e3744 32
d62a17ae 33#define BGP_AS_IS_PRIVATE(ASN) \
34 (((ASN) >= BGP_PRIVATE_AS_MIN && (ASN) <= BGP_PRIVATE_AS_MAX) \
35 || ((ASN) >= BGP_PRIVATE_AS4_MIN && (ASN) <= BGP_PRIVATE_AS4_MAX))
5000f21c 36
fe69a505 37/* AS_PATH segment data in abstracted form, no limit is placed on length */
d62a17ae 38struct assegment {
39 struct assegment *next;
40 as_t *as;
d7c0a89a
QY
41 unsigned short length;
42 uint8_t type;
fe69a505 43};
44
718e3744 45/* AS path may be include some AsSegments. */
d62a17ae 46struct aspath {
47 /* Reference count to this aspath. */
48 unsigned long refcnt;
49
50 /* segment data */
51 struct assegment *segments;
52
53 /* AS path as a json object */
54 json_object *json;
55
56 /* String expression of AS path. This string is used by vty output
57 and AS path regular expression match. */
58 char *str;
59 unsigned short str_len;
17571c4a
PG
60
61 /* AS notation used by string expression of AS path */
62 enum asnotation_mode asnotation;
718e3744 63};
64
65#define ASPATH_STR_DEFAULT_LEN 32
66
67/* Prototypes. */
d62a17ae 68extern void aspath_init(void);
69extern void aspath_finish(void);
137a38ac 70extern struct aspath *aspath_parse(struct stream *s, size_t length,
17571c4a
PG
71 int use32bit,
72 enum asnotation_mode asnotation);
73
137a38ac
DS
74extern struct aspath *aspath_dup(struct aspath *aspath);
75extern struct aspath *aspath_aggregate(struct aspath *as1, struct aspath *as2);
76extern struct aspath *aspath_prepend(struct aspath *as1, struct aspath *as2);
77extern struct aspath *aspath_filter_exclude(struct aspath *source,
78 struct aspath *exclude_list);
79extern struct aspath *aspath_add_seq_n(struct aspath *aspath, as_t asno,
80 unsigned num);
81extern struct aspath *aspath_add_seq(struct aspath *aspath, as_t asno);
82extern struct aspath *aspath_add_confed_seq(struct aspath *aspath, as_t asno);
74df8d6d 83extern bool aspath_cmp(const void *as1, const void *as2);
137a38ac
DS
84extern bool aspath_cmp_left(const struct aspath *aspath1,
85 const struct aspath *aspath2);
74df8d6d 86extern bool aspath_cmp_left_confed(const struct aspath *as1,
137a38ac
DS
87 const struct aspath *as2);
88extern struct aspath *aspath_delete_confed_seq(struct aspath *aspath);
17571c4a 89extern struct aspath *aspath_empty(enum asnotation_mode asnotation);
d62a17ae 90extern struct aspath *aspath_empty_get(void);
17571c4a
PG
91extern struct aspath *aspath_str2aspath(const char *str,
92 enum asnotation_mode asnotation);
68e1a55b 93extern void aspath_str_update(struct aspath *as, bool make_json);
137a38ac
DS
94extern void aspath_free(struct aspath *aspath);
95extern struct aspath *aspath_intern(struct aspath *aspath);
96extern void aspath_unintern(struct aspath **aspath);
97extern const char *aspath_print(struct aspath *aspath);
e678b143 98extern void aspath_print_vty(struct vty *vty, struct aspath *aspath);
137a38ac
DS
99extern void aspath_print_all_vty(struct vty *vty);
100extern unsigned int aspath_key_make(const void *p);
101extern unsigned int aspath_get_first_as(struct aspath *aspath);
102extern unsigned int aspath_get_last_as(struct aspath *aspath);
103extern int aspath_loop_check(struct aspath *aspath, as_t asno);
b0a8f709 104extern int aspath_loop_check_confed(struct aspath *aspath, as_t asno);
137a38ac 105extern bool aspath_private_as_check(struct aspath *aspath);
d62a17ae 106extern struct aspath *aspath_replace_specific_asn(struct aspath *aspath,
107 as_t target_asn,
108 as_t our_asn);
77e3d821
DA
109extern struct aspath *aspath_replace_all_asn(struct aspath *aspath,
110 as_t our_asn);
d62a17ae 111extern struct aspath *aspath_replace_private_asns(struct aspath *aspath,
bf26b80e
DS
112 as_t asn, as_t peer_asn);
113extern struct aspath *aspath_remove_private_asns(struct aspath *aspath,
114 as_t peer_asn);
137a38ac
DS
115extern bool aspath_firstas_check(struct aspath *aspath, as_t asno);
116extern bool aspath_confed_check(struct aspath *aspath);
117extern bool aspath_left_confed_check(struct aspath *aspath);
d62a17ae 118extern unsigned long aspath_count(void);
137a38ac 119extern unsigned int aspath_count_hops(const struct aspath *aspath);
fb29348a 120extern bool aspath_check_as_sets(struct aspath *aspath);
33d022bc 121extern bool aspath_check_as_zero(struct aspath *aspath);
137a38ac
DS
122extern unsigned int aspath_count_confeds(struct aspath *aspath);
123extern unsigned int aspath_size(struct aspath *aspath);
124extern as_t aspath_highest(struct aspath *aspath);
125extern as_t aspath_leftmost(struct aspath *aspath);
126extern size_t aspath_put(struct stream *s, struct aspath *aspath, int use32bit);
d62a17ae 127
137a38ac
DS
128extern struct aspath *aspath_reconcile_as4(struct aspath *aspath,
129 struct aspath *as4path);
130extern bool aspath_has_as4(struct aspath *aspath);
fe69a505 131
132/* For SNMP BGP4PATHATTRASPATHSEGMENT, might be useful for debug */
137a38ac 133extern uint8_t *aspath_snmp_pathseg(struct aspath *aspath, size_t *varlen);
00d252cb 134
e00d8008
NT
135extern void bgp_compute_aggregate_aspath(struct bgp_aggregate *aggregate,
136 struct aspath *aspath);
ef51a7d8 137
138extern void bgp_compute_aggregate_aspath_hash(struct bgp_aggregate *aggregate,
139 struct aspath *aspath);
140extern void bgp_compute_aggregate_aspath_val(struct bgp_aggregate *aggregate);
e00d8008
NT
141extern void bgp_remove_aspath_from_aggregate(struct bgp_aggregate *aggregate,
142 struct aspath *aspath);
ef51a7d8 143extern void bgp_remove_aspath_from_aggregate_hash(
144 struct bgp_aggregate *aggregate,
145 struct aspath *aspath);
146
e00d8008
NT
147extern void bgp_aggr_aspath_remove(void *arg);
148
00d252cb 149#endif /* _QUAGGA_BGP_ASPATH_H */