3 * Copyright (C) 2016 Cumulus Networks
6 * This file is part of Quagga.
8 * Quagga is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
13 * Quagga is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; see the file COPYING; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #if !defined(__ZEBRA_VRF_H__)
23 #define __ZEBRA_VRF_H__
27 #include <zebra/zebra_ns.h>
28 #include <zebra/zebra_pw.h>
29 #include <lib/vxlan.h>
35 /* MPLS (Segment Routing) global block */
36 typedef struct mpls_srgb_t_
{
43 struct route_map
*map
;
46 PREDECL_RBTREE_UNIQ(otable
);
48 struct other_route_table
{
49 struct otable_item next
;
55 struct route_table
*table
;
58 /* Routing table instance. */
71 #define ZEBRA_VRF_RETAIN (1 << 0)
72 #define ZEBRA_PIM_SEND_VXLAN_SG (1 << 1)
77 struct route_table
*table
[AFI_MAX
][SAFI_MAX
];
79 /* Recursive Nexthop table */
80 struct route_table
*rnh_table
[AFI_MAX
];
82 /* Import check table (used mostly by BGP */
83 struct route_table
*import_check_table
[AFI_MAX
];
85 struct otable_head other_tables
;
87 /* 2nd pointer type used primarily to quell a warning on
88 * ALL_LIST_ELEMENTS_RO
90 struct list _rid_all_sorted_list
;
91 struct list _rid_lo_sorted_list
;
92 struct list
*rid_all_sorted_list
;
93 struct list
*rid_lo_sorted_list
;
94 struct prefix rid_user_assigned
;
97 * Back pointer to the owning namespace.
101 /* MPLS Label to handle L3VPN <-> vrf popping */
102 mpls_label_t label
[AFI_MAX
];
104 /* MPLS static LSP config table */
105 struct hash
*slsp_table
;
107 /* MPLS label forwarding table */
108 struct hash
*lsp_table
;
110 /* MPLS FEC binding table */
111 struct route_table
*fec_table
[AFI_MAX
];
113 /* MPLS Segment Routing Global block */
114 mpls_srgb_t mpls_srgb
;
117 struct zebra_pw_head pseudowires
;
118 struct zebra_static_pw_head static_pseudowires
;
120 struct zebra_rmap proto_rm
[AFI_MAX
][ZEBRA_ROUTE_MAX
+ 1];
121 struct zebra_rmap nht_rm
[AFI_MAX
][ZEBRA_ROUTE_MAX
+ 1];
123 /* MPLS processing flags */
125 #define MPLS_FLAG_SCHEDULE_LSPS (1 << 0)
128 * VNI hash table (for EVPN). Only in the EVPN instance.
130 struct hash
*vni_table
;
133 * Whether EVPN is enabled or not. Only in the EVPN instance.
135 int advertise_all_vni
;
138 * Whether we are advertising g/w macip in EVPN or not.
139 * Only in the EVPN instance.
141 int advertise_gw_macip
;
143 int advertise_svi_macip
;
148 /* pim mroutes installed for vxlan flooding */
149 struct hash
*vxlan_sg_table
;
151 bool dup_addr_detect
;
154 uint32_t dad_max_moves
;
156 uint32_t dad_freeze_time
;
159 * Flooding mechanism for BUM packets for VxLAN-EVPN.
161 enum vxlan_flood_control vxlan_flood_ctrl
;
166 uint64_t installs_queued
;
167 uint64_t removals_queued
;
168 uint64_t neigh_updates
;
169 uint64_t lsp_installs_queued
;
170 uint64_t lsp_removals_queued
;
171 uint64_t lsp_installs
;
172 uint64_t lsp_removals
;
174 #if defined(HAVE_RTADV)
176 #endif /* HAVE_RTADV */
178 int zebra_rnh_ip_default_route
;
179 int zebra_rnh_ipv6_default_route
;
181 #define PROTO_RM_NAME(zvrf, afi, rtype) zvrf->proto_rm[afi][rtype].name
182 #define NHT_RM_NAME(zvrf, afi, rtype) zvrf->nht_rm[afi][rtype].name
183 #define PROTO_RM_MAP(zvrf, afi, rtype) zvrf->proto_rm[afi][rtype].map
184 #define NHT_RM_MAP(zvrf, afi, rtype) zvrf->nht_rm[afi][rtype].map
187 * special macro to allow us to get the correct zebra_vrf
189 #define ZEBRA_DECLVAR_CONTEXT(A, B) \
190 struct vrf *A = VTY_GET_CONTEXT(vrf); \
191 struct zebra_vrf *B = (A) ? A->info : vrf_info_lookup(VRF_DEFAULT)
193 static inline vrf_id_t
zvrf_id(struct zebra_vrf
*zvrf
)
195 if (!zvrf
|| !zvrf
->vrf
)
197 return zvrf
->vrf
->vrf_id
;
200 static inline const char *zvrf_ns_name(struct zebra_vrf
*zvrf
)
202 if (!zvrf
->vrf
|| !zvrf
->vrf
->ns_ctxt
)
204 return ns_get_name((struct ns
*)zvrf
->vrf
->ns_ctxt
);
207 static inline const char *zvrf_name(struct zebra_vrf
*zvrf
)
209 return zvrf
->vrf
->name
;
212 static inline bool zvrf_is_active(struct zebra_vrf
*zvrf
)
214 return zvrf
->vrf
->status
& VRF_ACTIVE
;
218 zvrf_other_table_compare_func(const struct other_route_table
*a
,
219 const struct other_route_table
*b
)
221 if (a
->afi
!= b
->afi
)
222 return a
->afi
- b
->afi
;
224 if (a
->safi
!= b
->safi
)
225 return a
->safi
- b
->safi
;
227 if (a
->table_id
!= b
->table_id
)
228 return a
->table_id
- b
->table_id
;
233 DECLARE_RBTREE_UNIQ(otable
, struct other_route_table
, next
,
234 zvrf_other_table_compare_func
)
236 extern struct route_table
*
237 zebra_vrf_lookup_table_with_table_id(afi_t afi
, safi_t safi
, vrf_id_t vrf_id
,
239 extern struct route_table
*zebra_vrf_get_table_with_table_id(afi_t afi
,
244 extern void zebra_vrf_update_all(struct zserv
*client
);
245 extern struct zebra_vrf
*zebra_vrf_lookup_by_id(vrf_id_t vrf_id
);
246 extern struct zebra_vrf
*zebra_vrf_lookup_by_name(const char *);
247 extern struct zebra_vrf
*zebra_vrf_alloc(void);
248 extern struct route_table
*zebra_vrf_table(afi_t
, safi_t
, vrf_id_t
);
250 extern int zebra_vrf_has_config(struct zebra_vrf
*zvrf
);
251 extern void zebra_vrf_init(void);
253 extern void zebra_rtable_node_cleanup(struct route_table
*table
,
254 struct route_node
*node
);
260 #endif /* ZEBRA_VRF_H */