]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_vrf.h
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / zebra / zebra_vrf.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Zebra Vrf Header
4 * Copyright (C) 2016 Cumulus Networks
5 * Donald Sharp
6 */
7 #if !defined(__ZEBRA_VRF_H__)
8 #define __ZEBRA_VRF_H__
9
10 #include "vxlan.h"
11
12 #include <zebra/zebra_ns.h>
13 #include <zebra/zebra_pw.h>
14 #include <zebra/rtadv.h>
15 #include <lib/vxlan.h>
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 /* MPLS (Segment Routing) global block */
22 struct mpls_srgb {
23 uint32_t start_label;
24 uint32_t end_label;
25 };
26
27 struct zebra_rmap {
28 char *name;
29 struct route_map *map;
30 };
31
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
44 /* Routing table instance. */
45 struct zebra_vrf {
46 /* Back pointer */
47 struct vrf *vrf;
48
49 /* Description. */
50 char *desc;
51
52 /* FIB identifier. */
53 uint8_t fib_id;
54
55 /* Flags. */
56 uint16_t flags;
57 #define ZEBRA_VRF_RETAIN (1 << 0)
58 #define ZEBRA_PIM_SEND_VXLAN_SG (1 << 1)
59
60 uint32_t table_id;
61
62 /* Routing table. */
63 struct route_table *table[AFI_MAX][SAFI_MAX];
64
65 /* Recursive Nexthop table */
66 struct route_table *rnh_table[AFI_MAX];
67 struct route_table *rnh_table_multicast[AFI_MAX];
68
69 struct otable_head other_tables;
70
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;
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;
84
85 /*
86 * Back pointer to the owning namespace.
87 */
88 struct zebra_ns *zns;
89
90 /* MPLS Label to handle L3VPN <-> vrf popping */
91 mpls_label_t label[AFI_MAX];
92 uint8_t label_proto[AFI_MAX];
93
94 /* MPLS static LSP config table */
95 struct hash *slsp_table;
96
97 /* MPLS label forwarding table */
98 struct hash *lsp_table;
99
100 /* MPLS FEC binding table */
101 struct route_table *fec_table[AFI_MAX];
102
103 /* MPLS Segment Routing Global block */
104 struct mpls_srgb mpls_srgb;
105
106 /* Pseudowires. */
107 struct zebra_pw_head pseudowires;
108 struct zebra_static_pw_head static_pseudowires;
109
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
113 /* MPLS processing flags */
114 uint16_t mpls_flags;
115 #define MPLS_FLAG_SCHEDULE_LSPS (1 << 0)
116
117 /*
118 * EVPN hash table. Only in the EVPN instance.
119 */
120 struct hash *evpn_table;
121
122 /*
123 * Whether EVPN is enabled or not. Only in the EVPN instance.
124 */
125 int advertise_all_vni;
126
127 /*
128 * Whether we are advertising g/w macip in EVPN or not.
129 * Only in the EVPN instance.
130 */
131 int advertise_gw_macip;
132
133 int advertise_svi_macip;
134
135 /* l3-vni info */
136 vni_t l3vni;
137
138 /* pim mroutes installed for vxlan flooding */
139 struct hash *vxlan_sg_table;
140
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
148 /*
149 * Flooding mechanism for BUM packets for VxLAN-EVPN.
150 */
151 enum vxlan_flood_control vxlan_flood_ctrl;
152
153 /* Install stats */
154 uint64_t installs;
155 uint64_t removals;
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;
163
164 struct table_manager *tbl_mgr;
165
166 struct rtadv rtadv;
167
168 bool zebra_rnh_ip_default_route;
169 bool zebra_rnh_ipv6_default_route;
170 };
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
175
176 /*
177 * special macro to allow us to get the correct zebra_vrf
178 */
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 */
183
184 static inline vrf_id_t zvrf_id(struct zebra_vrf *zvrf)
185 {
186 if (!zvrf || !zvrf->vrf)
187 return VRF_DEFAULT;
188 return zvrf->vrf->vrf_id;
189 }
190
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
198 static inline const char *zvrf_name(struct zebra_vrf *zvrf)
199 {
200 if (!zvrf || !zvrf->vrf)
201 return "Unknown";
202 return zvrf->vrf->name;
203 }
204
205 static inline bool zvrf_is_active(struct zebra_vrf *zvrf)
206 {
207 return zvrf->vrf->status & VRF_ACTIVE;
208 }
209
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,
227 zvrf_other_table_compare_func);
228
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);
236
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);
242
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
251 extern void zebra_vrf_init(void);
252
253 extern void zebra_rtable_node_cleanup(struct route_table *table,
254 struct route_node *node);
255
256 #ifdef __cplusplus
257 }
258 #endif
259
260 #endif /* ZEBRA_VRF_H */