mirror of
https://github.com/danderson/netboot.git
synced 2025-12-16 15:02:12 +01:00
Fix #87, add broadcast discover message support
This commit is contained in:
parent
a62f978630
commit
01f30467ac
@ -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:
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user