acpi.4: Add some missing references.
[dragonfly.git] / contrib / bind-9.3 / bin / named / include / named / lwdclient.h
1 /*
2  * Copyright (C) 2004  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 2000, 2001  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15  * PERFORMANCE OF THIS SOFTWARE.
16  */
17
18 /* $Id: lwdclient.h,v 1.13.208.1 2004/03/06 10:21:24 marka Exp $ */
19
20 #ifndef NAMED_LWDCLIENT_H
21 #define NAMED_LWDCLIENT_H 1
22
23 #include <isc/event.h>
24 #include <isc/eventclass.h>
25 #include <isc/netaddr.h>
26 #include <isc/sockaddr.h>
27 #include <isc/types.h>
28
29 #include <dns/fixedname.h>
30 #include <dns/types.h>
31
32 #include <lwres/lwres.h>
33
34 #include <named/lwsearch.h>
35
36 #define LWRD_EVENTCLASS         ISC_EVENTCLASS(4242)
37
38 #define LWRD_SHUTDOWN           (LWRD_EVENTCLASS + 0x0001)
39
40 struct ns_lwdclient {
41         isc_sockaddr_t          address;        /* where to reply */
42         struct in6_pktinfo      pktinfo;
43         isc_boolean_t           pktinfo_valid;
44         ns_lwdclientmgr_t       *clientmgr;     /* our parent */
45         ISC_LINK(ns_lwdclient_t) link;
46         unsigned int            state;
47         void                    *arg;           /* packet processing state */
48
49         /*
50          * Received data info.
51          */
52         unsigned char           buffer[LWRES_RECVLENGTH]; /* receive buffer */
53         isc_uint32_t            recvlength;     /* length recv'd */
54         lwres_lwpacket_t        pkt;
55
56         /*
57          * Send data state.  If sendbuf != buffer (that is, the send buffer
58          * isn't our receive buffer) it will be freed to the lwres_context_t.
59          */
60         unsigned char          *sendbuf;
61         isc_uint32_t            sendlength;
62         isc_buffer_t            recv_buffer;
63
64         /*
65          * gabn (get address by name) state info.
66          */
67         dns_adbfind_t           *find;
68         dns_adbfind_t           *v4find;
69         dns_adbfind_t           *v6find;
70         unsigned int            find_wanted;    /* Addresses we want */
71         dns_fixedname_t         query_name;
72         dns_fixedname_t         target_name;
73         ns_lwsearchctx_t        searchctx;
74         lwres_gabnresponse_t    gabn;
75
76         /*
77          * gnba (get name by address) state info.
78          */
79         lwres_gnbaresponse_t    gnba;
80         dns_byaddr_t           *byaddr;
81         unsigned int            options;
82         isc_netaddr_t           na;
83
84         /*
85          * grbn (get rrset by name) state info.
86          *
87          * Note: this also uses target_name and searchctx.
88          */
89         lwres_grbnresponse_t    grbn;
90         dns_lookup_t           *lookup;
91         dns_rdatatype_t         rdtype;
92
93         /*
94          * Alias and address info.  This is copied up to the gabn/gnba
95          * structures eventually.
96          *
97          * XXXMLG We can keep all of this in a client since we only service
98          * three packet types right now.  If we started handling more,
99          * we'd need to use "arg" above and allocate/destroy things.
100          */
101         char                   *aliases[LWRES_MAX_ALIASES];
102         isc_uint16_t            aliaslen[LWRES_MAX_ALIASES];
103         lwres_addr_t            addrs[LWRES_MAX_ADDRS];
104 };
105
106 /*
107  * Client states.
108  *
109  * _IDLE        The client is not doing anything at all.
110  *
111  * _RECV        The client is waiting for data after issuing a socket recv().
112  *
113  * _RECVDONE    Data has been received, and is being processed.
114  *
115  * _FINDWAIT    An adb (or other) request was made that cannot be satisfied
116  *              immediately.  An event will wake the client up.
117  *
118  * _SEND        All data for a response has completed, and a reply was
119  *              sent via a socket send() call.
120  *
121  * Badly formatted state table:
122  *
123  *      IDLE -> RECV when client has a recv() queued.
124  *
125  *      RECV -> RECVDONE when recvdone event received.
126  *
127  *      RECVDONE -> SEND if the data for a reply is at hand.
128  *      RECVDONE -> FINDWAIT if more searching is needed, and events will
129  *              eventually wake us up again.
130  *
131  *      FINDWAIT -> SEND when enough data was received to reply.
132  *
133  *      SEND -> IDLE when a senddone event was received.
134  *
135  *      At any time -> IDLE on error.  Sometimes this will be -> SEND
136  *      instead, if enough data is on hand to reply with a meaningful
137  *      error.
138  *
139  *      Packets which are badly formatted may or may not get error returns.
140  */
141 #define NS_LWDCLIENT_STATEIDLE          1
142 #define NS_LWDCLIENT_STATERECV          2
143 #define NS_LWDCLIENT_STATERECVDONE      3
144 #define NS_LWDCLIENT_STATEFINDWAIT      4
145 #define NS_LWDCLIENT_STATESEND          5
146 #define NS_LWDCLIENT_STATESENDDONE      6
147
148 #define NS_LWDCLIENT_ISIDLE(c)          \
149                         ((c)->state == NS_LWDCLIENT_STATEIDLE)
150 #define NS_LWDCLIENT_ISRECV(c)          \
151                         ((c)->state == NS_LWDCLIENT_STATERECV)
152 #define NS_LWDCLIENT_ISRECVDONE(c)      \
153                         ((c)->state == NS_LWDCLIENT_STATERECVDONE)
154 #define NS_LWDCLIENT_ISFINDWAIT(c)      \
155                         ((c)->state == NS_LWDCLIENT_STATEFINDWAIT)
156 #define NS_LWDCLIENT_ISSEND(c)          \
157                         ((c)->state == NS_LWDCLIENT_STATESEND)
158
159 /*
160  * Overall magic test that means we're not idle.
161  */
162 #define NS_LWDCLIENT_ISRUNNING(c)       (!NS_LWDCLIENT_ISIDLE(c))
163
164 #define NS_LWDCLIENT_SETIDLE(c)         \
165                         ((c)->state = NS_LWDCLIENT_STATEIDLE)
166 #define NS_LWDCLIENT_SETRECV(c)         \
167                         ((c)->state = NS_LWDCLIENT_STATERECV)
168 #define NS_LWDCLIENT_SETRECVDONE(c)     \
169                         ((c)->state = NS_LWDCLIENT_STATERECVDONE)
170 #define NS_LWDCLIENT_SETFINDWAIT(c)     \
171                         ((c)->state = NS_LWDCLIENT_STATEFINDWAIT)
172 #define NS_LWDCLIENT_SETSEND(c)         \
173                         ((c)->state = NS_LWDCLIENT_STATESEND)
174 #define NS_LWDCLIENT_SETSENDDONE(c)     \
175                         ((c)->state = NS_LWDCLIENT_STATESENDDONE)
176
177 struct ns_lwdclientmgr {
178         ns_lwreslistener_t     *listener;
179         isc_mem_t              *mctx;
180         isc_socket_t           *sock;           /* socket to use */
181         dns_view_t             *view;
182         lwres_context_t        *lwctx;          /* lightweight proto context */
183         isc_task_t             *task;           /* owning task */
184         unsigned int            flags;
185         ISC_LINK(ns_lwdclientmgr_t)     link;
186         ISC_LIST(ns_lwdclient_t)        idle;           /* idle client slots */
187         ISC_LIST(ns_lwdclient_t)        running;        /* running clients */
188 };
189
190 #define NS_LWDCLIENTMGR_FLAGRECVPENDING         0x00000001
191 #define NS_LWDCLIENTMGR_FLAGSHUTTINGDOWN        0x00000002
192
193 isc_result_t
194 ns_lwdclientmgr_create(ns_lwreslistener_t *, unsigned int, isc_taskmgr_t *);
195
196 void
197 ns_lwdclient_initialize(ns_lwdclient_t *, ns_lwdclientmgr_t *);
198
199 isc_result_t
200 ns_lwdclient_startrecv(ns_lwdclientmgr_t *);
201
202 void
203 ns_lwdclient_stateidle(ns_lwdclient_t *);
204
205 void
206 ns_lwdclient_recv(isc_task_t *, isc_event_t *);
207
208 void
209 ns_lwdclient_shutdown(isc_task_t *, isc_event_t *);
210
211 void
212 ns_lwdclient_send(isc_task_t *, isc_event_t *);
213
214 isc_result_t
215 ns_lwdclient_sendreply(ns_lwdclient_t *client, isc_region_t *r);
216
217 /*
218  * Processing functions of various types.
219  */
220 void ns_lwdclient_processgabn(ns_lwdclient_t *, lwres_buffer_t *);
221 void ns_lwdclient_processgnba(ns_lwdclient_t *, lwres_buffer_t *);
222 void ns_lwdclient_processgrbn(ns_lwdclient_t *, lwres_buffer_t *);
223 void ns_lwdclient_processnoop(ns_lwdclient_t *, lwres_buffer_t *);
224
225 void ns_lwdclient_errorpktsend(ns_lwdclient_t *, isc_uint32_t);
226
227 void ns_lwdclient_log(int level, const char *format, ...)
228      ISC_FORMAT_PRINTF(2, 3);
229
230 #endif /* NAMED_LWDCLIENT_H */