Hi.
I'm receiving UDP data (which is normally broadcast) which has to be delivered to multiple sockets.
By using SO_REUSEADDR on each socket, every socket gets a copy of each incoming broadcast packet.
I'd like to replace the broadcast messages with unicast (multicasting isn't an option), but then only one of the sockets in the computer receives the packets.
I thought of using an IP Filter NKE to replace the destination address of the incoming messages with the broadcast address, so that any UDP data for the port goes to all the sockets in the computer.
This seems to work for packets from-to 127.0.0.1, but not for "real" data from the network.
In my ipf_input routine, after checking for UDP and port number (ih is an ip*):
printf("Packet
from x to x\n",
htonl(ih->ip_src.s_addr),
htonl(ih->ip_dst.s_addr));
// pass through if already a broadcast packet
if(ih->ip_dst.s_addr
== -1) return 0;
// make the destination address broadcast
ih->ip_dst.s_addr
= -1;
ih->ip_sum
= 0;
mbuf_inet_cksum(*data,
0, 0, ih->ip_hl << 2, &ih->ip_sum);
ipf_inject_input(*data,
NULL);
return
EJUSTRETURN;
From 127.0.0.1->127.0.0.1, I see duplicate copies of each packet arrive at all my sockets. This
works even if I don't recalculate the checksum!
From other sources, the packets just disappear - they don't get delivered anywhere.
I've tried with and without the ipf_inject_input()
and EJUSTRETURN (returning 0), but the behaviour is just the same (and 127.0.0.1 still works!).
The printf() shows each packet being processed twice, once with the original destination, and again with the broadcast destination, but the data doesn't get to the sockets.
Clearly I'm doing (or not doing) something stupid.
Can anyone help please?
Mark
|