This commit is contained in:
Simon Zolin
2020-05-21 16:31:05 +03:00
parent 917f20fe1c
commit 8f9353782b
7 changed files with 164 additions and 324 deletions

View File

@@ -1,11 +1,9 @@
package dhcpd
import (
"fmt"
"net"
"net/http"
"path/filepath"
"strings"
"time"
"github.com/AdguardTeam/golibs/log"
@@ -58,18 +56,6 @@ const (
// Server - the current state of the DHCP server
type Server struct {
// conn *filterConn // listening UDP socket
// ipnet *net.IPNet // if interface name changes, this needs to be reset
// cond *sync.Cond // Synchronize worker thread with main thread
// mutex sync.Mutex // Mutex for 'cond'
// running bool // Set if the worker thread is running
// stopping bool // Set if the worker thread should be stopped
// leases
// leaseOptions dhcp4.Options // parsed from config GatewayIP and SubnetMask
srv4 *V4Server
srv6 *V6Server
@@ -79,16 +65,6 @@ type Server struct {
onLeaseChanged onLeaseChangedT
}
// Print information about the available network interfaces
func printInterfaces() {
ifaces, _ := net.Interfaces()
var buf strings.Builder
for i := range ifaces {
buf.WriteString(fmt.Sprintf("\"%s\", ", ifaces[i].Name))
}
log.Info("Available network interfaces: %s", buf.String())
}
// CheckConfig checks the configuration
func (s *Server) CheckConfig(config ServerConfig) error {
return nil
@@ -194,16 +170,15 @@ func (s *Server) Leases(flags int) []Lease {
return result
}
// AddStaticLease adds a static lease (thread-safe)
func (s *Server) AddStaticLease(lease Lease) error {
return s.srv4.AddStaticLease(lease)
}
// FindMACbyIP - find a MAC address by IP address in the currently active DHCP leases
func (s *Server) FindMACbyIP(ip net.IP) net.HardwareAddr {
if ip.To4() != nil {
return s.srv4.FindMACbyIP4(ip)
return s.srv4.FindMACbyIP(ip)
}
return s.srv6.FindMACbyIP6(ip)
}
// Reset internal state
func (s *Server) reset() {
s.srv4.Reset()
s.srv6.Reset()
return s.srv6.FindMACbyIP(ip)
}