summaryrefslogtreecommitdiffstats
path: root/zebra/zebra_vrf.h
blob: 02e3c197c9bea70ee71c42984813875edd7696c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/*
 * Zebra Vrf Header
 * Copyright (C) 2016 Cumulus Networks
 *                    Donald Sharp
 *
 * This file is part of Quagga.
 *
 * Quagga is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2, or (at your option) any
 * later version.
 *
 * Quagga is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; see the file COPYING; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 */
#if !defined(__ZEBRA_VRF_H__)
#define __ZEBRA_VRF_H__

#include "vxlan.h"

#include <zebra/zebra_ns.h>
#include <zebra/zebra_pw.h>
#include <zebra/rtadv.h>
#include <lib/vxlan.h>

#ifdef __cplusplus
extern "C" {
#endif

/* MPLS (Segment Routing) global block */
struct mpls_srgb {
	uint32_t start_label;
	uint32_t end_label;
};

struct zebra_rmap {
	char *name;
	struct route_map *map;
};

PREDECL_RBTREE_UNIQ(otable);

struct other_route_table {
	struct otable_item next;

	afi_t afi;
	safi_t safi;
	uint32_t table_id;

	struct route_table *table;
};

/* Routing table instance.  */
struct zebra_vrf {
	/* Back pointer */
	struct vrf *vrf;

	/* Description.  */
	char *desc;

	/* FIB identifier.  */
	uint8_t fib_id;

	/* Flags. */
	uint16_t flags;
#define ZEBRA_VRF_RETAIN          (1 << 0)
#define ZEBRA_PIM_SEND_VXLAN_SG   (1 << 1)

	uint32_t table_id;

	/* Routing table.  */
	struct route_table *table[AFI_MAX][SAFI_MAX];

	/* Recursive Nexthop table */
	struct route_table *rnh_table[AFI_MAX];
	struct route_table *rnh_table_multicast[AFI_MAX];

	struct otable_head other_tables;

	/* 2nd pointer type used primarily to quell a warning on
	 * ALL_LIST_ELEMENTS_RO
	 */
	struct list _rid_all_sorted_list;
	struct list _rid_lo_sorted_list;
	struct list *rid_all_sorted_list;
	struct list *rid_lo_sorted_list;
	struct prefix rid_user_assigned;
	struct list _rid6_all_sorted_list;
	struct list _rid6_lo_sorted_list;
	struct list *rid6_all_sorted_list;
	struct list *rid6_lo_sorted_list;
	struct prefix rid6_user_assigned;

	/*
	 * Back pointer to the owning namespace.
	 */
	struct zebra_ns *zns;

	/* MPLS Label to handle L3VPN <-> vrf popping */
	mpls_label_t label[AFI_MAX];
	uint8_t label_proto[AFI_MAX];

	/* MPLS static LSP config table */
	struct hash *slsp_table;

	/* MPLS label forwarding table */
	struct hash *lsp_table;

	/* MPLS FEC binding table */
	struct route_table *fec_table[AFI_MAX];

	/* MPLS Segment Routing Global block */
	struct mpls_srgb mpls_srgb;

	/* Pseudowires. */
	struct zebra_pw_head pseudowires;
	struct zebra_static_pw_head static_pseudowires;

	struct zebra_rmap proto_rm[AFI_MAX][ZEBRA_ROUTE_MAX + 1];
	struct zebra_rmap nht_rm[AFI_MAX][ZEBRA_ROUTE_MAX + 1];

	/* MPLS processing flags */
	uint16_t mpls_flags;
#define MPLS_FLAG_SCHEDULE_LSPS    (1 << 0)

	/*
	 * EVPN hash table. Only in the EVPN instance.
	 */
	struct hash *evpn_table;

	/*
	 * Whether EVPN is enabled or not. Only in the EVPN instance.
	 */
	int advertise_all_vni;

	/*
	 * Whether we are advertising g/w macip in EVPN or not.
	 * Only in the EVPN instance.
	 */
	int advertise_gw_macip;

	int advertise_svi_macip;

	/* l3-vni info */
	vni_t l3vni;

	/* pim mroutes installed for vxlan flooding */
	struct hash *vxlan_sg_table;

	bool dup_addr_detect;

	int dad_time;
	uint32_t dad_max_moves;
	bool dad_freeze;
	uint32_t dad_freeze_time;

	/*
	 * Flooding mechanism for BUM packets for VxLAN-EVPN.
	 */
	enum vxlan_flood_control vxlan_flood_ctrl;

	/* Install stats */
	uint64_t installs;
	uint64_t removals;
	uint64_t installs_queued;
	uint64_t removals_queued;
	uint64_t neigh_updates;
	uint64_t lsp_installs_queued;
	uint64_t lsp_removals_queued;
	uint64_t lsp_installs;
	uint64_t lsp_removals;

	struct table_manager *tbl_mgr;

	struct rtadv rtadv;

	bool zebra_rnh_ip_default_route;
	bool zebra_rnh_ipv6_default_route;
};
#define PROTO_RM_NAME(zvrf, afi, rtype) zvrf->proto_rm[afi][rtype].name
#define NHT_RM_NAME(zvrf, afi, rtype) zvrf->nht_rm[afi][rtype].name
#define PROTO_RM_MAP(zvrf, afi, rtype) zvrf->proto_rm[afi][rtype].map
#define NHT_RM_MAP(zvrf, afi, rtype) zvrf->nht_rm[afi][rtype].map

/*
 * special macro to allow us to get the correct zebra_vrf
 */
#define ZEBRA_DECLVAR_CONTEXT_VRF(vrfptr, zvrfptr)                             \
	VTY_DECLVAR_CONTEXT_VRF(vrfptr);                                       \
	struct zebra_vrf *zvrfptr = vrfptr->info;                              \
	MACRO_REQUIRE_SEMICOLON() /* end */

static inline vrf_id_t zvrf_id(struct zebra_vrf *zvrf)
{
	if (!zvrf || !zvrf->vrf)
		return VRF_DEFAULT;
	return zvrf->vrf->vrf_id;
}

static inline const char *zvrf_ns_name(struct zebra_vrf *zvrf)
{
	if (!zvrf->vrf || !zvrf->vrf->ns_ctxt)
		return NULL;
	return ns_get_name((struct ns *)zvrf->vrf->ns_ctxt);
}

static inline const char *zvrf_name(struct zebra_vrf *zvrf)
{
	if (!zvrf || !zvrf->vrf)
		return "Unknown";
	return zvrf->vrf->name;
}

static inline bool zvrf_is_active(struct zebra_vrf *zvrf)
{
	return zvrf->vrf->status & VRF_ACTIVE;
}

static inline int
zvrf_other_table_compare_func(const struct other_route_table *a,
			      const struct other_route_table *b)
{
	if (a->afi != b->afi)
		return a->afi - b->afi;

	if (a->safi != b->safi)
		return a->safi - b->safi;

	if (a->table_id != b->table_id)
		return a->table_id - b->table_id;

	return 0;
}

DECLARE_RBTREE_UNIQ(otable, struct other_route_table, next,
		    zvrf_other_table_compare_func);

extern struct route_table *
zebra_vrf_lookup_table_with_table_id(afi_t afi, safi_t safi, vrf_id_t vrf_id,
				     uint32_t table_id);
extern struct route_table *zebra_vrf_get_table_with_table_id(afi_t afi,
							     safi_t safi,
							     vrf_id_t vrf_id,
							     uint32_t table_id);

extern void zebra_vrf_update_all(struct zserv *client);
extern struct zebra_vrf *zebra_vrf_lookup_by_id(vrf_id_t vrf_id);
extern struct zebra_vrf *zebra_vrf_lookup_by_name(const char *);
extern struct zebra_vrf *zebra_vrf_alloc(struct vrf *vrf);
extern struct route_table *zebra_vrf_table(afi_t, safi_t, vrf_id_t);

/*
 * API to associate a VRF with a NETNS.
 * Called either from vty or through discovery.
 */
extern int zebra_vrf_netns_handler_create(struct vty *vty, struct vrf *vrf,
					  char *pathname, ns_id_t ext_ns_id,
					  ns_id_t ns_id, ns_id_t rel_def_ns_id);

extern void zebra_vrf_init(void);

extern void zebra_rtable_node_cleanup(struct route_table *table,
				      struct route_node *node);

#ifdef __cplusplus
}
#endif

#endif /* ZEBRA_VRF_H */