]>
Commit | Line | Data |
---|---|---|
fb018d25 DS |
1 | /* |
2 | * Nexthop structure definition. | |
a399694f | 3 | * Copyright (C) 1997, 98, 99, 2001 Kunihiro Ishiguro |
fb018d25 DS |
4 | * Copyright (C) 2013 Cumulus Networks, Inc. |
5 | * | |
a399694f | 6 | * This file is part of Quagga. |
fb018d25 | 7 | * |
a399694f | 8 | * Quagga is free software; you can redistribute it and/or modify it |
fb018d25 DS |
9 | * under the terms of the GNU General Public License as published by the |
10 | * Free Software Foundation; either version 2, or (at your option) any | |
11 | * later version. | |
12 | * | |
a399694f | 13 | * Quagga is distributed in the hope that it will be useful, but |
fb018d25 DS |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * General Public License for more details. | |
17 | * | |
896014f4 DL |
18 | * You should have received a copy of the GNU General Public License along |
19 | * with this program; see the file COPYING; if not, write to the Free Software | |
20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
fb018d25 DS |
21 | */ |
22 | ||
23 | #ifndef _LIB_NEXTHOP_H | |
24 | #define _LIB_NEXTHOP_H | |
25 | ||
26 | #include "prefix.h" | |
54d48ea1 | 27 | #include "mpls.h" |
f2a0ba3a | 28 | #include "vxlan.h" |
cb7775a9 | 29 | #include "srv6.h" |
fb018d25 | 30 | |
5e244469 RW |
31 | #ifdef __cplusplus |
32 | extern "C" { | |
33 | #endif | |
34 | ||
80c2442a | 35 | /* Maximum next hop string length - gateway + ifindex */ |
36 | #define NEXTHOP_STRLEN (INET6_ADDRSTRLEN + 30) | |
37 | ||
fb018d25 | 38 | union g_addr { |
d62a17ae | 39 | struct in_addr ipv4; |
40 | struct in6_addr ipv6; | |
fb018d25 DS |
41 | }; |
42 | ||
d62a17ae | 43 | enum nexthop_types_t { |
44 | NEXTHOP_TYPE_IFINDEX = 1, /* Directly connected. */ | |
45 | NEXTHOP_TYPE_IPV4, /* IPv4 nexthop. */ | |
46 | NEXTHOP_TYPE_IPV4_IFINDEX, /* IPv4 nexthop with ifindex. */ | |
47 | NEXTHOP_TYPE_IPV6, /* IPv6 nexthop. */ | |
48 | NEXTHOP_TYPE_IPV6_IFINDEX, /* IPv6 nexthop with ifindex. */ | |
49 | NEXTHOP_TYPE_BLACKHOLE, /* Null0 nexthop. */ | |
fb018d25 | 50 | }; |
09a484dd DL |
51 | |
52 | enum blackhole_type { | |
53 | BLACKHOLE_UNSPEC = 0, | |
54 | BLACKHOLE_NULL, | |
55 | BLACKHOLE_REJECT, | |
56 | BLACKHOLE_ADMINPROHIB, | |
57 | }; | |
fb018d25 | 58 | |
f2a0ba3a RZ |
59 | enum nh_encap_type { |
60 | NET_VXLAN = 100, /* value copied from FPM_NH_ENCAP_VXLAN. */ | |
61 | }; | |
62 | ||
474aebd9 MS |
63 | /* Fixed limit on the number of backup nexthops per primary nexthop */ |
64 | #define NEXTHOP_MAX_BACKUPS 8 | |
65 | ||
66 | /* Backup index value is limited */ | |
67 | #define NEXTHOP_BACKUP_IDX_MAX 255 | |
68 | ||
fb018d25 | 69 | /* Nexthop structure. */ |
d62a17ae | 70 | struct nexthop { |
71 | struct nexthop *next; | |
72 | struct nexthop *prev; | |
fb018d25 | 73 | |
4a7371e9 DS |
74 | /* |
75 | * What vrf is this nexthop associated with? | |
76 | */ | |
77 | vrf_id_t vrf_id; | |
78 | ||
d62a17ae | 79 | /* Interface index. */ |
80 | ifindex_t ifindex; | |
fb018d25 | 81 | |
d62a17ae | 82 | enum nexthop_types_t type; |
fb018d25 | 83 | |
d7c0a89a | 84 | uint8_t flags; |
fb018d25 DS |
85 | #define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */ |
86 | #define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */ | |
87 | #define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */ | |
0641a955 MS |
88 | #define NEXTHOP_FLAG_ONLINK (1 << 3) /* Nexthop should be installed |
89 | * onlink. | |
90 | */ | |
91 | #define NEXTHOP_FLAG_DUPLICATE (1 << 4) /* nexthop duplicates another | |
92 | * active one | |
93 | */ | |
94 | #define NEXTHOP_FLAG_RNH_FILTERED (1 << 5) /* rmap filtered, used by rnh */ | |
defd2ea4 | 95 | #define NEXTHOP_FLAG_HAS_BACKUP (1 << 6) /* Backup nexthop index is set */ |
31f937fb | 96 | #define NEXTHOP_FLAG_SRTE (1 << 7) /* SR-TE color used for BGP traffic */ |
defd2ea4 | 97 | |
996c9314 LB |
98 | #define NEXTHOP_IS_ACTIVE(flags) \ |
99 | (CHECK_FLAG(flags, NEXTHOP_FLAG_ACTIVE) \ | |
100 | && !CHECK_FLAG(flags, NEXTHOP_FLAG_DUPLICATE)) | |
fb018d25 | 101 | |
d62a17ae | 102 | /* Nexthop address */ |
a8309422 DL |
103 | union { |
104 | union g_addr gate; | |
105 | enum blackhole_type bh_type; | |
106 | }; | |
d62a17ae | 107 | union g_addr src; |
108 | union g_addr rmap_src; /* Src is set via routemap */ | |
109 | ||
110 | /* Nexthops obtained by recursive resolution. | |
111 | * | |
112 | * If the nexthop struct needs to be resolved recursively, | |
113 | * NEXTHOP_FLAG_RECURSIVE will be set in flags and the nexthops | |
114 | * obtained by recursive resolution will be added to `resolved'. | |
115 | */ | |
116 | struct nexthop *resolved; | |
117 | /* Recursive parent */ | |
118 | struct nexthop *rparent; | |
119 | ||
120 | /* Type of label(s), if any */ | |
121 | enum lsp_types_t nh_label_type; | |
122 | ||
123 | /* Label(s) associated with this nexthop. */ | |
8ecdb26e | 124 | struct mpls_label_stack *nh_label; |
df7fb580 DS |
125 | |
126 | /* Weight of the nexthop ( for unequal cost ECMP ) */ | |
127 | uint8_t weight; | |
defd2ea4 | 128 | |
474aebd9 | 129 | /* Count and index of corresponding backup nexthop(s) in a backup list; |
defd2ea4 MS |
130 | * only meaningful if the HAS_BACKUP flag is set. |
131 | */ | |
474aebd9 MS |
132 | uint8_t backup_num; |
133 | uint8_t backup_idx[NEXTHOP_MAX_BACKUPS]; | |
f2a0ba3a RZ |
134 | |
135 | /* Encapsulation information. */ | |
136 | enum nh_encap_type nh_encap_type; | |
137 | union { | |
138 | vni_t vni; | |
139 | } nh_encap; | |
31f937fb SM |
140 | |
141 | /* SR-TE color used for matching SR-TE policies */ | |
142 | uint32_t srte_color; | |
cb7775a9 | 143 | |
eab0f8f0 HS |
144 | /* SRv6 information */ |
145 | struct nexthop_srv6 *nh_srv6; | |
fb018d25 DS |
146 | }; |
147 | ||
e4a1ec74 MS |
148 | /* Utility to append one nexthop to another. */ |
149 | #define NEXTHOP_APPEND(to, new) \ | |
150 | do { \ | |
151 | (to)->next = (new); \ | |
152 | (new)->prev = (to); \ | |
153 | (new)->next = NULL; \ | |
154 | } while (0) | |
155 | ||
d62a17ae | 156 | struct nexthop *nexthop_new(void); |
a399694f | 157 | |
d62a17ae | 158 | void nexthop_free(struct nexthop *nexthop); |
159 | void nexthops_free(struct nexthop *nexthop); | |
a399694f | 160 | |
e4a1ec74 MS |
161 | void nexthop_add_labels(struct nexthop *nexthop, enum lsp_types_t ltype, |
162 | uint8_t num_labels, const mpls_label_t *labels); | |
d62a17ae | 163 | void nexthop_del_labels(struct nexthop *); |
eab0f8f0 HS |
164 | void nexthop_add_srv6_seg6local(struct nexthop *nexthop, uint32_t action, |
165 | const struct seg6local_context *ctx); | |
166 | void nexthop_del_srv6_seg6local(struct nexthop *nexthop); | |
167 | void nexthop_add_srv6_seg6(struct nexthop *nexthop, | |
168 | const struct in6_addr *segs); | |
169 | void nexthop_del_srv6_seg6(struct nexthop *nexthop); | |
40c7bdb0 | 170 | |
f3323df2 MS |
171 | /* |
172 | * Allocate a new nexthop object and initialize it from various args. | |
173 | */ | |
174 | struct nexthop *nexthop_from_ifindex(ifindex_t ifindex, vrf_id_t vrf_id); | |
175 | struct nexthop *nexthop_from_ipv4(const struct in_addr *ipv4, | |
176 | const struct in_addr *src, | |
177 | vrf_id_t vrf_id); | |
178 | struct nexthop *nexthop_from_ipv4_ifindex(const struct in_addr *ipv4, | |
179 | const struct in_addr *src, | |
180 | ifindex_t ifindex, vrf_id_t vrf_id); | |
181 | struct nexthop *nexthop_from_ipv6(const struct in6_addr *ipv6, | |
182 | vrf_id_t vrf_id); | |
183 | struct nexthop *nexthop_from_ipv6_ifindex(const struct in6_addr *ipv6, | |
184 | ifindex_t ifindex, vrf_id_t vrf_id); | |
0789eb69 KM |
185 | struct nexthop *nexthop_from_blackhole(enum blackhole_type bh_type, |
186 | vrf_id_t nh_vrf_id); | |
f3323df2 | 187 | |
d36d0d57 QY |
188 | /* |
189 | * Hash a nexthop. Suitable for use with hash tables. | |
190 | * | |
191 | * This function uses the following values when computing the hash: | |
192 | * - vrf_id | |
193 | * - ifindex | |
194 | * - type | |
195 | * - gate | |
196 | * | |
197 | * nexthop | |
198 | * The nexthop to hash | |
199 | * | |
200 | * Returns: | |
201 | * 32-bit hash of nexthop | |
202 | */ | |
1b1fe1c4 | 203 | uint32_t nexthop_hash(const struct nexthop *nexthop); |
73a38187 SW |
204 | /* |
205 | * Hash a nexthop only on word-sized attributes: | |
206 | * - vrf_id | |
207 | * - ifindex | |
208 | * - type | |
209 | * - (some) flags | |
210 | */ | |
211 | uint32_t nexthop_hash_quick(const struct nexthop *nexthop); | |
d36d0d57 | 212 | |
31919191 | 213 | extern bool nexthop_same(const struct nexthop *nh1, const struct nexthop *nh2); |
a5a2d802 SW |
214 | extern bool nexthop_same_no_labels(const struct nexthop *nh1, |
215 | const struct nexthop *nh2); | |
776c3e90 | 216 | extern int nexthop_cmp(const struct nexthop *nh1, const struct nexthop *nh2); |
3c6e0bd4 SW |
217 | extern int nexthop_g_addr_cmp(enum nexthop_types_t type, |
218 | const union g_addr *addr1, | |
219 | const union g_addr *addr2); | |
31919191 | 220 | |
338ec3b8 MS |
221 | /* More-limited comparison function used to detect duplicate nexthops. |
222 | * Returns -1, 0, 1 | |
223 | */ | |
224 | int nexthop_cmp_basic(const struct nexthop *nh1, const struct nexthop *nh2); | |
225 | ||
d62a17ae | 226 | extern const char *nexthop_type_to_str(enum nexthop_types_t nh_type); |
89dc3160 SW |
227 | extern bool nexthop_labels_match(const struct nexthop *nh1, |
228 | const struct nexthop *nh2); | |
fb018d25 | 229 | |
55f93d4b MS |
230 | extern const char *nexthop2str(const struct nexthop *nexthop, |
231 | char *str, int size); | |
17c25e03 SW |
232 | extern struct nexthop *nexthop_next(const struct nexthop *nexthop); |
233 | extern struct nexthop * | |
234 | nexthop_next_active_resolved(const struct nexthop *nexthop); | |
850c85b9 | 235 | extern unsigned int nexthop_level(const struct nexthop *nexthop); |
504d0a40 | 236 | /* Copies to an already allocated nexthop struct */ |
e7addf02 SW |
237 | extern void nexthop_copy(struct nexthop *copy, const struct nexthop *nexthop, |
238 | struct nexthop *rparent); | |
77bf9504 SW |
239 | /* Copies to an already allocated nexthop struct, not including recurse info */ |
240 | extern void nexthop_copy_no_recurse(struct nexthop *copy, | |
241 | const struct nexthop *nexthop, | |
242 | struct nexthop *rparent); | |
504d0a40 SW |
243 | /* Duplicates a nexthop and returns the newly allocated nexthop */ |
244 | extern struct nexthop *nexthop_dup(const struct nexthop *nexthop, | |
245 | struct nexthop *rparent); | |
77bf9504 SW |
246 | /* Duplicates a nexthop and returns the newly allocated nexthop */ |
247 | extern struct nexthop *nexthop_dup_no_recurse(const struct nexthop *nexthop, | |
248 | struct nexthop *rparent); | |
5e244469 | 249 | |
0cac0cf4 MS |
250 | /* |
251 | * Parse one or more backup index values, as comma-separated numbers, | |
252 | * into caller's array of uint8_ts. The array must be NEXTHOP_MAX_BACKUPS | |
253 | * in size. Mails back the number of values converted, and returns 0 on | |
254 | * success, <0 if an error in parsing. | |
255 | */ | |
256 | int nexthop_str2backups(const char *str, int *num_backups, | |
257 | uint8_t *backups); | |
258 | ||
07ef3e34 DL |
259 | #ifdef _FRR_ATTRIBUTE_PRINTFRR |
260 | #pragma FRR printfrr_ext "%pNH" (struct nexthop *) | |
261 | #endif | |
262 | ||
5e244469 RW |
263 | #ifdef __cplusplus |
264 | } | |
265 | #endif | |
266 | ||
fb018d25 | 267 | #endif /*_LIB_NEXTHOP_H */ |