Added docs for AddressPool and BootConfiguration interfaces and their implementations

This commit is contained in:
Dmitri Dolguikh 2017-11-02 12:23:08 -07:00 committed by Dave Anderson
parent aa977487cd
commit 5d5adcf2b9
3 changed files with 14 additions and 10 deletions

View File

@ -5,6 +5,7 @@ import (
"time" "time"
) )
// Associates an ip address with an individual network interface of a client
type IdentityAssociation struct { type IdentityAssociation struct {
IPAddress net.IP IPAddress net.IP
ClientID []byte ClientID []byte
@ -12,6 +13,7 @@ type IdentityAssociation struct {
CreatedAt time.Time CreatedAt time.Time
} }
// Keeps track of assigned and available ip address in an address pool
type AddressPool interface { type AddressPool interface {
ReserveAddresses(clientID []byte, interfaceIds [][]byte) ([]*IdentityAssociation, error) ReserveAddresses(clientID []byte, interfaceIds [][]byte) ([]*IdentityAssociation, error)
ReleaseAddresses(clientID []byte, interfaceIds [][]byte) ReleaseAddresses(clientID []byte, interfaceIds [][]byte)

View File

@ -10,12 +10,14 @@ import (
"net" "net"
) )
// BootConfiguration implementation provides values for dhcp options served to dhcp clients
type BootConfiguration interface { type BootConfiguration interface {
GetBootURL(id []byte, clientArchType uint16) ([]byte, error) GetBootURL(id []byte, clientArchType uint16) ([]byte, error)
GetPreference() []byte GetPreference() []byte
GetRecursiveDNS() []net.IP GetRecursiveDNS() []net.IP
} }
// StaticBootConfiguration provides values for dhcp options that remain unchanged until restart
type StaticBootConfiguration struct { type StaticBootConfiguration struct {
HTTPBootURL []byte HTTPBootURL []byte
IPxeBootURL []byte IPxeBootURL []byte
@ -24,6 +26,7 @@ type StaticBootConfiguration struct {
UsePreference bool UsePreference bool
} }
// MakeStaticBootConfiguration creates a new StaticBootConfiguration with provided values
func MakeStaticBootConfiguration(httpBootURL, ipxeBootURL string, preference uint8, usePreference bool, func MakeStaticBootConfiguration(httpBootURL, ipxeBootURL string, preference uint8, usePreference bool,
dnsServerAddresses []net.IP) *StaticBootConfiguration { dnsServerAddresses []net.IP) *StaticBootConfiguration {
ret := &StaticBootConfiguration{HTTPBootURL: []byte(httpBootURL), IPxeBootURL: []byte(ipxeBootURL), UsePreference: usePreference} ret := &StaticBootConfiguration{HTTPBootURL: []byte(httpBootURL), IPxeBootURL: []byte(ipxeBootURL), UsePreference: usePreference}
@ -35,6 +38,7 @@ func MakeStaticBootConfiguration(httpBootURL, ipxeBootURL string, preference uin
return ret return ret
} }
// GetBootURL returns Boot File URL, see RFC 5970
func (bc *StaticBootConfiguration) GetBootURL(id []byte, clientArchType uint16) ([]byte, error) { func (bc *StaticBootConfiguration) GetBootURL(id []byte, clientArchType uint16) ([]byte, error) {
if 0x10 == clientArchType { if 0x10 == clientArchType {
return bc.HTTPBootURL, nil return bc.HTTPBootURL, nil
@ -42,14 +46,18 @@ func (bc *StaticBootConfiguration) GetBootURL(id []byte, clientArchType uint16)
return bc.IPxeBootURL, nil return bc.IPxeBootURL, nil
} }
// GetPreference returns server's Preference, see RFC 3315
func (bc *StaticBootConfiguration) GetPreference() []byte { func (bc *StaticBootConfiguration) GetPreference() []byte {
return bc.Preference return bc.Preference
} }
// GetRecursiveDNS returns list of addresses of recursive DNS servers, see RFC 3646
func (bc *StaticBootConfiguration) GetRecursiveDNS() []net.IP { func (bc *StaticBootConfiguration) GetRecursiveDNS() []net.IP {
return bc.RecursiveDNS return bc.RecursiveDNS
} }
// APIBootConfiguration provides an interface to retrieve Boot File URL from an external server based on
// client ID and architecture type
type APIBootConfiguration struct { type APIBootConfiguration struct {
Client *http.Client Client *http.Client
URLPrefix string URLPrefix string
@ -58,6 +66,7 @@ type APIBootConfiguration struct {
UsePreference bool UsePreference bool
} }
// MakeApiBootConfiguration creates a new APIBootConfiguration initialized with provided values
func MakeApiBootConfiguration(url string, timeout time.Duration, preference uint8, usePreference bool, func MakeApiBootConfiguration(url string, timeout time.Duration, preference uint8, usePreference bool,
dnsServerAddresses []net.IP) *APIBootConfiguration { dnsServerAddresses []net.IP) *APIBootConfiguration {
if !strings.HasSuffix(url, "/") { if !strings.HasSuffix(url, "/") {
@ -77,6 +86,7 @@ func MakeApiBootConfiguration(url string, timeout time.Duration, preference uint
return ret return ret
} }
// GetBootURL returns Boot File URL, see RFC 5970
func (bc *APIBootConfiguration) GetBootURL(id []byte, clientArchType uint16) ([]byte, error) { func (bc *APIBootConfiguration) GetBootURL(id []byte, clientArchType uint16) ([]byte, error) {
reqURL := fmt.Sprintf("%s/boot/%x/%d", bc.URLPrefix, id, clientArchType) reqURL := fmt.Sprintf("%s/boot/%x/%d", bc.URLPrefix, id, clientArchType)
resp, err := bc.Client.Get(reqURL) resp, err := bc.Client.Get(reqURL)
@ -111,10 +121,12 @@ func (bc *APIBootConfiguration) makeURLAbsolute(urlStr string) (string, error) {
return u.String(), nil return u.String(), nil
} }
// GetPreference returns server's Preference, see RFC 3315
func (bc *APIBootConfiguration) GetPreference() []byte { func (bc *APIBootConfiguration) GetPreference() []byte {
return bc.Preference return bc.Preference
} }
// GetRecursiveDNS returns list of addresses of recursive DNS servers, see RFC 3646
func (bc *APIBootConfiguration) GetRecursiveDNS() []net.IP { func (bc *APIBootConfiguration) GetRecursiveDNS() []net.IP {
return bc.RecursiveDNS return bc.RecursiveDNS
} }

View File

@ -1,21 +1,11 @@
package dhcp6 package dhcp6
import ( import (
"io"
"net" "net"
"time"
"golang.org/x/net/ipv6" "golang.org/x/net/ipv6"
"fmt" "fmt"
) )
type conn interface {
io.Closer
Recv([]byte) (b []byte, addr *net.UDPAddr, ifidx int, err error)
Send(b []byte, addr *net.UDPAddr, ifidx int) error
SetReadDeadline(t time.Time) error
SetWriteDeadline(t time.Time) error
}
type Conn struct { type Conn struct {
conn *ipv6.PacketConn conn *ipv6.PacketConn
group net.IP group net.IP