4817. [cleanup] Use DNS_NAME_INITABSOLUTE and DNS_NAME_INITNONABSOLUTE.

[RT #45433]
This commit is contained in:
Mark Andrews 2017-11-13 16:58:12 +11:00
parent 3def40b01b
commit 3d905e0533
8 changed files with 94 additions and 166 deletions

View file

@ -1,3 +1,6 @@
4817. [cleanup] Use DNS_NAME_INITABSOLUTE and DNS_NAME_INITNONABSOLUTE.
[RT #45433]
4816. [bug] Don't use a common array for storing EDNS options
in DiG as it could fill up. [RT #45611]

View file

@ -51,7 +51,7 @@
static unsigned char dlviscorg_ndata[] = "\003dlv\003isc\003org";
static unsigned char dlviscorg_offsets[] = { 0, 4, 8, 12 };
static const dns_name_t dlviscorg =
static dns_name_t const dlviscorg =
DNS_NAME_INITABSOLUTE(dlviscorg_ndata, dlviscorg_offsets);
static isc_result_t

View file

@ -143,6 +143,26 @@ struct dns_name {
LIBDNS_EXTERNAL_DATA extern const dns_name_t *dns_rootname;
LIBDNS_EXTERNAL_DATA extern const dns_name_t *dns_wildcardname;
/*%<
* DNS_NAME_INITNONABSOLUTE and DNS_NAME_INITABSOLUTE are macros for
* initializing dns_name_t structures.
*
* Note[1]: 'length' is set to (sizeof(A) - 1) in DNS_NAME_INITNONABSOLUTE
* and sizeof(A) in DNS_NAME_INITABSOLUTE to allow C strings to be used
* to initialize 'ndata'.
*
* Note[2]: The final value of offsets for DNS_NAME_INITABSOLUTE should
* match (sizeof(A) - 1) which is the offset of the root label.
*
* Typical usage:
* unsigned char data[] = "\005value";
* unsigned char offsets[] = { 0 };
* dns_name_t value = DNS_NAME_INITNONABSOLUTE(data, offsets);
*
* unsigned char data[] = "\005value";
* unsigned char offsets[] = { 0, 6 };
* dns_name_t value = DNS_NAME_INITABSOLUTE(data, offsets);
*/
#define DNS_NAME_INITNONABSOLUTE(A,B) { \
DNS_NAME_MAGIC, \
A, (sizeof(A) - 1), sizeof(B), \

View file

@ -322,39 +322,18 @@ loadctx_destroy(dns_loadctx_t *lctx);
static unsigned char in_addr_arpa_data[] = "\007IN-ADDR\004ARPA";
static unsigned char in_addr_arpa_offsets[] = { 0, 8, 13 };
static const dns_name_t in_addr_arpa =
{
DNS_NAME_MAGIC,
in_addr_arpa_data, 14, 3,
DNS_NAMEATTR_READONLY | DNS_NAMEATTR_ABSOLUTE,
in_addr_arpa_offsets, NULL,
{(void *)-1, (void *)-1},
{NULL, NULL}
};
static dns_name_t const in_addr_arpa =
DNS_NAME_INITABSOLUTE(in_addr_arpa_data, in_addr_arpa_offsets);
static unsigned char ip6_int_data[] = "\003IP6\003INT";
static unsigned char ip6_int_offsets[] = { 0, 4, 8 };
static const dns_name_t ip6_int =
{
DNS_NAME_MAGIC,
ip6_int_data, 9, 3,
DNS_NAMEATTR_READONLY | DNS_NAMEATTR_ABSOLUTE,
ip6_int_offsets, NULL,
{(void *)-1, (void *)-1},
{NULL, NULL}
};
static dns_name_t const ip6_int =
DNS_NAME_INITABSOLUTE(ip6_int_data, ip6_int_offsets);
static unsigned char ip6_arpa_data[] = "\003IP6\004ARPA";
static unsigned char ip6_arpa_offsets[] = { 0, 4, 9 };
static const dns_name_t ip6_arpa =
{
DNS_NAME_MAGIC,
ip6_arpa_data, 10, 3,
DNS_NAMEATTR_READONLY | DNS_NAMEATTR_ABSOLUTE,
ip6_arpa_offsets, NULL,
{(void *)-1, (void *)-1},
{NULL, NULL}
};
static dns_name_t const ip6_arpa =
DNS_NAME_INITABSOLUTE(ip6_arpa_data, ip6_arpa_offsets);
static inline isc_result_t
gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *token,

View file

@ -144,34 +144,17 @@ do { \
* literal, to avoid compiler warnings about discarding
* the const attribute of a string.
*/
static unsigned char root_ndata[] = { '\0' };
static unsigned char root_ndata[] = { "" };
static unsigned char root_offsets[] = { 0 };
static dns_name_t root =
{
DNS_NAME_MAGIC,
root_ndata, 1, 1,
DNS_NAMEATTR_READONLY | DNS_NAMEATTR_ABSOLUTE,
root_offsets, NULL,
{(void *)-1, (void *)-1},
{NULL, NULL}
};
/* XXXDCL make const? */
static dns_name_t root = DNS_NAME_INITABSOLUTE(root_ndata, root_offsets);
LIBDNS_EXTERNAL_DATA const dns_name_t *dns_rootname = &root;
static unsigned char wild_ndata[] = { '\001', '*' };
static unsigned char wild_ndata[] = { "\001*" };
static unsigned char wild_offsets[] = { 0 };
static dns_name_t wild =
{
DNS_NAME_MAGIC,
wild_ndata, 2, 1,
DNS_NAMEATTR_READONLY,
wild_offsets, NULL,
{(void *)-1, (void *)-1},
{NULL, NULL}
};
static dns_name_t const wild =
DNS_NAME_INITNONABSOLUTE(wild_ndata, wild_offsets);
/* XXXDCL make const? */
LIBDNS_EXTERNAL_DATA const dns_name_t *dns_wildcardname = &wild;
@ -2613,47 +2596,12 @@ static unsigned char dr_dns_sd_udp_offsets[] = { 0, 3, 11 };
static unsigned char lb_dns_sd_udp_data[] = "\002lb\007_dns-sd\004_udp";
static unsigned char lb_dns_sd_udp_offsets[] = { 0, 3, 11 };
static const dns_name_t dns_sd[] = {
{
DNS_NAME_MAGIC,
b_dns_sd_udp_data, 15, 3,
DNS_NAMEATTR_READONLY,
b_dns_sd_udp_offsets, NULL,
{(void *)-1, (void *)-1},
{NULL, NULL}
},
{
DNS_NAME_MAGIC,
db_dns_sd_udp_data, 16, 3,
DNS_NAMEATTR_READONLY,
db_dns_sd_udp_offsets, NULL,
{(void *)-1, (void *)-1},
{NULL, NULL}
},
{
DNS_NAME_MAGIC,
r_dns_sd_udp_data, 15, 3,
DNS_NAMEATTR_READONLY,
r_dns_sd_udp_offsets, NULL,
{(void *)-1, (void *)-1},
{NULL, NULL}
},
{
DNS_NAME_MAGIC,
dr_dns_sd_udp_data, 16, 3,
DNS_NAMEATTR_READONLY,
dr_dns_sd_udp_offsets, NULL,
{(void *)-1, (void *)-1},
{NULL, NULL}
},
{
DNS_NAME_MAGIC,
lb_dns_sd_udp_data, 16, 3,
DNS_NAMEATTR_READONLY,
lb_dns_sd_udp_offsets, NULL,
{(void *)-1, (void *)-1},
{NULL, NULL}
}
static dns_name_t const dns_sd[] = {
DNS_NAME_INITNONABSOLUTE(b_dns_sd_udp_data, b_dns_sd_udp_offsets),
DNS_NAME_INITNONABSOLUTE(db_dns_sd_udp_data, db_dns_sd_udp_offsets),
DNS_NAME_INITNONABSOLUTE(r_dns_sd_udp_data, r_dns_sd_udp_offsets),
DNS_NAME_INITNONABSOLUTE(dr_dns_sd_udp_data, dr_dns_sd_udp_offsets),
DNS_NAME_INITNONABSOLUTE(lb_dns_sd_udp_data, lb_dns_sd_udp_offsets)
};
isc_boolean_t
@ -2672,15 +2620,6 @@ dns_name_isdnssd(const dns_name_t *name) {
return (ISC_FALSE);
}
#define NS_NAME_INIT(A,B) \
{ \
DNS_NAME_MAGIC, \
A, sizeof(A), sizeof(B), \
DNS_NAMEATTR_READONLY | DNS_NAMEATTR_ABSOLUTE, \
B, NULL, { (void *)-1, (void *)-1}, \
{NULL, NULL} \
}
static unsigned char inaddr10_offsets[] = { 0, 3, 11, 16 };
static unsigned char inaddr172_offsets[] = { 0, 3, 7, 15, 20 };
static unsigned char inaddr192_offsets[] = { 0, 4, 8, 16, 21 };
@ -2707,24 +2646,24 @@ static unsigned char inaddr31172[] = "\00231\003172\007IN-ADDR\004ARPA";
static unsigned char inaddr168192[] = "\003168\003192\007IN-ADDR\004ARPA";
static dns_name_t const rfc1918names[] = {
NS_NAME_INIT(inaddr10, inaddr10_offsets),
NS_NAME_INIT(inaddr16172, inaddr172_offsets),
NS_NAME_INIT(inaddr17172, inaddr172_offsets),
NS_NAME_INIT(inaddr18172, inaddr172_offsets),
NS_NAME_INIT(inaddr19172, inaddr172_offsets),
NS_NAME_INIT(inaddr20172, inaddr172_offsets),
NS_NAME_INIT(inaddr21172, inaddr172_offsets),
NS_NAME_INIT(inaddr22172, inaddr172_offsets),
NS_NAME_INIT(inaddr23172, inaddr172_offsets),
NS_NAME_INIT(inaddr24172, inaddr172_offsets),
NS_NAME_INIT(inaddr25172, inaddr172_offsets),
NS_NAME_INIT(inaddr26172, inaddr172_offsets),
NS_NAME_INIT(inaddr27172, inaddr172_offsets),
NS_NAME_INIT(inaddr28172, inaddr172_offsets),
NS_NAME_INIT(inaddr29172, inaddr172_offsets),
NS_NAME_INIT(inaddr30172, inaddr172_offsets),
NS_NAME_INIT(inaddr31172, inaddr172_offsets),
NS_NAME_INIT(inaddr168192, inaddr192_offsets)
DNS_NAME_INITABSOLUTE(inaddr10, inaddr10_offsets),
DNS_NAME_INITABSOLUTE(inaddr16172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr17172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr18172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr19172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr20172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr21172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr22172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr23172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr24172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr25172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr26172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr27172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr28172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr29172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr30172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr31172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr168192, inaddr192_offsets)
};
isc_boolean_t
@ -2742,8 +2681,8 @@ static unsigned char ip6fc[] = "\001c\001f\003ip6\004ARPA";
static unsigned char ip6fd[] = "\001d\001f\003ip6\004ARPA";
static dns_name_t const ulanames[] = {
NS_NAME_INIT(ip6fc, ulaoffsets),
NS_NAME_INIT(ip6fd, ulaoffsets),
DNS_NAME_INITABSOLUTE(ip6fc, ulaoffsets),
DNS_NAME_INITABSOLUTE(ip6fd, ulaoffsets)
};
isc_boolean_t

View file

@ -313,14 +313,8 @@ generic_freestruct_tlsa(ARGS_FREESTRUCT);
static unsigned char gc_msdcs_data[] = "\002gc\006_msdcs";
static unsigned char gc_msdcs_offset [] = { 0, 3 };
static const dns_name_t gc_msdcs = {
DNS_NAME_MAGIC,
gc_msdcs_data, 10, 2,
DNS_NAMEATTR_READONLY,
gc_msdcs_offset, NULL,
{(void *)-1, (void *)-1},
{NULL, NULL}
};
static dns_name_t const gc_msdcs =
DNS_NAME_INITNONABSOLUTE(gc_msdcs_data, gc_msdcs_offset);
/*%
* convert presentation level address to network order binary form.

View file

@ -52,14 +52,14 @@
static unsigned char hmacmd5_ndata[] = "\010hmac-md5\007sig-alg\003reg\003int";
static unsigned char hmacmd5_offsets[] = { 0, 9, 17, 21, 25 };
static dns_name_t hmacmd5 =
static dns_name_t const hmacmd5 =
DNS_NAME_INITABSOLUTE(hmacmd5_ndata, hmacmd5_offsets);
LIBDNS_EXTERNAL_DATA const dns_name_t *dns_tsig_hmacmd5_name = &hmacmd5;
#endif
static unsigned char gsstsig_ndata[] = "\010gss-tsig";
static unsigned char gsstsig_offsets[] = { 0, 9 };
static dns_name_t gsstsig =
static dns_name_t const gsstsig =
DNS_NAME_INITABSOLUTE(gsstsig_ndata, gsstsig_offsets);
LIBDNS_EXTERNAL_DATA const dns_name_t *dns_tsig_gssapi_name = &gsstsig;
@ -69,41 +69,41 @@ LIBDNS_EXTERNAL_DATA const dns_name_t *dns_tsig_gssapi_name = &gsstsig;
*/
static unsigned char gsstsigms_ndata[] = "\003gss\011microsoft\003com";
static unsigned char gsstsigms_offsets[] = { 0, 4, 14, 18 };
static dns_name_t gsstsigms =
static dns_name_t const gsstsigms =
DNS_NAME_INITABSOLUTE(gsstsigms_ndata, gsstsigms_offsets);
LIBDNS_EXTERNAL_DATA const dns_name_t *dns_tsig_gssapims_name = &gsstsigms;
static unsigned char hmacsha1_ndata[] = "\011hmac-sha1";
static unsigned char hmacsha1_offsets[] = { 0, 10 };
static dns_name_t hmacsha1 =
static dns_name_t const hmacsha1 =
DNS_NAME_INITABSOLUTE(hmacsha1_ndata, hmacsha1_offsets);
LIBDNS_EXTERNAL_DATA const dns_name_t *dns_tsig_hmacsha1_name = &hmacsha1;
static unsigned char hmacsha224_ndata[] = "\013hmac-sha224";
static unsigned char hmacsha224_offsets[] = { 0, 12 };
static dns_name_t hmacsha224 =
static dns_name_t const hmacsha224 =
DNS_NAME_INITABSOLUTE(hmacsha224_ndata, hmacsha224_offsets);
LIBDNS_EXTERNAL_DATA const dns_name_t *dns_tsig_hmacsha224_name = &hmacsha224;
static unsigned char hmacsha256_ndata[] = "\013hmac-sha256";
static unsigned char hmacsha256_offsets[] = { 0, 12 };
static dns_name_t hmacsha256 =
static dns_name_t const hmacsha256 =
DNS_NAME_INITABSOLUTE(hmacsha256_ndata, hmacsha256_offsets);
LIBDNS_EXTERNAL_DATA const dns_name_t *dns_tsig_hmacsha256_name = &hmacsha256;
static unsigned char hmacsha384_ndata[] = "\013hmac-sha384";
static unsigned char hmacsha384_offsets[] = { 0, 12 };
static dns_name_t hmacsha384 =
static dns_name_t const hmacsha384 =
DNS_NAME_INITABSOLUTE(hmacsha384_ndata, hmacsha384_offsets);
LIBDNS_EXTERNAL_DATA const dns_name_t *dns_tsig_hmacsha384_name = &hmacsha384;
static unsigned char hmacsha512_ndata[] = "\013hmac-sha512";
static unsigned char hmacsha512_offsets[] = { 0, 12 };
static dns_name_t hmacsha512 =
static dns_name_t const hmacsha512 =
DNS_NAME_INITABSOLUTE(hmacsha512_ndata, hmacsha512_offsets);
LIBDNS_EXTERNAL_DATA const dns_name_t *dns_tsig_hmacsha512_name = &hmacsha512;
static struct {
static const struct {
const dns_name_t *name;
unsigned int dstalg;
} known_algs[] = {

View file

@ -4343,15 +4343,6 @@ rdata_tonetaddr(const dns_rdata_t *rdata, isc_netaddr_t *netaddr) {
}
}
#define NS_NAME_INIT(A,B) \
{ \
DNS_NAME_MAGIC, \
A, sizeof(A), sizeof(B), \
DNS_NAMEATTR_READONLY | DNS_NAMEATTR_ABSOLUTE, \
B, NULL, { (void *)-1, (void *)-1}, \
{NULL, NULL} \
}
static unsigned char inaddr10_offsets[] = { 0, 3, 11, 16 };
static unsigned char inaddr172_offsets[] = { 0, 3, 7, 15, 20 };
static unsigned char inaddr192_offsets[] = { 0, 4, 8, 16, 21 };
@ -4378,24 +4369,24 @@ static unsigned char inaddr31172[] = "\00231\003172\007IN-ADDR\004ARPA";
static unsigned char inaddr168192[] = "\003168\003192\007IN-ADDR\004ARPA";
static dns_name_t rfc1918names[] = {
NS_NAME_INIT(inaddr10, inaddr10_offsets),
NS_NAME_INIT(inaddr16172, inaddr172_offsets),
NS_NAME_INIT(inaddr17172, inaddr172_offsets),
NS_NAME_INIT(inaddr18172, inaddr172_offsets),
NS_NAME_INIT(inaddr19172, inaddr172_offsets),
NS_NAME_INIT(inaddr20172, inaddr172_offsets),
NS_NAME_INIT(inaddr21172, inaddr172_offsets),
NS_NAME_INIT(inaddr22172, inaddr172_offsets),
NS_NAME_INIT(inaddr23172, inaddr172_offsets),
NS_NAME_INIT(inaddr24172, inaddr172_offsets),
NS_NAME_INIT(inaddr25172, inaddr172_offsets),
NS_NAME_INIT(inaddr26172, inaddr172_offsets),
NS_NAME_INIT(inaddr27172, inaddr172_offsets),
NS_NAME_INIT(inaddr28172, inaddr172_offsets),
NS_NAME_INIT(inaddr29172, inaddr172_offsets),
NS_NAME_INIT(inaddr30172, inaddr172_offsets),
NS_NAME_INIT(inaddr31172, inaddr172_offsets),
NS_NAME_INIT(inaddr168192, inaddr192_offsets)
DNS_NAME_INITABSOLUTE(inaddr10, inaddr10_offsets),
DNS_NAME_INITABSOLUTE(inaddr16172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr17172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr18172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr19172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr20172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr21172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr22172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr23172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr24172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr25172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr26172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr27172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr28172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr29172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr30172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr31172, inaddr172_offsets),
DNS_NAME_INITABSOLUTE(inaddr168192, inaddr192_offsets)
};
@ -4405,8 +4396,10 @@ static unsigned char hostmaster_data[] = "\012hostmaster\014root-servers\003org"
static unsigned char prisoner_offsets[] = { 0, 9, 14, 18 };
static unsigned char hostmaster_offsets[] = { 0, 11, 24, 28 };
static dns_name_t prisoner = NS_NAME_INIT(prisoner_data, prisoner_offsets);
static dns_name_t hostmaster = NS_NAME_INIT(hostmaster_data, hostmaster_offsets);
static dns_name_t const prisoner =
DNS_NAME_INITABSOLUTE(prisoner_data, prisoner_offsets);
static dns_name_t const hostmaster =
DNS_NAME_INITABSOLUTE(hostmaster_data, hostmaster_offsets);
static void
warn_rfc1918(ns_client_t *client, dns_name_t *fname, dns_rdataset_t *rdataset) {