diff options
-rw-r--r-- | usr.sbin/bgpd/bgpd.c | 24 | ||||
-rw-r--r-- | usr.sbin/bgpd/bgpd.h | 36 | ||||
-rw-r--r-- | usr.sbin/bgpd/config.c | 73 | ||||
-rw-r--r-- | usr.sbin/bgpd/kroute.c | 18 | ||||
-rw-r--r-- | usr.sbin/bgpd/mrt.c | 6 | ||||
-rw-r--r-- | usr.sbin/bgpd/parse.y | 41 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde.c | 57 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde.h | 14 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde_rib.c | 9 | ||||
-rw-r--r-- | usr.sbin/bgpd/session.c | 41 | ||||
-rw-r--r-- | usr.sbin/bgpd/session.h | 4 |
11 files changed, 180 insertions, 143 deletions
diff --git a/usr.sbin/bgpd/bgpd.c b/usr.sbin/bgpd/bgpd.c index dd2ed292895..1dd968af069 100644 --- a/usr.sbin/bgpd/bgpd.c +++ b/usr.sbin/bgpd/bgpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.c,v 1.212 2019/02/14 14:34:31 claudio Exp $ */ +/* $OpenBSD: bgpd.c,v 1.213 2019/03/07 07:42:36 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -101,6 +101,7 @@ main(int argc, char *argv[]) { struct bgpd_config *conf; struct peer *peer_l, *p; + struct rde_rib *rr; struct pollfd pfd[POLL_MAX]; time_t timeout; pid_t se_pid = 0, rde_pid = 0, pid; @@ -124,7 +125,6 @@ main(int argc, char *argv[]) if (saved_argv0 == NULL) saved_argv0 = "bgpd"; - conf = new_config(); peer_l = NULL; while ((ch = getopt(argc, argv, "cdD:f:nRSv")) != -1) { @@ -169,6 +169,7 @@ main(int argc, char *argv[]) usage(); if (cmd_opts & BGPD_OPT_NOACTION) { + conf = new_config(); if (parse_config(conffile, conf, &peer_l)) exit(1); @@ -177,6 +178,16 @@ main(int argc, char *argv[]) conf->filters, conf->mrt, &conf->l3vpns); else fprintf(stderr, "configuration OK\n"); + + while ((p = peer_l) != NULL) { + peer_l = p->next; + free(p); + } + while ((rr = SIMPLEQ_FIRST(&ribnames)) != NULL) { + SIMPLEQ_REMOVE_HEAD(&ribnames, entry); + free(rr); + } + free_config(conf); exit(0); } @@ -249,6 +260,7 @@ BROKEN if (pledge("stdio rpath wpath cpath fattr unix route recvfd sendfd", if (imsg_send_sockets(ibuf_se, ibuf_rde)) fatal("could not establish imsg links"); + conf = new_config(); quit = reconfigure(conffile, conf, &peer_l); if (pftable_clear_all() != 0) quit = 1; @@ -337,17 +349,23 @@ BROKEN if (pledge("stdio rpath wpath cpath fattr unix route recvfd sendfd", msgbuf_clear(&ibuf_se->w); close(ibuf_se->fd); free(ibuf_se); + ibuf_se = NULL; } if (ibuf_rde) { msgbuf_clear(&ibuf_rde->w); close(ibuf_rde->fd); free(ibuf_rde); + ibuf_rde = NULL; } while ((p = peer_l) != NULL) { peer_l = p->next; free(p); } + while ((rr = SIMPLEQ_FIRST(&ribnames)) != NULL) { + SIMPLEQ_REMOVE_HEAD(&ribnames, entry); + free(rr); + } carp_demote_shutdown(); kr_shutdown(conf->fib_priority, conf->default_tableid); @@ -895,6 +913,8 @@ send_imsg_session(int type, pid_t pid, void *data, u_int16_t datalen) int send_network(int type, struct network_config *net, struct filter_set_head *h) { + if (quit) + return (0); if (imsg_compose(ibuf_rde, type, 0, 0, -1, net, sizeof(struct network_config)) == -1) return (-1); diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h index b26f0c62248..a8480fbf88a 100644 --- a/usr.sbin/bgpd/bgpd.h +++ b/usr.sbin/bgpd/bgpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.h,v 1.376 2019/02/27 04:31:56 claudio Exp $ */ +/* $OpenBSD: bgpd.h,v 1.377 2019/03/07 07:42:36 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -1160,14 +1160,18 @@ int control_imsg_relay(struct imsg *); /* config.c */ struct bgpd_config *new_config(void); -void free_config(struct bgpd_config *); -void free_prefixsets(struct prefixset_head *); -void free_prefixtree(struct prefixset_tree *); -void filterlist_free(struct filter_head *); -int host(const char *, struct bgpd_addr *, u_int8_t *); -void copy_filterset(struct filter_set_head *, struct filter_set_head *); -void expand_networks(struct bgpd_config *); -int prefixset_cmp(struct prefixset_item *, struct prefixset_item *); +void copy_config(struct bgpd_config *, struct bgpd_config *); +void free_config(struct bgpd_config *); +void free_prefixsets(struct prefixset_head *); +void free_rde_prefixsets(struct rde_prefixset_head *); +void free_prefixtree(struct prefixset_tree *); +void filterlist_free(struct filter_head *); +int host(const char *, struct bgpd_addr *, u_int8_t *); +u_int32_t get_bgpid(void); +void copy_filterset(struct filter_set_head *, + struct filter_set_head *); +void expand_networks(struct bgpd_config *); +int prefixset_cmp(struct prefixset_item *, struct prefixset_item *); RB_PROTOTYPE(prefixset_tree, prefixset_item, entry, prefixset_cmp); /* kroute.c */ @@ -1213,7 +1217,7 @@ time_t mrt_timeout(struct mrt_head *); void mrt_reconfigure(struct mrt_head *); void mrt_handler(struct mrt_head *); struct mrt *mrt_get(struct mrt_head *, struct mrt *); -int mrt_mergeconfig(struct mrt_head *, struct mrt_head *); +void mrt_mergeconfig(struct mrt_head *, struct mrt_head *); /* name2id.c */ u_int16_t rib_name2id(const char *); @@ -1265,6 +1269,18 @@ void *set_match(const struct set_table *, u_int32_t); int set_equal(const struct set_table *, const struct set_table *); +/* rde_trie.c */ +int trie_add(struct trie_head *, struct bgpd_addr *, u_int8_t, u_int8_t, + u_int8_t); +int trie_roa_add(struct trie_head *, struct bgpd_addr *, u_int8_t, + struct set_table *); +void trie_free(struct trie_head *); +int trie_match(struct trie_head *, struct bgpd_addr *, u_int8_t, int); +int trie_roa_check(struct trie_head *, struct bgpd_addr *, u_int8_t, + u_int32_t); +void trie_dump(struct trie_head *); +int trie_equal(struct trie_head *, struct trie_head *); + /* util.c */ const char *log_addr(const struct bgpd_addr *); const char *log_in6addr(const struct in6_addr *); diff --git a/usr.sbin/bgpd/config.c b/usr.sbin/bgpd/config.c index 25deaac272e..ca2ec1b850e 100644 --- a/usr.sbin/bgpd/config.c +++ b/usr.sbin/bgpd/config.c @@ -1,4 +1,4 @@ -/* $OpenBSD: config.c,v 1.84 2019/02/27 04:31:56 claudio Exp $ */ +/* $OpenBSD: config.c,v 1.85 2019/03/07 07:42:36 claudio Exp $ */ /* * Copyright (c) 2003, 2004, 2005 Henning Brauer <henning@openbsd.org> @@ -31,7 +31,6 @@ #include "session.h" #include "log.h" -u_int32_t get_bgpid(void); int host_ip(const char *, struct bgpd_addr *, u_int8_t *); void free_networks(struct network_head *); void free_l3vpns(struct l3vpn_head *); @@ -40,24 +39,10 @@ struct bgpd_config * new_config(void) { struct bgpd_config *conf; - u_int rdomid; if ((conf = calloc(1, sizeof(struct bgpd_config))) == NULL) fatal(NULL); - conf->min_holdtime = MIN_HOLDTIME; - conf->bgpid = get_bgpid(); - conf->fib_priority = RTP_BGP; - conf->default_tableid = getrtable(); - ktable_exists(conf->default_tableid, &rdomid); - if (rdomid != conf->default_tableid) - fatalx("current routing table %u is not a routing domain", - conf->default_tableid); - - if (asprintf(&conf->csock, "%s.%d", SOCKET_NAME, - conf->default_tableid) == -1) - fatal(NULL); - if ((conf->as_sets = calloc(1, sizeof(struct as_set_head))) == NULL) fatal(NULL); if ((conf->filters = calloc(1, sizeof(struct filter_head))) == NULL) @@ -73,6 +58,8 @@ new_config(void) SIMPLEQ_INIT(&conf->l3vpns); SIMPLEQ_INIT(&conf->prefixsets); SIMPLEQ_INIT(&conf->originsets); + SIMPLEQ_INIT(&conf->rde_prefixsets); + SIMPLEQ_INIT(&conf->rde_originsets); RB_INIT(&conf->roa); SIMPLEQ_INIT(conf->as_sets); @@ -84,6 +71,22 @@ new_config(void) } void +copy_config(struct bgpd_config *to, struct bgpd_config *from) +{ + to->flags = from->flags; + to->log = from->log; + to->default_tableid = from->default_tableid; + to->bgpid = from->bgpid; + to->clusterid = from->clusterid; + to->as = from->as; + to->short_as = from->short_as; + to->holdtime = from->holdtime; + to->min_holdtime = from->min_holdtime; + to->connectretry = from->connectretry; + to->fib_priority = from->fib_priority; +} + +void free_networks(struct network_head *networks) { struct network *n; @@ -123,6 +126,22 @@ free_prefixsets(struct prefixset_head *psh) } void +free_rde_prefixsets(struct rde_prefixset_head *psh) +{ + struct rde_prefixset *ps; + + if (psh == NULL) + return; + + while (!SIMPLEQ_EMPTY(psh)) { + ps = SIMPLEQ_FIRST(psh); + trie_free(&ps->th); + SIMPLEQ_REMOVE_HEAD(psh, entry); + free(ps); + } +} + +void free_prefixtree(struct prefixset_tree *p) { struct prefixset_item *psi, *npsi; @@ -145,6 +164,8 @@ free_config(struct bgpd_config *conf) filterlist_free(conf->filters); free_prefixsets(&conf->prefixsets); free_prefixsets(&conf->originsets); + free_rde_prefixsets(&conf->rde_prefixsets); + free_rde_prefixsets(&conf->rde_originsets); free_prefixtree(&conf->roa); as_sets_free(conf->as_sets); @@ -166,7 +187,7 @@ free_config(struct bgpd_config *conf) free(conf); } -int +void merge_config(struct bgpd_config *xconf, struct bgpd_config *conf, struct peer *peer_l) { @@ -176,11 +197,6 @@ merge_config(struct bgpd_config *xconf, struct bgpd_config *conf, /* * merge the freshly parsed conf into the running xconf */ - if (!conf->as) { - log_warnx("configuration error: AS not given"); - return (1); - } - if ((conf->flags & BGPD_FLAG_REFLECTOR) && conf->clusterid == 0) conf->clusterid = conf->bgpid; @@ -194,16 +210,7 @@ merge_config(struct bgpd_config *xconf, struct bgpd_config *conf, } /* take over the easy config changes */ - xconf->flags = conf->flags; - xconf->log = conf->log; - xconf->bgpid = conf->bgpid; - xconf->clusterid = conf->clusterid; - xconf->as = conf->as; - xconf->short_as = conf->short_as; - xconf->holdtime = conf->holdtime; - xconf->min_holdtime = conf->min_holdtime; - xconf->connectretry = conf->connectretry; - xconf->fib_priority = conf->fib_priority; + copy_config(xconf, conf); /* clear old control sockets and use new */ free(xconf->csock); @@ -292,8 +299,6 @@ merge_config(struct bgpd_config *xconf, struct bgpd_config *conf, /* conf is merged so free it */ free_config(conf); - - return (0); } u_int32_t diff --git a/usr.sbin/bgpd/kroute.c b/usr.sbin/bgpd/kroute.c index 7332b05173f..0babd7377cb 100644 --- a/usr.sbin/bgpd/kroute.c +++ b/usr.sbin/bgpd/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.234 2019/03/01 09:24:56 claudio Exp $ */ +/* $OpenBSD: kroute.c,v 1.235 2019/03/07 07:42:36 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -112,6 +112,7 @@ int krVPN6_delete(struct ktable *, struct kroute_full *, u_int8_t); void kr_net_delete(struct network *); int kr_net_match(struct ktable *, struct network_config *, u_int16_t); struct network *kr_net_find(struct ktable *, struct network *); +void kr_net_clear(struct ktable *); void kr_redistribute(int, struct ktable *, struct kroute *); void kr_redistribute6(int, struct ktable *, struct kroute6 *); struct kroute_full *kr_tofull(struct kroute *); @@ -353,6 +354,7 @@ ktable_destroy(struct ktable *kt, u_int8_t fib_prio) knexthop_clear(kt); kroute_clear(kt); kroute6_clear(kt); + kr_net_clear(kt); krt[kt->rtableid] = NULL; free(kt); @@ -855,6 +857,7 @@ kr_shutdown(u_int8_t fib_prio, u_int rdomain) for (i = krt_size; i > 0; i--) ktable_free(i - 1, fib_prio); kif_clear(rdomain); + free(krt); } void @@ -1360,6 +1363,19 @@ kr_net_reload(u_int rtableid, u_int64_t rd, struct network_head *nh) } void +kr_net_clear(struct ktable *kt) +{ + struct network *n, *xn; + + TAILQ_FOREACH_SAFE(n, &kt->krn, entry, xn) { + TAILQ_REMOVE(&kt->krn, n, entry); + if (n->net.type == NETWORK_DEFAULT) + kr_net_redist_del(kt, &n->net, 0); + kr_net_delete(n); + } +} + +void kr_redistribute(int type, struct ktable *kt, struct kroute *kr) { struct network_config net; diff --git a/usr.sbin/bgpd/mrt.c b/usr.sbin/bgpd/mrt.c index ae7018eb8ef..8a549d2957c 100644 --- a/usr.sbin/bgpd/mrt.c +++ b/usr.sbin/bgpd/mrt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mrt.c,v 1.93 2019/02/27 04:31:56 claudio Exp $ */ +/* $OpenBSD: mrt.c,v 1.94 2019/03/07 07:42:36 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> @@ -995,7 +995,7 @@ mrt_get(struct mrt_head *c, struct mrt *m) return (NULL); } -int +void mrt_mergeconfig(struct mrt_head *xconf, struct mrt_head *nconf) { struct mrt *m, *xm; @@ -1031,6 +1031,4 @@ mrt_mergeconfig(struct mrt_head *xconf, struct mrt_head *nconf) LIST_REMOVE(m, entry); free(m); } - - return (0); } diff --git a/usr.sbin/bgpd/parse.y b/usr.sbin/bgpd/parse.y index dabb087f981..b1b95be3445 100644 --- a/usr.sbin/bgpd/parse.y +++ b/usr.sbin/bgpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.381 2019/02/27 04:16:02 claudio Exp $ */ +/* $OpenBSD: parse.y,v 1.382 2019/03/07 07:42:36 claudio Exp $ */ /* * Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -3242,6 +3242,24 @@ popfile(void) return (file ? 0 : EOF); } +static void +init_config(struct bgpd_config *c) +{ + u_int rdomid; + + c->min_holdtime = MIN_HOLDTIME; + c->bgpid = get_bgpid(); + c->fib_priority = RTP_BGP; + c->default_tableid = getrtable(); + ktable_exists(c->default_tableid, &rdomid); + if (rdomid != c->default_tableid) + fatalx("current routing table %u is not a routing domain", + c->default_tableid); + + if (asprintf(&c->csock, "%s.%d", SOCKET_NAME, c->default_tableid) == -1) + fatal(NULL); +} + int parse_config(char *filename, struct bgpd_config *xconf, struct peer **xpeers) { @@ -3252,6 +3270,7 @@ parse_config(char *filename, struct bgpd_config *xconf, struct peer **xpeers) int errors = 0; conf = new_config(); + init_config(conf); if ((filter_l = calloc(1, sizeof(struct filter_head))) == NULL) fatal(NULL); @@ -3277,10 +3296,8 @@ parse_config(char *filename, struct bgpd_config *xconf, struct peer **xpeers) F_RIB_NOFIB | F_RIB_NOEVALUATE); add_rib("Loc-RIB", conf->default_tableid, F_RIB_LOCAL); - if ((file = pushfile(filename, 1)) == NULL) { - free(conf); - return (-1); - } + if ((file = pushfile(filename, 1)) == NULL) + goto errors; topfile = file; yyparse(); @@ -3309,7 +3326,13 @@ parse_config(char *filename, struct bgpd_config *xconf, struct peer **xpeers) } } + if (!conf->as) { + log_warnx("configuration error: AS not given"); + errors++; + } + if (errors) { +errors: for (p = peer_l; p != NULL; p = pnext) { pnext = p->next; free(p); @@ -3325,6 +3348,7 @@ parse_config(char *filename, struct bgpd_config *xconf, struct peer **xpeers) filterlist_free(groupfilter_l); free_config(conf); + return -1; } else { /* * Concatenate filter list and static group and peer filtersets @@ -3337,8 +3361,8 @@ parse_config(char *filename, struct bgpd_config *xconf, struct peer **xpeers) optimize_filters(conf->filters); - errors += mrt_mergeconfig(xconf->mrt, conf->mrt); - errors += merge_config(xconf, conf, peer_l); + mrt_mergeconfig(xconf->mrt, conf->mrt); + merge_config(xconf, conf, peer_l); *xpeers = peer_l; for (p = peer_l_old; p != NULL; p = pnext) { @@ -3349,9 +3373,8 @@ parse_config(char *filename, struct bgpd_config *xconf, struct peer **xpeers) free(filter_l); free(peerfilter_l); free(groupfilter_l); + return 0; } - - return (errors ? -1 : 0); } int diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c index 06b64e44f02..24fff9c0340 100644 --- a/usr.sbin/bgpd/rde.c +++ b/usr.sbin/bgpd/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.464 2019/02/27 04:31:56 claudio Exp $ */ +/* $OpenBSD: rde.c,v 1.465 2019/03/07 07:42:36 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -86,7 +86,6 @@ int rde_update_queue_pending(void); void rde_update_queue_runner(void); void rde_update6_queue_runner(u_int8_t); struct rde_prefixset *rde_find_prefixset(char *, struct rde_prefixset_head *); -void rde_free_prefixsets(struct rde_prefixset_head *); void rde_mark_prefixsets_dirty(struct rde_prefixset_head *, struct rde_prefixset_head *); u_int8_t rde_roa_validity(struct rde_prefixset *, @@ -232,8 +231,7 @@ rde_main(int debug, int verbose) fatal(NULL); SIMPLEQ_INIT(l3vpns_l); - if ((conf = calloc(1, sizeof(struct bgpd_config))) == NULL) - fatal(NULL); + conf = new_config(); log_info("route decision engine ready"); while (rde_quit == 0) { @@ -324,6 +322,9 @@ rde_main(int debug, int verbose) if (debug) rde_shutdown(); + free_config(conf); + free(pfd); + /* close pipes */ if (ibuf_se) { msgbuf_clear(&ibuf_se->w); @@ -346,7 +347,6 @@ rde_main(int debug, int verbose) free(mctx); } - log_info("route decision engine exiting"); exit(0); } @@ -768,18 +768,14 @@ rde_dispatch_imsg_parent(struct imsgbuf *ibuf) if (newdomains == NULL) fatal(NULL); SIMPLEQ_INIT(newdomains); - if ((nconf = malloc(sizeof(struct bgpd_config))) == - NULL) - fatal(NULL); - memcpy(nconf, imsg.data, sizeof(struct bgpd_config)); + nconf = new_config(); + copy_config(nconf, imsg.data); + for (rid = 0; rid < rib_size; rid++) { if (!rib_valid(rid)) continue; ribs[rid].state = RECONF_DELETE; } - SIMPLEQ_INIT(&nconf->rde_prefixsets); - SIMPLEQ_INIT(&nconf->rde_originsets); - memset(&nconf->rde_roa, 0, sizeof(nconf->rde_roa)); break; case IMSG_RECONF_RIB: if (imsg.hdr.len - IMSG_HEADER_SIZE != @@ -2903,15 +2899,12 @@ rde_reload_done(void) roa_old = conf->rde_roa; as_sets_old = conf->as_sets; - memcpy(conf, nconf, sizeof(struct bgpd_config)); - conf->listen_addrs = NULL; - conf->csock = NULL; - conf->rcsock = NULL; + copy_config(conf, nconf); SIMPLEQ_INIT(&conf->rde_prefixsets); SIMPLEQ_INIT(&conf->rde_originsets); SIMPLEQ_CONCAT(&conf->rde_prefixsets, &nconf->rde_prefixsets); SIMPLEQ_CONCAT(&conf->rde_originsets, &nconf->rde_originsets); - free(nconf); + free_config(nconf); nconf = NULL; /* sync peerself with conf */ @@ -3127,8 +3120,8 @@ rde_softreconfig_done(void) ribs[rid].state = RECONF_NONE; } - rde_free_prefixsets(&prefixsets_old); - rde_free_prefixsets(&originsets_old); + free_rde_prefixsets(&prefixsets_old); + free_rde_prefixsets(&originsets_old); as_sets_free(as_sets_old); as_sets_old = NULL; @@ -3925,6 +3918,7 @@ network_flush_upcall(struct rib_entry *re, void *ptr) void rde_shutdown(void) { + struct l3vpn *vpn; struct rde_peer *p; u_int32_t i; @@ -3945,6 +3939,15 @@ rde_shutdown(void) filterlist_free(out_rules); filterlist_free(out_rules_tmp); + /* kill the VPN configs */ + while ((vpn = SIMPLEQ_FIRST(l3vpns_l)) != NULL) { + SIMPLEQ_REMOVE_HEAD(l3vpns_l, entry); + filterset_free(&vpn->import); + filterset_free(&vpn->export); + free(vpn); + } + free(l3vpns_l); + /* now check everything */ rib_shutdown(); nexthop_shutdown(); @@ -4006,22 +4009,6 @@ rde_find_prefixset(char *name, struct rde_prefixset_head *p) } void -rde_free_prefixsets(struct rde_prefixset_head *psh) -{ - struct rde_prefixset *ps; - - if (psh == NULL) - return; - - while (!SIMPLEQ_EMPTY(psh)) { - ps = SIMPLEQ_FIRST(psh); - trie_free(&ps->th); - SIMPLEQ_REMOVE_HEAD(psh, entry); - free(ps); - } -} - -void rde_mark_prefixsets_dirty(struct rde_prefixset_head *psold, struct rde_prefixset_head *psnew) { diff --git a/usr.sbin/bgpd/rde.h b/usr.sbin/bgpd/rde.h index 8eb453f617a..09b02c52eb4 100644 --- a/usr.sbin/bgpd/rde.h +++ b/usr.sbin/bgpd/rde.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.h,v 1.210 2019/02/26 10:49:15 claudio Exp $ */ +/* $OpenBSD: rde.h,v 1.211 2019/03/07 07:42:36 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> and @@ -570,16 +570,4 @@ int up_dump_mp_unreach(u_char *, int, struct rde_peer *, u_int8_t); int up_dump_attrnlri(u_char *, int, struct rde_peer *); int up_dump_mp_reach(u_char *, int, struct rde_peer *, u_int8_t); -/* rde_trie.c */ -int trie_add(struct trie_head *, struct bgpd_addr *, u_int8_t, u_int8_t, - u_int8_t); -int trie_roa_add(struct trie_head *, struct bgpd_addr *, u_int8_t, - struct set_table *); -void trie_free(struct trie_head *); -int trie_match(struct trie_head *, struct bgpd_addr *, u_int8_t, int); -int trie_roa_check(struct trie_head *, struct bgpd_addr *, u_int8_t, - u_int32_t); -void trie_dump(struct trie_head *); -int trie_equal(struct trie_head *, struct trie_head *); - #endif /* __RDE_H__ */ diff --git a/usr.sbin/bgpd/rde_rib.c b/usr.sbin/bgpd/rde_rib.c index 00aea42df37..0b88aa1a0dc 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.189 2019/01/21 02:07:56 claudio Exp $ */ +/* $OpenBSD: rde_rib.c,v 1.190 2019/03/07 07:42:36 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> @@ -236,6 +236,13 @@ rib_shutdown(void) ribs[id].name); rib_free(&ribs[id].rib); } + for (id = 0; id <= RIB_LOC_START; id++) { + struct rib_desc *rd = &ribs[id]; + filterlist_free(rd->in_rules_tmp); + filterlist_free(rd->in_rules); + bzero(rd, sizeof(struct rib_desc)); + } + free(ribs); } struct rib_entry * diff --git a/usr.sbin/bgpd/session.c b/usr.sbin/bgpd/session.c index f9e442f5967..3b2453f1bd1 100644 --- a/usr.sbin/bgpd/session.c +++ b/usr.sbin/bgpd/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.374 2019/02/27 04:31:56 claudio Exp $ */ +/* $OpenBSD: session.c,v 1.375 2019/03/07 07:42:36 claudio Exp $ */ /* * Copyright (c) 2003, 2004, 2005 Henning Brauer <henning@openbsd.org> @@ -247,13 +247,7 @@ session_main(int debug, int verbose) peer_cnt = 0; ctl_cnt = 0; - if ((conf = calloc(1, sizeof(struct bgpd_config))) == NULL) - fatal(NULL); - if ((conf->listen_addrs = calloc(1, sizeof(struct listen_addrs))) == - NULL) - fatal(NULL); - TAILQ_INIT(conf->listen_addrs); - + conf = new_config(); log_info("session engine ready"); while (session_quit == 0) { @@ -551,6 +545,7 @@ session_main(int debug, int verbose) "bgpd shutting down", sizeof(p->conf.shutcomm)); session_stop(p, ERR_CEASE_ADMIN_DOWN); + timer_remove_all(p); pfkey_remove(p); free(p); } @@ -561,11 +556,7 @@ session_main(int debug, int verbose) free(m); } - while ((la = TAILQ_FIRST(conf->listen_addrs)) != NULL) { - TAILQ_REMOVE(conf->listen_addrs, la, entry); - free(la); - } - free(conf->listen_addrs); + free_config(conf); free(peer_l); free(mrt_l); free(pfd); @@ -2624,15 +2615,10 @@ session_dispatch_imsg(struct imsgbuf *ibuf, int idx, u_int *listener_cnt) case IMSG_RECONF_CONF: if (idx != PFD_PIPE_MAIN) fatalx("reconf request not from parent"); - if ((nconf = malloc(sizeof(struct bgpd_config))) == - NULL) - fatal(NULL); - memcpy(nconf, imsg.data, sizeof(struct bgpd_config)); - if ((nconf->listen_addrs = calloc(1, - sizeof(struct listen_addrs))) == NULL) - fatal(NULL); - TAILQ_INIT(nconf->listen_addrs); + nconf = new_config(); npeers = NULL; + + copy_config(nconf, imsg.data); init_conf(nconf); pending_reconf = 1; break; @@ -2747,15 +2733,7 @@ session_dispatch_imsg(struct imsgbuf *ibuf, int idx, u_int *listener_cnt) fatalx("reconf request not from parent"); if (nconf == NULL) fatalx("got IMSG_RECONF_DONE but no config"); - conf->flags = nconf->flags; - conf->log = nconf->log; - conf->bgpid = nconf->bgpid; - conf->clusterid = nconf->clusterid; - conf->as = nconf->as; - conf->short_as = nconf->short_as; - conf->holdtime = nconf->holdtime; - conf->min_holdtime = nconf->min_holdtime; - conf->connectretry = nconf->connectretry; + copy_config(conf, nconf); /* add new peers */ for (p = npeers; p != NULL; p = next) { @@ -2798,8 +2776,7 @@ session_dispatch_imsg(struct imsgbuf *ibuf, int idx, u_int *listener_cnt) } setup_listeners(listener_cnt); - free(nconf->listen_addrs); - free(nconf); + free_config(nconf); nconf = NULL; pending_reconf = 0; log_info("SE reconfigured"); diff --git a/usr.sbin/bgpd/session.h b/usr.sbin/bgpd/session.h index bac15e885d1..ead763c2711 100644 --- a/usr.sbin/bgpd/session.h +++ b/usr.sbin/bgpd/session.h @@ -1,4 +1,4 @@ -/* $OpenBSD: session.h,v 1.133 2019/02/27 04:31:56 claudio Exp $ */ +/* $OpenBSD: session.h,v 1.134 2019/03/07 07:42:36 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -247,7 +247,7 @@ int carp_demote_get(char *); int carp_demote_set(char *, int); /* config.c */ -int merge_config(struct bgpd_config *, struct bgpd_config *, +void merge_config(struct bgpd_config *, struct bgpd_config *, struct peer *); int prepare_listeners(struct bgpd_config *); |