]>
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 | ||
26 | #include "zebra/rib.h" | |
69171da2 | 27 | #include "lib/nexthop_group.h" |
ad28e79a | 28 | |
5f3c9e52 SW |
29 | #include "zebra/zebra_dplane.h" |
30 | ||
0c8215cb SW |
31 | /* This struct is used exclusively for dataplane |
32 | * interaction via a dataplane context. | |
33 | * | |
34 | * It is designed to mimic the netlink nexthop_grp | |
35 | * struct in include/linux/nexthop.h | |
36 | */ | |
e22e8001 | 37 | struct nh_grp { |
0c8215cb SW |
38 | uint32_t id; |
39 | uint8_t weight; | |
40 | }; | |
41 | ||
37c6708b | 42 | PREDECL_RBTREE_UNIQ(nhg_connected_tree); |
0c8215cb | 43 | |
69171da2 | 44 | struct nhg_hash_entry { |
a95b8020 | 45 | uint32_t id; |
77b76fc9 | 46 | afi_t afi; |
69171da2 | 47 | vrf_id_t vrf_id; |
38e40db1 | 48 | int type; |
69171da2 | 49 | |
8e401b25 | 50 | struct nexthop_group *nhg; |
69171da2 | 51 | |
2614bf87 SW |
52 | /* If this is not a group, it |
53 | * will be a single nexthop | |
54 | * and must have an interface | |
55 | * associated with it. | |
56 | * Otherwise, this will be null. | |
57 | */ | |
58 | struct interface *ifp; | |
59 | ||
69171da2 DS |
60 | uint32_t refcnt; |
61 | uint32_t dplane_ref; | |
c8ee3cdb DS |
62 | |
63 | uint32_t flags; | |
3119f6a1 | 64 | |
0c8215cb | 65 | /* Dependency tree for other entries. |
3119f6a1 SW |
66 | * For instance a group with two |
67 | * nexthops will have two dependencies | |
68 | * pointing to those nhg_hash_entries. | |
0c8215cb SW |
69 | * |
70 | * Using a rb tree here to make lookups | |
71 | * faster with ID's. | |
3119f6a1 | 72 | */ |
37c6708b | 73 | struct nhg_connected_tree_head nhg_depends, nhg_dependents; |
c8ee3cdb DS |
74 | /* |
75 | * Is this nexthop group valid, ie all nexthops are fully resolved. | |
76 | * What is fully resolved? It's a nexthop that is either self contained | |
77 | * and correct( ie no recursive pointer ) or a nexthop that is recursively | |
78 | * resolved and correct. | |
79 | */ | |
38e40db1 | 80 | #define NEXTHOP_GROUP_VALID (1 << 0) |
c8ee3cdb DS |
81 | /* |
82 | * Has this nexthop group been installed? At this point in time, this | |
83 | * means that the data-plane has been told about this nexthop group | |
84 | * and it's possible usage by a route entry. | |
85 | */ | |
38e40db1 | 86 | #define NEXTHOP_GROUP_INSTALLED (1 << 1) |
7f6077d0 SW |
87 | /* |
88 | * Has the nexthop group been queued to be send to the FIB? | |
89 | * The NEXTHOP_GROUP_VALID flag should also be set by this point. | |
90 | */ | |
38e40db1 | 91 | #define NEXTHOP_GROUP_QUEUED (1 << 2) |
98cda54a SW |
92 | /* |
93 | * Is this a nexthop that is recursively resolved? | |
94 | */ | |
38e40db1 SW |
95 | #define NEXTHOP_GROUP_RECURSIVE (1 << 3) |
96 | /* | |
97 | * This is a duplicate nexthop we got from the kernel, we are only tracking | |
98 | * it in our ID hash table, it is unusable by our routes. | |
99 | */ | |
100 | #define NEXTHOP_GROUP_DUPLICATE (1 << 4) | |
69171da2 DS |
101 | }; |
102 | ||
38e40db1 SW |
103 | /* Was this one we created, either this session or previously? */ |
104 | #define ZEBRA_NHG_CREATED(NHE) ((NHE->type) == ZEBRA_ROUTE_NHG) | |
105 | ||
a15d4c00 SW |
106 | /* Abstraction for connected trees */ |
107 | struct nhg_connected { | |
37c6708b | 108 | struct nhg_connected_tree_item tree_item; |
3119f6a1 SW |
109 | struct nhg_hash_entry *nhe; |
110 | }; | |
111 | ||
37c6708b SW |
112 | static int nhg_connected_cmp(const struct nhg_connected *con1, |
113 | const struct nhg_connected *con2) | |
114 | { | |
115 | return (con1->nhe->id - con2->nhe->id); | |
116 | } | |
117 | ||
118 | DECLARE_RBTREE_UNIQ(nhg_connected_tree, struct nhg_connected, tree_item, | |
119 | nhg_connected_cmp); | |
3119f6a1 | 120 | |
e22e8001 SW |
121 | |
122 | enum nhg_ctx_op_e { | |
123 | NHG_CTX_OP_NONE = 0, | |
124 | NHG_CTX_OP_NEW, | |
125 | NHG_CTX_OP_DEL, | |
126 | }; | |
127 | ||
1b366e63 | 128 | enum nhg_ctx_status { |
e22e8001 SW |
129 | NHG_CTX_NONE = 0, |
130 | NHG_CTX_QUEUED, | |
1b366e63 | 131 | NHG_CTX_REQUEUED, |
e22e8001 SW |
132 | NHG_CTX_SUCCESS, |
133 | NHG_CTX_FAILURE, | |
134 | }; | |
135 | ||
136 | /* | |
137 | * Context needed to queue nhg updates on the | |
138 | * work queue. | |
139 | */ | |
140 | struct nhg_ctx { | |
141 | ||
142 | /* Unique ID */ | |
143 | uint32_t id; | |
144 | ||
145 | vrf_id_t vrf_id; | |
146 | afi_t afi; | |
38e40db1 SW |
147 | /* |
148 | * This should only every be ZEBRA_ROUTE_NHG unless we get a a kernel | |
149 | * created nexthop not made by us. | |
150 | */ | |
151 | int type; | |
e22e8001 SW |
152 | |
153 | /* If its a group array, how many? */ | |
154 | uint8_t count; | |
155 | ||
156 | /* Its either a single nexthop or an array of ID's */ | |
157 | union { | |
158 | struct nexthop nh; | |
159 | struct nh_grp grp[MULTIPATH_NUM]; | |
160 | } u; | |
161 | ||
162 | enum nhg_ctx_op_e op; | |
1b366e63 | 163 | enum nhg_ctx_status status; |
e22e8001 SW |
164 | }; |
165 | ||
166 | ||
69171da2 DS |
167 | void zebra_nhg_init(void); |
168 | void zebra_nhg_terminate(void); | |
169 | ||
fe593b78 SW |
170 | extern void nhg_connected_free(struct nhg_connected *dep); |
171 | extern struct nhg_connected *nhg_connected_new(struct nhg_hash_entry *nhe); | |
172 | ||
173 | /* nhg connected tree direct access functions */ | |
37c6708b SW |
174 | extern void nhg_connected_tree_init(struct nhg_connected_tree_head *head); |
175 | extern void nhg_connected_tree_free(struct nhg_connected_tree_head *head); | |
176 | extern bool | |
177 | nhg_connected_tree_is_empty(const struct nhg_connected_tree_head *head); | |
98cda54a | 178 | extern struct nhg_connected * |
37c6708b SW |
179 | nhg_connected_tree_root(struct nhg_connected_tree_head *head); |
180 | extern void nhg_connected_tree_del_nhe(struct nhg_connected_tree_head *head, | |
181 | struct nhg_hash_entry *nhe); | |
182 | extern void nhg_connected_tree_add_nhe(struct nhg_connected_tree_head *head, | |
183 | struct nhg_hash_entry *nhe); | |
fe593b78 SW |
184 | |
185 | /** | |
186 | * NHE abstracted tree functions. | |
187 | * Use these where possible instead of the direct ones access ones. | |
188 | */ | |
98cda54a SW |
189 | |
190 | ||
191 | extern struct nhg_hash_entry *zebra_nhg_resolve(struct nhg_hash_entry *nhe); | |
192 | extern uint32_t zebra_nhg_get_resolved_id(uint32_t id); | |
193 | ||
fe593b78 SW |
194 | /* Depends */ |
195 | extern unsigned int zebra_nhg_depends_count(const struct nhg_hash_entry *nhe); | |
0c8215cb | 196 | extern bool zebra_nhg_depends_is_empty(const struct nhg_hash_entry *nhe); |
0c8215cb SW |
197 | extern void zebra_nhg_depends_del(struct nhg_hash_entry *from, |
198 | struct nhg_hash_entry *depend); | |
199 | extern void zebra_nhg_depends_add(struct nhg_hash_entry *to, | |
200 | struct nhg_hash_entry *depend); | |
0c8215cb | 201 | extern void zebra_nhg_depends_init(struct nhg_hash_entry *nhe); |
fe593b78 SW |
202 | /* Dependents */ |
203 | extern unsigned int | |
204 | zebra_nhg_dependents_count(const struct nhg_hash_entry *nhe); | |
205 | extern bool zebra_nhg_dependents_is_empty(const struct nhg_hash_entry *nhe); | |
206 | extern void zebra_nhg_dependents_del(struct nhg_hash_entry *from, | |
207 | struct nhg_hash_entry *dependent); | |
208 | extern void zebra_nhg_dependents_add(struct nhg_hash_entry *to, | |
209 | struct nhg_hash_entry *dependent); | |
210 | extern void zebra_nhg_dependents_init(struct nhg_hash_entry *nhe); | |
3119f6a1 | 211 | |
3119f6a1 | 212 | |
d9f5b2f5 SW |
213 | extern struct nhg_hash_entry *zebra_nhg_lookup_id(uint32_t id); |
214 | extern int zebra_nhg_insert_id(struct nhg_hash_entry *nhe); | |
215 | ||
69171da2 | 216 | extern uint32_t zebra_nhg_hash_key(const void *arg); |
a95b8020 | 217 | extern uint32_t zebra_nhg_id_key(const void *arg); |
69171da2 DS |
218 | |
219 | extern bool zebra_nhg_hash_equal(const void *arg1, const void *arg2); | |
d9f5b2f5 | 220 | extern bool zebra_nhg_hash_id_equal(const void *arg1, const void *arg2); |
69171da2 | 221 | |
e22e8001 SW |
222 | /* |
223 | * Process a context off of a queue. | |
224 | * Specifically this should be from | |
225 | * the rib meta queue. | |
226 | */ | |
227 | extern int nhg_ctx_process(struct nhg_ctx *ctx); | |
85f5e761 | 228 | |
e22e8001 SW |
229 | /* Find via kernel nh creation */ |
230 | extern int zebra_nhg_kernel_find(uint32_t id, struct nexthop *nh, | |
231 | struct nh_grp *grp, uint8_t count, | |
38e40db1 SW |
232 | vrf_id_t vrf_id, afi_t afi, int type, |
233 | int startup); | |
9a1588c4 SW |
234 | /* Del via kernel */ |
235 | extern int zebra_nhg_kernel_del(uint32_t id); | |
e22e8001 SW |
236 | |
237 | /* Find via route creation */ | |
7f997721 SW |
238 | extern struct nhg_hash_entry * |
239 | zebra_nhg_rib_find(uint32_t id, struct nexthop_group *nhg, afi_t rt_afi); | |
3057df51 | 240 | |
0c8215cb | 241 | |
b599cd2a | 242 | void zebra_nhg_free_members(struct nhg_hash_entry *nhe); |
d9f5b2f5 | 243 | void zebra_nhg_free(void *arg); |
d9f5b2f5 | 244 | void zebra_nhg_decrement_ref(struct nhg_hash_entry *nhe); |
7fd392cc | 245 | void zebra_nhg_increment_ref(struct nhg_hash_entry *nhe); |
e22e8001 | 246 | |
fe593b78 SW |
247 | void zebra_nhg_set_invalid(struct nhg_hash_entry *nhe); |
248 | void zebra_nhg_set_if(struct nhg_hash_entry *nhe, struct interface *ifp); | |
8b5bdc8b SW |
249 | |
250 | extern int nexthop_active_update(struct route_node *rn, struct route_entry *re); | |
5be96a2d | 251 | |
144a1b34 SW |
252 | extern int zebra_nhg_re_update_ref(struct route_entry *re, |
253 | struct nhg_hash_entry *nhe); | |
254 | ||
8dbc800f SW |
255 | extern uint8_t zebra_nhg_nhe2grp(struct nh_grp *grp, struct nhg_hash_entry *nhe, |
256 | int size); | |
98cda54a | 257 | |
5be96a2d | 258 | void zebra_nhg_install_kernel(struct nhg_hash_entry *nhe); |
147bad16 SW |
259 | void zebra_nhg_uninstall_kernel(struct nhg_hash_entry *nhe); |
260 | ||
38e40db1 | 261 | void zebra_nhg_cleanup_tables(struct hash *hash); |
5f3c9e52 | 262 | |
0c8215cb SW |
263 | /* Forward ref of dplane update context type */ |
264 | struct zebra_dplane_ctx; | |
5f3c9e52 | 265 | void zebra_nhg_dplane_result(struct zebra_dplane_ctx *ctx); |
38e40db1 SW |
266 | |
267 | void zebra_nhg_sweep_table(struct hash *hash); | |
ad28e79a | 268 | #endif |