]>
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" |
fb018d25 | 29 | |
5e244469 RW |
30 | #ifdef __cplusplus |
31 | extern "C" { | |
32 | #endif | |
33 | ||
80c2442a | 34 | /* Maximum next hop string length - gateway + ifindex */ |
35 | #define NEXTHOP_STRLEN (INET6_ADDRSTRLEN + 30) | |
36 | ||
fb018d25 | 37 | union g_addr { |
d62a17ae | 38 | struct in_addr ipv4; |
39 | struct in6_addr ipv6; | |
fb018d25 DS |
40 | }; |
41 | ||
d62a17ae | 42 | enum nexthop_types_t { |
43 | NEXTHOP_TYPE_IFINDEX = 1, /* Directly connected. */ | |
44 | NEXTHOP_TYPE_IPV4, /* IPv4 nexthop. */ | |
45 | NEXTHOP_TYPE_IPV4_IFINDEX, /* IPv4 nexthop with ifindex. */ | |
46 | NEXTHOP_TYPE_IPV6, /* IPv6 nexthop. */ | |
47 | NEXTHOP_TYPE_IPV6_IFINDEX, /* IPv6 nexthop with ifindex. */ | |
48 | NEXTHOP_TYPE_BLACKHOLE, /* Null0 nexthop. */ | |
fb018d25 | 49 | }; |
09a484dd DL |
50 | |
51 | enum blackhole_type { | |
52 | BLACKHOLE_UNSPEC = 0, | |
53 | BLACKHOLE_NULL, | |
54 | BLACKHOLE_REJECT, | |
55 | BLACKHOLE_ADMINPROHIB, | |
56 | }; | |
fb018d25 | 57 | |
25b9cb0c | 58 | /* IPV[46] -> IPV[46]_IFINDEX */ |
996c9314 LB |
59 | #define NEXTHOP_FIRSTHOPTYPE(type) \ |
60 | ((type) == NEXTHOP_TYPE_IFINDEX || (type) == NEXTHOP_TYPE_BLACKHOLE) \ | |
61 | ? (type) \ | |
62 | : ((type) | 1) | |
25b9cb0c | 63 | |
f2a0ba3a RZ |
64 | enum nh_encap_type { |
65 | NET_VXLAN = 100, /* value copied from FPM_NH_ENCAP_VXLAN. */ | |
66 | }; | |
67 | ||
fb018d25 | 68 | /* Nexthop structure. */ |
d62a17ae | 69 | struct nexthop { |
70 | struct nexthop *next; | |
71 | struct nexthop *prev; | |
fb018d25 | 72 | |
4a7371e9 DS |
73 | /* |
74 | * What vrf is this nexthop associated with? | |
75 | */ | |
76 | vrf_id_t vrf_id; | |
77 | ||
d62a17ae | 78 | /* Interface index. */ |
79 | ifindex_t ifindex; | |
fb018d25 | 80 | |
d62a17ae | 81 | enum nexthop_types_t type; |
fb018d25 | 82 | |
d7c0a89a | 83 | uint8_t flags; |
fb018d25 DS |
84 | #define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */ |
85 | #define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */ | |
86 | #define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */ | |
0641a955 MS |
87 | #define NEXTHOP_FLAG_ONLINK (1 << 3) /* Nexthop should be installed |
88 | * onlink. | |
89 | */ | |
90 | #define NEXTHOP_FLAG_DUPLICATE (1 << 4) /* nexthop duplicates another | |
91 | * active one | |
92 | */ | |
93 | #define NEXTHOP_FLAG_RNH_FILTERED (1 << 5) /* rmap filtered, used by rnh */ | |
defd2ea4 MS |
94 | #define NEXTHOP_FLAG_HAS_BACKUP (1 << 6) /* Backup nexthop index is set */ |
95 | ||
996c9314 LB |
96 | #define NEXTHOP_IS_ACTIVE(flags) \ |
97 | (CHECK_FLAG(flags, NEXTHOP_FLAG_ACTIVE) \ | |
98 | && !CHECK_FLAG(flags, NEXTHOP_FLAG_DUPLICATE)) | |
fb018d25 | 99 | |
d62a17ae | 100 | /* Nexthop address */ |
a8309422 DL |
101 | union { |
102 | union g_addr gate; | |
103 | enum blackhole_type bh_type; | |
104 | }; | |
d62a17ae | 105 | union g_addr src; |
106 | union g_addr rmap_src; /* Src is set via routemap */ | |
107 | ||
108 | /* Nexthops obtained by recursive resolution. | |
109 | * | |
110 | * If the nexthop struct needs to be resolved recursively, | |
111 | * NEXTHOP_FLAG_RECURSIVE will be set in flags and the nexthops | |
112 | * obtained by recursive resolution will be added to `resolved'. | |
113 | */ | |
114 | struct nexthop *resolved; | |
115 | /* Recursive parent */ | |
116 | struct nexthop *rparent; | |
117 | ||
118 | /* Type of label(s), if any */ | |
119 | enum lsp_types_t nh_label_type; | |
120 | ||
121 | /* Label(s) associated with this nexthop. */ | |
8ecdb26e | 122 | struct mpls_label_stack *nh_label; |
df7fb580 DS |
123 | |
124 | /* Weight of the nexthop ( for unequal cost ECMP ) */ | |
125 | uint8_t weight; | |
defd2ea4 MS |
126 | |
127 | /* Index of a corresponding backup nexthop in a backup list; | |
128 | * only meaningful if the HAS_BACKUP flag is set. | |
129 | */ | |
130 | uint8_t backup_idx; | |
f2a0ba3a RZ |
131 | |
132 | /* Encapsulation information. */ | |
133 | enum nh_encap_type nh_encap_type; | |
134 | union { | |
135 | vni_t vni; | |
136 | } nh_encap; | |
fb018d25 DS |
137 | }; |
138 | ||
defd2ea4 MS |
139 | /* Backup index value is limited */ |
140 | #define NEXTHOP_BACKUP_IDX_MAX 255 | |
e4a1ec74 MS |
141 | |
142 | /* Utility to append one nexthop to another. */ | |
143 | #define NEXTHOP_APPEND(to, new) \ | |
144 | do { \ | |
145 | (to)->next = (new); \ | |
146 | (new)->prev = (to); \ | |
147 | (new)->next = NULL; \ | |
148 | } while (0) | |
149 | ||
d62a17ae | 150 | struct nexthop *nexthop_new(void); |
a399694f | 151 | |
d62a17ae | 152 | void nexthop_free(struct nexthop *nexthop); |
153 | void nexthops_free(struct nexthop *nexthop); | |
a399694f | 154 | |
e4a1ec74 MS |
155 | void nexthop_add_labels(struct nexthop *nexthop, enum lsp_types_t ltype, |
156 | uint8_t num_labels, const mpls_label_t *labels); | |
d62a17ae | 157 | void nexthop_del_labels(struct nexthop *); |
40c7bdb0 | 158 | |
f3323df2 MS |
159 | /* |
160 | * Allocate a new nexthop object and initialize it from various args. | |
161 | */ | |
162 | struct nexthop *nexthop_from_ifindex(ifindex_t ifindex, vrf_id_t vrf_id); | |
163 | struct nexthop *nexthop_from_ipv4(const struct in_addr *ipv4, | |
164 | const struct in_addr *src, | |
165 | vrf_id_t vrf_id); | |
166 | struct nexthop *nexthop_from_ipv4_ifindex(const struct in_addr *ipv4, | |
167 | const struct in_addr *src, | |
168 | ifindex_t ifindex, vrf_id_t vrf_id); | |
169 | struct nexthop *nexthop_from_ipv6(const struct in6_addr *ipv6, | |
170 | vrf_id_t vrf_id); | |
171 | struct nexthop *nexthop_from_ipv6_ifindex(const struct in6_addr *ipv6, | |
172 | ifindex_t ifindex, vrf_id_t vrf_id); | |
173 | struct nexthop *nexthop_from_blackhole(enum blackhole_type bh_type); | |
174 | ||
d36d0d57 QY |
175 | /* |
176 | * Hash a nexthop. Suitable for use with hash tables. | |
177 | * | |
178 | * This function uses the following values when computing the hash: | |
179 | * - vrf_id | |
180 | * - ifindex | |
181 | * - type | |
182 | * - gate | |
183 | * | |
184 | * nexthop | |
185 | * The nexthop to hash | |
186 | * | |
187 | * Returns: | |
188 | * 32-bit hash of nexthop | |
189 | */ | |
1b1fe1c4 | 190 | uint32_t nexthop_hash(const struct nexthop *nexthop); |
73a38187 SW |
191 | /* |
192 | * Hash a nexthop only on word-sized attributes: | |
193 | * - vrf_id | |
194 | * - ifindex | |
195 | * - type | |
196 | * - (some) flags | |
197 | */ | |
198 | uint32_t nexthop_hash_quick(const struct nexthop *nexthop); | |
d36d0d57 | 199 | |
31919191 | 200 | extern bool nexthop_same(const struct nexthop *nh1, const struct nexthop *nh2); |
a5a2d802 SW |
201 | extern bool nexthop_same_no_labels(const struct nexthop *nh1, |
202 | const struct nexthop *nh2); | |
776c3e90 | 203 | extern int nexthop_cmp(const struct nexthop *nh1, const struct nexthop *nh2); |
3c6e0bd4 SW |
204 | extern int nexthop_g_addr_cmp(enum nexthop_types_t type, |
205 | const union g_addr *addr1, | |
206 | const union g_addr *addr2); | |
31919191 | 207 | |
d62a17ae | 208 | extern const char *nexthop_type_to_str(enum nexthop_types_t nh_type); |
89dc3160 SW |
209 | extern bool nexthop_labels_match(const struct nexthop *nh1, |
210 | const struct nexthop *nh2); | |
996c9314 | 211 | extern int nexthop_same_firsthop(struct nexthop *next1, struct nexthop *next2); |
fb018d25 | 212 | |
55f93d4b MS |
213 | extern const char *nexthop2str(const struct nexthop *nexthop, |
214 | char *str, int size); | |
17c25e03 SW |
215 | extern struct nexthop *nexthop_next(const struct nexthop *nexthop); |
216 | extern struct nexthop * | |
217 | nexthop_next_active_resolved(const struct nexthop *nexthop); | |
e3054ee9 | 218 | extern unsigned int nexthop_level(struct nexthop *nexthop); |
504d0a40 | 219 | /* Copies to an already allocated nexthop struct */ |
e7addf02 SW |
220 | extern void nexthop_copy(struct nexthop *copy, const struct nexthop *nexthop, |
221 | struct nexthop *rparent); | |
77bf9504 SW |
222 | /* Copies to an already allocated nexthop struct, not including recurse info */ |
223 | extern void nexthop_copy_no_recurse(struct nexthop *copy, | |
224 | const struct nexthop *nexthop, | |
225 | struct nexthop *rparent); | |
504d0a40 SW |
226 | /* Duplicates a nexthop and returns the newly allocated nexthop */ |
227 | extern struct nexthop *nexthop_dup(const struct nexthop *nexthop, | |
228 | struct nexthop *rparent); | |
77bf9504 SW |
229 | /* Duplicates a nexthop and returns the newly allocated nexthop */ |
230 | extern struct nexthop *nexthop_dup_no_recurse(const struct nexthop *nexthop, | |
231 | struct nexthop *rparent); | |
5e244469 | 232 | |
07ef3e34 DL |
233 | #ifdef _FRR_ATTRIBUTE_PRINTFRR |
234 | #pragma FRR printfrr_ext "%pNH" (struct nexthop *) | |
235 | #endif | |
236 | ||
5e244469 RW |
237 | #ifdef __cplusplus |
238 | } | |
239 | #endif | |
240 | ||
fb018d25 | 241 | #endif /*_LIB_NEXTHOP_H */ |