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__
31 DECLARE_MGROUP(STATIC
);
33 /* Static route label information */
34 struct static_nh_label
{
37 mpls_label_t label
[MPLS_MAX_LABELS
];
40 enum static_blackhole_type
{
41 STATIC_BLACKHOLE_DROP
= 0,
42 STATIC_BLACKHOLE_NULL
,
43 STATIC_BLACKHOLE_REJECT
47 * The order for below macros should be in sync with
48 * yang model typedef nexthop-type
53 STATIC_IPV4_GATEWAY_IFNAME
,
55 STATIC_IPV6_GATEWAY_IFNAME
,
60 * Route Creation gives us:
61 * START -> Initial State, only exit is when we send the route to
62 * zebra for installation
63 * When we send the route to Zebra move to SENT_TO_ZEBRA
64 * SENT_TO_ZEBRA -> A way to notice that we've sent the route to zebra
65 * But have not received a response on it's status yet
66 * After The response from zebra we move to INSTALLED or FAILED
67 * INSTALLED -> Route was accepted
68 * FAILED -> Route was rejected
69 * When we receive notification about a nexthop that a route uses
70 * We move the route back to START and initiate the process again.
72 enum static_install_states
{
79 PREDECL_DLIST(static_path_list
);
80 PREDECL_DLIST(static_nexthop_list
);
82 /* Static route information */
83 struct static_route_info
{
84 struct static_vrf
*svrf
;
87 struct static_path_list_head path_list
;
90 /* Static path information */
92 /* Route node back pointer. */
93 struct route_node
*rn
;
94 /* Linkage for static path lists */
95 struct static_path_list_item list
;
96 /* Administrative distance. */
103 struct static_nexthop_list_head nexthop_list
;
106 DECLARE_DLIST(static_path_list
, struct static_path
, list
);
108 /* Static route information. */
109 struct static_nexthop
{
110 /* Path back pointer. */
111 struct static_path
*pn
;
112 /* For linked list. */
113 struct static_nexthop_list_item list
;
115 /* VRF identifier. */
117 char nh_vrfname
[VRF_NAMSIZ
+ 1];
120 * States that we walk the route through
121 * To know where we are.
123 enum static_install_states state
;
125 /* Flag for this static route's type. */
126 enum static_nh_type type
;
131 enum static_blackhole_type bh_type
;
137 char ifname
[INTERFACE_NAMSIZ
+ 1];
139 /* Label information */
140 struct static_nh_label snh_label
;
143 * Whether to pretend the nexthop is directly attached to the specified
144 * link. Only meaningful when both a gateway address and interface name
153 DECLARE_DLIST(static_nexthop_list
, struct static_nexthop
, list
);
157 * rib_dest_from_rnode
159 static inline struct static_route_info
*
160 static_route_info_from_rnode(struct route_node
*rn
)
162 return (struct static_route_info
*)(rn
->info
);
165 extern bool mpls_enabled
;
166 extern uint32_t zebra_ecmp_count
;
168 extern struct zebra_privs_t static_privs
;
170 void static_fixup_vrf_ids(struct static_vrf
*svrf
);
172 extern struct static_nexthop
*
173 static_add_nexthop(struct static_path
*pn
, enum static_nh_type type
,
174 struct ipaddr
*ipaddr
, const char *ifname
,
175 const char *nh_vrf
, uint32_t color
);
176 extern void static_install_nexthop(struct static_nexthop
*nh
);
178 extern void static_delete_nexthop(struct static_nexthop
*nh
);
180 extern void static_cleanup_vrf_ids(struct static_vrf
*disable_svrf
);
182 extern void static_install_intf_nh(struct interface
*ifp
);
184 extern void static_ifindex_update(struct interface
*ifp
, bool up
);
186 extern void static_install_path(struct static_path
*pn
);
188 extern struct route_node
*static_add_route(afi_t afi
, safi_t safi
,
190 struct prefix_ipv6
*src_p
,
191 struct static_vrf
*svrf
);
192 extern void static_del_route(struct route_node
*rn
);
194 extern struct static_path
*static_add_path(struct route_node
*rn
,
195 uint32_t table_id
, uint8_t distance
);
196 extern void static_del_path(struct static_path
*pn
);
198 extern void static_get_nh_type(enum static_nh_type stype
, char *type
,
200 extern bool static_add_nexthop_validate(const char *nh_vrf_name
,
201 enum static_nh_type type
,
202 struct ipaddr
*ipaddr
);
203 extern struct stable_info
*static_get_stable_info(struct route_node
*rn
);
205 extern void zebra_stable_node_cleanup(struct route_table
*table
,
206 struct route_node
*node
);
209 * Max string return via API static_get_nh_str in size_t
212 #define NEXTHOP_STR (INET6_ADDRSTRLEN + INTERFACE_NAMSIZ + 25)
214 * For the given nexthop, returns the string
215 * nexthop : returns the formatted string in nexthop
216 * size : max size of formatted string
218 extern void static_get_nh_str(struct static_nexthop
*nh
, char *nexthop
,