summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/bgpd/bgpd.c24
-rw-r--r--usr.sbin/bgpd/bgpd.h3
-rw-r--r--usr.sbin/bgpd/rde.c28
-rw-r--r--usr.sbin/bgpd/session.h4
4 files changed, 44 insertions, 15 deletions
diff --git a/usr.sbin/bgpd/bgpd.c b/usr.sbin/bgpd/bgpd.c
index d865bf70957..43ead525611 100644
--- a/usr.sbin/bgpd/bgpd.c
+++ b/usr.sbin/bgpd/bgpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bgpd.c,v 1.74 2004/02/06 20:18:18 henning Exp $ */
+/* $OpenBSD: bgpd.c,v 1.75 2004/02/07 11:42:30 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -96,7 +96,7 @@ main(int argc, char *argv[])
struct peer *peer_l;
struct mrt_head mrt_l;
struct network_head net_l;
- struct filter_head rules_l;
+ struct filter_head *rules_l;
struct network *net;
struct filter_rule *r;
struct mrt *(mrt[POLL_MAX]);
@@ -114,10 +114,13 @@ main(int argc, char *argv[])
log_init(1); /* log to stderr until daemonized */
+ if ((rules_l = calloc(1, sizeof(struct filter_head))) == NULL)
+ err(1, NULL);
+
bzero(&conf, sizeof(conf));
LIST_INIT(&mrt_l);
TAILQ_INIT(&net_l);
- TAILQ_INIT(&rules_l);
+ TAILQ_INIT(rules_l);
peer_l = NULL;
while ((ch = getopt(argc, argv, "dD:f:nv")) != -1) {
@@ -147,7 +150,7 @@ main(int argc, char *argv[])
}
}
- if (parse_config(conffile, &conf, &mrt_l, &peer_l, &net_l, &rules_l))
+ if (parse_config(conffile, &conf, &mrt_l, &peer_l, &net_l, rules_l))
exit(1);
if (conf.opts & BGPD_OPT_NOACTION) {
@@ -189,7 +192,7 @@ main(int argc, char *argv[])
fatalx("control socket setup failed");
/* fork children */
- rde_pid = rde_main(&conf, peer_l, &net_l, pipe_m2r, pipe_s2r);
+ rde_pid = rde_main(&conf, peer_l, &net_l, rules_l, pipe_m2r, pipe_s2r);
io_pid = session_main(&conf, peer_l, pipe_m2s, pipe_s2r);
setproctitle("parent");
@@ -219,8 +222,8 @@ main(int argc, char *argv[])
free(net);
}
- for (r = TAILQ_FIRST(&rules_l); r != NULL; r = TAILQ_FIRST(&rules_l)) {
- TAILQ_REMOVE(&rules_l, r, entries);
+ while ((r = TAILQ_FIRST(rules_l)) != NULL) {
+ TAILQ_REMOVE(rules_l, r, entries);
free(r);
}
@@ -286,7 +289,7 @@ main(int argc, char *argv[])
if (reconfig) {
log_info("rereading config");
- reconfigure(conffile, &conf, &mrt_l, &peer_l, &rules_l);
+ reconfigure(conffile, &conf, &mrt_l, &peer_l, rules_l);
reconfig = 0;
}
@@ -316,6 +319,7 @@ main(int argc, char *argv[])
pid = waitpid(-1, NULL, WNOHANG);
} while (pid > 0 || (pid == -1 && errno == EINTR));
+ free(rules_l);
control_cleanup();
kr_shutdown();
@@ -381,7 +385,9 @@ reconfigure(char *conffile, struct bgpd_config *conf, struct mrt_head *mrt_l,
free(n);
}
for (r = TAILQ_FIRST(rules_l); r != NULL; r = TAILQ_FIRST(rules_l)) {
- /* XXX imsg_compose... */
+ if (imsg_compose(&ibuf_rde, IMSG_RECONF_FILTER, 0,
+ r, sizeof(struct filter_rule)) == -1)
+ return (-1);
TAILQ_REMOVE(rules_l, r, entries);
free(r);
}
diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h
index cf24aad2b1e..43d02ed777f 100644
--- a/usr.sbin/bgpd/bgpd.h
+++ b/usr.sbin/bgpd/bgpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: bgpd.h,v 1.91 2004/02/06 20:18:18 henning Exp $ */
+/* $OpenBSD: bgpd.h,v 1.92 2004/02/07 11:42:30 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -172,6 +172,7 @@ enum imsg_type {
IMSG_RECONF_CONF,
IMSG_RECONF_PEER,
IMSG_RECONF_NETWORK,
+ IMSG_RECONF_FILTER,
IMSG_RECONF_DONE,
IMSG_UPDATE,
IMSG_UPDATE_ERR,
diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c
index ae6bef42ba9..48867e9daab 100644
--- a/usr.sbin/bgpd/rde.c
+++ b/usr.sbin/bgpd/rde.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde.c,v 1.73 2004/02/02 19:14:11 deraadt Exp $ */
+/* $OpenBSD: rde.c,v 1.74 2004/02/07 11:42:30 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -65,6 +65,7 @@ struct bgpd_config *conf, *nconf;
time_t reloadtime;
struct rde_peer_head peerlist;
struct rde_peer peerself;
+struct filter_head *rules_l, *newrules;
struct imsgbuf ibuf_se;
struct imsgbuf ibuf_main;
@@ -88,7 +89,8 @@ u_long nexthophashsize = 64;
int
rde_main(struct bgpd_config *config, struct peer *peer_l,
- struct network_head *net_l, int pipe_m2r[2], int pipe_s2r[2])
+ struct network_head *net_l, struct filter_head *rules,
+ int pipe_m2r[2], int pipe_s2r[2])
{
pid_t pid;
struct passwd *pw;
@@ -138,7 +140,7 @@ rde_main(struct bgpd_config *config, struct peer *peer_l,
path_init(pathhashsize);
nexthop_init(nexthophashsize);
peer_init(peer_l, peerhashsize);
-
+ rules_l = rules;
network_init(net_l);
log_info("route decision engine ready");
@@ -230,6 +232,7 @@ rde_dispatch_imsg_parent(struct imsgbuf *ibuf)
struct mrt_config mrt;
struct peer_config *pconf;
struct rde_peer *p, *np;
+ struct filter_rule *r;
int n;
if ((n = imsg_read(ibuf)) == -1)
@@ -246,6 +249,10 @@ rde_dispatch_imsg_parent(struct imsgbuf *ibuf)
switch (imsg.hdr.type) {
case IMSG_RECONF_CONF:
reloadtime = time(NULL);
+ newrules = calloc(1, sizeof(struct filter_head));
+ if (newrules == NULL)
+ fatal(NULL);
+ TAILQ_INIT(newrules);
if ((nconf = malloc(sizeof(struct bgpd_config))) ==
NULL)
fatal(NULL);
@@ -263,6 +270,15 @@ rde_dispatch_imsg_parent(struct imsgbuf *ibuf)
case IMSG_RECONF_NETWORK:
network_add(imsg.data);
break;
+ case IMSG_RECONF_FILTER:
+ if (imsg.hdr.len - IMSG_HEADER_SIZE !=
+ sizeof(struct filter_rule))
+ fatalx("IMSG_RECONF_FILTER bad len");
+ if ((r = malloc(sizeof(struct filter_rule))) == NULL)
+ fatal(NULL);
+ memcpy(r, imsg.data, sizeof(struct filter_rule));
+ TAILQ_INSERT_TAIL(newrules, r, entries);
+ break;
case IMSG_RECONF_DONE:
if (nconf == NULL)
fatalx("got IMSG_RECONF_DONE but no config");
@@ -285,6 +301,12 @@ rde_dispatch_imsg_parent(struct imsgbuf *ibuf)
free(nconf);
nconf = NULL;
prefix_network_clean(&peerself, reloadtime);
+ while ((r = TAILQ_FIRST(rules_l)) != NULL) {
+ TAILQ_REMOVE(rules_l, r, entries);
+ free(r);
+ }
+ free(rules_l);
+ rules_l = newrules;
log_info("RDE reconfigured");
break;
case IMSG_NEXTHOP_UPDATE:
diff --git a/usr.sbin/bgpd/session.h b/usr.sbin/bgpd/session.h
index 3f19f3941d4..ffe02dd80f0 100644
--- a/usr.sbin/bgpd/session.h
+++ b/usr.sbin/bgpd/session.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.h,v 1.25 2004/02/06 20:18:18 henning Exp $ */
+/* $OpenBSD: session.h,v 1.26 2004/02/07 11:42:30 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -184,7 +184,7 @@ int merge_config(struct bgpd_config *, struct bgpd_config *,
/* rde.c */
int rde_main(struct bgpd_config *, struct peer *, struct network_head *,
- int[2], int[2]);
+ struct filter_head *, int[2], int[2]);
/* control.c */
int control_listen(void);