RE: Do UDP broadcasts work in FreeBSD?
> why 255.255.255.255 not your net broadcast address? Because the systems we are using do not have IPs assigned and you to know your subnet before you can use subnet broadcasting. We're developing our own DHCP-like service to distribute IPs to all of the systems, and we need limited broadcast to 255.255.255.255 to do this. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
RE: Do UDP broadcasts work in FreeBSD?
>Did you enable SO_BROADCAST and IP_ONESBCAST on the socket? I remember needing >this on FreeBSD but not on Linux. Yes we did, but... >I know UDP broadcasting works fine, but is >somewhat more involved: > >addr.sin_family = AF_INET; >addr.sin_addr.s_addr = inet_addr("130.89.191.255"); >addr.sin_port = htons(UDP_PORT_ET); You are using a subnet broadcast here. We are dealing with systems that do not have IPs assigned, and as a result we have to send our broadcasts to 255.255.255.255. This works fine on other operating systems but for some reason the implementation is different on FreeBSD. It appears that the only way this kind of broadcast can be sent on FreeBSD is using raw sockets. This is how the FreeBSD DHCP client/server is written, so we're taking that approach as well... ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: Do UDP broadcasts work in FreeBSD?
On Tuesday 06 January 2009 17:49:49 Peter Steele wrote: > Our efforts so far indicate the answer is no, which baffles us. We want > to send a limited broadcast to 255.255.255.255 but the message never > arrives. The same code works fine under Linux. Is there a trick for > doing this kind of thing under FreeBSD? Did you enable SO_BROADCAST and IP_ONESBCAST on the socket? I remember needing this on FreeBSD but not on Linux. I know UDP broadcasting works fine, but is somewhat more involved: addr.sin_family = AF_INET; addr.sin_addr.s_addr = inet_addr("130.89.191.255"); addr.sin_port = htons(UDP_PORT_ET); optval = 1; if(setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &optval, sizeof optval) == -1) err(1, "setsockopt"); optval = 1; if(setsockopt(sock, IPPROTO_IP, IP_ONESBCAST, &optval, sizeof optval) == -1) err(1, "setsockopt"); const char data[] = "report"; if(sendto(sock, data, sizeof data, 0, (struct sockaddr*)&addr, addrlen) == -1) warn("sendto"); This code will send a packet with destination address 255.255.255.255, on the interface with broadcast address 130.89.191.255. netintro(4) talks about how to discover these addresses. SO_ONESBCAST is documented in ip(4), SO_BROADCAST in getsockopt(4). -- Pieter de Goeje ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
RE: Do UDP broadcasts work in FreeBSD?
> I've already looked at the ISC DHCP source code. They use raw sockets to > send their broadcasts, which seems to us to be a convoluted way of > sending a simple broadcast. I've seen examples of DHCP client/server > code written in Java using standard UDP. Unfortunately, our own system > is already largely implemented in Java/Python, so we'll need to provide > a JNI interface to support raw sockets. Alternatively we may patch the > kernel to fix the bug at its source. Another option we're considering is to use the firewall to detect broadcasts and rewrite the MAC addresses in the outgoing packets. In looking at tcpdump output of broadcasts, the IP address is set to 255.255.255.255 and the MAC address is set to the MAC address of the gateway. On Linux boxes the MAC address is ff:ff:ff:ff:ff:ff, and that's the only significant difference in the packet. We thought we might be able to come up with a firewall rule to detect broadcasts and change the MAC address to the same as what Linux uses. I'm still in the process of researching this, but if someone can tell me this is impossible, I'll move on. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
RE: Do UDP broadcasts work in FreeBSD?
> What you're trying to do with sending to the all-ones broadcast > address is known as sending a "link-local" packet. On some systems, > sending a UDP packet to 255.255.255.255 will actually cause a packet > with that destination to be generated from all network interfaces > which are "UP". That seems to be the behavior you are expecting. Yes it is. This is the behavior I've seen on every system I've used for 20+ years, except for FreeBSD. > On FreeBSD, IIRC, the behavior you get is that it will send to the > local network broadcast address for each interface [1] using the > network broadcast address (ie, if an interface is configured for > 10.1.1.1 with /16 netmask, the packet will have destination > 10.1.255.255). If an interface is UP but not configured with an IP > +netmask, I don't believe a packet will be sent. (In fact, it might > depend upon whether the BROADCAST flag is enabled, which gets set when > an inet-enabled interface is setup with a netmask...) In our case our systems have no IP identity of any kind, and we don't want to have to rely on whether or not our customers have a DHCP server available. So we've come up with our own "light" DHCP. It works fine for Linux and Windows. Not FreeBSD though. > Arguably, this is a bug in FreeBSD I don't think there is any doubt about that. And from what I understand it even used to work under FreeBSD a few years ago. > but you can work around it by > using the BPF interface to send the traffic directly rather than using > the network stack via socket()+send()/write(). I believe the ISC DHCP > server software provides examples of how to do this, as dhclient is > commonly used to send DHCP requests to the all-ones broadcast addr, > without needing an interface being configured with an IP I've already looked at the ISC DHCP source code. They use raw sockets to send their broadcasts, which seems to us to be a convoluted way of sending a simple broadcast. I've seen examples of DHCP client/server code written in Java using standard UDP. Unfortunately, our own system is already largely implemented in Java/Python, so we'll need to provide a JNI interface to support raw sockets. Alternatively we may patch the kernel to fix the bug at its source. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: Do UDP broadcasts work in FreeBSD?
On Jan 6, 2009, at 8:49 AM, Peter Steele wrote: Our efforts so far indicate the answer is no, which baffles us. We want to send a limited broadcast to 255.255.255.255 but the message never arrives. The same code works fine under Linux. Is there a trick for doing this kind of thing under FreeBSD? What you're trying to do with sending to the all-ones broadcast address is known as sending a "link-local" packet. On some systems, sending a UDP packet to 255.255.255.255 will actually cause a packet with that destination to be generated from all network interfaces which are "UP". That seems to be the behavior you are expecting. On FreeBSD, IIRC, the behavior you get is that it will send to the local network broadcast address for each interface [1] using the network broadcast address (ie, if an interface is configured for 10.1.1.1 with /16 netmask, the packet will have destination 10.1.255.255). If an interface is UP but not configured with an IP +netmask, I don't believe a packet will be sent. (In fact, it might depend upon whether the BROADCAST flag is enabled, which gets set when an inet-enabled interface is setup with a netmask...) Arguably, this is a bug in FreeBSD, but you can work around it by using the BPF interface to send the traffic directly rather than using the network stack via socket()+send()/write(). I believe the ISC DHCP server software provides examples of how to do this, as dhclient is commonly used to send DHCP requests to the all-ones broadcast addr, without needing an interface being configured with an IP -- -Chuck [1]: And I could be mis-remembering that part; it might do a routing table lookup and use only the interface which matches the destination IP, which is probably the default route. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: Do UDP broadcasts work in FreeBSD?
why 255.255.255.255 not your net broadcast address? On Tue, 6 Jan 2009, Peter Steele wrote: Our efforts so far indicate the answer is no, which baffles us. We want to send a limited broadcast to 255.255.255.255 but the message never arrives. The same code works fine under Linux. Is there a trick for doing this kind of thing under FreeBSD? ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org" ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"