summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReyk Floeter <reyk@cvs.openbsd.org>2015-11-23 19:28:35 +0000
committerReyk Floeter <reyk@cvs.openbsd.org>2015-11-23 19:28:35 +0000
commit2bfadaff0e5648be7030c20df9542a615ec8496a (patch)
treea22db61ef28a750b8f940b6b0581ce214bb524f8
parentc2f4f4e14bdbbe058f3635a258a5996514f45861 (diff)
Replace socket_set_blockmode() and fcntl(fd, F_SETFL, O_NONBLOCK) calls
with the SOCK_NONBLOCK flag to socket() and accept4(). OK claudio@ jung@
-rw-r--r--sbin/iked/control.c11
-rw-r--r--sbin/iked/iked.h3
-rw-r--r--sbin/iked/ocsp.c5
-rw-r--r--sbin/iked/proc.c8
-rw-r--r--sbin/iked/types.h7
-rw-r--r--sbin/iked/util.c22
6 files changed, 14 insertions, 42 deletions
diff --git a/sbin/iked/control.c b/sbin/iked/control.c
index 39e82102fb9..e08a2b9a666 100644
--- a/sbin/iked/control.c
+++ b/sbin/iked/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.19 2015/10/22 15:55:18 reyk Exp $ */
+/* $OpenBSD: control.c,v 1.20 2015/11/23 19:28:33 reyk Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
@@ -83,7 +83,7 @@ control_init(struct privsep *ps, struct control_sock *cs)
if (cs->cs_name == NULL)
return (0);
- if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
+ if ((fd = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0)) == -1) {
log_warn("%s: socket", __func__);
return (-1);
}
@@ -126,7 +126,6 @@ control_init(struct privsep *ps, struct control_sock *cs)
return (-1);
}
- socket_set_blockmode(fd, BM_NONBLOCK);
cs->cs_fd = fd;
cs->cs_env = env;
@@ -177,8 +176,8 @@ control_accept(int listenfd, short event, void *arg)
return;
len = sizeof(sun);
- if ((connfd = accept(listenfd,
- (struct sockaddr *)&sun, &len)) == -1) {
+ if ((connfd = accept4(listenfd,
+ (struct sockaddr *)&sun, &len, SOCK_NONBLOCK)) == -1) {
/*
* Pause accept if we are out of file descriptors, or
* libevent will haunt us here too.
@@ -194,8 +193,6 @@ control_accept(int listenfd, short event, void *arg)
return;
}
- socket_set_blockmode(connfd, BM_NONBLOCK);
-
if ((c = calloc(1, sizeof(struct ctl_conn))) == NULL) {
log_warn("%s", __func__);
close(connfd);
diff --git a/sbin/iked/iked.h b/sbin/iked/iked.h
index 6c1ef683032..1a833acc66b 100644
--- a/sbin/iked/iked.h
+++ b/sbin/iked/iked.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: iked.h,v 1.93 2015/11/22 13:27:13 reyk Exp $ */
+/* $OpenBSD: iked.h,v 1.94 2015/11/23 19:28:34 reyk Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
@@ -881,7 +881,6 @@ struct imsgev *
proc_iev(struct privsep *, enum privsep_procid, int);
/* util.c */
-void socket_set_blockmode(int, enum blockmodes);
int socket_af(struct sockaddr *, in_port_t);
in_port_t
socket_getport(struct sockaddr *);
diff --git a/sbin/iked/ocsp.c b/sbin/iked/ocsp.c
index 37356d8049d..11f9349520e 100644
--- a/sbin/iked/ocsp.c
+++ b/sbin/iked/ocsp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ocsp.c,v 1.6 2015/08/21 11:59:27 reyk Exp $ */
+/* $OpenBSD: ocsp.c,v 1.7 2015/11/23 19:28:34 reyk Exp $ */
/*
* Copyright (c) 2014 Markus Friedl
@@ -88,7 +88,7 @@ ocsp_connect(struct iked *env)
goto done;
}
- if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
+ if ((fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0)) < 0) {
log_debug("%s: socket failed", __func__);
goto done;
}
@@ -122,7 +122,6 @@ ocsp_connect(struct iked *env)
path = NULL;
log_debug("%s: connect(%s, %s)", __func__, host, port);
- socket_set_blockmode(fd, BM_NONBLOCK);
if (connect(fd, res->ai_addr, res->ai_addrlen) == -1) {
/* register callback for ansync connect */
if (errno == EINPROGRESS) {
diff --git a/sbin/iked/proc.c b/sbin/iked/proc.c
index 8554b7c353b..c6948d9a129 100644
--- a/sbin/iked/proc.c
+++ b/sbin/iked/proc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: proc.c,v 1.25 2015/11/22 13:27:13 reyk Exp $ */
+/* $OpenBSD: proc.c,v 1.26 2015/11/23 19:28:34 reyk Exp $ */
/*
* Copyright (c) 2010 - 2014 Reyk Floeter <reyk@openbsd.org>
@@ -178,13 +178,11 @@ proc_open(struct privsep *ps, struct privsep_proc *p,
if (pa->pp_pipes[procs[proc].p_id][j] != -1)
continue;
- if (socketpair(AF_UNIX, SOCK_STREAM,
+ if (socketpair(AF_UNIX,
+ SOCK_STREAM | SOCK_NONBLOCK,
PF_UNSPEC, fds) == -1)
fatal("socketpair");
- socket_set_blockmode(fds[0], BM_NONBLOCK);
- socket_set_blockmode(fds[1], BM_NONBLOCK);
-
pa->pp_pipes[procs[proc].p_id][j] = fds[0];
pb->pp_pipes[src][i] = fds[1];
}
diff --git a/sbin/iked/types.h b/sbin/iked/types.h
index 9c3be522067..79b2d32d9ec 100644
--- a/sbin/iked/types.h
+++ b/sbin/iked/types.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: types.h,v 1.23 2015/10/22 15:55:18 reyk Exp $ */
+/* $OpenBSD: types.h,v 1.24 2015/11/23 19:28:34 reyk Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
@@ -119,11 +119,6 @@ enum privsep_procid {
PROC_MAX
};
-enum blockmodes {
- BM_NORMAL,
- BM_NONBLOCK
-};
-
enum flushmode {
RESET_RELOAD = 0,
RESET_ALL,
diff --git a/sbin/iked/util.c b/sbin/iked/util.c
index 15786a6ab26..bb6ae62fd4f 100644
--- a/sbin/iked/util.c
+++ b/sbin/iked/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.29 2015/11/21 12:59:24 reyk Exp $ */
+/* $OpenBSD: util.c,v 1.30 2015/11/23 19:28:34 reyk Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
@@ -39,23 +39,6 @@
extern int debug;
extern int verbose;
-void
-socket_set_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");
-}
-
int
socket_af(struct sockaddr *sa, in_port_t port)
{
@@ -187,7 +170,8 @@ udp_bind(struct sockaddr *sa, in_port_t port)
return (-1);
}
- if ((s = socket(sa->sa_family, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
+ if ((s = socket(sa->sa_family,
+ SOCK_DGRAM | SOCK_NONBLOCK, IPPROTO_UDP)) == -1) {
log_warn("%s: failed to get UDP socket", __func__);
return (-1);
}