1 /* $NetBSD: buffer.h,v 1.3 2022/04/03 01:10:59 christos Exp $ */ 2 3 /* buffer.h 4 5 Definitions for the object management API protocol buffering... */ 6 7 /* 8 * Copyright (C) 2004-2022 Internet Systems Consortium, Inc. ("ISC") 9 * Copyright (c) 1996-2003 by Internet Software Consortium 10 * 11 * This Source Code Form is subject to the terms of the Mozilla Public 12 * License, v. 2.0. If a copy of the MPL was not distributed with this 13 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES 16 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 17 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR 18 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 20 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 21 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 22 * 23 * Internet Systems Consortium, Inc. 24 * PO Box 360 25 * Newmarket, NH 03857 USA 26 * <info@isc.org> 27 * https://www.isc.org/ 28 * 29 */ 30 31 /* OMAPI buffers are ring buffers, which means that the beginning of the 32 buffer and the end of the buffer chase each other around. As long as 33 the tail never catches up to the head, there's room in the buffer for 34 data. 35 36 - If the tail and the head are equal, the buffer is empty. 37 38 - If the tail is less than the head, the contents of the buffer 39 are the bytes from the head to the end of buffer, and in addition, 40 the bytes between the beginning of the buffer and the tail, not 41 including the byte addressed by the tail. 42 43 - If the tail is greater than the head, then the buffer contains 44 valid bytes starting with the byte addressed by the head, and 45 ending with the byte before the byte addressed by the tail. 46 47 There will always be at least one byte of waste, because the tail can't 48 increase so that it's equal to the head (that would represent an empty 49 buffer. */ 50 #define OMAPI_BUF_SIZE 4048 51 typedef struct _omapi_buffer { 52 struct _omapi_buffer *next; /* Buffers can be chained. */ 53 u_int32_t refcnt; /* Buffers are reference counted. */ 54 u_int16_t head, tail; /* Buffers are organized in a ring. */ 55 char buf [OMAPI_BUF_SIZE]; /* The actual buffer is included in 56 the buffer data structure. */ 57 } omapi_buffer_t; 58 59 #define BUFFER_BYTES_FREE(x) \ 60 ((x) -> tail > (x) -> head \ 61 ? sizeof ((x) -> buf) - ((x) -> tail - (x) -> head) \ 62 : (x) -> head - (x) -> tail) 63 64 #define BYTES_IN_BUFFER(x) \ 65 ((x) -> tail > (x) -> head \ 66 ? (x) -> tail - (x) -> head - 1 \ 67 : sizeof ((x) -> buf) - ((x) -> head - (x) -> tail) - 1) 68 69 isc_result_t omapi_connection_require (omapi_object_t *, unsigned); 70 isc_result_t omapi_connection_copyout (unsigned char *, 71 omapi_object_t *, unsigned); 72 isc_result_t omapi_connection_copyin (omapi_object_t *, 73 const unsigned char *, unsigned); 74 isc_result_t omapi_connection_flush (omapi_object_t *); 75 isc_result_t omapi_connection_get_uint32 (omapi_object_t *, u_int32_t *); 76 isc_result_t omapi_connection_put_uint32 (omapi_object_t *, u_int32_t); 77 isc_result_t omapi_connection_get_uint16 (omapi_object_t *, u_int16_t *); 78 isc_result_t omapi_connection_put_uint16 (omapi_object_t *, u_int32_t); 79