Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* $NetBSD: nameser.h,v 1.19 2005/12/26 19:01:47 perry Exp $ */ |
michael@0 | 2 | |
michael@0 | 3 | /* |
michael@0 | 4 | * Copyright (c) 1983, 1989, 1993 |
michael@0 | 5 | * The Regents of the University of California. All rights reserved. |
michael@0 | 6 | * |
michael@0 | 7 | * Redistribution and use in source and binary forms, with or without |
michael@0 | 8 | * modification, are permitted provided that the following conditions |
michael@0 | 9 | * are met: |
michael@0 | 10 | * 1. Redistributions of source code must retain the above copyright |
michael@0 | 11 | * notice, this list of conditions and the following disclaimer. |
michael@0 | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
michael@0 | 13 | * notice, this list of conditions and the following disclaimer in the |
michael@0 | 14 | * documentation and/or other materials provided with the distribution. |
michael@0 | 15 | * 3. Neither the name of the University nor the names of its contributors |
michael@0 | 16 | * may be used to endorse or promote products derived from this software |
michael@0 | 17 | * without specific prior written permission. |
michael@0 | 18 | * |
michael@0 | 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
michael@0 | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
michael@0 | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
michael@0 | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
michael@0 | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
michael@0 | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
michael@0 | 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
michael@0 | 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
michael@0 | 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
michael@0 | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
michael@0 | 29 | * SUCH DAMAGE. |
michael@0 | 30 | */ |
michael@0 | 31 | |
michael@0 | 32 | /* |
michael@0 | 33 | * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") |
michael@0 | 34 | * Copyright (c) 1996-1999 by Internet Software Consortium. |
michael@0 | 35 | * |
michael@0 | 36 | * Permission to use, copy, modify, and distribute this software for any |
michael@0 | 37 | * purpose with or without fee is hereby granted, provided that the above |
michael@0 | 38 | * copyright notice and this permission notice appear in all copies. |
michael@0 | 39 | * |
michael@0 | 40 | * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES |
michael@0 | 41 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
michael@0 | 42 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR |
michael@0 | 43 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
michael@0 | 44 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
michael@0 | 45 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
michael@0 | 46 | * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
michael@0 | 47 | */ |
michael@0 | 48 | |
michael@0 | 49 | /* |
michael@0 | 50 | * Id: nameser.h,v 1.2.2.4.4.1 2004/03/09 08:33:30 marka Exp |
michael@0 | 51 | */ |
michael@0 | 52 | |
michael@0 | 53 | /* |
michael@0 | 54 | * This version of this file is derived from Android 2.3 "Gingerbread", |
michael@0 | 55 | * which contains uncredited changes by Android/Google developers. It has |
michael@0 | 56 | * been modified in 2011 for use in the Android build of Mozilla Firefox by |
michael@0 | 57 | * Mozilla contributors (including Michael Edwards <m.k.edwards@gmail.com>, |
michael@0 | 58 | * and Steve Workman <sjhworkman@gmail.com>). |
michael@0 | 59 | * These changes are offered under the same license as the original NetBSD |
michael@0 | 60 | * file, whose copyright and license are unchanged above. |
michael@0 | 61 | */ |
michael@0 | 62 | |
michael@0 | 63 | #ifndef _ARPA_NAMESER_H_ |
michael@0 | 64 | #define _ARPA_NAMESER_H_ |
michael@0 | 65 | |
michael@0 | 66 | #define BIND_4_COMPAT |
michael@0 | 67 | |
michael@0 | 68 | #include <sys/types.h> |
michael@0 | 69 | #include <sys/cdefs.h> |
michael@0 | 70 | |
michael@0 | 71 | /* |
michael@0 | 72 | * Revision information. This is the release date in YYYYMMDD format. |
michael@0 | 73 | * It can change every day so the right thing to do with it is use it |
michael@0 | 74 | * in preprocessor commands such as "#if (__NAMESER > 19931104)". Do not |
michael@0 | 75 | * compare for equality; rather, use it to determine whether your libbind.a |
michael@0 | 76 | * contains a new enough lib/nameser/ to support the feature you need. |
michael@0 | 77 | */ |
michael@0 | 78 | |
michael@0 | 79 | #define __NAMESER 19991006 /* New interface version stamp. */ |
michael@0 | 80 | |
michael@0 | 81 | /* |
michael@0 | 82 | * Define constants based on RFC 883, RFC 1034, RFC 1035 |
michael@0 | 83 | */ |
michael@0 | 84 | #define NS_PACKETSZ 512 /* default UDP packet size */ |
michael@0 | 85 | #define NS_MAXDNAME 1025 /* maximum domain name */ |
michael@0 | 86 | #define NS_MAXMSG 65535 /* maximum message size */ |
michael@0 | 87 | #define NS_MAXCDNAME 255 /* maximum compressed domain name */ |
michael@0 | 88 | #define NS_MAXLABEL 63 /* maximum length of domain label */ |
michael@0 | 89 | #define NS_HFIXEDSZ 12 /* #/bytes of fixed data in header */ |
michael@0 | 90 | #define NS_QFIXEDSZ 4 /* #/bytes of fixed data in query */ |
michael@0 | 91 | #define NS_RRFIXEDSZ 10 /* #/bytes of fixed data in r record */ |
michael@0 | 92 | #define NS_INT32SZ 4 /* #/bytes of data in a uint32_t */ |
michael@0 | 93 | #define NS_INT16SZ 2 /* #/bytes of data in a uint16_t */ |
michael@0 | 94 | #define NS_INT8SZ 1 /* #/bytes of data in a uint8_t */ |
michael@0 | 95 | #define NS_INADDRSZ 4 /* IPv4 T_A */ |
michael@0 | 96 | #define NS_IN6ADDRSZ 16 /* IPv6 T_AAAA */ |
michael@0 | 97 | #define NS_CMPRSFLGS 0xc0 /* Flag bits indicating name compression. */ |
michael@0 | 98 | #define NS_DEFAULTPORT 53 /* For both TCP and UDP. */ |
michael@0 | 99 | |
michael@0 | 100 | /* |
michael@0 | 101 | * These can be expanded with synonyms, just keep ns_parse.c:ns_parserecord() |
michael@0 | 102 | * in synch with it. |
michael@0 | 103 | */ |
michael@0 | 104 | typedef enum __ns_sect { |
michael@0 | 105 | ns_s_qd = 0, /* Query: Question. */ |
michael@0 | 106 | ns_s_zn = 0, /* Update: Zone. */ |
michael@0 | 107 | ns_s_an = 1, /* Query: Answer. */ |
michael@0 | 108 | ns_s_pr = 1, /* Update: Prerequisites. */ |
michael@0 | 109 | ns_s_ns = 2, /* Query: Name servers. */ |
michael@0 | 110 | ns_s_ud = 2, /* Update: Update. */ |
michael@0 | 111 | ns_s_ar = 3, /* Query|Update: Additional records. */ |
michael@0 | 112 | ns_s_max = 4 |
michael@0 | 113 | } ns_sect; |
michael@0 | 114 | |
michael@0 | 115 | /* |
michael@0 | 116 | * This is a message handle. It is caller allocated and has no dynamic data. |
michael@0 | 117 | * This structure is intended to be opaque to all but ns_parse.c, thus the |
michael@0 | 118 | * leading _'s on the member names. Use the accessor functions, not the _'s. |
michael@0 | 119 | */ |
michael@0 | 120 | typedef struct __ns_msg { |
michael@0 | 121 | const u_char *_msg, *_eom; |
michael@0 | 122 | uint16_t _id, _flags, _counts[ns_s_max]; |
michael@0 | 123 | const u_char *_sections[ns_s_max]; |
michael@0 | 124 | ns_sect _sect; |
michael@0 | 125 | int _rrnum; |
michael@0 | 126 | const u_char *_msg_ptr; |
michael@0 | 127 | } ns_msg; |
michael@0 | 128 | |
michael@0 | 129 | /* Private data structure - do not use from outside library. */ |
michael@0 | 130 | struct _ns_flagdata { int mask, shift; }; |
michael@0 | 131 | extern const struct _ns_flagdata _ns_flagdata[]; |
michael@0 | 132 | |
michael@0 | 133 | /* Accessor macros - this is part of the public interface. */ |
michael@0 | 134 | |
michael@0 | 135 | #define ns_msg_id(handle) ((handle)._id + 0) |
michael@0 | 136 | #define ns_msg_base(handle) ((handle)._msg + 0) |
michael@0 | 137 | #define ns_msg_end(handle) ((handle)._eom + 0) |
michael@0 | 138 | #define ns_msg_size(handle) ((size_t)((handle)._eom - (handle)._msg)) |
michael@0 | 139 | #define ns_msg_count(handle, section) ((handle)._counts[section] + 0) |
michael@0 | 140 | |
michael@0 | 141 | /* |
michael@0 | 142 | * This is a parsed record. It is caller allocated and has no dynamic data. |
michael@0 | 143 | */ |
michael@0 | 144 | typedef struct __ns_rr { |
michael@0 | 145 | char name[NS_MAXDNAME]; |
michael@0 | 146 | uint16_t type; |
michael@0 | 147 | uint16_t rr_class; |
michael@0 | 148 | uint32_t ttl; |
michael@0 | 149 | uint16_t rdlength; |
michael@0 | 150 | const u_char * rdata; |
michael@0 | 151 | } ns_rr; |
michael@0 | 152 | |
michael@0 | 153 | /* Accessor macros - this is part of the public interface. */ |
michael@0 | 154 | #define ns_rr_name(rr) (((rr).name[0] != '\0') ? (rr).name : ".") |
michael@0 | 155 | #define ns_rr_type(rr) ((ns_type)((rr).type + 0)) |
michael@0 | 156 | #define ns_rr_class(rr) ((ns_class)((rr).rr_class + 0)) |
michael@0 | 157 | #define ns_rr_ttl(rr) ((u_long)(rr).ttl + 0) |
michael@0 | 158 | #define ns_rr_rdlen(rr) ((size_t)(rr).rdlength + 0) |
michael@0 | 159 | #define ns_rr_rdata(rr) ((rr).rdata + 0) |
michael@0 | 160 | |
michael@0 | 161 | /* |
michael@0 | 162 | * These don't have to be in the same order as in the packet flags word, |
michael@0 | 163 | * and they can even overlap in some cases, but they will need to be kept |
michael@0 | 164 | * in synch with ns_parse.c:ns_flagdata[]. |
michael@0 | 165 | */ |
michael@0 | 166 | typedef enum __ns_flag { |
michael@0 | 167 | ns_f_qr, /* Question/Response. */ |
michael@0 | 168 | ns_f_opcode, /* Operation code. */ |
michael@0 | 169 | ns_f_aa, /* Authoritative Answer. */ |
michael@0 | 170 | ns_f_tc, /* Truncation occurred. */ |
michael@0 | 171 | ns_f_rd, /* Recursion Desired. */ |
michael@0 | 172 | ns_f_ra, /* Recursion Available. */ |
michael@0 | 173 | ns_f_z, /* MBZ. */ |
michael@0 | 174 | ns_f_ad, /* Authentic Data (DNSSEC). */ |
michael@0 | 175 | ns_f_cd, /* Checking Disabled (DNSSEC). */ |
michael@0 | 176 | ns_f_rcode, /* Response code. */ |
michael@0 | 177 | ns_f_max |
michael@0 | 178 | } ns_flag; |
michael@0 | 179 | |
michael@0 | 180 | /* |
michael@0 | 181 | * Currently defined opcodes. |
michael@0 | 182 | */ |
michael@0 | 183 | typedef enum __ns_opcode { |
michael@0 | 184 | ns_o_query = 0, /* Standard query. */ |
michael@0 | 185 | ns_o_iquery = 1, /* Inverse query (deprecated/unsupported). */ |
michael@0 | 186 | ns_o_status = 2, /* Name server status query (unsupported). */ |
michael@0 | 187 | /* Opcode 3 is undefined/reserved. */ |
michael@0 | 188 | ns_o_notify = 4, /* Zone change notification. */ |
michael@0 | 189 | ns_o_update = 5, /* Zone update message. */ |
michael@0 | 190 | ns_o_max = 6 |
michael@0 | 191 | } ns_opcode; |
michael@0 | 192 | |
michael@0 | 193 | /* |
michael@0 | 194 | * Currently defined response codes. |
michael@0 | 195 | */ |
michael@0 | 196 | typedef enum __ns_rcode { |
michael@0 | 197 | ns_r_noerror = 0, /* No error occurred. */ |
michael@0 | 198 | ns_r_formerr = 1, /* Format error. */ |
michael@0 | 199 | ns_r_servfail = 2, /* Server failure. */ |
michael@0 | 200 | ns_r_nxdomain = 3, /* Name error. */ |
michael@0 | 201 | ns_r_notimpl = 4, /* Unimplemented. */ |
michael@0 | 202 | ns_r_refused = 5, /* Operation refused. */ |
michael@0 | 203 | /* these are for BIND_UPDATE */ |
michael@0 | 204 | ns_r_yxdomain = 6, /* Name exists */ |
michael@0 | 205 | ns_r_yxrrset = 7, /* RRset exists */ |
michael@0 | 206 | ns_r_nxrrset = 8, /* RRset does not exist */ |
michael@0 | 207 | ns_r_notauth = 9, /* Not authoritative for zone */ |
michael@0 | 208 | ns_r_notzone = 10, /* Zone of record different from zone section */ |
michael@0 | 209 | ns_r_max = 11, |
michael@0 | 210 | /* The following are EDNS extended rcodes */ |
michael@0 | 211 | ns_r_badvers = 16, |
michael@0 | 212 | /* The following are TSIG errors */ |
michael@0 | 213 | ns_r_badsig = 16, |
michael@0 | 214 | ns_r_badkey = 17, |
michael@0 | 215 | ns_r_badtime = 18 |
michael@0 | 216 | } ns_rcode; |
michael@0 | 217 | |
michael@0 | 218 | /* BIND_UPDATE */ |
michael@0 | 219 | typedef enum __ns_update_operation { |
michael@0 | 220 | ns_uop_delete = 0, |
michael@0 | 221 | ns_uop_add = 1, |
michael@0 | 222 | ns_uop_max = 2 |
michael@0 | 223 | } ns_update_operation; |
michael@0 | 224 | |
michael@0 | 225 | /* |
michael@0 | 226 | * This structure is used for TSIG authenticated messages |
michael@0 | 227 | */ |
michael@0 | 228 | struct ns_tsig_key { |
michael@0 | 229 | char name[NS_MAXDNAME], alg[NS_MAXDNAME]; |
michael@0 | 230 | unsigned char *data; |
michael@0 | 231 | int len; |
michael@0 | 232 | }; |
michael@0 | 233 | typedef struct ns_tsig_key ns_tsig_key; |
michael@0 | 234 | |
michael@0 | 235 | /* |
michael@0 | 236 | * This structure is used for TSIG authenticated TCP messages |
michael@0 | 237 | */ |
michael@0 | 238 | struct ns_tcp_tsig_state { |
michael@0 | 239 | int counter; |
michael@0 | 240 | struct dst_key *key; |
michael@0 | 241 | void *ctx; |
michael@0 | 242 | unsigned char sig[NS_PACKETSZ]; |
michael@0 | 243 | int siglen; |
michael@0 | 244 | }; |
michael@0 | 245 | typedef struct ns_tcp_tsig_state ns_tcp_tsig_state; |
michael@0 | 246 | |
michael@0 | 247 | #define NS_TSIG_FUDGE 300 |
michael@0 | 248 | #define NS_TSIG_TCP_COUNT 100 |
michael@0 | 249 | #define NS_TSIG_ALG_HMAC_MD5 "HMAC-MD5.SIG-ALG.REG.INT" |
michael@0 | 250 | |
michael@0 | 251 | #define NS_TSIG_ERROR_NO_TSIG -10 |
michael@0 | 252 | #define NS_TSIG_ERROR_NO_SPACE -11 |
michael@0 | 253 | #define NS_TSIG_ERROR_FORMERR -12 |
michael@0 | 254 | |
michael@0 | 255 | /* |
michael@0 | 256 | * Currently defined type values for resources and queries. |
michael@0 | 257 | */ |
michael@0 | 258 | typedef enum __ns_type { |
michael@0 | 259 | ns_t_invalid = 0, /* Cookie. */ |
michael@0 | 260 | ns_t_a = 1, /* Host address. */ |
michael@0 | 261 | ns_t_ns = 2, /* Authoritative server. */ |
michael@0 | 262 | ns_t_md = 3, /* Mail destination. */ |
michael@0 | 263 | ns_t_mf = 4, /* Mail forwarder. */ |
michael@0 | 264 | ns_t_cname = 5, /* Canonical name. */ |
michael@0 | 265 | ns_t_soa = 6, /* Start of authority zone. */ |
michael@0 | 266 | ns_t_mb = 7, /* Mailbox domain name. */ |
michael@0 | 267 | ns_t_mg = 8, /* Mail group member. */ |
michael@0 | 268 | ns_t_mr = 9, /* Mail rename name. */ |
michael@0 | 269 | ns_t_null = 10, /* Null resource record. */ |
michael@0 | 270 | ns_t_wks = 11, /* Well known service. */ |
michael@0 | 271 | ns_t_ptr = 12, /* Domain name pointer. */ |
michael@0 | 272 | ns_t_hinfo = 13, /* Host information. */ |
michael@0 | 273 | ns_t_minfo = 14, /* Mailbox information. */ |
michael@0 | 274 | ns_t_mx = 15, /* Mail routing information. */ |
michael@0 | 275 | ns_t_txt = 16, /* Text strings. */ |
michael@0 | 276 | ns_t_rp = 17, /* Responsible person. */ |
michael@0 | 277 | ns_t_afsdb = 18, /* AFS cell database. */ |
michael@0 | 278 | ns_t_x25 = 19, /* X_25 calling address. */ |
michael@0 | 279 | ns_t_isdn = 20, /* ISDN calling address. */ |
michael@0 | 280 | ns_t_rt = 21, /* Router. */ |
michael@0 | 281 | ns_t_nsap = 22, /* NSAP address. */ |
michael@0 | 282 | ns_t_nsap_ptr = 23, /* Reverse NSAP lookup (deprecated). */ |
michael@0 | 283 | ns_t_sig = 24, /* Security signature. */ |
michael@0 | 284 | ns_t_key = 25, /* Security key. */ |
michael@0 | 285 | ns_t_px = 26, /* X.400 mail mapping. */ |
michael@0 | 286 | ns_t_gpos = 27, /* Geographical position (withdrawn). */ |
michael@0 | 287 | ns_t_aaaa = 28, /* Ip6 Address. */ |
michael@0 | 288 | ns_t_loc = 29, /* Location Information. */ |
michael@0 | 289 | ns_t_nxt = 30, /* Next domain (security). */ |
michael@0 | 290 | ns_t_eid = 31, /* Endpoint identifier. */ |
michael@0 | 291 | ns_t_nimloc = 32, /* Nimrod Locator. */ |
michael@0 | 292 | ns_t_srv = 33, /* Server Selection. */ |
michael@0 | 293 | ns_t_atma = 34, /* ATM Address */ |
michael@0 | 294 | ns_t_naptr = 35, /* Naming Authority PoinTeR */ |
michael@0 | 295 | ns_t_kx = 36, /* Key Exchange */ |
michael@0 | 296 | ns_t_cert = 37, /* Certification record */ |
michael@0 | 297 | ns_t_a6 = 38, /* IPv6 address (deprecates AAAA) */ |
michael@0 | 298 | ns_t_dname = 39, /* Non-terminal DNAME (for IPv6) */ |
michael@0 | 299 | ns_t_sink = 40, /* Kitchen sink (experimentatl) */ |
michael@0 | 300 | ns_t_opt = 41, /* EDNS0 option (meta-RR) */ |
michael@0 | 301 | ns_t_apl = 42, /* Address prefix list (RFC 3123) */ |
michael@0 | 302 | ns_t_tkey = 249, /* Transaction key */ |
michael@0 | 303 | ns_t_tsig = 250, /* Transaction signature. */ |
michael@0 | 304 | ns_t_ixfr = 251, /* Incremental zone transfer. */ |
michael@0 | 305 | ns_t_axfr = 252, /* Transfer zone of authority. */ |
michael@0 | 306 | ns_t_mailb = 253, /* Transfer mailbox records. */ |
michael@0 | 307 | ns_t_maila = 254, /* Transfer mail agent records. */ |
michael@0 | 308 | ns_t_any = 255, /* Wildcard match. */ |
michael@0 | 309 | ns_t_zxfr = 256, /* BIND-specific, nonstandard. */ |
michael@0 | 310 | ns_t_max = 65536 |
michael@0 | 311 | } ns_type; |
michael@0 | 312 | |
michael@0 | 313 | /* Exclusively a QTYPE? (not also an RTYPE) */ |
michael@0 | 314 | #define ns_t_qt_p(t) (ns_t_xfr_p(t) || (t) == ns_t_any || \ |
michael@0 | 315 | (t) == ns_t_mailb || (t) == ns_t_maila) |
michael@0 | 316 | /* Some kind of meta-RR? (not a QTYPE, but also not an RTYPE) */ |
michael@0 | 317 | #define ns_t_mrr_p(t) ((t) == ns_t_tsig || (t) == ns_t_opt) |
michael@0 | 318 | /* Exclusively an RTYPE? (not also a QTYPE or a meta-RR) */ |
michael@0 | 319 | #define ns_t_rr_p(t) (!ns_t_qt_p(t) && !ns_t_mrr_p(t)) |
michael@0 | 320 | #define ns_t_udp_p(t) ((t) != ns_t_axfr && (t) != ns_t_zxfr) |
michael@0 | 321 | #define ns_t_xfr_p(t) ((t) == ns_t_axfr || (t) == ns_t_ixfr || \ |
michael@0 | 322 | (t) == ns_t_zxfr) |
michael@0 | 323 | |
michael@0 | 324 | /* |
michael@0 | 325 | * Values for class field |
michael@0 | 326 | */ |
michael@0 | 327 | typedef enum __ns_class { |
michael@0 | 328 | ns_c_invalid = 0, /* Cookie. */ |
michael@0 | 329 | ns_c_in = 1, /* Internet. */ |
michael@0 | 330 | ns_c_2 = 2, /* unallocated/unsupported. */ |
michael@0 | 331 | ns_c_chaos = 3, /* MIT Chaos-net. */ |
michael@0 | 332 | ns_c_hs = 4, /* MIT Hesiod. */ |
michael@0 | 333 | /* Query class values which do not appear in resource records */ |
michael@0 | 334 | ns_c_none = 254, /* for prereq. sections in update requests */ |
michael@0 | 335 | ns_c_any = 255, /* Wildcard match. */ |
michael@0 | 336 | ns_c_max = 65536 |
michael@0 | 337 | } ns_class; |
michael@0 | 338 | |
michael@0 | 339 | /* DNSSEC constants. */ |
michael@0 | 340 | |
michael@0 | 341 | typedef enum __ns_key_types { |
michael@0 | 342 | ns_kt_rsa = 1, /* key type RSA/MD5 */ |
michael@0 | 343 | ns_kt_dh = 2, /* Diffie Hellman */ |
michael@0 | 344 | ns_kt_dsa = 3, /* Digital Signature Standard (MANDATORY) */ |
michael@0 | 345 | ns_kt_private = 254 /* Private key type starts with OID */ |
michael@0 | 346 | } ns_key_types; |
michael@0 | 347 | |
michael@0 | 348 | typedef enum __ns_cert_types { |
michael@0 | 349 | cert_t_pkix = 1, /* PKIX (X.509v3) */ |
michael@0 | 350 | cert_t_spki = 2, /* SPKI */ |
michael@0 | 351 | cert_t_pgp = 3, /* PGP */ |
michael@0 | 352 | cert_t_url = 253, /* URL private type */ |
michael@0 | 353 | cert_t_oid = 254 /* OID private type */ |
michael@0 | 354 | } ns_cert_types; |
michael@0 | 355 | |
michael@0 | 356 | /* Flags field of the KEY RR rdata. */ |
michael@0 | 357 | #define NS_KEY_TYPEMASK 0xC000 /* Mask for "type" bits */ |
michael@0 | 358 | #define NS_KEY_TYPE_AUTH_CONF 0x0000 /* Key usable for both */ |
michael@0 | 359 | #define NS_KEY_TYPE_CONF_ONLY 0x8000 /* Key usable for confidentiality */ |
michael@0 | 360 | #define NS_KEY_TYPE_AUTH_ONLY 0x4000 /* Key usable for authentication */ |
michael@0 | 361 | #define NS_KEY_TYPE_NO_KEY 0xC000 /* No key usable for either; no key */ |
michael@0 | 362 | /* The type bits can also be interpreted independently, as single bits: */ |
michael@0 | 363 | #define NS_KEY_NO_AUTH 0x8000 /* Key unusable for authentication */ |
michael@0 | 364 | #define NS_KEY_NO_CONF 0x4000 /* Key unusable for confidentiality */ |
michael@0 | 365 | #define NS_KEY_RESERVED2 0x2000 /* Security is *mandatory* if bit=0 */ |
michael@0 | 366 | #define NS_KEY_EXTENDED_FLAGS 0x1000 /* reserved - must be zero */ |
michael@0 | 367 | #define NS_KEY_RESERVED4 0x0800 /* reserved - must be zero */ |
michael@0 | 368 | #define NS_KEY_RESERVED5 0x0400 /* reserved - must be zero */ |
michael@0 | 369 | #define NS_KEY_NAME_TYPE 0x0300 /* these bits determine the type */ |
michael@0 | 370 | #define NS_KEY_NAME_USER 0x0000 /* key is assoc. with user */ |
michael@0 | 371 | #define NS_KEY_NAME_ENTITY 0x0200 /* key is assoc. with entity eg host */ |
michael@0 | 372 | #define NS_KEY_NAME_ZONE 0x0100 /* key is zone key */ |
michael@0 | 373 | #define NS_KEY_NAME_RESERVED 0x0300 /* reserved meaning */ |
michael@0 | 374 | #define NS_KEY_RESERVED8 0x0080 /* reserved - must be zero */ |
michael@0 | 375 | #define NS_KEY_RESERVED9 0x0040 /* reserved - must be zero */ |
michael@0 | 376 | #define NS_KEY_RESERVED10 0x0020 /* reserved - must be zero */ |
michael@0 | 377 | #define NS_KEY_RESERVED11 0x0010 /* reserved - must be zero */ |
michael@0 | 378 | #define NS_KEY_SIGNATORYMASK 0x000F /* key can sign RR's of same name */ |
michael@0 | 379 | #define NS_KEY_RESERVED_BITMASK ( NS_KEY_RESERVED2 | \ |
michael@0 | 380 | NS_KEY_RESERVED4 | \ |
michael@0 | 381 | NS_KEY_RESERVED5 | \ |
michael@0 | 382 | NS_KEY_RESERVED8 | \ |
michael@0 | 383 | NS_KEY_RESERVED9 | \ |
michael@0 | 384 | NS_KEY_RESERVED10 | \ |
michael@0 | 385 | NS_KEY_RESERVED11 ) |
michael@0 | 386 | #define NS_KEY_RESERVED_BITMASK2 0xFFFF /* no bits defined here */ |
michael@0 | 387 | |
michael@0 | 388 | /* The Algorithm field of the KEY and SIG RR's is an integer, {1..254} */ |
michael@0 | 389 | #define NS_ALG_MD5RSA 1 /* MD5 with RSA */ |
michael@0 | 390 | #define NS_ALG_DH 2 /* Diffie Hellman KEY */ |
michael@0 | 391 | #define NS_ALG_DSA 3 /* DSA KEY */ |
michael@0 | 392 | #define NS_ALG_DSS NS_ALG_DSA |
michael@0 | 393 | #define NS_ALG_EXPIRE_ONLY 253 /* No alg, no security */ |
michael@0 | 394 | #define NS_ALG_PRIVATE_OID 254 /* Key begins with OID giving alg */ |
michael@0 | 395 | |
michael@0 | 396 | /* Protocol values */ |
michael@0 | 397 | /* value 0 is reserved */ |
michael@0 | 398 | #define NS_KEY_PROT_TLS 1 |
michael@0 | 399 | #define NS_KEY_PROT_EMAIL 2 |
michael@0 | 400 | #define NS_KEY_PROT_DNSSEC 3 |
michael@0 | 401 | #define NS_KEY_PROT_IPSEC 4 |
michael@0 | 402 | #define NS_KEY_PROT_ANY 255 |
michael@0 | 403 | |
michael@0 | 404 | /* Signatures */ |
michael@0 | 405 | #define NS_MD5RSA_MIN_BITS 512 /* Size of a mod or exp in bits */ |
michael@0 | 406 | #define NS_MD5RSA_MAX_BITS 4096 |
michael@0 | 407 | /* Total of binary mod and exp */ |
michael@0 | 408 | #define NS_MD5RSA_MAX_BYTES ((NS_MD5RSA_MAX_BITS+7/8)*2+3) |
michael@0 | 409 | /* Max length of text sig block */ |
michael@0 | 410 | #define NS_MD5RSA_MAX_BASE64 (((NS_MD5RSA_MAX_BYTES+2)/3)*4) |
michael@0 | 411 | #define NS_MD5RSA_MIN_SIZE ((NS_MD5RSA_MIN_BITS+7)/8) |
michael@0 | 412 | #define NS_MD5RSA_MAX_SIZE ((NS_MD5RSA_MAX_BITS+7)/8) |
michael@0 | 413 | |
michael@0 | 414 | #define NS_DSA_SIG_SIZE 41 |
michael@0 | 415 | #define NS_DSA_MIN_SIZE 213 |
michael@0 | 416 | #define NS_DSA_MAX_BYTES 405 |
michael@0 | 417 | |
michael@0 | 418 | /* Offsets into SIG record rdata to find various values */ |
michael@0 | 419 | #define NS_SIG_TYPE 0 /* Type flags */ |
michael@0 | 420 | #define NS_SIG_ALG 2 /* Algorithm */ |
michael@0 | 421 | #define NS_SIG_LABELS 3 /* How many labels in name */ |
michael@0 | 422 | #define NS_SIG_OTTL 4 /* Original TTL */ |
michael@0 | 423 | #define NS_SIG_EXPIR 8 /* Expiration time */ |
michael@0 | 424 | #define NS_SIG_SIGNED 12 /* Signature time */ |
michael@0 | 425 | #define NS_SIG_FOOT 16 /* Key footprint */ |
michael@0 | 426 | #define NS_SIG_SIGNER 18 /* Domain name of who signed it */ |
michael@0 | 427 | |
michael@0 | 428 | /* How RR types are represented as bit-flags in NXT records */ |
michael@0 | 429 | #define NS_NXT_BITS 8 |
michael@0 | 430 | #define NS_NXT_BIT_SET( n,p) (p[(n)/NS_NXT_BITS] |= (0x80>>((n)%NS_NXT_BITS))) |
michael@0 | 431 | #define NS_NXT_BIT_CLEAR(n,p) (p[(n)/NS_NXT_BITS] &= ~(0x80>>((n)%NS_NXT_BITS))) |
michael@0 | 432 | #define NS_NXT_BIT_ISSET(n,p) (p[(n)/NS_NXT_BITS] & (0x80>>((n)%NS_NXT_BITS))) |
michael@0 | 433 | #define NS_NXT_MAX 127 |
michael@0 | 434 | |
michael@0 | 435 | /* |
michael@0 | 436 | * EDNS0 extended flags, host order. |
michael@0 | 437 | */ |
michael@0 | 438 | #define NS_OPT_DNSSEC_OK 0x8000U |
michael@0 | 439 | |
michael@0 | 440 | /* |
michael@0 | 441 | * Inline versions of get/put short/long. Pointer is advanced. |
michael@0 | 442 | */ |
michael@0 | 443 | #define NS_GET16(s, cp) do { \ |
michael@0 | 444 | const u_char *t_cp = (const u_char *)(cp); \ |
michael@0 | 445 | (s) = ((uint16_t)t_cp[0] << 8) \ |
michael@0 | 446 | | ((uint16_t)t_cp[1]) \ |
michael@0 | 447 | ; \ |
michael@0 | 448 | (cp) += NS_INT16SZ; \ |
michael@0 | 449 | } while (/*CONSTCOND*/0) |
michael@0 | 450 | |
michael@0 | 451 | #define NS_GET32(l, cp) do { \ |
michael@0 | 452 | const u_char *t_cp = (const u_char *)(cp); \ |
michael@0 | 453 | (l) = ((uint32_t)t_cp[0] << 24) \ |
michael@0 | 454 | | ((uint32_t)t_cp[1] << 16) \ |
michael@0 | 455 | | ((uint32_t)t_cp[2] << 8) \ |
michael@0 | 456 | | ((uint32_t)t_cp[3]) \ |
michael@0 | 457 | ; \ |
michael@0 | 458 | (cp) += NS_INT32SZ; \ |
michael@0 | 459 | } while (/*CONSTCOND*/0) |
michael@0 | 460 | |
michael@0 | 461 | #define NS_PUT16(s, cp) do { \ |
michael@0 | 462 | uint32_t t_s = (uint32_t)(s); \ |
michael@0 | 463 | u_char *t_cp = (u_char *)(cp); \ |
michael@0 | 464 | *t_cp++ = t_s >> 8; \ |
michael@0 | 465 | *t_cp = t_s; \ |
michael@0 | 466 | (cp) += NS_INT16SZ; \ |
michael@0 | 467 | } while (/*CONSTCOND*/0) |
michael@0 | 468 | |
michael@0 | 469 | #define NS_PUT32(l, cp) do { \ |
michael@0 | 470 | uint32_t t_l = (uint32_t)(l); \ |
michael@0 | 471 | u_char *t_cp = (u_char *)(cp); \ |
michael@0 | 472 | *t_cp++ = t_l >> 24; \ |
michael@0 | 473 | *t_cp++ = t_l >> 16; \ |
michael@0 | 474 | *t_cp++ = t_l >> 8; \ |
michael@0 | 475 | *t_cp = t_l; \ |
michael@0 | 476 | (cp) += NS_INT32SZ; \ |
michael@0 | 477 | } while (/*CONSTCOND*/0) |
michael@0 | 478 | |
michael@0 | 479 | /* |
michael@0 | 480 | * ANSI C identifier hiding for bind's lib/nameser. |
michael@0 | 481 | */ |
michael@0 | 482 | #define ns_msg_getflag __ns_msg_getflag |
michael@0 | 483 | #define ns_get16 __ns_get16 |
michael@0 | 484 | #define ns_get32 __ns_get32 |
michael@0 | 485 | #define ns_put16 __ns_put16 |
michael@0 | 486 | #define ns_put32 __ns_put32 |
michael@0 | 487 | #define ns_initparse __ns_initparse |
michael@0 | 488 | #define ns_skiprr __ns_skiprr |
michael@0 | 489 | #define ns_parserr __ns_parserr |
michael@0 | 490 | #define ns_sprintrr __ns_sprintrr |
michael@0 | 491 | #define ns_sprintrrf __ns_sprintrrf |
michael@0 | 492 | #define ns_format_ttl __ns_format_ttl |
michael@0 | 493 | #define ns_parse_ttl __ns_parse_ttl |
michael@0 | 494 | #define ns_datetosecs __ns_datetosecs |
michael@0 | 495 | #define ns_name_ntol __ns_name_ntol |
michael@0 | 496 | #define ns_name_ntop __ns_name_ntop |
michael@0 | 497 | #define ns_name_pton __ns_name_pton |
michael@0 | 498 | #define ns_name_unpack __ns_name_unpack |
michael@0 | 499 | #define ns_name_pack __ns_name_pack |
michael@0 | 500 | #define ns_name_compress __ns_name_compress |
michael@0 | 501 | #define ns_name_uncompress __ns_name_uncompress |
michael@0 | 502 | #define ns_name_skip __ns_name_skip |
michael@0 | 503 | #define ns_name_rollback __ns_name_rollback |
michael@0 | 504 | #define ns_sign __ns_sign |
michael@0 | 505 | #define ns_sign2 __ns_sign2 |
michael@0 | 506 | #define ns_sign_tcp __ns_sign_tcp |
michael@0 | 507 | #define ns_sign_tcp2 __ns_sign_tcp2 |
michael@0 | 508 | #define ns_sign_tcp_init __ns_sign_tcp_init |
michael@0 | 509 | #define ns_find_tsig __ns_find_tsig |
michael@0 | 510 | #define ns_verify __ns_verify |
michael@0 | 511 | #define ns_verify_tcp __ns_verify_tcp |
michael@0 | 512 | #define ns_verify_tcp_init __ns_verify_tcp_init |
michael@0 | 513 | #define ns_samedomain __ns_samedomain |
michael@0 | 514 | #define ns_subdomain __ns_subdomain |
michael@0 | 515 | #define ns_makecanon __ns_makecanon |
michael@0 | 516 | #define ns_samename __ns_samename |
michael@0 | 517 | |
michael@0 | 518 | __BEGIN_DECLS |
michael@0 | 519 | int ns_msg_getflag(ns_msg, int); |
michael@0 | 520 | uint16_t ns_get16(const u_char *); |
michael@0 | 521 | uint32_t ns_get32(const u_char *); |
michael@0 | 522 | void ns_put16(uint16_t, u_char *); |
michael@0 | 523 | void ns_put32(uint32_t, u_char *); |
michael@0 | 524 | int ns_initparse(const u_char *, int, ns_msg *); |
michael@0 | 525 | int ns_skiprr(const u_char *, const u_char *, ns_sect, int); |
michael@0 | 526 | int ns_parserr(ns_msg *, ns_sect, int, ns_rr *); |
michael@0 | 527 | int ns_sprintrr(const ns_msg *, const ns_rr *, |
michael@0 | 528 | const char *, const char *, char *, size_t); |
michael@0 | 529 | int ns_sprintrrf(const u_char *, size_t, const char *, |
michael@0 | 530 | ns_class, ns_type, u_long, const u_char *, |
michael@0 | 531 | size_t, const char *, const char *, |
michael@0 | 532 | char *, size_t); |
michael@0 | 533 | int ns_format_ttl(u_long, char *, size_t); |
michael@0 | 534 | int ns_parse_ttl(const char *, u_long *); |
michael@0 | 535 | uint32_t ns_datetosecs(const char *cp, int *errp); |
michael@0 | 536 | int ns_name_ntol(const u_char *, u_char *, size_t); |
michael@0 | 537 | int ns_name_ntop(const u_char *, char *, size_t); |
michael@0 | 538 | int ns_name_pton(const char *, u_char *, size_t); |
michael@0 | 539 | int ns_name_unpack(const u_char *, const u_char *, |
michael@0 | 540 | const u_char *, u_char *, size_t); |
michael@0 | 541 | int ns_name_pack(const u_char *, u_char *, int, |
michael@0 | 542 | const u_char **, const u_char **); |
michael@0 | 543 | int ns_name_uncompress(const u_char *, const u_char *, |
michael@0 | 544 | const u_char *, char *, size_t); |
michael@0 | 545 | int ns_name_compress(const char *, u_char *, size_t, |
michael@0 | 546 | const u_char **, const u_char **); |
michael@0 | 547 | int ns_name_skip(const u_char **, const u_char *); |
michael@0 | 548 | void ns_name_rollback(const u_char *, const u_char **, |
michael@0 | 549 | const u_char **); |
michael@0 | 550 | int ns_sign(u_char *, int *, int, int, void *, |
michael@0 | 551 | const u_char *, int, u_char *, int *, time_t); |
michael@0 | 552 | int ns_sign2(u_char *, int *, int, int, void *, |
michael@0 | 553 | const u_char *, int, u_char *, int *, time_t, |
michael@0 | 554 | u_char **, u_char **); |
michael@0 | 555 | int ns_sign_tcp(u_char *, int *, int, int, |
michael@0 | 556 | ns_tcp_tsig_state *, int); |
michael@0 | 557 | int ns_sign_tcp2(u_char *, int *, int, int, |
michael@0 | 558 | ns_tcp_tsig_state *, int, |
michael@0 | 559 | u_char **, u_char **); |
michael@0 | 560 | int ns_sign_tcp_init(void *, const u_char *, int, |
michael@0 | 561 | ns_tcp_tsig_state *); |
michael@0 | 562 | u_char *ns_find_tsig(u_char *, u_char *); |
michael@0 | 563 | int ns_verify(u_char *, int *, void *, |
michael@0 | 564 | const u_char *, int, u_char *, int *, |
michael@0 | 565 | time_t *, int); |
michael@0 | 566 | int ns_verify_tcp(u_char *, int *, ns_tcp_tsig_state *, int); |
michael@0 | 567 | int ns_verify_tcp_init(void *, const u_char *, int, |
michael@0 | 568 | ns_tcp_tsig_state *); |
michael@0 | 569 | int ns_samedomain(const char *, const char *); |
michael@0 | 570 | int ns_subdomain(const char *, const char *); |
michael@0 | 571 | int ns_makecanon(const char *, char *, size_t); |
michael@0 | 572 | int ns_samename(const char *, const char *); |
michael@0 | 573 | __END_DECLS |
michael@0 | 574 | |
michael@0 | 575 | #ifdef BIND_4_COMPAT |
michael@0 | 576 | #include "arpa_nameser_compat.h" |
michael@0 | 577 | #endif |
michael@0 | 578 | |
michael@0 | 579 | #if 0 |
michael@0 | 580 | # include <logd.h> |
michael@0 | 581 | # define XLOG(...) \ |
michael@0 | 582 | __libc_android_log_print(ANDROID_LOG_DEBUG,"libc",__VA_ARGS__) |
michael@0 | 583 | #else |
michael@0 | 584 | #define XLOG(...) do {} while (0) |
michael@0 | 585 | #endif |
michael@0 | 586 | |
michael@0 | 587 | #endif /* !_ARPA_NAMESER_H_ */ |