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