]> git.proxmox.com Git - mirror_frr.git/blame_incremental - bgpd/bgp_aspath.h
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / bgpd / bgp_aspath.h
... / ...
CommitLineData
1// SPDX-License-Identifier: GPL-2.0-or-later
2/* AS path related definitions.
3 * Copyright (C) 1997, 98, 99 Kunihiro Ishiguro
4 */
5
6#ifndef _QUAGGA_BGP_ASPATH_H
7#define _QUAGGA_BGP_ASPATH_H
8
9#include "lib/json.h"
10#include "bgpd/bgp_route.h"
11
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. */
19#define BGP_PRIVATE_AS_MIN 64512U
20#define BGP_PRIVATE_AS_MAX UINT16_MAX
21
22/* Private 4 byte AS range defined in RFC6996. */
23#define BGP_PRIVATE_AS4_MIN 4200000000U
24#define BGP_PRIVATE_AS4_MAX 4294967294U
25
26/* we leave BGP_AS_MAX as the 16bit AS MAX number. */
27#define BGP_AS_ZERO 0
28#define BGP_AS_MAX UINT16_MAX
29#define BGP_AS4_MAX 4294967295U
30/* Transition 16Bit AS as defined by IANA */
31#define BGP_AS_TRANS 23456U
32
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))
36
37/* AS_PATH segment data in abstracted form, no limit is placed on length */
38struct assegment {
39 struct assegment *next;
40 as_t *as;
41 unsigned short length;
42 uint8_t type;
43};
44
45/* AS path may be include some AsSegments. */
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;
60
61 /* AS notation used by string expression of AS path */
62 enum asnotation_mode asnotation;
63};
64
65#define ASPATH_STR_DEFAULT_LEN 32
66
67/* Prototypes. */
68extern void aspath_init(void);
69extern void aspath_finish(void);
70extern struct aspath *aspath_parse(struct stream *s, size_t length,
71 int use32bit,
72 enum asnotation_mode asnotation);
73
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);
83extern bool aspath_cmp(const void *as1, const void *as2);
84extern bool aspath_cmp_left(const struct aspath *aspath1,
85 const struct aspath *aspath2);
86extern bool aspath_cmp_left_confed(const struct aspath *as1,
87 const struct aspath *as2);
88extern struct aspath *aspath_delete_confed_seq(struct aspath *aspath);
89extern struct aspath *aspath_empty(enum asnotation_mode asnotation);
90extern struct aspath *aspath_empty_get(void);
91extern struct aspath *aspath_str2aspath(const char *str,
92 enum asnotation_mode asnotation);
93extern void aspath_str_update(struct aspath *as, bool make_json);
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);
98extern void aspath_print_vty(struct vty *vty, struct aspath *aspath);
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);
104extern int aspath_loop_check_confed(struct aspath *aspath, as_t asno);
105extern bool aspath_private_as_check(struct aspath *aspath);
106extern struct aspath *aspath_replace_specific_asn(struct aspath *aspath,
107 as_t target_asn,
108 as_t our_asn);
109extern struct aspath *aspath_replace_all_asn(struct aspath *aspath,
110 as_t our_asn);
111extern struct aspath *aspath_replace_private_asns(struct aspath *aspath,
112 as_t asn, as_t peer_asn);
113extern struct aspath *aspath_remove_private_asns(struct aspath *aspath,
114 as_t peer_asn);
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);
118extern unsigned long aspath_count(void);
119extern unsigned int aspath_count_hops(const struct aspath *aspath);
120extern bool aspath_check_as_sets(struct aspath *aspath);
121extern bool aspath_check_as_zero(struct aspath *aspath);
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);
127
128extern struct aspath *aspath_reconcile_as4(struct aspath *aspath,
129 struct aspath *as4path);
130extern bool aspath_has_as4(struct aspath *aspath);
131
132/* For SNMP BGP4PATHATTRASPATHSEGMENT, might be useful for debug */
133extern uint8_t *aspath_snmp_pathseg(struct aspath *aspath, size_t *varlen);
134
135extern void bgp_compute_aggregate_aspath(struct bgp_aggregate *aggregate,
136 struct aspath *aspath);
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);
141extern void bgp_remove_aspath_from_aggregate(struct bgp_aggregate *aggregate,
142 struct aspath *aspath);
143extern void bgp_remove_aspath_from_aggregate_hash(
144 struct bgp_aggregate *aggregate,
145 struct aspath *aspath);
146
147extern void bgp_aggr_aspath_remove(void *arg);
148
149#endif /* _QUAGGA_BGP_ASPATH_H */