summaryrefslogtreecommitdiffstats
path: root/avahi-core
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2007-04-12 20:43:29 +0000
committerLennart Poettering <lennart@poettering.net>2007-04-12 20:43:29 +0000
commitbbf6b92f662ed909d5b4fca4a43b19e815812b3e (patch)
tree4bab07da0f40615b5b752f26fdf4968e6e13d72b /avahi-core
parent23addc6fe9cd09b395d327a4f6f981f2981ae63b (diff)
Fix registration of really large records, like it is necessary for XEP-0174 (jabber+bonjour)
Based on an original patch by Sjoerd Simons, but heavily modified. (Closes #131) git-svn-id: file:///home/lennart/svn/public/avahi/trunk@1405 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
Diffstat (limited to 'avahi-core')
-rw-r--r--avahi-core/dns.c2
-rw-r--r--avahi-core/dns.h5
-rw-r--r--avahi-core/probe-sched.c5
-rw-r--r--avahi-core/response-sched.c5
-rw-r--r--avahi-core/server.c26
5 files changed, 23 insertions, 20 deletions
diff --git a/avahi-core/dns.c b/avahi-core/dns.c
index 3a48482..614c396 100644
--- a/avahi-core/dns.c
+++ b/avahi-core/dns.c
@@ -786,7 +786,7 @@ uint8_t* avahi_dns_packet_append_record(AvahiDnsPacket *p, AvahiRecord *r, int c
goto fail;
size = avahi_dns_packet_extend(p, 0) - start;
- assert(size <= 0xFFFF);
+ assert(size <= AVAHI_DNS_RDATA_MAX);
/* avahi_log_debug("appended %u", size); */
diff --git a/avahi-core/dns.h b/avahi-core/dns.h
index d1c06a5..d485510 100644
--- a/avahi-core/dns.h
+++ b/avahi-core/dns.h
@@ -25,10 +25,11 @@
#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;
@@ -106,7 +107,5 @@ size_t avahi_dns_packet_space(AvahiDnsPacket *p);
#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
diff --git a/avahi-core/probe-sched.c b/avahi-core/probe-sched.c
index f430bce..106bb81 100644
--- a/avahi-core/probe-sched.c
+++ b/avahi-core/probe-sched.c
@@ -250,10 +250,7 @@ static void elapse_callback(AVAHI_GCC_UNUSED AvahiTimeEvent *e, void* data) {
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))) {
diff --git a/avahi-core/response-sched.c b/avahi-core/response-sched.c
index ef10eca..b194ef3 100644
--- a/avahi-core/response-sched.c
+++ b/avahi-core/response-sched.c
@@ -247,10 +247,7 @@ static void send_response_packet(AvahiResponseScheduler *s, AvahiResponseJob *rj
/* 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)) {
diff --git a/avahi-core/server.c b/avahi-core/server.c
index 952f09e..61f488f 100644
--- a/avahi-core/server.c
+++ b/avahi-core/server.c
@@ -370,7 +370,7 @@ void avahi_server_generate_response(AvahiServer *s, AvahiInterface *i, AvahiDnsP
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))) {
@@ -438,7 +438,6 @@ void avahi_server_generate_response(AvahiServer *s, AvahiInterface *i, AvahiDnsP
* the specific header field, and return to the caller */
avahi_dns_packet_inc_field(reply, AVAHI_DNS_FIELD_ANCOUNT);
-
break;
}
@@ -449,21 +448,32 @@ void avahi_server_generate_response(AvahiServer *s, AvahiInterface *i, AvahiDnsP
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 */