]> git.proxmox.com Git - mirror_frr.git/blame - lib/nexthop_group.h
lib: Separate nexthop_group_equal() into recursive
[mirror_frr.git] / lib / nexthop_group.h
CommitLineData
7ee30f28
DS
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
1b7bce04
DS
24#include <vty.h>
25
5e244469
RW
26#ifdef __cplusplus
27extern "C" {
28#endif
29
7ee30f28
DS
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 */
38struct nexthop_group {
39 struct nexthop *nexthop;
40};
41
31919191
DS
42struct nexthop_group *nexthop_group_new(void);
43void nexthop_group_delete(struct nexthop_group **nhg);
0c8215cb 44void nexthop_group_free_delete(struct nexthop_group **nhg);
dba32923 45
6c8b51e1
DS
46void nexthop_group_copy(struct nexthop_group *to,
47 struct nexthop_group *from);
deff170e 48void copy_nexthops(struct nexthop **tnh, const struct nexthop *nh,
7ee30f28
DS
49 struct nexthop *rparent);
50
2f000944 51uint32_t nexthop_group_hash_no_recurse(const struct nexthop_group *nhg);
1b1fe1c4 52uint32_t nexthop_group_hash(const struct nexthop_group *nhg);
9ef49038 53void nexthop_group_mark_duplicates(struct nexthop_group *nhg);
1b1fe1c4 54
7ee30f28
DS
55/* The following for loop allows to iterate over the nexthop
56 * structure of routes.
57 *
58 * head: The pointer to the first nexthop in the chain.
59 *
60 * nexthop: The pointer to the current nexthop, either in the
61 * top-level chain or in a resolved chain.
62 */
63#define ALL_NEXTHOPS(head, nhop) \
64 (nhop) = (head.nexthop); \
65 (nhop); \
66 (nhop) = nexthop_next(nhop)
31919191 67
d826a734
MS
68#define ALL_NEXTHOPS_PTR(head, nhop) \
69 (nhop) = ((head)->nexthop); \
70 (nhop); \
71 (nhop) = nexthop_next(nhop)
72
c57bd6bb
DS
73
74struct nexthop_hold {
75 char *nhvrf_name;
b43bb64f 76 union sockunion *addr;
c57bd6bb
DS
77 char *intf;
78};
79
31919191
DS
80struct nexthop_group_cmd {
81
82 RB_ENTRY(nexthop_group_cmd) nhgc_entry;
83
84 char name[80];
85
86 struct nexthop_group nhg;
87
c57bd6bb
DS
88 struct list *nhg_list;
89
31919191
DS
90 QOBJ_FIELDS
91};
92RB_HEAD(nhgc_entry_head, nexthp_group_cmd);
93RB_PROTOTYPE(nhgc_entry_head, nexthop_group_cmd, nhgc_entry,
94 nexthop_group_cmd_compare)
95DECLARE_QOBJ_TYPE(nexthop_group_cmd)
96
97/*
98 * Initialize nexthop_groups. If you are interested in when
99 * a nexthop_group is added/deleted/modified, then set the
100 * appropriate callback functions to handle it in your
101 * code
102 */
103void nexthop_group_init(
d01b92fd 104 void (*create)(const char *name),
31919191
DS
105 void (*add_nexthop)(const struct nexthop_group_cmd *nhgc,
106 const struct nexthop *nhop),
107 void (*del_nexthop)(const struct nexthop_group_cmd *nhgc,
108 const struct nexthop *nhop),
d01b92fd 109 void (*destroy)(const char *name));
31919191 110
98cbbaea
DS
111void nexthop_group_enable_vrf(struct vrf *vrf);
112void nexthop_group_disable_vrf(struct vrf *vrf);
113void nexthop_group_interface_state_change(struct interface *ifp,
114 ifindex_t oldifindex);
115
8f8d9845
SW
116extern struct nexthop *nexthop_exists(const struct nexthop_group *nhg,
117 const struct nexthop *nh);
2171b19c
SW
118/* This assumes ordered */
119extern bool nexthop_group_equal_no_recurse(const struct nexthop_group *nhg1,
120 const struct nexthop_group *nhg2);
121
122/* This assumes ordered */
8f8d9845
SW
123extern bool nexthop_group_equal(const struct nexthop_group *nhg1,
124 const struct nexthop_group *nhg2);
d604266c
DS
125
126extern struct nexthop_group_cmd *nhgc_find(const char *name);
127
1b7bce04 128extern void nexthop_group_write_nexthop(struct vty *vty, struct nexthop *nh);
5e244469 129
454192f4
DS
130/* Return the number of nexthops in this nhg */
131extern uint8_t nexthop_group_nexthop_num(const struct nexthop_group *nhg);
132extern uint8_t
98cda54a
SW
133nexthop_group_nexthop_num_no_recurse(const struct nexthop_group *nhg);
134extern uint8_t
454192f4 135nexthop_group_active_nexthop_num(const struct nexthop_group *nhg);
98cda54a
SW
136extern uint8_t
137nexthop_group_active_nexthop_num_no_recurse(const struct nexthop_group *nhg);
454192f4 138
5e244469
RW
139#ifdef __cplusplus
140}
141#endif
142
7ee30f28 143#endif