summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2015-02-10 05:18:40 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2015-02-10 05:18:40 +0000
commitb4218cc65b63357cc69f467f1f4fdf296f0fe118 (patch)
treea376f2c118337cd549700947e6bca78596b95f73 /usr.sbin
parente2eb1b648b732f54dd3da111a6fb0268d806da04 (diff)
Make also the special sockets SOCK_NONBLOCK. For the routing socket add
a trigger for the case that not a full message has been read. Should not be possible but lets see if this triggers somewhen. With and OK henning@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/bgpd/kroute.c11
-rw-r--r--usr.sbin/bgpd/pfkey.c9
2 files changed, 15 insertions, 5 deletions
diff --git a/usr.sbin/bgpd/kroute.c b/usr.sbin/bgpd/kroute.c
index 0c4f3720a8f..b309656fc15 100644
--- a/usr.sbin/bgpd/kroute.c
+++ b/usr.sbin/bgpd/kroute.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kroute.c,v 1.200 2015/02/09 11:37:31 claudio Exp $ */
+/* $OpenBSD: kroute.c,v 1.201 2015/02/10 05:18:39 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -199,8 +199,8 @@ kr_init(void)
unsigned int tid = RTABLE_ANY;
socklen_t optlen;
- if ((kr_state.fd = socket(AF_ROUTE, SOCK_RAW | SOCK_CLOEXEC,
- 0)) == -1) {
+ if ((kr_state.fd = socket(AF_ROUTE,
+ SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK, 0)) == -1) {
log_warn("kr_init: socket");
return (-1);
}
@@ -3024,6 +3024,8 @@ dispatch_rtmsg(void)
struct ktable *kt;
if ((n = read(kr_state.fd, &buf, sizeof(buf))) == -1) {
+ if (errno == EAGAIN || errno == EINTR)
+ return (0);
log_warn("dispatch_rtmsg: read error");
return (-1);
}
@@ -3036,6 +3038,9 @@ dispatch_rtmsg(void)
lim = buf + n;
for (next = buf; next < lim; next += rtm->rtm_msglen) {
rtm = (struct rt_msghdr *)next;
+ if (lim < next + sizeof(*rtm) ||
+ lim < next + rtm->rtm_msglen)
+ fatalx("dispatch_rtmsg: partial rtm in buffer");
if (rtm->rtm_version != RTM_VERSION)
continue;
diff --git a/usr.sbin/bgpd/pfkey.c b/usr.sbin/bgpd/pfkey.c
index af97d4777f0..1017cc02dfc 100644
--- a/usr.sbin/bgpd/pfkey.c
+++ b/usr.sbin/bgpd/pfkey.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfkey.c,v 1.43 2015/02/09 11:37:31 claudio Exp $ */
+/* $OpenBSD: pfkey.c,v 1.44 2015/02/10 05:18:39 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -407,6 +407,8 @@ pfkey_read(int sd, struct sadb_msg *h)
struct sadb_msg hdr;
if (recv(sd, &hdr, sizeof(hdr), MSG_PEEK) != sizeof(hdr)) {
+ if (errno == EAGAIN || errno == EINTR)
+ return (0);
log_warn("pfkey peek");
return (-1);
}
@@ -421,6 +423,8 @@ pfkey_read(int sd, struct sadb_msg *h)
/* not ours, discard */
if (read(sd, &hdr, sizeof(hdr)) == -1) {
+ if (errno == EAGAIN || errno == EINTR)
+ return (0);
log_warn("pfkey read");
return (-1);
}
@@ -734,7 +738,8 @@ pfkey_remove(struct peer *p)
int
pfkey_init(struct bgpd_sysdep *sysdep)
{
- if ((fd = socket(PF_KEY, SOCK_RAW | SOCK_CLOEXEC, PF_KEY_V2)) == -1) {
+ if ((fd = socket(PF_KEY, SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK,
+ PF_KEY_V2)) == -1) {
if (errno == EPROTONOSUPPORT) {
log_warnx("PF_KEY not available, disabling ipsec");
sysdep->no_pfkey = 1;