]> git.meshlink.io Git - catta/commitdiff
Fix registration of really large records, like it is necessary for XEP-0174 (jabber...
authorLennart Poettering <lennart@poettering.net>
Thu, 12 Apr 2007 20:43:29 +0000 (20:43 +0000)
committerLennart Poettering <lennart@poettering.net>
Thu, 12 Apr 2007 20:43:29 +0000 (20:43 +0000)
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

avahi-core/dns.c
avahi-core/dns.h
avahi-core/probe-sched.c
avahi-core/response-sched.c
avahi-core/server.c

index 3a48482bab9d188aa253d92134f1661b946c484d..614c3960dd10eb4c08bf2eb481ee4b500b69fa93 100644 (file)
@@ -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); */
 
index d1c06a5b37f1793a9f8ab4f87a39c4575e5edf0b..d4855100988f771776ac57de1b4af3da7772545c 100644 (file)
 #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
 
index f430bce2ca3b4fbaeca0b051e8d906f65b74446a..106bb8135fda21b15bac6aa9744b036f4095e721 100644 (file)
@@ -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))) {
index ef10eca2ccc50f5829af193f73de3e6ecd4c5c06..b194ef3f6f009a5b274052051f8cedc3e8500fef 100644 (file)
@@ -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)) {
index 952f09e1245a94dd64d73fc3d0c40606f40bb8cc..61f488fde9d2d030647993de903e55714aa91b5b 100644 (file)
@@ -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 */