client.c revision 915723e4007e177b10c0e1c9d1bfe77ac2bfe853
297be3708069ef31814d6d75c0d71a50a78feb03Mark Andrews * Copyright (C) 2000 Internet Software Consortium.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Permission to use, copy, modify, and distribute this software for any
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * purpose with or without fee is hereby granted, provided that the above
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * copyright notice and this permission notice appear in all copies.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein unsigned char *p;
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein unsigned int cnt;
ab8729140b1ad688ab03e1e9ce438fb1cbb49222Automatic Updater printf("*** %s (%u bytes @ %p)\n", msg, len, base);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein if ((cm->flags & CLIENTMGR_FLAG_SHUTTINGDOWN) == 0)
ab8729140b1ad688ab03e1e9ce438fb1cbb49222Automatic Updater lwres_buffer_init(&b, client->buffer, client->recvlength);
ab8729140b1ad688ab03e1e9ce438fb1cbb49222Automatic Updater result = lwres_lwpacket_parseheader(&b, &client->pkt);
28b3569d6248168e6c00caab951521cc8141a49dAutomatic Updater DP(50, "OPCODE %08x", client->pkt.opcode);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein DP(50, "Unknown opcode %08x", client->pkt.opcode);
28b3569d6248168e6c00caab951521cc8141a49dAutomatic Updater * Drop the packet.
28b3569d6248168e6c00caab951521cc8141a49dAutomatic Updater DP(50, "restarting client %p...", client);
28b3569d6248168e6c00caab951521cc8141a49dAutomatic Updater isc_socketevent_t *dev = (isc_socketevent_t *)ev;
28b3569d6248168e6c00caab951521cc8141a49dAutomatic Updater INSIST(dev->region.base == client->buffer);
28b3569d6248168e6c00caab951521cc8141a49dAutomatic Updater INSIST((cm->flags & CLIENTMGR_FLAG_RECVPENDING) != 0);
28b3569d6248168e6c00caab951521cc8141a49dAutomatic Updater DP(50, "Event received! Task %p, length %u, result %u (%s)",
28b3569d6248168e6c00caab951521cc8141a49dAutomatic Updater task, dev->n, dev->result, isc_result_totext(dev->result));
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * XXXMLG If we wanted to run on ipv6 as well, we'd need the pktinfo
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * bits. Right now we don't, so don't remember them.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * This function will start a new recv() on a socket for this client manager.
28b3569d6248168e6c00caab951521cc8141a49dAutomatic Updater if ((cm->flags & CLIENTMGR_FLAG_SHUTTINGDOWN) != 0)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * If a recv is already running, don't bother.
28b3569d6248168e6c00caab951521cc8141a49dAutomatic Updater if ((cm->flags & CLIENTMGR_FLAG_RECVPENDING) != 0)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * If we have no idle slots, just return success.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * Issue the recv. If it fails, return that it did.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews result = isc_socket_recv(cm->sock, &r, 0, cm->task, client_recv,
28b3569d6248168e6c00caab951521cc8141a49dAutomatic Updater * Set the flag to say we've issued a recv() call.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * Remove the client from the idle list, and put it on the running
71c66a876ecca77923638d3f94cc0783152b2f03Mark Andrewsclient_shutdown(isc_task_t *task, isc_event_t *ev)
71c66a876ecca77923638d3f94cc0783152b2f03Mark Andrews REQUIRE((cm->flags & CLIENTMGR_FLAG_SHUTTINGDOWN) == 0);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Cancel any pending I/O.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein if ((cm->flags & CLIENTMGR_FLAG_RECVPENDING) != 0)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein isc_socket_cancel(cm->sock, task, ISC_SOCKCANCEL_ALL);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Run through the running client list and kill off any finds
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * in progress.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein /* XXXMLG */
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Do all the crap needed to move a client from the run queue to the idle
for (i = 0 ; i < LWRES_MAX_ALIASES ; i++) {
for (i = 0 ; i < LWRES_MAX_ADDRS ; i++) {