]> git.proxmox.com Git - mirror_frr.git/blob - lib/agg_table.h
zebra, lib: fix the ZEBRA_INTERFACE_VRF_UPDATE zapi message
[mirror_frr.git] / lib / agg_table.h
1 /*
2 * agg_table - Aggregate Table Header
3 * Copyright (C) 2018 Cumulus Networks, Inc.
4 * Donald Sharp
5 *
6 * FRR is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * FRR is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 #ifndef __AGG_TABLE_H__
21 #define __AGG_TABLE_H__
22
23 #include "prefix.h"
24 #include "table.h"
25
26 struct agg_table {
27 struct route_table *route_table;
28
29 void *info;
30 };
31
32 struct agg_node {
33 /*
34 * Caution these must be the very first fields
35 * @see agg_node_to_rnode
36 * @see agg_node_from_rnode
37 */
38 ROUTE_NODE_FIELDS
39
40 /* Aggregation. */
41 void *aggregate;
42 };
43
44 static inline struct route_node *agg_node_to_rnode(struct agg_node *node)
45 {
46 return (struct route_node *)node;
47 }
48
49 static inline struct agg_node *agg_node_from_rnode(struct route_node *node)
50 {
51 return (struct agg_node *)node;
52 }
53
54 static inline struct agg_node *agg_lock_node(struct agg_node *node)
55 {
56 return (struct agg_node *)route_lock_node(agg_node_to_rnode(node));
57 }
58
59 static inline void agg_unlock_node(struct agg_node *node)
60 {
61 route_unlock_node(agg_node_to_rnode(node));
62 }
63
64 static inline void agg_set_table_info(struct agg_table *atable, void *data)
65 {
66 atable->info = data;
67 }
68
69 static inline void *agg_get_table_info(struct agg_table *atable)
70 {
71 return atable->info;
72 }
73
74 static inline struct agg_node *agg_route_top(struct agg_table *table)
75 {
76 return agg_node_from_rnode(route_top(table->route_table));
77 }
78
79 static inline struct agg_node *agg_route_next(struct agg_node *node)
80 {
81 return agg_node_from_rnode(route_next(agg_node_to_rnode(node)));
82 }
83
84 static inline struct agg_node *agg_node_get(struct agg_table *table,
85 struct prefix *p)
86 {
87 return agg_node_from_rnode(route_node_get(table->route_table, p));
88 }
89
90 static inline struct agg_node *
91 agg_node_lookup(const struct agg_table *const table, struct prefix *p)
92 {
93 return agg_node_from_rnode(route_node_lookup(table->route_table, p));
94 }
95
96 static inline struct agg_node *agg_route_next_until(struct agg_node *node,
97 struct agg_node *limit)
98 {
99 struct route_node *rnode;
100
101 rnode = route_next_until(agg_node_to_rnode(node),
102 agg_node_to_rnode(limit));
103
104 return agg_node_from_rnode(rnode);
105 }
106
107 static inline struct agg_node *agg_node_match(struct agg_table *table,
108 struct prefix *p)
109 {
110 return agg_node_from_rnode(route_node_match(table->route_table, p));
111 }
112
113 static inline struct agg_node *agg_node_parent(struct agg_node *node)
114 {
115 struct route_node *rn = agg_node_to_rnode(node);
116
117 return agg_node_from_rnode(rn->parent);
118 }
119
120 static inline struct agg_node *agg_node_left(struct agg_node *node)
121 {
122 struct route_node *rn = agg_node_to_rnode(node);
123
124 return agg_node_from_rnode(rn->l_left);
125 }
126
127 static inline struct agg_node *agg_node_right(struct agg_node *node)
128 {
129 struct route_node *rn = agg_node_to_rnode(node);
130
131 return agg_node_from_rnode(rn->l_right);
132 }
133
134 extern struct agg_table *agg_table_init(void);
135
136 static inline void agg_table_finish(struct agg_table *atable)
137 {
138 route_table_finish(atable->route_table);
139 atable->route_table = NULL;
140
141 XFREE(MTYPE_TMP, atable);
142 }
143
144 static inline struct agg_node *agg_route_table_top(struct agg_node *node)
145 {
146 return (struct agg_node *)route_top(node->table);
147 }
148
149 static inline struct agg_table *agg_get_table(struct agg_node *node)
150 {
151 return (struct agg_table *)route_table_get_info(node->table);
152 }
153 #endif