Shuyi Chen | d7955ce | 2013-05-22 14:51:55 -0700 | [diff] [blame] | 1 | // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org) |
| 2 | |
| 3 | package org.xbill.DNS; |
| 4 | |
| 5 | import java.util.HashMap; |
| 6 | |
| 7 | /** |
| 8 | * Constants and functions relating to DNS Types |
| 9 | * |
| 10 | * @author Brian Wellington |
| 11 | */ |
| 12 | |
| 13 | public final class Type { |
| 14 | |
| 15 | /** Address */ |
| 16 | public static final int A = 1; |
| 17 | |
| 18 | /** Name server */ |
| 19 | public static final int NS = 2; |
| 20 | |
| 21 | /** Mail destination */ |
| 22 | public static final int MD = 3; |
| 23 | |
| 24 | /** Mail forwarder */ |
| 25 | public static final int MF = 4; |
| 26 | |
| 27 | /** Canonical name (alias) */ |
| 28 | public static final int CNAME = 5; |
| 29 | |
| 30 | /** Start of authority */ |
| 31 | public static final int SOA = 6; |
| 32 | |
| 33 | /** Mailbox domain name */ |
| 34 | public static final int MB = 7; |
| 35 | |
| 36 | /** Mail group member */ |
| 37 | public static final int MG = 8; |
| 38 | |
| 39 | /** Mail rename name */ |
| 40 | public static final int MR = 9; |
| 41 | |
| 42 | /** Null record */ |
| 43 | public static final int NULL = 10; |
| 44 | |
| 45 | /** Well known services */ |
| 46 | public static final int WKS = 11; |
| 47 | |
| 48 | /** Domain name pointer */ |
| 49 | public static final int PTR = 12; |
| 50 | |
| 51 | /** Host information */ |
| 52 | public static final int HINFO = 13; |
| 53 | |
| 54 | /** Mailbox information */ |
| 55 | public static final int MINFO = 14; |
| 56 | |
| 57 | /** Mail routing information */ |
| 58 | public static final int MX = 15; |
| 59 | |
| 60 | /** Text strings */ |
| 61 | public static final int TXT = 16; |
| 62 | |
| 63 | /** Responsible person */ |
| 64 | public static final int RP = 17; |
| 65 | |
| 66 | /** AFS cell database */ |
| 67 | public static final int AFSDB = 18; |
| 68 | |
| 69 | /** X.25 calling address */ |
| 70 | public static final int X25 = 19; |
| 71 | |
| 72 | /** ISDN calling address */ |
| 73 | public static final int ISDN = 20; |
| 74 | |
| 75 | /** Router */ |
| 76 | public static final int RT = 21; |
| 77 | |
| 78 | /** NSAP address */ |
| 79 | public static final int NSAP = 22; |
| 80 | |
| 81 | /** Reverse NSAP address (deprecated) */ |
| 82 | public static final int NSAP_PTR = 23; |
| 83 | |
| 84 | /** Signature */ |
| 85 | public static final int SIG = 24; |
| 86 | |
| 87 | /** Key */ |
| 88 | public static final int KEY = 25; |
| 89 | |
| 90 | /** X.400 mail mapping */ |
| 91 | public static final int PX = 26; |
| 92 | |
| 93 | /** Geographical position (withdrawn) */ |
| 94 | public static final int GPOS = 27; |
| 95 | |
| 96 | /** IPv6 address */ |
| 97 | public static final int AAAA = 28; |
| 98 | |
| 99 | /** Location */ |
| 100 | public static final int LOC = 29; |
| 101 | |
| 102 | /** Next valid name in zone */ |
| 103 | public static final int NXT = 30; |
| 104 | |
| 105 | /** Endpoint identifier */ |
| 106 | public static final int EID = 31; |
| 107 | |
| 108 | /** Nimrod locator */ |
| 109 | public static final int NIMLOC = 32; |
| 110 | |
| 111 | /** Server selection */ |
| 112 | public static final int SRV = 33; |
| 113 | |
| 114 | /** ATM address */ |
| 115 | public static final int ATMA = 34; |
| 116 | |
| 117 | /** Naming authority pointer */ |
| 118 | public static final int NAPTR = 35; |
| 119 | |
| 120 | /** Key exchange */ |
| 121 | public static final int KX = 36; |
| 122 | |
| 123 | /** Certificate */ |
| 124 | public static final int CERT = 37; |
| 125 | |
| 126 | /** IPv6 address (experimental) */ |
| 127 | public static final int A6 = 38; |
| 128 | |
| 129 | /** Non-terminal name redirection */ |
| 130 | public static final int DNAME = 39; |
| 131 | |
| 132 | /** Options - contains EDNS metadata */ |
| 133 | public static final int OPT = 41; |
| 134 | |
| 135 | /** Address Prefix List */ |
| 136 | public static final int APL = 42; |
| 137 | |
| 138 | /** Delegation Signer */ |
| 139 | public static final int DS = 43; |
| 140 | |
| 141 | /** SSH Key Fingerprint */ |
| 142 | public static final int SSHFP = 44; |
| 143 | |
| 144 | /** IPSEC key */ |
| 145 | public static final int IPSECKEY = 45; |
| 146 | |
| 147 | /** Resource Record Signature */ |
| 148 | public static final int RRSIG = 46; |
| 149 | |
| 150 | /** Next Secure Name */ |
| 151 | public static final int NSEC = 47; |
| 152 | |
| 153 | /** DNSSEC Key */ |
| 154 | public static final int DNSKEY = 48; |
| 155 | |
| 156 | /** Dynamic Host Configuration Protocol (DHCP) ID */ |
| 157 | public static final int DHCID = 49; |
| 158 | |
| 159 | /** Next SECure, 3rd edition, RFC 5155 */ |
| 160 | public static final int NSEC3 = 50; |
| 161 | |
| 162 | /** Next SECure PARAMeter, RFC 5155 */ |
| 163 | public static final int NSEC3PARAM = 51; |
| 164 | |
| 165 | /** Transport Layer Security Authentication, draft-ietf-dane-protocol-23 */ |
| 166 | public static final int TLSA = 52; |
| 167 | |
| 168 | /** Sender Policy Framework (experimental) */ |
| 169 | public static final int SPF = 99; |
| 170 | |
| 171 | /** Transaction key - used to compute a shared secret or exchange a key */ |
| 172 | public static final int TKEY = 249; |
| 173 | |
| 174 | /** Transaction signature */ |
| 175 | public static final int TSIG = 250; |
| 176 | |
| 177 | /** Incremental zone transfer */ |
| 178 | public static final int IXFR = 251; |
| 179 | |
| 180 | /** Zone transfer */ |
| 181 | public static final int AXFR = 252; |
| 182 | |
| 183 | /** Transfer mailbox records */ |
| 184 | public static final int MAILB = 253; |
| 185 | |
| 186 | /** Transfer mail agent records */ |
| 187 | public static final int MAILA = 254; |
| 188 | |
| 189 | /** Matches any type */ |
| 190 | public static final int ANY = 255; |
| 191 | |
| 192 | /** DNSSEC Lookaside Validation, RFC 4431 . */ |
| 193 | public static final int DLV = 32769; |
| 194 | |
| 195 | |
| 196 | private static class TypeMnemonic extends Mnemonic { |
| 197 | private HashMap objects; |
| 198 | |
| 199 | public |
| 200 | TypeMnemonic() { |
| 201 | super("Type", CASE_UPPER); |
| 202 | setPrefix("TYPE"); |
| 203 | objects = new HashMap(); |
| 204 | } |
| 205 | |
| 206 | public void |
| 207 | add(int val, String str, Record proto) { |
| 208 | super.add(val, str); |
| 209 | objects.put(Mnemonic.toInteger(val), proto); |
| 210 | } |
| 211 | |
| 212 | public void |
| 213 | check(int val) { |
| 214 | Type.check(val); |
| 215 | } |
| 216 | |
| 217 | public Record |
| 218 | getProto(int val) { |
| 219 | check(val); |
| 220 | return (Record) objects.get(toInteger(val)); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | private static TypeMnemonic types = new TypeMnemonic(); |
| 225 | |
| 226 | static { |
| 227 | types.add(A, "A", new ARecord()); |
| 228 | types.add(NS, "NS", new NSRecord()); |
| 229 | types.add(MD, "MD", new MDRecord()); |
| 230 | types.add(MF, "MF", new MFRecord()); |
| 231 | types.add(CNAME, "CNAME", new CNAMERecord()); |
| 232 | types.add(SOA, "SOA", new SOARecord()); |
| 233 | types.add(MB, "MB", new MBRecord()); |
| 234 | types.add(MG, "MG", new MGRecord()); |
| 235 | types.add(MR, "MR", new MRRecord()); |
| 236 | types.add(NULL, "NULL", new NULLRecord()); |
| 237 | types.add(WKS, "WKS", new WKSRecord()); |
| 238 | types.add(PTR, "PTR", new PTRRecord()); |
| 239 | types.add(HINFO, "HINFO", new HINFORecord()); |
| 240 | types.add(MINFO, "MINFO", new MINFORecord()); |
| 241 | types.add(MX, "MX", new MXRecord()); |
| 242 | types.add(TXT, "TXT", new TXTRecord()); |
| 243 | types.add(RP, "RP", new RPRecord()); |
| 244 | types.add(AFSDB, "AFSDB", new AFSDBRecord()); |
| 245 | types.add(X25, "X25", new X25Record()); |
| 246 | types.add(ISDN, "ISDN", new ISDNRecord()); |
| 247 | types.add(RT, "RT", new RTRecord()); |
| 248 | types.add(NSAP, "NSAP", new NSAPRecord()); |
| 249 | types.add(NSAP_PTR, "NSAP-PTR", new NSAP_PTRRecord()); |
| 250 | types.add(SIG, "SIG", new SIGRecord()); |
| 251 | types.add(KEY, "KEY", new KEYRecord()); |
| 252 | types.add(PX, "PX", new PXRecord()); |
| 253 | types.add(GPOS, "GPOS", new GPOSRecord()); |
| 254 | types.add(AAAA, "AAAA", new AAAARecord()); |
| 255 | types.add(LOC, "LOC", new LOCRecord()); |
| 256 | types.add(NXT, "NXT", new NXTRecord()); |
| 257 | types.add(EID, "EID"); |
| 258 | types.add(NIMLOC, "NIMLOC"); |
| 259 | types.add(SRV, "SRV", new SRVRecord()); |
| 260 | types.add(ATMA, "ATMA"); |
| 261 | types.add(NAPTR, "NAPTR", new NAPTRRecord()); |
| 262 | types.add(KX, "KX", new KXRecord()); |
| 263 | types.add(CERT, "CERT", new CERTRecord()); |
| 264 | types.add(A6, "A6", new A6Record()); |
| 265 | types.add(DNAME, "DNAME", new DNAMERecord()); |
| 266 | types.add(OPT, "OPT", new OPTRecord()); |
| 267 | types.add(APL, "APL", new APLRecord()); |
| 268 | types.add(DS, "DS", new DSRecord()); |
| 269 | types.add(SSHFP, "SSHFP", new SSHFPRecord()); |
| 270 | types.add(IPSECKEY, "IPSECKEY", new IPSECKEYRecord()); |
| 271 | types.add(RRSIG, "RRSIG", new RRSIGRecord()); |
| 272 | types.add(NSEC, "NSEC", new NSECRecord()); |
| 273 | types.add(DNSKEY, "DNSKEY", new DNSKEYRecord()); |
| 274 | types.add(DHCID, "DHCID", new DHCIDRecord()); |
| 275 | types.add(NSEC3, "NSEC3", new NSEC3Record()); |
| 276 | types.add(NSEC3PARAM, "NSEC3PARAM", new NSEC3PARAMRecord()); |
| 277 | types.add(TLSA, "TLSA", new TLSARecord()); |
| 278 | types.add(SPF, "SPF", new SPFRecord()); |
| 279 | types.add(TKEY, "TKEY", new TKEYRecord()); |
| 280 | types.add(TSIG, "TSIG", new TSIGRecord()); |
| 281 | types.add(IXFR, "IXFR"); |
| 282 | types.add(AXFR, "AXFR"); |
| 283 | types.add(MAILB, "MAILB"); |
| 284 | types.add(MAILA, "MAILA"); |
| 285 | types.add(ANY, "ANY"); |
| 286 | types.add(DLV, "DLV", new DLVRecord()); |
| 287 | } |
| 288 | |
| 289 | private |
| 290 | Type() { |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * Checks that a numeric Type is valid. |
| 295 | * @throws InvalidTypeException The type is out of range. |
| 296 | */ |
| 297 | public static void |
| 298 | check(int val) { |
| 299 | if (val < 0 || val > 0xFFFF) |
| 300 | throw new InvalidTypeException(val); |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * Converts a numeric Type into a String |
| 305 | * @param val The type value. |
| 306 | * @return The canonical string representation of the type |
| 307 | * @throws InvalidTypeException The type is out of range. |
| 308 | */ |
| 309 | public static String |
| 310 | string(int val) { |
| 311 | return types.getText(val); |
| 312 | } |
| 313 | |
| 314 | /** |
| 315 | * Converts a String representation of an Type into its numeric value. |
| 316 | * @param s The string representation of the type |
| 317 | * @param numberok Whether a number will be accepted or not. |
| 318 | * @return The type code, or -1 on error. |
| 319 | */ |
| 320 | public static int |
| 321 | value(String s, boolean numberok) { |
| 322 | int val = types.getValue(s); |
| 323 | if (val == -1 && numberok) { |
| 324 | val = types.getValue("TYPE" + s); |
| 325 | } |
| 326 | return val; |
| 327 | } |
| 328 | |
| 329 | /** |
| 330 | * Converts a String representation of an Type into its numeric value |
| 331 | * @return The type code, or -1 on error. |
| 332 | */ |
| 333 | public static int |
| 334 | value(String s) { |
| 335 | return value(s, false); |
| 336 | } |
| 337 | |
| 338 | static Record |
| 339 | getProto(int val) { |
| 340 | return types.getProto(val); |
| 341 | } |
| 342 | |
| 343 | /** Is this type valid for a record (a non-meta type)? */ |
| 344 | public static boolean |
| 345 | isRR(int type) { |
| 346 | switch (type) { |
| 347 | case OPT: |
| 348 | case TKEY: |
| 349 | case TSIG: |
| 350 | case IXFR: |
| 351 | case AXFR: |
| 352 | case MAILB: |
| 353 | case MAILA: |
| 354 | case ANY: |
| 355 | return false; |
| 356 | default: |
| 357 | return true; |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | } |