1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * STATICd - static routes header
4 * Copyright (C) 2018 Cumulus Networks, Inc.
7 #ifndef __STATIC_ROUTES_H__
8 #define __STATIC_ROUTES_H__
19 DECLARE_MGROUP(STATIC
);
21 #include "staticd/static_vrf.h"
23 /* Static route label information */
24 struct static_nh_label
{
27 mpls_label_t label
[MPLS_MAX_LABELS
];
30 enum static_blackhole_type
{
31 STATIC_BLACKHOLE_DROP
= 0,
32 STATIC_BLACKHOLE_NULL
,
33 STATIC_BLACKHOLE_REJECT
37 * The order for below macros should be in sync with
38 * yang model typedef nexthop-type
43 STATIC_IPV4_GATEWAY_IFNAME
,
45 STATIC_IPV6_GATEWAY_IFNAME
,
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.
62 enum static_install_states
{
69 PREDECL_DLIST(static_path_list
);
70 PREDECL_DLIST(static_nexthop_list
);
72 /* Static route information */
73 struct static_route_info
{
74 struct static_vrf
*svrf
;
77 struct static_path_list_head path_list
;
80 /* Static path information */
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. */
93 struct static_nexthop_list_head nexthop_list
;
96 DECLARE_DLIST(static_path_list
, struct static_path
, list
);
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
;
105 /* VRF identifier. */
107 char nh_vrfname
[VRF_NAMSIZ
+ 1];
110 * States that we walk the route through
111 * To know where we are.
113 enum static_install_states state
;
115 /* Flag for this static route's type. */
116 enum static_nh_type type
;
121 enum static_blackhole_type bh_type
;
127 char ifname
[INTERFACE_NAMSIZ
+ 1];
129 /* Label information */
130 struct static_nh_label snh_label
;
133 * Whether to pretend the nexthop is directly attached to the specified
134 * link. Only meaningful when both a gateway address and interface name
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. */
150 DECLARE_DLIST(static_nexthop_list
, struct static_nexthop
, list
);
154 * rib_dest_from_rnode
156 static inline struct static_route_info
*
157 static_route_info_from_rnode(struct route_node
*rn
)
159 return (struct static_route_info
*)(rn
->info
);
162 static inline void static_get_nh_type(enum static_nh_type stype
, char *type
,
167 strlcpy(type
, "ifindex", size
);
169 case STATIC_IPV4_GATEWAY
:
170 strlcpy(type
, "ip4", size
);
172 case STATIC_IPV4_GATEWAY_IFNAME
:
173 strlcpy(type
, "ip4-ifindex", size
);
175 case STATIC_BLACKHOLE
:
176 strlcpy(type
, "blackhole", size
);
178 case STATIC_IPV6_GATEWAY
:
179 strlcpy(type
, "ip6", size
);
181 case STATIC_IPV6_GATEWAY_IFNAME
:
182 strlcpy(type
, "ip6-ifindex", size
);
187 extern bool mpls_enabled
;
188 extern uint32_t zebra_ecmp_count
;
190 extern struct zebra_privs_t static_privs
;
192 void static_fixup_vrf_ids(struct static_vrf
*svrf
);
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
);
200 extern void static_delete_nexthop(struct static_nexthop
*nh
);
202 extern void static_cleanup_vrf_ids(struct static_vrf
*disable_svrf
);
204 extern void static_install_intf_nh(struct interface
*ifp
);
206 extern void static_ifindex_update(struct interface
*ifp
, bool up
);
208 extern void static_install_path(struct static_path
*pn
);
210 extern struct route_node
*static_add_route(afi_t afi
, safi_t safi
,
212 struct prefix_ipv6
*src_p
,
213 struct static_vrf
*svrf
);
214 extern void static_del_route(struct route_node
*rn
);
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
);
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
);
225 extern void zebra_stable_node_cleanup(struct route_table
*table
,
226 struct route_node
*node
);
229 * Max string return via API static_get_nh_str in size_t
232 #define NEXTHOP_STR (INET6_ADDRSTRLEN + INTERFACE_NAMSIZ + 25)
234 * For the given nexthop, returns the string
235 * nexthop : returns the formatted string in nexthop
236 * size : max size of formatted string
238 extern void static_get_nh_str(struct static_nexthop
*nh
, char *nexthop
,
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
,
252 extern void static_next_hop_bfd_multi_hop(struct static_nexthop
*sn
, bool mhop
);
254 /** Call this function after zebra client initialization. */
255 extern void static_bfd_initialize(struct zclient
*zc
, struct event_loop
*tm
);
257 extern void static_bfd_show(struct vty
*vty
, bool isjson
);