summaryrefslogtreecommitdiff
path: root/usr.sbin/ripd
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2007-10-24 19:05:07 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2007-10-24 19:05:07 +0000
commitb191dbcad5cabfb39e7e9ed382fc88b2cf5c00cc (patch)
treee58beccfe8946b28c215b8d85e910e5f8bc0f762 /usr.sbin/ripd
parentc714cacd141cf760172df4ee096001cc2d89a2e4 (diff)
Sync a bit more with ospfd. Do not fatal if one of the pipes is closed,
instead do a "nice" shutdown. Ignore SIGHUP in the childs even though we have no reload support (yet). Remove some redundant code and clean up some types.
Diffstat (limited to 'usr.sbin/ripd')
-rw-r--r--usr.sbin/ripd/rde.c34
-rw-r--r--usr.sbin/ripd/ripd.c24
-rw-r--r--usr.sbin/ripd/ripe.c30
3 files changed, 63 insertions, 25 deletions
diff --git a/usr.sbin/ripd/rde.c b/usr.sbin/ripd/rde.c
index b7152bf7ec1..1f98731b106 100644
--- a/usr.sbin/ripd/rde.c
+++ b/usr.sbin/ripd/rde.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde.c,v 1.7 2007/10/18 17:00:59 deraadt Exp $ */
+/* $OpenBSD: rde.c,v 1.8 2007/10/24 19:05:06 claudio Exp $ */
/*
* Copyright (c) 2006 Michele Marchetto <mydecay@openbeer.it>
@@ -115,6 +115,7 @@ rde(struct ripd_conf *xconf, int pipe_parent2rde[2], int pipe_ripe2rde[2],
signal_add(&ev_sigint, NULL);
signal_add(&ev_sigterm, NULL);
signal(SIGPIPE, SIG_IGN);
+ signal(SIGHUP, SIG_IGN);
/* setup pipes */
close(pipe_ripe2rde[0]);
@@ -169,7 +170,6 @@ rde_shutdown(void)
_exit(0);
}
-/* imesg */
int
rde_imsg_compose_ripe(int type, u_int32_t peerid, pid_t pid, void *data,
u_int16_t datalen)
@@ -184,14 +184,15 @@ rde_dispatch_imsg(int fd, short event, void *bula)
struct imsgbuf *ibuf = bula;
struct rip_route rr;
struct imsg imsg;
- int n;
+ ssize_t n;
+ int shut = 0;
switch (event) {
case EV_READ:
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read error");
if (n == 0) /* connection closed */
- fatalx("pipe closed");
+ shut = 1;
break;
case EV_WRITE:
if (msgbuf_write(&ibuf->w) == -1)
@@ -265,7 +266,13 @@ rde_dispatch_imsg(int fd, short event, void *bula)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ if (!shut)
+ imsg_event_add(ibuf);
+ else {
+ /* this pipe is dead, so remove the event handler */
+ event_del(&ibuf->ev);
+ event_loopexit(NULL);
+ }
}
/* ARGSUSED */
@@ -277,13 +284,14 @@ rde_dispatch_parent(int fd, short event, void *bula)
struct kroute kr;
struct imsgbuf *ibuf = bula;
ssize_t n;
+ int shut = 0;
switch (event) {
case EV_READ:
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read error");
if (n == 0) /* connection closed */
- fatalx("pipe closed");
+ shut = 1;
break;
case EV_WRITE:
if (msgbuf_write(&ibuf->w) == -1)
@@ -346,7 +354,13 @@ rde_dispatch_parent(int fd, short event, void *bula)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ if (!shut)
+ imsg_event_add(ibuf);
+ else {
+ /* this pipe is dead, so remove the event handler */
+ event_del(&ibuf->ev);
+ event_loopexit(NULL);
+ }
}
void
@@ -391,11 +405,7 @@ rde_check_route(struct rip_route *e)
if ((e->nexthop.s_addr & htonl(IN_CLASSA_NET)) ==
htonl(INADDR_LOOPBACK & IN_CLASSA_NET) ||
- (e->nexthop.s_addr == INADDR_ANY))
- return (-1);
-
- if ((e->address.s_addr & htonl(IN_CLASSA_NET)) ==
- htonl(INADDR_LOOPBACK & IN_CLASSA_NET))
+ e->nexthop.s_addr == INADDR_ANY)
return (-1);
if ((iface = if_find_index(e->ifindex)) == NULL)
diff --git a/usr.sbin/ripd/ripd.c b/usr.sbin/ripd/ripd.c
index 3ba9406f1ba..6acca39ce2b 100644
--- a/usr.sbin/ripd/ripd.c
+++ b/usr.sbin/ripd/ripd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ripd.c,v 1.6 2007/10/20 13:26:50 pyr Exp $ */
+/* $OpenBSD: ripd.c,v 1.7 2007/10/24 19:05:06 claudio Exp $ */
/*
* Copyright (c) 2006 Michele Marchetto <mydecay@openbeer.it>
@@ -327,13 +327,14 @@ main_dispatch_ripe(int fd, short event, void *bula)
struct imsgbuf *ibuf = bula;
struct imsg imsg;
ssize_t n;
+ int shut = 0;
switch (event) {
case EV_READ:
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read error");
if (n == 0) /* connection closed */
- fatalx("pipe closed");
+ shut = 1;
break;
case EV_WRITE:
if (msgbuf_write(&ibuf->w) == -1)
@@ -380,7 +381,13 @@ main_dispatch_ripe(int fd, short event, void *bula)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ if (!shut)
+ imsg_event_add(ibuf);
+ else {
+ /* this pipe is dead, so remove the event handler */
+ event_del(&ibuf->ev);
+ event_loopexit(NULL);
+ }
}
/* ARGSUSED */
@@ -390,13 +397,14 @@ main_dispatch_rde(int fd, short event, void *bula)
struct imsgbuf *ibuf = bula;
struct imsg imsg;
ssize_t n;
+ int shut = 0;
switch (event) {
case EV_READ:
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read error");
if (n == 0) /* connection closed */
- fatalx("pipe closed");
+ shut = 1;
break;
case EV_WRITE:
if (msgbuf_write(&ibuf->w) == -1)
@@ -432,7 +440,13 @@ main_dispatch_rde(int fd, short event, void *bula)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ if (!shut)
+ imsg_event_add(ibuf);
+ else {
+ /* this pipe is dead, so remove the event handler */
+ event_del(&ibuf->ev);
+ event_loopexit(NULL);
+ }
}
void
diff --git a/usr.sbin/ripd/ripe.c b/usr.sbin/ripd/ripe.c
index 559a32fd557..25a5664d842 100644
--- a/usr.sbin/ripd/ripe.c
+++ b/usr.sbin/ripd/ripe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ripe.c,v 1.5 2007/01/08 13:01:10 claudio Exp $ */
+/* $OpenBSD: ripe.c,v 1.6 2007/10/24 19:05:06 claudio Exp $ */
/*
* Copyright (c) 2006 Michele Marchetto <mydecay@openbeer.it>
@@ -143,6 +143,7 @@ ripe(struct ripd_conf *xconf, int pipe_parent2ripe[2], int pipe_ripe2rde[2],
signal_add(&ev_sigint, NULL);
signal_add(&ev_sigterm, NULL);
signal(SIGPIPE, SIG_IGN);
+ signal(SIGHUP, SIG_IGN);
/* setup pipes */
close(pipe_parent2ripe[0]);
@@ -204,7 +205,6 @@ ripe(struct ripd_conf *xconf, int pipe_parent2ripe[2], int pipe_ripe2rde[2],
return (0);
}
-/* imesg */
int
ripe_imsg_compose_parent(int type, pid_t pid, void *data, u_int16_t datalen)
{
@@ -224,16 +224,17 @@ ripe_dispatch_main(int fd, short event, void *bula)
{
struct imsg imsg;
struct imsgbuf *ibuf = bula;
- int n, link_ok;
struct kif *kif;
struct iface *iface;
+ ssize_t n;
+ int link_ok, shut = 0;
switch (event) {
case EV_READ:
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read error");
if (n == 0) /* connection closed */
- fatalx("pipe closed");
+ shut = 1;
break;
case EV_WRITE:
if (msgbuf_write(&ibuf->w) == -1)
@@ -291,7 +292,13 @@ ripe_dispatch_main(int fd, short event, void *bula)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ if (!shut)
+ imsg_event_add(ibuf);
+ else {
+ /* this pipe is dead, so remove the event handler */
+ event_del(&ibuf->ev);
+ event_loopexit(NULL);
+ }
}
/* ARGSUSED */
@@ -303,14 +310,15 @@ ripe_dispatch_rde(int fd, short event, void *bula)
struct imsgbuf *ibuf = bula;
struct iface *iface;
struct nbr *nbr;
- int n;
+ ssize_t n;
+ int shut = 0;
switch (event) {
case EV_READ:
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read error");
if (n == 0) /* connection closed */
- fatalx("pipe closed");
+ shut = 1;
break;
case EV_WRITE:
if (msgbuf_write(&ibuf->w) == -1)
@@ -444,7 +452,13 @@ ripe_dispatch_rde(int fd, short event, void *bula)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ if (!shut)
+ imsg_event_add(ibuf);
+ else {
+ /* this pipe is dead, so remove the event handler */
+ event_del(&ibuf->ev);
+ event_loopexit(NULL);
+ }
}
void