31 #elif HAVE_IDN2_IDN2_H 32 #include <idn2/idn2.h> 58 if (NULL != strchr (label,
'.'))
60 if (0 == strcmp (label,
"@"))
62 if (IDNA_SUCCESS != idna_to_ascii_8z (label, &output, IDNA_ALLOW_UNASSIGNED))
64 slen = strlen (output);
87 for (tok = strtok (ldup,
"."); NULL != tok; tok = strtok (NULL,
"."))
94 if (IDNA_SUCCESS != idna_to_ascii_8z (name, &output, IDNA_ALLOW_UNASSIGNED))
96 slen = strlen (output);
215 size_t udp_payload_length,
219 const uint8_t *input = (
const uint8_t *) udp_payload;
231 if (*off >= udp_payload_length)
244 if (*off + 1 + len > udp_payload_length)
251 (rc = idna_to_unicode_8z8z (tmp, &utf8, IDNA_ALLOW_UNASSIGNED)))
254 _ (
"Failed to convert DNS IDNA name `%s' to UTF-8: %s\n"),
262 &udp_payload[*off + 1]);
274 else if ((64 | 128) == (len & (64 | 128)))
282 if (*off + 1 > udp_payload_length)
287 xoff = ((len - (64 | 128)) << 8) + input[*off + 1];
288 xstr =
parse_name (udp_payload, udp_payload_length, &xoff, depth + 1);
298 if (strlen (ret) > udp_payload_length)
314 if (0 < strlen (ret))
315 ret[strlen (ret) - 1] =
'\0';
335 size_t udp_payload_length,
338 return parse_name (udp_payload, udp_payload_length, off, 0);
354 size_t udp_payload_length,
392 size_t udp_payload_length,
405 if ((NULL == soa->
mname) || (NULL == soa->
rname) ||
437 size_t udp_payload_length,
445 if (*off +
sizeof(uint16_t) > udp_payload_length)
450 GNUNET_memcpy (&mxpref, &udp_payload[*off],
sizeof(uint16_t));
451 (*off) +=
sizeof(uint16_t);
478 size_t udp_payload_length,
519 size_t udp_payload_length,
560 size_t udp_payload_length,
582 (*off) +=
sizeof(rl);
588 if (*off + data_len > udp_payload_length)
602 if ((NULL == r->
data.
hostname) || (old_off + data_len != *off))
609 if ((NULL == r->
data.
soa) || (old_off + data_len != *off))
619 if ((NULL == r->
data.
mx) || (old_off + data_len != *off))
629 if ((NULL == r->
data.
srv) || (old_off + data_len != *off))
675 for (
unsigned int i = 0; i < n; i++)
687 for (
unsigned int i = 0; i < n; i++)
699 for (
unsigned int i = 0; i < n; i++)
712 for (
unsigned int i = 0; i < n; i++)
906 (rc = idna_to_ascii_8z (name, &idna_start, IDNA_ALLOW_UNASSIGNED)))
910 "Failed to convert UTF-8 name `%s' to DNS IDNA format: %s\n"),
915 idna_name = idna_start;
917 if (start + strlen (idna_name) + 2 > dst_len)
922 dot = strchr (idna_name,
'.');
924 len = strlen (idna_name);
927 if ((len >= 64) || (0 == len))
930 "Invalid DNS name `%s': label with %u characters encountered\n",
935 dst[pos++] = (char) (uint8_t)
len;
938 idna_name += len + 1;
983 (*off) +=
sizeof(ql);
1008 if (*off +
sizeof(uint16_t) > dst_len)
1012 (*off) +=
sizeof(mxpref);
1039 #pragma clang diagnostic push 1040 #pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare" 1048 #pragma clang diagnostic pop 1057 (*off) +=
sizeof(dcert);
1100 (*off) +=
sizeof(sd);
1132 (*off) +=
sizeof(sd);
1176 switch (record->
type)
1358 const uint8_t *idata;
1363 sprintf (&ret[off * 2],
"%02x", idata[off]);
1385 data_size = strlen (hex) / 2;
1390 in[0] = tolower ((
unsigned char) hex[off * 2]);
1391 in[1] = tolower ((
unsigned char) hex[off * 2 + 1]);
1392 if (1 != sscanf (in,
"%x", &h))
1394 idata[off] = (uint8_t) h;
uint16_t port
TCP or UDP port of the service.
void GNUNET_DNSPARSER_free_soa(struct GNUNET_DNSPARSER_SoaRecord *soa)
Free SOA information record.
struct GNUNET_DNSPARSER_Record * answers
Array of all answers in the packet, must contain "num_answers" entries.
int GNUNET_DNSPARSER_check_label(const char *label)
Check if a label in UTF-8 format can be coded into valid IDNA.
uint16_t type
See GNUNET_DNSPARSER_TYPE_*.
Information from SOA records (RFC 1035).
uint16_t type
See GNUNET_DNSPARSER_TYPE_*.
static int add_record(char *dst, size_t dst_len, size_t *off, const struct GNUNET_DNSPARSER_Record *record)
Add a DNS record to the UDP packet at the given location.
uint32_t retry
Time interval that should elapse before a failed refresh should be retried.
char * GNUNET_DNSPARSER_parse_name(const char *udp_payload, size_t udp_payload_length, size_t *off)
Parse name inside of a DNS query or record.
uint64_t rel_value_us
The actual value.
uint32_t refresh
Time interval before the zone should be refreshed.
char * mname
The domainname of the name server that was the original or primary source of data for this zone...
enum GNUNET_DNSPARSER_CertAlgorithm algorithm
Algorithm.
void GNUNET_DNSPARSER_free_srv(struct GNUNET_DNSPARSER_SrvRecord *srv)
Free SRV information record.
#define GNUNET_DNSPARSER_TYPE_CNAME
static char * parse_name(const char *udp_payload, size_t udp_payload_length, size_t *off, unsigned int depth)
Parse name inside of a DNS query or record.
char * mxhost
Name of the mail server.
struct GNUNET_DNSPARSER_SrvRecord * srv
SRV data for SRV records.
enum GNUNET_DNSPARSER_CertType cert_type
Certificate type.
uint16_t cert_tag
Certificate KeyTag.
static int start
Set if we are to start default services (including ARM).
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
static size_t data_size
Number of bytes in data.
int GNUNET_DNSPARSER_parse_record(const char *udp_payload, size_t udp_payload_length, size_t *off, struct GNUNET_DNSPARSER_Record *r)
Parse a DNS record entry.
int GNUNET_DNSPARSER_pack(const struct GNUNET_DNSPARSER_Packet *p, uint16_t max, char **buf, size_t *buf_length)
Given a DNS packet p, generate the corresponding UDP payload.
void GNUNET_DNSPARSER_free_record(struct GNUNET_DNSPARSER_Record *r)
Free the given DNS record.
#define GNUNET_TIME_UNIT_SECONDS
One second.
Information from CERT records (RFC 4034).
int GNUNET_DNSPARSER_builder_add_srv(char *dst, size_t dst_len, size_t *off, const struct GNUNET_DNSPARSER_SrvRecord *srv)
Add an SRV record to the UDP packet at the given location.
uint16_t id
DNS ID (to match replies to requests).
struct GNUNET_DNSPARSER_SoaRecord * GNUNET_DNSPARSER_duplicate_soa_record(const struct GNUNET_DNSPARSER_SoaRecord *r)
Duplicate (deep-copy) the given DNS record.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static int ret
Return value of the commandline.
void GNUNET_DNSPARSER_free_packet(struct GNUNET_DNSPARSER_Packet *p)
Free memory taken by a packet.
struct GNUNET_DNSPARSER_CertRecord * GNUNET_DNSPARSER_duplicate_cert_record(const struct GNUNET_DNSPARSER_CertRecord *r)
Duplicate (deep-copy) the given DNS record.
struct GNUNET_DNSPARSER_SoaRecord * GNUNET_DNSPARSER_parse_soa(const char *udp_payload, size_t udp_payload_length, size_t *off)
Parse a DNS SOA record.
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
Payload of DNS CERT record.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_DNSPARSER_Record * additional_records
Array of all additional answers in the packet, must contain "num_additional_records" entries...
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_DNSPARSER_TYPE_MX
Information from MX records (RFC 1035).
unsigned int num_answers
Number of answers in the packet, should be 0 for queries.
uint16_t dns_traffic_class
Desired class (usually GNUNET_TUN_DNS_CLASS_INTERNET).
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ARM_Handle * h
Connection with ARM.
General DNS record prefix.
uint32_t serial
The version number of the original copy of the zone.
#define GNUNET_DNSPARSER_TYPE_PTR
uint16_t dns_traffic_class
See GNUNET_TUN_DNS_CLASS_*.
size_t GNUNET_DNSPARSER_hex_to_bin(const char *hex, void *data)
Convert a HEX string to block of binary data.
uint16_t weight
Relative weight for records with the same priority.
uint32_t minimum_ttl
The bit minimum TTL field that should be exported with any RR from this zone.
struct GNUNET_DNSPARSER_SrvRecord * GNUNET_DNSPARSER_duplicate_srv_record(const struct GNUNET_DNSPARSER_SrvRecord *r)
Duplicate (deep-copy) the given DNS record.
#define GNUNET_DNSPARSER_TYPE_SOA
char * name
Name of the record that the query is for (0-terminated).
char * hostname
For NS, CNAME and PTR records, this is the uncompressed 0-terminated hostname.
static struct GNUNET_OS_Process * p
Helper process we started.
struct GNUNET_DNSPARSER_SoaRecord * soa
SOA data for SOA records.
unsigned int num_additional_records
Number of additional records in the packet, should be 0 for queries.
struct GNUNET_DNSPARSER_Packet * GNUNET_DNSPARSER_parse(const char *udp_payload, size_t udp_payload_length)
Parse a UDP payload of a DNS packet in to a nice struct for further processing and manipulation...
uint16_t port
TCP or UDP port of the service.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_DNSPARSER_TYPE_DNAME
uint16_t type
Record type (GNUNET_DNSPARSER_TYPE_XXX).
char * target
Hostname offering the service.
struct GNUNET_DNSPARSER_CertRecord * GNUNET_DNSPARSER_parse_cert(const char *udp_payload, size_t udp_payload_length, size_t *off)
Parse a DNS CERT record.
uint16_t cert_tag
Certificate KeyTag.
char * rname
A domainname which specifies the mailbox of the person responsible for this zone. ...
uint16_t prio
Preference for this entry (lower value is higher preference).
struct GNUNET_DNSPARSER_SrvRecord * GNUNET_DNSPARSER_parse_srv(const char *udp_payload, size_t udp_payload_length, size_t *off)
Parse a DNS SRV record.
uint8_t algorithm
Algorithm.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
union GNUNET_DNSPARSER_Record::@24 data
Payload of the record (which one of these is valid depends on the 'type').
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
unsigned int message_truncated
Set to 1 if message is truncated.
int GNUNET_DNSPARSER_builder_add_soa(char *dst, size_t dst_len, size_t *off, const struct GNUNET_DNSPARSER_SoaRecord *soa)
Add an SOA record to the UDP packet at the given location.
uint32_t serial
The version number of the original copy of the zone.
uint32_t expire
Time value that specifies the upper limit on the time interval that can elapse before the zone is no ...
struct GNUNET_DNSPARSER_Record * authority_records
Array of all authority records in the packet, must contain "num_authority_records" entries...
struct GNUNET_DNSPARSER_MxRecord * GNUNET_DNSPARSER_duplicate_mx_record(const struct GNUNET_DNSPARSER_MxRecord *r)
Duplicate (deep-copy) the given DNS record.
struct GNUNET_DNSPARSER_Record * GNUNET_DNSPARSER_duplicate_record(const struct GNUNET_DNSPARSER_Record *r)
Duplicate (deep-copy) the given DNS record.
uint32_t expire
Time value that specifies the upper limit on the time interval that can elapse before the zone is no ...
struct GNUNET_DNSPARSER_Query * queries
Array of all queries in the packet, must contain "num_queries" entries.
struct GNUNET_DNSPARSER_MxRecord * GNUNET_DNSPARSER_parse_mx(const char *udp_payload, size_t udp_payload_length, size_t *off)
Parse a DNS MX record.
int GNUNET_DNSPARSER_builder_add_cert(char *dst, size_t dst_len, size_t *off, const struct GNUNET_DNSPARSER_CertRecord *cert)
Add a CERT record to the UDP packet at the given location.
static struct GNUNET_REVOCATION_Query * q
Handle for revocation query.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
int GNUNET_DNSPARSER_parse_query(const char *udp_payload, size_t udp_payload_length, size_t *off, struct GNUNET_DNSPARSER_Query *q)
Parse a DNS query entry.
uint16_t cert_type
Certificate type.
size_t data_len
Number of bytes in data.
void * data
Binary record data.
int GNUNET_DNSPARSER_builder_add_mx(char *dst, size_t dst_len, size_t *off, const struct GNUNET_DNSPARSER_MxRecord *mx)
Add an MX record to the UDP packet at the given location.
int GNUNET_DNSPARSER_check_name(const char *name)
Check if a label in UTF-8 format can be coded into valid IDNA.
uint32_t refresh
Time interval before the zone should be refreshed.
unsigned int num_authority_records
Number of authoritative answers in the packet, should be 0 for queries.
struct GNUNET_TIME_Absolute expiration_time
When does the record expire?
char * idna_name
DNS IDNA name to lookup.
Payload of DNS SRV record (header).
size_t certificate_size
Number of bytes in certificate_data.
uint16_t data_len
Number of bytes of data that follow.
struct GNUNET_DNSPARSER_MxRecord * mx
MX data for MX records.
#define GNUNET_DNSPARSER_TYPE_NS
void GNUNET_DNSPARSER_free_cert(struct GNUNET_DNSPARSER_CertRecord *cert)
Free CERT information record.
Easy-to-process, parsed version of a DNS packet.
#define GNUNET_log(kind,...)
uint16_t dns_traffic_class
See GNUNET_TUN_DNS_CLASS_*.
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
uint16_t priority
Preference for this entry (lower value is higher preference).
char * name
Name of the record that the query is for (0-terminated).
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Payload of DNS SOA record (header).
unsigned int num_queries
Number of queries in the packet.
int GNUNET_DNSPARSER_builder_add_query(char *dst, size_t dst_len, size_t *off, const struct GNUNET_DNSPARSER_Query *query)
Add a DNS query to the UDP packet at the given location.
uint16_t weight
Relative weight for records with the same priority.
uint32_t minimum
The bit minimum TTL field that should be exported with any RR from this zone.
char * certificate_data
Data of the certificate.
uint32_t ttl
Expiration for the record (in seconds).
struct GNUNET_TUN_DnsFlags flags
Bitfield of DNS flags.
int GNUNET_DNSPARSER_builder_add_name(char *dst, size_t dst_len, size_t *off, const char *name)
Add a DNS name to the UDP packet at the given location, converting the name to IDNA notation as neces...
#define GNUNET_DNSPARSER_TYPE_SRV
uint32_t data
The data value.
uint16_t preference
Preference for this entry (lower value is higher preference).
struct GNUNET_DNSPARSER_RawRecord raw
Raw data for all other types.
void GNUNET_DNSPARSER_free_mx(struct GNUNET_DNSPARSER_MxRecord *mx)
Free MX information record.
#define GNUNET_DNSPARSER_TYPE_CERT
uint16_t dns_traffic_class
Record class (usually GNUNET_TUN_DNS_CLASS_INTERNET).
#define GNUNET_malloc(size)
Wrapper around malloc.
uint16_t type
Desired type (GNUNET_DNSPARSER_TYPE_XXX).
struct GNUNET_DNSPARSER_CertRecord * cert
CERT data for CERT records.
char * GNUNET_DNSPARSER_bin_to_hex(const void *data, size_t data_size)
Convert a block of binary data to HEX.
Information from SRV records (RFC 2782).
#define GNUNET_free(ptr)
Wrapper around free.
uint32_t retry
Time interval that should elapse before a failed refresh should be retried.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...