]>
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 | ||
24 | /* | |
25 | * What is a nexthop group? | |
26 | * | |
27 | * A nexthop group is a collection of nexthops that make up | |
28 | * the ECMP path for the route. | |
29 | * | |
30 | * This module provides a proper abstraction to this idea. | |
31 | */ | |
32 | struct nexthop_group { | |
33 | struct nexthop *nexthop; | |
34 | }; | |
35 | ||
31919191 DS |
36 | struct nexthop_group *nexthop_group_new(void); |
37 | void nexthop_group_delete(struct nexthop_group **nhg); | |
dba32923 | 38 | |
7ee30f28 | 39 | void nexthop_add(struct nexthop **target, struct nexthop *nexthop); |
31919191 | 40 | void nexthop_del(struct nexthop_group *nhg, struct nexthop *nexthop); |
7ee30f28 DS |
41 | void copy_nexthops(struct nexthop **tnh, struct nexthop *nh, |
42 | struct nexthop *rparent); | |
43 | ||
44 | /* The following for loop allows to iterate over the nexthop | |
45 | * structure of routes. | |
46 | * | |
47 | * head: The pointer to the first nexthop in the chain. | |
48 | * | |
49 | * nexthop: The pointer to the current nexthop, either in the | |
50 | * top-level chain or in a resolved chain. | |
51 | */ | |
52 | #define ALL_NEXTHOPS(head, nhop) \ | |
53 | (nhop) = (head.nexthop); \ | |
54 | (nhop); \ | |
55 | (nhop) = nexthop_next(nhop) | |
31919191 DS |
56 | |
57 | struct nexthop_group_cmd { | |
58 | ||
59 | RB_ENTRY(nexthop_group_cmd) nhgc_entry; | |
60 | ||
61 | char name[80]; | |
62 | ||
63 | struct nexthop_group nhg; | |
64 | ||
65 | QOBJ_FIELDS | |
66 | }; | |
67 | RB_HEAD(nhgc_entry_head, nexthp_group_cmd); | |
68 | RB_PROTOTYPE(nhgc_entry_head, nexthop_group_cmd, nhgc_entry, | |
69 | nexthop_group_cmd_compare) | |
70 | DECLARE_QOBJ_TYPE(nexthop_group_cmd) | |
71 | ||
72 | /* | |
73 | * Initialize nexthop_groups. If you are interested in when | |
74 | * a nexthop_group is added/deleted/modified, then set the | |
75 | * appropriate callback functions to handle it in your | |
76 | * code | |
77 | */ | |
78 | void nexthop_group_init( | |
79 | void (*new)(const char *name), | |
80 | void (*add_nexthop)(const struct nexthop_group_cmd *nhgc, | |
81 | const struct nexthop *nhop), | |
82 | void (*del_nexthop)(const struct nexthop_group_cmd *nhgc, | |
83 | const struct nexthop *nhop), | |
84 | void (*delete)(const char *name)); | |
85 | ||
86 | extern struct nexthop *nexthop_exists(struct nexthop_group *nhg, | |
87 | struct nexthop *nh); | |
d604266c DS |
88 | |
89 | extern struct nexthop_group_cmd *nhgc_find(const char *name); | |
90 | ||
7ee30f28 | 91 | #endif |