Skip to content

net: ponies: ListenBroadcastUDP(net string, ifi *Interface) (*UDPConn, error) #6935

@gopherbot

Description

@gopherbot

by krolaw:

In writing my DHCP library I have found:
l, err := net.ListenPacket("udp4", "192.168.1.250:67")
Listens on one interface but ignores broadcast packets coming to that interface.

So I end up using:
l, err := net.ListenPacket("udp4", ":67")
Listens on all interfaces and captures broadcast packets:

On a device with multiple interfaces this can be problematic.  The workaround so far has
been to use iptables to block dhcp client packets coming in on unwanted interfaces.

However, there is still the issue that any response packet doesn't go over the correct
interface.  When I try to open a new udp socket on the correct interface (using ip), 
and source port, it obviously doesn't work as the listener bound to that port.  The
workaround has been to open a new udp socket on a different port and use iptables to
SNAT the source port on the way through to 67.

Having a ListenBroadcastUDP function would also make writing client side DHCP practical.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions