|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
- Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
|
Packit Service |
ae04f2 |
-
|
|
Packit Service |
ae04f2 |
- This Source Code Form is subject to the terms of the Mozilla Public
|
|
Packit Service |
ae04f2 |
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
Packit Service |
ae04f2 |
- file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
Packit Service |
ae04f2 |
-
|
|
Packit Service |
ae04f2 |
- See the COPYRIGHT file distributed with this work for additional
|
|
Packit Service |
ae04f2 |
- information regarding copyright ownership.
|
|
Packit Service |
ae04f2 |
-->
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
<refentry xmlns:db="http://docbook.org/ns/docbook" version="5.0">
|
|
Packit Service |
ae04f2 |
<info>
|
|
Packit Service |
ae04f2 |
<date>2007-06-18</date>
|
|
Packit Service |
ae04f2 |
</info>
|
|
Packit Service |
ae04f2 |
<refentryinfo>
|
|
Packit Service |
ae04f2 |
<corpname>ISC</corpname>
|
|
Packit Service |
ae04f2 |
<corpauthor>Internet Systems Consortium, Inc.</corpauthor>
|
|
Packit Service |
ae04f2 |
</refentryinfo>
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
<refmeta>
|
|
Packit Service |
ae04f2 |
<refentrytitle>lwres</refentrytitle>
|
|
Packit Service |
ae04f2 |
<manvolnum>3</manvolnum>
|
|
Packit Service |
ae04f2 |
<refmiscinfo>BIND9</refmiscinfo>
|
|
Packit Service |
ae04f2 |
</refmeta>
|
|
Packit Service |
ae04f2 |
<refnamediv>
|
|
Packit Service |
ae04f2 |
<refname>lwres</refname>
|
|
Packit Service |
ae04f2 |
<refpurpose>introduction to the lightweight resolver library</refpurpose>
|
|
Packit Service |
ae04f2 |
</refnamediv>
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
<docinfo>
|
|
Packit Service |
ae04f2 |
<copyright>
|
|
Packit Service |
ae04f2 |
<year>2000</year>
|
|
Packit Service |
ae04f2 |
<year>2001</year>
|
|
Packit Service |
ae04f2 |
<year>2004</year>
|
|
Packit Service |
ae04f2 |
<year>2005</year>
|
|
Packit Service |
ae04f2 |
<year>2007</year>
|
|
Packit Service |
ae04f2 |
<year>2014</year>
|
|
Packit Service |
ae04f2 |
<year>2015</year>
|
|
Packit Service |
ae04f2 |
<year>2016</year>
|
|
Packit Service |
ae04f2 |
<year>2018</year>
|
|
Packit Service |
ae04f2 |
<year>2019</year>
|
|
Packit Service |
ae04f2 |
<year>2020</year>
|
|
Packit Service |
ae04f2 |
<holder>Internet Systems Consortium, Inc. ("ISC")</holder>
|
|
Packit Service |
ae04f2 |
</copyright>
|
|
Packit Service |
ae04f2 |
</docinfo>
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
<refsynopsisdiv>
|
|
Packit Service |
ae04f2 |
<funcsynopsis>
|
|
Packit Service |
ae04f2 |
<funcsynopsisinfo>#include <lwres/lwres.h></funcsynopsisinfo>
|
|
Packit Service |
ae04f2 |
</funcsynopsis>
|
|
Packit Service |
ae04f2 |
</refsynopsisdiv>
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
<refsection><info><title>DESCRIPTION</title></info>
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
<para>
|
|
Packit Service |
ae04f2 |
The BIND 9 lightweight resolver library is a simple, name service
|
|
Packit Service |
ae04f2 |
independent stub resolver library. It provides hostname-to-address
|
|
Packit Service |
ae04f2 |
and address-to-hostname lookup services to applications by
|
|
Packit Service |
ae04f2 |
transmitting lookup requests to a resolver daemon
|
|
Packit Service |
ae04f2 |
<command>lwresd</command>
|
|
Packit Service |
ae04f2 |
running on the local host. The resolver daemon performs the
|
|
Packit Service |
ae04f2 |
lookup using the DNS or possibly other name service protocols,
|
|
Packit Service |
ae04f2 |
and returns the results to the application through the library.
|
|
Packit Service |
ae04f2 |
The library and resolver daemon communicate using a simple
|
|
Packit Service |
ae04f2 |
UDP-based protocol.
|
|
Packit Service |
ae04f2 |
</para>
|
|
Packit Service |
ae04f2 |
</refsection>
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
<refsection><info><title>OVERVIEW</title></info>
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
<para>
|
|
Packit Service |
ae04f2 |
The lwresd library implements multiple name service APIs.
|
|
Packit Service |
ae04f2 |
The standard
|
|
Packit Service |
ae04f2 |
<function>gethostbyname()</function>,
|
|
Packit Service |
ae04f2 |
<function>gethostbyaddr()</function>,
|
|
Packit Service |
ae04f2 |
<function>gethostbyname_r()</function>,
|
|
Packit Service |
ae04f2 |
<function>gethostbyaddr_r()</function>,
|
|
Packit Service |
ae04f2 |
<function>getaddrinfo()</function>,
|
|
Packit Service |
ae04f2 |
<function>getipnodebyname()</function>,
|
|
Packit Service |
ae04f2 |
and
|
|
Packit Service |
ae04f2 |
<function>getipnodebyaddr()</function>
|
|
Packit Service |
ae04f2 |
functions are all supported. To allow the lwres library to coexist
|
|
Packit Service |
ae04f2 |
with system libraries that define functions of the same name,
|
|
Packit Service |
ae04f2 |
the library defines these functions with names prefixed by
|
|
Packit Service |
ae04f2 |
<literal>lwres_</literal>.
|
|
Packit Service |
ae04f2 |
To define the standard names, applications must include the
|
|
Packit Service |
ae04f2 |
header file
|
|
Packit Service |
ae04f2 |
<filename><lwres/netdb.h></filename>
|
|
Packit Service |
ae04f2 |
which contains macro definitions mapping the standard function names
|
|
Packit Service |
ae04f2 |
into
|
|
Packit Service |
ae04f2 |
<literal>lwres_</literal>
|
|
Packit Service |
ae04f2 |
prefixed ones. Operating system vendors who integrate the lwres
|
|
Packit Service |
ae04f2 |
library into their base distributions should rename the functions
|
|
Packit Service |
ae04f2 |
in the library proper so that the renaming macros are not needed.
|
|
Packit Service |
ae04f2 |
</para>
|
|
Packit Service |
ae04f2 |
<para>
|
|
Packit Service |
ae04f2 |
The library also provides a native API consisting of the functions
|
|
Packit Service |
ae04f2 |
<function>lwres_getaddrsbyname()</function>
|
|
Packit Service |
ae04f2 |
and
|
|
Packit Service |
ae04f2 |
<function>lwres_getnamebyaddr()</function>.
|
|
Packit Service |
ae04f2 |
These may be called by applications that require more detailed
|
|
Packit Service |
ae04f2 |
control over the lookup process than the standard functions
|
|
Packit Service |
ae04f2 |
provide.
|
|
Packit Service |
ae04f2 |
</para>
|
|
Packit Service |
ae04f2 |
<para>
|
|
Packit Service |
ae04f2 |
In addition to these name service independent address lookup
|
|
Packit Service |
ae04f2 |
functions, the library implements a new, experimental API
|
|
Packit Service |
ae04f2 |
for looking up arbitrary DNS resource records, using the
|
|
Packit Service |
ae04f2 |
<function>lwres_getaddrsbyname()</function>
|
|
Packit Service |
ae04f2 |
function.
|
|
Packit Service |
ae04f2 |
</para>
|
|
Packit Service |
ae04f2 |
<para>
|
|
Packit Service |
ae04f2 |
Finally, there is a low-level API for converting lookup
|
|
Packit Service |
ae04f2 |
requests and responses to and from raw lwres protocol packets.
|
|
Packit Service |
ae04f2 |
This API can be used by clients requiring nonblocking operation,
|
|
Packit Service |
ae04f2 |
and is also used when implementing the server side of the lwres
|
|
Packit Service |
ae04f2 |
protocol, for example in the
|
|
Packit Service |
ae04f2 |
<command>lwresd</command>
|
|
Packit Service |
ae04f2 |
resolver daemon. The use of this low-level API in clients
|
|
Packit Service |
ae04f2 |
and servers is outlined in the following sections.
|
|
Packit Service |
ae04f2 |
</para>
|
|
Packit Service |
ae04f2 |
</refsection>
|
|
Packit Service |
ae04f2 |
<refsection><info><title>CLIENT-SIDE LOW-LEVEL API CALL FLOW</title></info>
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
<para>
|
|
Packit Service |
ae04f2 |
When a client program wishes to make an lwres request using the
|
|
Packit Service |
ae04f2 |
native low-level API, it typically performs the following
|
|
Packit Service |
ae04f2 |
sequence of actions.
|
|
Packit Service |
ae04f2 |
</para>
|
|
Packit Service |
ae04f2 |
<para>
|
|
Packit Service |
ae04f2 |
(1) Allocate or use an existing <type>lwres_packet_t</type>,
|
|
Packit Service |
ae04f2 |
called <varname>pkt</varname> below.
|
|
Packit Service |
ae04f2 |
</para>
|
|
Packit Service |
ae04f2 |
<para>
|
|
Packit Service |
ae04f2 |
(2) Set <varname remap="structfield">pkt.recvlength</varname> to the maximum length
|
|
Packit Service |
ae04f2 |
we will accept.
|
|
Packit Service |
ae04f2 |
This is done so the receiver of our packets knows how large our receive
|
|
Packit Service |
ae04f2 |
buffer is. The "default" is a constant in
|
|
Packit Service |
ae04f2 |
<filename>lwres.h</filename>: <constant>LWRES_RECVLENGTH = 4096</constant>.
|
|
Packit Service |
ae04f2 |
</para>
|
|
Packit Service |
ae04f2 |
<para>
|
|
Packit Service |
ae04f2 |
(3) Set <varname remap="structfield">pkt.serial</varname>
|
|
Packit Service |
ae04f2 |
to a unique serial number. This value is echoed
|
|
Packit Service |
ae04f2 |
back to the application by the remote server.
|
|
Packit Service |
ae04f2 |
</para>
|
|
Packit Service |
ae04f2 |
<para>
|
|
Packit Service |
ae04f2 |
(4) Set <varname remap="structfield">pkt.pktflags</varname>. Usually this is set to
|
|
Packit Service |
ae04f2 |
0.
|
|
Packit Service |
ae04f2 |
</para>
|
|
Packit Service |
ae04f2 |
<para>
|
|
Packit Service |
ae04f2 |
(5) Set <varname remap="structfield">pkt.result</varname> to 0.
|
|
Packit Service |
ae04f2 |
</para>
|
|
Packit Service |
ae04f2 |
<para>
|
|
Packit Service |
ae04f2 |
(6) Call <function>lwres_*request_render()</function>,
|
|
Packit Service |
ae04f2 |
or marshall in the data using the primitives
|
|
Packit Service |
ae04f2 |
such as <function>lwres_packet_render()</function>
|
|
Packit Service |
ae04f2 |
and storing the packet data.
|
|
Packit Service |
ae04f2 |
</para>
|
|
Packit Service |
ae04f2 |
<para>
|
|
Packit Service |
ae04f2 |
(7) Transmit the resulting buffer.
|
|
Packit Service |
ae04f2 |
</para>
|
|
Packit Service |
ae04f2 |
<para>
|
|
Packit Service |
ae04f2 |
(8) Call <function>lwres_*response_parse()</function>
|
|
Packit Service |
ae04f2 |
to parse any packets received.
|
|
Packit Service |
ae04f2 |
</para>
|
|
Packit Service |
ae04f2 |
<para>
|
|
Packit Service |
ae04f2 |
(9) Verify that the opcode and serial match a request, and process the
|
|
Packit Service |
ae04f2 |
packet specific information contained in the body.
|
|
Packit Service |
ae04f2 |
</para>
|
|
Packit Service |
ae04f2 |
</refsection>
|
|
Packit Service |
ae04f2 |
<refsection><info><title>SERVER-SIDE LOW-LEVEL API CALL FLOW</title></info>
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
<para>
|
|
Packit Service |
ae04f2 |
When implementing the server side of the lightweight resolver
|
|
Packit Service |
ae04f2 |
protocol using the lwres library, a sequence of actions like the
|
|
Packit Service |
ae04f2 |
following is typically involved in processing each request packet.
|
|
Packit Service |
ae04f2 |
</para>
|
|
Packit Service |
ae04f2 |
<para>
|
|
Packit Service |
ae04f2 |
Note that the same <type>lwres_packet_t</type> is used
|
|
Packit Service |
ae04f2 |
in both the <function>_parse()</function> and <function>_render()</function> calls,
|
|
Packit Service |
ae04f2 |
with only a few modifications made
|
|
Packit Service |
ae04f2 |
to the packet header's contents between uses. This method is
|
|
Packit Service |
ae04f2 |
recommended
|
|
Packit Service |
ae04f2 |
as it keeps the serial, opcode, and other fields correct.
|
|
Packit Service |
ae04f2 |
</para>
|
|
Packit Service |
ae04f2 |
<para>
|
|
Packit Service |
ae04f2 |
(1) When a packet is received, call <function>lwres_*request_parse()</function> to
|
|
Packit Service |
ae04f2 |
unmarshall it. This returns a <type>lwres_packet_t</type> (also called <varname>pkt</varname>, below)
|
|
Packit Service |
ae04f2 |
as well as a data specific type, such as <type>lwres_gabnrequest_t</type>.
|
|
Packit Service |
ae04f2 |
</para>
|
|
Packit Service |
ae04f2 |
<para>
|
|
Packit Service |
ae04f2 |
(2) Process the request in the data specific type.
|
|
Packit Service |
ae04f2 |
</para>
|
|
Packit Service |
ae04f2 |
<para>
|
|
Packit Service |
ae04f2 |
(3) Set the <varname remap="structfield">pkt.result</varname>,
|
|
Packit Service |
ae04f2 |
<varname remap="structfield">pkt.recvlength</varname> as above. All other fields
|
|
Packit Service |
ae04f2 |
can
|
|
Packit Service |
ae04f2 |
be left untouched since they were filled in by the <function>*_parse()</function> call
|
|
Packit Service |
ae04f2 |
above. If using <function>lwres_*response_render()</function>,
|
|
Packit Service |
ae04f2 |
<varname remap="structfield">pkt.pktflags</varname> will be set up
|
|
Packit Service |
ae04f2 |
properly. Otherwise, the <constant>LWRES_LWPACKETFLAG_RESPONSE</constant> bit should be
|
|
Packit Service |
ae04f2 |
set.
|
|
Packit Service |
ae04f2 |
</para>
|
|
Packit Service |
ae04f2 |
<para>
|
|
Packit Service |
ae04f2 |
(4) Call the data specific rendering function, such as
|
|
Packit Service |
ae04f2 |
<function>lwres_gabnresponse_render()</function>.
|
|
Packit Service |
ae04f2 |
</para>
|
|
Packit Service |
ae04f2 |
<para>
|
|
Packit Service |
ae04f2 |
(5) Send the resulting packet to the client.
|
|
Packit Service |
ae04f2 |
</para>
|
|
Packit Service |
ae04f2 |
<para/>
|
|
Packit Service |
ae04f2 |
</refsection>
|
|
Packit Service |
ae04f2 |
<refsection><info><title>SEE ALSO</title></info>
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
<para><citerefentry>
|
|
Packit Service |
ae04f2 |
<refentrytitle>lwres_gethostent</refentrytitle><manvolnum>3</manvolnum>
|
|
Packit Service |
ae04f2 |
</citerefentry>,
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
<citerefentry>
|
|
Packit Service |
ae04f2 |
<refentrytitle>lwres_getipnode</refentrytitle><manvolnum>3</manvolnum>
|
|
Packit Service |
ae04f2 |
</citerefentry>,
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
<citerefentry>
|
|
Packit Service |
ae04f2 |
<refentrytitle>lwres_getnameinfo</refentrytitle><manvolnum>3</manvolnum>
|
|
Packit Service |
ae04f2 |
</citerefentry>,
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
<citerefentry>
|
|
Packit Service |
ae04f2 |
<refentrytitle>lwres_noop</refentrytitle><manvolnum>3</manvolnum>
|
|
Packit Service |
ae04f2 |
</citerefentry>,
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
<citerefentry>
|
|
Packit Service |
ae04f2 |
<refentrytitle>lwres_gabn</refentrytitle><manvolnum>3</manvolnum>
|
|
Packit Service |
ae04f2 |
</citerefentry>,
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
<citerefentry>
|
|
Packit Service |
ae04f2 |
<refentrytitle>lwres_gnba</refentrytitle><manvolnum>3</manvolnum>
|
|
Packit Service |
ae04f2 |
</citerefentry>,
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
<citerefentry>
|
|
Packit Service |
ae04f2 |
<refentrytitle>lwres_context</refentrytitle><manvolnum>3</manvolnum>
|
|
Packit Service |
ae04f2 |
</citerefentry>,
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
<citerefentry>
|
|
Packit Service |
ae04f2 |
<refentrytitle>lwres_config</refentrytitle><manvolnum>3</manvolnum>
|
|
Packit Service |
ae04f2 |
</citerefentry>,
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
<citerefentry>
|
|
Packit Service |
ae04f2 |
<refentrytitle>resolver</refentrytitle><manvolnum>5</manvolnum>
|
|
Packit Service |
ae04f2 |
</citerefentry>,
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
<citerefentry>
|
|
Packit Service |
ae04f2 |
<refentrytitle>lwresd</refentrytitle><manvolnum>8</manvolnum>
|
|
Packit Service |
ae04f2 |
</citerefentry>.
|
|
Packit Service |
ae04f2 |
|
|
Packit Service |
ae04f2 |
</para>
|
|
Packit Service |
ae04f2 |
</refsection>
|
|
Packit Service |
ae04f2 |
</refentry>
|