diff --git a/pkg/baremetal/pxe/dhcp.go b/pkg/baremetal/pxe/dhcp.go index 33d0b13525..4c48313ba3 100644 --- a/pkg/baremetal/pxe/dhcp.go +++ b/pkg/baremetal/pxe/dhcp.go @@ -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") diff --git a/pkg/hostman/hostinfo/hostdhcp/dhcpserver.go b/pkg/hostman/hostinfo/hostdhcp/dhcpserver.go index 80650ddebb..ab4fffc063 100644 --- a/pkg/hostman/hostinfo/hostdhcp/dhcpserver.go +++ b/pkg/hostman/hostinfo/hostdhcp/dhcpserver.go @@ -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 diff --git a/pkg/util/dhcp/helpers.go b/pkg/util/dhcp/helpers.go index 9d419909e6..02324ebdcb 100644 --- a/pkg/util/dhcp/helpers.go +++ b/pkg/util/dhcp/helpers.go @@ -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}