Skip to content

Commit

Permalink
zebra: Start breakup of zns into zrouter and zns
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
donaldsharp committed Oct 24, 2018
1 parent 82d6d6e commit 8927291
Show file tree
Hide file tree
Showing 11 changed files with 278 additions and 228 deletions.
6 changes: 5 additions & 1 deletion zebra/main.c
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -418,7 +422,7 @@ int main(int argc, char **argv)

/* RNH init */
zebra_rnh_init();

/* Error init */
zebra_error_init();

Expand Down
2 changes: 2 additions & 0 deletions zebra/subdir.am
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down
123 changes: 0 additions & 123 deletions zebra/zebra_ns.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand Down
25 changes: 0 additions & 25 deletions zebra/zebra_ns.h
Expand Up @@ -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];
Expand All @@ -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;
Expand All @@ -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
5 changes: 3 additions & 2 deletions zebra/zebra_rib.c
Expand Up @@ -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"
Expand Down Expand Up @@ -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'. */
Expand Down Expand Up @@ -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;
}
Expand Down
13 changes: 6 additions & 7 deletions zebra/zebra_rnh.c
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand Down

0 comments on commit 8927291

Please sign in to comment.