Home | History | Annotate | Download | only in DNS
      1 // Copyright (c) 1999-2004 Brian Wellington (bwelling (at) xbill.org)
      2 
      3 package org.xbill.DNS;
      4 
      5 /**
      6  * Constants and functions relating to DNS rcodes (error values)
      7  *
      8  * @author Brian Wellington
      9  */
     10 
     11 public final class Rcode {
     12 
     13 private static Mnemonic rcodes = new Mnemonic("DNS Rcode",
     14 					      Mnemonic.CASE_UPPER);
     15 
     16 private static Mnemonic tsigrcodes = new Mnemonic("TSIG rcode",
     17 						  Mnemonic.CASE_UPPER);
     18 
     19 /** No error */
     20 public static final int NOERROR		= 0;
     21 
     22 /** Format error */
     23 public static final int FORMERR		= 1;
     24 
     25 /** Server failure */
     26 public static final int SERVFAIL	= 2;
     27 
     28 /** The name does not exist */
     29 public static final int NXDOMAIN	= 3;
     30 
     31 /** The operation requested is not implemented */
     32 public static final int NOTIMP		= 4;
     33 
     34 /** Deprecated synonym for NOTIMP. */
     35 public static final int NOTIMPL		= 4;
     36 
     37 /** The operation was refused by the server */
     38 public static final int REFUSED		= 5;
     39 
     40 /** The name exists */
     41 public static final int YXDOMAIN	= 6;
     42 
     43 /** The RRset (name, type) exists */
     44 public static final int YXRRSET		= 7;
     45 
     46 /** The RRset (name, type) does not exist */
     47 public static final int NXRRSET		= 8;
     48 
     49 /** The requestor is not authorized to perform this operation */
     50 public static final int NOTAUTH		= 9;
     51 
     52 /** The zone specified is not a zone */
     53 public static final int NOTZONE		= 10;
     54 
     55 /* EDNS extended rcodes */
     56 /** Unsupported EDNS level */
     57 public static final int BADVERS		= 16;
     58 
     59 /* TSIG/TKEY only rcodes */
     60 /** The signature is invalid (TSIG/TKEY extended error) */
     61 public static final int BADSIG		= 16;
     62 
     63 /** The key is invalid (TSIG/TKEY extended error) */
     64 public static final int BADKEY		= 17;
     65 
     66 /** The time is out of range (TSIG/TKEY extended error) */
     67 public static final int BADTIME		= 18;
     68 
     69 /** The mode is invalid (TKEY extended error) */
     70 public static final int BADMODE		= 19;
     71 
     72 static {
     73 	rcodes.setMaximum(0xFFF);
     74 	rcodes.setPrefix("RESERVED");
     75 	rcodes.setNumericAllowed(true);
     76 
     77 	rcodes.add(NOERROR, "NOERROR");
     78 	rcodes.add(FORMERR, "FORMERR");
     79 	rcodes.add(SERVFAIL, "SERVFAIL");
     80 	rcodes.add(NXDOMAIN, "NXDOMAIN");
     81 	rcodes.add(NOTIMP, "NOTIMP");
     82 	rcodes.addAlias(NOTIMP, "NOTIMPL");
     83 	rcodes.add(REFUSED, "REFUSED");
     84 	rcodes.add(YXDOMAIN, "YXDOMAIN");
     85 	rcodes.add(YXRRSET, "YXRRSET");
     86 	rcodes.add(NXRRSET, "NXRRSET");
     87 	rcodes.add(NOTAUTH, "NOTAUTH");
     88 	rcodes.add(NOTZONE, "NOTZONE");
     89 	rcodes.add(BADVERS, "BADVERS");
     90 
     91 	tsigrcodes.setMaximum(0xFFFF);
     92 	tsigrcodes.setPrefix("RESERVED");
     93 	tsigrcodes.setNumericAllowed(true);
     94 	tsigrcodes.addAll(rcodes);
     95 
     96 	tsigrcodes.add(BADSIG, "BADSIG");
     97 	tsigrcodes.add(BADKEY, "BADKEY");
     98 	tsigrcodes.add(BADTIME, "BADTIME");
     99 	tsigrcodes.add(BADMODE, "BADMODE");
    100 }
    101 
    102 private
    103 Rcode() {}
    104 
    105 /** Converts a numeric Rcode into a String */
    106 public static String
    107 string(int i) {
    108 	return rcodes.getText(i);
    109 }
    110 
    111 /** Converts a numeric TSIG extended Rcode into a String */
    112 public static String
    113 TSIGstring(int i) {
    114 	return tsigrcodes.getText(i);
    115 }
    116 
    117 /** Converts a String representation of an Rcode into its numeric value */
    118 public static int
    119 value(String s) {
    120 	return rcodes.getValue(s);
    121 }
    122 
    123 }
    124