From c2f42583c0b126e6f62b1ab250f3126d1972f236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Sat, 17 Mar 2018 11:01:39 +0000 Subject: [PATCH 1/3] Refactor ISC_SOCKET_* defines into an isc_socket_options_t enum --- lib/dns/dispatch.c | 2 +- lib/isc/include/isc/socket.h | 19 ++++++++++++------- lib/isc/unix/socket.c | 3 ++- lib/isc/win32/socket.c | 3 ++- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/dns/dispatch.c b/lib/dns/dispatch.c index f66533154d..a65f693002 100644 --- a/lib/dns/dispatch.c +++ b/lib/dns/dispatch.c @@ -673,7 +673,7 @@ get_dispsocket(dns_dispatch_t *disp, const isc_sockaddr_t *dest, dispsocket_t *dispsock; unsigned int nports; in_port_t *ports; - unsigned int bindoptions; + isc_socket_options_t bindoptions; dispportentry_t *portentry = NULL; dns_qid_t *qid; diff --git a/lib/isc/include/isc/socket.h b/lib/isc/include/isc/socket.h index a5033c3ede..70b28e83a4 100644 --- a/lib/isc/include/isc/socket.h +++ b/lib/isc/include/isc/socket.h @@ -9,8 +9,6 @@ * information regarding copyright ownership. */ -/* $Id$ */ - #ifndef ISC_SOCKET_H #define ISC_SOCKET_H 1 @@ -122,11 +120,18 @@ ISC_LANG_BEGINDECLS */ #define ISC_SOCKET_MAXSCATTERGATHER 8 -/*% - * In isc_socket_bind() set socket option SO_REUSEADDR prior to calling - * bind() if a non zero port is specified (AF_INET and AF_INET6). +/*@{*/ +/*! + * Socket options: + * + * _REUSEADDRESS: Set SO_REUSEADDR prior to calling bind(), + * if a non-zero port is specified (applies to + * AF_INET and AF_INET6). */ -#define ISC_SOCKET_REUSEADDRESS 0x01U +typedef enum { + ISC_SOCKET_REUSEADDRESS = 0x01U, +} isc_socket_options_t; +/*@}*/ /*% * Statistics counters. Used as isc_statscounter_t values. @@ -691,7 +696,7 @@ isc_socket_close(isc_socket_t *sock); isc_result_t isc_socket_bind(isc_socket_t *sock, const isc_sockaddr_t *addressp, - unsigned int options); + isc_socket_options_t options); /*%< * Bind 'socket' to '*addressp'. * diff --git a/lib/isc/unix/socket.c b/lib/isc/unix/socket.c index fd767100bd..b5ddbf745a 100644 --- a/lib/isc/unix/socket.c +++ b/lib/isc/unix/socket.c @@ -5573,7 +5573,8 @@ isc__socket_permunix(const isc_sockaddr_t *sockaddr, isc_uint32_t perm, isc_result_t isc__socket_bind(isc_socket_t *sock0, const isc_sockaddr_t *sockaddr, - unsigned int options) { + isc_socket_options_t options) +{ isc__socket_t *sock = (isc__socket_t *)sock0; char strbuf[ISC_STRERRORSIZE]; int on = 1; diff --git a/lib/isc/win32/socket.c b/lib/isc/win32/socket.c index 3e54988e94..f2c3f8325c 100644 --- a/lib/isc/win32/socket.c +++ b/lib/isc/win32/socket.c @@ -3238,7 +3238,8 @@ isc__socket_sendto2(isc_socket_t *sock, isc_region_t *region, isc_task_t *task, isc_result_t isc__socket_bind(isc_socket_t *sock, const isc_sockaddr_t *sockaddr, - unsigned int options) { + isc_socket_options_t options) +{ int bind_errno; char strbuf[ISC_STRERRORSIZE]; int on = 1; From 8bdc23add2ef4ead8c062138f69f2103e034a5e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Sat, 17 Mar 2018 11:15:40 +0000 Subject: [PATCH 2/3] Change ISC_SOCKEVENTATTR_* defines into isc_sockeventattr_t enum --- lib/dns/resolver.c | 2 +- lib/isc/include/isc/socket.h | 51 +++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c index 799a588b69..f31f208a87 100644 --- a/lib/dns/resolver.c +++ b/lib/dns/resolver.c @@ -219,7 +219,7 @@ typedef struct query { isc_dscp_t dscp; int ednsversion; unsigned int options; - unsigned int attributes; + isc_sockeventattr_t attributes; unsigned int sends; unsigned int connects; unsigned int udpsize; diff --git a/lib/isc/include/isc/socket.h b/lib/isc/include/isc/socket.h index 70b28e83a4..e6f613b329 100644 --- a/lib/isc/include/isc/socket.h +++ b/lib/isc/include/isc/socket.h @@ -214,6 +214,31 @@ enum { isc_sockstatscounter_max = 62 }; +/*@{*/ +/*! + * _ATTACHED: Internal use only. + * _TRUNC: Packet was truncated on receive. + * _CTRUNC: Packet control information was truncated. This can + * indicate that the packet is not complete, even though + * all the data is valid. + * _TIMESTAMP: The timestamp member is valid. + * _PKTINFO: The pktinfo member is valid. + * _MULTICAST: The UDP packet was received via a multicast transmission. + * _DSCP: The UDP DSCP value is valid. + * _USEMINMTU: Set the per packet IPV6_USE_MIN_MTU flag. + */ +typedef enum { + ISC_SOCKEVENTATTR_ATTACHED = 0x80000000U, /* internal */ + ISC_SOCKEVENTATTR_TRUNC = 0x00800000U, /* public */ + ISC_SOCKEVENTATTR_CTRUNC = 0x00400000U, /* public */ + ISC_SOCKEVENTATTR_TIMESTAMP = 0x00200000U, /* public */ + ISC_SOCKEVENTATTR_PKTINFO = 0x00100000U, /* public */ + ISC_SOCKEVENTATTR_MULTICAST = 0x00080000U, /* public */ + ISC_SOCKEVENTATTR_DSCP = 0x00040000U, /* public */ + ISC_SOCKEVENTATTR_USEMINMTU = 0x00020000U /* public */ +} isc_sockeventattr_t; +/*@}*/ + /*** *** Types ***/ @@ -229,7 +254,8 @@ struct isc_socketevent { isc_sockaddr_t address; /*%< source address */ isc_time_t timestamp; /*%< timestamp of packet recv */ struct in6_pktinfo pktinfo; /*%< ipv6 pktinfo */ - isc_uint32_t attributes; /*%< see below */ + isc_sockeventattr_t attributes; /*%< see isc_sockeventattr_t + enum */ isc_eventdestructor_t destroy; /*%< original destructor */ unsigned int dscp; /*%< UDP dscp value */ }; @@ -248,29 +274,6 @@ struct isc_socket_connev { isc_result_t result; /*%< OK, EOF, whatever else */ }; -/*@{*/ -/*! - * _ATTACHED: Internal use only. - * _TRUNC: Packet was truncated on receive. - * _CTRUNC: Packet control information was truncated. This can - * indicate that the packet is not complete, even though - * all the data is valid. - * _TIMESTAMP: The timestamp member is valid. - * _PKTINFO: The pktinfo member is valid. - * _MULTICAST: The UDP packet was received via a multicast transmission. - * _DSCP: The UDP DSCP value is valid. - * _USEMINMTU: Set the per packet IPV6_USE_MIN_MTU flag. - */ -#define ISC_SOCKEVENTATTR_ATTACHED 0x80000000U /* internal */ -#define ISC_SOCKEVENTATTR_TRUNC 0x00800000U /* public */ -#define ISC_SOCKEVENTATTR_CTRUNC 0x00400000U /* public */ -#define ISC_SOCKEVENTATTR_TIMESTAMP 0x00200000U /* public */ -#define ISC_SOCKEVENTATTR_PKTINFO 0x00100000U /* public */ -#define ISC_SOCKEVENTATTR_MULTICAST 0x00080000U /* public */ -#define ISC_SOCKEVENTATTR_DSCP 0x00040000U /* public */ -#define ISC_SOCKEVENTATTR_USEMINMTU 0x00020000U /* public */ -/*@}*/ - #define ISC_SOCKEVENT_ANYEVENT (0) #define ISC_SOCKEVENT_RECVDONE (ISC_EVENTCLASS_SOCKET + 1) #define ISC_SOCKEVENT_SENDDONE (ISC_EVENTCLASS_SOCKET + 2) From 97a88e2248dbb2be6d285e3ecb1ce7868c4d1f0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Thu, 12 Apr 2018 09:55:40 +0200 Subject: [PATCH 3/3] Add CHANGES entry: 4923. [cleanup] Refactor socket and socket event options into enum types. [GL !135] --- CHANGES | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES b/CHANGES index dababd96a1..64a2bd3e65 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +4923. [cleanup] Refactor socket and socket event options into + enum types. [GL !135] + 4922. [bug] dnstap: Log the destination address of client packets rather than the interface address. [GL #197]