dhcp: daemon dhcp client timeout is configurable
Fixes #470 Signed-off-by: toby lorne <toby@toby.codes>
This commit is contained in:
@ -42,11 +42,13 @@ type DHCP struct {
|
||||
mux sync.Mutex
|
||||
leases map[string]*DHCPLease
|
||||
hostNetnsPrefix string
|
||||
clientTimeout time.Duration
|
||||
}
|
||||
|
||||
func newDHCP() *DHCP {
|
||||
func newDHCP(clientTimeout time.Duration) *DHCP {
|
||||
return &DHCP{
|
||||
leases: make(map[string]*DHCPLease),
|
||||
leases: make(map[string]*DHCPLease),
|
||||
clientTimeout: clientTimeout,
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,7 +66,7 @@ func (d *DHCP) Allocate(args *skel.CmdArgs, result *current.Result) error {
|
||||
|
||||
clientID := generateClientID(args.ContainerID, conf.Name, args.IfName)
|
||||
hostNetns := d.hostNetnsPrefix + args.Netns
|
||||
l, err := AcquireLease(clientID, hostNetns, args.IfName, 5*time.Second)
|
||||
l, err := AcquireLease(clientID, hostNetns, args.IfName, d.clientTimeout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -157,7 +159,10 @@ func getListener(socketPath string) (net.Listener, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func runDaemon(pidfilePath string, hostPrefix string, socketPath string) error {
|
||||
func runDaemon(
|
||||
pidfilePath, hostPrefix, socketPath string,
|
||||
dhcpClientTimeout time.Duration,
|
||||
) error {
|
||||
// since other goroutines (on separate threads) will change namespaces,
|
||||
// ensure the RPC server does not get scheduled onto those
|
||||
runtime.LockOSThread()
|
||||
@ -177,7 +182,7 @@ func runDaemon(pidfilePath string, hostPrefix string, socketPath string) error {
|
||||
return fmt.Errorf("Error getting listener: %v", err)
|
||||
}
|
||||
|
||||
dhcp := newDHCP()
|
||||
dhcp := newDHCP(dhcpClientTimeout)
|
||||
dhcp.hostNetnsPrefix = hostPrefix
|
||||
rpc.Register(dhcp)
|
||||
rpc.HandleHTTP()
|
||||
|
Reference in New Issue
Block a user