Fix config hot-reload for serverIP
- Add getServerIP() method to dynamically read Gateway from config - Update sendOffer, sendACK, sendNAK to use getServerIP() - This ensures gateway IP updates when config changes via web UI
This commit is contained in:
@@ -76,6 +76,12 @@ func (s *Server) getConfig() *config.DHCPConfig {
|
||||
return s.config
|
||||
}
|
||||
|
||||
// getServerIP returns the server IP for DHCP options
|
||||
func (s *Server) getServerIP() net.IP {
|
||||
cfg := s.getConfig()
|
||||
return net.ParseIP(cfg.Gateway).To4()
|
||||
}
|
||||
|
||||
func (s *Server) Start() error {
|
||||
if !s.config.Enabled {
|
||||
return nil
|
||||
@@ -383,7 +389,7 @@ func (s *Server) sendOffer(data []byte, clientMAC, offeredIP string, remoteAddr
|
||||
response = appendOption(response, OptionLeaseTime, leaseTime)
|
||||
|
||||
// Add server identifier
|
||||
response = appendOption(response, OptionServerIdentifier, []byte(s.serverIP.To4()))
|
||||
response = appendOption(response, OptionServerIdentifier, []byte(s.getServerIP().To4()))
|
||||
|
||||
// Add end option
|
||||
response = append(response, OptionEnd)
|
||||
@@ -412,7 +418,7 @@ func (s *Server) sendACK(data []byte, clientMAC, ip string, remoteAddr *net.UDPA
|
||||
binary.BigEndian.PutUint32(leaseTime, uint32(s.getConfig().LeaseTime))
|
||||
response = appendOption(response, OptionLeaseTime, leaseTime)
|
||||
|
||||
response = appendOption(response, OptionServerIdentifier, []byte(s.serverIP.To4()))
|
||||
response = appendOption(response, OptionServerIdentifier, []byte(s.getServerIP().To4()))
|
||||
response = append(response, OptionEnd)
|
||||
|
||||
targetAddr := s.getResponseAddr(data, remoteAddr)
|
||||
@@ -421,7 +427,7 @@ func (s *Server) sendACK(data []byte, clientMAC, ip string, remoteAddr *net.UDPA
|
||||
|
||||
func (s *Server) sendNAK(data []byte, remoteAddr *net.UDPAddr) {
|
||||
response := buildDHCPMessage(MsgNAK, data, "0.0.0.0", s.config)
|
||||
response = appendOption(response, OptionServerIdentifier, []byte(s.serverIP.To4()))
|
||||
response = appendOption(response, OptionServerIdentifier, []byte(s.getServerIP().To4()))
|
||||
response = append(response, OptionEnd)
|
||||
|
||||
// NAK must always be broadcast
|
||||
|
||||
Reference in New Issue
Block a user