diff options
-rw-r--r-- | usr.sbin/ldpd/control.c | 28 | ||||
-rw-r--r-- | usr.sbin/ldpd/ldpd.c | 18 | ||||
-rw-r--r-- | usr.sbin/ldpd/ldpd.h | 10 | ||||
-rw-r--r-- | usr.sbin/ldpd/ldpe.c | 6 | ||||
-rw-r--r-- | usr.sbin/ldpd/neighbor.c | 6 | ||||
-rw-r--r-- | usr.sbin/ldpd/packet.c | 7 |
6 files changed, 21 insertions, 54 deletions
diff --git a/usr.sbin/ldpd/control.c b/usr.sbin/ldpd/control.c index 7a16254619d..34ca615f0f2 100644 --- a/usr.sbin/ldpd/control.c +++ b/usr.sbin/ldpd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.14 2014/07/11 16:43:33 krw Exp $ */ +/* $OpenBSD: control.c,v 1.15 2015/02/09 11:54:24 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -47,7 +47,8 @@ control_init(void) 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); } @@ -79,7 +80,6 @@ control_init(void) return (-1); } - session_socket_blockmode(fd, BM_NONBLOCK); control_fd = fd; return (0); @@ -113,7 +113,8 @@ control_accept(int listenfd, short event, void *bula) struct ctl_conn *c; len = sizeof(sun); - if ((connfd = accept(listenfd, (struct sockaddr *)&sun, &len)) == -1) { + if ((connfd = accept4(listenfd, (struct sockaddr *)&sun, &len, + SOCK_NONBLOCK | SOCK_CLOEXEC)) == -1) { /* * Pause accept if we are out of file descriptors, or * libevent will haunt us here too. @@ -126,8 +127,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); @@ -295,20 +294,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/ldpd/ldpd.c b/usr.sbin/ldpd/ldpd.c index 847c782d99a..77dd9535034 100644 --- a/usr.sbin/ldpd/ldpd.c +++ b/usr.sbin/ldpd/ldpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ldpd.c,v 1.21 2015/01/16 06:40:17 deraadt Exp $ */ +/* $OpenBSD: ldpd.c,v 1.22 2015/02/09 11:54:24 claudio Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -193,19 +193,15 @@ main(int argc, char *argv[]) log_info("startup"); - if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, - pipe_parent2ldpe) == -1) + if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, + PF_UNSPEC, pipe_parent2ldpe) == -1) fatal("socketpair"); - if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_parent2lde) == -1) + if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, + PF_UNSPEC, pipe_parent2lde) == -1) fatal("socketpair"); - if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_ldpe2lde) == -1) + if (socketpair(AF_UNIX, SOCK_STREAM |SOCK_NONBLOCK | SOCK_CLOEXEC, + PF_UNSPEC, pipe_ldpe2lde) == -1) fatal("socketpair"); - session_socket_blockmode(pipe_parent2ldpe[0], BM_NONBLOCK); - session_socket_blockmode(pipe_parent2ldpe[1], BM_NONBLOCK); - session_socket_blockmode(pipe_parent2lde[0], BM_NONBLOCK); - session_socket_blockmode(pipe_parent2lde[1], BM_NONBLOCK); - session_socket_blockmode(pipe_ldpe2lde[0], BM_NONBLOCK); - session_socket_blockmode(pipe_ldpe2lde[1], BM_NONBLOCK); /* start children */ lde_pid = lde(ldpd_conf, pipe_parent2lde, pipe_ldpe2lde, diff --git a/usr.sbin/ldpd/ldpd.h b/usr.sbin/ldpd/ldpd.h index b1a8d9d772e..1f091b7308e 100644 --- a/usr.sbin/ldpd/ldpd.h +++ b/usr.sbin/ldpd/ldpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ldpd.h,v 1.42 2013/06/04 02:34:48 claudio Exp $ */ +/* $OpenBSD: ldpd.h,v 1.43 2015/02/09 11:54:24 claudio Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -244,11 +244,6 @@ enum { PROC_LDE_ENGINE } ldpd_process; -enum blockmodes { - BM_NORMAL, - BM_NONBLOCK -}; - enum hello_type { HELLO_LINK, HELLO_TARGETED @@ -360,9 +355,6 @@ struct ctl_rt { struct ldpd_conf *parse_config(char *, int); int cmdline_symset(char *); -/* control.c */ -void session_socket_blockmode(int, enum blockmodes); - /* kroute.c */ int kif_init(void); void kif_redistribute(void); diff --git a/usr.sbin/ldpd/ldpe.c b/usr.sbin/ldpd/ldpe.c index e3323d9d4d9..01efffb9789 100644 --- a/usr.sbin/ldpd/ldpe.c +++ b/usr.sbin/ldpd/ldpe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ldpe.c,v 1.25 2014/11/18 20:54:28 krw Exp $ */ +/* $OpenBSD: ldpe.c,v 1.26 2015/02/09 11:54:24 claudio Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -154,7 +154,8 @@ ldpe(struct ldpd_conf *xconf, int pipe_parent2ldpe[2], int pipe_ldpe2lde[2], sess_addr.sin_port = htons(LDP_PORT); sess_addr.sin_addr.s_addr = INADDR_ANY; - if ((xconf->ldp_session_socket = socket(AF_INET, SOCK_STREAM, + if ((xconf->ldp_session_socket = socket(AF_INET, + SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, IPPROTO_TCP)) == -1) fatal("error creating session socket"); @@ -172,7 +173,6 @@ ldpe(struct ldpd_conf *xconf, int pipe_parent2ldpe[2], int pipe_ldpe2lde[2], if (if_set_tos(xconf->ldp_session_socket, IPTOS_PREC_INTERNETCONTROL) == -1) fatal("if_set_tos"); - session_socket_blockmode(xconf->ldp_session_socket, BM_NONBLOCK); if ((pw = getpwnam(LDPD_USER)) == NULL) fatal("getpwnam"); diff --git a/usr.sbin/ldpd/neighbor.c b/usr.sbin/ldpd/neighbor.c index 282d13e6bc8..db1bfbbff40 100644 --- a/usr.sbin/ldpd/neighbor.c +++ b/usr.sbin/ldpd/neighbor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: neighbor.c,v 1.43 2013/10/17 17:47:04 renato Exp $ */ +/* $OpenBSD: neighbor.c,v 1.44 2015/02/09 11:54:24 claudio Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -469,15 +469,13 @@ nbr_establish_connection(struct nbr *nbr) struct sockaddr_in remote_sa; struct adj *adj; - nbr->fd = socket(AF_INET, SOCK_STREAM, 0); + nbr->fd = socket(AF_INET, SOCK_STREAM|SOCK_NONBLOCK|SOCK_CLOEXEC, 0); if (nbr->fd == -1) { log_warn("nbr_establish_connection: error while " "creating socket"); return (-1); } - session_socket_blockmode(nbr->fd, BM_NONBLOCK); - bzero(&local_sa, sizeof(local_sa)); local_sa.sin_family = AF_INET; local_sa.sin_port = htons(0); diff --git a/usr.sbin/ldpd/packet.c b/usr.sbin/ldpd/packet.c index 957ae4ddc78..f7f5b5d4a83 100644 --- a/usr.sbin/ldpd/packet.c +++ b/usr.sbin/ldpd/packet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.c,v 1.36 2014/10/25 03:23:49 lteo Exp $ */ +/* $OpenBSD: packet.c,v 1.37 2015/02/09 11:54:24 claudio Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -267,7 +267,8 @@ session_accept(int fd, short event, void *bula) if (!(event & EV_READ)) return; - newfd = accept(fd, (struct sockaddr *)&src, &len); + newfd = accept4(fd, (struct sockaddr *)&src, &len, + SOCK_NONBLOCK | SOCK_CLOEXEC); if (newfd == -1) { /* * Pause accept if we are out of file descriptors, or @@ -282,8 +283,6 @@ session_accept(int fd, short event, void *bula) return; } - session_socket_blockmode(newfd, BM_NONBLOCK); - tcp_new(newfd, NULL); } |