]> git.proxmox.com Git - mirror_frr.git/blame - zebra/zebra_nhg.h
zebra: Accept NULL value for updating route NHE
[mirror_frr.git] / zebra / zebra_nhg.h
CommitLineData
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 37struct nh_grp {
0c8215cb
SW
38 uint32_t id;
39 uint8_t weight;
40};
41
42
69171da2 43struct nhg_hash_entry {
a95b8020 44 uint32_t id;
77b76fc9 45 afi_t afi;
69171da2 46 vrf_id_t vrf_id;
d9f5b2f5 47 bool is_kernel_nh;
69171da2 48
8e401b25 49 struct nexthop_group *nhg;
69171da2 50
2614bf87
SW
51 /* If this is not a group, it
52 * will be a single nexthop
53 * and must have an interface
54 * associated with it.
55 * Otherwise, this will be null.
56 */
57 struct interface *ifp;
58
69171da2
DS
59 uint32_t refcnt;
60 uint32_t dplane_ref;
c8ee3cdb
DS
61
62 uint32_t flags;
3119f6a1 63
0c8215cb 64 /* Dependency tree for other entries.
3119f6a1
SW
65 * For instance a group with two
66 * nexthops will have two dependencies
67 * pointing to those nhg_hash_entries.
0c8215cb
SW
68 *
69 * Using a rb tree here to make lookups
70 * faster with ID's.
3119f6a1 71 */
a15d4c00 72 RB_HEAD(nhg_connected_head, nhg_connected) nhg_depends, nhg_dependents;
c8ee3cdb
DS
73/*
74 * Is this nexthop group valid, ie all nexthops are fully resolved.
75 * What is fully resolved? It's a nexthop that is either self contained
76 * and correct( ie no recursive pointer ) or a nexthop that is recursively
77 * resolved and correct.
78 */
79#define NEXTHOP_GROUP_VALID 0x1
80/*
81 * Has this nexthop group been installed? At this point in time, this
82 * means that the data-plane has been told about this nexthop group
83 * and it's possible usage by a route entry.
84 */
85#define NEXTHOP_GROUP_INSTALLED 0x2
7f6077d0
SW
86/*
87 * Has the nexthop group been queued to be send to the FIB?
88 * The NEXTHOP_GROUP_VALID flag should also be set by this point.
89 */
90#define NEXTHOP_GROUP_QUEUED 0x4
98cda54a
SW
91/*
92 * Is this a nexthop that is recursively resolved?
93 */
94#define NEXTHOP_GROUP_RECURSIVE 0x8
69171da2
DS
95};
96
a15d4c00
SW
97/* Abstraction for connected trees */
98struct nhg_connected {
99 RB_ENTRY(nhg_connected) nhg_entry;
3119f6a1
SW
100 struct nhg_hash_entry *nhe;
101};
102
fe593b78 103RB_PROTOTYPE(nhg_connected_head, nhg_connected, nhg_entry, nhg_connected_cmp);
3119f6a1 104
e22e8001
SW
105
106enum nhg_ctx_op_e {
107 NHG_CTX_OP_NONE = 0,
108 NHG_CTX_OP_NEW,
109 NHG_CTX_OP_DEL,
110};
111
112enum nhg_ctx_result {
113 NHG_CTX_NONE = 0,
114 NHG_CTX_QUEUED,
115 NHG_CTX_SUCCESS,
116 NHG_CTX_FAILURE,
117};
118
119/*
120 * Context needed to queue nhg updates on the
121 * work queue.
122 */
123struct nhg_ctx {
124
125 /* Unique ID */
126 uint32_t id;
127
128 vrf_id_t vrf_id;
129 afi_t afi;
130 bool is_kernel_nh;
131
132 /* If its a group array, how many? */
133 uint8_t count;
134
135 /* Its either a single nexthop or an array of ID's */
136 union {
137 struct nexthop nh;
138 struct nh_grp grp[MULTIPATH_NUM];
139 } u;
140
141 enum nhg_ctx_op_e op;
142 enum nhg_ctx_result status;
143};
144
145
69171da2
DS
146void zebra_nhg_init(void);
147void zebra_nhg_terminate(void);
148
fe593b78
SW
149extern void nhg_connected_free(struct nhg_connected *dep);
150extern struct nhg_connected *nhg_connected_new(struct nhg_hash_entry *nhe);
151
152/* nhg connected tree direct access functions */
153extern void nhg_connected_head_init(struct nhg_connected_head *head);
154extern unsigned int
155nhg_connected_head_count(const struct nhg_connected_head *head);
156extern void nhg_connected_head_free(struct nhg_connected_head *head);
157extern bool nhg_connected_head_is_empty(const struct nhg_connected_head *head);
98cda54a
SW
158extern struct nhg_connected *
159nhg_connected_head_root(const struct nhg_connected_head *head);
fe593b78
SW
160extern void nhg_connected_head_del(struct nhg_connected_head *head,
161 struct nhg_hash_entry *nhe);
162extern void nhg_connected_head_add(struct nhg_connected_head *head,
163 struct nhg_hash_entry *nhe);
164
165/**
166 * NHE abstracted tree functions.
167 * Use these where possible instead of the direct ones access ones.
168 */
98cda54a
SW
169
170
171extern struct nhg_hash_entry *zebra_nhg_resolve(struct nhg_hash_entry *nhe);
172extern uint32_t zebra_nhg_get_resolved_id(uint32_t id);
173
fe593b78
SW
174/* Depends */
175extern unsigned int zebra_nhg_depends_count(const struct nhg_hash_entry *nhe);
0c8215cb 176extern bool zebra_nhg_depends_is_empty(const struct nhg_hash_entry *nhe);
0c8215cb
SW
177extern void zebra_nhg_depends_del(struct nhg_hash_entry *from,
178 struct nhg_hash_entry *depend);
179extern void zebra_nhg_depends_add(struct nhg_hash_entry *to,
180 struct nhg_hash_entry *depend);
0c8215cb 181extern void zebra_nhg_depends_init(struct nhg_hash_entry *nhe);
fe593b78
SW
182/* Dependents */
183extern unsigned int
184zebra_nhg_dependents_count(const struct nhg_hash_entry *nhe);
185extern bool zebra_nhg_dependents_is_empty(const struct nhg_hash_entry *nhe);
186extern void zebra_nhg_dependents_del(struct nhg_hash_entry *from,
187 struct nhg_hash_entry *dependent);
188extern void zebra_nhg_dependents_add(struct nhg_hash_entry *to,
189 struct nhg_hash_entry *dependent);
190extern void zebra_nhg_dependents_init(struct nhg_hash_entry *nhe);
3119f6a1 191
3119f6a1 192
d9f5b2f5
SW
193extern struct nhg_hash_entry *zebra_nhg_lookup_id(uint32_t id);
194extern int zebra_nhg_insert_id(struct nhg_hash_entry *nhe);
195
69171da2 196extern uint32_t zebra_nhg_hash_key(const void *arg);
a95b8020 197extern uint32_t zebra_nhg_id_key(const void *arg);
69171da2
DS
198
199extern bool zebra_nhg_hash_equal(const void *arg1, const void *arg2);
d9f5b2f5 200extern bool zebra_nhg_hash_id_equal(const void *arg1, const void *arg2);
69171da2 201
e22e8001
SW
202/*
203 * Process a context off of a queue.
204 * Specifically this should be from
205 * the rib meta queue.
206 */
207extern int nhg_ctx_process(struct nhg_ctx *ctx);
85f5e761 208
e22e8001
SW
209/* Find via kernel nh creation */
210extern int zebra_nhg_kernel_find(uint32_t id, struct nexthop *nh,
211 struct nh_grp *grp, uint8_t count,
212 vrf_id_t vrf_id, afi_t afi);
213
214/* Find via route creation */
215extern struct nhg_hash_entry *zebra_nhg_rib_find(uint32_t id,
216 struct nexthop_group *nhg,
217 vrf_id_t rt_vrf_id,
218 afi_t rt_afi);
3057df51 219
0c8215cb 220
b599cd2a 221void zebra_nhg_free_members(struct nhg_hash_entry *nhe);
d9f5b2f5 222void zebra_nhg_free(void *arg);
d9f5b2f5 223void zebra_nhg_decrement_ref(struct nhg_hash_entry *nhe);
7fd392cc 224void zebra_nhg_increment_ref(struct nhg_hash_entry *nhe);
e22e8001 225
fe593b78
SW
226void zebra_nhg_set_invalid(struct nhg_hash_entry *nhe);
227void zebra_nhg_set_if(struct nhg_hash_entry *nhe, struct interface *ifp);
8b5bdc8b
SW
228
229extern int nexthop_active_update(struct route_node *rn, struct route_entry *re);
5be96a2d 230
144a1b34
SW
231extern int zebra_nhg_re_update_ref(struct route_entry *re,
232 struct nhg_hash_entry *nhe);
233
98cda54a
SW
234extern uint8_t zebra_nhg_nhe2grp(struct nh_grp *grp,
235 struct nhg_hash_entry *nhe);
236
5be96a2d 237void zebra_nhg_install_kernel(struct nhg_hash_entry *nhe);
147bad16
SW
238void zebra_nhg_uninstall_kernel(struct nhg_hash_entry *nhe);
239
240void zebra_nhg_cleanup_tables(void);
5f3c9e52 241
0c8215cb
SW
242/* Forward ref of dplane update context type */
243struct zebra_dplane_ctx;
5f3c9e52 244void zebra_nhg_dplane_result(struct zebra_dplane_ctx *ctx);
ad28e79a 245#endif