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
|
dhcpClientPort = 68
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const dhcpServerPort = 67
|
||||||
|
|
||||||
// txType describes how a Packet should be sent on the wire.
|
// txType describes how a Packet should be sent on the wire.
|
||||||
type txType int
|
type txType int
|
||||||
|
|
||||||
// The various transmission strategies described in RFC 2131. "MUST",
|
// The various transmission strategies described in RFC 2131. "MUST",
|
||||||
// "MUST NOT", "SHOULD" and "MAY" are as specified in RFC 2119.
|
// "MUST NOT", "SHOULD" and "MAY" are as specified in RFC 2119.
|
||||||
const (
|
const (
|
||||||
// Packet MUST be broadcast.
|
// Packet MUST be broadcast from client side.
|
||||||
txBroadcast txType = iota
|
txClientBroadcast txType = iota
|
||||||
|
// Packet MUST be broadcast from server side.
|
||||||
|
txServerBroadcast
|
||||||
// Packet MUST be unicasted to port 67 of RelayAddr
|
// Packet MUST be unicasted to port 67 of RelayAddr
|
||||||
txRelayAddr
|
txRelayAddr
|
||||||
// Packet MUST be unicasted to port 68 of ClientAddr
|
// 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() {
|
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{
|
addr := net.UDPAddr{
|
||||||
IP: net.IPv4bcast,
|
IP: net.IPv4bcast,
|
||||||
Port: dhcpClientPort,
|
Port: dhcpClientPort,
|
||||||
@ -178,7 +188,7 @@ func (c *Conn) SendDHCP(pkt *Packet, intf *net.Interface) error {
|
|||||||
case txRelayAddr:
|
case txRelayAddr:
|
||||||
addr := net.UDPAddr{
|
addr := net.UDPAddr{
|
||||||
IP: pkt.RelayAddr,
|
IP: pkt.RelayAddr,
|
||||||
Port: 67,
|
Port: dhcpServerPort,
|
||||||
}
|
}
|
||||||
return c.conn.Send(b, &addr, 0)
|
return c.conn.Send(b, &addr, 0)
|
||||||
case txClientAddr:
|
case txClientAddr:
|
||||||
|
|||||||
@ -91,11 +91,13 @@ func (p *Packet) txType() txType {
|
|||||||
case p.RelayAddr != nil && p.RelayAddr.IsGlobalUnicast():
|
case p.RelayAddr != nil && p.RelayAddr.IsGlobalUnicast():
|
||||||
return txRelayAddr
|
return txRelayAddr
|
||||||
case p.Type == MsgNack:
|
case p.Type == MsgNack:
|
||||||
return txBroadcast
|
return txServerBroadcast
|
||||||
case p.ClientAddr != nil && (p.ClientAddr.IsGlobalUnicast() || p.ClientAddr.IsLoopback()):
|
case p.ClientAddr != nil && (p.ClientAddr.IsGlobalUnicast() || p.ClientAddr.IsLoopback()):
|
||||||
return txClientAddr
|
return txClientAddr
|
||||||
|
case p.Broadcast && p.Type == MsgDiscover:
|
||||||
|
return txClientBroadcast
|
||||||
case p.Broadcast:
|
case p.Broadcast:
|
||||||
return txBroadcast
|
return txServerBroadcast
|
||||||
default:
|
default:
|
||||||
return txHardwareAddr
|
return txHardwareAddr
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user