]>
Commit | Line | Data |
---|---|---|
ad28e79a SW |
1 | /* Zebra Nexthop Group header. |
2 | * Copyright (C) 2019 Cumulus Networks, Inc. | |
3 | * Donald Sharp | |
4 | * Stephen Worley | |
5 | * | |
6 | * This file is part of FRR. | |
7 | * | |
8 | * FRR is free software; you can redistribute it and/or modify it | |
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 | * | |
13 | * FRR is distributed in the hope that it will be useful, but | |
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 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with FRR; see the file COPYING. If not, write to the Free | |
20 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
21 | * 02111-1307, USA. | |
22 | */ | |
23 | #ifndef __ZEBRA_NHG_H__ | |
24 | #define __ZEBRA_NHG_H__ | |
25 | ||
5463ce26 | 26 | #include "lib/nexthop.h" |
69171da2 | 27 | #include "lib/nexthop_group.h" |
ad28e79a | 28 | |
0c8215cb SW |
29 | /* This struct is used exclusively for dataplane |
30 | * interaction via a dataplane context. | |
31 | * | |
32 | * It is designed to mimic the netlink nexthop_grp | |
33 | * struct in include/linux/nexthop.h | |
34 | */ | |
e22e8001 | 35 | struct nh_grp { |
0c8215cb SW |
36 | uint32_t id; |
37 | uint8_t weight; | |
38 | }; | |
39 | ||
37c6708b | 40 | PREDECL_RBTREE_UNIQ(nhg_connected_tree); |
0c8215cb | 41 | |
53ac1fbb | 42 | /* |
c415d895 | 43 | * Hashtables containing nhg entries is in `zebra_router`. |
53ac1fbb | 44 | */ |
69171da2 | 45 | struct nhg_hash_entry { |
a95b8020 | 46 | uint32_t id; |
77b76fc9 | 47 | afi_t afi; |
69171da2 | 48 | vrf_id_t vrf_id; |
38e40db1 | 49 | int type; |
69171da2 | 50 | |
c415d895 | 51 | struct nexthop_group nhg; |
69171da2 | 52 | |
2614bf87 SW |
53 | /* If this is not a group, it |
54 | * will be a single nexthop | |
55 | * and must have an interface | |
56 | * associated with it. | |
57 | * Otherwise, this will be null. | |
58 | */ | |
59 | struct interface *ifp; | |
60 | ||
69171da2 DS |
61 | uint32_t refcnt; |
62 | uint32_t dplane_ref; | |
c8ee3cdb DS |
63 | |
64 | uint32_t flags; | |
3119f6a1 | 65 | |
0c8215cb | 66 | /* Dependency tree for other entries. |
3119f6a1 SW |
67 | * For instance a group with two |
68 | * nexthops will have two dependencies | |
69 | * pointing to those nhg_hash_entries. | |
0c8215cb SW |
70 | * |
71 | * Using a rb tree here to make lookups | |
72 | * faster with ID's. | |
3119f6a1 | 73 | */ |
37c6708b | 74 | struct nhg_connected_tree_head nhg_depends, nhg_dependents; |
c8ee3cdb DS |
75 | /* |
76 | * Is this nexthop group valid, ie all nexthops are fully resolved. | |
77 | * What is fully resolved? It's a nexthop that is either self contained | |
78 | * and correct( ie no recursive pointer ) or a nexthop that is recursively | |
79 | * resolved and correct. | |
80 | */ | |
38e40db1 | 81 | #define NEXTHOP_GROUP_VALID (1 << 0) |
c8ee3cdb DS |
82 | /* |
83 | * Has this nexthop group been installed? At this point in time, this | |
84 | * means that the data-plane has been told about this nexthop group | |
85 | * and it's possible usage by a route entry. | |
86 | */ | |
38e40db1 | 87 | #define NEXTHOP_GROUP_INSTALLED (1 << 1) |
7f6077d0 SW |
88 | /* |
89 | * Has the nexthop group been queued to be send to the FIB? | |
90 | * The NEXTHOP_GROUP_VALID flag should also be set by this point. | |
91 | */ | |
38e40db1 | 92 | #define NEXTHOP_GROUP_QUEUED (1 << 2) |
98cda54a SW |
93 | /* |
94 | * Is this a nexthop that is recursively resolved? | |
95 | */ | |
38e40db1 SW |
96 | #define NEXTHOP_GROUP_RECURSIVE (1 << 3) |
97 | /* | |
c1da832a SW |
98 | * This is a nexthop group we got from the kernel, it is identical to |
99 | * one we already have. (The kernel allows duplicate nexthops, we don't | |
100 | * since we hash on them). We are only tracking it in our ID table, | |
101 | * it is unusable by our created routes but may be used by routes we get | |
102 | * from the kernel. Therefore, it is unhashable. | |
38e40db1 | 103 | */ |
c1da832a | 104 | #define NEXTHOP_GROUP_UNHASHABLE (1 << 4) |
69171da2 DS |
105 | }; |
106 | ||
38e40db1 SW |
107 | /* Was this one we created, either this session or previously? */ |
108 | #define ZEBRA_NHG_CREATED(NHE) ((NHE->type) == ZEBRA_ROUTE_NHG) | |
109 | ||
e22e8001 SW |
110 | |
111 | enum nhg_ctx_op_e { | |
112 | NHG_CTX_OP_NONE = 0, | |
113 | NHG_CTX_OP_NEW, | |
114 | NHG_CTX_OP_DEL, | |
115 | }; | |
116 | ||
1b366e63 | 117 | enum nhg_ctx_status { |
e22e8001 SW |
118 | NHG_CTX_NONE = 0, |
119 | NHG_CTX_QUEUED, | |
1b366e63 | 120 | NHG_CTX_REQUEUED, |
e22e8001 SW |
121 | NHG_CTX_SUCCESS, |
122 | NHG_CTX_FAILURE, | |
123 | }; | |
124 | ||
125 | /* | |
126 | * Context needed to queue nhg updates on the | |
127 | * work queue. | |
128 | */ | |
129 | struct nhg_ctx { | |
130 | ||
131 | /* Unique ID */ | |
132 | uint32_t id; | |
133 | ||
134 | vrf_id_t vrf_id; | |
135 | afi_t afi; | |
38e40db1 SW |
136 | /* |
137 | * This should only every be ZEBRA_ROUTE_NHG unless we get a a kernel | |
138 | * created nexthop not made by us. | |
139 | */ | |
140 | int type; | |
e22e8001 SW |
141 | |
142 | /* If its a group array, how many? */ | |
143 | uint8_t count; | |
144 | ||
145 | /* Its either a single nexthop or an array of ID's */ | |
146 | union { | |
147 | struct nexthop nh; | |
148 | struct nh_grp grp[MULTIPATH_NUM]; | |
149 | } u; | |
150 | ||
151 | enum nhg_ctx_op_e op; | |
1b366e63 | 152 | enum nhg_ctx_status status; |
e22e8001 SW |
153 | }; |
154 | ||
7c99d51b MS |
155 | /* Global control to disable use of kernel nexthops, if available. We can't |
156 | * force the kernel to support nexthop ids, of course, but we can disable | |
157 | * zebra's use of them, for testing e.g. By default, if the kernel supports | |
158 | * nexthop ids, zebra uses them. | |
159 | */ | |
160 | void zebra_nhg_enable_kernel_nexthops(bool set); | |
161 | bool zebra_nhg_kernel_nexthops_enabled(void); | |
e22e8001 | 162 | |
fe593b78 SW |
163 | /** |
164 | * NHE abstracted tree functions. | |
165 | * Use these where possible instead of the direct ones access ones. | |
166 | */ | |
0eb97b86 MS |
167 | struct nhg_hash_entry *zebra_nhg_alloc(void); |
168 | void zebra_nhg_free(struct nhg_hash_entry *nhe); | |
169 | /* In order to clear a generic hash, we need a generic api, sigh. */ | |
170 | void zebra_nhg_hash_free(void *p); | |
171 | ||
98cda54a | 172 | extern struct nhg_hash_entry *zebra_nhg_resolve(struct nhg_hash_entry *nhe); |
98cda54a | 173 | |
fe593b78 | 174 | extern unsigned int zebra_nhg_depends_count(const struct nhg_hash_entry *nhe); |
0c8215cb | 175 | extern bool zebra_nhg_depends_is_empty(const struct nhg_hash_entry *nhe); |
5948f013 | 176 | |
fe593b78 SW |
177 | extern unsigned int |
178 | zebra_nhg_dependents_count(const struct nhg_hash_entry *nhe); | |
179 | extern bool zebra_nhg_dependents_is_empty(const struct nhg_hash_entry *nhe); | |
3119f6a1 | 180 | |
5948f013 | 181 | /* Lookup ID, doesn't create */ |
d9f5b2f5 | 182 | extern struct nhg_hash_entry *zebra_nhg_lookup_id(uint32_t id); |
d9f5b2f5 | 183 | |
5948f013 | 184 | /* Hash functions */ |
69171da2 | 185 | extern uint32_t zebra_nhg_hash_key(const void *arg); |
a95b8020 | 186 | extern uint32_t zebra_nhg_id_key(const void *arg); |
69171da2 DS |
187 | |
188 | extern bool zebra_nhg_hash_equal(const void *arg1, const void *arg2); | |
d9f5b2f5 | 189 | extern bool zebra_nhg_hash_id_equal(const void *arg1, const void *arg2); |
69171da2 | 190 | |
e22e8001 SW |
191 | /* |
192 | * Process a context off of a queue. | |
193 | * Specifically this should be from | |
194 | * the rib meta queue. | |
195 | */ | |
196 | extern int nhg_ctx_process(struct nhg_ctx *ctx); | |
85f5e761 | 197 | |
e22e8001 SW |
198 | /* Find via kernel nh creation */ |
199 | extern int zebra_nhg_kernel_find(uint32_t id, struct nexthop *nh, | |
200 | struct nh_grp *grp, uint8_t count, | |
38e40db1 SW |
201 | vrf_id_t vrf_id, afi_t afi, int type, |
202 | int startup); | |
9a1588c4 | 203 | /* Del via kernel */ |
88cafda7 | 204 | extern int zebra_nhg_kernel_del(uint32_t id, vrf_id_t vrf_id); |
e22e8001 SW |
205 | |
206 | /* Find via route creation */ | |
7f997721 SW |
207 | extern struct nhg_hash_entry * |
208 | zebra_nhg_rib_find(uint32_t id, struct nexthop_group *nhg, afi_t rt_afi); | |
3057df51 | 209 | |
5948f013 SW |
210 | /* Reference counter functions */ |
211 | extern void zebra_nhg_decrement_ref(struct nhg_hash_entry *nhe); | |
212 | extern void zebra_nhg_increment_ref(struct nhg_hash_entry *nhe); | |
144a1b34 | 213 | |
5948f013 SW |
214 | /* Check validity of nhe, if invalid will update dependents as well */ |
215 | extern void zebra_nhg_check_valid(struct nhg_hash_entry *nhe); | |
216 | ||
217 | /* Convert nhe depends to a grp context that can be passed around safely */ | |
8dbc800f SW |
218 | extern uint8_t zebra_nhg_nhe2grp(struct nh_grp *grp, struct nhg_hash_entry *nhe, |
219 | int size); | |
98cda54a | 220 | |
5948f013 SW |
221 | /* Dataplane install/uninstall */ |
222 | extern void zebra_nhg_install_kernel(struct nhg_hash_entry *nhe); | |
223 | extern void zebra_nhg_uninstall_kernel(struct nhg_hash_entry *nhe); | |
147bad16 | 224 | |
0c8215cb SW |
225 | /* Forward ref of dplane update context type */ |
226 | struct zebra_dplane_ctx; | |
5948f013 SW |
227 | extern void zebra_nhg_dplane_result(struct zebra_dplane_ctx *ctx); |
228 | ||
38e40db1 | 229 | |
5948f013 SW |
230 | /* Sweet the nhg hash tables for old entries on restart */ |
231 | extern void zebra_nhg_sweep_table(struct hash *hash); | |
232 | ||
233 | /* Nexthop resolution processing */ | |
5463ce26 | 234 | struct route_entry; /* Forward ref to avoid circular includes */ |
5948f013 | 235 | extern int nexthop_active_update(struct route_node *rn, struct route_entry *re); |
7c99d51b MS |
236 | |
237 | #endif /* __ZEBRA_NHG_H__ */ |