diff options
Diffstat (limited to 'usr.sbin/bgpd')
-rw-r--r-- | usr.sbin/bgpd/bgpd.c | 31 | ||||
-rw-r--r-- | usr.sbin/bgpd/bgpd.h | 14 | ||||
-rw-r--r-- | usr.sbin/bgpd/config.c | 17 | ||||
-rw-r--r-- | usr.sbin/bgpd/control.c | 4 | ||||
-rw-r--r-- | usr.sbin/bgpd/parse.y | 13 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde.c | 16 | ||||
-rw-r--r-- | usr.sbin/bgpd/session.c | 45 | ||||
-rw-r--r-- | usr.sbin/bgpd/session.h | 4 |
8 files changed, 78 insertions, 66 deletions
diff --git a/usr.sbin/bgpd/bgpd.c b/usr.sbin/bgpd/bgpd.c index 1b37de9ecb1..228ea3a4824 100644 --- a/usr.sbin/bgpd/bgpd.c +++ b/usr.sbin/bgpd/bgpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.c,v 1.50 2004/01/03 14:06:35 henning Exp $ */ +/* $OpenBSD: bgpd.c,v 1.51 2004/01/03 20:22:07 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -37,7 +37,8 @@ void sighdlr(int); void usage(void); int main(int, char *[]); -int reconfigure(char *, struct bgpd_config *, struct mrt_config *); +int reconfigure(char *, struct bgpd_config *, struct mrt_config *, + struct peer *); int dispatch_imsg(struct imsgbuf *, int, struct mrt_config *); int mrtfd = -1; @@ -89,6 +90,7 @@ int main(int argc, char *argv[]) { struct bgpd_config conf; + struct peer *peers, *p, *next; struct mrt_config mrtconf; struct mrtdump_config *mconf, *(mrt[POLL_MAX]); struct pollfd pfd[POLL_MAX]; @@ -108,6 +110,7 @@ main(int argc, char *argv[]) bzero(&conf, sizeof(conf)); bzero(&mrtconf, sizeof(mrtconf)); LIST_INIT(&mrtconf); + peers = NULL; while ((ch = getopt(argc, argv, "dD:f:nv")) != -1) { switch (ch) { @@ -137,7 +140,7 @@ main(int argc, char *argv[]) } } - if (parse_config(conffile, &conf, &mrtconf)) + if (parse_config(conffile, &conf, &mrtconf, &peers)) exit(1); if (conf.opts & BGPD_OPT_NOACTION) { @@ -175,8 +178,8 @@ main(int argc, char *argv[]) fatalx("control socket setup failed"); /* fork children */ - rde_pid = rde_main(&conf, pipe_m2r, pipe_s2r); - io_pid = session_main(&conf, pipe_m2s, pipe_s2r); + rde_pid = rde_main(&conf, peers, pipe_m2r, pipe_s2r); + io_pid = session_main(&conf, peers, pipe_m2s, pipe_s2r); setproctitle("parent"); @@ -198,6 +201,11 @@ main(int argc, char *argv[]) if ((rfd = kroute_init(!(conf.flags & BGPD_FLAG_NO_FIB_UPDATE))) == -1) quit = 1; + for (p = peers; p != NULL; p = next) { + next = p->next; + free(p); + } + while (quit == 0) { pfd[PFD_PIPE_SESSION].fd = ibuf_se.sock; pfd[PFD_PIPE_SESSION].events = POLLIN; @@ -266,7 +274,7 @@ main(int argc, char *argv[]) if (reconfig) { logit(LOG_CRIT, "rereading config"); - reconfigure(conffile, &conf, &mrtconf); + reconfigure(conffile, &conf, &mrtconf, peers); LIST_FOREACH(mconf, &mrtconf, list) mrt_state(mconf, IMSG_NONE, &ibuf_rde); reconfig = 0; @@ -301,11 +309,12 @@ main(int argc, char *argv[]) } int -reconfigure(char *conffile, struct bgpd_config *conf, struct mrt_config *mrtc) +reconfigure(char *conffile, struct bgpd_config *conf, struct mrt_config *mrtc, + struct peer *peers) { - struct peer *p; + struct peer *p, *next; - if (parse_config(conffile, conf, mrtc)) { + if (parse_config(conffile, conf, mrtc, &peers)) { logit(LOG_CRIT, "config file %s has errors, not reloading", conffile); return (-1); @@ -317,13 +326,15 @@ reconfigure(char *conffile, struct bgpd_config *conf, struct mrt_config *mrtc) if (imsg_compose(&ibuf_rde, IMSG_RECONF_CONF, 0, conf, sizeof(struct bgpd_config)) == -1) return (-1); - for (p = conf->peers; p != NULL; p = p->next) { + for (p = peers; p != NULL; p = next) { + next = p->next; if (imsg_compose(&ibuf_se, IMSG_RECONF_PEER, p->conf.id, &p->conf, sizeof(struct peer_config)) == -1) return (-1); if (imsg_compose(&ibuf_rde, IMSG_RECONF_PEER, p->conf.id, &p->conf, sizeof(struct peer_config)) == -1) return (-1); + free(p); } if (imsg_compose(&ibuf_se, IMSG_RECONF_DONE, 0, NULL, 0) == -1 || imsg_compose(&ibuf_rde, IMSG_RECONF_DONE, 0, NULL, 0) == -1) diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h index aa8b00dc01c..ec8f95017af 100644 --- a/usr.sbin/bgpd/bgpd.h +++ b/usr.sbin/bgpd/bgpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.h,v 1.48 2004/01/03 13:54:27 henning Exp $ */ +/* $OpenBSD: bgpd.h,v 1.49 2004/01/03 20:22:07 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -116,7 +116,6 @@ struct bgpd_config { int flags; int log; struct sockaddr_in listen_addr; - struct peer *peers; }; struct buf_read { @@ -267,7 +266,8 @@ void send_nexthop_update(struct kroute_nexthop *); /* session.c */ void session_socket_blockmode(int, enum blockmodes); -int session_main(struct bgpd_config *, int[2], int[2]); +int session_main(struct bgpd_config *, struct peer *, int[2], + int[2]); /* buffer.c */ struct buf *buf_open(ssize_t); @@ -298,10 +298,12 @@ char *log_ntoa(in_addr_t); /* parse.y */ int cmdline_symset(char *); -int parse_config(char *, struct bgpd_config *, struct mrt_config *); +int parse_config(char *, struct bgpd_config *, struct mrt_config *, + struct peer **); /* config.c */ -int merge_config(struct bgpd_config *, struct bgpd_config *); +int merge_config(struct bgpd_config *, struct bgpd_config *, + struct peer *); /* imsg.c */ void imsg_init(struct imsgbuf *, int); @@ -311,7 +313,7 @@ int imsg_compose(struct imsgbuf *, int, u_int32_t, void *, u_int16_t); void imsg_free(struct imsg *); /* rde.c */ -int rde_main(struct bgpd_config *, int[2], int[2]); +int rde_main(struct bgpd_config *, struct peer *, int[2], int[2]); /* mrt.c */ int mrt_mergeconfig(struct mrt_config *, struct mrt_config *); diff --git a/usr.sbin/bgpd/config.c b/usr.sbin/bgpd/config.c index e4ae55b9f4e..6fa0cdcdc45 100644 --- a/usr.sbin/bgpd/config.c +++ b/usr.sbin/bgpd/config.c @@ -1,4 +1,4 @@ -/* $OpenBSD: config.c,v 1.13 2004/01/02 22:47:33 itojun Exp $ */ +/* $OpenBSD: config.c,v 1.14 2004/01/03 20:22:07 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -34,10 +34,11 @@ u_int32_t get_bgpid(void); u_int32_t get_id(struct peer *); int -merge_config(struct bgpd_config *xconf, struct bgpd_config *conf) +merge_config(struct bgpd_config *xconf, struct bgpd_config *conf, + struct peer *peers) { enum reconf_action reconf = RECONF_NONE; - struct peer *p, *next; + struct peer *p; /* merge conf (new) into xconf (old) */ if (!conf->as) { @@ -90,21 +91,13 @@ merge_config(struct bgpd_config *xconf, struct bgpd_config *conf) xconf->holdtime = conf->holdtime; xconf->min_holdtime = conf->min_holdtime; - for (p = conf->peers; p != NULL; p = p->next) { + for (p = peers; p != NULL; p = p->next) { p->conf.reconf_action = reconf; p->conf.ebgp = (p->conf.remote_as != xconf->as); if (!p->conf.id) p->conf.id = get_id(p); } - for (p = xconf->peers; p != NULL; p = next) { - next = p->next; - free(p); - } - - /* merge peers done by session engine except for initial config */ - xconf->peers = conf->peers; - return (0); } diff --git a/usr.sbin/bgpd/control.c b/usr.sbin/bgpd/control.c index c201b20dc3c..fbeb4f22f24 100644 --- a/usr.sbin/bgpd/control.c +++ b/usr.sbin/bgpd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.6 2004/01/03 14:06:35 henning Exp $ */ +/* $OpenBSD: control.c,v 1.7 2004/01/03 20:22:07 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -195,7 +195,7 @@ control_dispatch_msg(struct pollfd *pfd, int i) switch (imsg.hdr.type) { case IMSG_CTL_SHOW_NEIGHBOR: - for (p = conf->peers; p != NULL; p = p->next) + for (p = peers; p != NULL; p = p->next) imsg_compose(&c->ibuf, IMSG_CTL_SHOW_NEIGHBOR, 0, p, sizeof(struct peer)); imsg_compose(&c->ibuf, IMSG_CTL_END, 0, NULL, 0); diff --git a/usr.sbin/bgpd/parse.y b/usr.sbin/bgpd/parse.y index 7b8463ab614..fd6bd551002 100644 --- a/usr.sbin/bgpd/parse.y +++ b/usr.sbin/bgpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.24 2003/12/27 21:40:43 henning Exp $ */ +/* $OpenBSD: parse.y,v 1.25 2004/01/03 20:22:07 henning Exp $ */ /* * Copyright (c) 2002, 2003 Henning Brauer <henning@openbsd.org> @@ -36,6 +36,7 @@ static struct bgpd_config *conf; static struct mrt_config *mrtconf; +static struct peer *peers; static struct peer *curpeer; static struct peer *curgroup; static FILE *fin = NULL; @@ -218,8 +219,8 @@ neighbor : NEIGHBOR address optnl '{' optnl { curpeer->conf.remote_addr.sin_addr.s_addr = $2.s_addr; } peeropts_l optnl '}' { - curpeer->next = conf->peers; - conf->peers = curpeer; + curpeer->next = peers; + peers = curpeer; curpeer = NULL; } ; @@ -547,7 +548,7 @@ top: int parse_config(char *filename, struct bgpd_config *xconf, - struct mrt_config *xmconf) + struct mrt_config *xmconf, struct peer **xpeers) { struct sym *sym, *next; @@ -557,6 +558,7 @@ parse_config(char *filename, struct bgpd_config *xconf, fatal(NULL); LIST_INIT(mrtconf); + peers = NULL; curpeer = NULL; curgroup = NULL; lineno = 1; @@ -594,8 +596,9 @@ parse_config(char *filename, struct bgpd_config *xconf, } } - errors += merge_config(xconf, conf); + errors += merge_config(xconf, conf, peers); errors += mrt_mergeconfig(xmconf, mrtconf); + *xpeers = peers; free(conf); free(mrtconf); diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c index 7010c8177c5..1500edfef4f 100644 --- a/usr.sbin/bgpd/rde.c +++ b/usr.sbin/bgpd/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.41 2004/01/03 14:06:35 henning Exp $ */ +/* $OpenBSD: rde.c,v 1.42 2004/01/03 20:22:07 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -46,7 +46,7 @@ void rde_update_log(const char *, const struct rde_peer *, const struct attr_flags *, const struct in_addr *, u_int8_t); -void peer_init(struct bgpd_config *, u_long); +void peer_init(struct peer *, u_long); struct rde_peer *peer_add(u_int32_t, struct peer_config *); void peer_remove(struct rde_peer *); struct rde_peer *peer_get(u_int32_t); @@ -74,7 +74,8 @@ u_long pathhashsize = 1024; u_long nexthophashsize = 64; int -rde_main(struct bgpd_config *config, int pipe_m2r[2], int pipe_s2r[2]) +rde_main(struct bgpd_config *config, struct peer *peers, int pipe_m2r[2], + int pipe_s2r[2]) { pid_t pid; struct passwd *pw; @@ -116,7 +117,7 @@ rde_main(struct bgpd_config *config, int pipe_m2r[2], int pipe_s2r[2]) close(pipe_m2r[0]); /* initialize the RIB structures */ - peer_init(config, peerhashsize); + peer_init(peers, peerhashsize); path_init(pathhashsize); nexthop_init(nexthophashsize); pt_init(); @@ -197,7 +198,6 @@ rde_dispatch_imsg(struct imsgbuf *ibuf, int idx) NULL) fatal(NULL); memcpy(nconf, imsg.data, sizeof(struct bgpd_config)); - nconf->peers = NULL; break; case IMSG_RECONF_PEER: if (idx != PFD_PIPE_MAIN) @@ -607,7 +607,7 @@ struct peer_table { &peertable.peer_hashtbl[(x) & peertable.peer_hashmask] void -peer_init(struct bgpd_config *bgpconf, u_long hashsize) +peer_init(struct peer *peers, u_long hashsize) { struct peer *p, *next; u_long hs, i; @@ -624,13 +624,13 @@ peer_init(struct bgpd_config *bgpconf, u_long hashsize) peertable.peer_hashmask = hs - 1; - for (p = bgpconf->peers; p != NULL; p = next) { + for (p = peers; p != NULL; p = next) { next = p->next; p->conf.reconf_action = RECONF_NONE; peer_add(p->conf.id, &p->conf); free(p); } - bgpconf->peers = NULL; + peers = NULL; } struct rde_peer * diff --git a/usr.sbin/bgpd/session.c b/usr.sbin/bgpd/session.c index 52e546334e9..077bed74238 100644 --- a/usr.sbin/bgpd/session.c +++ b/usr.sbin/bgpd/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.55 2004/01/03 14:06:35 henning Exp $ */ +/* $OpenBSD: session.c,v 1.56 2004/01/03 20:22:07 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -80,7 +80,8 @@ void session_down(struct peer *); struct peer *getpeerbyip(in_addr_t); -struct bgpd_config *nconf = NULL; +struct bgpd_config *conf, *nconf = NULL; +struct peer *npeers; volatile sig_atomic_t session_quit = 0; int pending_reconf = 0; int sock = -1; @@ -127,17 +128,19 @@ setup_listener(void) int -session_main(struct bgpd_config *config, int pipe_m2s[2], int pipe_s2r[2]) +session_main(struct bgpd_config *config, struct peer *cpeers, int pipe_m2s[2], + int pipe_s2r[2]) { - int nfds, i, j, timeout, npeers; + int nfds, i, j, timeout, idx_peers; pid_t pid; time_t nextaction; struct passwd *pw; - struct peer *p, *peers[OPEN_MAX], *last, *next; + struct peer *p, *peer_l[OPEN_MAX], *last, *next; struct pollfd pfd[OPEN_MAX]; struct ctl_conn *ctl_conn; conf = config; + peers = cpeers; switch (pid = fork()) { case -1: @@ -196,7 +199,7 @@ session_main(struct bgpd_config *config, int pipe_m2s[2], int pipe_s2r[2]) i = PFD_PEERS_START; last = NULL; - for (p = conf->peers; p != NULL; p = next) { + for (p = peers; p != NULL; p = next) { next = p->next; if (!pending_reconf) { /* needs init? */ @@ -216,7 +219,7 @@ session_main(struct bgpd_config *config, int pipe_m2s[2], int pipe_s2r[2]) if (last != NULL) last->next = next; else - conf->peers = next; + peers = next; free(p); continue; } @@ -253,12 +256,12 @@ session_main(struct bgpd_config *config, int pipe_m2s[2], int pipe_s2r[2]) if (p->sock != -1 && p->events != 0) { pfd[i].fd = p->sock; pfd[i].events = p->events; - peers[i] = p; + peer_l[i] = p; i++; } } - npeers = i; + idx_peers = i; TAILQ_FOREACH(ctl_conn, &ctl_conns, entries) { pfd[i].fd = ctl_conn->ibuf.sock; @@ -299,8 +302,8 @@ session_main(struct bgpd_config *config, int pipe_m2s[2], int pipe_s2r[2]) control_accept(csock); } - for (j = PFD_PEERS_START; nfds > 0 && j < npeers; j++) - nfds -= session_dispatch_msg(&pfd[j], peers[j]); + for (j = PFD_PEERS_START; nfds > 0 && j < idx_peers; j++) + nfds -= session_dispatch_msg(&pfd[j], peer_l[j]); for (; nfds > 0 && j < i; j++) nfds -= control_dispatch_msg(&pfd[j], j); @@ -323,7 +326,7 @@ init_peers(void) { struct peer *p; - for (p = conf->peers; p != NULL; p = p->next) { + for (p = peers; p != NULL; p = p->next) { if (p->state == STATE_NONE) { change_state(p, STATE_IDLE, EVNT_NONE); p->StartTimer = time(NULL); /* start ASAP */ @@ -587,7 +590,7 @@ session_terminate(void) { struct peer *p; - for (p = conf->peers; p != NULL; p = p->next) + for (p = peers; p != NULL; p = p->next) bgp_fsm(p, EVNT_STOP); shutdown(sock, SHUT_RDWR); @@ -1291,7 +1294,7 @@ session_dispatch_imsg(struct imsgbuf *ibuf, int idx) NULL) fatal(NULL); memcpy(nconf, imsg.data, sizeof(struct bgpd_config)); - nconf->peers = NULL; + npeers = NULL; init_conf(nconf); pending_reconf = 1; break; @@ -1306,8 +1309,8 @@ session_dispatch_imsg(struct imsgbuf *ibuf, int idx) fatal("new_peer"); p->state = STATE_NONE; p->sock = -1; - p->next = nconf->peers; - nconf->peers = p; + p->next = npeers; + npeers = p; reconf = RECONF_REINIT; } else reconf = RECONF_KEEP; @@ -1352,13 +1355,13 @@ session_dispatch_imsg(struct imsgbuf *ibuf, int idx) conf->bgpid = nconf->bgpid; conf->min_holdtime = nconf->min_holdtime; /* add new peers */ - for (p = nconf->peers; p != NULL; p = next) { + for (p = npeers; p != NULL; p = next) { next = p->next; - p->next = conf->peers; - conf->peers = p; + p->next = peers; + peers = p; } /* find peers to be deleted */ - for (p = conf->peers; p != NULL; p = p->next) + for (p = peers; p != NULL; p = p->next) if (p->conf.reconf_action == RECONF_NONE) p->conf.reconf_action = RECONF_DELETE; free(nconf); @@ -1379,7 +1382,7 @@ getpeerbyip(in_addr_t ip) struct peer *p; /* we might want a more effective way to find peers by IP */ - for (p = conf->peers; p != NULL && + for (p = peers; p != NULL && p->conf.remote_addr.sin_addr.s_addr != ip; p = p->next) ; /* nothing */ diff --git a/usr.sbin/bgpd/session.h b/usr.sbin/bgpd/session.h index ef99c5a85c1..52a90c94b95 100644 --- a/usr.sbin/bgpd/session.h +++ b/usr.sbin/bgpd/session.h @@ -1,4 +1,4 @@ -/* $OpenBSD: session.h,v 1.3 2004/01/01 23:46:47 henning Exp $ */ +/* $OpenBSD: session.h,v 1.4 2004/01/03 20:22:07 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -83,7 +83,7 @@ struct ctl_conn { TAILQ_HEAD(ctl_conns, ctl_conn) ctl_conns; -struct bgpd_config *conf; +struct peer *peers; /* control.c */ int control_listen(void); |