]> git.proxmox.com Git - mirror_frr.git/blob - lib/agg_table.h
*: auto-convert to SPDX License IDs
[mirror_frr.git] / lib / agg_table.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * agg_table - Aggregate Table Header
4 * Copyright (C) 2018 Cumulus Networks, Inc.
5 * Donald Sharp
6 */
7 #ifndef __AGG_TABLE_H__
8 #define __AGG_TABLE_H__
9
10 #include "prefix.h"
11 #include "table.h"
12
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16
17 struct agg_table {
18 struct route_table *route_table;
19
20 void *info;
21 };
22
23 struct agg_node {
24 /*
25 * Caution these must be the very first fields
26 * @see agg_node_to_rnode
27 * @see agg_node_from_rnode
28 */
29 ROUTE_NODE_FIELDS
30
31 /* Aggregation. */
32 void *aggregate;
33 };
34
35 static inline struct route_node *agg_node_to_rnode(struct agg_node *node)
36 {
37 return (struct route_node *)node;
38 }
39
40 static inline struct agg_node *agg_node_from_rnode(struct route_node *node)
41 {
42 return (struct agg_node *)node;
43 }
44
45 static inline struct agg_node *agg_lock_node(struct agg_node *node)
46 {
47 return (struct agg_node *)route_lock_node(agg_node_to_rnode(node));
48 }
49
50 static inline void agg_unlock_node(struct agg_node *node)
51 {
52 route_unlock_node(agg_node_to_rnode(node));
53 }
54
55 static inline void agg_set_table_info(struct agg_table *atable, void *data)
56 {
57 atable->info = data;
58 }
59
60 static inline void *agg_get_table_info(struct agg_table *atable)
61 {
62 return atable->info;
63 }
64
65 static inline struct agg_node *agg_route_top(struct agg_table *table)
66 {
67 return agg_node_from_rnode(route_top(table->route_table));
68 }
69
70 static inline struct agg_node *agg_route_next(struct agg_node *node)
71 {
72 return agg_node_from_rnode(route_next(agg_node_to_rnode(node)));
73 }
74
75 static inline struct agg_node *agg_node_get(struct agg_table *table,
76 const struct prefix *p)
77 {
78 return agg_node_from_rnode(route_node_get(table->route_table, p));
79 }
80
81 static inline struct agg_node *
82 agg_node_lookup(const struct agg_table *const table, const struct prefix *p)
83 {
84 return agg_node_from_rnode(route_node_lookup(table->route_table, p));
85 }
86
87 static inline struct agg_node *agg_route_next_until(struct agg_node *node,
88 struct agg_node *limit)
89 {
90 struct route_node *rnode;
91
92 rnode = route_next_until(agg_node_to_rnode(node),
93 agg_node_to_rnode(limit));
94
95 return agg_node_from_rnode(rnode);
96 }
97
98 static inline struct agg_node *agg_node_match(struct agg_table *table,
99 const struct prefix *p)
100 {
101 return agg_node_from_rnode(route_node_match(table->route_table, p));
102 }
103
104 static inline struct agg_node *agg_node_parent(struct agg_node *node)
105 {
106 struct route_node *rn = agg_node_to_rnode(node);
107
108 return agg_node_from_rnode(rn->parent);
109 }
110
111 static inline struct agg_node *agg_node_left(struct agg_node *node)
112 {
113 struct route_node *rn = agg_node_to_rnode(node);
114
115 return agg_node_from_rnode(rn->l_left);
116 }
117
118 static inline struct agg_node *agg_node_right(struct agg_node *node)
119 {
120 struct route_node *rn = agg_node_to_rnode(node);
121
122 return agg_node_from_rnode(rn->l_right);
123 }
124
125 extern struct agg_table *agg_table_init(void);
126
127 static inline void agg_table_finish(struct agg_table *atable)
128 {
129 route_table_finish(atable->route_table);
130 atable->route_table = NULL;
131
132 XFREE(MTYPE_TMP, atable);
133 }
134
135 static inline struct agg_node *agg_route_table_top(struct agg_node *node)
136 {
137 return (struct agg_node *)route_top(node->table);
138 }
139
140 static inline struct agg_table *agg_get_table(struct agg_node *node)
141 {
142 return (struct agg_table *)route_table_get_info(node->table);
143 }
144
145 static inline const struct prefix *
146 agg_node_get_prefix(const struct agg_node *node)
147 {
148 return &node->p;
149 }
150
151 static inline unsigned int agg_node_get_lock_count(const struct agg_node *node)
152 {
153 return node->lock;
154 }
155
156 #ifdef _FRR_ATTRIBUTE_PRINTFRR
157 #pragma FRR printfrr_ext "%pRN" (struct agg_node *)
158 #endif
159
160 #ifdef __cplusplus
161 }
162 #endif
163
164 #endif