]>
Commit | Line | Data |
---|---|---|
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 */ | |
38 | struct 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. */ | |
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; | |
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. */ | |
68 | extern void aspath_init(void); | |
69 | extern void aspath_finish(void); | |
70 | extern struct aspath *aspath_parse(struct stream *s, size_t length, | |
71 | int use32bit, | |
72 | enum asnotation_mode asnotation); | |
73 | ||
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); | |
83 | extern bool aspath_cmp(const void *as1, const void *as2); | |
84 | extern bool aspath_cmp_left(const struct aspath *aspath1, | |
85 | const struct aspath *aspath2); | |
86 | extern bool aspath_cmp_left_confed(const struct aspath *as1, | |
87 | const struct aspath *as2); | |
88 | extern struct aspath *aspath_delete_confed_seq(struct aspath *aspath); | |
89 | extern struct aspath *aspath_empty(enum asnotation_mode asnotation); | |
90 | extern struct aspath *aspath_empty_get(void); | |
91 | extern struct aspath *aspath_str2aspath(const char *str, | |
92 | enum asnotation_mode asnotation); | |
93 | extern void aspath_str_update(struct aspath *as, bool make_json); | |
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); | |
98 | extern void aspath_print_vty(struct vty *vty, struct aspath *aspath); | |
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); | |
104 | extern int aspath_loop_check_confed(struct aspath *aspath, as_t asno); | |
105 | extern bool aspath_private_as_check(struct aspath *aspath); | |
106 | extern struct aspath *aspath_replace_specific_asn(struct aspath *aspath, | |
107 | as_t target_asn, | |
108 | as_t our_asn); | |
109 | extern struct aspath *aspath_replace_all_asn(struct aspath *aspath, | |
110 | as_t our_asn); | |
111 | extern struct aspath *aspath_replace_private_asns(struct aspath *aspath, | |
112 | as_t asn, as_t peer_asn); | |
113 | extern struct aspath *aspath_remove_private_asns(struct aspath *aspath, | |
114 | as_t peer_asn); | |
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); | |
118 | extern unsigned long aspath_count(void); | |
119 | extern unsigned int aspath_count_hops(const struct aspath *aspath); | |
120 | extern bool aspath_check_as_sets(struct aspath *aspath); | |
121 | extern bool aspath_check_as_zero(struct aspath *aspath); | |
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); | |
127 | ||
128 | extern struct aspath *aspath_reconcile_as4(struct aspath *aspath, | |
129 | struct aspath *as4path); | |
130 | extern bool aspath_has_as4(struct aspath *aspath); | |
131 | ||
132 | /* For SNMP BGP4PATHATTRASPATHSEGMENT, might be useful for debug */ | |
133 | extern uint8_t *aspath_snmp_pathseg(struct aspath *aspath, size_t *varlen); | |
134 | ||
135 | extern void bgp_compute_aggregate_aspath(struct bgp_aggregate *aggregate, | |
136 | struct aspath *aspath); | |
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); | |
141 | extern void bgp_remove_aspath_from_aggregate(struct bgp_aggregate *aggregate, | |
142 | struct aspath *aspath); | |
143 | extern void bgp_remove_aspath_from_aggregate_hash( | |
144 | struct bgp_aggregate *aggregate, | |
145 | struct aspath *aspath); | |
146 | ||
147 | extern void bgp_aggr_aspath_remove(void *arg); | |
148 | ||
149 | #endif /* _QUAGGA_BGP_ASPATH_H */ |