2 * Nexthop Group structure definition.
3 * Copyright (C) 2018 Cumulus Networks, Inc.
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)
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
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
21 #ifndef __NEXTHOP_GROUP__
22 #define __NEXTHOP_GROUP__
31 * What is a nexthop group?
33 * A nexthop group is a collection of nexthops that make up
34 * the ECMP path for the route.
36 * This module provides a proper abstraction to this idea.
38 struct nexthop_group
{
39 struct nexthop
*nexthop
;
42 struct nexthop_group
*nexthop_group_new(void);
43 void nexthop_group_delete(struct nexthop_group
**nhg
);
45 void nexthop_add(struct nexthop
**target
, struct nexthop
*nexthop
);
46 void nexthop_del(struct nexthop_group
*nhg
, struct nexthop
*nexthop
);
47 void copy_nexthops(struct nexthop
**tnh
, const struct nexthop
*nh
,
48 struct nexthop
*rparent
);
50 /* The following for loop allows to iterate over the nexthop
51 * structure of routes.
53 * head: The pointer to the first nexthop in the chain.
55 * nexthop: The pointer to the current nexthop, either in the
56 * top-level chain or in a resolved chain.
58 #define ALL_NEXTHOPS(head, nhop) \
59 (nhop) = (head.nexthop); \
61 (nhop) = nexthop_next(nhop)
63 #define ALL_NEXTHOPS_PTR(head, nhop) \
64 (nhop) = ((head)->nexthop); \
66 (nhop) = nexthop_next(nhop)
71 union sockunion
*addr
;
75 struct nexthop_group_cmd
{
77 RB_ENTRY(nexthop_group_cmd
) nhgc_entry
;
81 struct nexthop_group nhg
;
83 struct list
*nhg_list
;
87 RB_HEAD(nhgc_entry_head
, nexthp_group_cmd
);
88 RB_PROTOTYPE(nhgc_entry_head
, nexthop_group_cmd
, nhgc_entry
,
89 nexthop_group_cmd_compare
)
90 DECLARE_QOBJ_TYPE(nexthop_group_cmd
)
93 * Initialize nexthop_groups. If you are interested in when
94 * a nexthop_group is added/deleted/modified, then set the
95 * appropriate callback functions to handle it in your
98 void nexthop_group_init(
99 void (*create
)(const char *name
),
100 void (*add_nexthop
)(const struct nexthop_group_cmd
*nhgc
,
101 const struct nexthop
*nhop
),
102 void (*del_nexthop
)(const struct nexthop_group_cmd
*nhgc
,
103 const struct nexthop
*nhop
),
104 void (*destroy
)(const char *name
));
106 void nexthop_group_enable_vrf(struct vrf
*vrf
);
107 void nexthop_group_disable_vrf(struct vrf
*vrf
);
108 void nexthop_group_interface_state_change(struct interface
*ifp
,
109 ifindex_t oldifindex
);
111 extern struct nexthop
*nexthop_exists(struct nexthop_group
*nhg
,
114 extern struct nexthop_group_cmd
*nhgc_find(const char *name
);
116 extern void nexthop_group_write_nexthop(struct vty
*vty
, struct nexthop
*nh
);