1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Nexthop Group Private Functions.
4 * Copyright (C) 2019 Cumulus Networks, Inc.
9 * These functions should only be used internally for nhg_hash_entry
10 * manipulation and in certain special cases.
12 * Please use `zebra/zebra_nhg.h` for any general nhg_hash_entry api needs.
15 #ifndef __ZEBRA_NHG_PRIVATE_H__
16 #define __ZEBRA_NHG_PRIVATE_H__
18 #include "zebra/zebra_nhg.h"
24 /* Abstraction for connected trees */
25 struct nhg_connected
{
26 struct nhg_connected_tree_item tree_item
;
27 struct nhg_hash_entry
*nhe
;
30 static int nhg_connected_cmp(const struct nhg_connected
*con1
,
31 const struct nhg_connected
*con2
)
33 return (con1
->nhe
->id
- con2
->nhe
->id
);
36 DECLARE_RBTREE_UNIQ(nhg_connected_tree
, struct nhg_connected
, tree_item
,
39 /* nhg connected tree direct access functions */
40 extern void nhg_connected_tree_init(struct nhg_connected_tree_head
*head
);
41 extern void nhg_connected_tree_free(struct nhg_connected_tree_head
*head
);
43 nhg_connected_tree_is_empty(const struct nhg_connected_tree_head
*head
);
44 extern struct nhg_connected
*
45 nhg_connected_tree_root(struct nhg_connected_tree_head
*head
);
47 /* I realize _add/_del returns are backwords.
49 * Currently the list APIs are not standardized for what happens in
50 * the _del() function when the item isn't present.
52 * We are choosing to return NULL if not found in the _del case for now.
55 /* Delete NHE from the tree. On success, return the NHE, otherwise NULL. */
56 extern struct nhg_hash_entry
*
57 nhg_connected_tree_del_nhe(struct nhg_connected_tree_head
*head
,
58 struct nhg_hash_entry
*nhe
);
59 /* ADD NHE to the tree. On success, return NULL, otherwise return the NHE. */
60 extern struct nhg_hash_entry
*
61 nhg_connected_tree_add_nhe(struct nhg_connected_tree_head
*head
,
62 struct nhg_hash_entry
*nhe
);
68 #endif /* __ZEBRA_NHG_PRIVATE_H__ */