1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (C) 2016 Cumulus Networks
7 #if !defined(__ZEBRA_VRF_H__)
8 #define __ZEBRA_VRF_H__
12 #include <zebra/zebra_ns.h>
13 #include <zebra/zebra_pw.h>
14 #include <zebra/rtadv.h>
15 #include <lib/vxlan.h>
21 /* MPLS (Segment Routing) global block */
29 struct route_map
*map
;
32 PREDECL_RBTREE_UNIQ(otable
);
34 struct other_route_table
{
35 struct otable_item next
;
41 struct route_table
*table
;
44 /* Routing table instance. */
57 #define ZEBRA_VRF_RETAIN (1 << 0)
58 #define ZEBRA_PIM_SEND_VXLAN_SG (1 << 1)
63 struct route_table
*table
[AFI_MAX
][SAFI_MAX
];
65 /* Recursive Nexthop table */
66 struct route_table
*rnh_table
[AFI_MAX
];
67 struct route_table
*rnh_table_multicast
[AFI_MAX
];
69 struct otable_head other_tables
;
71 /* 2nd pointer type used primarily to quell a warning on
72 * ALL_LIST_ELEMENTS_RO
74 struct list _rid_all_sorted_list
;
75 struct list _rid_lo_sorted_list
;
76 struct list
*rid_all_sorted_list
;
77 struct list
*rid_lo_sorted_list
;
78 struct prefix rid_user_assigned
;
79 struct list _rid6_all_sorted_list
;
80 struct list _rid6_lo_sorted_list
;
81 struct list
*rid6_all_sorted_list
;
82 struct list
*rid6_lo_sorted_list
;
83 struct prefix rid6_user_assigned
;
86 * Back pointer to the owning namespace.
90 /* MPLS Label to handle L3VPN <-> vrf popping */
91 mpls_label_t label
[AFI_MAX
];
92 uint8_t label_proto
[AFI_MAX
];
94 /* MPLS static LSP config table */
95 struct hash
*slsp_table
;
97 /* MPLS label forwarding table */
98 struct hash
*lsp_table
;
100 /* MPLS FEC binding table */
101 struct route_table
*fec_table
[AFI_MAX
];
103 /* MPLS Segment Routing Global block */
104 struct mpls_srgb mpls_srgb
;
107 struct zebra_pw_head pseudowires
;
108 struct zebra_static_pw_head static_pseudowires
;
110 struct zebra_rmap proto_rm
[AFI_MAX
][ZEBRA_ROUTE_MAX
+ 1];
111 struct zebra_rmap nht_rm
[AFI_MAX
][ZEBRA_ROUTE_MAX
+ 1];
113 /* MPLS processing flags */
115 #define MPLS_FLAG_SCHEDULE_LSPS (1 << 0)
118 * EVPN hash table. Only in the EVPN instance.
120 struct hash
*evpn_table
;
123 * Whether EVPN is enabled or not. Only in the EVPN instance.
125 int advertise_all_vni
;
128 * Whether we are advertising g/w macip in EVPN or not.
129 * Only in the EVPN instance.
131 int advertise_gw_macip
;
133 int advertise_svi_macip
;
138 /* pim mroutes installed for vxlan flooding */
139 struct hash
*vxlan_sg_table
;
141 bool dup_addr_detect
;
144 uint32_t dad_max_moves
;
146 uint32_t dad_freeze_time
;
149 * Flooding mechanism for BUM packets for VxLAN-EVPN.
151 enum vxlan_flood_control vxlan_flood_ctrl
;
156 uint64_t installs_queued
;
157 uint64_t removals_queued
;
158 uint64_t neigh_updates
;
159 uint64_t lsp_installs_queued
;
160 uint64_t lsp_removals_queued
;
161 uint64_t lsp_installs
;
162 uint64_t lsp_removals
;
164 struct table_manager
*tbl_mgr
;
168 bool zebra_rnh_ip_default_route
;
169 bool zebra_rnh_ipv6_default_route
;
171 #define PROTO_RM_NAME(zvrf, afi, rtype) zvrf->proto_rm[afi][rtype].name
172 #define NHT_RM_NAME(zvrf, afi, rtype) zvrf->nht_rm[afi][rtype].name
173 #define PROTO_RM_MAP(zvrf, afi, rtype) zvrf->proto_rm[afi][rtype].map
174 #define NHT_RM_MAP(zvrf, afi, rtype) zvrf->nht_rm[afi][rtype].map
177 * special macro to allow us to get the correct zebra_vrf
179 #define ZEBRA_DECLVAR_CONTEXT_VRF(vrfptr, zvrfptr) \
180 VTY_DECLVAR_CONTEXT_VRF(vrfptr); \
181 struct zebra_vrf *zvrfptr = vrfptr->info; \
182 MACRO_REQUIRE_SEMICOLON() /* end */
184 static inline vrf_id_t
zvrf_id(struct zebra_vrf
*zvrf
)
186 if (!zvrf
|| !zvrf
->vrf
)
188 return zvrf
->vrf
->vrf_id
;
191 static inline const char *zvrf_ns_name(struct zebra_vrf
*zvrf
)
193 if (!zvrf
->vrf
|| !zvrf
->vrf
->ns_ctxt
)
195 return ns_get_name((struct ns
*)zvrf
->vrf
->ns_ctxt
);
198 static inline const char *zvrf_name(struct zebra_vrf
*zvrf
)
200 if (!zvrf
|| !zvrf
->vrf
)
202 return zvrf
->vrf
->name
;
205 static inline bool zvrf_is_active(struct zebra_vrf
*zvrf
)
207 return zvrf
->vrf
->status
& VRF_ACTIVE
;
211 zvrf_other_table_compare_func(const struct other_route_table
*a
,
212 const struct other_route_table
*b
)
214 if (a
->afi
!= b
->afi
)
215 return a
->afi
- b
->afi
;
217 if (a
->safi
!= b
->safi
)
218 return a
->safi
- b
->safi
;
220 if (a
->table_id
!= b
->table_id
)
221 return a
->table_id
- b
->table_id
;
226 DECLARE_RBTREE_UNIQ(otable
, struct other_route_table
, next
,
227 zvrf_other_table_compare_func
);
229 extern struct route_table
*
230 zebra_vrf_lookup_table_with_table_id(afi_t afi
, safi_t safi
, vrf_id_t vrf_id
,
232 extern struct route_table
*zebra_vrf_get_table_with_table_id(afi_t afi
,
237 extern void zebra_vrf_update_all(struct zserv
*client
);
238 extern struct zebra_vrf
*zebra_vrf_lookup_by_id(vrf_id_t vrf_id
);
239 extern struct zebra_vrf
*zebra_vrf_lookup_by_name(const char *);
240 extern struct zebra_vrf
*zebra_vrf_alloc(struct vrf
*vrf
);
241 extern struct route_table
*zebra_vrf_table(afi_t
, safi_t
, vrf_id_t
);
244 * API to associate a VRF with a NETNS.
245 * Called either from vty or through discovery.
247 extern int zebra_vrf_netns_handler_create(struct vty
*vty
, struct vrf
*vrf
,
248 char *pathname
, ns_id_t ext_ns_id
,
249 ns_id_t ns_id
, ns_id_t rel_def_ns_id
);
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 */