mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-10-30 18:23:35 +08:00
Merge pull request #13209 from swordqiu/feature/qj-support-dhcp-option-82
feature: support dhcp relay information option 82
This commit is contained in:
@@ -88,6 +88,12 @@ func (h *DHCPHandler) ServeDHCP(pkt dhcp.Packet, _ *net.UDPAddr, _ *net.Interfac
|
||||
if conf == nil {
|
||||
return nil, nil, fmt.Errorf("Empty packet config")
|
||||
}
|
||||
// handle Option 82 relay information
|
||||
// https://datatracker.ietf.org/doc/html/rfc3046
|
||||
if relayInfo := pkt.GetOptionValue(dhcp.OptionRelayAgentInformation); relayInfo != nil {
|
||||
// return relay information transparently
|
||||
conf.RelayInfo = relayInfo
|
||||
}
|
||||
pkg, err := dhcp.MakeReplyPacket(pkt, conf)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, "dhcp.MakeReplyPacket")
|
||||
|
||||
@@ -151,6 +151,10 @@ func (s *SGuestDHCPServer) getGuestConfig(guestDesc, guestNic jsonutils.JSONObje
|
||||
}
|
||||
}
|
||||
|
||||
if nicdesc.Mtu > 0 {
|
||||
conf.MTU = uint16(nicdesc.Mtu)
|
||||
}
|
||||
|
||||
conf.OsName, _ = guestDesc.GetString("os_name")
|
||||
conf.LeaseTime = time.Duration(options.HostOptions.DhcpLeaseTime) * time.Second
|
||||
conf.RenewalTime = time.Duration(options.HostOptions.DhcpRenewalTime) * time.Second
|
||||
|
||||
@@ -47,6 +47,10 @@ type ResponseConfig struct {
|
||||
DNSServers []net.IP // OptDNSServers
|
||||
Routes [][]string // TODO: 249 for windows, 121 for linux
|
||||
NTPServers []net.IP // OptNTPServers 42
|
||||
MTU uint16 // OptMTU 26
|
||||
|
||||
// Relay Info https://datatracker.ietf.org/doc/html/rfc3046
|
||||
RelayInfo []byte
|
||||
|
||||
// TFTP config
|
||||
BootServer string
|
||||
@@ -62,6 +66,12 @@ func (conf ResponseConfig) GetHostname() string {
|
||||
return hostname
|
||||
}
|
||||
|
||||
func GetOptUint16(val uint16) []byte {
|
||||
opts := []byte{0, 0}
|
||||
binary.BigEndian.PutUint16(opts, val)
|
||||
return opts
|
||||
}
|
||||
|
||||
func GetOptIP(ip net.IP) []byte {
|
||||
return []byte(ip.To4())
|
||||
}
|
||||
@@ -154,6 +164,12 @@ func makeDHCPReplyPacket(req Packet, conf *ResponseConfig, msgType MessageType)
|
||||
if len(conf.NTPServers) > 0 {
|
||||
opts = append(opts, Option{OptionNetworkTimeProtocolServers, GetOptIPs(conf.NTPServers)})
|
||||
}
|
||||
if conf.MTU > 0 {
|
||||
opts = append(opts, Option{OptionInterfaceMTU, GetOptUint16(conf.MTU)})
|
||||
}
|
||||
if conf.RelayInfo != nil {
|
||||
opts = append(opts, Option{OptionRelayAgentInformation, conf.RelayInfo})
|
||||
}
|
||||
resp := ReplyPacket(req, msgType, conf.ServerIP, conf.ClientIP, conf.LeaseTime, opts)
|
||||
if conf.BootServer != "" {
|
||||
//resp.Options[OptOverload] = []byte{3}
|
||||
|
||||
Reference in New Issue
Block a user