From bafa76b324e2336d707a158cccdb309df30bca65 Mon Sep 17 00:00:00 2001 From: Shawn Routhier Date: Thu, 1 Oct 2009 01:30:01 +0000 Subject: [PATCH] Updates to fdwatch code to support DHCP/DDNS code, ticket rt20253. --- CHANGES | 7 ++++++ lib/isc/include/isc/msgs.h | 4 +-- lib/isc/include/isc/namespace.h | 5 ++-- lib/isc/include/isc/socket.h | 37 ++++++++++++++++++++++++++- lib/isc/include/isc/types.h | 4 +-- lib/isc/socket_api.c | 22 ++++++++++++++++- lib/isc/unix/socket.c | 44 ++++++++++++++++++++++++++++----- 7 files changed, 109 insertions(+), 14 deletions(-) diff --git a/CHANGES b/CHANGES index c23002338e..0e32dd900e 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,10 @@ +2695. [func] DHCP/DDNS - update fdwatch code for use by + DHCP. Modify the api to isc_sockfdwatch_t (the + callback funciton for isc_socket_fdwatchcreate) + to include information about the direction (read + or write) and add isc_socket_fdwatchpoke. + [RT #20253] + 2694. [bug] Reduce default NSEC3 iterations from 100 to 10. [RT #19970] diff --git a/lib/isc/include/isc/msgs.h b/lib/isc/include/isc/msgs.h index d8f2787a28..14d0967a1d 100644 --- a/lib/isc/include/isc/msgs.h +++ b/lib/isc/include/isc/msgs.h @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: msgs.h,v 1.17 2008/08/08 06:28:59 tbox Exp $ */ +/* $Id: msgs.h,v 1.18 2009/10/01 01:30:01 sar Exp $ */ #ifndef ISC_MSGS_H #define ISC_MSGS_H 1 @@ -156,7 +156,7 @@ #define ISC_MSG_FILTER 1421 /*%< setsockopt(SO_ACCEPTFILTER): %s */ #define ISC_MSG_TOOMANYHANDLES 1422 /*%< %s: too many open WSA event handles: %s */ - +#define ISC_MSG_POKED 1423 /*%< "poked flags: %d" */ #define ISC_MSG_AWAKE 1502 /*%< "awake" */ #define ISC_MSG_WORKING 1503 /*%< "working" */ diff --git a/lib/isc/include/isc/namespace.h b/lib/isc/include/isc/namespace.h index 33ec63a38f..4fa05ac4ef 100644 --- a/lib/isc/include/isc/namespace.h +++ b/lib/isc/include/isc/namespace.h @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: namespace.h,v 1.4 2009/09/02 23:48:03 tbox Exp $ */ +/* $Id: namespace.h,v 1.5 2009/10/01 01:30:01 sar Exp $ */ #ifndef ISCAPI_NAMESPACE_H #define ISCAPI_NAMESPACE_H 1 @@ -109,7 +109,6 @@ #define isc_socket_listen isc__socket_listen #define isc_socket_accept isc__socket_accept #define isc_socket_connect isc__socket_connect -#define isc_socket_fdwatchcreate isc__socket_fdwatchcreate #define isc_socket_getname isc__socket_getname #define isc_socket_gettag isc__socket_gettag #define isc_socket_getpeername isc__socket_getpeername @@ -123,6 +122,8 @@ #define isc_socketmgr_setstats isc__socketmgr_setstats #define isc_socketmgr_setreserved isc__socketmgr_setreserved #define isc__socketmgr_maxudp isc___socketmgr_maxudp +#define isc_socket_fdwatchcreate isc__socket_fdwatchcreate +#define isc_socket_fdwatchpoke isc__socket_fdwatchpoke #define isc_task_create isc__task_create #define isc_task_attach isc__task_attach diff --git a/lib/isc/include/isc/socket.h b/lib/isc/include/isc/socket.h index 376dcc09ad..c4ab0e2959 100644 --- a/lib/isc/include/isc/socket.h +++ b/lib/isc/include/isc/socket.h @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: socket.h,v 1.93 2009/09/02 23:43:54 each Exp $ */ +/* $Id: socket.h,v 1.94 2009/10/01 01:30:01 sar Exp $ */ #ifndef ISC_SOCKET_H #define ISC_SOCKET_H 1 @@ -266,6 +266,11 @@ typedef struct isc_socketmgrmethods { isc_result_t (*socketcreate)(isc_socketmgr_t *manager, int pf, isc_sockettype_t type, isc_socket_t **socketp); + isc_result_t (*fdwatchcreate)(isc_socketmgr_t *manager, int fd, + int flags, + isc_sockfdwatch_t callback, + void *cbarg, isc_task_t *task, + isc_socket_t **socketp); } isc_socketmgrmethods_t; typedef struct isc_socketmethods { @@ -290,6 +295,7 @@ typedef struct isc_socketmethods { isc_sockaddr_t *addressp); isc_sockettype_t (*gettype)(isc_socket_t *sock); void (*ipv6only)(isc_socket_t *sock, isc_boolean_t yes); + isc_result_t (*fdwatchpoke)(isc_socket_t *sock, int flags); } isc_socketmethods_t; /*% @@ -379,6 +385,35 @@ isc_socket_fdwatchcreate(isc_socketmgr_t *manager, *\li #ISC_R_UNEXPECTED */ +isc_result_t +isc_socket_fdwatchpoke(isc_socket_t *sock, + int flags); +/*%< + * Poke a file descriptor watch socket informing the manager that it + * should restart watching the socket + * + * Note: + * + *\li 'sock' is the socket returned by isc_socket_fdwatchcreate + * + *\li 'flags' indicates what the manager should watch for on the socket + * in addition to what it may already be watching. It can be one or + * both of ISC_SOCKFDWATCH_READ and ISC_SOCKFDWATCH_WRITE. To + * temporarily disable watching on a socket the value indicating + * no more data should be returned from the call back routine. + * + *\li This function is not available on Windows. + * + * Requires: + * + *\li 'sock' is a valid isc socket + * + * + * Returns: + * + *\li #ISC_R_SUCCESS + */ + isc_result_t isc_socket_create(isc_socketmgr_t *manager, int pf, diff --git a/lib/isc/include/isc/types.h b/lib/isc/include/isc/types.h index 03ada89a1c..906bad176f 100644 --- a/lib/isc/include/isc/types.h +++ b/lib/isc/include/isc/types.h @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: types.h,v 1.50 2009/09/01 18:40:25 jinmei Exp $ */ +/* $Id: types.h,v 1.51 2009/10/01 01:30:01 sar Exp $ */ #ifndef ISC_TYPES_H #define ISC_TYPES_H 1 @@ -98,7 +98,7 @@ typedef struct isc_timer isc_timer_t; /*%< Timer */ typedef struct isc_timermgr isc_timermgr_t; /*%< Timer Manager */ typedef void (*isc_taskaction_t)(isc_task_t *, isc_event_t *); -typedef int (*isc_sockfdwatch_t)(isc_task_t *, isc_socket_t *, void *); +typedef int (*isc_sockfdwatch_t)(isc_task_t *, isc_socket_t *, void *, int); /* The following cannot be listed alphabetically due to forward reference */ typedef isc_result_t (isc_httpdaction_t)(const char *url, diff --git a/lib/isc/socket_api.c b/lib/isc/socket_api.c index 8ba206070c..95075f5a65 100644 --- a/lib/isc/socket_api.c +++ b/lib/isc/socket_api.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: socket_api.c,v 1.4 2009/09/02 23:48:02 tbox Exp $ */ +/* $Id: socket_api.c,v 1.5 2009/10/01 01:30:01 sar Exp $ */ #include @@ -194,3 +194,23 @@ isc_socket_setname(isc_socket_t *socket, const char *name, void *tag) { UNUSED(name); UNUSED(tag); } + +isc_result_t +isc_socket_fdwatchcreate(isc_socketmgr_t *manager, int fd, int flags, + isc_sockfdwatch_t callback, void *cbarg, + isc_task_t *task, isc_socket_t **socketp) +{ + REQUIRE(ISCAPI_SOCKETMGR_VALID(manager)); + + return (manager->methods->fdwatchcreate(manager, fd, flags, + callback, cbarg, task, + socketp)); +} + +isc_result_t +isc_socket_fdwatchpoke(isc_socket_t *sock, int flags) +{ + REQUIRE(ISCAPI_SOCKET_VALID(sock)); + + return(sock->methods->fdwatchpoke(sock, flags)); +} diff --git a/lib/isc/unix/socket.c b/lib/isc/unix/socket.c index e2e06934ee..663a03ab10 100644 --- a/lib/isc/unix/socket.c +++ b/lib/isc/unix/socket.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: socket.c,v 1.324 2009/09/07 02:08:51 marka Exp $ */ +/* $Id: socket.c,v 1.325 2009/10/01 01:30:01 sar Exp $ */ /*! \file */ @@ -535,6 +535,13 @@ ISC_SOCKETFUNC_SCOPE void isc__socketmgr_renderxml(isc_socketmgr_t *mgr0, xmlTextWriterPtr writer); #endif +ISC_SOCKETFUNC_SCOPE isc_result_t +isc__socket_fdwatchcreate(isc_socketmgr_t *manager, int fd, int flags, + isc_sockfdwatch_t callback, void *cbarg, + isc_task_t *task, isc_socket_t **socketp); +ISC_SOCKETFUNC_SCOPE isc_result_t +isc__socket_fdwatchpoke(isc_socket_t *sock, int flags); + static struct { isc_socketmethods_t methods; @@ -556,7 +563,8 @@ static struct { isc__socket_cancel, isc__socket_getsockname, isc__socket_gettype, - isc__socket_ipv6only + isc__socket_ipv6only, + isc__socket_fdwatchpoke } #ifndef BIND9 , @@ -571,7 +579,8 @@ static struct { static isc_socketmgrmethods_t socketmgrmethods = { isc__socketmgr_destroy, - isc__socket_create + isc__socket_create, + isc__socket_fdwatchcreate }; #define SELECT_POKE_SHUTDOWN (-1) @@ -2553,6 +2562,7 @@ isc__socket_open(isc_socket_t *sock0) { return (result); } +#endif /* BIND9 */ /* * Create a new 'type' socket managed by 'manager'. Events @@ -2617,7 +2627,29 @@ isc__socket_fdwatchcreate(isc_socketmgr_t *manager0, int fd, int flags, return (ISC_R_SUCCESS); } -#endif /* BIND9 */ + +/* Indicate to the manager that it should watch the socket again. + * This can be used to restart watching if the previous event handler + * didn't indicate there was more data to be processed. Primarily + * it is for writing but could be used for reading if desired */ + +ISC_SOCKETFUNC_SCOPE isc_result_t +isc__socket_fdwatchpoke(isc_socket_t *sock0, int flags) +{ + isc__socket_t *sock = (isc__socket_t *)sock0; + + REQUIRE(VALID_SOCKET(sock)); + + if (flags & ISC_SOCKFDWATCH_READ) + select_poke(sock->manager, sock->fd, SELECT_POKE_READ); + if (flags & ISC_SOCKFDWATCH_WRITE) + select_poke(sock->manager, sock->fd, SELECT_POKE_WRITE); + + socket_log(sock, NULL, TRACE, isc_msgcat, ISC_MSGSET_SOCKET, + ISC_MSG_POKED, "fdwatch-poked flags: %d", flags); + + return (ISC_R_SUCCESS); +} /* * Attach to a socket. Caller must explicitly detach when it is done. @@ -3276,7 +3308,7 @@ internal_fdwatch_write(isc_task_t *me, isc_event_t *ev) { UNLOCK(&sock->lock); more_data = (sock->fdwatchcb)(me, (isc_socket_t *)sock, - sock->fdwatcharg); + sock->fdwatcharg, ISC_SOCKFDWATCH_WRITE); LOCK(&sock->lock); sock->pending_send = 0; @@ -3317,7 +3349,7 @@ internal_fdwatch_read(isc_task_t *me, isc_event_t *ev) { UNLOCK(&sock->lock); more_data = (sock->fdwatchcb)(me, (isc_socket_t *)sock, - sock->fdwatcharg); + sock->fdwatcharg, ISC_SOCKFDWATCH_READ); LOCK(&sock->lock); sock->pending_recv = 0;