]> git.proxmox.com Git - mirror_frr.git/blob - staticd/static_routes.h
Merge pull request #13113 from sri-mohan1/sri-mohan-ldp
[mirror_frr.git] / staticd / static_routes.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * STATICd - static routes header
4 * Copyright (C) 2018 Cumulus Networks, Inc.
5 * Donald Sharp
6 */
7 #ifndef __STATIC_ROUTES_H__
8 #define __STATIC_ROUTES_H__
9
10 #include "lib/bfd.h"
11 #include "lib/mpls.h"
12 #include "table.h"
13 #include "memory.h"
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19 DECLARE_MGROUP(STATIC);
20
21 #include "staticd/static_vrf.h"
22
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
36 /*
37 * The order for below macros should be in sync with
38 * yang model typedef nexthop-type
39 */
40 enum static_nh_type {
41 STATIC_IFNAME = 1,
42 STATIC_IPV4_GATEWAY,
43 STATIC_IPV4_GATEWAY_IFNAME,
44 STATIC_IPV6_GATEWAY,
45 STATIC_IPV6_GATEWAY_IFNAME,
46 STATIC_BLACKHOLE,
47 };
48
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
69 PREDECL_DLIST(static_path_list);
70 PREDECL_DLIST(static_nexthop_list);
71
72 /* Static route information */
73 struct static_route_info {
74 struct static_vrf *svrf;
75 safi_t safi;
76 /* path list */
77 struct static_path_list_head path_list;
78 };
79
80 /* Static path information */
81 struct static_path {
82 /* Route node back pointer. */
83 struct route_node *rn;
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
98 /* Static route information. */
99 struct static_nexthop {
100 /* Path back pointer. */
101 struct static_path *pn;
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 enum static_nh_type 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 /** 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;
148 };
149
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
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
187 extern bool mpls_enabled;
188 extern uint32_t zebra_ecmp_count;
189
190 extern struct zebra_privs_t static_privs;
191
192 void static_fixup_vrf_ids(struct static_vrf *svrf);
193
194 extern struct static_nexthop *
195 static_add_nexthop(struct static_path *pn, enum static_nh_type type,
196 struct ipaddr *ipaddr, const char *ifname,
197 const char *nh_vrf, uint32_t color);
198 extern void static_install_nexthop(struct static_nexthop *nh);
199
200 extern void static_delete_nexthop(struct static_nexthop *nh);
201
202 extern void static_cleanup_vrf_ids(struct static_vrf *disable_svrf);
203
204 extern void static_install_intf_nh(struct interface *ifp);
205
206 extern void static_ifindex_update(struct interface *ifp, bool up);
207
208 extern void static_install_path(struct static_path *pn);
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);
214 extern void static_del_route(struct route_node *rn);
215
216 extern struct static_path *static_add_path(struct route_node *rn,
217 uint32_t table_id, uint8_t distance);
218 extern void static_del_path(struct static_path *pn);
219
220 extern bool static_add_nexthop_validate(const char *nh_vrf_name,
221 enum static_nh_type type,
222 struct ipaddr *ipaddr);
223 extern struct stable_info *static_get_stable_info(struct route_node *rn);
224
225 extern void zebra_stable_node_cleanup(struct route_table *table,
226 struct route_node *node);
227
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);
240
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. */
255 extern void static_bfd_initialize(struct zclient *zc, struct event_loop *tm);
256
257 extern void static_bfd_show(struct vty *vty, bool isjson);
258
259 #ifdef __cplusplus
260 }
261 #endif
262
263 #endif