diff options
author | 2017-01-25 03:21:55 +0000 | |
---|---|---|
committer | 2017-01-25 03:21:55 +0000 | |
commit | a7fc929cc726993aebb55524baa4f3e1cd3fea3f (patch) | |
tree | af495bfebd47f1ca70e87679774a44cc97cdcc45 | |
parent | Provide defines for SSL_CTRL_SET_CURVES/SSL_CTRL_SET_CURVES_LIST for things (diff) | |
download | wireguard-openbsd-a7fc929cc726993aebb55524baa4f3e1cd3fea3f.tar.xz wireguard-openbsd-a7fc929cc726993aebb55524baa4f3e1cd3fea3f.zip |
Hopefully the last of the struct rib rototilling. Peer just points to a
struct rib and not rib_desc since the full descriptor is almost never needed.
This should now allow the update code to be changed.
-rw-r--r-- | usr.sbin/bgpd/rde.c | 51 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde.h | 11 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde_rib.c | 32 |
3 files changed, 52 insertions, 42 deletions
diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c index 1a1a19b41c5..37d98d7b7d9 100644 --- a/usr.sbin/bgpd/rde.c +++ b/usr.sbin/bgpd/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.360 2017/01/25 00:15:38 claudio Exp $ */ +/* $OpenBSD: rde.c,v 1.361 2017/01/25 03:21:55 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -630,7 +630,7 @@ rde_dispatch_imsg_parent(struct imsgbuf *ibuf) struct filter_rule *r; struct filter_set *s; struct nexthop *nh; - struct rib_desc *rib; + struct rib *rib; int n, fd; u_int16_t rid; @@ -724,23 +724,24 @@ rde_dispatch_imsg_parent(struct imsgbuf *ibuf) rib = rib_find(rn.name); if (rib == NULL) rib = rib_new(rn.name, rn.rtableid, rn.flags); - else if (rib->rib.rtableid != rn.rtableid || - (rib->rib.flags & F_RIB_HASNOFIB) != - (rib->rib.flags & F_RIB_HASNOFIB)) { + else if (rib->rtableid != rn.rtableid || + (rib->flags & F_RIB_HASNOFIB) != + (rib->flags & F_RIB_HASNOFIB)) { struct filter_head *in_rules; + struct rib_desc *ribd = rib_desc(rib); /* * Big hammer in the F_RIB_HASNOFIB case but * not often enough used to optimise it more. * Need to save the filters so that they're not * lost. */ - in_rules = rib->in_rules; - rib->in_rules = NULL; + in_rules = ribd->in_rules; + ribd->in_rules = NULL; rib_free(rib); rib = rib_new(rn.name, rn.rtableid, rn.flags); - rib->in_rules = in_rules; + ribd->in_rules = in_rules; } else - rib->state = RECONF_KEEP; + rib_desc(rib)->state = RECONF_KEEP; break; case IMSG_RECONF_FILTER: if (imsg.hdr.len - IMSG_HEADER_SIZE != @@ -757,17 +758,17 @@ rde_dispatch_imsg_parent(struct imsgbuf *ibuf) free(r); break; } - r->peer.ribid = rib->rib.id; + r->peer.ribid = rib->id; parent_set = &r->set; if (r->dir == DIR_IN) { - nr = rib->in_rules_tmp; + nr = rib_desc(rib)->in_rules_tmp; if (nr == NULL) { nr = calloc(1, sizeof(struct filter_head)); if (nr == NULL) fatal(NULL); TAILQ_INIT(nr); - rib->in_rules_tmp = nr; + rib_desc(rib)->in_rules_tmp = nr; } TAILQ_INSERT_TAIL(nr, r, entry); } else @@ -2331,7 +2332,7 @@ rde_dump_ctx_new(struct ctl_show_rib_request *req, pid_t pid, enum imsg_type type) { struct rde_dump_ctx *ctx; - struct rib_desc *rib; + struct rib *rib; struct rib_entry *re; u_int error; u_int8_t hostplen; @@ -2356,7 +2357,7 @@ rde_dump_ctx_new(struct ctl_show_rib_request *req, pid_t pid, ctx->req.pid = pid; ctx->req.type = type; ctx->ribctx.ctx_count = RDE_RUNNER_ROUNDS; - ctx->ribctx.ctx_rib = &rib->rib; + ctx->ribctx.ctx_rib = rib; switch (ctx->req.type) { case IMSG_CTL_SHOW_NETWORK: ctx->ribctx.ctx_upcall = network_dump_upcall; @@ -2384,9 +2385,9 @@ rde_dump_ctx_new(struct ctl_show_rib_request *req, pid_t pid, fatalx("rde_dump_ctx_new: unknown af"); } if (req->prefixlen == hostplen) - re = rib_lookup(&rib->rib, &req->prefix); + re = rib_lookup(rib, &req->prefix); else - re = rib_get(&rib->rib, &req->prefix, req->prefixlen); + re = rib_get(rib, &req->prefix, req->prefixlen); if (re) rde_dump_upcall(re, ctx); rde_dump_done(ctx); @@ -2414,7 +2415,7 @@ void rde_dump_mrt_new(struct mrt *mrt, pid_t pid, int fd) { struct rde_mrt_ctx *ctx; - struct rib_desc *rib; + struct rib *rib; if ((ctx = calloc(1, sizeof(*ctx))) == NULL) { log_warn("rde_dump_mrt_new"); @@ -2435,7 +2436,7 @@ rde_dump_mrt_new(struct mrt *mrt, pid_t pid, int fd) mrt_dump_v2_hdr(&ctx->mrt, conf, &peerlist); ctx->ribctx.ctx_count = RDE_RUNNER_ROUNDS; - ctx->ribctx.ctx_rib = &rib->rib; + ctx->ribctx.ctx_rib = rib; ctx->ribctx.ctx_upcall = mrt_dump_upcall; ctx->ribctx.ctx_done = mrt_done; ctx->ribctx.ctx_arg = &ctx->mrt; @@ -2548,7 +2549,7 @@ rde_generate_updates(struct rib *rib, struct prefix *new, struct prefix *old) LIST_FOREACH(peer, &peerlist, peer_l) { if (peer->conf.id == 0) continue; - if (&peer->rib->rib != rib) + if (peer->rib != rib) continue; if (peer->state != PEER_UP) continue; @@ -2563,7 +2564,7 @@ rde_up_dump_upcall(struct rib_entry *re, void *ptr) { struct rde_peer *peer = ptr; - if (re_rib(re) != &peer->rib->rib) + if (re_rib(re) != peer->rib) fatalx("King Bula: monstrous evil horror."); if (re->active == NULL) return; @@ -2820,8 +2821,8 @@ rde_reload_done(void) peer->reconf_out = 0; peer->reconf_rib = 0; if (peer->rib != rib_find(peer->conf.rib)) { - rib_dump(&peer->rib->rib, - rde_softreconfig_unload_peer, peer, AID_UNSPEC); + rib_dump(peer->rib, rde_softreconfig_unload_peer, peer, + AID_UNSPEC); peer->rib = rib_find(peer->conf.rib); if (peer->rib == NULL) fatalx("King Bula's peer met an unknown RIB"); @@ -2846,7 +2847,7 @@ rde_reload_done(void) switch (ribs[rid].state) { case RECONF_DELETE: - rib_free(&ribs[rid]); + rib_free(&ribs[rid].rib); break; case RECONF_KEEP: if (rde_filter_equal(ribs[rid].in_rules, @@ -2868,7 +2869,7 @@ rde_reload_done(void) } LIST_FOREACH(peer, &peerlist, peer_l) { if (peer->reconf_out) - rib_dump(&peer->rib->rib, rde_softreconfig_out, + rib_dump(peer->rib, rde_softreconfig_out, peer, AID_UNSPEC); else if (peer->reconf_rib) /* dump the full table to neighbors that changed rib */ @@ -3364,7 +3365,7 @@ peer_dump(u_int32_t id, u_int8_t aid) if (peer->conf.announce_type == ANNOUNCE_DEFAULT_ROUTE) up_generate_default(out_rules, peer, aid); else - rib_dump(&peer->rib->rib, rde_up_dump_upcall, peer, aid); + rib_dump(peer->rib, rde_up_dump_upcall, peer, aid); if (peer->capa.grestart.restart) up_generate_marker(peer, aid); } diff --git a/usr.sbin/bgpd/rde.h b/usr.sbin/bgpd/rde.h index a51637cebd0..cdf5ad2f6d4 100644 --- a/usr.sbin/bgpd/rde.h +++ b/usr.sbin/bgpd/rde.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.h,v 1.159 2017/01/25 00:15:38 claudio Exp $ */ +/* $OpenBSD: rde.h,v 1.160 2017/01/25 03:21:55 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> and @@ -76,7 +76,7 @@ struct rde_peer { u_int32_t up_nlricnt; u_int32_t up_wcnt; enum peer_state state; - struct rib_desc *rib; + struct rib *rib; u_int16_t short_as; u_int16_t mrt_idx; u_int8_t reconf_out; /* out filter changed */ @@ -427,9 +427,10 @@ int pt_prefix_cmp(const struct pt_entry *, const struct pt_entry *); extern u_int16_t rib_size; extern struct rib_desc *ribs; -struct rib_desc *rib_new(char *, u_int, u_int16_t); -struct rib_desc *rib_find(char *); -void rib_free(struct rib_desc *); +struct rib *rib_new(char *, u_int, u_int16_t); +struct rib *rib_find(char *); +struct rib_desc *rib_desc(struct rib *); +void rib_free(struct rib *); struct rib_entry *rib_get(struct rib *, struct bgpd_addr *, int); struct rib_entry *rib_lookup(struct rib *, struct bgpd_addr *); void rib_dump(struct rib *, void (*)(struct rib_entry *, void *), diff --git a/usr.sbin/bgpd/rde_rib.c b/usr.sbin/bgpd/rde_rib.c index 85d66398a2a..dce18137b8c 100644 --- a/usr.sbin/bgpd/rde_rib.c +++ b/usr.sbin/bgpd/rde_rib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_rib.c,v 1.152 2017/01/25 00:15:38 claudio Exp $ */ +/* $OpenBSD: rde_rib.c,v 1.153 2017/01/25 03:21:55 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> @@ -74,7 +74,7 @@ rib_tree(struct rib *rib) } /* RIB specific functions */ -struct rib_desc * +struct rib * rib_new(char *name, u_int rtableid, u_int16_t flags) { struct rib_desc *xribs; @@ -108,36 +108,43 @@ rib_new(char *name, u_int rtableid, u_int16_t flags) fatal(NULL); TAILQ_INIT(ribs[id].in_rules); - return (&ribs[id]); + return (&ribs[id].rib); } -struct rib_desc * +struct rib * rib_find(char *name) { u_int16_t id; if (name == NULL || *name == '\0') - return (&ribs[1]); /* no name returns the Loc-RIB */ + return (&ribs[1].rib); /* no name returns the Loc-RIB */ for (id = 0; id < rib_size; id++) { if (!strcmp(ribs[id].name, name)) - return (&ribs[id]); + return (&ribs[id].rib); } return (NULL); } +struct rib_desc * +rib_desc(struct rib *rib) +{ + return (&ribs[rib->id]); +} + void -rib_free(struct rib_desc *rib) +rib_free(struct rib *rib) { struct rib_context *ctx, *next; + struct rib_desc *rd; struct rib_entry *re, *xre; struct prefix *p, *np; /* abort pending rib_dumps */ for (ctx = LIST_FIRST(&rib_dump_h); ctx != NULL; ctx = next) { next = LIST_NEXT(ctx, entry); - if (ctx->ctx_rib == &rib->rib) { + if (ctx->ctx_rib == rib) { re = ctx->ctx_re; re_unlock(re); LIST_REMOVE(ctx, entry); @@ -148,8 +155,8 @@ rib_free(struct rib_desc *rib) } } - for (re = RB_MIN(rib_tree, rib_tree(&rib->rib)); re != NULL; re = xre) { - xre = RB_NEXT(rib_tree, rib_tree(&rib->rib), re); + for (re = RB_MIN(rib_tree, rib_tree(rib)); re != NULL; re = xre) { + xre = RB_NEXT(rib_tree, rib_tree(rib), re); /* * Removing the prefixes is tricky because the last one @@ -172,8 +179,9 @@ rib_free(struct rib_desc *rib) break; } } - filterlist_free(rib->in_rules_tmp); - filterlist_free(rib->in_rules); + rd = &ribs[rib->id]; + filterlist_free(rd->in_rules_tmp); + filterlist_free(rd->in_rules); bzero(rib, sizeof(struct rib_desc)); } |