1135446Strhodes/*
2193149Sdougb * Copyright (C) 2004-2007  Internet Systems Consortium, Inc. ("ISC")
3135446Strhodes * Copyright (C) 1999-2001  Internet Software Consortium.
4135446Strhodes *
5193149Sdougb * Permission to use, copy, modify, and/or distribute this software for any
6135446Strhodes * purpose with or without fee is hereby granted, provided that the above
7135446Strhodes * copyright notice and this permission notice appear in all copies.
8135446Strhodes *
9135446Strhodes * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10135446Strhodes * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11135446Strhodes * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12135446Strhodes * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13135446Strhodes * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14135446Strhodes * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15135446Strhodes * PERFORMANCE OF THIS SOFTWARE.
16135446Strhodes */
17135446Strhodes
18234010Sdougb/* $Id: lwpacket.h,v 1.24 2007/06/19 23:47:23 tbox Exp $ */
19135446Strhodes
20135446Strhodes#ifndef LWRES_LWPACKET_H
21135446Strhodes#define LWRES_LWPACKET_H 1
22135446Strhodes
23135446Strhodes#include <lwres/lang.h>
24135446Strhodes#include <lwres/lwbuffer.h>
25135446Strhodes#include <lwres/result.h>
26135446Strhodes
27170222Sdougb/*% lwres_lwpacket_t */
28135446Strhodestypedef struct lwres_lwpacket lwres_lwpacket_t;
29135446Strhodes
30170222Sdougb/*% lwres_lwpacket structure */
31135446Strhodesstruct lwres_lwpacket {
32170222Sdougb	/*! The overall packet length, including the
33170222Sdougb	 *  entire packet header.
34170222Sdougb	 *  This field is filled in by the
35170222Sdougb	 *  \link lwres_gabn.c lwres_gabn_*()\endlink
36170222Sdougb	 *  and \link lwres_gnba.c lwres_gnba_*()\endlink calls.
37170222Sdougb	 */
38135446Strhodes	lwres_uint32_t		length;
39170222Sdougb	/*! Specifies the header format.  Currently,
40170222Sdougb	 *  there is only one format, #LWRES_LWPACKETVERSION_0.
41170222Sdougb	 *  This field is filled in by the
42170222Sdougb	 *  \link lwres_gabn.c lwres_gabn_*()\endlink
43170222Sdougb	 *  and \link lwres_gnba.c lwres_gnba_*()\endlink calls.
44170222Sdougb         */
45135446Strhodes	lwres_uint16_t		version;
46170222Sdougb 	/*! Specifies library-defined flags for this packet, such as
47170222Sdougb	 *  whether the packet is a request or a reply.  None of
48170222Sdougb	 *  these are definable by the caller, but library-defined values
49170222Sdougb	 *  can be set by the caller.  For example, one bit in this field
50170222Sdougb	 *  indicates if the packet is a request or a response.
51170222Sdougb	 *  This field is filled in by
52170222Sdougb	 *  the application wits the exception of the
53170222Sdougb	 *  #LWRES_LWPACKETFLAG_RESPONSE bit, which is set by the library
54170222Sdougb	 *  in the
55170222Sdougb	 *  \link lwres_gabn.c lwres_gabn_*()\endlink
56170222Sdougb	 *  and \link lwres_gnba.c lwres_gnba_*()\endlink calls.
57170222Sdougb         */
58135446Strhodes	lwres_uint16_t		pktflags;
59170222Sdougb 	/*! Set by the requestor and is returned in all replies.
60170222Sdougb	 *  If two packets from the same source have the same serial
61170222Sdougb	 *  number and are from the same source, they are assumed to
62170222Sdougb	 *  be duplicates and the latter ones may be dropped.
63170222Sdougb	 *  (The library does not do this by default on replies, but
64170222Sdougb 	 * does so on requests.)
65170222Sdougb         */
66135446Strhodes	lwres_uint32_t		serial;
67170222Sdougb 	/*! Opcodes between 0x04000000 and 0xffffffff
68170222Sdougb 	 *  are application defined.  Opcodes between
69170222Sdougb	 *  0x00000000 and 0x03ffffff are
70170222Sdougb 	 * reserved for library use.
71170222Sdougb	 *  This field is filled in by the
72170222Sdougb	 *  \link lwres_gabn.c lwres_gabn_*()\endlink
73170222Sdougb	 *  and \link lwres_gnba.c lwres_gnba_*()\endlink calls.
74170222Sdougb	 */
75135446Strhodes	lwres_uint32_t		opcode;
76170222Sdougb 	/*! Only valid for results.
77170222Sdougb	 *  Results between 0x04000000 and 0xffffffff are application
78170222Sdougb	 *  defined.
79170222Sdougb 	 * Results between 0x00000000 and 0x03ffffff are reserved for
80170222Sdougb	 * library use.
81170222Sdougb 	 * (This is the same reserved range defined in <isc/resultclass.h>,
82170222Sdougb	 * so it
83170222Sdougb 	 * would be trivial to map ISC_R_* result codes into packet result
84170222Sdougb	 * codes when appropriate.)
85170222Sdougb	 *  This field is filled in by the
86170222Sdougb	 *  \link lwres_gabn.c lwres_gabn_*()\endlink
87170222Sdougb	 *  and \link lwres_gnba.c lwres_gnba_*()\endlink calls.
88170222Sdougb	 */
89135446Strhodes	lwres_uint32_t		result;
90170222Sdougb 	/*! Set to the maximum buffer size that the receiver can
91170222Sdougb 	 *  handle on requests, and the size of the buffer needed to
92170222Sdougb	 *  satisfy a request
93170222Sdougb 	 *  when the buffer is too large for replies.
94170222Sdougb	 *  This field is supplied by the application.
95170222Sdougb	 */
96135446Strhodes	lwres_uint32_t		recvlength;
97170222Sdougb 	/*! The packet level auth type used.
98170222Sdougb 	 *  Authtypes between 0x1000 and 0xffff are application defined.
99170222Sdougb	 *  Authtypes
100170222Sdougb 	 *  between 0x0000 and 0x0fff are reserved for library use.
101170222Sdougb	 *  This is currently
102170222Sdougb 	 *  unused and MUST be set to zero.
103170222Sdougb	 */
104135446Strhodes	lwres_uint16_t		authtype;
105170222Sdougb 	/*! The length of the authentication data.
106170222Sdougb	 *  See the specific
107170222Sdougb 	 * authtypes for more information on what is contained
108170222Sdougb	 * in this field.  This is currently unused, and
109170222Sdougb	 * MUST be set to zero.
110170222Sdougb	 */
111135446Strhodes	lwres_uint16_t		authlength;
112135446Strhodes};
113135446Strhodes
114170222Sdougb#define LWRES_LWPACKET_LENGTH		(4 * 5 + 2 * 4) /*%< Overall length. */
115135446Strhodes
116170222Sdougb#define LWRES_LWPACKETFLAG_RESPONSE	0x0001U	/*%< If set, pkt is a response. */
117135446Strhodes
118135446Strhodes
119170222Sdougb#define LWRES_LWPACKETVERSION_0		0	/*%< Header format. */
120135446Strhodes
121193149Sdougb/*! \file lwres/lwpacket.h
122135446Strhodes *
123135446Strhodes *
124135446Strhodes * The remainder of the packet consists of two regions, one described by
125135446Strhodes * "authlen" and one of "length - authlen - sizeof(lwres_lwpacket_t)".
126135446Strhodes *
127135446Strhodes * That is:
128135446Strhodes *
129170222Sdougb * \code
130135446Strhodes *	pkt header
131135446Strhodes *	authlen bytes of auth information
132135446Strhodes *	data bytes
133170222Sdougb * \endcode
134170222Sdougb *
135135446Strhodes * Currently defined opcodes:
136135446Strhodes *
137170222Sdougb *\li	#LWRES_OPCODE_NOOP.  Success is always returned, with the packet contents echoed.
138135446Strhodes *
139170222Sdougb *\li	#LWRES_OPCODE_GETADDRSBYNAME.  Return all known addresses for a given name.
140135446Strhodes *		This may return NIS or /etc/hosts info as well as DNS
141135446Strhodes *		information.  Flags will be provided to indicate ip4/ip6
142135446Strhodes *		addresses are desired.
143135446Strhodes *
144170222Sdougb *\li	#LWRES_OPCODE_GETNAMEBYADDR.	Return the hostname for the given address.  Once
145135446Strhodes *		again, it will return data from multiple sources.
146135446Strhodes */
147135446Strhodes
148135446StrhodesLWRES_LANG_BEGINDECLS
149135446Strhodes
150135446Strhodes/* XXXMLG document */
151135446Strhodeslwres_result_t
152135446Strhodeslwres_lwpacket_renderheader(lwres_buffer_t *b, lwres_lwpacket_t *pkt);
153135446Strhodes
154135446Strhodeslwres_result_t
155135446Strhodeslwres_lwpacket_parseheader(lwres_buffer_t *b, lwres_lwpacket_t *pkt);
156135446Strhodes
157135446StrhodesLWRES_LANG_ENDDECLS
158135446Strhodes
159135446Strhodes#endif /* LWRES_LWPACKET_H */
160