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