xref: /minix3/external/bsd/dhcp/dist/includes/omapip/buffer.h (revision 83ee113ee0d94f3844d44065af2311604e9a30ad)
1*83ee113eSDavid van Moolenbroek /*	$NetBSD: buffer.h,v 1.1.1.3 2014/07/12 11:57:57 spz Exp $	*/
2*83ee113eSDavid van Moolenbroek /* buffer.h
3*83ee113eSDavid van Moolenbroek 
4*83ee113eSDavid van Moolenbroek    Definitions for the object management API protocol buffering... */
5*83ee113eSDavid van Moolenbroek 
6*83ee113eSDavid van Moolenbroek /*
7*83ee113eSDavid van Moolenbroek  * Copyright (c) 2004,2009,2014 by Internet Systems Consortium, Inc. ("ISC")
8*83ee113eSDavid van Moolenbroek  * Copyright (c) 1996-2003 by Internet Software Consortium
9*83ee113eSDavid van Moolenbroek  *
10*83ee113eSDavid van Moolenbroek  * Permission to use, copy, modify, and distribute this software for any
11*83ee113eSDavid van Moolenbroek  * purpose with or without fee is hereby granted, provided that the above
12*83ee113eSDavid van Moolenbroek  * copyright notice and this permission notice appear in all copies.
13*83ee113eSDavid van Moolenbroek  *
14*83ee113eSDavid van Moolenbroek  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
15*83ee113eSDavid van Moolenbroek  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16*83ee113eSDavid van Moolenbroek  * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
17*83ee113eSDavid van Moolenbroek  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18*83ee113eSDavid van Moolenbroek  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19*83ee113eSDavid van Moolenbroek  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
20*83ee113eSDavid van Moolenbroek  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21*83ee113eSDavid van Moolenbroek  *
22*83ee113eSDavid van Moolenbroek  *   Internet Systems Consortium, Inc.
23*83ee113eSDavid van Moolenbroek  *   950 Charter Street
24*83ee113eSDavid van Moolenbroek  *   Redwood City, CA 94063
25*83ee113eSDavid van Moolenbroek  *   <info@isc.org>
26*83ee113eSDavid van Moolenbroek  *   https://www.isc.org/
27*83ee113eSDavid van Moolenbroek  *
28*83ee113eSDavid van Moolenbroek  */
29*83ee113eSDavid van Moolenbroek 
30*83ee113eSDavid van Moolenbroek /* OMAPI buffers are ring buffers, which means that the beginning of the
31*83ee113eSDavid van Moolenbroek    buffer and the end of the buffer chase each other around.   As long as
32*83ee113eSDavid van Moolenbroek    the tail never catches up to the head, there's room in the buffer for
33*83ee113eSDavid van Moolenbroek    data.
34*83ee113eSDavid van Moolenbroek 
35*83ee113eSDavid van Moolenbroek 	- If the tail and the head are equal, the buffer is empty.
36*83ee113eSDavid van Moolenbroek 
37*83ee113eSDavid van Moolenbroek 	- If the tail is less than the head, the contents of the buffer
38*83ee113eSDavid van Moolenbroek 	  are the bytes from the head to the end of buffer, and in addition,
39*83ee113eSDavid van Moolenbroek 	  the bytes between the beginning of the buffer and the tail, not
40*83ee113eSDavid van Moolenbroek 	  including the byte addressed by the tail.
41*83ee113eSDavid van Moolenbroek 
42*83ee113eSDavid van Moolenbroek 	- If the tail is greater than the head, then the buffer contains
43*83ee113eSDavid van Moolenbroek 	  valid bytes starting with the byte addressed by the head, and
44*83ee113eSDavid van Moolenbroek 	  ending with the byte before the byte addressed by the tail.
45*83ee113eSDavid van Moolenbroek 
46*83ee113eSDavid van Moolenbroek    There will always be at least one byte of waste, because the tail can't
47*83ee113eSDavid van Moolenbroek    increase so that it's equal to the head (that would represent an empty
48*83ee113eSDavid van Moolenbroek    buffer. */
49*83ee113eSDavid van Moolenbroek #define OMAPI_BUF_SIZE 4048
50*83ee113eSDavid van Moolenbroek typedef struct _omapi_buffer {
51*83ee113eSDavid van Moolenbroek 	struct _omapi_buffer *next;	/* Buffers can be chained. */
52*83ee113eSDavid van Moolenbroek 	u_int32_t refcnt;		/* Buffers are reference counted. */
53*83ee113eSDavid van Moolenbroek 	u_int16_t head, tail;		/* Buffers are organized in a ring. */
54*83ee113eSDavid van Moolenbroek 	char buf [OMAPI_BUF_SIZE];	/* The actual buffer is included in
55*83ee113eSDavid van Moolenbroek 					   the buffer data structure. */
56*83ee113eSDavid van Moolenbroek } omapi_buffer_t;
57*83ee113eSDavid van Moolenbroek 
58*83ee113eSDavid van Moolenbroek #define BUFFER_BYTES_FREE(x)	\
59*83ee113eSDavid van Moolenbroek 	((x) -> tail > (x) -> head \
60*83ee113eSDavid van Moolenbroek 	  ? sizeof ((x) -> buf) - ((x) -> tail - (x) -> head) \
61*83ee113eSDavid van Moolenbroek 	  : (x) -> head - (x) -> tail)
62*83ee113eSDavid van Moolenbroek 
63*83ee113eSDavid van Moolenbroek #define BYTES_IN_BUFFER(x)	\
64*83ee113eSDavid van Moolenbroek 	((x) -> tail > (x) -> head \
65*83ee113eSDavid van Moolenbroek 	 ? (x) -> tail - (x) -> head - 1 \
66*83ee113eSDavid van Moolenbroek 	 : sizeof ((x) -> buf) - ((x) -> head - (x) -> tail) - 1)
67*83ee113eSDavid van Moolenbroek 
68*83ee113eSDavid van Moolenbroek isc_result_t omapi_connection_require (omapi_object_t *, unsigned);
69*83ee113eSDavid van Moolenbroek isc_result_t omapi_connection_copyout (unsigned char *,
70*83ee113eSDavid van Moolenbroek 				       omapi_object_t *, unsigned);
71*83ee113eSDavid van Moolenbroek isc_result_t omapi_connection_copyin (omapi_object_t *,
72*83ee113eSDavid van Moolenbroek 				      const unsigned char *, unsigned);
73*83ee113eSDavid van Moolenbroek isc_result_t omapi_connection_flush (omapi_object_t *);
74*83ee113eSDavid van Moolenbroek isc_result_t omapi_connection_get_uint32 (omapi_object_t *, u_int32_t *);
75*83ee113eSDavid van Moolenbroek isc_result_t omapi_connection_put_uint32 (omapi_object_t *, u_int32_t);
76*83ee113eSDavid van Moolenbroek isc_result_t omapi_connection_get_uint16 (omapi_object_t *, u_int16_t *);
77*83ee113eSDavid van Moolenbroek isc_result_t omapi_connection_put_uint16 (omapi_object_t *, u_int32_t);
78*83ee113eSDavid van Moolenbroek 
79