haesbaert / mdnsd

Mdns daemon for OpenBSD.
www.haesbaert.org/openmdns
135 stars 27 forks source link

"insane mtu" setting for loopback #34

Open tehfink opened 5 years ago

tehfink commented 5 years ago

Trying to run mdnsd on FreeBSD 11.2-RELEASE-p9 with a GENERIC Kernel, in a jail mounted on the loopback interface:

lo1: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
        options=600003<RXCSUM,TXCSUM,RXCSUM_IPV6,TXCSUM_IPV6>
        inet 172.16.10.10 netmask 0xfffffff0 
        groups: lo 

Results in this error:

# mdnsd -d lo1
startup
cache_insert: (new, cleaned up) (0x801c1c800) files [lo1:00:00:00:00:00:00]._workstation._tcp.local (SRV)
cache_insert: (new, cleaned up) (0x801c1cc00) files [lo1:00:00:00:00:00:00]._workstation._tcp.local (TXT)
using iface lo1 index 4
cache_insert: (new, cleaned up) (0x801c1d800) files.local (A)
cache_insert: (new, cleaned up) (0x801c1dc00) 10.10.16.172.in-addr.arpa (PTR)
cache_insert: (new, cleaned up) (0x801c1e000) files.local (HINFO)
opened raw socket with kernel on fd 5
mdns sock bound to 0.0.0.0:5353
if_fsm: event 'UP' resulted in action 'START' and changing state for interface lo1 from 'DOWN' to 'ACTIVE'
pkt_sendto: insane mtu
Can't send packet through lo1
can't send probe packet
pkt_sendto: insane mtu
Can't send packet through lo1
can't send probe packet
…
can't send announce packet

Changing the default mtu on the host works:

# ifconfig lo1 mtu 1500
# iocage console files
# ifconfig lo1
lo1: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 1500
        options=600003<RXCSUM,TXCSUM,RXCSUM_IPV6,TXCSUM_IPV6>
        inet 172.16.10.10 netmask 0xfffffff0 
        groups: lo 
# mdnsd -d lo1
startup
cache_insert: (new, cleaned up) (0x801c1c800) files [lo1:00:00:00:00:00:00]._workstation._tcp.local (SRV)
cache_insert: (new, cleaned up) (0x801c1cc00) files [lo1:00:00:00:00:00:00]._workstation._tcp.local (TXT)
using iface lo1 index 4
cache_insert: (new, cleaned up) (0x801c1d800) files.local (A)
cache_insert: (new, cleaned up) (0x801c1dc00) 10.10.16.172.in-addr.arpa (PTR)
cache_insert: (new, cleaned up) (0x801c1e000) files.local (HINFO)
opened raw socket with kernel on fd 5
mdns sock bound to 0.0.0.0:5353
if_fsm: event 'UP' resulted in action 'START' and changing state for interface lo1 from 'DOWN' to 'ACTIVE'

But, now all the other jails must use the lower mtu setting.

twinshadow commented 5 years ago

You can fix this by changing the value of MAXPACKET in mdnsd/packet.c to a larger value. I don't know the reasoning behind the current value, so I'll do some more research before submitting a PR.

diff --git i/mdnsd/packet.c w/mdnsd/packet.c
index 7472836..1a3a7db 100644
--- i/mdnsd/packet.c
+++ w/mdnsd/packet.c
@@ -51,7 +51,7 @@
 #define NAMECOMP_MSK   0xc000
 #define NAMEADDR_MSK   ~0xc000
 #define MAXLABELS      128
-#define MAXPACKET      10000
+#define MAXPACKET      65535
 #define HDR_LEN                12
 #define MINQRY_LEN     6 /* 4 (qtype + qclass) +1 (null) + 1 (label len) */
 /* Defer truncated packets from 400ms-500ms */
twinshadow commented 5 years ago

Currently the functions recv_packet and pkt_sendto allocate the buffer on the stack using buf[MAXPACKET]. Instead, they should be allocating the buffer based on the size of the interface MTU.