]> git.proxmox.com Git - mirror_frr.git/blob - lib/nexthop_group.h
Merge pull request #11003 from anlancs/bgpd-mh-trival-remove
[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 #include "json.h"
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 /*
32 * What is a nexthop group?
33 *
34 * A nexthop group is a collection of nexthops that make up
35 * the ECMP path for the route.
36 *
37 * This module provides a proper abstraction to this idea.
38 */
39 struct nexthop_group {
40 struct nexthop *nexthop;
41 };
42
43 struct nexthop_group *nexthop_group_new(void);
44 void nexthop_group_delete(struct nexthop_group **nhg);
45
46 void nexthop_group_copy(struct nexthop_group *to,
47 const struct nexthop_group *from);
48
49 /*
50 * Copy a list of nexthops in 'nh' to an nhg, enforcing canonical sort order
51 */
52 void nexthop_group_copy_nh_sorted(struct nexthop_group *nhg,
53 const struct nexthop *nh);
54
55 void copy_nexthops(struct nexthop **tnh, const struct nexthop *nh,
56 struct nexthop *rparent);
57
58 uint32_t nexthop_group_hash_no_recurse(const struct nexthop_group *nhg);
59 uint32_t nexthop_group_hash(const struct nexthop_group *nhg);
60 void nexthop_group_mark_duplicates(struct nexthop_group *nhg);
61
62 /* Add a nexthop to a list, enforcing the canonical sort order. */
63 void nexthop_group_add_sorted(struct nexthop_group *nhg,
64 struct nexthop *nexthop);
65
66 /* The following for loop allows to iterate over the nexthop
67 * structure of routes.
68 *
69 * head: The pointer to the first nexthop in the chain.
70 *
71 * nexthop: The pointer to the current nexthop, either in the
72 * top-level chain or in a resolved chain.
73 */
74 #define ALL_NEXTHOPS(head, nhop) \
75 (nhop) = (head.nexthop); \
76 (nhop); \
77 (nhop) = nexthop_next(nhop)
78
79 #define ALL_NEXTHOPS_PTR(head, nhop) \
80 (nhop) = ((head)->nexthop); \
81 (nhop); \
82 (nhop) = nexthop_next(nhop)
83
84
85 #define NHGC_NAME_SIZE 80
86
87 struct nexthop_group_cmd {
88
89 RB_ENTRY(nexthop_group_cmd) nhgc_entry;
90
91 char name[NHGC_NAME_SIZE];
92
93 /* Name of group containing backup nexthops (if set) */
94 char backup_list_name[NHGC_NAME_SIZE];
95
96 struct nexthop_group nhg;
97
98 struct list *nhg_list;
99
100 QOBJ_FIELDS;
101 };
102 RB_HEAD(nhgc_entry_head, nexthp_group_cmd);
103 RB_PROTOTYPE(nhgc_entry_head, nexthop_group_cmd, nhgc_entry,
104 nexthop_group_cmd_compare)
105 DECLARE_QOBJ_TYPE(nexthop_group_cmd);
106
107 /*
108 * Initialize nexthop_groups. If you are interested in when
109 * a nexthop_group is added/deleted/modified, then set the
110 * appropriate callback functions to handle it in your
111 * code
112 */
113 void nexthop_group_init(
114 void (*create)(const char *name),
115 void (*add_nexthop)(const struct nexthop_group_cmd *nhgc,
116 const struct nexthop *nhop),
117 void (*del_nexthop)(const struct nexthop_group_cmd *nhgc,
118 const struct nexthop *nhop),
119 void (*destroy)(const char *name));
120
121 void nexthop_group_enable_vrf(struct vrf *vrf);
122 void nexthop_group_disable_vrf(struct vrf *vrf);
123 void nexthop_group_interface_state_change(struct interface *ifp,
124 ifindex_t oldifindex);
125
126 extern struct nexthop *nexthop_exists(const struct nexthop_group *nhg,
127 const struct nexthop *nh);
128 /* This assumes ordered */
129 extern bool nexthop_group_equal_no_recurse(const struct nexthop_group *nhg1,
130 const struct nexthop_group *nhg2);
131
132 /* This assumes ordered */
133 extern bool nexthop_group_equal(const struct nexthop_group *nhg1,
134 const struct nexthop_group *nhg2);
135
136 extern struct nexthop_group_cmd *nhgc_find(const char *name);
137
138 extern void nexthop_group_write_nexthop_simple(struct vty *vty,
139 const struct nexthop *nh,
140 char *altifname);
141 extern void nexthop_group_write_nexthop(struct vty *vty,
142 const struct nexthop *nh);
143
144 extern void nexthop_group_json_nexthop(json_object *j,
145 const struct nexthop *nh);
146
147 /* Return the number of nexthops in this nhg */
148 extern uint8_t nexthop_group_nexthop_num(const struct nexthop_group *nhg);
149 extern uint8_t
150 nexthop_group_nexthop_num_no_recurse(const struct nexthop_group *nhg);
151 extern uint8_t
152 nexthop_group_active_nexthop_num(const struct nexthop_group *nhg);
153 extern uint8_t
154 nexthop_group_active_nexthop_num_no_recurse(const struct nexthop_group *nhg);
155
156 #ifdef __cplusplus
157 }
158 #endif
159
160 #endif