2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 06:25:31 +00:00

2375. [security] Fully randomize UDP query ports to improve

forgery resilience. [RT #17949, #18098]
This commit is contained in:
Tatuya JINMEI 神明達哉
2008-06-23 19:41:20 +00:00
parent 40976ef802
commit 386d3a99c1
26 changed files with 3403 additions and 1553 deletions

View File

@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: platform.h.in,v 1.47 2008/01/24 23:47:00 tbox Exp $ */
/* $Id: platform.h.in,v 1.48 2008/06/23 19:41:19 jinmei Exp $ */
#ifndef ISC_PLATFORM_H
#define ISC_PLATFORM_H 1
@@ -136,6 +136,21 @@
*/
@ISC_PLATFORM_FIXIN6ISADDR@
/*! \brief
* Define if the system supports kqueue multiplexing
*/
@ISC_PLATFORM_HAVEKQUEUE@
/*! \brief
* Define if the system supports epoll multiplexing
*/
@ISC_PLATFORM_HAVEEPOLL@
/*! \brief
* Define if the system supports /dev/poll multiplexing
*/
@ISC_PLATFORM_HAVEDEVPOLL@
/*
*** Printing.
***/

View File

@@ -0,0 +1,141 @@
/*
* Copyright (C) 2008 Internet Systems Consortium, Inc. ("ISC")
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: portset.h,v 1.2 2008/06/23 19:41:19 jinmei Exp $ */
/*! \file isc/portset.h
* \brief Transport Protocol Port Manipuration Module
*
* This module provides simple utilities to handle a set of transport protocol
* (UDP or TCP) port numbers, e.g., for creating an ACL list. An isc_portset_t
* object is an opaque instance of a port set, for which the user can add or
* remove a specific port or a range of consecutive ports. This object is
* expected to be used as a temporary work space only, and does not protect
* simultaneous access from multiple threads. Therefore it must not be stored
* in a place that can be accessed from multiple threads.
*/
#ifndef ISC_PORTSET_H
#define ISC_PORTSET_H 1
/***
*** Imports
***/
#include <isc/net.h>
/***
*** Functions
***/
ISC_LANG_BEGINDECLS
isc_result_t
isc_portset_create(isc_mem_t *mctx, isc_portset_t **portsetp);
/*%<
* Create a port set and initialize it as an empty set.
*
* Requires:
*\li 'mctx' to be valid.
*\li 'portsetp' to be non NULL and '*portsetp' to be NULL;
*
* Returns:
*\li #ISC_R_SUCCESS
*\li #ISC_R_NOMEMORY
*/
void
isc_portset_destroy(isc_mem_t *mctx, isc_portset_t **portsetp);
/*%<
* Destroy a port set.
*
* Requires:
*\li 'mctx' to be valid and must be the same context given when the port set
* was created.
*\li '*portsetp' to be a valid set.
*/
isc_boolean_t
isc_portset_isset(isc_portset_t *portset, in_port_t port);
/*%<
* Test whether the given port is stored in the portset.
*
* Requires:
*\li 'portset' to be a valid set.
*
* Returns
* \li #ISC_TRUE if the port is found, ISC_FALSE otherwise.
*/
unsigned int
isc_portset_nports(isc_portset_t *portset);
/*%<
* Provides the number of ports stored in the given portset.
*
* Requires:
*\li 'portset' to be a valid set.
*
* Returns
* \li the number of ports stored in portset.
*/
void
isc_portset_add(isc_portset_t *portset, in_port_t port);
/*%<
* Add the given port to the portset. The port may or may not be stored in
* the portset.
*
* Requires:
*\li 'portlist' to be valid.
*/
void
isc_portset_remove(isc_portset_t *portset, in_port_t port);
/*%<
* Remove the given port to the portset. The port may or may not be stored in
* the portset.
*
* Requires:
*\li 'portlist' to be valid.
*/
void
isc_portset_addrange(isc_portset_t *portset, in_port_t port_lo,
in_port_t port_hi);
/*%<
* Add a subset of [port_lo, port_hi] (inclusive) to the portset. Ports in the
* subset may or may not be stored in portset.
*
* Requires:
*\li 'portlist' to be valid.
*\li port_lo <= port_hi
*/
void
isc_portset_removerange(isc_portset_t *portset, in_port_t port_lo,
in_port_t port_hi);
/*%<
* Subtract a subset of [port_lo, port_hi] (inclusive) from the portset. Ports
* in the subset may or may not be stored in portset.
*
* Requires:
*\li 'portlist' to be valid.
*\li port_lo <= port_hi
*/
ISC_LANG_ENDDECLS
#endif /* ISC_NETADDR_H */

View File

@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: socket.h,v 1.74 2008/06/04 23:47:11 tbox Exp $ */
/* $Id: socket.h,v 1.75 2008/06/23 19:41:19 jinmei Exp $ */
#ifndef ISC_SOCKET_H
#define ISC_SOCKET_H 1
@@ -360,6 +360,45 @@ isc_socket_detach(isc_socket_t **socketp);
* All resources used by the socket have been freed
*/
isc_result_t
isc_socket_open(isc_socket_t *sock);
/*%<
* Open a new socket file descriptor of the given socket structure. It simply
* opens a new descriptor; all of the other parameters including the socket
* type are inherited from the existing socket. This function is provided to
* avoid overhead of destroying and creating sockets when many short-lived
* sockets are frequently opened and closed. When the efficiency is not an
* issue, it should be safer to detach the unused socket and re-create a new
* one.
*
* Requires:
*
* \li there must be no other reference to this socket.
*
* \li 'socket' is a valid and previously closed by isc_socket_close()
*
* Returns:
* Same as isc_socket_create().
*/
void
isc_socket_close(isc_socket_t *sock);
/*%<
* Close a socket file descriptor of the given socket structure. This function
* is provided as an alternative to destroying an unused socket when overhead
* destroying/re-creating sockets can be significant, and is expected to be
* used with isc_socket_open().
*
* Requires:
*
* \li The socket must have a valid descriptor.
*
* \li There must be no other reference to this socket.
*
* \li There must be no pending I/O requests.
*
*/
isc_result_t
isc_socket_bind(isc_socket_t *sock, isc_sockaddr_t *addressp);
/*%<

View File

@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: timer.h,v 1.38 2007/06/19 23:47:18 tbox Exp $ */
/* $Id: timer.h,v 1.39 2008/06/23 19:41:19 jinmei Exp $ */
#ifndef ISC_TIMER_H
#define ISC_TIMER_H 1
@@ -76,6 +76,7 @@
#include <isc/event.h>
#include <isc/eventclass.h>
#include <isc/lang.h>
#include <isc/time.h>
ISC_LANG_BEGINDECLS
@@ -93,6 +94,7 @@ typedef enum {
typedef struct isc_timerevent {
struct isc_event common;
isc_time_t due;
} isc_timerevent_t;
#define ISC_TIMEREVENT_FIRSTEVENT (ISC_EVENTCLASS_TIMER + 0)

View File

@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: types.h,v 1.45 2008/01/17 23:47:00 tbox Exp $ */
/* $Id: types.h,v 1.46 2008/06/23 19:41:19 jinmei Exp $ */
#ifndef ISC_TYPES_H
#define ISC_TYPES_H 1
@@ -70,6 +70,7 @@ typedef struct isc_mempool isc_mempool_t; /*%< Memory Pool */
typedef struct isc_msgcat isc_msgcat_t; /*%< Message Catalog */
typedef struct isc_ondestroy isc_ondestroy_t; /*%< On Destroy */
typedef struct isc_netaddr isc_netaddr_t; /*%< Net Address */
typedef struct isc_portset isc_portset_t; /*%< Port Set */
typedef struct isc_quota isc_quota_t; /*%< Quota */
typedef struct isc_random isc_random_t; /*%< Random */
typedef struct isc_ratelimiter isc_ratelimiter_t; /*%< Rate Limiter */