Hi,
With the introduction of re-exec of the childs the config parsing happened
after bgpd demonized. This is super annoying and therefor this diff
changes that. It will make bgpd fail on startup if there is an issue with
the config file. I could not move the control socket setup before
daemonizing since that call will send out imsgs and so the childs need to
be up and running. To change this more refactoring is needed but this is
already a good first step.
OK?
--
:wq Claudio
Index: bgpd.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.c,v
retrieving revision 1.224
diff -u -p -r1.224 bgpd.c
--- bgpd.c 5 Aug 2019 08:46:55 -0000 1.224
+++ bgpd.c 8 Aug 2019 09:30:36 -0000
@@ -43,6 +43,7 @@ int main(int, char *[]);
pid_t start_child(enum bgpd_process, char *, int, int, int);
int send_filterset(struct imsgbuf *, struct filter_set_head *);
int reconfigure(char *, struct bgpd_config *);
+int send_config(struct bgpd_config *);
int dispatch_imsg(struct imsgbuf *, int, struct bgpd_config *);
int control_setup(struct bgpd_config *);
static void getsockpair(int [2]);
@@ -195,6 +196,14 @@ main(int argc, char *argv[])
if (getpwnam(BGPD_USER) == NULL)
errx(1, "unknown user %s", BGPD_USER);
+ if ((conf = parse_config(conffile, NULL)) == NULL) {
+ log_warnx("config file %s has errors", conffile);
+ exit(1);
+ }
+
+ if (prepare_listeners(conf) == -1)
+ exit(1);
+
log_init(debug, LOG_DAEMON);
log_setverbose(cmd_opts & BGPD_OPT_VERBOSE);
@@ -250,8 +259,11 @@ BROKEN if (pledge("stdio rpath wpath cpa
if (imsg_send_sockets(ibuf_se, ibuf_rde))
fatal("could not establish imsg links");
- conf = new_config();
- quit = reconfigure(conffile, conf);
+ /* control setup needs to happen late since it sends imsgs */
+ if (control_setup(conf) == -1)
+ quit = 1;
+ if (send_config(conf) != 0)
+ quit = 1;
if (pftable_clear_all() != 0)
quit = 1;
@@ -325,9 +337,12 @@ BROKEN if (pledge("stdio rpath wpath cpa
error = 0;
break;
case 2:
+ log_info("previous reload still running");
error = CTL_RES_PENDING;
break;
default: /* parse error */
+ log_warnx("config file %s has errors, "
+ "not reloading", conffile);
error = CTL_RES_PARSE_ERROR;
break;
}
@@ -456,39 +471,40 @@ int
reconfigure(char *conffile, struct bgpd_config *conf)
{
struct bgpd_config *new_conf;
- struct peer *p;
- struct filter_rule *r;
- struct listen_addr *la;
- struct rde_rib *rr;
- struct l3vpn *vpn;
- struct as_set *aset;
- struct prefixset *ps;
- struct prefixset_item *psi, *npsi;
- if (reconfpending) {
- log_info("previous reload still running");
+ if (reconfpending)
return (2);
- }
- reconfpending = 2; /* one per child */
log_info("rereading config");
- if ((new_conf = parse_config(conffile, &conf->peers)) == NULL) {
- log_warnx("config file %s has errors, not reloading",
- conffile);
- reconfpending = 0;
+ if ((new_conf = parse_config(conffile, &conf->peers)) == NULL)
return (1);
- }
+
merge_config(conf, new_conf);
if (prepare_listeners(conf) == -1) {
- reconfpending = 0;
return (1);
}
if (control_setup(conf) == -1) {
- reconfpending = 0;
return (1);
}
+
+ return send_config(conf);
+}
+
+int
+send_config(struct bgpd_config *conf)
+{
+ struct peer *p;
+ struct filter_rule *r;
+ struct listen_addr *la;
+ struct rde_rib *rr;
+ struct l3vpn *vpn;
+ struct as_set *aset;
+ struct prefixset *ps;
+ struct prefixset_item *psi, *npsi;
+
+ reconfpending = 2; /* one per child */
expand_networks(conf);
Index: parse.y
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/parse.y,v
retrieving revision 1.399
diff -u -p -r1.399 parse.y
--- parse.y 7 Aug 2019 10:26:41 -0000 1.399
+++ parse.y 8 Aug 2019 09:22:48 -0000
@@ -592,6 +592,7 @@ conf_main : AS as4number {
fatal("parse conf_main listen on calloc");
la->fd = -1;
+ la->reconf = RECONF_REINIT;
sa = addr2sa(&$3, BGP_PORT, &la->sa_len);
memcpy(&la->sa, sa, la->sa_len);
TAILQ_INSERT_TAIL(conf->listen_addrs, la, entry);