mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-13 17:40:04 +00:00
zebra: Start breakup of zns into zrouter and zns
The `struct zebra_ns` data structure is being used for both router information as well as support for the vrf backend( as appropriate ). This is a confusing state. Start the movement of `struct zebra_ns` into 2 things `struct zebra_router` and `struct zebra_ns`. In this new regime `struct zebra_router` is purely for handling data about the router. It has no knowledge of the underlying representation of the Data Plane. `struct zebra_ns` becomes a linux specific bit of code that allows us to handle the vrf backend and is allowed to have knowledge about underlying data plane constructs. When someone implements a *bsd backend the zebra_vrf data structure will need to be abstracted to take advantage of this instead of relying on zebra_ns. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
This commit is contained in:
parent
82d6d6e9be
commit
89272910f7
@ -39,6 +39,7 @@
|
||||
#include "routemap.h"
|
||||
#include "frr_pthread.h"
|
||||
|
||||
#include "zebra/zebra_router.h"
|
||||
#include "zebra/zebra_errors.h"
|
||||
#include "zebra/rib.h"
|
||||
#include "zebra/zserv.h"
|
||||
@ -174,6 +175,8 @@ static void sigint(void)
|
||||
work_queue_free_and_null(&zebrad.ribq);
|
||||
meta_queue_free(zebrad.mq);
|
||||
|
||||
zebra_router_terminate();
|
||||
|
||||
frr_fini();
|
||||
exit(0);
|
||||
}
|
||||
@ -354,6 +357,7 @@ int main(int argc, char **argv)
|
||||
zebrad.master = frr_init();
|
||||
|
||||
/* Zebra related initialize. */
|
||||
zebra_router_init();
|
||||
zserv_init();
|
||||
rib_init();
|
||||
zebra_if_init();
|
||||
|
@ -79,6 +79,7 @@ zebra_zebra_SOURCES = \
|
||||
zebra/zebra_ptm_redistribute.c \
|
||||
zebra/zebra_pw.c \
|
||||
zebra/zebra_rib.c \
|
||||
zebra/zebra_router.c \
|
||||
zebra/zebra_rnh.c \
|
||||
zebra/zebra_routemap.c \
|
||||
zebra/zebra_vrf.c \
|
||||
@ -131,6 +132,7 @@ noinst_HEADERS += \
|
||||
zebra/zebra_pw.h \
|
||||
zebra/zebra_rnh.h \
|
||||
zebra/zebra_routemap.h \
|
||||
zebra/zebra_router.h \
|
||||
zebra/zebra_vrf.h \
|
||||
zebra/zebra_vxlan.h \
|
||||
zebra/zebra_vxlan_private.h \
|
||||
|
123
zebra/zebra_ns.c
123
zebra/zebra_ns.c
@ -44,28 +44,8 @@ extern struct zebra_privs_t zserv_privs;
|
||||
|
||||
DEFINE_MTYPE(ZEBRA, ZEBRA_NS, "Zebra Name Space")
|
||||
|
||||
static inline int zebra_ns_table_entry_compare(const struct zebra_ns_table *e1,
|
||||
const struct zebra_ns_table *e2);
|
||||
|
||||
RB_GENERATE(zebra_ns_table_head, zebra_ns_table, zebra_ns_table_entry,
|
||||
zebra_ns_table_entry_compare);
|
||||
|
||||
static struct zebra_ns *dzns;
|
||||
|
||||
static inline int zebra_ns_table_entry_compare(const struct zebra_ns_table *e1,
|
||||
const struct zebra_ns_table *e2)
|
||||
{
|
||||
if (e1->tableid < e2->tableid)
|
||||
return -1;
|
||||
if (e1->tableid > e2->tableid)
|
||||
return 1;
|
||||
if (e1->ns_id < e2->ns_id)
|
||||
return -1;
|
||||
if (e1->ns_id > e2->ns_id)
|
||||
return 1;
|
||||
return (e1->afi - e2->afi);
|
||||
}
|
||||
|
||||
static int logicalrouter_config_write(struct vty *vty);
|
||||
|
||||
struct zebra_ns *zebra_ns_lookup(ns_id_t ns_id)
|
||||
@ -173,104 +153,8 @@ int zebra_ns_enable(ns_id_t ns_id, void **info)
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct route_table *zebra_ns_find_table(struct zebra_ns *zns, uint32_t tableid,
|
||||
afi_t afi)
|
||||
{
|
||||
struct zebra_ns_table finder;
|
||||
struct zebra_ns_table *znst;
|
||||
|
||||
memset(&finder, 0, sizeof(finder));
|
||||
finder.afi = afi;
|
||||
finder.tableid = tableid;
|
||||
finder.ns_id = zns->ns_id;
|
||||
znst = RB_FIND(zebra_ns_table_head, &zns->ns_tables, &finder);
|
||||
|
||||
if (znst)
|
||||
return znst->table;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
unsigned long zebra_ns_score_proto(uint8_t proto, unsigned short instance)
|
||||
{
|
||||
struct zebra_ns *zns;
|
||||
struct zebra_ns_table *znst;
|
||||
unsigned long cnt = 0;
|
||||
|
||||
zns = zebra_ns_lookup(NS_DEFAULT);
|
||||
|
||||
RB_FOREACH (znst, zebra_ns_table_head, &zns->ns_tables) {
|
||||
if (znst->ns_id != NS_DEFAULT)
|
||||
continue;
|
||||
cnt += rib_score_proto_table(proto, instance, znst->table);
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
void zebra_ns_sweep_route(void)
|
||||
{
|
||||
struct zebra_ns_table *znst;
|
||||
struct zebra_ns *zns;
|
||||
|
||||
zns = zebra_ns_lookup(NS_DEFAULT);
|
||||
|
||||
RB_FOREACH (znst, zebra_ns_table_head, &zns->ns_tables) {
|
||||
if (znst->ns_id != NS_DEFAULT)
|
||||
continue;
|
||||
rib_sweep_table(znst->table);
|
||||
}
|
||||
}
|
||||
|
||||
struct route_table *zebra_ns_get_table(struct zebra_ns *zns,
|
||||
struct zebra_vrf *zvrf, uint32_t tableid,
|
||||
afi_t afi)
|
||||
{
|
||||
struct zebra_ns_table finder;
|
||||
struct zebra_ns_table *znst;
|
||||
rib_table_info_t *info;
|
||||
|
||||
memset(&finder, 0, sizeof(finder));
|
||||
finder.afi = afi;
|
||||
finder.tableid = tableid;
|
||||
finder.ns_id = zns->ns_id;
|
||||
znst = RB_FIND(zebra_ns_table_head, &zns->ns_tables, &finder);
|
||||
|
||||
if (znst)
|
||||
return znst->table;
|
||||
|
||||
znst = XCALLOC(MTYPE_ZEBRA_NS, sizeof(*znst));
|
||||
znst->tableid = tableid;
|
||||
znst->afi = afi;
|
||||
znst->ns_id = zns->ns_id;
|
||||
znst->table =
|
||||
(afi == AFI_IP6) ? srcdest_table_init() : route_table_init();
|
||||
|
||||
info = XCALLOC(MTYPE_RIB_TABLE_INFO, sizeof(*info));
|
||||
info->zvrf = zvrf;
|
||||
info->afi = afi;
|
||||
info->safi = SAFI_UNICAST;
|
||||
route_table_set_info(znst->table, info);
|
||||
znst->table->cleanup = zebra_rtable_node_cleanup;
|
||||
|
||||
RB_INSERT(zebra_ns_table_head, &zns->ns_tables, znst);
|
||||
return znst->table;
|
||||
}
|
||||
|
||||
static void zebra_ns_free_table(struct zebra_ns_table *znst)
|
||||
{
|
||||
void *table_info;
|
||||
|
||||
rib_close_table(znst->table);
|
||||
|
||||
table_info = route_table_get_info(znst->table);
|
||||
route_table_finish(znst->table);
|
||||
XFREE(MTYPE_RIB_TABLE_INFO, table_info);
|
||||
XFREE(MTYPE_ZEBRA_NS, znst);
|
||||
}
|
||||
|
||||
int zebra_ns_disable(ns_id_t ns_id, void **info)
|
||||
{
|
||||
struct zebra_ns_table *znst, *tmp;
|
||||
struct zebra_ns *zns = (struct zebra_ns *)(*info);
|
||||
|
||||
hash_clean(zns->rules_hash, zebra_pbr_rules_free);
|
||||
@ -283,13 +167,6 @@ int zebra_ns_disable(ns_id_t ns_id, void **info)
|
||||
zebra_pbr_iptable_free);
|
||||
hash_free(zns->iptable_hash);
|
||||
|
||||
RB_FOREACH_SAFE (znst, zebra_ns_table_head, &zns->ns_tables, tmp) {
|
||||
if (znst->ns_id != ns_id)
|
||||
continue;
|
||||
RB_REMOVE(zebra_ns_table_head, &zns->ns_tables, znst);
|
||||
zebra_ns_free_table(znst);
|
||||
}
|
||||
|
||||
route_table_finish(zns->if_table);
|
||||
zebra_vxlan_ns_disable(zns);
|
||||
#if defined(HAVE_RTADV)
|
||||
|
@ -38,19 +38,6 @@ struct nlsock {
|
||||
};
|
||||
#endif
|
||||
|
||||
struct zebra_ns_table {
|
||||
RB_ENTRY(zebra_ns_table) zebra_ns_table_entry;
|
||||
|
||||
uint32_t tableid;
|
||||
afi_t afi;
|
||||
ns_id_t ns_id;
|
||||
|
||||
struct route_table *table;
|
||||
};
|
||||
RB_HEAD(zebra_ns_table_head, zebra_ns_table);
|
||||
RB_PROTOTYPE(zebra_ns_table_head, zebra_ns_table, zebra_ns_table_entry,
|
||||
zebra_ns_table_entry_compare)
|
||||
|
||||
struct zebra_ns {
|
||||
/* net-ns name. */
|
||||
char name[VRF_NAMSIZ];
|
||||
@ -66,15 +53,10 @@ struct zebra_ns {
|
||||
|
||||
struct route_table *if_table;
|
||||
|
||||
/* L3-VNI hash table (for EVPN). Only in default instance */
|
||||
struct hash *l3vni_table;
|
||||
|
||||
#if defined(HAVE_RTADV)
|
||||
struct rtadv rtadv;
|
||||
#endif /* HAVE_RTADV */
|
||||
|
||||
struct zebra_ns_table_head ns_tables;
|
||||
|
||||
struct hash *rules_hash;
|
||||
|
||||
struct hash *ipset_hash;
|
||||
@ -94,13 +76,6 @@ int zebra_ns_enable(ns_id_t ns_id, void **info);
|
||||
int zebra_ns_disabled(struct ns *ns);
|
||||
int zebra_ns_disable(ns_id_t ns_id, void **info);
|
||||
|
||||
extern struct route_table *zebra_ns_find_table(struct zebra_ns *zns,
|
||||
uint32_t tableid, afi_t afi);
|
||||
extern struct route_table *zebra_ns_get_table(struct zebra_ns *zns,
|
||||
struct zebra_vrf *zvrf,
|
||||
uint32_t tableid, afi_t afi);
|
||||
int zebra_ns_config_write(struct vty *vty, struct ns *ns);
|
||||
|
||||
unsigned long zebra_ns_score_proto(uint8_t proto, unsigned short instance);
|
||||
void zebra_ns_sweep_route(void);
|
||||
#endif
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include "vrf.h"
|
||||
#include "workqueue.h"
|
||||
|
||||
#include "zebra/zebra_router.h"
|
||||
#include "zebra/connected.h"
|
||||
#include "zebra/debug.h"
|
||||
#include "zebra/interface.h"
|
||||
@ -2930,7 +2931,7 @@ void rib_sweep_route(void)
|
||||
rib_sweep_table(zvrf->table[AFI_IP6][SAFI_UNICAST]);
|
||||
}
|
||||
|
||||
zebra_ns_sweep_route();
|
||||
zebra_router_sweep_route();
|
||||
}
|
||||
|
||||
/* Remove specific by protocol routes from 'table'. */
|
||||
@ -2972,7 +2973,7 @@ unsigned long rib_score_proto(uint8_t proto, unsigned short instance)
|
||||
proto, instance,
|
||||
zvrf->table[AFI_IP6][SAFI_UNICAST]);
|
||||
|
||||
cnt += zebra_ns_score_proto(proto, instance);
|
||||
cnt += zebra_router_score_proto(proto, instance);
|
||||
|
||||
return cnt;
|
||||
}
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "nexthop.h"
|
||||
#include "vrf.h"
|
||||
|
||||
#include "zebra/zebra_router.h"
|
||||
#include "zebra/rib.h"
|
||||
#include "zebra/rt.h"
|
||||
#include "zebra/zserv.h"
|
||||
@ -469,12 +470,11 @@ static void zebra_rnh_process_pbr_tables(int family,
|
||||
struct route_node *prn,
|
||||
struct route_entry *re)
|
||||
{
|
||||
struct zebra_ns_table *znst;
|
||||
struct zebra_router_table *zrt;
|
||||
struct route_entry *o_re;
|
||||
struct route_node *o_rn;
|
||||
struct listnode *node;
|
||||
struct zserv *client;
|
||||
struct zebra_ns *zns;
|
||||
afi_t afi = AFI_IP;
|
||||
|
||||
if (family == AF_INET6)
|
||||
@ -492,13 +492,12 @@ static void zebra_rnh_process_pbr_tables(int family,
|
||||
if (!client)
|
||||
return;
|
||||
|
||||
zns = zebra_ns_lookup(NS_DEFAULT);
|
||||
RB_FOREACH (znst, zebra_ns_table_head, &zns->ns_tables) {
|
||||
if (afi != znst->afi)
|
||||
RB_FOREACH (zrt, zebra_router_table_head, &zrouter.tables) {
|
||||
if (afi != zrt->afi)
|
||||
continue;
|
||||
|
||||
for (o_rn = route_top(znst->table);
|
||||
o_rn; o_rn = srcdest_route_next(o_rn)) {
|
||||
for (o_rn = route_top(zrt->table); o_rn;
|
||||
o_rn = srcdest_route_next(o_rn)) {
|
||||
RNODE_FOREACH_RE (o_rn, o_re) {
|
||||
if (o_re->type == ZEBRA_ROUTE_PBR)
|
||||
break;
|
||||
|
162
zebra/zebra_router.c
Normal file
162
zebra/zebra_router.c
Normal file
@ -0,0 +1,162 @@
|
||||
/* Zebra Router Code.
|
||||
* Copyright (C) 2018 Cumulus Networks, Inc.
|
||||
* Donald Sharp
|
||||
*
|
||||
* This file is part of FRR.
|
||||
*
|
||||
* FRR 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.
|
||||
*
|
||||
* FRR 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 FRR; see the file COPYING. If not, write to the Free
|
||||
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*/
|
||||
#include "zebra.h"
|
||||
|
||||
#include "zebra_router.h"
|
||||
#include "zebra_memory.h"
|
||||
|
||||
struct zebra_router zrouter;
|
||||
|
||||
static inline int
|
||||
zebra_router_table_entry_compare(const struct zebra_router_table *e1,
|
||||
const struct zebra_router_table *e2);
|
||||
|
||||
RB_GENERATE(zebra_router_table_head, zebra_router_table,
|
||||
zebra_router_table_entry, zebra_router_table_entry_compare);
|
||||
|
||||
|
||||
static inline int
|
||||
zebra_router_table_entry_compare(const struct zebra_router_table *e1,
|
||||
const struct zebra_router_table *e2)
|
||||
{
|
||||
if (e1->tableid < e2->tableid)
|
||||
return -1;
|
||||
if (e1->tableid > e2->tableid)
|
||||
return 1;
|
||||
if (e1->ns_id < e2->ns_id)
|
||||
return -1;
|
||||
if (e1->ns_id > e2->ns_id)
|
||||
return 1;
|
||||
if (e1->afi < e2->afi)
|
||||
return -1;
|
||||
if (e1->afi > e2->afi)
|
||||
return 1;
|
||||
return (e1->safi - e2->safi);
|
||||
}
|
||||
|
||||
|
||||
struct route_table *zebra_router_find_table(struct zebra_vrf *zvrf,
|
||||
uint32_t tableid, afi_t afi,
|
||||
safi_t safi)
|
||||
{
|
||||
struct zebra_router_table finder;
|
||||
struct zebra_router_table *zrt;
|
||||
|
||||
memset(&finder, 0, sizeof(finder));
|
||||
finder.afi = afi;
|
||||
finder.safi = safi;
|
||||
finder.tableid = tableid;
|
||||
finder.ns_id = zvrf->zns->ns_id;
|
||||
zrt = RB_FIND(zebra_router_table_head, &zrouter.tables, &finder);
|
||||
|
||||
if (zrt)
|
||||
return zrt->table;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct route_table *zebra_router_get_table(struct zebra_vrf *zvrf,
|
||||
uint32_t tableid, afi_t afi,
|
||||
safi_t safi)
|
||||
{
|
||||
struct zebra_router_table finder;
|
||||
struct zebra_router_table *zrt;
|
||||
rib_table_info_t *info;
|
||||
|
||||
memset(&finder, 0, sizeof(finder));
|
||||
finder.afi = afi;
|
||||
finder.safi = safi;
|
||||
finder.tableid = tableid;
|
||||
finder.ns_id = zvrf->zns->ns_id;
|
||||
zrt = RB_FIND(zebra_router_table_head, &zrouter.tables, &finder);
|
||||
|
||||
if (zrt)
|
||||
return zrt->table;
|
||||
|
||||
zrt = XCALLOC(MTYPE_ZEBRA_NS, sizeof(*zrt));
|
||||
zrt->tableid = tableid;
|
||||
zrt->afi = afi;
|
||||
zrt->ns_id = zvrf->zns->ns_id;
|
||||
zrt->table =
|
||||
(afi == AFI_IP6) ? srcdest_table_init() : route_table_init();
|
||||
|
||||
info = XCALLOC(MTYPE_RIB_TABLE_INFO, sizeof(*info));
|
||||
info->zvrf = zvrf;
|
||||
info->afi = afi;
|
||||
info->safi = SAFI_UNICAST;
|
||||
route_table_set_info(zrt->table, info);
|
||||
zrt->table->cleanup = zebra_rtable_node_cleanup;
|
||||
|
||||
RB_INSERT(zebra_router_table_head, &zrouter.tables, zrt);
|
||||
return zrt->table;
|
||||
}
|
||||
|
||||
unsigned long zebra_router_score_proto(uint8_t proto, unsigned short instance)
|
||||
{
|
||||
struct zebra_router_table *zrt;
|
||||
unsigned long cnt = 0;
|
||||
|
||||
RB_FOREACH (zrt, zebra_router_table_head, &zrouter.tables) {
|
||||
if (zrt->ns_id != NS_DEFAULT)
|
||||
continue;
|
||||
cnt += rib_score_proto_table(proto, instance, zrt->table);
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
void zebra_router_sweep_route(void)
|
||||
{
|
||||
struct zebra_router_table *zrt;
|
||||
|
||||
RB_FOREACH (zrt, zebra_router_table_head, &zrouter.tables) {
|
||||
if (zrt->ns_id != NS_DEFAULT)
|
||||
continue;
|
||||
rib_sweep_table(zrt->table);
|
||||
}
|
||||
}
|
||||
|
||||
static void zebra_router_free_table(struct zebra_router_table *zrt)
|
||||
{
|
||||
void *table_info;
|
||||
|
||||
rib_close_table(zrt->table);
|
||||
|
||||
table_info = route_table_get_info(zrt->table);
|
||||
route_table_finish(zrt->table);
|
||||
XFREE(MTYPE_RIB_TABLE_INFO, table_info);
|
||||
XFREE(MTYPE_ZEBRA_NS, zrt);
|
||||
}
|
||||
|
||||
void zebra_router_terminate(void)
|
||||
{
|
||||
struct zebra_router_table *zrt, *tmp;
|
||||
|
||||
RB_FOREACH_SAFE (zrt, zebra_router_table_head, &zrouter.tables, tmp) {
|
||||
RB_REMOVE(zebra_router_table_head, &zrouter.tables, zrt);
|
||||
zebra_router_free_table(zrt);
|
||||
}
|
||||
}
|
||||
|
||||
void zebra_router_init(void)
|
||||
{
|
||||
zrouter.l3vni_table = NULL;
|
||||
}
|
71
zebra/zebra_router.h
Normal file
71
zebra/zebra_router.h
Normal file
@ -0,0 +1,71 @@
|
||||
/* Zebra Router header.
|
||||
* Copyright (C) 2018 Cumulus Networks, Inc.
|
||||
* Donald Sharp
|
||||
*
|
||||
* This file is part of FRR.
|
||||
*
|
||||
* FRR 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.
|
||||
*
|
||||
* FRR 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 FRR; see the file COPYING. If not, write to the Free
|
||||
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*/
|
||||
#ifndef __ZEBRA_ROUTER_H__
|
||||
#define __ZEBRA_ROUTER_H__
|
||||
|
||||
#include "zebra/zebra_ns.h"
|
||||
|
||||
/*
|
||||
* This header file contains the idea of a router and as such
|
||||
* owns data that is associated with a router from zebra's
|
||||
* perspective.
|
||||
*/
|
||||
|
||||
struct zebra_router_table {
|
||||
RB_ENTRY(zebra_router_table) zebra_router_table_entry;
|
||||
|
||||
uint32_t tableid;
|
||||
afi_t afi;
|
||||
safi_t safi;
|
||||
ns_id_t ns_id;
|
||||
|
||||
struct route_table *table;
|
||||
};
|
||||
RB_HEAD(zebra_router_table_head, zebra_router_table);
|
||||
RB_PROTOTYPE(zebra_router_table_head, zebra_router_table,
|
||||
zebra_router_table_entry, zebra_router_table_entry_compare)
|
||||
|
||||
struct zebra_router {
|
||||
|
||||
struct zebra_router_table_head tables;
|
||||
/* L3-VNI hash table (for EVPN). Only in default instance */
|
||||
struct hash *l3vni_table;
|
||||
};
|
||||
|
||||
extern struct zebra_router zrouter;
|
||||
|
||||
extern void zebra_router_init(void);
|
||||
extern void zebra_router_terminate(void);
|
||||
|
||||
extern struct route_table *zebra_router_find_table(struct zebra_vrf *zvrf,
|
||||
uint32_t tableid, afi_t afi,
|
||||
safi_t safi);
|
||||
extern struct route_table *zebra_router_get_table(struct zebra_vrf *zvrf,
|
||||
uint32_t tableid, afi_t afi,
|
||||
safi_t safi);
|
||||
|
||||
extern int zebra_router_config_write(struct vty *vty);
|
||||
|
||||
extern unsigned long zebra_router_score_proto(uint8_t proto,
|
||||
unsigned short instance);
|
||||
extern void zebra_router_sweep_route(void);
|
||||
#endif
|
@ -28,6 +28,7 @@
|
||||
#include "vrf.h"
|
||||
#include "vty.h"
|
||||
|
||||
#include "zebra/zebra_router.h"
|
||||
#include "zebra/debug.h"
|
||||
#include "zebra/zapi_msg.h"
|
||||
#include "zebra/rib.h"
|
||||
@ -144,7 +145,6 @@ static int zebra_vrf_enable(struct vrf *vrf)
|
||||
static int zebra_vrf_disable(struct vrf *vrf)
|
||||
{
|
||||
struct zebra_vrf *zvrf = vrf->info;
|
||||
struct route_table *table;
|
||||
struct interface *ifp;
|
||||
afi_t afi;
|
||||
safi_t safi;
|
||||
@ -202,15 +202,16 @@ static int zebra_vrf_disable(struct vrf *vrf)
|
||||
|
||||
/* Cleanup (free) routing tables and NHT tables. */
|
||||
for (afi = AFI_IP; afi <= AFI_IP6; afi++) {
|
||||
void *table_info;
|
||||
|
||||
for (safi = SAFI_UNICAST; safi <= SAFI_MULTICAST; safi++) {
|
||||
table = zvrf->table[afi][safi];
|
||||
table_info = route_table_get_info(table);
|
||||
route_table_finish(table);
|
||||
XFREE(MTYPE_RIB_TABLE_INFO, table_info);
|
||||
/*
|
||||
* Set the table pointer to NULL as that
|
||||
* we no-longer need a copy of it, nor do we
|
||||
* own this data, the zebra_router structure
|
||||
* owns these tables. Once we've cleaned up the
|
||||
* table, see rib_close_table above
|
||||
* we no-longer need this pointer.
|
||||
*/
|
||||
for (safi = SAFI_UNICAST; safi <= SAFI_MULTICAST; safi++)
|
||||
zvrf->table[afi][safi] = NULL;
|
||||
}
|
||||
|
||||
route_table_finish(zvrf->rnh_table[afi]);
|
||||
zvrf->rnh_table[afi] = NULL;
|
||||
@ -374,10 +375,8 @@ static void zebra_vrf_table_create(struct zebra_vrf *zvrf, afi_t afi,
|
||||
|
||||
assert(!zvrf->table[afi][safi]);
|
||||
|
||||
if (afi == AFI_IP6)
|
||||
table = srcdest_table_init();
|
||||
else
|
||||
table = route_table_init();
|
||||
table = zebra_router_get_table(zvrf, zvrf->table_id, afi, safi);
|
||||
|
||||
table->cleanup = zebra_rtable_node_cleanup;
|
||||
zvrf->table[afi][safi] = table;
|
||||
|
||||
@ -442,14 +441,11 @@ struct route_table *zebra_vrf_other_route_table(afi_t afi, uint32_t table_id,
|
||||
vrf_id_t vrf_id)
|
||||
{
|
||||
struct zebra_vrf *zvrf;
|
||||
struct zebra_ns *zns;
|
||||
|
||||
zvrf = vrf_info_lookup(vrf_id);
|
||||
if (!zvrf)
|
||||
return NULL;
|
||||
|
||||
zns = zvrf->zns;
|
||||
|
||||
if (afi >= AFI_MAX)
|
||||
return NULL;
|
||||
|
||||
@ -461,7 +457,8 @@ struct route_table *zebra_vrf_other_route_table(afi_t afi, uint32_t table_id,
|
||||
* so in all cases, it does not use specific table
|
||||
* so it is possible to configure tables in this VRF
|
||||
*/
|
||||
return zebra_ns_get_table(zns, zvrf, table_id, afi);
|
||||
return zebra_router_get_table(zvrf, table_id, afi,
|
||||
SAFI_UNICAST);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "srcdest_table.h"
|
||||
#include "vxlan.h"
|
||||
|
||||
#include "zebra/zebra_router.h"
|
||||
#include "zebra/zserv.h"
|
||||
#include "zebra/zebra_vrf.h"
|
||||
#include "zebra/zebra_mpls.h"
|
||||
@ -896,7 +897,7 @@ DEFPY (show_route_table,
|
||||
struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
|
||||
struct route_table *t;
|
||||
|
||||
t = zebra_ns_find_table(zvrf->zns, table, afi);
|
||||
t = zebra_router_find_table(zvrf, table, afi, SAFI_UNICAST);
|
||||
if (t)
|
||||
do_show_route_helper(vty, zvrf, t, afi, false, 0, false, false,
|
||||
0, 0, !!json);
|
||||
@ -925,7 +926,7 @@ DEFPY (show_route_table_vrf,
|
||||
VRF_GET_ID(vrf_id, vrf_name, !!json);
|
||||
zvrf = zebra_vrf_lookup_by_id(vrf_id);
|
||||
|
||||
t = zebra_ns_find_table(zvrf->zns, table, afi);
|
||||
t = zebra_router_find_table(zvrf, table, afi, SAFI_UNICAST);
|
||||
if (t)
|
||||
do_show_route_helper(vty, zvrf, t, afi, false, 0, false, false,
|
||||
0, 0, !!json);
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include <linux/neighbour.h>
|
||||
#endif
|
||||
|
||||
#include "zebra/zebra_router.h"
|
||||
#include "zebra/debug.h"
|
||||
#include "zebra/interface.h"
|
||||
#include "zebra/rib.h"
|
||||
@ -3643,15 +3644,12 @@ static void *zl3vni_alloc(void *p)
|
||||
*/
|
||||
static zebra_l3vni_t *zl3vni_lookup(vni_t vni)
|
||||
{
|
||||
struct zebra_ns *zns;
|
||||
zebra_l3vni_t tmp_l3vni;
|
||||
zebra_l3vni_t *zl3vni = NULL;
|
||||
|
||||
zns = zebra_ns_lookup(NS_DEFAULT);
|
||||
assert(zns);
|
||||
memset(&tmp_l3vni, 0, sizeof(zebra_l3vni_t));
|
||||
tmp_l3vni.vni = vni;
|
||||
zl3vni = hash_lookup(zns->l3vni_table, &tmp_l3vni);
|
||||
zl3vni = hash_lookup(zrouter.l3vni_table, &tmp_l3vni);
|
||||
|
||||
return zl3vni;
|
||||
}
|
||||
@ -3662,16 +3660,12 @@ static zebra_l3vni_t *zl3vni_lookup(vni_t vni)
|
||||
static zebra_l3vni_t *zl3vni_add(vni_t vni, vrf_id_t vrf_id)
|
||||
{
|
||||
zebra_l3vni_t tmp_zl3vni;
|
||||
struct zebra_ns *zns = NULL;
|
||||
zebra_l3vni_t *zl3vni = NULL;
|
||||
|
||||
zns = zebra_ns_lookup(NS_DEFAULT);
|
||||
assert(zns);
|
||||
|
||||
memset(&tmp_zl3vni, 0, sizeof(zebra_l3vni_t));
|
||||
tmp_zl3vni.vni = vni;
|
||||
|
||||
zl3vni = hash_get(zns->l3vni_table, &tmp_zl3vni, zl3vni_alloc);
|
||||
zl3vni = hash_get(zrouter.l3vni_table, &tmp_zl3vni, zl3vni_alloc);
|
||||
assert(zl3vni);
|
||||
|
||||
zl3vni->vrf_id = vrf_id;
|
||||
@ -3696,12 +3690,8 @@ static zebra_l3vni_t *zl3vni_add(vni_t vni, vrf_id_t vrf_id)
|
||||
*/
|
||||
static int zl3vni_del(zebra_l3vni_t *zl3vni)
|
||||
{
|
||||
struct zebra_ns *zns;
|
||||
zebra_l3vni_t *tmp_zl3vni;
|
||||
|
||||
zns = zebra_ns_lookup(NS_DEFAULT);
|
||||
assert(zns);
|
||||
|
||||
/* free the list of l2vnis */
|
||||
list_delete(&zl3vni->l2vnis);
|
||||
zl3vni->l2vnis = NULL;
|
||||
@ -3715,7 +3705,7 @@ static int zl3vni_del(zebra_l3vni_t *zl3vni)
|
||||
zl3vni->nh_table = NULL;
|
||||
|
||||
/* Free the VNI hash entry and allocated memory. */
|
||||
tmp_zl3vni = hash_release(zns->l3vni_table, zl3vni);
|
||||
tmp_zl3vni = hash_release(zrouter.l3vni_table, zl3vni);
|
||||
if (tmp_zl3vni)
|
||||
XFREE(MTYPE_ZL3VNI, tmp_zl3vni);
|
||||
|
||||
@ -4634,7 +4624,6 @@ void zebra_vxlan_print_rmacs_l3vni(struct vty *vty, vni_t l3vni, bool use_json)
|
||||
|
||||
void zebra_vxlan_print_rmacs_all_l3vni(struct vty *vty, bool use_json)
|
||||
{
|
||||
struct zebra_ns *zns = NULL;
|
||||
json_object *json = NULL;
|
||||
void *args[2];
|
||||
|
||||
@ -4644,19 +4633,12 @@ void zebra_vxlan_print_rmacs_all_l3vni(struct vty *vty, bool use_json)
|
||||
return;
|
||||
}
|
||||
|
||||
zns = zebra_ns_lookup(NS_DEFAULT);
|
||||
if (!zns) {
|
||||
if (use_json)
|
||||
vty_out(vty, "{}\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (use_json)
|
||||
json = json_object_new_object();
|
||||
|
||||
args[0] = vty;
|
||||
args[1] = json;
|
||||
hash_iterate(zns->l3vni_table,
|
||||
hash_iterate(zrouter.l3vni_table,
|
||||
(void (*)(struct hash_backet *,
|
||||
void *))zl3vni_print_rmac_hash_all_vni,
|
||||
args);
|
||||
@ -4759,7 +4741,6 @@ void zebra_vxlan_print_nh_l3vni(struct vty *vty, vni_t l3vni, bool use_json)
|
||||
|
||||
void zebra_vxlan_print_nh_all_l3vni(struct vty *vty, bool use_json)
|
||||
{
|
||||
struct zebra_ns *zns = NULL;
|
||||
json_object *json = NULL;
|
||||
void *args[2];
|
||||
|
||||
@ -4769,16 +4750,12 @@ void zebra_vxlan_print_nh_all_l3vni(struct vty *vty, bool use_json)
|
||||
return;
|
||||
}
|
||||
|
||||
zns = zebra_ns_lookup(NS_DEFAULT);
|
||||
if (!zns)
|
||||
return;
|
||||
|
||||
if (use_json)
|
||||
json = json_object_new_object();
|
||||
|
||||
args[0] = vty;
|
||||
args[1] = json;
|
||||
hash_iterate(zns->l3vni_table,
|
||||
hash_iterate(zrouter.l3vni_table,
|
||||
(void (*)(struct hash_backet *,
|
||||
void *))zl3vni_print_nh_hash_all_vni,
|
||||
args);
|
||||
@ -5273,21 +5250,16 @@ void zebra_vxlan_print_evpn(struct vty *vty, bool uj)
|
||||
int num_l3vnis = 0;
|
||||
int num_vnis = 0;
|
||||
json_object *json = NULL;
|
||||
struct zebra_ns *zns = NULL;
|
||||
struct zebra_vrf *zvrf = NULL;
|
||||
|
||||
if (!is_evpn_enabled())
|
||||
return;
|
||||
|
||||
zns = zebra_ns_lookup(NS_DEFAULT);
|
||||
if (!zns)
|
||||
return;
|
||||
|
||||
zvrf = vrf_info_lookup(VRF_DEFAULT);
|
||||
if (!zvrf)
|
||||
return;
|
||||
|
||||
num_l3vnis = hashcount(zns->l3vni_table);
|
||||
num_l3vnis = hashcount(zrouter.l3vni_table);
|
||||
num_l2vnis = hashcount(zvrf->vni_table);
|
||||
num_vnis = num_l2vnis + num_l3vnis;
|
||||
|
||||
@ -5319,17 +5291,11 @@ void zebra_vxlan_print_vnis(struct vty *vty, struct zebra_vrf *zvrf,
|
||||
bool use_json)
|
||||
{
|
||||
json_object *json = NULL;
|
||||
struct zebra_ns *zns = NULL;
|
||||
void *args[2];
|
||||
|
||||
if (!is_evpn_enabled())
|
||||
return;
|
||||
|
||||
zns = zebra_ns_lookup(NS_DEFAULT);
|
||||
if (!zns)
|
||||
return;
|
||||
|
||||
|
||||
if (use_json)
|
||||
json = json_object_new_object();
|
||||
else
|
||||
@ -5346,7 +5312,7 @@ void zebra_vxlan_print_vnis(struct vty *vty, struct zebra_vrf *zvrf,
|
||||
args);
|
||||
|
||||
/* Display all L3-VNIs */
|
||||
hash_iterate(zns->l3vni_table,
|
||||
hash_iterate(zrouter.l3vni_table,
|
||||
(void (*)(struct hash_backet *, void *))zl3vni_print_hash,
|
||||
args);
|
||||
|
||||
@ -7160,7 +7126,6 @@ void zebra_vxlan_advertise_all_vni(ZAPI_HANDLER_ARGS)
|
||||
{
|
||||
struct stream *s = NULL;
|
||||
int advertise = 0;
|
||||
struct zebra_ns *zns = NULL;
|
||||
enum vxlan_flood_control flood_ctrl;
|
||||
|
||||
if (zvrf_id(zvrf) != VRF_DEFAULT) {
|
||||
@ -7206,11 +7171,7 @@ void zebra_vxlan_advertise_all_vni(ZAPI_HANDLER_ARGS)
|
||||
hash_iterate(zvrf->vni_table, zvni_cleanup_all, zvrf);
|
||||
|
||||
/* cleanup all l3vnis */
|
||||
zns = zebra_ns_lookup(NS_DEFAULT);
|
||||
if (!zns)
|
||||
return;
|
||||
|
||||
hash_iterate(zns->l3vni_table, zl3vni_cleanup_all, NULL);
|
||||
hash_iterate(zrouter.l3vni_table, zl3vni_cleanup_all, NULL);
|
||||
}
|
||||
|
||||
stream_failure:
|
||||
@ -7249,14 +7210,14 @@ void zebra_vxlan_close_tables(struct zebra_vrf *zvrf)
|
||||
/* init the l3vni table */
|
||||
void zebra_vxlan_ns_init(struct zebra_ns *zns)
|
||||
{
|
||||
zns->l3vni_table = hash_create(l3vni_hash_keymake, l3vni_hash_cmp,
|
||||
zrouter.l3vni_table = hash_create(l3vni_hash_keymake, l3vni_hash_cmp,
|
||||
"Zebra VRF L3 VNI table");
|
||||
}
|
||||
|
||||
/* free l3vni table */
|
||||
void zebra_vxlan_ns_disable(struct zebra_ns *zns)
|
||||
{
|
||||
hash_free(zns->l3vni_table);
|
||||
hash_free(zrouter.l3vni_table);
|
||||
}
|
||||
|
||||
/* get the l3vni svi ifindex */
|
||||
|
Loading…
Reference in New Issue
Block a user