From a957c3e347e4f628c77b61a9dc6e49cb81a0efec Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Tue, 14 Feb 2017 00:14:45 +0100 Subject: [PATCH] Set TTL to 255 for outgoing IPv4 unicast packets MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 1) We SHOULD do this according to the RFC 6762 (Section 11, "Source Address Check"). 2) We already do it for IPv6 unicast and both multicast interfaces 3) When receiving IPv4 packet we ignore it if TTL doesn't equal 255 In other words this is a requirement for working unicast communication between 2 umdns instances (which doesn't seem to work yet though). Signed-off-by: Rafał Miłecki Acked-by: John Crispin --- interface.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/interface.c b/interface.c index 587b188..76820c7 100644 --- a/interface.c +++ b/interface.c @@ -389,6 +389,7 @@ static void reconnect_socket4(struct uloop_timeout *timeout) { struct interface *iface = container_of(timeout, struct interface, reconnect); + int ttl = 255; int yes = 1; iface->fd.fd = usock(USOCK_UDP | USOCK_SERVER | USOCK_NONBLOCK | USOCK_IPV4ONLY, @@ -404,6 +405,9 @@ reconnect_socket4(struct uloop_timeout *timeout) if (setsockopt(iface->fd.fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0) fprintf(stderr, "ioctl failed: SO_REUSEADDR\n"); + if (setsockopt(iface->fd.fd, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl)) < 0) + fprintf(stderr, "ioctl failed: IP_TTL\n"); + if (setsockopt(iface->fd.fd, IPPROTO_IP, IP_RECVTTL, &yes, sizeof(yes)) < 0) fprintf(stderr, "ioctl failed: IP_RECVTTL\n"); -- 2.11.0