diff --git a/dhcp4/conn.go b/dhcp4/conn.go index 134affc..661400a 100644 --- a/dhcp4/conn.go +++ b/dhcp4/conn.go @@ -29,14 +29,18 @@ var ( dhcpClientPort = 68 ) +const dhcpServerPort = 67 + // txType describes how a Packet should be sent on the wire. type txType int // The various transmission strategies described in RFC 2131. "MUST", // "MUST NOT", "SHOULD" and "MAY" are as specified in RFC 2119. const ( - // Packet MUST be broadcast. - txBroadcast txType = iota + // Packet MUST be broadcast from client side. + txClientBroadcast txType = iota + // Packet MUST be broadcast from server side. + txServerBroadcast // Packet MUST be unicasted to port 67 of RelayAddr txRelayAddr // Packet MUST be unicasted to port 68 of ClientAddr @@ -169,7 +173,13 @@ func (c *Conn) SendDHCP(pkt *Packet, intf *net.Interface) error { } switch pkt.txType() { - case txBroadcast, txHardwareAddr: + case txClientBroadcast: + addr := net.UDPAddr{ + IP: net.IPv4bcast, + Port: dhcpServerPort, + } + return c.conn.Send(b, &addr, intf.Index) + case txServerBroadcast, txHardwareAddr: addr := net.UDPAddr{ IP: net.IPv4bcast, Port: dhcpClientPort, @@ -178,7 +188,7 @@ func (c *Conn) SendDHCP(pkt *Packet, intf *net.Interface) error { case txRelayAddr: addr := net.UDPAddr{ IP: pkt.RelayAddr, - Port: 67, + Port: dhcpServerPort, } return c.conn.Send(b, &addr, 0) case txClientAddr: diff --git a/dhcp4/packet.go b/dhcp4/packet.go index 114874b..2c01978 100644 --- a/dhcp4/packet.go +++ b/dhcp4/packet.go @@ -91,11 +91,13 @@ func (p *Packet) txType() txType { case p.RelayAddr != nil && p.RelayAddr.IsGlobalUnicast(): return txRelayAddr case p.Type == MsgNack: - return txBroadcast + return txServerBroadcast case p.ClientAddr != nil && (p.ClientAddr.IsGlobalUnicast() || p.ClientAddr.IsLoopback()): return txClientAddr + case p.Broadcast && p.Type == MsgDiscover: + return txClientBroadcast case p.Broadcast: - return txBroadcast + return txServerBroadcast default: return txHardwareAddr }