]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
7c551956 DS |
2 | /* |
3 | * Zebra Vrf Header | |
4 | * Copyright (C) 2016 Cumulus Networks | |
7cdb1a84 | 5 | * Donald Sharp |
7c551956 | 6 | */ |
736d41ad PG |
7 | #if !defined(__ZEBRA_VRF_H__) |
8 | #define __ZEBRA_VRF_H__ | |
7c551956 | 9 | |
fbac9605 DS |
10 | #include "vxlan.h" |
11 | ||
7c551956 | 12 | #include <zebra/zebra_ns.h> |
6833ae01 | 13 | #include <zebra/zebra_pw.h> |
7ca9c407 | 14 | #include <zebra/rtadv.h> |
b7cfce93 | 15 | #include <lib/vxlan.h> |
7c551956 | 16 | |
51e94aa7 EDP |
17 | #ifdef __cplusplus |
18 | extern "C" { | |
19 | #endif | |
20 | ||
1b6d5c7e | 21 | /* MPLS (Segment Routing) global block */ |
c4528712 | 22 | struct mpls_srgb { |
d7c0a89a QY |
23 | uint32_t start_label; |
24 | uint32_t end_label; | |
c4528712 | 25 | }; |
1b6d5c7e | 26 | |
ac6eebce | 27 | struct zebra_rmap { |
28 | char *name; | |
29 | struct route_map *map; | |
30 | }; | |
31 | ||
d8612e65 DS |
32 | PREDECL_RBTREE_UNIQ(otable); |
33 | ||
34 | struct other_route_table { | |
35 | struct otable_item next; | |
36 | ||
37 | afi_t afi; | |
38 | safi_t safi; | |
39 | uint32_t table_id; | |
40 | ||
41 | struct route_table *table; | |
42 | }; | |
43 | ||
7c551956 | 44 | /* Routing table instance. */ |
d62a17ae | 45 | struct zebra_vrf { |
46 | /* Back pointer */ | |
47 | struct vrf *vrf; | |
7c551956 | 48 | |
d62a17ae | 49 | /* Description. */ |
50 | char *desc; | |
7c551956 | 51 | |
d62a17ae | 52 | /* FIB identifier. */ |
d7c0a89a | 53 | uint8_t fib_id; |
7c551956 | 54 | |
d62a17ae | 55 | /* Flags. */ |
d7c0a89a | 56 | uint16_t flags; |
f4c6e2a8 | 57 | #define ZEBRA_VRF_RETAIN (1 << 0) |
ecbbc3a7 | 58 | #define ZEBRA_PIM_SEND_VXLAN_SG (1 << 1) |
7c551956 | 59 | |
d7c0a89a | 60 | uint32_t table_id; |
7c551956 | 61 | |
d62a17ae | 62 | /* Routing table. */ |
63 | struct route_table *table[AFI_MAX][SAFI_MAX]; | |
7c551956 | 64 | |
d62a17ae | 65 | /* Recursive Nexthop table */ |
66 | struct route_table *rnh_table[AFI_MAX]; | |
a4598b97 | 67 | struct route_table *rnh_table_multicast[AFI_MAX]; |
7c551956 | 68 | |
d8612e65 DS |
69 | struct otable_head other_tables; |
70 | ||
d62a17ae | 71 | /* 2nd pointer type used primarily to quell a warning on |
72 | * ALL_LIST_ELEMENTS_RO | |
73 | */ | |
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; | |
98a3fb0a SM |
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; | |
7c551956 | 84 | |
d62a17ae | 85 | /* |
86 | * Back pointer to the owning namespace. | |
87 | */ | |
88 | struct zebra_ns *zns; | |
54d48ea1 | 89 | |
c83c5e44 | 90 | /* MPLS Label to handle L3VPN <-> vrf popping */ |
7d061b3c | 91 | mpls_label_t label[AFI_MAX]; |
06302ecb | 92 | uint8_t label_proto[AFI_MAX]; |
c83c5e44 | 93 | |
d62a17ae | 94 | /* MPLS static LSP config table */ |
95 | struct hash *slsp_table; | |
54d48ea1 | 96 | |
d62a17ae | 97 | /* MPLS label forwarding table */ |
98 | struct hash *lsp_table; | |
939fba27 | 99 | |
d62a17ae | 100 | /* MPLS FEC binding table */ |
101 | struct route_table *fec_table[AFI_MAX]; | |
f31e084c | 102 | |
d62a17ae | 103 | /* MPLS Segment Routing Global block */ |
c4528712 | 104 | struct mpls_srgb mpls_srgb; |
1b6d5c7e | 105 | |
6833ae01 | 106 | /* Pseudowires. */ |
107 | struct zebra_pw_head pseudowires; | |
2dd0d726 | 108 | struct zebra_static_pw_head static_pseudowires; |
6833ae01 | 109 | |
ac6eebce | 110 | struct zebra_rmap proto_rm[AFI_MAX][ZEBRA_ROUTE_MAX + 1]; |
111 | struct zebra_rmap nht_rm[AFI_MAX][ZEBRA_ROUTE_MAX + 1]; | |
112 | ||
d62a17ae | 113 | /* MPLS processing flags */ |
d7c0a89a | 114 | uint16_t mpls_flags; |
939fba27 | 115 | #define MPLS_FLAG_SCHEDULE_LSPS (1 << 0) |
57282a31 | 116 | |
d62a17ae | 117 | /* |
87d76d54 | 118 | * EVPN hash table. Only in the EVPN instance. |
d62a17ae | 119 | */ |
87d76d54 | 120 | struct hash *evpn_table; |
2853fed6 | 121 | |
d62a17ae | 122 | /* |
150971b5 | 123 | * Whether EVPN is enabled or not. Only in the EVPN instance. |
d62a17ae | 124 | */ |
125 | int advertise_all_vni; | |
126 | ||
1a98c087 MK |
127 | /* |
128 | * Whether we are advertising g/w macip in EVPN or not. | |
150971b5 | 129 | * Only in the EVPN instance. |
1a98c087 MK |
130 | */ |
131 | int advertise_gw_macip; | |
132 | ||
278e26de CS |
133 | int advertise_svi_macip; |
134 | ||
b7cfce93 MK |
135 | /* l3-vni info */ |
136 | vni_t l3vni; | |
137 | ||
8a93734c AK |
138 | /* pim mroutes installed for vxlan flooding */ |
139 | struct hash *vxlan_sg_table; | |
140 | ||
3950b52c CS |
141 | bool dup_addr_detect; |
142 | ||
143 | int dad_time; | |
144 | uint32_t dad_max_moves; | |
145 | bool dad_freeze; | |
146 | uint32_t dad_freeze_time; | |
147 | ||
fbac9605 DS |
148 | /* |
149 | * Flooding mechanism for BUM packets for VxLAN-EVPN. | |
150 | */ | |
151 | enum vxlan_flood_control vxlan_flood_ctrl; | |
152 | ||
d37f4d6c | 153 | /* Install stats */ |
d62a17ae | 154 | uint64_t installs; |
155 | uint64_t removals; | |
97f5b441 MS |
156 | uint64_t installs_queued; |
157 | uint64_t removals_queued; | |
d62a17ae | 158 | uint64_t neigh_updates; |
d37f4d6c MS |
159 | uint64_t lsp_installs_queued; |
160 | uint64_t lsp_removals_queued; | |
d62a17ae | 161 | uint64_t lsp_installs; |
162 | uint64_t lsp_removals; | |
df9c8c57 | 163 | |
42d4b30e PG |
164 | struct table_manager *tbl_mgr; |
165 | ||
df9c8c57 | 166 | struct rtadv rtadv; |
5a0bdc78 | 167 | |
4aabcba0 DS |
168 | bool zebra_rnh_ip_default_route; |
169 | bool zebra_rnh_ipv6_default_route; | |
7c551956 | 170 | }; |
ac6eebce | 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 | |
7c551956 | 175 | |
214e5c26 | 176 | /* |
177 | * special macro to allow us to get the correct zebra_vrf | |
178 | */ | |
0cbed951 DL |
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 */ | |
214e5c26 | 183 | |
d62a17ae | 184 | static inline vrf_id_t zvrf_id(struct zebra_vrf *zvrf) |
661512bf | 185 | { |
2c7d4021 | 186 | if (!zvrf || !zvrf->vrf) |
bd47f3a3 | 187 | return VRF_DEFAULT; |
d62a17ae | 188 | return zvrf->vrf->vrf_id; |
661512bf RW |
189 | } |
190 | ||
81c9005f PG |
191 | static inline const char *zvrf_ns_name(struct zebra_vrf *zvrf) |
192 | { | |
193 | if (!zvrf->vrf || !zvrf->vrf->ns_ctxt) | |
194 | return NULL; | |
195 | return ns_get_name((struct ns *)zvrf->vrf->ns_ctxt); | |
196 | } | |
197 | ||
d62a17ae | 198 | static inline const char *zvrf_name(struct zebra_vrf *zvrf) |
661512bf | 199 | { |
bd47f3a3 JU |
200 | if (!zvrf || !zvrf->vrf) |
201 | return "Unknown"; | |
d62a17ae | 202 | return zvrf->vrf->name; |
661512bf RW |
203 | } |
204 | ||
81c9005f PG |
205 | static inline bool zvrf_is_active(struct zebra_vrf *zvrf) |
206 | { | |
207 | return zvrf->vrf->status & VRF_ACTIVE; | |
208 | } | |
209 | ||
d8612e65 DS |
210 | static inline int |
211 | zvrf_other_table_compare_func(const struct other_route_table *a, | |
212 | const struct other_route_table *b) | |
213 | { | |
214 | if (a->afi != b->afi) | |
215 | return a->afi - b->afi; | |
216 | ||
217 | if (a->safi != b->safi) | |
218 | return a->safi - b->safi; | |
219 | ||
220 | if (a->table_id != b->table_id) | |
221 | return a->table_id - b->table_id; | |
222 | ||
223 | return 0; | |
224 | } | |
225 | ||
226 | DECLARE_RBTREE_UNIQ(otable, struct other_route_table, next, | |
960b9a53 | 227 | zvrf_other_table_compare_func); |
d8612e65 | 228 | |
c7c0b007 SW |
229 | extern struct route_table * |
230 | zebra_vrf_lookup_table_with_table_id(afi_t afi, safi_t safi, vrf_id_t vrf_id, | |
231 | uint32_t table_id); | |
232 | extern struct route_table *zebra_vrf_get_table_with_table_id(afi_t afi, | |
233 | safi_t safi, | |
234 | vrf_id_t vrf_id, | |
235 | uint32_t table_id); | |
d62a17ae | 236 | |
d62a17ae | 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 *); | |
ec64a634 | 240 | extern struct zebra_vrf *zebra_vrf_alloc(struct vrf *vrf); |
d62a17ae | 241 | extern struct route_table *zebra_vrf_table(afi_t, safi_t, vrf_id_t); |
7e24fdf3 | 242 | |
62d89c64 IR |
243 | /* |
244 | * API to associate a VRF with a NETNS. | |
245 | * Called either from vty or through discovery. | |
246 | */ | |
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); | |
250 | ||
d62a17ae | 251 | extern void zebra_vrf_init(void); |
5335613b DS |
252 | |
253 | extern void zebra_rtable_node_cleanup(struct route_table *table, | |
254 | struct route_node *node); | |
51e94aa7 EDP |
255 | |
256 | #ifdef __cplusplus | |
257 | } | |
258 | #endif | |
259 | ||
736d41ad | 260 | #endif /* ZEBRA_VRF_H */ |