]>
Commit | Line | Data |
---|---|---|
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 | 38 | struct 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 | 46 | struct 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 | 68 | extern void aspath_init(void); |
69 | extern void aspath_finish(void); | |
137a38ac | 70 | extern struct aspath *aspath_parse(struct stream *s, size_t length, |
17571c4a PG |
71 | int use32bit, |
72 | enum asnotation_mode asnotation); | |
73 | ||
137a38ac DS |
74 | extern struct aspath *aspath_dup(struct aspath *aspath); |
75 | extern struct aspath *aspath_aggregate(struct aspath *as1, struct aspath *as2); | |
76 | extern struct aspath *aspath_prepend(struct aspath *as1, struct aspath *as2); | |
77 | extern struct aspath *aspath_filter_exclude(struct aspath *source, | |
78 | struct aspath *exclude_list); | |
79 | extern struct aspath *aspath_add_seq_n(struct aspath *aspath, as_t asno, | |
80 | unsigned num); | |
81 | extern struct aspath *aspath_add_seq(struct aspath *aspath, as_t asno); | |
82 | extern struct aspath *aspath_add_confed_seq(struct aspath *aspath, as_t asno); | |
74df8d6d | 83 | extern bool aspath_cmp(const void *as1, const void *as2); |
137a38ac DS |
84 | extern bool aspath_cmp_left(const struct aspath *aspath1, |
85 | const struct aspath *aspath2); | |
74df8d6d | 86 | extern bool aspath_cmp_left_confed(const struct aspath *as1, |
137a38ac DS |
87 | const struct aspath *as2); |
88 | extern struct aspath *aspath_delete_confed_seq(struct aspath *aspath); | |
17571c4a | 89 | extern struct aspath *aspath_empty(enum asnotation_mode asnotation); |
d62a17ae | 90 | extern struct aspath *aspath_empty_get(void); |
17571c4a PG |
91 | extern struct aspath *aspath_str2aspath(const char *str, |
92 | enum asnotation_mode asnotation); | |
68e1a55b | 93 | extern void aspath_str_update(struct aspath *as, bool make_json); |
137a38ac DS |
94 | extern void aspath_free(struct aspath *aspath); |
95 | extern struct aspath *aspath_intern(struct aspath *aspath); | |
96 | extern void aspath_unintern(struct aspath **aspath); | |
97 | extern const char *aspath_print(struct aspath *aspath); | |
e678b143 | 98 | extern void aspath_print_vty(struct vty *vty, struct aspath *aspath); |
137a38ac DS |
99 | extern void aspath_print_all_vty(struct vty *vty); |
100 | extern unsigned int aspath_key_make(const void *p); | |
101 | extern unsigned int aspath_get_first_as(struct aspath *aspath); | |
102 | extern unsigned int aspath_get_last_as(struct aspath *aspath); | |
103 | extern int aspath_loop_check(struct aspath *aspath, as_t asno); | |
b0a8f709 | 104 | extern int aspath_loop_check_confed(struct aspath *aspath, as_t asno); |
137a38ac | 105 | extern bool aspath_private_as_check(struct aspath *aspath); |
d62a17ae | 106 | extern struct aspath *aspath_replace_specific_asn(struct aspath *aspath, |
107 | as_t target_asn, | |
108 | as_t our_asn); | |
77e3d821 DA |
109 | extern struct aspath *aspath_replace_all_asn(struct aspath *aspath, |
110 | as_t our_asn); | |
d62a17ae | 111 | extern struct aspath *aspath_replace_private_asns(struct aspath *aspath, |
bf26b80e DS |
112 | as_t asn, as_t peer_asn); |
113 | extern struct aspath *aspath_remove_private_asns(struct aspath *aspath, | |
114 | as_t peer_asn); | |
137a38ac DS |
115 | extern bool aspath_firstas_check(struct aspath *aspath, as_t asno); |
116 | extern bool aspath_confed_check(struct aspath *aspath); | |
117 | extern bool aspath_left_confed_check(struct aspath *aspath); | |
d62a17ae | 118 | extern unsigned long aspath_count(void); |
137a38ac | 119 | extern unsigned int aspath_count_hops(const struct aspath *aspath); |
fb29348a | 120 | extern bool aspath_check_as_sets(struct aspath *aspath); |
33d022bc | 121 | extern bool aspath_check_as_zero(struct aspath *aspath); |
137a38ac DS |
122 | extern unsigned int aspath_count_confeds(struct aspath *aspath); |
123 | extern unsigned int aspath_size(struct aspath *aspath); | |
124 | extern as_t aspath_highest(struct aspath *aspath); | |
125 | extern as_t aspath_leftmost(struct aspath *aspath); | |
126 | extern size_t aspath_put(struct stream *s, struct aspath *aspath, int use32bit); | |
d62a17ae | 127 | |
137a38ac DS |
128 | extern struct aspath *aspath_reconcile_as4(struct aspath *aspath, |
129 | struct aspath *as4path); | |
130 | extern bool aspath_has_as4(struct aspath *aspath); | |
fe69a505 | 131 | |
132 | /* For SNMP BGP4PATHATTRASPATHSEGMENT, might be useful for debug */ | |
137a38ac | 133 | extern uint8_t *aspath_snmp_pathseg(struct aspath *aspath, size_t *varlen); |
00d252cb | 134 | |
e00d8008 NT |
135 | extern void bgp_compute_aggregate_aspath(struct bgp_aggregate *aggregate, |
136 | struct aspath *aspath); | |
ef51a7d8 | 137 | |
138 | extern void bgp_compute_aggregate_aspath_hash(struct bgp_aggregate *aggregate, | |
139 | struct aspath *aspath); | |
140 | extern void bgp_compute_aggregate_aspath_val(struct bgp_aggregate *aggregate); | |
e00d8008 NT |
141 | extern void bgp_remove_aspath_from_aggregate(struct bgp_aggregate *aggregate, |
142 | struct aspath *aspath); | |
ef51a7d8 | 143 | extern void bgp_remove_aspath_from_aggregate_hash( |
144 | struct bgp_aggregate *aggregate, | |
145 | struct aspath *aspath); | |
146 | ||
e00d8008 NT |
147 | extern void bgp_aggr_aspath_remove(void *arg); |
148 | ||
00d252cb | 149 | #endif /* _QUAGGA_BGP_ASPATH_H */ |