]> git.proxmox.com Git - mirror_frr.git/blame - zebra/zebra_vrf.h
*: change interface structure, from vrf_id to vrf
[mirror_frr.git] / zebra / zebra_vrf.h
CommitLineData
7c551956
DS
1/*
2 * Zebra Vrf Header
3 * Copyright (C) 2016 Cumulus Networks
7cdb1a84 4 * Donald Sharp
7c551956
DS
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 *
896014f4
DL
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
7c551956 21 */
736d41ad
PG
22#if !defined(__ZEBRA_VRF_H__)
23#define __ZEBRA_VRF_H__
7c551956 24
fbac9605
DS
25#include "vxlan.h"
26
7c551956 27#include <zebra/zebra_ns.h>
6833ae01 28#include <zebra/zebra_pw.h>
b7cfce93 29#include <lib/vxlan.h>
7c551956 30
51e94aa7
EDP
31#ifdef __cplusplus
32extern "C" {
33#endif
34
1b6d5c7e 35/* MPLS (Segment Routing) global block */
d62a17ae 36typedef struct mpls_srgb_t_ {
d7c0a89a
QY
37 uint32_t start_label;
38 uint32_t end_label;
1b6d5c7e
VV
39} mpls_srgb_t;
40
ac6eebce 41struct zebra_rmap {
42 char *name;
43 struct route_map *map;
44};
45
d8612e65
DS
46PREDECL_RBTREE_UNIQ(otable);
47
48struct 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
7c551956 58/* Routing table instance. */
d62a17ae 59struct zebra_vrf {
60 /* Back pointer */
61 struct vrf *vrf;
7c551956 62
d62a17ae 63 /* Description. */
64 char *desc;
7c551956 65
d62a17ae 66 /* FIB identifier. */
d7c0a89a 67 uint8_t fib_id;
7c551956 68
d62a17ae 69 /* Flags. */
d7c0a89a 70 uint16_t flags;
f4c6e2a8 71#define ZEBRA_VRF_RETAIN (1 << 0)
7c551956 72
d7c0a89a 73 uint32_t table_id;
7c551956 74
d62a17ae 75 /* Routing table. */
76 struct route_table *table[AFI_MAX][SAFI_MAX];
7c551956 77
d62a17ae 78 /* Recursive Nexthop table */
79 struct route_table *rnh_table[AFI_MAX];
7c551956 80
d62a17ae 81 /* Import check table (used mostly by BGP */
82 struct route_table *import_check_table[AFI_MAX];
7c551956 83
d8612e65
DS
84 struct otable_head other_tables;
85
d62a17ae 86 /* 2nd pointer type used primarily to quell a warning on
87 * ALL_LIST_ELEMENTS_RO
88 */
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;
7c551956 94
d62a17ae 95 /*
96 * Back pointer to the owning namespace.
97 */
98 struct zebra_ns *zns;
54d48ea1 99
c83c5e44 100 /* MPLS Label to handle L3VPN <-> vrf popping */
7d061b3c 101 mpls_label_t label[AFI_MAX];
c83c5e44 102
d62a17ae 103 /* MPLS static LSP config table */
104 struct hash *slsp_table;
54d48ea1 105
d62a17ae 106 /* MPLS label forwarding table */
107 struct hash *lsp_table;
939fba27 108
d62a17ae 109 /* MPLS FEC binding table */
110 struct route_table *fec_table[AFI_MAX];
f31e084c 111
d62a17ae 112 /* MPLS Segment Routing Global block */
113 mpls_srgb_t mpls_srgb;
1b6d5c7e 114
6833ae01 115 /* Pseudowires. */
116 struct zebra_pw_head pseudowires;
2dd0d726 117 struct zebra_static_pw_head static_pseudowires;
6833ae01 118
ac6eebce 119 struct zebra_rmap proto_rm[AFI_MAX][ZEBRA_ROUTE_MAX + 1];
120 struct zebra_rmap nht_rm[AFI_MAX][ZEBRA_ROUTE_MAX + 1];
121
d62a17ae 122 /* MPLS processing flags */
d7c0a89a 123 uint16_t mpls_flags;
939fba27 124#define MPLS_FLAG_SCHEDULE_LSPS (1 << 0)
57282a31 125
d62a17ae 126 /*
150971b5 127 * VNI hash table (for EVPN). Only in the EVPN instance.
d62a17ae 128 */
129 struct hash *vni_table;
2853fed6 130
d62a17ae 131 /*
150971b5 132 * Whether EVPN is enabled or not. Only in the EVPN instance.
d62a17ae 133 */
134 int advertise_all_vni;
135
1a98c087
MK
136 /*
137 * Whether we are advertising g/w macip in EVPN or not.
150971b5 138 * Only in the EVPN instance.
1a98c087
MK
139 */
140 int advertise_gw_macip;
141
278e26de
CS
142 int advertise_svi_macip;
143
b7cfce93
MK
144 /* l3-vni info */
145 vni_t l3vni;
146
8a93734c
AK
147 /* pim mroutes installed for vxlan flooding */
148 struct hash *vxlan_sg_table;
149
3950b52c
CS
150 bool dup_addr_detect;
151
152 int dad_time;
153 uint32_t dad_max_moves;
154 bool dad_freeze;
155 uint32_t dad_freeze_time;
156
fbac9605
DS
157 /*
158 * Flooding mechanism for BUM packets for VxLAN-EVPN.
159 */
160 enum vxlan_flood_control vxlan_flood_ctrl;
161
d37f4d6c 162 /* Install stats */
d62a17ae 163 uint64_t installs;
164 uint64_t removals;
97f5b441
MS
165 uint64_t installs_queued;
166 uint64_t removals_queued;
d62a17ae 167 uint64_t neigh_updates;
d37f4d6c
MS
168 uint64_t lsp_installs_queued;
169 uint64_t lsp_removals_queued;
d62a17ae 170 uint64_t lsp_installs;
171 uint64_t lsp_removals;
df9c8c57
PG
172
173#if defined(HAVE_RTADV)
174 struct rtadv rtadv;
175#endif /* HAVE_RTADV */
7c551956 176};
ac6eebce 177#define PROTO_RM_NAME(zvrf, afi, rtype) zvrf->proto_rm[afi][rtype].name
178#define NHT_RM_NAME(zvrf, afi, rtype) zvrf->nht_rm[afi][rtype].name
179#define PROTO_RM_MAP(zvrf, afi, rtype) zvrf->proto_rm[afi][rtype].map
180#define NHT_RM_MAP(zvrf, afi, rtype) zvrf->nht_rm[afi][rtype].map
7c551956 181
214e5c26 182/*
183 * special macro to allow us to get the correct zebra_vrf
184 */
185#define ZEBRA_DECLVAR_CONTEXT(A, B) \
186 struct vrf *A = VTY_GET_CONTEXT(vrf); \
187 struct zebra_vrf *B = (A) ? A->info : vrf_info_lookup(VRF_DEFAULT)
188
d62a17ae 189static inline vrf_id_t zvrf_id(struct zebra_vrf *zvrf)
661512bf 190{
2c7d4021
PG
191 if (!zvrf || !zvrf->vrf)
192 return VRF_UNKNOWN;
d62a17ae 193 return zvrf->vrf->vrf_id;
661512bf
RW
194}
195
a41c4e1b
PG
196static inline struct zebra_vrf *zvrf_info_lookup(struct vrf *vrf)
197{
198 struct zebra_vrf *zvrf = NULL;
199
200 if (vrf)
201 zvrf = (struct zebra_vrf *)vrf->info;
202 return zvrf;
203}
204
81c9005f
PG
205static inline const char *zvrf_ns_name(struct zebra_vrf *zvrf)
206{
207 if (!zvrf->vrf || !zvrf->vrf->ns_ctxt)
208 return NULL;
209 return ns_get_name((struct ns *)zvrf->vrf->ns_ctxt);
210}
211
d62a17ae 212static inline const char *zvrf_name(struct zebra_vrf *zvrf)
661512bf 213{
d62a17ae 214 return zvrf->vrf->name;
661512bf
RW
215}
216
81c9005f
PG
217static inline bool zvrf_is_active(struct zebra_vrf *zvrf)
218{
219 return zvrf->vrf->status & VRF_ACTIVE;
220}
221
d8612e65
DS
222static inline int
223zvrf_other_table_compare_func(const struct other_route_table *a,
224 const struct other_route_table *b)
225{
226 if (a->afi != b->afi)
227 return a->afi - b->afi;
228
229 if (a->safi != b->safi)
230 return a->safi - b->safi;
231
232 if (a->table_id != b->table_id)
233 return a->table_id - b->table_id;
234
235 return 0;
236}
237
238DECLARE_RBTREE_UNIQ(otable, struct other_route_table, next,
239 zvrf_other_table_compare_func)
240
d62a17ae 241struct route_table *zebra_vrf_table_with_table_id(afi_t afi, safi_t safi,
242 vrf_id_t vrf_id,
d7c0a89a 243 uint32_t table_id);
d62a17ae 244
d62a17ae 245extern void zebra_vrf_update_all(struct zserv *client);
246extern struct zebra_vrf *zebra_vrf_lookup_by_id(vrf_id_t vrf_id);
247extern struct zebra_vrf *zebra_vrf_lookup_by_name(const char *);
248extern struct zebra_vrf *zebra_vrf_alloc(void);
249extern struct route_table *zebra_vrf_table(afi_t, safi_t, vrf_id_t);
7e24fdf3 250
22bd3e94 251extern int zebra_vrf_has_config(struct zebra_vrf *zvrf);
d62a17ae 252extern void zebra_vrf_init(void);
5335613b
DS
253
254extern void zebra_rtable_node_cleanup(struct route_table *table,
255 struct route_node *node);
51e94aa7
EDP
256
257#ifdef __cplusplus
258}
259#endif
260
736d41ad 261#endif /* ZEBRA_VRF_H */