From a241516541360da48caa93086826a39e70bb6789 Mon Sep 17 00:00:00 2001 From: Henning Brauer Date: Sat, 3 Jan 2004 20:37:35 +0000 Subject: move some session specific stuff to session.h and make the few files that need it include that --- usr.sbin/bgpd/bgpd.c | 23 ++++++++------- usr.sbin/bgpd/bgpd.h | 72 +--------------------------------------------- usr.sbin/bgpd/config.c | 7 +++-- usr.sbin/bgpd/parse.y | 15 +++++----- usr.sbin/bgpd/rde.c | 13 +++++---- usr.sbin/bgpd/session.h | 76 ++++++++++++++++++++++++++++++++++++++++++++++++- 6 files changed, 107 insertions(+), 99 deletions(-) (limited to 'usr.sbin') diff --git a/usr.sbin/bgpd/bgpd.c b/usr.sbin/bgpd/bgpd.c index 228ea3a4824..6b95380fe77 100644 --- a/usr.sbin/bgpd/bgpd.c +++ b/usr.sbin/bgpd/bgpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.c,v 1.51 2004/01/03 20:22:07 henning Exp $ */ +/* $OpenBSD: bgpd.c,v 1.52 2004/01/03 20:37:34 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer @@ -33,6 +33,7 @@ #include "mrt.h" #include "bgpd.h" +#include "session.h" void sighdlr(int); void usage(void); @@ -90,7 +91,7 @@ int main(int argc, char *argv[]) { struct bgpd_config conf; - struct peer *peers, *p, *next; + struct peer *peer_l, *p, *next; struct mrt_config mrtconf; struct mrtdump_config *mconf, *(mrt[POLL_MAX]); struct pollfd pfd[POLL_MAX]; @@ -110,7 +111,7 @@ main(int argc, char *argv[]) bzero(&conf, sizeof(conf)); bzero(&mrtconf, sizeof(mrtconf)); LIST_INIT(&mrtconf); - peers = NULL; + peer_l = NULL; while ((ch = getopt(argc, argv, "dD:f:nv")) != -1) { switch (ch) { @@ -140,7 +141,7 @@ main(int argc, char *argv[]) } } - if (parse_config(conffile, &conf, &mrtconf, &peers)) + if (parse_config(conffile, &conf, &mrtconf, &peer_l)) exit(1); if (conf.opts & BGPD_OPT_NOACTION) { @@ -178,8 +179,8 @@ main(int argc, char *argv[]) fatalx("control socket setup failed"); /* fork children */ - rde_pid = rde_main(&conf, peers, pipe_m2r, pipe_s2r); - io_pid = session_main(&conf, peers, pipe_m2s, pipe_s2r); + rde_pid = rde_main(&conf, peer_l, pipe_m2r, pipe_s2r); + io_pid = session_main(&conf, peer_l, pipe_m2s, pipe_s2r); setproctitle("parent"); @@ -201,7 +202,7 @@ 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) { + for (p = peer_l; p != NULL; p = next) { next = p->next; free(p); } @@ -274,7 +275,7 @@ main(int argc, char *argv[]) if (reconfig) { logit(LOG_CRIT, "rereading config"); - reconfigure(conffile, &conf, &mrtconf, peers); + reconfigure(conffile, &conf, &mrtconf, peer_l); LIST_FOREACH(mconf, &mrtconf, list) mrt_state(mconf, IMSG_NONE, &ibuf_rde); reconfig = 0; @@ -310,11 +311,11 @@ main(int argc, char *argv[]) int reconfigure(char *conffile, struct bgpd_config *conf, struct mrt_config *mrtc, - struct peer *peers) + struct peer *peer_l) { struct peer *p, *next; - if (parse_config(conffile, conf, mrtc, &peers)) { + if (parse_config(conffile, conf, mrtc, &peer_l)) { logit(LOG_CRIT, "config file %s has errors, not reloading", conffile); return (-1); @@ -326,7 +327,7 @@ 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 = peers; p != NULL; p = next) { + for (p = peer_l; 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) diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h index ec8f95017af..f7d8f6ba2bf 100644 --- a/usr.sbin/bgpd/bgpd.h +++ b/usr.sbin/bgpd/bgpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.h,v 1.49 2004/01/03 20:22:07 henning Exp $ */ +/* $OpenBSD: bgpd.h,v 1.50 2004/01/03 20:37:34 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer @@ -54,33 +54,6 @@ enum { PROC_RDE } bgpd_process; -enum session_state { - STATE_NONE, - STATE_IDLE, - STATE_CONNECT, - STATE_ACTIVE, - STATE_OPENSENT, - STATE_OPENCONFIRM, - STATE_ESTABLISHED -}; - -enum session_events { - EVNT_NONE, - EVNT_START, - EVNT_STOP, - EVNT_CON_OPEN, - EVNT_CON_CLOSED, - EVNT_CON_OPENFAIL, - EVNT_CON_FATAL, - EVNT_TIMER_CONNRETRY, - EVNT_TIMER_HOLDTIME, - EVNT_TIMER_KEEPALIVE, - EVNT_RCVD_OPEN, - EVNT_RCVD_KEEPALIVE, - EVNT_RCVD_UPDATE, - EVNT_RCVD_NOTIFICATION -}; - enum reconf_action { RECONF_NONE, RECONF_KEEP, @@ -88,11 +61,6 @@ enum reconf_action { RECONF_DELETE }; -enum blockmodes { - BM_NORMAL, - BM_NONBLOCK -}; - struct buf { TAILQ_ENTRY(buf) entries; u_char *buf; @@ -137,23 +105,6 @@ struct peer_config { enum reconf_action reconf_action; }; -struct peer { - struct peer_config conf; - u_int32_t remote_bgpid; - u_int16_t holdtime; - enum session_state state; - time_t ConnectRetryTimer; - time_t KeepaliveTimer; - time_t HoldTimer; - time_t StartTimer; - u_int StartTimerInterval; - int sock; - int events; - struct msgbuf wbuf; - struct buf_read *rbuf; - struct peer *next; -}; - #define MRT_FILE_LEN 512 enum mrtdump_type { MRT_NONE, @@ -264,11 +215,6 @@ struct kroute_nexthop { /* bgpd.c */ void send_nexthop_update(struct kroute_nexthop *); -/* session.c */ -void session_socket_blockmode(int, enum blockmodes); -int session_main(struct bgpd_config *, struct peer *, int[2], - int[2]); - /* buffer.c */ struct buf *buf_open(ssize_t); int buf_add(struct buf *, void *, ssize_t); @@ -283,27 +229,14 @@ int msgbuf_write(struct msgbuf *); void log_init(int); void logit(int, const char *, ...); void vlog(int, const char *, va_list); -void log_peer_err(const struct peer *, const char *, ...); -void log_peer_errx(const struct peer *, const char *, ...); void log_err(const char *, ...); void fatal(const char *); void fatalx(const char *); void fatal_ensure(const char *, int, const char *); -void log_statechange(const struct peer *, enum session_state, - enum session_events); -void log_notification(const struct peer *, u_int8_t, u_int8_t, - u_char *, u_int16_t); -void log_conn_attempt(const struct peer *, struct in_addr); char *log_ntoa(in_addr_t); /* parse.y */ int cmdline_symset(char *); -int parse_config(char *, struct bgpd_config *, struct mrt_config *, - struct peer **); - -/* config.c */ -int merge_config(struct bgpd_config *, struct bgpd_config *, - struct peer *); /* imsg.c */ void imsg_init(struct imsgbuf *, int); @@ -312,9 +245,6 @@ int imsg_get(struct imsgbuf *, struct imsg *); 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 *, 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 6fa0cdcdc45..82192861dcc 100644 --- a/usr.sbin/bgpd/config.c +++ b/usr.sbin/bgpd/config.c @@ -1,4 +1,4 @@ -/* $OpenBSD: config.c,v 1.14 2004/01/03 20:22:07 henning Exp $ */ +/* $OpenBSD: config.c,v 1.15 2004/01/03 20:37:34 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer @@ -27,6 +27,7 @@ #include #include "bgpd.h" +#include "session.h" void *sconf; @@ -35,7 +36,7 @@ u_int32_t get_id(struct peer *); int merge_config(struct bgpd_config *xconf, struct bgpd_config *conf, - struct peer *peers) + struct peer *peer_l) { enum reconf_action reconf = RECONF_NONE; struct peer *p; @@ -91,7 +92,7 @@ merge_config(struct bgpd_config *xconf, struct bgpd_config *conf, xconf->holdtime = conf->holdtime; xconf->min_holdtime = conf->min_holdtime; - for (p = peers; p != NULL; p = p->next) { + for (p = peer_l; p != NULL; p = p->next) { p->conf.reconf_action = reconf; p->conf.ebgp = (p->conf.remote_as != xconf->as); if (!p->conf.id) diff --git a/usr.sbin/bgpd/parse.y b/usr.sbin/bgpd/parse.y index fd6bd551002..e34c9348b59 100644 --- a/usr.sbin/bgpd/parse.y +++ b/usr.sbin/bgpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.25 2004/01/03 20:22:07 henning Exp $ */ +/* $OpenBSD: parse.y,v 1.26 2004/01/03 20:37:34 henning Exp $ */ /* * Copyright (c) 2002, 2003 Henning Brauer @@ -33,10 +33,11 @@ #include #include "bgpd.h" +#include "session.h" static struct bgpd_config *conf; static struct mrt_config *mrtconf; -static struct peer *peers; +static struct peer *peer_l; static struct peer *curpeer; static struct peer *curgroup; static FILE *fin = NULL; @@ -219,8 +220,8 @@ neighbor : NEIGHBOR address optnl '{' optnl { curpeer->conf.remote_addr.sin_addr.s_addr = $2.s_addr; } peeropts_l optnl '}' { - curpeer->next = peers; - peers = curpeer; + curpeer->next = peer_l; + peer_l = curpeer; curpeer = NULL; } ; @@ -558,7 +559,7 @@ parse_config(char *filename, struct bgpd_config *xconf, fatal(NULL); LIST_INIT(mrtconf); - peers = NULL; + peer_l = NULL; curpeer = NULL; curgroup = NULL; lineno = 1; @@ -596,9 +597,9 @@ parse_config(char *filename, struct bgpd_config *xconf, } } - errors += merge_config(xconf, conf, peers); + errors += merge_config(xconf, conf, peer_l); errors += mrt_mergeconfig(xmconf, mrtconf); - *xpeers = peers; + *xpeers = peer_l; free(conf); free(mrtconf); diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c index 1500edfef4f..78df8ef91ac 100644 --- a/usr.sbin/bgpd/rde.c +++ b/usr.sbin/bgpd/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.42 2004/01/03 20:22:07 henning Exp $ */ +/* $OpenBSD: rde.c,v 1.43 2004/01/03 20:37:34 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer @@ -30,6 +30,7 @@ #include "ensure.h" #include "mrt.h" #include "rde.h" +#include "session.h" #define PFD_PIPE_MAIN 0 #define PFD_PIPE_SESSION 1 @@ -74,7 +75,7 @@ u_long pathhashsize = 1024; u_long nexthophashsize = 64; int -rde_main(struct bgpd_config *config, struct peer *peers, int pipe_m2r[2], +rde_main(struct bgpd_config *config, struct peer *peer_l, int pipe_m2r[2], int pipe_s2r[2]) { pid_t pid; @@ -117,7 +118,7 @@ rde_main(struct bgpd_config *config, struct peer *peers, int pipe_m2r[2], close(pipe_m2r[0]); /* initialize the RIB structures */ - peer_init(peers, peerhashsize); + peer_init(peer_l, peerhashsize); path_init(pathhashsize); nexthop_init(nexthophashsize); pt_init(); @@ -607,7 +608,7 @@ struct peer_table { &peertable.peer_hashtbl[(x) & peertable.peer_hashmask] void -peer_init(struct peer *peers, u_long hashsize) +peer_init(struct peer *peer_l, u_long hashsize) { struct peer *p, *next; u_long hs, i; @@ -624,13 +625,13 @@ peer_init(struct peer *peers, u_long hashsize) peertable.peer_hashmask = hs - 1; - for (p = peers; p != NULL; p = next) { + for (p = peer_l; p != NULL; p = next) { next = p->next; p->conf.reconf_action = RECONF_NONE; peer_add(p->conf.id, &p->conf); free(p); } - peers = NULL; + peer_l = NULL; } struct rde_peer * diff --git a/usr.sbin/bgpd/session.h b/usr.sbin/bgpd/session.h index 52a90c94b95..106add0eeff 100644 --- a/usr.sbin/bgpd/session.h +++ b/usr.sbin/bgpd/session.h @@ -1,4 +1,4 @@ -/* $OpenBSD: session.h,v 1.4 2004/01/03 20:22:07 henning Exp $ */ +/* $OpenBSD: session.h,v 1.5 2004/01/03 20:37:34 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer @@ -30,6 +30,38 @@ #define MSGSIZE_UPDATE_MIN 23 #define MSGSIZE_KEEPALIVE MSGSIZE_HEADER +enum session_state { + STATE_NONE, + STATE_IDLE, + STATE_CONNECT, + STATE_ACTIVE, + STATE_OPENSENT, + STATE_OPENCONFIRM, + STATE_ESTABLISHED +}; + +enum session_events { + EVNT_NONE, + EVNT_START, + EVNT_STOP, + EVNT_CON_OPEN, + EVNT_CON_CLOSED, + EVNT_CON_OPENFAIL, + EVNT_CON_FATAL, + EVNT_TIMER_CONNRETRY, + EVNT_TIMER_HOLDTIME, + EVNT_TIMER_KEEPALIVE, + EVNT_RCVD_OPEN, + EVNT_RCVD_KEEPALIVE, + EVNT_RCVD_UPDATE, + EVNT_RCVD_NOTIFICATION +}; + +enum blockmodes { + BM_NORMAL, + BM_NONBLOCK +}; + enum msg_type { OPEN = 1, UPDATE, @@ -83,8 +115,50 @@ struct ctl_conn { TAILQ_HEAD(ctl_conns, ctl_conn) ctl_conns; +struct peer { + struct peer_config conf; + u_int32_t remote_bgpid; + u_int16_t holdtime; + enum session_state state; + time_t ConnectRetryTimer; + time_t KeepaliveTimer; + time_t HoldTimer; + time_t StartTimer; + u_int StartTimerInterval; + int sock; + int events; + struct msgbuf wbuf; + struct buf_read *rbuf; + struct peer *next; +}; + struct peer *peers; +/* session.c */ +void session_socket_blockmode(int, enum blockmodes); +int session_main(struct bgpd_config *, struct peer *, int[2], + int[2]); + +/* log.c */ +void log_peer_err(const struct peer *, const char *, ...); +void log_peer_errx(const struct peer *, const char *, ...); +void log_statechange(const struct peer *, enum session_state, + enum session_events); +void log_notification(const struct peer *, u_int8_t, u_int8_t, + u_char *, u_int16_t); +void log_conn_attempt(const struct peer *, struct in_addr); + +/* parse.y */ +int parse_config(char *, struct bgpd_config *, struct mrt_config *, + struct peer **); + +/* config.c */ +int merge_config(struct bgpd_config *, struct bgpd_config *, + struct peer *); + +/* rde.c */ +int rde_main(struct bgpd_config *, struct peer *, int[2], int[2]); + /* control.c */ int control_listen(void); void control_shutdown(void); -- cgit v1.2.3