github.com/Cloud-Foundations/Dominator@v0.3.4/hypervisor/dhcpd/api.go (about) 1 package dhcpd 2 3 import ( 4 "io" 5 "net" 6 "sync" 7 "time" 8 9 "github.com/Cloud-Foundations/Dominator/lib/log" 10 "github.com/Cloud-Foundations/Dominator/lib/net/util" 11 proto "github.com/Cloud-Foundations/Dominator/proto/hypervisor" 12 ) 13 14 type DhcpServer struct { 15 dynamicLeasesFile string 16 logger log.DebugLogger 17 cleanupTrigger chan<- struct{} 18 interfaceIPs map[string][]net.IP // Key: interface name. 19 myIPs []net.IP 20 networkBootImage []byte 21 requestInterface string 22 routeTable map[string]*util.RouteEntry // Key: interface name. 23 mutex sync.RWMutex // Protect everything below. 24 ackChannels map[string]chan struct{} // Key: IPaddr. 25 dynamicLeases map[string]*leaseType // Key: MACaddr. 26 interfaceSubnets map[string][]*subnetType // Key: interface name. 27 ipAddrToMacAddr map[string]string // Key: IPaddr, V: MACaddr. 28 packetWatchers map[<-chan proto.WatchDhcpResponse]chan<- proto.WatchDhcpResponse 29 requestChannels map[string]chan net.IP // Key: MACaddr. 30 staticLeases map[string]leaseType // Key: MACaddr. 31 subnets []*subnetType 32 } 33 34 type leaseType struct { 35 proto.Address 36 clientHostname string 37 expires time.Time 38 hostname string 39 doNetboot bool 40 subnet *subnetType 41 } 42 43 type subnetType struct { 44 amGateway bool 45 myIP net.IP 46 nextDynamicIP net.IP 47 proto.Subnet 48 } 49 50 func New(interfaceNames []string, dynamicLeasesFile string, 51 logger log.DebugLogger) (*DhcpServer, error) { 52 return newServer(interfaceNames, dynamicLeasesFile, logger) 53 } 54 55 func (s *DhcpServer) AddLease(address proto.Address, hostname string) error { 56 return s.addLease(address, false, hostname, nil) 57 } 58 59 func (s *DhcpServer) AddNetbootLease(address proto.Address, 60 hostname string, subnet *proto.Subnet) error { 61 return s.addLease(address, true, hostname, subnet) 62 } 63 64 func (s *DhcpServer) AddSubnet(subnet proto.Subnet) { 65 s.addSubnet(subnet) 66 } 67 68 func (s *DhcpServer) ClosePacketWatchChannel( 69 channel <-chan proto.WatchDhcpResponse) { 70 s.closePacketWatchChannel(channel) 71 } 72 73 func (s *DhcpServer) MakeAcknowledgmentChannel(ipAddr net.IP) <-chan struct{} { 74 return s.makeAcknowledgmentChannel(ipAddr) 75 } 76 77 func (s *DhcpServer) MakePacketWatchChannel() <-chan proto.WatchDhcpResponse { 78 return s.makePacketWatchChannel() 79 } 80 81 func (s *DhcpServer) MakeRequestChannel(macAddr string) <-chan net.IP { 82 return s.makeRequestChannel(macAddr) 83 } 84 85 func (s *DhcpServer) RemoveLease(ipAddr net.IP) { 86 s.removeLease(ipAddr) 87 } 88 89 func (s *DhcpServer) RemoveSubnet(subnetId string) { 90 s.removeSubnet(subnetId) 91 } 92 93 func (s *DhcpServer) SetNetworkBootImage(nbiName string) error { 94 s.networkBootImage = []byte(nbiName) 95 return nil 96 } 97 98 func (s *DhcpServer) WriteHtml(writer io.Writer) { 99 s.writeHtml(writer) 100 }