1546f56c3Schristos /* 2546f56c3Schristos * Copyright (c) 1983, 1989, 1993 3546f56c3Schristos * The Regents of the University of California. All rights reserved. 4546f56c3Schristos * 5546f56c3Schristos * Redistribution and use in source and binary forms, with or without 6546f56c3Schristos * modification, are permitted provided that the following conditions 7546f56c3Schristos * are met: 8546f56c3Schristos * 1. Redistributions of source code must retain the above copyright 9546f56c3Schristos * notice, this list of conditions and the following disclaimer. 10546f56c3Schristos * 2. Redistributions in binary form must reproduce the above copyright 11546f56c3Schristos * notice, this list of conditions and the following disclaimer in the 12546f56c3Schristos * documentation and/or other materials provided with the distribution. 13c8632dc8Schristos * 3. Neither the name of the University nor the names of its contributors 14546f56c3Schristos * may be used to endorse or promote products derived from this software 15546f56c3Schristos * without specific prior written permission. 16546f56c3Schristos * 17546f56c3Schristos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18546f56c3Schristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19546f56c3Schristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20546f56c3Schristos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21546f56c3Schristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22546f56c3Schristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23546f56c3Schristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24546f56c3Schristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25546f56c3Schristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26546f56c3Schristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27546f56c3Schristos * SUCH DAMAGE. 28546f56c3Schristos * 29546f56c3Schristos * @(#)nameser.h 8.2 (Berkeley) 2/16/94 30546f56c3Schristos * - 31546f56c3Schristos * Portions Copyright (c) 1993 by Digital Equipment Corporation. 32546f56c3Schristos * 33546f56c3Schristos * Permission to use, copy, modify, and distribute this software for any 34546f56c3Schristos * purpose with or without fee is hereby granted, provided that the above 35546f56c3Schristos * copyright notice and this permission notice appear in all copies, and that 36546f56c3Schristos * the name of Digital Equipment Corporation not be used in advertising or 37546f56c3Schristos * publicity pertaining to distribution of the document or software without 38546f56c3Schristos * specific, written prior permission. 39546f56c3Schristos * 40546f56c3Schristos * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL 41546f56c3Schristos * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 42546f56c3Schristos * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT 43546f56c3Schristos * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 44546f56c3Schristos * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 45546f56c3Schristos * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 46546f56c3Schristos * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 47546f56c3Schristos * SOFTWARE. 48546f56c3Schristos * - 49546f56c3Schristos * --Copyright-- 50546f56c3Schristos */ 51546f56c3Schristos 52546f56c3Schristos #ifndef _NAMESER_H_ 53546f56c3Schristos #define _NAMESER_H_ 54546f56c3Schristos 55546f56c3Schristos #include <sys/types.h> 56546f56c3Schristos 57546f56c3Schristos /* 58546f56c3Schristos * Define constants based on rfc883 59546f56c3Schristos */ 60546f56c3Schristos #define PACKETSZ 512 /* maximum packet size */ 61546f56c3Schristos #define MAXDNAME 256 /* maximum domain name */ 62546f56c3Schristos #define MAXCDNAME 255 /* maximum compressed domain name */ 63546f56c3Schristos #define MAXLABEL 63 /* maximum length of domain label */ 64546f56c3Schristos /* Number of bytes of fixed size data in query structure */ 65546f56c3Schristos #define QFIXEDSZ 4 66546f56c3Schristos /* number of bytes of fixed size data in resource record */ 67546f56c3Schristos #define RRFIXEDSZ 10 68546f56c3Schristos 69546f56c3Schristos /* 70546f56c3Schristos * Currently defined opcodes 71546f56c3Schristos */ 72546f56c3Schristos #define QUERY 0x0 /* standard query */ 73546f56c3Schristos #define IQUERY 0x1 /* inverse query */ 74546f56c3Schristos #define STATUS 0x2 /* nameserver status query */ 75546f56c3Schristos #if 0 76546f56c3Schristos #define xxx 0x3 /* 0x3 reserved */ 77546f56c3Schristos #endif 78546f56c3Schristos /* non standard - supports ALLOW_UPDATES stuff from Mike Schwartz */ 79546f56c3Schristos #define UPDATEA 0x9 /* add resource record */ 80546f56c3Schristos #define UPDATED 0xa /* delete a specific resource record */ 81546f56c3Schristos #define UPDATEDA 0xb /* delete all named resource record */ 82546f56c3Schristos #define UPDATEM 0xc /* modify a specific resource record */ 83546f56c3Schristos #define UPDATEMA 0xd /* modify all named resource record */ 84546f56c3Schristos 85546f56c3Schristos #define ZONEINIT 0xe /* initial zone transfer */ 86546f56c3Schristos #define ZONEREF 0xf /* incremental zone referesh */ 87546f56c3Schristos 88546f56c3Schristos /* 89546f56c3Schristos * Undefine various #defines from various System V-flavored OSes (Solaris, 90546f56c3Schristos * SINIX, HP-UX) so the compiler doesn't whine that we redefine them. 91546f56c3Schristos */ 92546f56c3Schristos #ifdef T_NULL 93546f56c3Schristos #undef T_NULL 94546f56c3Schristos #endif 95546f56c3Schristos #ifdef T_OPT 96546f56c3Schristos #undef T_OPT 97546f56c3Schristos #endif 98546f56c3Schristos #ifdef T_UNSPEC 99546f56c3Schristos #undef T_UNSPEC 100546f56c3Schristos #endif 101546f56c3Schristos #ifdef NOERROR 102546f56c3Schristos #undef NOERROR 103546f56c3Schristos #endif 104546f56c3Schristos 105546f56c3Schristos /* 106546f56c3Schristos * Currently defined response codes 107546f56c3Schristos */ 108546f56c3Schristos #define NOERROR 0 /* no error */ 109546f56c3Schristos #define FORMERR 1 /* format error */ 110546f56c3Schristos #define SERVFAIL 2 /* server failure */ 111546f56c3Schristos #define NXDOMAIN 3 /* non existent domain */ 112546f56c3Schristos #define NOTIMP 4 /* not implemented */ 113546f56c3Schristos #define REFUSED 5 /* query refused */ 114546f56c3Schristos /* non standard */ 115546f56c3Schristos #define NOCHANGE 0xf /* update failed to change db */ 116546f56c3Schristos 117546f56c3Schristos /* 118546f56c3Schristos * Type values for resources and queries 119546f56c3Schristos */ 120546f56c3Schristos #define T_A 1 /* host address */ 121546f56c3Schristos #define T_NS 2 /* authoritative server */ 122546f56c3Schristos #define T_MD 3 /* mail destination */ 123546f56c3Schristos #define T_MF 4 /* mail forwarder */ 124546f56c3Schristos #define T_CNAME 5 /* connonical name */ 125546f56c3Schristos #define T_SOA 6 /* start of authority zone */ 126546f56c3Schristos #define T_MB 7 /* mailbox domain name */ 127546f56c3Schristos #define T_MG 8 /* mail group member */ 128546f56c3Schristos #define T_MR 9 /* mail rename name */ 129546f56c3Schristos #define T_NULL 10 /* null resource record */ 130546f56c3Schristos #define T_WKS 11 /* well known service */ 131546f56c3Schristos #define T_PTR 12 /* domain name pointer */ 132546f56c3Schristos #define T_HINFO 13 /* host information */ 133546f56c3Schristos #define T_MINFO 14 /* mailbox information */ 134546f56c3Schristos #define T_MX 15 /* mail routing information */ 135546f56c3Schristos #define T_TXT 16 /* text strings */ 136546f56c3Schristos #define T_RP 17 /* responsible person */ 137546f56c3Schristos #define T_AFSDB 18 /* AFS cell database */ 138546f56c3Schristos #define T_X25 19 /* X_25 calling address */ 139546f56c3Schristos #define T_ISDN 20 /* ISDN calling address */ 140546f56c3Schristos #define T_RT 21 /* router */ 141546f56c3Schristos #define T_NSAP 22 /* NSAP address */ 142546f56c3Schristos #define T_NSAP_PTR 23 /* reverse lookup for NSAP */ 143546f56c3Schristos #define T_SIG 24 /* security signature */ 144546f56c3Schristos #define T_KEY 25 /* security key */ 145546f56c3Schristos #define T_PX 26 /* X.400 mail mapping */ 146546f56c3Schristos #define T_GPOS 27 /* geographical position (withdrawn) */ 147546f56c3Schristos #define T_AAAA 28 /* IP6 Address */ 148546f56c3Schristos #define T_LOC 29 /* Location Information */ 149546f56c3Schristos #define T_NXT 30 /* Next Valid Name in Zone */ 150546f56c3Schristos #define T_EID 31 /* Endpoint identifier */ 151546f56c3Schristos #define T_NIMLOC 32 /* Nimrod locator */ 152546f56c3Schristos #define T_SRV 33 /* Server selection */ 153546f56c3Schristos #define T_ATMA 34 /* ATM Address */ 154546f56c3Schristos #define T_NAPTR 35 /* Naming Authority PoinTeR */ 155546f56c3Schristos #define T_KX 36 /* Key Exchanger */ 156546f56c3Schristos #define T_CERT 37 /* Certificates in the DNS */ 157546f56c3Schristos #define T_A6 38 /* IP6 address */ 158546f56c3Schristos #define T_DNAME 39 /* non-terminal redirection */ 159546f56c3Schristos #define T_SINK 40 /* unknown */ 160546f56c3Schristos #define T_OPT 41 /* EDNS0 option (meta-RR) */ 161546f56c3Schristos #define T_APL 42 /* lists of address prefixes */ 162546f56c3Schristos #define T_DS 43 /* Delegation Signer */ 163546f56c3Schristos #define T_SSHFP 44 /* SSH Fingerprint */ 164546f56c3Schristos #define T_IPSECKEY 45 /* IPsec keying material */ 165546f56c3Schristos #define T_RRSIG 46 /* new security signature */ 166546f56c3Schristos #define T_NSEC 47 /* provable insecure information */ 167546f56c3Schristos #define T_DNSKEY 48 /* new security key */ 168546f56c3Schristos /* non standard */ 169546f56c3Schristos #define T_SPF 99 /* sender policy framework */ 170546f56c3Schristos #define T_UINFO 100 /* user (finger) information */ 171546f56c3Schristos #define T_UID 101 /* user ID */ 172546f56c3Schristos #define T_GID 102 /* group ID */ 173546f56c3Schristos #define T_UNSPEC 103 /* Unspecified format (binary data) */ 174546f56c3Schristos #define T_UNSPECA 104 /* "unspecified ascii". Ugly MIT hack */ 175546f56c3Schristos /* Query type values which do not appear in resource records */ 176546f56c3Schristos #define T_TKEY 249 /* Transaction Key [RFC2930] */ 177546f56c3Schristos #define T_TSIG 250 /* Transaction Signature [RFC2845] */ 178546f56c3Schristos #define T_IXFR 251 /* incremental transfer [RFC1995] */ 179546f56c3Schristos #define T_AXFR 252 /* transfer zone of authority */ 180546f56c3Schristos #define T_MAILB 253 /* transfer mailbox records */ 181546f56c3Schristos #define T_MAILA 254 /* transfer mail agent records */ 182546f56c3Schristos #define T_ANY 255 /* wildcard match */ 183546f56c3Schristos 184546f56c3Schristos /* 185546f56c3Schristos * Values for class field 186546f56c3Schristos */ 187546f56c3Schristos 188546f56c3Schristos #define C_IN 1 /* the arpa internet */ 189546f56c3Schristos #define C_CHAOS 3 /* for chaos net (MIT) */ 190546f56c3Schristos #define C_HS 4 /* for Hesiod name server (MIT) (XXX) */ 191546f56c3Schristos /* Query class values which do not appear in resource records */ 192546f56c3Schristos #define C_ANY 255 /* wildcard match */ 193546f56c3Schristos #define C_QU 0x8000 /* mDNS QU flag in queries */ 194546f56c3Schristos #define C_CACHE_FLUSH 0x8000 /* mDNS cache flush flag in replies */ 195546f56c3Schristos 196546f56c3Schristos /* 197546f56c3Schristos * Status return codes for T_UNSPEC conversion routines 198546f56c3Schristos */ 199546f56c3Schristos #define CONV_SUCCESS 0 200546f56c3Schristos #define CONV_OVERFLOW -1 201546f56c3Schristos #define CONV_BADFMT -2 202546f56c3Schristos #define CONV_BADCKSUM -3 203546f56c3Schristos #define CONV_BADBUFLEN -4 204546f56c3Schristos 205546f56c3Schristos /* 206546f56c3Schristos * Structure for query header. 207546f56c3Schristos */ 208546f56c3Schristos typedef struct { 209*7e4823a9Schristos uint16_t id; /* query identification number */ 210*7e4823a9Schristos uint8_t flags1; /* first byte of flags */ 211*7e4823a9Schristos uint8_t flags2; /* second byte of flags */ 212*7e4823a9Schristos uint16_t qdcount; /* number of question entries */ 213*7e4823a9Schristos uint16_t ancount; /* number of answer entries */ 214*7e4823a9Schristos uint16_t nscount; /* number of authority entries */ 215*7e4823a9Schristos uint16_t arcount; /* number of resource entries */ 216546f56c3Schristos } HEADER; 217546f56c3Schristos 218546f56c3Schristos /* 219546f56c3Schristos * Macros for subfields of flag fields. 220546f56c3Schristos */ 221546f56c3Schristos #define DNS_QR(np) ((np)->flags1 & 0x80) /* response flag */ 222546f56c3Schristos #define DNS_OPCODE(np) ((((np)->flags1) >> 3) & 0xF) /* purpose of message */ 223546f56c3Schristos #define DNS_AA(np) ((np)->flags1 & 0x04) /* authoritative answer */ 224546f56c3Schristos #define DNS_TC(np) ((np)->flags1 & 0x02) /* truncated message */ 225546f56c3Schristos #define DNS_RD(np) ((np)->flags1 & 0x01) /* recursion desired */ 226546f56c3Schristos 227546f56c3Schristos #define DNS_RA(np) ((np)->flags2 & 0x80) /* recursion available */ 228546f56c3Schristos #define DNS_AD(np) ((np)->flags2 & 0x20) /* authentic data from named */ 229546f56c3Schristos #define DNS_CD(np) ((np)->flags2 & 0x10) /* checking disabled by resolver */ 230546f56c3Schristos #define DNS_RCODE(np) ((np)->flags2 & 0xF) /* response code */ 231546f56c3Schristos 232546f56c3Schristos /* 233546f56c3Schristos * Defines for handling compressed domain names, EDNS0 labels, etc. 234546f56c3Schristos */ 235546f56c3Schristos #define INDIR_MASK 0xc0 /* 11.... */ 236546f56c3Schristos #define EDNS0_MASK 0x40 /* 01.... */ 237546f56c3Schristos # define EDNS0_ELT_BITLABEL 0x01 238546f56c3Schristos 239546f56c3Schristos /* 240546f56c3Schristos * Structure for passing resource records around. 241546f56c3Schristos */ 242546f56c3Schristos struct rrec { 243546f56c3Schristos int16_t r_zone; /* zone number */ 244546f56c3Schristos int16_t r_class; /* class number */ 245546f56c3Schristos int16_t r_type; /* type number */ 246*7e4823a9Schristos uint32_t r_ttl; /* time to live */ 247546f56c3Schristos int r_size; /* size of data area */ 248546f56c3Schristos char *r_data; /* pointer to data */ 249546f56c3Schristos }; 250546f56c3Schristos 251546f56c3Schristos /* 252546f56c3Schristos * Inline versions of get/put short/long. Pointer is advanced. 253*7e4823a9Schristos * We also assume that a "uint16_t" holds 2 "chars" 254*7e4823a9Schristos * and that a "uint32_t" holds 4 "chars". 255546f56c3Schristos * 256546f56c3Schristos * These macros demonstrate the property of C whereby it can be 257546f56c3Schristos * portable or it can be elegant but never both. 258546f56c3Schristos */ 259546f56c3Schristos #define GETSHORT(s, cp) { \ 260546f56c3Schristos register u_char *t_cp = (u_char *)(cp); \ 261*7e4823a9Schristos (s) = ((uint16_t)t_cp[0] << 8) | (uint16_t)t_cp[1]; \ 262546f56c3Schristos (cp) += 2; \ 263546f56c3Schristos } 264546f56c3Schristos 265546f56c3Schristos #define GETLONG(l, cp) { \ 266546f56c3Schristos register u_char *t_cp = (u_char *)(cp); \ 267*7e4823a9Schristos (l) = (((uint32_t)t_cp[0]) << 24) \ 268*7e4823a9Schristos | (((uint32_t)t_cp[1]) << 16) \ 269*7e4823a9Schristos | (((uint32_t)t_cp[2]) << 8) \ 270*7e4823a9Schristos | (((uint32_t)t_cp[3])); \ 271546f56c3Schristos (cp) += 4; \ 272546f56c3Schristos } 273546f56c3Schristos 274546f56c3Schristos #define PUTSHORT(s, cp) { \ 275*7e4823a9Schristos register uint16_t t_s = (uint16_t)(s); \ 276546f56c3Schristos register u_char *t_cp = (u_char *)(cp); \ 277546f56c3Schristos *t_cp++ = t_s >> 8; \ 278546f56c3Schristos *t_cp = t_s; \ 279546f56c3Schristos (cp) += 2; \ 280546f56c3Schristos } 281546f56c3Schristos 282546f56c3Schristos /* 283546f56c3Schristos * Warning: PUTLONG --no-longer-- destroys its first argument. if you 284546f56c3Schristos * were depending on this "feature", you will lose. 285546f56c3Schristos */ 286546f56c3Schristos #define PUTLONG(l, cp) { \ 287*7e4823a9Schristos register uint32_t t_l = (uint32_t)(l); \ 288546f56c3Schristos register u_char *t_cp = (u_char *)(cp); \ 289546f56c3Schristos *t_cp++ = t_l >> 24; \ 290546f56c3Schristos *t_cp++ = t_l >> 16; \ 291546f56c3Schristos *t_cp++ = t_l >> 8; \ 292546f56c3Schristos *t_cp = t_l; \ 293546f56c3Schristos (cp) += 4; \ 294546f56c3Schristos } 295546f56c3Schristos 296546f56c3Schristos #endif /* !_NAMESER_H_ */ 297