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 <zebra/rtadv.h>
30 #include <lib/vxlan.h>
36 /* MPLS (Segment Routing) global block */
44 struct route_map
*map
;
47 PREDECL_RBTREE_UNIQ(otable
);
49 struct other_route_table
{
50 struct otable_item next
;
56 struct route_table
*table
;
59 /* Routing table instance. */
72 #define ZEBRA_VRF_RETAIN (1 << 0)
73 #define ZEBRA_PIM_SEND_VXLAN_SG (1 << 1)
78 struct route_table
*table
[AFI_MAX
][SAFI_MAX
];
80 /* Recursive Nexthop table */
81 struct route_table
*rnh_table
[AFI_MAX
];
82 struct route_table
*rnh_table_multicast
[AFI_MAX
];
84 struct otable_head other_tables
;
86 /* 2nd pointer type used primarily to quell a warning on
87 * ALL_LIST_ELEMENTS_RO
89 struct list _rid_all_sorted_list
;
90 struct list _rid_lo_sorted_list
;
91 struct list
*rid_all_sorted_list
;
92 struct list
*rid_lo_sorted_list
;
93 struct prefix rid_user_assigned
;
94 struct list _rid6_all_sorted_list
;
95 struct list _rid6_lo_sorted_list
;
96 struct list
*rid6_all_sorted_list
;
97 struct list
*rid6_lo_sorted_list
;
98 struct prefix rid6_user_assigned
;
101 * Back pointer to the owning namespace.
103 struct zebra_ns
*zns
;
105 /* MPLS Label to handle L3VPN <-> vrf popping */
106 mpls_label_t label
[AFI_MAX
];
107 uint8_t label_proto
[AFI_MAX
];
109 /* MPLS static LSP config table */
110 struct hash
*slsp_table
;
112 /* MPLS label forwarding table */
113 struct hash
*lsp_table
;
115 /* MPLS FEC binding table */
116 struct route_table
*fec_table
[AFI_MAX
];
118 /* MPLS Segment Routing Global block */
119 struct mpls_srgb mpls_srgb
;
122 struct zebra_pw_head pseudowires
;
123 struct zebra_static_pw_head static_pseudowires
;
125 struct zebra_rmap proto_rm
[AFI_MAX
][ZEBRA_ROUTE_MAX
+ 1];
126 struct zebra_rmap nht_rm
[AFI_MAX
][ZEBRA_ROUTE_MAX
+ 1];
128 /* MPLS processing flags */
130 #define MPLS_FLAG_SCHEDULE_LSPS (1 << 0)
133 * EVPN hash table. Only in the EVPN instance.
135 struct hash
*evpn_table
;
138 * Whether EVPN is enabled or not. Only in the EVPN instance.
140 int advertise_all_vni
;
143 * Whether we are advertising g/w macip in EVPN or not.
144 * Only in the EVPN instance.
146 int advertise_gw_macip
;
148 int advertise_svi_macip
;
153 /* pim mroutes installed for vxlan flooding */
154 struct hash
*vxlan_sg_table
;
156 bool dup_addr_detect
;
159 uint32_t dad_max_moves
;
161 uint32_t dad_freeze_time
;
164 * Flooding mechanism for BUM packets for VxLAN-EVPN.
166 enum vxlan_flood_control vxlan_flood_ctrl
;
171 uint64_t installs_queued
;
172 uint64_t removals_queued
;
173 uint64_t neigh_updates
;
174 uint64_t lsp_installs_queued
;
175 uint64_t lsp_removals_queued
;
176 uint64_t lsp_installs
;
177 uint64_t lsp_removals
;
179 struct table_manager
*tbl_mgr
;
183 bool zebra_rnh_ip_default_route
;
184 bool zebra_rnh_ipv6_default_route
;
186 #define PROTO_RM_NAME(zvrf, afi, rtype) zvrf->proto_rm[afi][rtype].name
187 #define NHT_RM_NAME(zvrf, afi, rtype) zvrf->nht_rm[afi][rtype].name
188 #define PROTO_RM_MAP(zvrf, afi, rtype) zvrf->proto_rm[afi][rtype].map
189 #define NHT_RM_MAP(zvrf, afi, rtype) zvrf->nht_rm[afi][rtype].map
192 * special macro to allow us to get the correct zebra_vrf
194 #define ZEBRA_DECLVAR_CONTEXT_VRF(vrfptr, zvrfptr) \
195 VTY_DECLVAR_CONTEXT_VRF(vrfptr); \
196 struct zebra_vrf *zvrfptr = vrfptr->info; \
197 MACRO_REQUIRE_SEMICOLON() /* end */
199 static inline vrf_id_t
zvrf_id(struct zebra_vrf
*zvrf
)
201 if (!zvrf
|| !zvrf
->vrf
)
203 return zvrf
->vrf
->vrf_id
;
206 static inline const char *zvrf_ns_name(struct zebra_vrf
*zvrf
)
208 if (!zvrf
->vrf
|| !zvrf
->vrf
->ns_ctxt
)
210 return ns_get_name((struct ns
*)zvrf
->vrf
->ns_ctxt
);
213 static inline const char *zvrf_name(struct zebra_vrf
*zvrf
)
215 if (!zvrf
|| !zvrf
->vrf
)
217 return zvrf
->vrf
->name
;
220 static inline bool zvrf_is_active(struct zebra_vrf
*zvrf
)
222 return zvrf
->vrf
->status
& VRF_ACTIVE
;
226 zvrf_other_table_compare_func(const struct other_route_table
*a
,
227 const struct other_route_table
*b
)
229 if (a
->afi
!= b
->afi
)
230 return a
->afi
- b
->afi
;
232 if (a
->safi
!= b
->safi
)
233 return a
->safi
- b
->safi
;
235 if (a
->table_id
!= b
->table_id
)
236 return a
->table_id
- b
->table_id
;
241 DECLARE_RBTREE_UNIQ(otable
, struct other_route_table
, next
,
242 zvrf_other_table_compare_func
);
244 extern struct route_table
*
245 zebra_vrf_lookup_table_with_table_id(afi_t afi
, safi_t safi
, vrf_id_t vrf_id
,
247 extern struct route_table
*zebra_vrf_get_table_with_table_id(afi_t afi
,
252 extern void zebra_vrf_update_all(struct zserv
*client
);
253 extern struct zebra_vrf
*zebra_vrf_lookup_by_id(vrf_id_t vrf_id
);
254 extern struct zebra_vrf
*zebra_vrf_lookup_by_name(const char *);
255 extern struct zebra_vrf
*zebra_vrf_alloc(struct vrf
*vrf
);
256 extern struct route_table
*zebra_vrf_table(afi_t
, safi_t
, vrf_id_t
);
259 * API to associate a VRF with a NETNS.
260 * Called either from vty or through discovery.
262 extern int zebra_vrf_netns_handler_create(struct vty
*vty
, struct vrf
*vrf
,
263 char *pathname
, ns_id_t ext_ns_id
,
264 ns_id_t ns_id
, ns_id_t rel_def_ns_id
);
266 extern void zebra_vrf_init(void);
268 extern void zebra_rtable_node_cleanup(struct route_table
*table
,
269 struct route_node
*node
);
275 #endif /* ZEBRA_VRF_H */