]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_vrf.h
Merge pull request #9862 from donaldsharp/all_protocol_retry
[mirror_frr.git] / zebra / zebra_vrf.h
1 /*
2 * Zebra Vrf Header
3 * Copyright (C) 2016 Cumulus Networks
4 * Donald Sharp
5 *
6 * This file is part of Quagga.
7 *
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
11 * later version.
12 *
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.
17 *
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
21 */
22 #if !defined(__ZEBRA_VRF_H__)
23 #define __ZEBRA_VRF_H__
24
25 #include "vxlan.h"
26
27 #include <zebra/zebra_ns.h>
28 #include <zebra/zebra_pw.h>
29 #include <lib/vxlan.h>
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 /* MPLS (Segment Routing) global block */
36 struct mpls_srgb {
37 uint32_t start_label;
38 uint32_t end_label;
39 };
40
41 struct zebra_rmap {
42 char *name;
43 struct route_map *map;
44 };
45
46 PREDECL_RBTREE_UNIQ(otable);
47
48 struct other_route_table {
49 struct otable_item next;
50
51 afi_t afi;
52 safi_t safi;
53 uint32_t table_id;
54
55 struct route_table *table;
56 };
57
58 /* Routing table instance. */
59 struct zebra_vrf {
60 /* Back pointer */
61 struct vrf *vrf;
62
63 /* Description. */
64 char *desc;
65
66 /* FIB identifier. */
67 uint8_t fib_id;
68
69 /* Flags. */
70 uint16_t flags;
71 #define ZEBRA_VRF_RETAIN (1 << 0)
72 #define ZEBRA_PIM_SEND_VXLAN_SG (1 << 1)
73
74 uint32_t table_id;
75
76 /* Routing table. */
77 struct route_table *table[AFI_MAX][SAFI_MAX];
78
79 /* Recursive Nexthop table */
80 struct route_table *rnh_table[AFI_MAX];
81 struct route_table *rnh_table_multicast[AFI_MAX];
82
83 struct otable_head other_tables;
84
85 /* 2nd pointer type used primarily to quell a warning on
86 * ALL_LIST_ELEMENTS_RO
87 */
88 struct list _rid_all_sorted_list;
89 struct list _rid_lo_sorted_list;
90 struct list *rid_all_sorted_list;
91 struct list *rid_lo_sorted_list;
92 struct prefix rid_user_assigned;
93 struct list _rid6_all_sorted_list;
94 struct list _rid6_lo_sorted_list;
95 struct list *rid6_all_sorted_list;
96 struct list *rid6_lo_sorted_list;
97 struct prefix rid6_user_assigned;
98
99 /*
100 * Back pointer to the owning namespace.
101 */
102 struct zebra_ns *zns;
103
104 /* MPLS Label to handle L3VPN <-> vrf popping */
105 mpls_label_t label[AFI_MAX];
106 uint8_t label_proto[AFI_MAX];
107
108 /* MPLS static LSP config table */
109 struct hash *slsp_table;
110
111 /* MPLS label forwarding table */
112 struct hash *lsp_table;
113
114 /* MPLS FEC binding table */
115 struct route_table *fec_table[AFI_MAX];
116
117 /* MPLS Segment Routing Global block */
118 struct mpls_srgb mpls_srgb;
119
120 /* Pseudowires. */
121 struct zebra_pw_head pseudowires;
122 struct zebra_static_pw_head static_pseudowires;
123
124 struct zebra_rmap proto_rm[AFI_MAX][ZEBRA_ROUTE_MAX + 1];
125 struct zebra_rmap nht_rm[AFI_MAX][ZEBRA_ROUTE_MAX + 1];
126
127 /* MPLS processing flags */
128 uint16_t mpls_flags;
129 #define MPLS_FLAG_SCHEDULE_LSPS (1 << 0)
130
131 /*
132 * EVPN hash table. Only in the EVPN instance.
133 */
134 struct hash *evpn_table;
135
136 /*
137 * Whether EVPN is enabled or not. Only in the EVPN instance.
138 */
139 int advertise_all_vni;
140
141 /*
142 * Whether we are advertising g/w macip in EVPN or not.
143 * Only in the EVPN instance.
144 */
145 int advertise_gw_macip;
146
147 int advertise_svi_macip;
148
149 /* l3-vni info */
150 vni_t l3vni;
151
152 /* pim mroutes installed for vxlan flooding */
153 struct hash *vxlan_sg_table;
154
155 bool dup_addr_detect;
156
157 int dad_time;
158 uint32_t dad_max_moves;
159 bool dad_freeze;
160 uint32_t dad_freeze_time;
161
162 /*
163 * Flooding mechanism for BUM packets for VxLAN-EVPN.
164 */
165 enum vxlan_flood_control vxlan_flood_ctrl;
166
167 /* Install stats */
168 uint64_t installs;
169 uint64_t removals;
170 uint64_t installs_queued;
171 uint64_t removals_queued;
172 uint64_t neigh_updates;
173 uint64_t lsp_installs_queued;
174 uint64_t lsp_removals_queued;
175 uint64_t lsp_installs;
176 uint64_t lsp_removals;
177
178 struct table_manager *tbl_mgr;
179
180 #if defined(HAVE_RTADV)
181 struct rtadv rtadv;
182 #endif /* HAVE_RTADV */
183
184 bool zebra_rnh_ip_default_route;
185 bool zebra_rnh_ipv6_default_route;
186 };
187 #define PROTO_RM_NAME(zvrf, afi, rtype) zvrf->proto_rm[afi][rtype].name
188 #define NHT_RM_NAME(zvrf, afi, rtype) zvrf->nht_rm[afi][rtype].name
189 #define PROTO_RM_MAP(zvrf, afi, rtype) zvrf->proto_rm[afi][rtype].map
190 #define NHT_RM_MAP(zvrf, afi, rtype) zvrf->nht_rm[afi][rtype].map
191
192 /*
193 * special macro to allow us to get the correct zebra_vrf
194 */
195 #define ZEBRA_DECLVAR_CONTEXT(A, B) \
196 struct vrf *A; \
197 if (vty->node == CONFIG_NODE) \
198 A = vrf_lookup_by_id(VRF_DEFAULT); \
199 else \
200 A = VTY_GET_CONTEXT(vrf); \
201 VTY_CHECK_CONTEXT(A); \
202 struct zebra_vrf *B = A->info
203
204 static inline vrf_id_t zvrf_id(struct zebra_vrf *zvrf)
205 {
206 if (!zvrf || !zvrf->vrf)
207 return VRF_DEFAULT;
208 return zvrf->vrf->vrf_id;
209 }
210
211 static inline const char *zvrf_ns_name(struct zebra_vrf *zvrf)
212 {
213 if (!zvrf->vrf || !zvrf->vrf->ns_ctxt)
214 return NULL;
215 return ns_get_name((struct ns *)zvrf->vrf->ns_ctxt);
216 }
217
218 static inline const char *zvrf_name(struct zebra_vrf *zvrf)
219 {
220 if (!zvrf || !zvrf->vrf)
221 return "Unknown";
222 return zvrf->vrf->name;
223 }
224
225 static inline bool zvrf_is_active(struct zebra_vrf *zvrf)
226 {
227 return zvrf->vrf->status & VRF_ACTIVE;
228 }
229
230 static inline int
231 zvrf_other_table_compare_func(const struct other_route_table *a,
232 const struct other_route_table *b)
233 {
234 if (a->afi != b->afi)
235 return a->afi - b->afi;
236
237 if (a->safi != b->safi)
238 return a->safi - b->safi;
239
240 if (a->table_id != b->table_id)
241 return a->table_id - b->table_id;
242
243 return 0;
244 }
245
246 DECLARE_RBTREE_UNIQ(otable, struct other_route_table, next,
247 zvrf_other_table_compare_func);
248
249 extern struct route_table *
250 zebra_vrf_lookup_table_with_table_id(afi_t afi, safi_t safi, vrf_id_t vrf_id,
251 uint32_t table_id);
252 extern struct route_table *zebra_vrf_get_table_with_table_id(afi_t afi,
253 safi_t safi,
254 vrf_id_t vrf_id,
255 uint32_t table_id);
256
257 extern void zebra_vrf_update_all(struct zserv *client);
258 extern struct zebra_vrf *zebra_vrf_lookup_by_id(vrf_id_t vrf_id);
259 extern struct zebra_vrf *zebra_vrf_lookup_by_name(const char *);
260 extern struct zebra_vrf *zebra_vrf_alloc(struct vrf *vrf);
261 extern struct route_table *zebra_vrf_table(afi_t, safi_t, vrf_id_t);
262
263 /*
264 * API to associate a VRF with a NETNS.
265 * Called either from vty or through discovery.
266 */
267 extern int zebra_vrf_netns_handler_create(struct vty *vty, struct vrf *vrf,
268 char *pathname, ns_id_t ext_ns_id,
269 ns_id_t ns_id, ns_id_t rel_def_ns_id);
270
271 extern void zebra_vrf_init(void);
272
273 extern void zebra_rtable_node_cleanup(struct route_table *table,
274 struct route_node *node);
275
276 #ifdef __cplusplus
277 }
278 #endif
279
280 #endif /* ZEBRA_VRF_H */