]> git.proxmox.com Git - mirror_frr.git/blob - staticd/static_routes.h
Merge pull request #12798 from donaldsharp/rib_match_multicast
[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 extern bool mpls_enabled;
163 extern uint32_t zebra_ecmp_count;
164
165 extern struct zebra_privs_t static_privs;
166
167 void static_fixup_vrf_ids(struct static_vrf *svrf);
168
169 extern struct static_nexthop *
170 static_add_nexthop(struct static_path *pn, enum static_nh_type type,
171 struct ipaddr *ipaddr, const char *ifname,
172 const char *nh_vrf, uint32_t color);
173 extern void static_install_nexthop(struct static_nexthop *nh);
174
175 extern void static_delete_nexthop(struct static_nexthop *nh);
176
177 extern void static_cleanup_vrf_ids(struct static_vrf *disable_svrf);
178
179 extern void static_install_intf_nh(struct interface *ifp);
180
181 extern void static_ifindex_update(struct interface *ifp, bool up);
182
183 extern void static_install_path(struct static_path *pn);
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);
190
191 extern struct static_path *static_add_path(struct route_node *rn,
192 uint32_t table_id, uint8_t distance);
193 extern void static_del_path(struct static_path *pn);
194
195 extern void static_get_nh_type(enum static_nh_type stype, char *type,
196 size_t size);
197 extern bool static_add_nexthop_validate(const char *nh_vrf_name,
198 enum static_nh_type type,
199 struct ipaddr *ipaddr);
200 extern struct stable_info *static_get_stable_info(struct route_node *rn);
201
202 extern void zebra_stable_node_cleanup(struct route_table *table,
203 struct route_node *node);
204
205 /*
206 * Max string return via API static_get_nh_str in size_t
207 */
208
209 #define NEXTHOP_STR (INET6_ADDRSTRLEN + INTERFACE_NAMSIZ + 25)
210 /*
211 * For the given nexthop, returns the string
212 * nexthop : returns the formatted string in nexthop
213 * size : max size of formatted string
214 */
215 extern void static_get_nh_str(struct static_nexthop *nh, char *nexthop,
216 size_t size);
217
218 /*
219 * BFD integration.
220 */
221 extern void static_next_hop_bfd_source(struct static_nexthop *sn,
222 const struct ipaddr *source);
223 extern void static_next_hop_bfd_auto_source(struct static_nexthop *sn);
224 extern void static_next_hop_bfd_monitor_enable(struct static_nexthop *sn,
225 const struct lyd_node *dnode);
226 extern void static_next_hop_bfd_monitor_disable(struct static_nexthop *sn);
227 extern void static_next_hop_bfd_profile(struct static_nexthop *sn,
228 const char *name);
229 extern void static_next_hop_bfd_multi_hop(struct static_nexthop *sn, bool mhop);
230
231 /** Call this function after zebra client initialization. */
232 extern void static_bfd_initialize(struct zclient *zc, struct thread_master *tm);
233
234 extern void static_bfd_show(struct vty *vty, bool isjson);
235
236 #ifdef __cplusplus
237 }
238 #endif
239
240 #endif