]> git.proxmox.com Git - mirror_frr.git/blob - staticd/static_routes.h
Merge pull request #8167 from LabNConsulting/chopps/tests-add-gdb
[mirror_frr.git] / staticd / static_routes.h
1 /*
2 * STATICd - static routes header
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 #ifndef __STATIC_ROUTES_H__
21 #define __STATIC_ROUTES_H__
22
23 #include "lib/mpls.h"
24 #include "table.h"
25 #include "memory.h"
26
27 DECLARE_MGROUP(STATIC);
28
29 /* Static route label information */
30 struct static_nh_label {
31 uint8_t num_labels;
32 uint8_t reserved[3];
33 mpls_label_t label[MPLS_MAX_LABELS];
34 };
35
36 enum static_blackhole_type {
37 STATIC_BLACKHOLE_DROP = 0,
38 STATIC_BLACKHOLE_NULL,
39 STATIC_BLACKHOLE_REJECT
40 };
41
42 /*
43 * The order for below macros should be in sync with
44 * yang model typedef nexthop-type
45 */
46 typedef enum {
47 STATIC_IFNAME = 1,
48 STATIC_IPV4_GATEWAY,
49 STATIC_IPV4_GATEWAY_IFNAME,
50 STATIC_IPV6_GATEWAY,
51 STATIC_IPV6_GATEWAY_IFNAME,
52 STATIC_BLACKHOLE,
53 } static_types;
54
55 /*
56 * Route Creation gives us:
57 * START -> Initial State, only exit is when we send the route to
58 * zebra for installation
59 * When we send the route to Zebra move to SENT_TO_ZEBRA
60 * SENT_TO_ZEBRA -> A way to notice that we've sent the route to zebra
61 * But have not received a response on it's status yet
62 * After The response from zebra we move to INSTALLED or FAILED
63 * INSTALLED -> Route was accepted
64 * FAILED -> Route was rejected
65 * When we receive notification about a nexthop that a route uses
66 * We move the route back to START and initiate the process again.
67 */
68 enum static_install_states {
69 STATIC_START,
70 STATIC_SENT_TO_ZEBRA,
71 STATIC_INSTALLED,
72 STATIC_NOT_INSTALLED,
73 };
74
75 PREDECL_DLIST(static_path_list);
76 PREDECL_DLIST(static_nexthop_list);
77
78 /* Static route information */
79 struct static_route_info {
80 /* path list */
81 struct static_path_list_head path_list;
82 };
83
84 /* Static path information */
85 struct static_path {
86 /* Linkage for static path lists */
87 struct static_path_list_item list;
88 /* Administrative distance. */
89 uint8_t distance;
90 /* Tag */
91 route_tag_t tag;
92 /* Table-id */
93 uint32_t table_id;
94 /* Nexthop list */
95 struct static_nexthop_list_head nexthop_list;
96 };
97
98 DECLARE_DLIST(static_path_list, struct static_path, list);
99
100 /* Static route information. */
101 struct static_nexthop {
102 /* For linked list. */
103 struct static_nexthop_list_item list;
104
105 /* VRF identifier. */
106 vrf_id_t nh_vrf_id;
107 char nh_vrfname[VRF_NAMSIZ + 1];
108
109 /*
110 * States that we walk the route through
111 * To know where we are.
112 */
113 enum static_install_states state;
114
115 /* Flag for this static route's type. */
116 static_types type;
117
118 /*
119 * Nexthop value.
120 */
121 enum static_blackhole_type bh_type;
122 union g_addr addr;
123 ifindex_t ifindex;
124 bool nh_registered;
125 bool nh_valid;
126
127 char ifname[INTERFACE_NAMSIZ + 1];
128
129 /* Label information */
130 struct static_nh_label snh_label;
131
132 /*
133 * Whether to pretend the nexthop is directly attached to the specified
134 * link. Only meaningful when both a gateway address and interface name
135 * are specified.
136 */
137 bool onlink;
138
139 /* SR-TE color */
140 uint32_t color;
141 };
142
143 DECLARE_DLIST(static_nexthop_list, struct static_nexthop, list);
144
145
146 /*
147 * rib_dest_from_rnode
148 */
149 static inline struct static_route_info *
150 static_route_info_from_rnode(struct route_node *rn)
151 {
152 return (struct static_route_info *)(rn->info);
153 }
154
155 extern bool mpls_enabled;
156
157 extern struct zebra_privs_t static_privs;
158
159 void static_fixup_vrf_ids(struct static_vrf *svrf);
160
161 extern struct static_nexthop *
162 static_add_nexthop(struct route_node *rn, struct static_path *pn, safi_t safi,
163 struct static_vrf *svrf, static_types type,
164 struct ipaddr *ipaddr, const char *ifname,
165 const char *nh_vrf, uint32_t color);
166 extern void static_install_nexthop(struct route_node *rn,
167 struct static_path *pn,
168 struct static_nexthop *nh, safi_t safi,
169 struct static_vrf *svrf, const char *ifname,
170 static_types type, const char *nh_vrf);
171
172 extern int static_delete_nexthop(struct route_node *rn, struct static_path *pn,
173 safi_t safi, struct static_vrf *svrf,
174 struct static_nexthop *nh);
175
176 extern void static_cleanup_vrf_ids(struct static_vrf *disable_svrf);
177
178 extern void static_install_intf_nh(struct interface *ifp);
179
180 extern void static_ifindex_update(struct interface *ifp, bool up);
181
182 extern void static_install_path(struct route_node *rn, struct static_path *pn,
183 safi_t safi, struct static_vrf *svrf);
184
185 extern struct route_node *static_add_route(afi_t afi, safi_t safi,
186 struct prefix *p,
187 struct prefix_ipv6 *src_p,
188 struct static_vrf *svrf);
189 extern void static_del_route(struct route_node *rn, safi_t safi,
190 struct static_vrf *svrf);
191
192 extern struct static_path *static_add_path(struct route_node *rn,
193 uint32_t table_id, uint8_t distance);
194 extern void static_del_path(struct route_node *rn, struct static_path *pn,
195 safi_t safi, struct static_vrf *svrf);
196
197 extern void static_get_nh_type(static_types stype, char *type, size_t size);
198 extern bool static_add_nexthop_validate(const char *nh_vrf_name,
199 static_types type,
200 struct ipaddr *ipaddr);
201 extern struct stable_info *static_get_stable_info(struct route_node *rn);
202 extern void static_route_info_init(struct static_route_info *si);
203
204 extern void zebra_stable_node_cleanup(struct route_table *table,
205 struct route_node *node);
206
207 /*
208 * Max string return via API static_get_nh_str in size_t
209 */
210
211 #define NEXTHOP_STR (INET6_ADDRSTRLEN + INTERFACE_NAMSIZ + 25)
212 /*
213 * For the given nexthop, returns the string
214 * nexthop : returns the formatted string in nexthop
215 * size : max size of formatted string
216 */
217 extern void static_get_nh_str(struct static_nexthop *nh, char *nexthop,
218 size_t size);
219 #endif