1 /* Zebra Router header.
2 * Copyright (C) 2018 Cumulus Networks, Inc.
5 * This file is part of FRR.
7 * FRR is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * FRR is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with FRR; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 #ifndef __ZEBRA_ROUTER_H__
23 #define __ZEBRA_ROUTER_H__
27 #include "zebra/zebra_ns.h"
34 * This header file contains the idea of a router and as such
35 * owns data that is associated with a router from zebra's
39 struct zebra_router_table
{
40 RB_ENTRY(zebra_router_table
) zebra_router_table_entry
;
47 struct route_table
*table
;
49 RB_HEAD(zebra_router_table_head
, zebra_router_table
);
50 RB_PROTOTYPE(zebra_router_table_head
, zebra_router_table
,
51 zebra_router_table_entry
, zebra_router_table_entry_compare
)
53 /* RPF lookup behaviour */
55 MCAST_NO_CONFIG
= 0, /* MIX_MRIB_FIRST, but no show in config write */
56 MCAST_MRIB_ONLY
, /* MRIB only */
57 MCAST_URIB_ONLY
, /* URIB only */
58 MCAST_MIX_MRIB_FIRST
, /* MRIB, if nothing at all then URIB */
59 MCAST_MIX_DISTANCE
, /* MRIB & URIB, lower distance wins */
60 MCAST_MIX_PFXLEN
, /* MRIB & URIB, longer prefix wins */
61 /* on equal value, MRIB wins for last 2 */
64 /* An interface can be error-disabled if a protocol (such as EVPN or
65 * VRRP) detects a problem with keeping it operationally-up.
66 * If any of the protodown bits are set protodown-on is programmed
67 * in the dataplane. This results in a carrier/L1 down on the
70 enum protodown_reasons
{
71 /* On startup local ESs are held down for some time to
72 * allow the underlay to converge and EVPN routes to
75 ZEBRA_PROTODOWN_EVPN_STARTUP_DELAY
= (1 << 0),
76 /* If all the uplinks are down the switch has lost access
77 * to the VxLAN overlay and must shut down the access
78 * ports to allow servers to re-direct their traffic to
79 * other switches on the Ethernet Segment
81 ZEBRA_PROTODOWN_EVPN_UPLINK_DOWN
= (1 << 1),
82 ZEBRA_PROTODOWN_EVPN_ALL
= (ZEBRA_PROTODOWN_EVPN_UPLINK_DOWN
83 | ZEBRA_PROTODOWN_EVPN_STARTUP_DELAY
)
85 #define ZEBRA_PROTODOWN_RC_STR_LEN 80
87 struct zebra_mlag_info
{
88 /* Role this zebra router is playing */
91 /* The peerlink being used for mlag */
93 ifindex_t peerlink_ifindex
;
95 /* The system mac being used */
98 * Zebra will open the communication channel with MLAGD only if any
99 * clients are interested and it is controlled dynamically based on
100 * client registers & un-registers.
102 uint32_t clients_interested_cnt
;
104 /* coomunication channel with MLAGD is established */
107 /* connection retry timer is running */
110 /* Holds the client data(unencoded) that need to be pushed to MCLAGD*/
111 struct stream_fifo
*mlag_fifo
;
114 * A new Kernel thread will be created to post the data to MCLAGD.
115 * where as, read will be performed from the zebra main thread, because
116 * read involves accessing client registartion data structures.
118 struct frr_pthread
*zebra_pth_mlag
;
120 /* MLAG Thread context 'master' */
121 struct thread_master
*th_master
;
124 * Event for Initial MLAG Connection setup & Data Read
125 * Read can be performed only after successful connection establishment,
129 struct thread
*t_read
;
130 /* Event for MLAG write */
131 struct thread
*t_write
;
134 struct zebra_router
{
135 atomic_bool in_shutdown
;
138 struct thread_master
*master
;
140 /* Lists of clients who have connected to us */
141 struct list
*client_list
;
143 /* List of clients in GR */
144 struct list
*stale_client_list
;
146 struct zebra_router_table_head tables
;
148 /* L3-VNI hash table (for EVPN). Only in default instance */
149 struct hash
*l3vni_table
;
151 /* Tables and other global info maintained for EVPN multihoming */
152 struct zebra_evpn_mh_info
*mh_info
;
154 /* EVPN MH broadcast domains indexed by the VID */
155 struct hash
*evpn_vlan_table
;
157 struct hash
*rules_hash
;
159 struct hash
*ipset_hash
;
161 struct hash
*ipset_entry_hash
;
163 struct hash
*iptable_hash
;
165 /* A sequence number used for tracking routes */
166 _Atomic
uint32_t sequence_num
;
169 #define ZEBRA_RIB_PROCESS_HOLD_TIME 10
170 #define ZEBRA_RIB_PROCESS_RETRY_TIME 1
171 struct work_queue
*ribq
;
173 /* Meta Queue Information */
174 struct meta_queue
*mq
;
177 struct work_queue
*lsp_process_q
;
179 #define ZEBRA_ZAPI_PACKETS_TO_PROCESS 1000
180 _Atomic
uint32_t packets_to_process
;
182 /* Mlag information for the router */
183 struct zebra_mlag_info mlag_info
;
186 * The EVPN instance, if any
188 struct zebra_vrf
*evpn_vrf
;
190 uint32_t multipath_num
;
192 /* RPF Lookup behavior */
193 enum multicast_mode ipv4_multicast_mode
;
196 * Time for when we sweep the rib from old routes
201 * The hash of nexthop groups associated with this router
204 struct hash
*nhgs_id
;
207 * Does the underlying system provide an asic offload
213 #define GRACEFUL_RESTART_TIME 60
215 extern struct zebra_router zrouter
;
217 extern void zebra_router_init(bool asic_offload
, bool notify_on_ack
);
218 extern void zebra_router_cleanup(void);
219 extern void zebra_router_terminate(void);
221 extern struct zebra_router_table
*zebra_router_find_zrt(struct zebra_vrf
*zvrf
,
223 afi_t afi
, safi_t safi
);
224 extern struct route_table
*zebra_router_find_table(struct zebra_vrf
*zvrf
,
225 uint32_t tableid
, afi_t afi
,
227 extern struct route_table
*zebra_router_get_table(struct zebra_vrf
*zvrf
,
228 uint32_t tableid
, afi_t afi
,
230 extern void zebra_router_release_table(struct zebra_vrf
*zvrf
, uint32_t tableid
,
231 afi_t afi
, safi_t safi
);
233 extern int zebra_router_config_write(struct vty
*vty
);
235 extern void zebra_router_sweep_route(void);
236 extern void zebra_router_sweep_nhgs(void);
238 extern void zebra_router_show_table_summary(struct vty
*vty
);
240 extern uint32_t zebra_router_get_next_sequence(void);
242 static inline vrf_id_t
zebra_vrf_get_evpn_id(void)
244 return zrouter
.evpn_vrf
? zvrf_id(zrouter
.evpn_vrf
) : VRF_DEFAULT
;
246 static inline struct zebra_vrf
*zebra_vrf_get_evpn(void)
248 return zrouter
.evpn_vrf
? zrouter
.evpn_vrf
249 : zebra_vrf_lookup_by_id(VRF_DEFAULT
);
252 extern void multicast_mode_ipv4_set(enum multicast_mode mode
);
254 extern enum multicast_mode
multicast_mode_ipv4_get(void);
256 extern bool zebra_router_notify_on_ack(void);
258 /* zebra_northbound.c */
259 extern const struct frr_yang_module_info frr_zebra_info
;