]> git.proxmox.com Git - mirror_frr.git/blob - lib/nexthop_group.h
zebra: Allow ns delete to happen after under/over flow checks
[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
26 /*
27 * What is a nexthop group?
28 *
29 * A nexthop group is a collection of nexthops that make up
30 * the ECMP path for the route.
31 *
32 * This module provides a proper abstraction to this idea.
33 */
34 struct nexthop_group {
35 struct nexthop *nexthop;
36 };
37
38 struct nexthop_group *nexthop_group_new(void);
39 void nexthop_group_delete(struct nexthop_group **nhg);
40
41 void nexthop_add(struct nexthop **target, struct nexthop *nexthop);
42 void nexthop_del(struct nexthop_group *nhg, struct nexthop *nexthop);
43 void copy_nexthops(struct nexthop **tnh, struct nexthop *nh,
44 struct nexthop *rparent);
45
46 /* The following for loop allows to iterate over the nexthop
47 * structure of routes.
48 *
49 * head: The pointer to the first nexthop in the chain.
50 *
51 * nexthop: The pointer to the current nexthop, either in the
52 * top-level chain or in a resolved chain.
53 */
54 #define ALL_NEXTHOPS(head, nhop) \
55 (nhop) = (head.nexthop); \
56 (nhop); \
57 (nhop) = nexthop_next(nhop)
58
59 #define ALL_NEXTHOPS_PTR(head, nhop) \
60 (nhop) = ((head)->nexthop); \
61 (nhop); \
62 (nhop) = nexthop_next(nhop)
63
64
65 struct nexthop_hold {
66 char *nhvrf_name;
67 union sockunion addr;
68 char *intf;
69 };
70
71 struct nexthop_group_cmd {
72
73 RB_ENTRY(nexthop_group_cmd) nhgc_entry;
74
75 char name[80];
76
77 struct nexthop_group nhg;
78
79 struct list *nhg_list;
80
81 QOBJ_FIELDS
82 };
83 RB_HEAD(nhgc_entry_head, nexthp_group_cmd);
84 RB_PROTOTYPE(nhgc_entry_head, nexthop_group_cmd, nhgc_entry,
85 nexthop_group_cmd_compare)
86 DECLARE_QOBJ_TYPE(nexthop_group_cmd)
87
88 /*
89 * Initialize nexthop_groups. If you are interested in when
90 * a nexthop_group is added/deleted/modified, then set the
91 * appropriate callback functions to handle it in your
92 * code
93 */
94 void nexthop_group_init(
95 void (*new)(const char *name),
96 void (*add_nexthop)(const struct nexthop_group_cmd *nhgc,
97 const struct nexthop *nhop),
98 void (*del_nexthop)(const struct nexthop_group_cmd *nhgc,
99 const struct nexthop *nhop),
100 void (*delete)(const char *name));
101
102 void nexthop_group_enable_vrf(struct vrf *vrf);
103 void nexthop_group_disable_vrf(struct vrf *vrf);
104 void nexthop_group_interface_state_change(struct interface *ifp,
105 ifindex_t oldifindex);
106
107 extern struct nexthop *nexthop_exists(struct nexthop_group *nhg,
108 struct nexthop *nh);
109
110 extern struct nexthop_group_cmd *nhgc_find(const char *name);
111
112 extern void nexthop_group_write_nexthop(struct vty *vty, struct nexthop *nh);
113 #endif