1
  B   ˆl–Ãa¾”ji?u@?pÜŠbÑ¿À„A?_†I|¥�+a–Ým_J*j"Tâ�fã ¸ÛÊbÑ¿Ä ?÷     /*
 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, you can obtain one at https://mozilla.org/MPL/2.0/.
 *
 * See the COPYRIGHT file distributed with this work for additional
 * information regarding copyright ownership.
 */

#ifndef ISC_SOCKET_H
#define ISC_SOCKET_H 1

/*****
***** Module Info
*****/

/*! \file isc/socket.h
 * \brief Provides TCP and UDP sockets for network I/O.  The sockets are event
 * sources in the task system.
 *
 * When I/O completes, a completion event for the socket is posted to the
 * event queue of the task which requested the I/O.
 *
 * \li MP:
 *	The module ensures appropriate synchronization of data structures it
 *	creates and manipulates.
 *	Clients of this module must not be holding a socket's task's lock when
 *	making a call that affects that socket.  Failure to follow this rule
 *	can result in deadlock.
 *	The caller must ensure that isc_socketmgr_destroy() is called only
 *	once for a given manager.
 *
 * \li Reliability:
 *	No anticipated impact.
 *
 * \li Resources:
 *	TBS
 *
 * \li Security:
 *	No anticipated impact.
 *
 * \li Standards:
 *	None.
 */

/***
 *** Imports
 ***/

#include <inttypes.h>
#include <stdbool.h>

#include <isc/event.h>
#include <isc/eventclass.h>
#include <isc/lang.h>
#include <isc/region.h>
#include <isc/sockaddr.h>
#include <isc/time.h>
#include <isc/types.h>

ISC_LANG_BEGINDECLS

/***
 *** Constants
 ***/

/*%
 * Maximum number of buffers in a scatter/gather read/write.  The operating
 * system in use must support at least this number (plus one on some.)
 */
#define ISC_SOCKET_MAXSCATTERGATHER 8

/*@{*/
/*!
 * Socket options:
 *
 * _REUSEADDRESS:	Set SO_REUSEADDR prior to calling bind(),
 * 			if a non-zero port is specified (applies to
 * 			AF_INET and AF_INET6).
 */
typedef enum {
	ISC_SOCKET_REUSEADDRESS = 0x01U,
} isc_socket_options_t;
/*@}*/

/*@{*/
/*!
 * _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 = 0x10000000U,  /* 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
 ***/

struct isc_socketevent {
	ISC_EVENT_COMMON(isc_socketevent_t);
	isc_result_t	    result;	/*%< OK, EOF, whatever else */
	unsigned int	    minimum;	/*%< minimum i/o for event */
	unsigned int	    n;		/*%< bytes read or written */
	unsigned int	    offset;	/*%< offset into buffer list */
	isc_region_t	    region;	/*%< for single-buffer i/o */
	isc_sockaddr_t	    address;	/*%< source address */
	isc_time_t	    timestamp;	/*%< timestamp of packet recv */
	struct in6_pktinfo  pktinfo;	/*%< ipv6 pktinfo */
	isc_sockeventattr_t attributes; /*%< see isc_sockeventattr_t
					 *   enum */
	isc_eventdestructor_t destroy;	/*%< original destructor */
	unsigned int	      dscp;	/*%< UDP dscp value */
};

typedef struct isc_socket_newconnev isc_socket_newconnev_t;
struct isc_socket_newconnev {
	ISC_EVENT_COMMON(isc_socket_newconnev_t);
	isc_socket_t  *newsocket;
	isc_result_t   result;	/*%< OK, EOF, whatever else */
	isc_sockaddr_t address; /*%< source address */
};

typedef str