2 * STATICd - static routes header
3 * Copyright (C) 2018 Cumulus Networks, Inc.
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)
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
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
20 #ifndef __STATIC_ROUTES_H__
21 #define __STATIC_ROUTES_H__
27 DECLARE_MGROUP(STATIC
);
29 /* Static route label information */
30 struct static_nh_label
{
33 mpls_label_t label
[MPLS_MAX_LABELS
];
36 enum static_blackhole_type
{
37 STATIC_BLACKHOLE_DROP
= 0,
38 STATIC_BLACKHOLE_NULL
,
39 STATIC_BLACKHOLE_REJECT
43 * The order for below macros should be in sync with
44 * yang model typedef nexthop-type
49 STATIC_IPV4_GATEWAY_IFNAME
,
51 STATIC_IPV6_GATEWAY_IFNAME
,
56 * Route Creation gives us:
57 * START -> Initial State, only exit is when we send the route to
58 * zebra for installation
59 * When we send the route to Zebra move to SENT_TO_ZEBRA
60 * SENT_TO_ZEBRA -> A way to notice that we've sent the route to zebra
61 * But have not received a response on it's status yet
62 * After The response from zebra we move to INSTALLED or FAILED
63 * INSTALLED -> Route was accepted
64 * FAILED -> Route was rejected
65 * When we receive notification about a nexthop that a route uses
66 * We move the route back to START and initiate the process again.
68 enum static_install_states
{
75 PREDECL_DLIST(static_path_list
);
76 PREDECL_DLIST(static_nexthop_list
);
78 /* Static route information */
79 struct static_route_info
{
81 struct static_path_list_head path_list
;
84 /* Static path information */
86 /* Linkage for static path lists */
87 struct static_path_list_item list
;
88 /* Administrative distance. */
95 struct static_nexthop_list_head nexthop_list
;
98 DECLARE_DLIST(static_path_list
, struct static_path
, list
);
100 /* Static route information. */
101 struct static_nexthop
{
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. */
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
143 DECLARE_DLIST(static_nexthop_list
, struct static_nexthop
, list
);
147 * rib_dest_from_rnode
149 static inline struct static_route_info
*
150 static_route_info_from_rnode(struct route_node
*rn
)
152 return (struct static_route_info
*)(rn
->info
);
155 extern bool mpls_enabled
;
157 extern struct zebra_privs_t static_privs
;
159 void static_fixup_vrf_ids(struct static_vrf
*svrf
);
161 extern struct static_nexthop
*
162 static_add_nexthop(struct route_node
*rn
, struct static_path
*pn
, safi_t safi
,
163 struct static_vrf
*svrf
, static_types type
,
164 struct ipaddr
*ipaddr
, const char *ifname
,
165 const char *nh_vrf
, uint32_t color
);
166 extern void static_install_nexthop(struct route_node
*rn
,
167 struct static_path
*pn
,
168 struct static_nexthop
*nh
, safi_t safi
,
169 struct static_vrf
*svrf
, const char *ifname
,
170 static_types type
, const char *nh_vrf
);
172 extern int static_delete_nexthop(struct route_node
*rn
, struct static_path
*pn
,
173 safi_t safi
, struct static_vrf
*svrf
,
174 struct static_nexthop
*nh
);
176 extern void static_cleanup_vrf_ids(struct static_vrf
*disable_svrf
);
178 extern void static_install_intf_nh(struct interface
*ifp
);
180 extern void static_ifindex_update(struct interface
*ifp
, bool up
);
182 extern void static_install_path(struct route_node
*rn
, struct static_path
*pn
,
183 safi_t safi
, struct static_vrf
*svrf
);
185 extern struct route_node
*static_add_route(afi_t afi
, safi_t safi
,
187 struct prefix_ipv6
*src_p
,
188 struct static_vrf
*svrf
);
189 extern void static_del_route(struct route_node
*rn
, safi_t safi
,
190 struct static_vrf
*svrf
);
192 extern struct static_path
*static_add_path(struct route_node
*rn
,
193 uint32_t table_id
, uint8_t distance
);
194 extern void static_del_path(struct route_node
*rn
, struct static_path
*pn
,
195 safi_t safi
, struct static_vrf
*svrf
);
197 extern void static_get_nh_type(static_types stype
, char *type
, size_t size
);
198 extern bool static_add_nexthop_validate(const char *nh_vrf_name
,
200 struct ipaddr
*ipaddr
);
201 extern struct stable_info
*static_get_stable_info(struct route_node
*rn
);
202 extern void static_route_info_init(struct static_route_info
*si
);
204 extern void zebra_stable_node_cleanup(struct route_table
*table
,
205 struct route_node
*node
);
208 * Max string return via API static_get_nh_str in size_t
211 #define NEXTHOP_STR (INET6_ADDRSTRLEN + INTERFACE_NAMSIZ + 25)
213 * For the given nexthop, returns the string
214 * nexthop : returns the formatted string in nexthop
215 * size : max size of formatted string
217 extern void static_get_nh_str(struct static_nexthop
*nh
, char *nexthop
,