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