Skip to content
Snippets Groups Projects
Commit 491447ed authored by Marek Vavrusa's avatar Marek Vavrusa
Browse files

Reviewed error codes for dnslib.

Commit refs #583.
parent bbfd446a
No related branches found
No related tags found
No related merge requests found
......@@ -18,44 +18,51 @@
/*
* OPCODEs
*/
static const uint16_t DNSLIB_OPCODE_QUERY = 0; /* a standard query (QUERY) */
static const uint16_t DNSLIB_OPCODE_IQUERY = 1; /* an inverse query (IQUERY) */
static const uint16_t DNSLIB_OPCODE_STATUS = 2; /* a server status request (STATUS) */
static const uint16_t DNSLIB_OPCODE_NOTIFY = 4; /* NOTIFY */
static const uint16_t DNSLIB_OPCODE_UPDATE = 5; /* Dynamic update */
static const uint16_t DNSLIB_OPCODE_OFFSET = 14;
typedef enum dnslib_opcode {
DNSLIB_OPCODE_QUERY = 0, /* a standard query (QUERY) */
DNSLIB_OPCODE_IQUERY = 1, /* an inverse query (IQUERY) */
DNSLIB_OPCODE_STATUS = 2, /* a server status request (STATUS) */
DNSLIB_OPCODE_NOTIFY = 4, /* NOTIFY */
DNSLIB_OPCODE_UPDATE = 5, /* Dynamic update */
DNSLIB_OPCODE_OFFSET = 14
} dnslib_opcode_t;
/*
* RCODEs
*/
static const uint16_t DNSLIB_RCODE_NOERROR = 0; /* No error condition */
static const uint16_t DNSLIB_RCODE_FORMERR = 1; /* Format error */
static const uint16_t DNSLIB_RCODE_SERVFAIL = 2; /* Server failure */
static const uint16_t DNSLIB_RCODE_NXDOMAIN = 3; /* Name Error */
static const uint16_t DNSLIB_RCODE_NOTIMPL = 4; /* Not implemented */
static const uint16_t DNSLIB_RCODE_REFUSED = 5; /* Refused */
static const uint16_t DNSLIB_RCODE_YXDOMAIN = 6; /* name should not exist */
static const uint16_t DNSLIB_RCODE_YXRRSET = 7; /* rrset should not exist */
static const uint16_t DNSLIB_RCODE_NXRRSET = 8; /* rrset does not exist */
static const uint16_t DNSLIB_RCODE_NOTAUTH = 9; /* server not authoritative */
static const uint16_t DNSLIB_RCODE_NOTZONE = 10; /* name not inside zone */
typedef enum dnslib_rcode {
DNSLIB_RCODE_NOERROR = 0, /* No error condition */
DNSLIB_RCODE_FORMERR = 1, /* Format error */
DNSLIB_RCODE_SERVFAIL = 2, /* Server failure */
DNSLIB_RCODE_NXDOMAIN = 3, /* Name Error */
DNSLIB_RCODE_NOTIMPL = 4, /* Not implemented */
DNSLIB_RCODE_REFUSED = 5, /* Refused */
DNSLIB_RCODE_YXDOMAIN = 6, /* name should not exist */
DNSLIB_RCODE_YXRRSET = 7, /* rrset should not exist */
DNSLIB_RCODE_NXRRSET = 8, /* rrset does not exist */
DNSLIB_RCODE_NOTAUTH = 9, /* server not authoritative */
DNSLIB_RCODE_NOTZONE = 10 /* name not inside zone */
} dnslib_rcode_t;
/*
* CLASSes
*/
//const uint16_t DNSLIB_CLASS_IN = 1; /* Class IN */
//const uint16_t DNSLIB_CLASS_CS = 2; /* Class CS */
//const uint16_t DNSLIB_CLASS_CH = 3; /* Class CHAOS */
//const uint16_t DNSLIB_CLASS_HS = 4; /* Class HS */
//const uint16_t DNSLIB_CLASS_NONE = 254; /* Class NONE rfc2136 */
//const uint16_t DNSLIB_CLASS_ANY = 255; /* Class ANY */
//typedef enum dnslib_class {
// DNSLIB_CLASS_IN = 1, /* Class IN */
// DNSLIB_CLASS_CS = 2, /* Class CS */
// DNSLIB_CLASS_CH = 3, /* Class CHAOS */
// DNSLIB_CLASS_HS = 4, /* Class HS */
// DNSLIB_CLASS_NONE = 254, /* Class NONE rfc2136 */
// DNSLIB_CLASS_ANY = 255 /* Class ANY */
//} dnslib_class_t;
/*
* Other
*/
static const unsigned int DNSLIB_MAX_DNAME_LENGTH = 255;
static const unsigned int DNSLIB_MAX_DNAME_LABELS = 127; // 1-char labels
typedef enum dnslib_const {
DNSLIB_MAX_DNAME_LENGTH = 255,
DNSLIB_MAX_DNAME_LABELS = 127 // 1-char labels
} dnslib_const_t;
#endif /* _KNOT_DNSLIB_CONSTS_H_ */
......
......@@ -20,7 +20,7 @@
#include <stdbool.h>
#include <string.h>
enum mxrdtln {
enum dnslib_mxrdtln {
/*! \brief Maximum items in RDATA wireformat. */
DNSLIB_MAX_RDATA_ITEMS = 64,
/*! \brief Maximum size of one item in RDATA wireformat. */
......@@ -29,6 +29,8 @@ enum mxrdtln {
DNSLIB_MAX_RDATA_WIRE_SIZE =
DNSLIB_MAX_RDATA_ITEMS * DNSLIB_MAX_RDATA_ITEM_SIZE
};
typedef enum dnslib_mxrdtln dnslib_mxrdtln_t;
//#define MAXRDATALEN 64
/* 64 is in NSD. Seems a little too much, but I'd say it's not a real issue. */
......@@ -49,6 +51,7 @@ typedef enum dnslib_rr_class dnslib_rr_class_t;
/*!
* \brief Resource record type constants.
* \todo Not all indices can be used for indexing.
*/
enum dnslib_rr_type {
DNSLIB_RRTYPE_UNKNOWN, /*!< 0 - an unknown type */
......@@ -129,19 +132,14 @@ enum dnslib_rr_type {
// totally weird numbers (cannot use for indexing)
DNSLIB_RRTYPE_TA = 32768, /*!< DNSSEC Trust Authorities */
DNSLIB_RRTYPE_DLV = 32769 /*!< RFC 4431 */
DNSLIB_RRTYPE_DLV = 32769, /*!< RFC 4431 */
/*! \brief Last normal RR type. */
DNSLIB_RRTYPE_LAST = DNSLIB_RRTYPE_NSEC3PARAM
};
/*!
* \brief Enum containing RR type codes.
*
* \todo Not all indices can be used for indexing.
*/
typedef enum dnslib_rr_type dnslib_rr_type_t;
/*! \brief Last normal RR type. */
static const uint DNSLIB_RRTYPE_LAST = DNSLIB_RRTYPE_NSEC3PARAM;
/*! \brief Constants characterising the wire format of RDATA items. */
enum dnslib_rdata_wireformat {
/*!
......
......@@ -106,6 +106,7 @@ dnslib_dname_t *dnslib_dname_new_from_wire(const uint8_t *name,
*
* \retval DNSLIB_EOK on success.
* \retval DNSLIB_ENOMEM if allocation of labels info failed.
* \retval DNSLIB_EBADARG if name or target is null.
*
* \todo This function does not check if the given data is in correct wire
* format at all. It thus creates a invalid domain name, which if passed
......
......@@ -204,7 +204,7 @@ int dnslib_edns_add_option(dnslib_opt_rr_t *opt_rr, uint16_t code,
}
opt_rr->options[opt_rr->option_count].data = (uint8_t *)malloc(length);
CHECK_ALLOC_LOG(opt_rr->options[opt_rr->option_count].data, -1);
CHECK_ALLOC_LOG(opt_rr->options[opt_rr->option_count].data, DNSLIB_ENOMEM);
memcpy(opt_rr->options[opt_rr->option_count].data, data, length);
opt_rr->options[opt_rr->option_count].code = code;
......
......@@ -56,6 +56,7 @@ int dnslib_nsec3_params_from_wire(dnslib_nsec3_params_t *params,
* \param[out] digest_size Size of the result in octets will be stored here.
*
* \retval DNSLIB_EOK if successful.
* \retval DNSLIB_ENOMEM
* \retval DNSLIB_EBADARG
* \retval DNSLIB_ECRYPTO
*/
......
......@@ -15,11 +15,11 @@
#include <stdint.h>
/*! \brief Size of the character conversion table. */
#define KNOT_CHAR_TABLE_SIZE 256
#define DNSLIB_CHAR_TABLE_SIZE 256
enum {
/*! \brief Size of the character conversion table. */
CHAR_TABLE_SIZE = KNOT_CHAR_TABLE_SIZE
CHAR_TABLE_SIZE = DNSLIB_CHAR_TABLE_SIZE
};
/*! \brief Character table mapping uppercase letters to lowercase. */
......@@ -33,7 +33,7 @@ const uint8_t char_table[CHAR_TABLE_SIZE];
* \return \a c converted to lowercase (or \a c if not applicable).
*/
static inline uint8_t dnslib_tolower(uint8_t c) {
#if KNOT_CHAR_TABLE_SIZE < 256
#if DNSLIB_CHAR_TABLE_SIZE < 256
assert(c < CHAR_TABLE_SIZE);
#endif
return char_table[c];
......
......@@ -1067,8 +1067,7 @@ int zone_dump_text(dnslib_zone_t *zone, const char *filename)
{
FILE *f = fopen(filename, "w");
if (f == NULL) {
//TODO log message
return -1;
return DNSLIB_EBADARG;
}
fprintf(f, ";Dumped using %s v. %d.%d.%d\n", PROJECT_NAME,
......@@ -1082,5 +1081,5 @@ int zone_dump_text(dnslib_zone_t *zone, const char *filename)
dnslib_zone_tree_apply_inorder(zone, node_dump_text, &param);
fclose(f);
return 0;
return DNSLIB_EOK;
}
......@@ -21,8 +21,8 @@
* \param zone Zone to be saved.
* \param filename Name of file to be created.
*
* \retval 0 on success.
* \retval -1 on error.
* \retval DNSLIB_EOK on success.
* \retval DNSLIB_EBADARG if the specified file is not valid for writing.
*/
int zone_dump_text(dnslib_zone_t *zone, const char *filename);
......
......@@ -31,8 +31,8 @@ enum {
* \param filename Name of file to be created.
* \param sfilename Source filename of the text zone file.
*
* \retval 0 on success.
* \retval 1 on error.
* \retval DNSLIB_EOK on success.
* \retval DNSLIB_EBADARG if the file cannot be opened for writing.
*/
int dnslib_zdump_binary(dnslib_zone_t *zone, const char *filename,
char do_checks, const char *sfilename);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment