]>
Commit | Line | Data |
---|---|---|
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 |
27 | extern "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 | */ | |
38 | struct nexthop_group { | |
39 | struct nexthop *nexthop; | |
40 | }; | |
41 | ||
31919191 DS |
42 | struct nexthop_group *nexthop_group_new(void); |
43 | void nexthop_group_delete(struct nexthop_group **nhg); | |
dba32923 | 44 | |
7ee30f28 | 45 | void nexthop_add(struct nexthop **target, struct nexthop *nexthop); |
31919191 | 46 | void nexthop_del(struct nexthop_group *nhg, struct nexthop *nexthop); |
deff170e | 47 | void copy_nexthops(struct nexthop **tnh, const struct nexthop *nh, |
7ee30f28 DS |
48 | struct nexthop *rparent); |
49 | ||
1b1fe1c4 SW |
50 | uint32_t nexthop_group_hash(const struct nexthop_group *nhg); |
51 | ||
7ee30f28 DS |
52 | /* The following for loop allows to iterate over the nexthop |
53 | * structure of routes. | |
54 | * | |
55 | * head: The pointer to the first nexthop in the chain. | |
56 | * | |
57 | * nexthop: The pointer to the current nexthop, either in the | |
58 | * top-level chain or in a resolved chain. | |
59 | */ | |
60 | #define ALL_NEXTHOPS(head, nhop) \ | |
61 | (nhop) = (head.nexthop); \ | |
62 | (nhop); \ | |
63 | (nhop) = nexthop_next(nhop) | |
31919191 | 64 | |
d826a734 MS |
65 | #define ALL_NEXTHOPS_PTR(head, nhop) \ |
66 | (nhop) = ((head)->nexthop); \ | |
67 | (nhop); \ | |
68 | (nhop) = nexthop_next(nhop) | |
69 | ||
c57bd6bb DS |
70 | |
71 | struct nexthop_hold { | |
72 | char *nhvrf_name; | |
b43bb64f | 73 | union sockunion *addr; |
c57bd6bb DS |
74 | char *intf; |
75 | }; | |
76 | ||
31919191 DS |
77 | struct nexthop_group_cmd { |
78 | ||
79 | RB_ENTRY(nexthop_group_cmd) nhgc_entry; | |
80 | ||
81 | char name[80]; | |
82 | ||
83 | struct nexthop_group nhg; | |
84 | ||
c57bd6bb DS |
85 | struct list *nhg_list; |
86 | ||
31919191 DS |
87 | QOBJ_FIELDS |
88 | }; | |
89 | RB_HEAD(nhgc_entry_head, nexthp_group_cmd); | |
90 | RB_PROTOTYPE(nhgc_entry_head, nexthop_group_cmd, nhgc_entry, | |
91 | nexthop_group_cmd_compare) | |
92 | DECLARE_QOBJ_TYPE(nexthop_group_cmd) | |
93 | ||
94 | /* | |
95 | * Initialize nexthop_groups. If you are interested in when | |
96 | * a nexthop_group is added/deleted/modified, then set the | |
97 | * appropriate callback functions to handle it in your | |
98 | * code | |
99 | */ | |
100 | void nexthop_group_init( | |
d01b92fd | 101 | void (*create)(const char *name), |
31919191 DS |
102 | void (*add_nexthop)(const struct nexthop_group_cmd *nhgc, |
103 | const struct nexthop *nhop), | |
104 | void (*del_nexthop)(const struct nexthop_group_cmd *nhgc, | |
105 | const struct nexthop *nhop), | |
d01b92fd | 106 | void (*destroy)(const char *name)); |
31919191 | 107 | |
98cbbaea DS |
108 | void nexthop_group_enable_vrf(struct vrf *vrf); |
109 | void nexthop_group_disable_vrf(struct vrf *vrf); | |
110 | void nexthop_group_interface_state_change(struct interface *ifp, | |
111 | ifindex_t oldifindex); | |
112 | ||
31919191 DS |
113 | extern struct nexthop *nexthop_exists(struct nexthop_group *nhg, |
114 | struct nexthop *nh); | |
d604266c DS |
115 | |
116 | extern struct nexthop_group_cmd *nhgc_find(const char *name); | |
117 | ||
1b7bce04 | 118 | extern void nexthop_group_write_nexthop(struct vty *vty, struct nexthop *nh); |
5e244469 | 119 | |
454192f4 DS |
120 | /* Return the number of nexthops in this nhg */ |
121 | extern uint8_t nexthop_group_nexthop_num(const struct nexthop_group *nhg); | |
122 | extern uint8_t | |
123 | nexthop_group_active_nexthop_num(const struct nexthop_group *nhg); | |
124 | ||
5e244469 RW |
125 | #ifdef __cplusplus |
126 | } | |
127 | #endif | |
128 | ||
7ee30f28 | 129 | #endif |