diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2017-01-23 22:48:00 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2017-01-23 22:48:00 +0000 |
commit | 26ad5a12fb1e299d39afe98546de32532d0f80f4 (patch) | |
tree | 243f76e72c33977074e62f9b636ff72737e266c2 /usr.sbin/bgpd | |
parent | b7673da177d7b703d7726af6796735f57d70ccd6 (diff) |
Introduce a struct rib sitting between struct rib_desc and struct rib_tree.
This way the tree becomes a bit better decoupled.
Diffstat (limited to 'usr.sbin/bgpd')
-rw-r--r-- | usr.sbin/bgpd/rde.c | 49 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde.h | 33 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde_decide.c | 6 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde_rib.c | 55 |
4 files changed, 77 insertions, 66 deletions
diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c index 3b50fc64380..87872d15bdc 100644 --- a/usr.sbin/bgpd/rde.c +++ b/usr.sbin/bgpd/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.355 2017/01/23 12:25:19 claudio Exp $ */ +/* $OpenBSD: rde.c,v 1.356 2017/01/23 22:47:59 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -723,8 +723,8 @@ rde_dispatch_imsg_parent(struct imsgbuf *ibuf) if (rib == NULL) rib = rib_new(rn.name, rn.rtableid, rn.flags); else if (rib->rtableid != rn.rtableid || - (rib->flags & F_RIB_HASNOFIB) != - (rib->flags & F_RIB_HASNOFIB)) { + (rib->rib.flags & F_RIB_HASNOFIB) != + (rib->rib.flags & F_RIB_HASNOFIB)) { struct filter_head *in_rules; /* * Big hammer in the F_RIB_HASNOFIB case but @@ -755,7 +755,7 @@ rde_dispatch_imsg_parent(struct imsgbuf *ibuf) free(r); break; } - r->peer.ribid = rib->id; + r->peer.ribid = rib->rib.id; parent_set = &r->set; if (r->dir == DIR_IN) { nr = rib->in_rules_tmp; @@ -1298,7 +1298,7 @@ rde_update_update(struct rde_peer *peer, struct rde_aspath *asp, peer->prefix_rcvd_update++; /* add original path to the Adj-RIB-In */ if (peer->conf.softreconfig_in) - r += path_update(&ribs[0], peer, asp, prefix, prefixlen); + r += path_update(&ribs[0].rib, peer, asp, prefix, prefixlen); for (i = 1; i < rib_size; i++) { if (*ribs[i].name == '\0') @@ -1313,9 +1313,9 @@ rde_update_update(struct rde_peer *peer, struct rde_aspath *asp, if (action == ACTION_ALLOW) { rde_update_log("update", i, peer, &fasp->nexthop->exit_nexthop, prefix, prefixlen); - r += path_update(&ribs[i], peer, fasp, prefix, + r += path_update(&ribs[i].rib, peer, fasp, prefix, prefixlen); - } else if (prefix_remove(&ribs[i], peer, prefix, prefixlen, + } else if (prefix_remove(&ribs[i].rib, peer, prefix, prefixlen, 0)) { rde_update_log("filtered withdraw", i, peer, NULL, prefix, prefixlen); @@ -1345,7 +1345,7 @@ rde_update_withdraw(struct rde_peer *peer, struct bgpd_addr *prefix, for (i = rib_size - 1; ; i--) { if (*ribs[i].name == '\0') break; - if (prefix_remove(&ribs[i], peer, prefix, prefixlen, 0)) { + if (prefix_remove(&ribs[i].rib, peer, prefix, prefixlen, 0)) { rde_update_log("withdraw", i, peer, NULL, prefix, prefixlen); r++; @@ -2354,7 +2354,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; + ctx->ribctx.ctx_rib = &rib->rib; switch (ctx->req.type) { case IMSG_CTL_SHOW_NETWORK: ctx->ribctx.ctx_upcall = network_dump_upcall; @@ -2382,9 +2382,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, &req->prefix); + re = rib_lookup(&rib->rib, &req->prefix); else - re = rib_get(rib, &req->prefix, req->prefixlen); + re = rib_get(&rib->rib, &req->prefix, req->prefixlen); if (re) rde_dump_upcall(re, ctx); rde_dump_done(ctx); @@ -2433,7 +2433,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; + ctx->ribctx.ctx_rib = &rib->rib; ctx->ribctx.ctx_upcall = mrt_dump_upcall; ctx->ribctx.ctx_done = mrt_done; ctx->ribctx.ctx_arg = &ctx->mrt; @@ -2647,7 +2647,7 @@ 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_dump(&peer->rib->rib, rde_softreconfig_unload_peer, peer, AID_UNSPEC); peer->rib = rib_find(peer->conf.rib); if (peer->rib == NULL) @@ -2683,7 +2683,7 @@ rde_reload_done(void) ribs[rid].state = RECONF_RELOAD; /* FALLTHROUGH */ case RECONF_REINIT: - rib_dump(&ribs[0], rde_softreconfig_in, &ribs[rid], + rib_dump(&ribs[0].rib, rde_softreconfig_in, &ribs[rid], AID_UNSPEC); break; case RECONF_RELOAD: @@ -2695,7 +2695,7 @@ rde_reload_done(void) } LIST_FOREACH(peer, &peerlist, peer_l) { if (peer->reconf_out) - rib_dump(peer->rib, rde_softreconfig_out, + rib_dump(&peer->rib->rib, rde_softreconfig_out, peer, AID_UNSPEC); else if (peer->reconf_rib) /* dump the full table to neighbors that changed rib */ @@ -2757,14 +2757,15 @@ rde_softreconfig_in(struct rib_entry *re, void *ptr) /* nothing todo */ if (oa == ACTION_DENY && na == ACTION_ALLOW) { /* update Local-RIB */ - path_update(rib, peer, nasp, &addr, pt->prefixlen); + path_update(&rib->rib, peer, nasp, &addr, + pt->prefixlen); } else if (oa == ACTION_ALLOW && na == ACTION_DENY) { /* remove from Local-RIB */ - prefix_remove(rib, peer, &addr, pt->prefixlen, 0); + prefix_remove(&rib->rib, peer, &addr, pt->prefixlen, 0); } else if (oa == ACTION_ALLOW && na == ACTION_ALLOW) { if (path_compare(nasp, oasp) != 0) /* send update */ - path_update(rib, peer, nasp, &addr, + path_update(&rib->rib, peer, nasp, &addr, pt->prefixlen); } @@ -2867,7 +2868,7 @@ rde_up_dump_upcall(struct rib_entry *re, void *ptr) { struct rde_peer *peer = ptr; - if (re->ribid != peer->rib->id) + if (re->rib != &peer->rib->rib) fatalx("King Bula: monstrous evil horror."); if (re->active == NULL) return; @@ -2890,7 +2891,7 @@ rde_generate_updates(u_int16_t ribid, struct prefix *new, struct prefix *old) LIST_FOREACH(peer, &peerlist, peer_l) { if (peer->conf.id == 0) continue; - if (peer->rib->id != ribid) + if (peer->rib->rib.id != ribid) continue; if (peer->state != PEER_UP) continue; @@ -3361,7 +3362,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, rde_up_dump_upcall, peer, aid); + rib_dump(&peer->rib->rib, rde_up_dump_upcall, peer, aid); if (peer->capa.grestart.restart) up_generate_marker(peer, aid); } @@ -3492,7 +3493,7 @@ network_add(struct network_config *nc, int flagstatic) for (i = 1; i < rib_size; i++) { if (*ribs[i].name == '\0') break; - path_update(&ribs[i], peerself, asp, &nc->prefix, + path_update(&ribs[i].rib, peerself, asp, &nc->prefix, nc->prefixlen); } path_put(asp); @@ -3540,8 +3541,8 @@ network_delete(struct network_config *nc, int flagstatic) for (i = rib_size - 1; i > 0; i--) { if (*ribs[i].name == '\0') break; - prefix_remove(&ribs[i], peerself, &nc->prefix, nc->prefixlen, - flags); + prefix_remove(&ribs[i].rib, peerself, &nc->prefix, + nc->prefixlen, flags); } } diff --git a/usr.sbin/bgpd/rde.h b/usr.sbin/bgpd/rde.h index e2448a827b3..9de719ff344 100644 --- a/usr.sbin/bgpd/rde.h +++ b/usr.sbin/bgpd/rde.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.h,v 1.155 2017/01/23 13:08:47 claudio Exp $ */ +/* $OpenBSD: rde.h,v 1.156 2017/01/23 22:47:59 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> and @@ -38,11 +38,12 @@ enum peer_state { * How do we identify peers between the session handler and the rde? * Currently I assume that we can do that with the neighbor_ip... */ -struct rib_desc; LIST_HEAD(rde_peer_head, rde_peer); LIST_HEAD(aspath_head, rde_aspath); RB_HEAD(uptree_prefix, update_prefix); RB_HEAD(uptree_attr, update_attr); +struct rib_desc; +struct rib; RB_HEAD(rib_tree, rib_entry); TAILQ_HEAD(uplist_prefix, update_prefix); TAILQ_HEAD(uplist_attr, update_attr); @@ -267,7 +268,7 @@ struct pt_entry_vpn4 { struct rib_context { LIST_ENTRY(rib_context) entry; struct rib_entry *ctx_re; - struct rib_desc *ctx_rib; + struct rib *ctx_rib; void (*ctx_upcall)(struct rib_entry *, void *); void (*ctx_done)(void *); void (*ctx_wait)(void *); @@ -281,18 +282,22 @@ struct rib_entry { struct prefix_head prefix_h; struct prefix *active; /* for fast access */ struct pt_entry *prefix; - u_int16_t ribid; + struct rib *rib; u_int16_t flags; }; +struct rib { + struct rib_tree tree; + u_int16_t flags; + u_int16_t id; +}; + struct rib_desc { char name[PEER_DESCR_LEN]; - struct rib_tree rib; + struct rib rib; struct filter_head *in_rules; struct filter_head *in_rules_tmp; u_int rtableid; - u_int16_t flags; - u_int16_t id; enum reconf_action state; }; @@ -425,9 +430,9 @@ 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_entry *rib_get(struct rib_desc *, struct bgpd_addr *, int); -struct rib_entry *rib_lookup(struct rib_desc *, struct bgpd_addr *); -void rib_dump(struct rib_desc *, void (*)(struct rib_entry *, void *), +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 *), void *, u_int8_t); void rib_dump_r(struct rib_context *); void rib_dump_runner(void); @@ -435,7 +440,7 @@ int rib_dump_pending(void); void path_init(u_int32_t); void path_shutdown(void); -int path_update(struct rib_desc *, struct rde_peer *, +int path_update(struct rib *, struct rde_peer *, struct rde_aspath *, struct bgpd_addr *, int); int path_compare(struct rde_aspath *, struct rde_aspath *); struct rde_aspath *path_lookup(struct rde_aspath *, struct rde_peer *); @@ -448,12 +453,12 @@ struct rde_aspath *path_get(void); void path_put(struct rde_aspath *); #define PREFIX_SIZE(x) (((x) + 7) / 8 + 1) -struct prefix *prefix_get(struct rib_desc *, struct rde_peer *, +struct prefix *prefix_get(struct rib *, struct rde_peer *, struct bgpd_addr *, int, u_int32_t); -int prefix_add(struct rib_desc *, struct rde_aspath *, +int prefix_add(struct rib *, struct rde_aspath *, struct bgpd_addr *, int); void prefix_move(struct rde_aspath *, struct prefix *); -int prefix_remove(struct rib_desc *, struct rde_peer *, +int prefix_remove(struct rib *, struct rde_peer *, struct bgpd_addr *, int, u_int32_t); int prefix_write(u_char *, int, struct bgpd_addr *, u_int8_t); int prefix_writebuf(struct ibuf *, struct bgpd_addr *, u_int8_t); diff --git a/usr.sbin/bgpd/rde_decide.c b/usr.sbin/bgpd/rde_decide.c index f58d4b7d528..4127bc73a29 100644 --- a/usr.sbin/bgpd/rde_decide.c +++ b/usr.sbin/bgpd/rde_decide.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_decide.c,v 1.62 2012/07/04 20:43:26 claudio Exp $ */ +/* $OpenBSD: rde_decide.c,v 1.63 2017/01/23 22:47:59 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> @@ -287,9 +287,9 @@ prefix_evaluate(struct prefix *p, struct rib_entry *re) * but remember that xp may be NULL aka ineligible. * Additional decision may be made by the called functions. */ - rde_generate_updates(re->ribid, xp, re->active); + rde_generate_updates(re->rib->id, xp, re->active); if ((re->flags & F_RIB_NOFIB) == 0) - rde_send_kroute(xp, re->active, re->ribid); + rde_send_kroute(xp, re->active, re->rib->id); re->active = xp; if (xp != NULL) diff --git a/usr.sbin/bgpd/rde_rib.c b/usr.sbin/bgpd/rde_rib.c index 9492cc630d1..b470370ef72 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.147 2017/01/23 13:08:47 claudio Exp $ */ +/* $OpenBSD: rde_rib.c,v 1.148 2017/01/23 22:47:59 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> @@ -39,7 +39,7 @@ struct rib_desc *ribs; LIST_HEAD(, rib_context) rib_dump_h = LIST_HEAD_INITIALIZER(rib_dump_h); -struct rib_entry *rib_add(struct rib_desc *, struct bgpd_addr *, int); +struct rib_entry *rib_add(struct rib *, struct bgpd_addr *, int); int rib_compare(const struct rib_entry *, const struct rib_entry *); void rib_remove(struct rib_entry *); int rib_empty(struct rib_entry *); @@ -48,6 +48,11 @@ struct rib_entry *rib_restart(struct rib_context *); RB_PROTOTYPE(rib_tree, rib_entry, rib_e, rib_compare); RB_GENERATE(rib_tree, rib_entry, rib_e, rib_compare); +static inline struct rib_tree * +rib_tree(struct rib *rib) +{ + return (&rib->tree); +} /* RIB specific functions */ struct rib_desc * @@ -73,10 +78,10 @@ rib_new(char *name, u_int rtableid, u_int16_t flags) bzero(&ribs[id], sizeof(struct rib_desc)); strlcpy(ribs[id].name, name, sizeof(ribs[id].name)); - RB_INIT(&ribs[id].rib); + RB_INIT(rib_tree(&ribs[id].rib)); ribs[id].state = RECONF_REINIT; - ribs[id].id = id; - ribs[id].flags = flags; + ribs[id].rib.id = id; + ribs[id].rib.flags = flags; ribs[id].rtableid = rtableid; ribs[id].in_rules = calloc(1, sizeof(struct filter_head)); @@ -113,7 +118,7 @@ rib_free(struct rib_desc *rib) /* 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) { + if (ctx->ctx_rib == &rib->rib) { re = ctx->ctx_re; re->flags &= ~F_RIB_ENTRYLOCK; LIST_REMOVE(ctx, entry); @@ -124,8 +129,8 @@ rib_free(struct rib_desc *rib) } } - for (re = RB_MIN(rib_tree, &rib->rib); re != NULL; re = xre) { - xre = RB_NEXT(rib_tree, &rib->rib, re); + for (re = RB_MIN(rib_tree, rib_tree(&rib->rib)); re != NULL; re = xre) { + xre = RB_NEXT(rib_tree, rib_tree(&rib->rib), re); /* * Removing the prefixes is tricky because the last one @@ -160,7 +165,7 @@ rib_compare(const struct rib_entry *a, const struct rib_entry *b) } struct rib_entry * -rib_get(struct rib_desc *rib, struct bgpd_addr *prefix, int prefixlen) +rib_get(struct rib *rib, struct bgpd_addr *prefix, int prefixlen) { struct rib_entry xre; struct pt_entry *pte; @@ -169,11 +174,11 @@ rib_get(struct rib_desc *rib, struct bgpd_addr *prefix, int prefixlen) bzero(&xre, sizeof(xre)); xre.prefix = pte; - return (RB_FIND(rib_tree, &rib->rib, &xre)); + return (RB_FIND(rib_tree, rib_tree(rib), &xre)); } struct rib_entry * -rib_lookup(struct rib_desc *rib, struct bgpd_addr *addr) +rib_lookup(struct rib *rib, struct bgpd_addr *addr) { struct rib_entry *re; int i; @@ -202,7 +207,7 @@ rib_lookup(struct rib_desc *rib, struct bgpd_addr *addr) struct rib_entry * -rib_add(struct rib_desc *rib, struct bgpd_addr *prefix, int prefixlen) +rib_add(struct rib *rib, struct bgpd_addr *prefix, int prefixlen) { struct pt_entry *pte; struct rib_entry *re; @@ -216,10 +221,10 @@ rib_add(struct rib_desc *rib, struct bgpd_addr *prefix, int prefixlen) LIST_INIT(&re->prefix_h); re->prefix = pte; + re->rib = rib; re->flags = rib->flags; - re->ribid = rib->id; - if (RB_INSERT(rib_tree, &rib->rib, re) != NULL) { + if (RB_INSERT(rib_tree, rib_tree(rib), re) != NULL) { log_warnx("rib_add: insert failed"); free(re); return (NULL); @@ -246,7 +251,7 @@ rib_remove(struct rib_entry *re) if (pt_empty(re->prefix)) pt_remove(re->prefix); - if (RB_REMOVE(rib_tree, &ribs[re->ribid].rib, re) == NULL) + if (RB_REMOVE(rib_tree, rib_tree(re->rib), re) == NULL) log_warnx("rib_remove: remove failed."); free(re); @@ -260,7 +265,7 @@ rib_empty(struct rib_entry *re) } void -rib_dump(struct rib_desc *rib, void (*upcall)(struct rib_entry *, void *), +rib_dump(struct rib *rib, void (*upcall)(struct rib_entry *, void *), void *arg, u_int8_t aid) { struct rib_context *ctx; @@ -281,7 +286,7 @@ rib_dump_r(struct rib_context *ctx) unsigned int i; if (ctx->ctx_re == NULL) { - re = RB_MIN(rib_tree, &ctx->ctx_rib->rib); + re = RB_MIN(rib_tree, rib_tree(ctx->ctx_rib)); LIST_INSERT_HEAD(&rib_dump_h, ctx, entry); } else re = rib_restart(ctx); @@ -393,7 +398,7 @@ path_shutdown(void) } int -path_update(struct rib_desc *rib, struct rde_peer *peer, struct rde_aspath *nasp, +path_update(struct rib *rib, struct rde_peer *peer, struct rde_aspath *nasp, struct bgpd_addr *prefix, int prefixlen) { struct rde_aspath *asp; @@ -542,7 +547,7 @@ path_remove_stale(struct rde_aspath *asp, u_int8_t aid) } /* only count Adj-RIB-In */ - if (p->rib->ribid == 0) + if (p->rib->rib == &ribs[0].rib) rprefixes++; prefix_destroy(p); @@ -677,7 +682,7 @@ static void prefix_unlink(struct prefix *); * search for specified prefix of a peer. Returns NULL if not found. */ struct prefix * -prefix_get(struct rib_desc *rib, struct rde_peer *peer, struct bgpd_addr *prefix, +prefix_get(struct rib *rib, struct rde_peer *peer, struct bgpd_addr *prefix, int prefixlen, u_int32_t flags) { struct rib_entry *re; @@ -692,7 +697,7 @@ prefix_get(struct rib_desc *rib, struct rde_peer *peer, struct bgpd_addr *prefix * Adds or updates a prefix. */ int -prefix_add(struct rib_desc *rib, struct rde_aspath *asp, struct bgpd_addr *prefix, +prefix_add(struct rib *rib, struct rde_aspath *asp, struct bgpd_addr *prefix, int prefixlen) { @@ -779,7 +784,7 @@ prefix_move(struct rde_aspath *asp, struct prefix *p) * pt_entry -- become empty remove them too. */ int -prefix_remove(struct rib_desc *rib, struct rde_peer *peer, struct bgpd_addr *prefix, +prefix_remove(struct rib *rib, struct rde_peer *peer, struct bgpd_addr *prefix, int prefixlen, u_int32_t flags) { struct prefix *p; @@ -899,7 +904,7 @@ prefix_updateall(struct rde_aspath *asp, enum nexthop_state state, /* * skip non local-RIBs or RIBs that are flagged as noeval. */ - if (p->rib->flags & F_RIB_NOEVALUATE) + if (p->rib->rib->flags & F_RIB_NOEVALUATE) continue; if (oldstate == state && state == NEXTHOP_REACH) { @@ -909,9 +914,9 @@ prefix_updateall(struct rde_aspath *asp, enum nexthop_state state, * or other internal infos. This will not change * the routing decision so shortcut here. */ - if ((p->rib->flags & F_RIB_NOFIB) == 0 && + if ((p->rib->rib->flags & F_RIB_NOFIB) == 0 && p == p->rib->active) - rde_send_kroute(p, NULL, p->rib->ribid); + rde_send_kroute(p, NULL, p->rib->rib->id); continue; } |