From a2498898b05b1cb284c8f11cb37ab8b7c16e1224 Mon Sep 17 00:00:00 2001 From: David Girault Date: Thu, 31 Jan 2019 16:47:10 +0100 Subject: [PATCH] mdns: increase mDNS output packet size When more than one service (just 2) need to be probed for conflict, generation of the probe packet fail because pbuf is too small! So OUTPACKET_SIZE renamed to MDNS_OUTPUT_PACKET_SIZE and moved to mdns_opts.h to allow configuration. Default configuration raise it to 1450 to have enough space when MDNS_MAX_SERVICES > 1 else it remain 512. Extract from RFC 6762, chapter 17, Multicast DNS Message Size: The 1987 DNS specification [RFC1035] restricts DNS messages carried by UDP to no more than 512 bytes (not counting the IP or UDP headers). For UDP packets carried over the wide-area Internet in 1987, this was appropriate. For link-local multicast packets on today's networks, there is no reason to retain this restriction. Given that the packets are by definition link-local, there are no Path MTU issues to consider. Multicast DNS messages carried by UDP may be up to the IP MTU of the physical interface, less the space required for the IP header (20 bytes for IPv4; 40 bytes for IPv6) and the UDP header (8 bytes). Signed-off-by: Simon Goldschmidt --- src/apps/mdns/mdns_out.c | 7 ++----- src/include/lwip/apps/mdns_opts.h | 10 ++++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/apps/mdns/mdns_out.c b/src/apps/mdns/mdns_out.c index 10a61929..776af804 100644 --- a/src/apps/mdns/mdns_out.c +++ b/src/apps/mdns/mdns_out.c @@ -52,9 +52,6 @@ #if LWIP_MDNS_RESPONDER -/* Payload size allocated for each outgoing UDP packet */ -#define OUTPACKET_SIZE 500 - /* Function prototypes */ static void mdns_clear_outmsg(struct mdns_outmsg *outmsg); @@ -93,7 +90,7 @@ mdns_add_question(struct mdns_outpacket *outpkt, struct mdns_domain *domain, if (!outpkt->pbuf) { /* If no pbuf is active, allocate one */ - outpkt->pbuf = pbuf_alloc(PBUF_TRANSPORT, OUTPACKET_SIZE, PBUF_RAM); + outpkt->pbuf = pbuf_alloc(PBUF_TRANSPORT, MDNS_OUTPUT_PACKET_SIZE, PBUF_RAM); if (!outpkt->pbuf) { return ERR_MEM; } @@ -166,7 +163,7 @@ mdns_add_answer(struct mdns_outpacket *reply, struct mdns_domain *domain, if (!reply->pbuf) { /* If no pbuf is active, allocate one */ - reply->pbuf = pbuf_alloc(PBUF_TRANSPORT, OUTPACKET_SIZE, PBUF_RAM); + reply->pbuf = pbuf_alloc(PBUF_TRANSPORT, MDNS_OUTPUT_PACKET_SIZE, PBUF_RAM); if (!reply->pbuf) { return ERR_MEM; } diff --git a/src/include/lwip/apps/mdns_opts.h b/src/include/lwip/apps/mdns_opts.h index 684d631e..50a8e57f 100644 --- a/src/include/lwip/apps/mdns_opts.h +++ b/src/include/lwip/apps/mdns_opts.h @@ -60,6 +60,16 @@ #define MDNS_MAX_SERVICES 1 #endif +/** Payload size allocated for each outgoing UDP packet. Will be allocated with + * PBUF_RAM and freed after packet was sent. + * According to RFC 6762, there is no reason to retain the 512 bytes restriction + * for link-local multicast packet. + * 512 bytes isn't enough when 2 services need to be probed. + */ +#ifndef MDNS_OUTPUT_PACKET_SIZE +#define MDNS_OUTPUT_PACKET_SIZE ((MDNS_MAX_SERVICES == 1) ? 512 : 1450) +#endif + /** MDNS_RESP_USENETIF_EXTCALLBACK==1: register an ext_callback on the netif * to automatically restart probing/announcing on status or address change. */