]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
7e24fdf3 DS |
2 | /* |
3 | * STATICd - static routes header | |
4 | * Copyright (C) 2018 Cumulus Networks, Inc. | |
5 | * Donald Sharp | |
7e24fdf3 DS |
6 | */ |
7 | #ifndef __STATIC_ROUTES_H__ | |
8 | #define __STATIC_ROUTES_H__ | |
9 | ||
351ad684 | 10 | #include "lib/bfd.h" |
7e24fdf3 | 11 | #include "lib/mpls.h" |
88fa5104 | 12 | #include "table.h" |
8392606e DL |
13 | #include "memory.h" |
14 | ||
deca28a3 CH |
15 | #ifdef __cplusplus |
16 | extern "C" { | |
17 | #endif | |
18 | ||
8392606e | 19 | DECLARE_MGROUP(STATIC); |
7e24fdf3 | 20 | |
351ad684 RZ |
21 | #include "staticd/static_vrf.h" |
22 | ||
7e24fdf3 DS |
23 | /* Static route label information */ |
24 | struct static_nh_label { | |
25 | uint8_t num_labels; | |
26 | uint8_t reserved[3]; | |
27 | mpls_label_t label[MPLS_MAX_LABELS]; | |
28 | }; | |
29 | ||
30 | enum static_blackhole_type { | |
31 | STATIC_BLACKHOLE_DROP = 0, | |
32 | STATIC_BLACKHOLE_NULL, | |
33 | STATIC_BLACKHOLE_REJECT | |
34 | }; | |
35 | ||
88fa5104 | 36 | /* |
37 | * The order for below macros should be in sync with | |
38 | * yang model typedef nexthop-type | |
39 | */ | |
9ccaa12d | 40 | enum static_nh_type { |
88fa5104 | 41 | STATIC_IFNAME = 1, |
7e24fdf3 DS |
42 | STATIC_IPV4_GATEWAY, |
43 | STATIC_IPV4_GATEWAY_IFNAME, | |
7e24fdf3 DS |
44 | STATIC_IPV6_GATEWAY, |
45 | STATIC_IPV6_GATEWAY_IFNAME, | |
88fa5104 | 46 | STATIC_BLACKHOLE, |
9ccaa12d | 47 | }; |
7e24fdf3 | 48 | |
0ed857ab DS |
49 | /* |
50 | * Route Creation gives us: | |
51 | * START -> Initial State, only exit is when we send the route to | |
52 | * zebra for installation | |
53 | * When we send the route to Zebra move to SENT_TO_ZEBRA | |
54 | * SENT_TO_ZEBRA -> A way to notice that we've sent the route to zebra | |
55 | * But have not received a response on it's status yet | |
56 | * After The response from zebra we move to INSTALLED or FAILED | |
57 | * INSTALLED -> Route was accepted | |
58 | * FAILED -> Route was rejected | |
59 | * When we receive notification about a nexthop that a route uses | |
60 | * We move the route back to START and initiate the process again. | |
61 | */ | |
62 | enum static_install_states { | |
63 | STATIC_START, | |
64 | STATIC_SENT_TO_ZEBRA, | |
65 | STATIC_INSTALLED, | |
66 | STATIC_NOT_INSTALLED, | |
67 | }; | |
68 | ||
88fa5104 | 69 | PREDECL_DLIST(static_path_list); |
70 | PREDECL_DLIST(static_nexthop_list); | |
71 | ||
72 | /* Static route information */ | |
73 | struct static_route_info { | |
4067e951 IR |
74 | struct static_vrf *svrf; |
75 | safi_t safi; | |
88fa5104 | 76 | /* path list */ |
77 | struct static_path_list_head path_list; | |
78 | }; | |
79 | ||
80 | /* Static path information */ | |
81 | struct static_path { | |
4067e951 IR |
82 | /* Route node back pointer. */ |
83 | struct route_node *rn; | |
88fa5104 | 84 | /* Linkage for static path lists */ |
85 | struct static_path_list_item list; | |
86 | /* Administrative distance. */ | |
87 | uint8_t distance; | |
88 | /* Tag */ | |
89 | route_tag_t tag; | |
90 | /* Table-id */ | |
91 | uint32_t table_id; | |
92 | /* Nexthop list */ | |
93 | struct static_nexthop_list_head nexthop_list; | |
94 | }; | |
95 | ||
96 | DECLARE_DLIST(static_path_list, struct static_path, list); | |
97 | ||
7e24fdf3 | 98 | /* Static route information. */ |
88fa5104 | 99 | struct static_nexthop { |
4067e951 IR |
100 | /* Path back pointer. */ |
101 | struct static_path *pn; | |
7e24fdf3 | 102 | /* For linked list. */ |
88fa5104 | 103 | struct static_nexthop_list_item list; |
7e24fdf3 DS |
104 | |
105 | /* VRF identifier. */ | |
7e24fdf3 DS |
106 | vrf_id_t nh_vrf_id; |
107 | char nh_vrfname[VRF_NAMSIZ + 1]; | |
108 | ||
0ed857ab DS |
109 | /* |
110 | * States that we walk the route through | |
111 | * To know where we are. | |
112 | */ | |
113 | enum static_install_states state; | |
114 | ||
7e24fdf3 | 115 | /* Flag for this static route's type. */ |
9ccaa12d | 116 | enum static_nh_type type; |
7e24fdf3 DS |
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 | ||
02dc8ba3 QY |
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; | |
065276ae SM |
138 | |
139 | /* SR-TE color */ | |
140 | uint32_t color; | |
351ad684 RZ |
141 | |
142 | /** BFD integration data. */ | |
143 | struct bfd_session_params *bsp; | |
144 | /** Back pointer for route node. */ | |
145 | struct route_node *rn; | |
146 | /** Path connection status. */ | |
147 | bool path_down; | |
7e24fdf3 DS |
148 | }; |
149 | ||
88fa5104 | 150 | DECLARE_DLIST(static_nexthop_list, struct static_nexthop, list); |
151 | ||
152 | ||
153 | /* | |
154 | * rib_dest_from_rnode | |
155 | */ | |
156 | static inline struct static_route_info * | |
157 | static_route_info_from_rnode(struct route_node *rn) | |
158 | { | |
159 | return (struct static_route_info *)(rn->info); | |
160 | } | |
161 | ||
d1e85e36 CH |
162 | static inline void static_get_nh_type(enum static_nh_type stype, char *type, |
163 | size_t size) | |
164 | { | |
165 | switch (stype) { | |
166 | case STATIC_IFNAME: | |
167 | strlcpy(type, "ifindex", size); | |
168 | break; | |
169 | case STATIC_IPV4_GATEWAY: | |
170 | strlcpy(type, "ip4", size); | |
171 | break; | |
172 | case STATIC_IPV4_GATEWAY_IFNAME: | |
173 | strlcpy(type, "ip4-ifindex", size); | |
174 | break; | |
175 | case STATIC_BLACKHOLE: | |
176 | strlcpy(type, "blackhole", size); | |
177 | break; | |
178 | case STATIC_IPV6_GATEWAY: | |
179 | strlcpy(type, "ip6", size); | |
180 | break; | |
181 | case STATIC_IPV6_GATEWAY_IFNAME: | |
182 | strlcpy(type, "ip6-ifindex", size); | |
183 | break; | |
184 | }; | |
185 | } | |
186 | ||
7e24fdf3 | 187 | extern bool mpls_enabled; |
abc246e1 | 188 | extern uint32_t zebra_ecmp_count; |
7e24fdf3 DS |
189 | |
190 | extern struct zebra_privs_t static_privs; | |
191 | ||
192 | void static_fixup_vrf_ids(struct static_vrf *svrf); | |
193 | ||
88fa5104 | 194 | extern struct static_nexthop * |
9ccaa12d | 195 | static_add_nexthop(struct static_path *pn, enum static_nh_type type, |
88fa5104 | 196 | struct ipaddr *ipaddr, const char *ifname, |
065276ae | 197 | const char *nh_vrf, uint32_t color); |
4067e951 | 198 | extern void static_install_nexthop(struct static_nexthop *nh); |
88fa5104 | 199 | |
4067e951 | 200 | extern void static_delete_nexthop(struct static_nexthop *nh); |
7e24fdf3 DS |
201 | |
202 | extern void static_cleanup_vrf_ids(struct static_vrf *disable_svrf); | |
203 | ||
a9be49bc DS |
204 | extern void static_install_intf_nh(struct interface *ifp); |
205 | ||
7e24fdf3 | 206 | extern void static_ifindex_update(struct interface *ifp, bool up); |
88fa5104 | 207 | |
4067e951 | 208 | extern void static_install_path(struct static_path *pn); |
88fa5104 | 209 | |
210 | extern struct route_node *static_add_route(afi_t afi, safi_t safi, | |
211 | struct prefix *p, | |
212 | struct prefix_ipv6 *src_p, | |
213 | struct static_vrf *svrf); | |
4067e951 | 214 | extern void static_del_route(struct route_node *rn); |
88fa5104 | 215 | |
216 | extern struct static_path *static_add_path(struct route_node *rn, | |
ef4b6b22 | 217 | uint32_t table_id, uint8_t distance); |
4067e951 | 218 | extern void static_del_path(struct static_path *pn); |
88fa5104 | 219 | |
ddd45515 | 220 | extern bool static_add_nexthop_validate(const char *nh_vrf_name, |
9ccaa12d | 221 | enum static_nh_type type, |
88fa5104 | 222 | struct ipaddr *ipaddr); |
223 | extern struct stable_info *static_get_stable_info(struct route_node *rn); | |
b2f6ab67 | 224 | |
8392606e DL |
225 | extern void zebra_stable_node_cleanup(struct route_table *table, |
226 | struct route_node *node); | |
227 | ||
b2f6ab67 | 228 | /* |
229 | * Max string return via API static_get_nh_str in size_t | |
230 | */ | |
231 | ||
232 | #define NEXTHOP_STR (INET6_ADDRSTRLEN + INTERFACE_NAMSIZ + 25) | |
233 | /* | |
234 | * For the given nexthop, returns the string | |
235 | * nexthop : returns the formatted string in nexthop | |
236 | * size : max size of formatted string | |
237 | */ | |
238 | extern void static_get_nh_str(struct static_nexthop *nh, char *nexthop, | |
239 | size_t size); | |
deca28a3 | 240 | |
351ad684 RZ |
241 | /* |
242 | * BFD integration. | |
243 | */ | |
244 | extern void static_next_hop_bfd_source(struct static_nexthop *sn, | |
245 | const struct ipaddr *source); | |
246 | extern void static_next_hop_bfd_auto_source(struct static_nexthop *sn); | |
247 | extern void static_next_hop_bfd_monitor_enable(struct static_nexthop *sn, | |
248 | const struct lyd_node *dnode); | |
249 | extern void static_next_hop_bfd_monitor_disable(struct static_nexthop *sn); | |
250 | extern void static_next_hop_bfd_profile(struct static_nexthop *sn, | |
251 | const char *name); | |
252 | extern void static_next_hop_bfd_multi_hop(struct static_nexthop *sn, bool mhop); | |
253 | ||
254 | /** Call this function after zebra client initialization. */ | |
cd9d0537 | 255 | extern void static_bfd_initialize(struct zclient *zc, struct event_loop *tm); |
351ad684 | 256 | |
d8c78a8d RZ |
257 | extern void static_bfd_show(struct vty *vty, bool isjson); |
258 | ||
deca28a3 CH |
259 | #ifdef __cplusplus |
260 | } | |
261 | #endif | |
262 | ||
7e24fdf3 | 263 | #endif |