diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2010-04-15 15:04:24 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2010-04-15 15:04:24 +0000 |
commit | c1819b1f795527a74b4694473fc2f99536b19b8e (patch) | |
tree | 63653833f6340c4e6ff929030c819724735d96d4 /usr.sbin/ldpd | |
parent | 212b26394887ee3c41510adacde36bc5c0ebfa21 (diff) |
Instead of having three ways of setting fds non-blocking use
session_socket_blockmode() everywhere.
Additionally make two fatal() distinguishable.
OK michele@
Diffstat (limited to 'usr.sbin/ldpd')
-rw-r--r-- | usr.sbin/ldpd/control.h | 9 | ||||
-rw-r--r-- | usr.sbin/ldpd/interface.c | 14 | ||||
-rw-r--r-- | usr.sbin/ldpd/ldpd.h | 10 | ||||
-rw-r--r-- | usr.sbin/ldpd/ldpe.c | 9 | ||||
-rw-r--r-- | usr.sbin/ldpd/ldpe.h | 3 | ||||
-rw-r--r-- | usr.sbin/ldpd/packet.c | 7 |
6 files changed, 18 insertions, 34 deletions
diff --git a/usr.sbin/ldpd/control.h b/usr.sbin/ldpd/control.h index 76a9b41afee..7468b636500 100644 --- a/usr.sbin/ldpd/control.h +++ b/usr.sbin/ldpd/control.h @@ -1,4 +1,4 @@ -/* $OpenBSD: control.h,v 1.2 2009/06/06 08:09:43 pyr Exp $ */ +/* $OpenBSD: control.h,v 1.3 2010/04/15 15:04:23 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -28,11 +28,6 @@ struct { int fd; } control_state; -enum blockmodes { - BM_NORMAL, - BM_NONBLOCK -}; - struct ctl_conn { TAILQ_ENTRY(ctl_conn) entry; struct imsgev iev; @@ -45,6 +40,4 @@ void control_dispatch_imsg(int, short, void *); int control_imsg_relay(struct imsg *); void control_cleanup(void); -void session_socket_blockmode(int, enum blockmodes); - #endif /* _CONTROL_H_ */ diff --git a/usr.sbin/ldpd/interface.c b/usr.sbin/ldpd/interface.c index a7dc36147f5..0bb2d90d441 100644 --- a/usr.sbin/ldpd/interface.c +++ b/usr.sbin/ldpd/interface.c @@ -1,4 +1,4 @@ -/* $OpenBSD: interface.c,v 1.2 2010/02/18 10:50:14 claudio Exp $ */ +/* $OpenBSD: interface.c,v 1.3 2010/04/15 15:04:23 claudio Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -440,18 +440,6 @@ if_set_reuse(int fd, int enable) return (0); } -int -if_set_nonblock(int fd) -{ - if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) { - log_warn("if_set_nonblock: error setting O_NONBLOCK"); - return (-1); - } - - return (0); -} - - /* * only one JOIN or DROP per interface and address is allowed so we need * to keep track of what is added and removed. diff --git a/usr.sbin/ldpd/ldpd.h b/usr.sbin/ldpd/ldpd.h index 9a87a78560c..8b7bf5ece01 100644 --- a/usr.sbin/ldpd/ldpd.h +++ b/usr.sbin/ldpd/ldpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ldpd.h,v 1.11 2010/03/03 10:17:05 claudio Exp $ */ +/* $OpenBSD: ldpd.h,v 1.12 2010/04/15 15:04:23 claudio Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -240,6 +240,11 @@ enum { PROC_LDE_ENGINE } ldpd_process; +enum blockmodes { + BM_NORMAL, + BM_NONBLOCK +}; + #define MODE_DIST_INDEPENDENT 0x01 #define MODE_DIST_ORDERED 0x02 #define MODE_RET_LIBERAL 0x04 @@ -391,6 +396,9 @@ struct ctl_sum_lspace { struct ldpd_conf *parse_config(char *, int); int cmdline_symset(char *); +/* control.c */ +void session_socket_blockmode(int, enum blockmodes); + /* in_cksum.c */ u_int16_t in_cksum(void *, size_t); diff --git a/usr.sbin/ldpd/ldpe.c b/usr.sbin/ldpd/ldpe.c index 68b3f2061a8..7910a5a2119 100644 --- a/usr.sbin/ldpd/ldpe.c +++ b/usr.sbin/ldpd/ldpe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ldpe.c,v 1.5 2010/02/25 17:40:46 claudio Exp $ */ +/* $OpenBSD: ldpe.c,v 1.6 2010/04/15 15:04:23 claudio Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -140,8 +140,7 @@ 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"); - if (if_set_nonblock(xconf->ldp_session_socket) == -1) - fatal("if_set_nonblock"); + session_socket_blockmode(xconf->ldp_session_socket, BM_NONBLOCK); leconf = xconf; if (leconf->flags & LDPD_FLAG_NO_LFIB_UPDATE) @@ -293,7 +292,7 @@ ldpe_dispatch_main(int fd, short event, void *bula) } if (event & EV_WRITE) { if (msgbuf_write(&ibuf->w) == -1) - fatal("msgbuf_write"); + fatal("ldpe_dispatch_main: msgbuf_write"); } for (;;) { @@ -384,7 +383,7 @@ ldpe_dispatch_lde(int fd, short event, void *bula) } if (event & EV_WRITE) { if (msgbuf_write(&ibuf->w) == -1) - fatal("msgbuf_write"); + fatal("ldpe_dispatch_lde: msgbuf_write"); } for (;;) { diff --git a/usr.sbin/ldpd/ldpe.h b/usr.sbin/ldpd/ldpe.h index 8c709d0f0e1..fd2eb3d330c 100644 --- a/usr.sbin/ldpd/ldpe.h +++ b/usr.sbin/ldpd/ldpe.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ldpe.h,v 1.6 2010/02/25 17:40:46 claudio Exp $ */ +/* $OpenBSD: ldpe.h,v 1.7 2010/04/15 15:04:23 claudio Exp $ */ /* * Copyright (c) 2004, 2005, 2008 Esben Norby <norby@openbsd.org> @@ -145,7 +145,6 @@ int if_set_mcast_loop(int); int if_set_mcast_ttl(int, u_int8_t); int if_set_tos(int, int); int if_set_reuse(int, int); -int if_set_nonblock(int); /* neighbor.c */ void nbr_init(u_int32_t); diff --git a/usr.sbin/ldpd/packet.c b/usr.sbin/ldpd/packet.c index 7e7e1d46149..7e08cdf125b 100644 --- a/usr.sbin/ldpd/packet.c +++ b/usr.sbin/ldpd/packet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.c,v 1.5 2010/03/26 16:00:09 claudio Exp $ */ +/* $OpenBSD: packet.c,v 1.6 2010/04/15 15:04:23 claudio Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -283,10 +283,7 @@ session_accept(int fd, short event, void *bula) return; } - if (fcntl(newfd, F_SETFL, O_NONBLOCK) == -1) { - log_debug("sess_recv_packet: unable to set non blocking flag"); - return; - } + session_socket_blockmode(newfd, BM_NONBLOCK); if ((iface = session_find_iface(xconf, src.sin_addr)) == NULL) { log_debug("sess_recv_packet: cannot find a matching interface"); |