Skip to content

Commit

Permalink
Fixing loops for mDNS packets when mDNS plugin is misconfigured
Browse files Browse the repository at this point in the history
If two mDNS plug-in enabled OLSR routers are attached to the same HNA network, then mDNS packets will loop back and forth between the two, also flooding the whole OLSR network. For the moment the temporary solution to this problem was to enable the plug-in on one router at a time on the same HNA. A real implemented here is  the following:

    usually mDNS packets have a TTL != 1, so:
    capture only mDNS packets with TTL != 1
    when decapsulating mDNS packets, set TTL = 1
    where TTL is the IP Time-to-live field or the IPv6 HopLimit field

 * Modified code to forward mdns packet from HNA into OLSRd network changing TTL/Hlim to 1
 * Now the mDns plugin discard all packet from HNA that have TTL/Hlim equals to 1
  • Loading branch information
Alessandro Gnagni authored and Saverio Proto committed May 30, 2012
1 parent 17d6e51 commit 5e26a83
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/mdns/src/mdns.c
Expand Up @@ -112,10 +112,12 @@ PacketReceivedFromOLSR(unsigned char *encapsulationUdpData, int len)
if ((encapsulationUdpData[0] & 0xf0) == 0x40) {
dest.sll_protocol = htons(ETH_P_IP);
stripped_len = ntohs(ipHeader->ip_len);
ipHeader->ip_ttl = (u_int8_t) 1; //setting up TTL to 1 to avoid mdns packets flood
}
if ((encapsulationUdpData[0] & 0xf0) == 0x60) {
dest.sll_protocol = htons(ETH_P_IPV6);
stripped_len = 40 + ntohs(ip6Header->ip6_plen); //IPv6 Header size (40) + payload_len
ip6Header->ip6_hops = (uint8_t) 1; //setting up Hop Limit to 1 to avoid mdns packets flood
}
// Sven-Ola: Don't know how to handle the "stripped_len is uninitialized" condition, maybe exit(1) is better...?
if (0 == stripped_len) return;
Expand All @@ -134,7 +136,7 @@ PacketReceivedFromOLSR(unsigned char *encapsulationUdpData, int len)
* seem to matter when the destination MAC address is set to all-ones
* in that case. */
memset(dest.sll_addr, 0xFF, IFHWADDRLEN);

nBytesWritten = sendto(walker->capturingSkfd, encapsulationUdpData, stripped_len, 0, (struct sockaddr *)&dest, sizeof(dest));
if (nBytesWritten != stripped_len) {
BmfPError("sendto() error forwarding unpacked encapsulated pkt on \"%s\"", walker->ifName);
Expand Down Expand Up @@ -359,6 +361,9 @@ BmfPacketCaptured(
if (destPort != 5353) {
return;
}
if(((u_int8_t) ipHeader->ip_ttl) <= ((u_int8_t) 1)) // Discard mdns packet with TTL limit 1 or less
return;

} //END IPV4

else if ((encapsulationUdpData[0] & 0xf0) == 0x60) { //IPv6
Expand All @@ -380,6 +385,9 @@ BmfPacketCaptured(
if (destPort != 5353) {
return;
}
if(((uint8_t) ipHeader6->ip6_hops) <= ((uint8_t) 1)) // Discard mdns packet with hop limit 1 or less
return;

} //END IPV6
else
return; //Is not IP packet
Expand Down

0 comments on commit 5e26a83

Please sign in to comment.