1 /*	$NetBSD: lwpacket.h,v 1.4 2014/12/10 04:38:02 christos Exp $	*/
2 
3 /*
4  * Copyright (C) 2004-2007  Internet Systems Consortium, Inc. ("ISC")
5  * Copyright (C) 1999-2001  Internet Software Consortium.
6  *
7  * Permission to use, copy, modify, and/or distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /* Id: lwpacket.h,v 1.24 2007/06/19 23:47:23 tbox Exp  */
21 
22 #ifndef LWRES_LWPACKET_H
23 #define LWRES_LWPACKET_H 1
24 
25 #include <lwres/lang.h>
26 #include <lwres/lwbuffer.h>
27 #include <lwres/result.h>
28 
29 /*% lwres_lwpacket_t */
30 typedef struct lwres_lwpacket lwres_lwpacket_t;
31 
32 /*% lwres_lwpacket structure */
33 struct lwres_lwpacket {
34 	/*! The overall packet length, including the
35 	 *  entire packet header.
36 	 *  This field is filled in by the
37 	 *  \link lwres_gabn.c lwres_gabn_*()\endlink
38 	 *  and \link lwres_gnba.c lwres_gnba_*()\endlink calls.
39 	 */
40 	lwres_uint32_t		length;
41 	/*! Specifies the header format.  Currently,
42 	 *  there is only one format, #LWRES_LWPACKETVERSION_0.
43 	 *  This field is filled in by the
44 	 *  \link lwres_gabn.c lwres_gabn_*()\endlink
45 	 *  and \link lwres_gnba.c lwres_gnba_*()\endlink calls.
46          */
47 	lwres_uint16_t		version;
48  	/*! Specifies library-defined flags for this packet, such as
49 	 *  whether the packet is a request or a reply.  None of
50 	 *  these are definable by the caller, but library-defined values
51 	 *  can be set by the caller.  For example, one bit in this field
52 	 *  indicates if the packet is a request or a response.
53 	 *  This field is filled in by
54 	 *  the application wits the exception of the
55 	 *  #LWRES_LWPACKETFLAG_RESPONSE bit, which is set by the library
56 	 *  in the
57 	 *  \link lwres_gabn.c lwres_gabn_*()\endlink
58 	 *  and \link lwres_gnba.c lwres_gnba_*()\endlink calls.
59          */
60 	lwres_uint16_t		pktflags;
61  	/*! Set by the requestor and is returned in all replies.
62 	 *  If two packets from the same source have the same serial
63 	 *  number and are from the same source, they are assumed to
64 	 *  be duplicates and the latter ones may be dropped.
65 	 *  (The library does not do this by default on replies, but
66  	 * does so on requests.)
67          */
68 	lwres_uint32_t		serial;
69  	/*! Opcodes between 0x04000000 and 0xffffffff
70  	 *  are application defined.  Opcodes between
71 	 *  0x00000000 and 0x03ffffff are
72  	 * reserved for library use.
73 	 *  This field is filled in by the
74 	 *  \link lwres_gabn.c lwres_gabn_*()\endlink
75 	 *  and \link lwres_gnba.c lwres_gnba_*()\endlink calls.
76 	 */
77 	lwres_uint32_t		opcode;
78  	/*! Only valid for results.
79 	 *  Results between 0x04000000 and 0xffffffff are application
80 	 *  defined.
81  	 * Results between 0x00000000 and 0x03ffffff are reserved for
82 	 * library use.
83  	 * (This is the same reserved range defined in <isc/resultclass.h>,
84 	 * so it
85  	 * would be trivial to map ISC_R_* result codes into packet result
86 	 * codes when appropriate.)
87 	 *  This field is filled in by the
88 	 *  \link lwres_gabn.c lwres_gabn_*()\endlink
89 	 *  and \link lwres_gnba.c lwres_gnba_*()\endlink calls.
90 	 */
91 	lwres_uint32_t		result;
92  	/*! Set to the maximum buffer size that the receiver can
93  	 *  handle on requests, and the size of the buffer needed to
94 	 *  satisfy a request
95  	 *  when the buffer is too large for replies.
96 	 *  This field is supplied by the application.
97 	 */
98 	lwres_uint32_t		recvlength;
99  	/*! The packet level auth type used.
100  	 *  Authtypes between 0x1000 and 0xffff are application defined.
101 	 *  Authtypes
102  	 *  between 0x0000 and 0x0fff are reserved for library use.
103 	 *  This is currently
104  	 *  unused and MUST be set to zero.
105 	 */
106 	lwres_uint16_t		authtype;
107  	/*! The length of the authentication data.
108 	 *  See the specific
109  	 * authtypes for more information on what is contained
110 	 * in this field.  This is currently unused, and
111 	 * MUST be set to zero.
112 	 */
113 	lwres_uint16_t		authlength;
114 };
115 
116 #define LWRES_LWPACKET_LENGTH		(4 * 5 + 2 * 4) /*%< Overall length. */
117 
118 #define LWRES_LWPACKETFLAG_RESPONSE	0x0001U	/*%< If set, pkt is a response. */
119 
120 
121 #define LWRES_LWPACKETVERSION_0		0	/*%< Header format. */
122 
123 /*! \file lwres/lwpacket.h
124  *
125  *
126  * The remainder of the packet consists of two regions, one described by
127  * "authlen" and one of "length - authlen - sizeof(lwres_lwpacket_t)".
128  *
129  * That is:
130  *
131  * \code
132  *	pkt header
133  *	authlen bytes of auth information
134  *	data bytes
135  * \endcode
136  *
137  * Currently defined opcodes:
138  *
139  *\li	#LWRES_OPCODE_NOOP.  Success is always returned, with the packet contents echoed.
140  *
141  *\li	#LWRES_OPCODE_GETADDRSBYNAME.  Return all known addresses for a given name.
142  *		This may return NIS or /etc/hosts info as well as DNS
143  *		information.  Flags will be provided to indicate ip4/ip6
144  *		addresses are desired.
145  *
146  *\li	#LWRES_OPCODE_GETNAMEBYADDR.	Return the hostname for the given address.  Once
147  *		again, it will return data from multiple sources.
148  */
149 
150 LWRES_LANG_BEGINDECLS
151 
152 /* XXXMLG document */
153 lwres_result_t
154 lwres_lwpacket_renderheader(lwres_buffer_t *b, lwres_lwpacket_t *pkt);
155 
156 lwres_result_t
157 lwres_lwpacket_parseheader(lwres_buffer_t *b, lwres_lwpacket_t *pkt);
158 
159 LWRES_LANG_ENDDECLS
160 
161 #endif /* LWRES_LWPACKET_H */
162