]> git.proxmox.com Git - mirror_frr.git/blob - lib/nexthop_group.h
zebra, lib: Remove return from void functions
[mirror_frr.git] / lib / nexthop_group.h
1 /*
2 * Nexthop Group structure definition.
3 * Copyright (C) 2018 Cumulus Networks, Inc.
4 * Donald Sharp
5 *
6 * This program 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 Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * 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
21 #ifndef __NEXTHOP_GROUP__
22 #define __NEXTHOP_GROUP__
23
24 #include <vty.h>
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 /*
31 * What is a nexthop group?
32 *
33 * A nexthop group is a collection of nexthops that make up
34 * the ECMP path for the route.
35 *
36 * This module provides a proper abstraction to this idea.
37 */
38 struct nexthop_group {
39 struct nexthop *nexthop;
40 };
41
42 struct nexthop_group *nexthop_group_new(void);
43 void nexthop_group_delete(struct nexthop_group **nhg);
44
45 void nexthop_group_copy(struct nexthop_group *to,
46 struct nexthop_group *from);
47
48 /*
49 * Copy a list of nexthops in 'nh' to an nhg, enforcing canonical sort order
50 */
51 void nexthop_group_copy_nh_sorted(struct nexthop_group *nhg,
52 const struct nexthop *nh);
53
54 void copy_nexthops(struct nexthop **tnh, const struct nexthop *nh,
55 struct nexthop *rparent);
56
57 uint32_t nexthop_group_hash_no_recurse(const struct nexthop_group *nhg);
58 uint32_t nexthop_group_hash(const struct nexthop_group *nhg);
59 void nexthop_group_mark_duplicates(struct nexthop_group *nhg);
60 void nexthop_group_add_sorted(struct nexthop_group *nhg,
61 struct nexthop *nexthop);
62
63 /* The following for loop allows to iterate over the nexthop
64 * structure of routes.
65 *
66 * head: The pointer to the first nexthop in the chain.
67 *
68 * nexthop: The pointer to the current nexthop, either in the
69 * top-level chain or in a resolved chain.
70 */
71 #define ALL_NEXTHOPS(head, nhop) \
72 (nhop) = (head.nexthop); \
73 (nhop); \
74 (nhop) = nexthop_next(nhop)
75
76 #define ALL_NEXTHOPS_PTR(head, nhop) \
77 (nhop) = ((head)->nexthop); \
78 (nhop); \
79 (nhop) = nexthop_next(nhop)
80
81
82 struct nexthop_group_cmd {
83
84 RB_ENTRY(nexthop_group_cmd) nhgc_entry;
85
86 char name[80];
87
88 struct nexthop_group nhg;
89
90 struct list *nhg_list;
91
92 QOBJ_FIELDS
93 };
94 RB_HEAD(nhgc_entry_head, nexthp_group_cmd);
95 RB_PROTOTYPE(nhgc_entry_head, nexthop_group_cmd, nhgc_entry,
96 nexthop_group_cmd_compare)
97 DECLARE_QOBJ_TYPE(nexthop_group_cmd)
98
99 /*
100 * Initialize nexthop_groups. If you are interested in when
101 * a nexthop_group is added/deleted/modified, then set the
102 * appropriate callback functions to handle it in your
103 * code
104 */
105 void nexthop_group_init(
106 void (*create)(const char *name),
107 void (*add_nexthop)(const struct nexthop_group_cmd *nhgc,
108 const struct nexthop *nhop),
109 void (*del_nexthop)(const struct nexthop_group_cmd *nhgc,
110 const struct nexthop *nhop),
111 void (*destroy)(const char *name));
112
113 void nexthop_group_enable_vrf(struct vrf *vrf);
114 void nexthop_group_disable_vrf(struct vrf *vrf);
115 void nexthop_group_interface_state_change(struct interface *ifp,
116 ifindex_t oldifindex);
117
118 extern struct nexthop *nexthop_exists(const struct nexthop_group *nhg,
119 const struct nexthop *nh);
120 /* This assumes ordered */
121 extern bool nexthop_group_equal_no_recurse(const struct nexthop_group *nhg1,
122 const struct nexthop_group *nhg2);
123
124 /* This assumes ordered */
125 extern bool nexthop_group_equal(const struct nexthop_group *nhg1,
126 const struct nexthop_group *nhg2);
127
128 extern struct nexthop_group_cmd *nhgc_find(const char *name);
129
130 extern void nexthop_group_write_nexthop(struct vty *vty, struct nexthop *nh);
131
132 /* Return the number of nexthops in this nhg */
133 extern uint8_t nexthop_group_nexthop_num(const struct nexthop_group *nhg);
134 extern uint8_t
135 nexthop_group_nexthop_num_no_recurse(const struct nexthop_group *nhg);
136 extern uint8_t
137 nexthop_group_active_nexthop_num(const struct nexthop_group *nhg);
138 extern uint8_t
139 nexthop_group_active_nexthop_num_no_recurse(const struct nexthop_group *nhg);
140
141 #ifdef __cplusplus
142 }
143 #endif
144
145 #endif