#include "rr.h"
#include "hashmap.h"
-#define AVAHI_DNS_PACKET_SIZE_MAX 9000
#define AVAHI_DNS_PACKET_HEADER_SIZE 12
#define AVAHI_DNS_PACKET_EXTRA_SIZE 48
#define AVAHI_DNS_LABELS_MAX 127
+#define AVAHI_DNS_RDATA_MAX 0xFFFF
+#define AVAHI_DNS_PACKET_SIZE_MAX (AVAHI_DNS_PACKET_HEADER_SIZE + 256 + 2 + 2 + 4 + 2 + AVAHI_DNS_RDATA_MAX)
typedef struct AvahiDnsPacket {
size_t size, rindex, max_size;
#define AVAHI_MDNS_SUFFIX_ADDR_IPV4 "254.169.in-addr.arpa"
#define AVAHI_MDNS_SUFFIX_ADDR_IPV6 "0.8.e.f.ip6.arpa"
-#define AVAHI_DNS_RDATA_MAX 65535
-
#endif
avahi_record_get_estimate_size(pj->record) +
AVAHI_DNS_PACKET_HEADER_SIZE;
- if (size > AVAHI_DNS_PACKET_SIZE_MAX)
- size = AVAHI_DNS_PACKET_SIZE_MAX;
-
- if (!(p = avahi_dns_packet_new_query(size)))
+ if (!(p = avahi_dns_packet_new_query(size + AVAHI_DNS_PACKET_EXTRA_SIZE)))
return; /* OOM */
if (!(k = avahi_key_new(pj->record->key->name, pj->record->key->clazz, AVAHI_DNS_TYPE_ANY))) {
/* OK, the packet was too small, so create one that fits */
size = avahi_record_get_estimate_size(rj->record) + AVAHI_DNS_PACKET_HEADER_SIZE;
- if (size > AVAHI_DNS_PACKET_SIZE_MAX)
- size = AVAHI_DNS_PACKET_SIZE_MAX;
-
- if (!(p = avahi_dns_packet_new_response(size, 1)))
+ if (!(p = avahi_dns_packet_new_response(size + AVAHI_DNS_PACKET_EXTRA_SIZE, 1)))
return; /* OOM */
if (!packet_add_response_job(s, p, rj)) {
AvahiDnsPacket *reply;
AvahiRecord *r;
- if (!(reply = avahi_dns_packet_new_reply(p, 512 /* unicast DNS maximum packet size is 512 */ , 1, 1)))
+ if (!(reply = avahi_dns_packet_new_reply(p, 512 + AVAHI_DNS_PACKET_EXTRA_SIZE /* unicast DNS maximum packet size is 512 */ , 1, 1)))
return; /* OOM */
while ((r = avahi_record_list_next(s->record_list, NULL, NULL, NULL))) {
* the specific header field, and return to the caller */
avahi_dns_packet_inc_field(reply, AVAHI_DNS_FIELD_ANCOUNT);
-
break;
}
avahi_dns_packet_free(reply);
size = avahi_record_get_estimate_size(r) + AVAHI_DNS_PACKET_HEADER_SIZE;
- if (size > AVAHI_DNS_PACKET_SIZE_MAX)
- size = AVAHI_DNS_PACKET_SIZE_MAX;
- if (!(reply = avahi_dns_packet_new_reply(p, size, 0, 1)))
+ if (!(reply = avahi_dns_packet_new_reply(p, size + AVAHI_DNS_PACKET_EXTRA_SIZE, 0, 1)))
break; /* OOM */
- if (!avahi_dns_packet_append_record(reply, r, flush_cache, 0)) {
+ if (avahi_dns_packet_append_record(reply, r, flush_cache, 0)) {
+
+ /* Appending this record succeeded, so incremeant
+ * the specific header field, and return to the caller */
+
+ avahi_dns_packet_inc_field(reply, AVAHI_DNS_FIELD_ANCOUNT);
+ break;
+
+ } else {
+
+ /* We completely fucked up, there's
+ * nothing we can do. The RR just doesn't
+ * fit in. Let's ignore it. */
+
char *t;
avahi_dns_packet_free(reply);
+ reply = NULL;
t = avahi_record_to_string(r);
avahi_log_warn("Record [%s] too large, doesn't fit in any packet!", t);
avahi_free(t);
break;
- } else
- avahi_dns_packet_inc_field(reply, AVAHI_DNS_FIELD_ANCOUNT);
+ }
}
/* Appending the record didn't succeeed, so let's send this packet, and create a new one */