]> git.proxmox.com Git - mirror_frr.git/blame - zebra/zebra_vrf.h
zebra: Prevent installation of connected multiple times
[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 */
c4528712 36struct mpls_srgb {
d7c0a89a
QY
37 uint32_t start_label;
38 uint32_t end_label;
c4528712 39};
1b6d5c7e 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)
ecbbc3a7 72#define ZEBRA_PIM_SEND_VXLAN_SG (1 << 1)
7c551956 73
d7c0a89a 74 uint32_t table_id;
7c551956 75
d62a17ae 76 /* Routing table. */
77 struct route_table *table[AFI_MAX][SAFI_MAX];
7c551956 78
d62a17ae 79 /* Recursive Nexthop table */
80 struct route_table *rnh_table[AFI_MAX];
a4598b97 81 struct route_table *rnh_table_multicast[AFI_MAX];
7c551956 82
d8612e65
DS
83 struct otable_head other_tables;
84
d62a17ae 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;
98a3fb0a
SM
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;
7c551956 98
d62a17ae 99 /*
100 * Back pointer to the owning namespace.
101 */
102 struct zebra_ns *zns;
54d48ea1 103
c83c5e44 104 /* MPLS Label to handle L3VPN <-> vrf popping */
7d061b3c 105 mpls_label_t label[AFI_MAX];
06302ecb 106 uint8_t label_proto[AFI_MAX];
c83c5e44 107
d62a17ae 108 /* MPLS static LSP config table */
109 struct hash *slsp_table;
54d48ea1 110
d62a17ae 111 /* MPLS label forwarding table */
112 struct hash *lsp_table;
939fba27 113
d62a17ae 114 /* MPLS FEC binding table */
115 struct route_table *fec_table[AFI_MAX];
f31e084c 116
d62a17ae 117 /* MPLS Segment Routing Global block */
c4528712 118 struct mpls_srgb mpls_srgb;
1b6d5c7e 119
6833ae01 120 /* Pseudowires. */
121 struct zebra_pw_head pseudowires;
2dd0d726 122 struct zebra_static_pw_head static_pseudowires;
6833ae01 123
ac6eebce 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
d62a17ae 127 /* MPLS processing flags */
d7c0a89a 128 uint16_t mpls_flags;
939fba27 129#define MPLS_FLAG_SCHEDULE_LSPS (1 << 0)
57282a31 130
d62a17ae 131 /*
87d76d54 132 * EVPN hash table. Only in the EVPN instance.
d62a17ae 133 */
87d76d54 134 struct hash *evpn_table;
2853fed6 135
d62a17ae 136 /*
150971b5 137 * Whether EVPN is enabled or not. Only in the EVPN instance.
d62a17ae 138 */
139 int advertise_all_vni;
140
1a98c087
MK
141 /*
142 * Whether we are advertising g/w macip in EVPN or not.
150971b5 143 * Only in the EVPN instance.
1a98c087
MK
144 */
145 int advertise_gw_macip;
146
278e26de
CS
147 int advertise_svi_macip;
148
b7cfce93
MK
149 /* l3-vni info */
150 vni_t l3vni;
151
8a93734c
AK
152 /* pim mroutes installed for vxlan flooding */
153 struct hash *vxlan_sg_table;
154
3950b52c
CS
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
fbac9605
DS
162 /*
163 * Flooding mechanism for BUM packets for VxLAN-EVPN.
164 */
165 enum vxlan_flood_control vxlan_flood_ctrl;
166
d37f4d6c 167 /* Install stats */
d62a17ae 168 uint64_t installs;
169 uint64_t removals;
97f5b441
MS
170 uint64_t installs_queued;
171 uint64_t removals_queued;
d62a17ae 172 uint64_t neigh_updates;
d37f4d6c
MS
173 uint64_t lsp_installs_queued;
174 uint64_t lsp_removals_queued;
d62a17ae 175 uint64_t lsp_installs;
176 uint64_t lsp_removals;
df9c8c57 177
42d4b30e
PG
178 struct table_manager *tbl_mgr;
179
df9c8c57
PG
180#if defined(HAVE_RTADV)
181 struct rtadv rtadv;
182#endif /* HAVE_RTADV */
5a0bdc78 183
4aabcba0
DS
184 bool zebra_rnh_ip_default_route;
185 bool zebra_rnh_ipv6_default_route;
7c551956 186};
ac6eebce 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
7c551956 191
214e5c26 192/*
193 * special macro to allow us to get the correct zebra_vrf
194 */
195#define ZEBRA_DECLVAR_CONTEXT(A, B) \
58929633
IR
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
214e5c26 203
d62a17ae 204static inline vrf_id_t zvrf_id(struct zebra_vrf *zvrf)
661512bf 205{
2c7d4021 206 if (!zvrf || !zvrf->vrf)
bd47f3a3 207 return VRF_DEFAULT;
d62a17ae 208 return zvrf->vrf->vrf_id;
661512bf
RW
209}
210
81c9005f
PG
211static 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
d62a17ae 218static inline const char *zvrf_name(struct zebra_vrf *zvrf)
661512bf 219{
bd47f3a3
JU
220 if (!zvrf || !zvrf->vrf)
221 return "Unknown";
d62a17ae 222 return zvrf->vrf->name;
661512bf
RW
223}
224
81c9005f
PG
225static inline bool zvrf_is_active(struct zebra_vrf *zvrf)
226{
227 return zvrf->vrf->status & VRF_ACTIVE;
228}
229
d8612e65
DS
230static inline int
231zvrf_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
246DECLARE_RBTREE_UNIQ(otable, struct other_route_table, next,
960b9a53 247 zvrf_other_table_compare_func);
d8612e65 248
c7c0b007
SW
249extern struct route_table *
250zebra_vrf_lookup_table_with_table_id(afi_t afi, safi_t safi, vrf_id_t vrf_id,
251 uint32_t table_id);
252extern 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);
d62a17ae 256
d62a17ae 257extern void zebra_vrf_update_all(struct zserv *client);
258extern struct zebra_vrf *zebra_vrf_lookup_by_id(vrf_id_t vrf_id);
259extern struct zebra_vrf *zebra_vrf_lookup_by_name(const char *);
ec64a634 260extern struct zebra_vrf *zebra_vrf_alloc(struct vrf *vrf);
d62a17ae 261extern struct route_table *zebra_vrf_table(afi_t, safi_t, vrf_id_t);
7e24fdf3 262
62d89c64
IR
263/*
264 * API to associate a VRF with a NETNS.
265 * Called either from vty or through discovery.
266 */
267extern 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
d62a17ae 271extern void zebra_vrf_init(void);
5335613b
DS
272
273extern void zebra_rtable_node_cleanup(struct route_table *table,
274 struct route_node *node);
51e94aa7
EDP
275
276#ifdef __cplusplus
277}
278#endif
279
736d41ad 280#endif /* ZEBRA_VRF_H */