1*c0b5d9fbSchristos /* $NetBSD: tcpmsg.h,v 1.6 2022/09/23 12:15:30 christos Exp $ */ 2e2b1b9c0Schristos 3e2b1b9c0Schristos /* 4e2b1b9c0Schristos * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 5e2b1b9c0Schristos * 6*c0b5d9fbSchristos * SPDX-License-Identifier: MPL-2.0 7*c0b5d9fbSchristos * 8e2b1b9c0Schristos * This Source Code Form is subject to the terms of the Mozilla Public 9e2b1b9c0Schristos * License, v. 2.0. If a copy of the MPL was not distributed with this 1073584a28Schristos * file, you can obtain one at https://mozilla.org/MPL/2.0/. 11e2b1b9c0Schristos * 12e2b1b9c0Schristos * See the COPYRIGHT file distributed with this work for additional 13e2b1b9c0Schristos * information regarding copyright ownership. 14e2b1b9c0Schristos */ 15e2b1b9c0Schristos 16e2b1b9c0Schristos #ifndef DNS_TCPMSG_H 17e2b1b9c0Schristos #define DNS_TCPMSG_H 1 18e2b1b9c0Schristos 19e2b1b9c0Schristos /*! \file dns/tcpmsg.h */ 20e2b1b9c0Schristos 21f2e20987Schristos #include <inttypes.h> 22f2e20987Schristos 23e2b1b9c0Schristos #include <isc/buffer.h> 24e2b1b9c0Schristos #include <isc/lang.h> 25e2b1b9c0Schristos #include <isc/socket.h> 26e2b1b9c0Schristos 27e2b1b9c0Schristos typedef struct dns_tcpmsg { 28e2b1b9c0Schristos /* private (don't touch!) */ 29e2b1b9c0Schristos unsigned int magic; 30f2e20987Schristos uint16_t size; 31e2b1b9c0Schristos isc_buffer_t buffer; 32e2b1b9c0Schristos unsigned int maxsize; 33e2b1b9c0Schristos isc_mem_t *mctx; 34e2b1b9c0Schristos isc_socket_t *sock; 35e2b1b9c0Schristos isc_task_t *task; 36e2b1b9c0Schristos isc_taskaction_t action; 37e2b1b9c0Schristos void *arg; 38e2b1b9c0Schristos isc_event_t event; 39e2b1b9c0Schristos /* public (read-only) */ 40e2b1b9c0Schristos isc_result_t result; 41e2b1b9c0Schristos isc_sockaddr_t address; 42e2b1b9c0Schristos } dns_tcpmsg_t; 43e2b1b9c0Schristos 44e2b1b9c0Schristos ISC_LANG_BEGINDECLS 45e2b1b9c0Schristos 46e2b1b9c0Schristos void 47e2b1b9c0Schristos dns_tcpmsg_init(isc_mem_t *mctx, isc_socket_t *sock, dns_tcpmsg_t *tcpmsg); 48e2b1b9c0Schristos /*%< 49e2b1b9c0Schristos * Associate a tcp message state with a given memory context and 50e2b1b9c0Schristos * TCP socket. 51e2b1b9c0Schristos * 52e2b1b9c0Schristos * Requires: 53e2b1b9c0Schristos * 54e2b1b9c0Schristos *\li "mctx" and "sock" be non-NULL and valid types. 55e2b1b9c0Schristos * 56e2b1b9c0Schristos *\li "sock" be a read/write TCP socket. 57e2b1b9c0Schristos * 58e2b1b9c0Schristos *\li "tcpmsg" be non-NULL and an uninitialized or invalidated structure. 59e2b1b9c0Schristos * 60e2b1b9c0Schristos * Ensures: 61e2b1b9c0Schristos * 62e2b1b9c0Schristos *\li "tcpmsg" is a valid structure. 63e2b1b9c0Schristos */ 64e2b1b9c0Schristos 65e2b1b9c0Schristos void 66e2b1b9c0Schristos dns_tcpmsg_setmaxsize(dns_tcpmsg_t *tcpmsg, unsigned int maxsize); 67e2b1b9c0Schristos /*%< 68e2b1b9c0Schristos * Set the maximum packet size to "maxsize" 69e2b1b9c0Schristos * 70e2b1b9c0Schristos * Requires: 71e2b1b9c0Schristos * 72e2b1b9c0Schristos *\li "tcpmsg" be valid. 73e2b1b9c0Schristos * 74e2b1b9c0Schristos *\li 512 <= "maxsize" <= 65536 75e2b1b9c0Schristos */ 76e2b1b9c0Schristos 77e2b1b9c0Schristos isc_result_t 789742fdb4Schristos dns_tcpmsg_readmessage(dns_tcpmsg_t *tcpmsg, isc_task_t *task, 799742fdb4Schristos isc_taskaction_t action, void *arg); 80e2b1b9c0Schristos /*%< 81e2b1b9c0Schristos * Schedule an event to be delivered when a DNS message is readable, or 82e2b1b9c0Schristos * when an error occurs on the socket. 83e2b1b9c0Schristos * 84e2b1b9c0Schristos * Requires: 85e2b1b9c0Schristos * 86e2b1b9c0Schristos *\li "tcpmsg" be valid. 87e2b1b9c0Schristos * 88e2b1b9c0Schristos *\li "task", "taskaction", and "arg" be valid. 89e2b1b9c0Schristos * 90e2b1b9c0Schristos * Returns: 91e2b1b9c0Schristos * 92e2b1b9c0Schristos *\li ISC_R_SUCCESS -- no error 93e2b1b9c0Schristos *\li Anything that the isc_socket_recv() call can return. XXXMLG 94e2b1b9c0Schristos * 95e2b1b9c0Schristos * Notes: 96e2b1b9c0Schristos * 97e2b1b9c0Schristos *\li The event delivered is a fully generic event. It will contain no 98e2b1b9c0Schristos * actual data. The sender will be a pointer to the dns_tcpmsg_t. 99e2b1b9c0Schristos * The result code inside that structure should be checked to see 100e2b1b9c0Schristos * what the final result was. 101e2b1b9c0Schristos */ 102e2b1b9c0Schristos 103e2b1b9c0Schristos void 104e2b1b9c0Schristos dns_tcpmsg_cancelread(dns_tcpmsg_t *tcpmsg); 105e2b1b9c0Schristos /*%< 106e2b1b9c0Schristos * Cancel a readmessage() call. The event will still be posted with a 107e2b1b9c0Schristos * CANCELED result code. 108e2b1b9c0Schristos * 109e2b1b9c0Schristos * Requires: 110e2b1b9c0Schristos * 111e2b1b9c0Schristos *\li "tcpmsg" be valid. 112e2b1b9c0Schristos */ 113e2b1b9c0Schristos 114e2b1b9c0Schristos void 115e2b1b9c0Schristos dns_tcpmsg_keepbuffer(dns_tcpmsg_t *tcpmsg, isc_buffer_t *buffer); 116e2b1b9c0Schristos /*%< 117e2b1b9c0Schristos * If a dns buffer is to be kept between calls, this function marks the 118e2b1b9c0Schristos * internal state-machine buffer as invalid, and copies all the contents 119e2b1b9c0Schristos * of the state into "buffer". 120e2b1b9c0Schristos * 121e2b1b9c0Schristos * Requires: 122e2b1b9c0Schristos * 123e2b1b9c0Schristos *\li "tcpmsg" be valid. 124e2b1b9c0Schristos * 125e2b1b9c0Schristos *\li "buffer" be non-NULL. 126e2b1b9c0Schristos */ 127e2b1b9c0Schristos 128e2b1b9c0Schristos void 129e2b1b9c0Schristos dns_tcpmsg_invalidate(dns_tcpmsg_t *tcpmsg); 130e2b1b9c0Schristos /*%< 131e2b1b9c0Schristos * Clean up all allocated state, and invalidate the structure. 132e2b1b9c0Schristos * 133e2b1b9c0Schristos * Requires: 134e2b1b9c0Schristos * 135e2b1b9c0Schristos *\li "tcpmsg" be valid. 136e2b1b9c0Schristos * 137e2b1b9c0Schristos * Ensures: 138e2b1b9c0Schristos * 139e2b1b9c0Schristos *\li "tcpmsg" is invalidated and disassociated with all memory contexts, 140e2b1b9c0Schristos * sockets, etc. 141e2b1b9c0Schristos */ 142e2b1b9c0Schristos 143e2b1b9c0Schristos ISC_LANG_ENDDECLS 144e2b1b9c0Schristos 145e2b1b9c0Schristos #endif /* DNS_TCPMSG_H */ 146