diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2015-02-10 05:39:11 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2015-02-10 05:39:11 +0000 |
commit | 22e21cf760ba5bc3c9090a896b1828464943c11b (patch) | |
tree | 3dbce421c600d1ba6766d0516c2c724942a9a83a | |
parent | 9be8c964cf1951bedebfd1dd6dc01ffc093e2833 (diff) |
Same session_socket_blockmode() changes as done to ospfd. Also do the same
kroute change (make socket non-blocking and add trigger for partial reads).
-rw-r--r-- | usr.sbin/ospf6d/control.c | 29 | ||||
-rw-r--r-- | usr.sbin/ospf6d/control.h | 9 | ||||
-rw-r--r-- | usr.sbin/ospf6d/kroute.c | 10 | ||||
-rw-r--r-- | usr.sbin/ospf6d/ospf6d.c | 18 | ||||
-rw-r--r-- | usr.sbin/ospf6d/ospfe.c | 6 |
5 files changed, 24 insertions, 48 deletions
diff --git a/usr.sbin/ospf6d/control.c b/usr.sbin/ospf6d/control.c index 7251ba63080..b9d63249689 100644 --- a/usr.sbin/ospf6d/control.c +++ b/usr.sbin/ospf6d/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.22 2014/07/11 16:43:33 krw Exp $ */ +/* $OpenBSD: control.c,v 1.23 2015/02/10 05:39:10 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -45,7 +45,8 @@ control_init(char *path) int fd; mode_t old_umask; - if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { + if ((fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, + 0)) == -1) { log_warn("control_init: socket"); return (-1); } @@ -77,7 +78,6 @@ control_init(char *path) return (-1); } - session_socket_blockmode(fd, BM_NONBLOCK); control_state.fd = fd; return (0); @@ -122,8 +122,8 @@ control_accept(int listenfd, short event, void *bula) return; len = sizeof(sun); - if ((connfd = accept(listenfd, - (struct sockaddr *)&sun, &len)) == -1) { + if ((connfd = accept4(listenfd, (struct sockaddr *)&sun, &len, + SOCK_CLOEXEC | SOCK_NONBLOCK)) == -1) { /* * Pause accept if we are out of file descriptors, or * libevent will haunt us here too. @@ -139,8 +139,6 @@ control_accept(int listenfd, short event, void *bula) return; } - session_socket_blockmode(connfd, BM_NONBLOCK); - if ((c = calloc(1, sizeof(struct ctl_conn))) == NULL) { log_warn("control_accept"); close(connfd); @@ -321,20 +319,3 @@ control_imsg_relay(struct imsg *imsg) return (imsg_compose_event(&c->iev, imsg->hdr.type, 0, imsg->hdr.pid, -1, imsg->data, imsg->hdr.len - IMSG_HEADER_SIZE)); } - -void -session_socket_blockmode(int fd, enum blockmodes bm) -{ - int flags; - - if ((flags = fcntl(fd, F_GETFL, 0)) == -1) - fatal("fcntl F_GETFL"); - - if (bm == BM_NONBLOCK) - flags |= O_NONBLOCK; - else - flags &= ~O_NONBLOCK; - - if ((flags = fcntl(fd, F_SETFL, flags)) == -1) - fatal("fcntl F_SETFL"); -} diff --git a/usr.sbin/ospf6d/control.h b/usr.sbin/ospf6d/control.h index 939520faec1..c71a8189828 100644 --- a/usr.sbin/ospf6d/control.h +++ b/usr.sbin/ospf6d/control.h @@ -1,4 +1,4 @@ -/* $OpenBSD: control.h,v 1.4 2013/03/22 14:25:31 sthen Exp $ */ +/* $OpenBSD: control.h,v 1.5 2015/02/10 05:39:10 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -29,11 +29,6 @@ struct { int fd; } control_state; -enum blockmodes { - BM_NORMAL, - BM_NONBLOCK -}; - struct ctl_conn { TAILQ_ENTRY(ctl_conn) entry; struct imsgev iev; @@ -46,6 +41,4 @@ void control_dispatch_imsg(int, short, void *); int control_imsg_relay(struct imsg *); void control_cleanup(char *); -void session_socket_blockmode(int, enum blockmodes); - #endif /* _CONTROL_H_ */ diff --git a/usr.sbin/ospf6d/kroute.c b/usr.sbin/ospf6d/kroute.c index b1efa74c578..9cf6513036f 100644 --- a/usr.sbin/ospf6d/kroute.c +++ b/usr.sbin/ospf6d/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.45 2015/01/16 06:40:19 deraadt Exp $ */ +/* $OpenBSD: kroute.c,v 1.46 2015/02/10 05:39:10 claudio Exp $ */ /* * Copyright (c) 2004 Esben Norby <norby@openbsd.org> @@ -98,7 +98,8 @@ kr_init(int fs) kr_state.fib_sync = fs; - if ((kr_state.fd = socket(AF_ROUTE, SOCK_RAW, 0)) == -1) { + if ((kr_state.fd = socket(AF_ROUTE, + SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK, 0)) == -1) { log_warn("kr_init: socket"); return (-1); } @@ -1256,6 +1257,8 @@ dispatch_rtmsg(void) u_short ifindex = 0; 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); } @@ -1268,6 +1271,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/ospf6d/ospf6d.c b/usr.sbin/ospf6d/ospf6d.c index 1f18fc5270f..e4cacc72743 100644 --- a/usr.sbin/ospf6d/ospf6d.c +++ b/usr.sbin/ospf6d/ospf6d.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ospf6d.c,v 1.26 2015/01/16 06:40:19 deraadt Exp $ */ +/* $OpenBSD: ospf6d.c,v 1.27 2015/02/10 05:39:10 claudio Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -224,19 +224,15 @@ main(int argc, char *argv[]) log_info("startup"); - if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, - pipe_parent2ospfe) == -1) + if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, + PF_UNSPEC, pipe_parent2ospfe) == -1) fatal("socketpair"); - if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_parent2rde) == -1) + if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, + PF_UNSPEC, pipe_parent2rde) == -1) fatal("socketpair"); - if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_ospfe2rde) == -1) + if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, + PF_UNSPEC, pipe_ospfe2rde) == -1) fatal("socketpair"); - session_socket_blockmode(pipe_parent2ospfe[0], BM_NONBLOCK); - session_socket_blockmode(pipe_parent2ospfe[1], BM_NONBLOCK); - session_socket_blockmode(pipe_parent2rde[0], BM_NONBLOCK); - session_socket_blockmode(pipe_parent2rde[1], BM_NONBLOCK); - session_socket_blockmode(pipe_ospfe2rde[0], BM_NONBLOCK); - session_socket_blockmode(pipe_ospfe2rde[1], BM_NONBLOCK); /* start children */ rde_pid = rde(ospfd_conf, pipe_parent2rde, pipe_ospfe2rde, diff --git a/usr.sbin/ospf6d/ospfe.c b/usr.sbin/ospf6d/ospfe.c index 15329abe570..1d678bae86e 100644 --- a/usr.sbin/ospf6d/ospfe.c +++ b/usr.sbin/ospf6d/ospfe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfe.c,v 1.44 2014/11/18 20:54:28 krw Exp $ */ +/* $OpenBSD: ospfe.c,v 1.45 2015/02/10 05:39:10 claudio Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -93,8 +93,8 @@ ospfe(struct ospfd_conf *xconf, int pipe_parent2ospfe[2], int pipe_ospfe2rde[2], fatalx("control socket setup failed"); /* create the raw ip socket */ - if ((xconf->ospf_socket = socket(AF_INET6, SOCK_RAW, - IPPROTO_OSPF)) == -1) + if ((xconf->ospf_socket = socket(AF_INET6, + SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK, IPPROTO_OSPF)) == -1) fatal("error creating raw socket"); /* set some defaults */ |