Add client eviction feature
- Add EvictClient method to DHCP Server - Add /api/dhcp/leases/evict endpoint to force client IP release - Add 'Evict' button in Web UI for online clients - Update table layout to include Action column - Evicted client will be forced to get a new IP on next DHCP request
This commit is contained in:
@@ -700,3 +700,26 @@ func newBroadcastUDPConn(host string, port int) (*net.UDPConn, error) {
|
||||
|
||||
return udpConn, nil
|
||||
}
|
||||
|
||||
// EvictClient removes a client's lease, forcing them to get a new IP
|
||||
func (s *Server) EvictClient(mac string) error {
|
||||
s.leaseMutex.Lock()
|
||||
defer s.leaseMutex.Unlock()
|
||||
|
||||
lease, exists := s.leases[mac]
|
||||
if !exists {
|
||||
return fmt.Errorf("lease not found for MAC %s", mac)
|
||||
}
|
||||
|
||||
// Remove from in-memory lease map
|
||||
delete(s.leases, mac)
|
||||
delete(s.usedIPs, lease.IP)
|
||||
|
||||
// Delete from database
|
||||
if err := s.db.Where("mac = ?", mac).Delete(&db.DHCPLease{}).Error; err != nil {
|
||||
return fmt.Errorf("failed to delete lease from database: %v", err)
|
||||
}
|
||||
|
||||
log.Printf("DHCP: Evicted client %s (%s)", mac, lease.IP)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user