This commit is contained in:
Simon Zolin 2020-04-30 13:04:21 +03:00
parent 2ec69bc6ed
commit c8db736745
2 changed files with 23 additions and 7 deletions

View file

@ -47,7 +47,7 @@ type ServerConfig struct {
// 0: disable // 0: disable
ICMPTimeout uint32 `json:"icmp_timeout_msec" yaml:"icmp_timeout_msec"` ICMPTimeout uint32 `json:"icmp_timeout_msec" yaml:"icmp_timeout_msec"`
Conf6 V6ServerConf `yaml:"dhcpv6"` Conf6 V6ServerConf `json:"-" yaml:"dhcpv6"`
WorkDir string `json:"-" yaml:"-"` WorkDir string `json:"-" yaml:"-"`
DBFilePath string `json:"-" yaml:"-"` // path to DB file DBFilePath string `json:"-" yaml:"-"` // path to DB file
@ -133,8 +133,10 @@ func Create(config ServerConfig) *Server {
s.registerHandlers() s.registerHandlers()
} }
s.srv6 = v6Create(config.Conf6) var err error
s.srv6, err = v6Create(config.Conf6)
if s.srv6 == nil { if s.srv6 == nil {
log.Error("%s", err)
return nil return nil
} }
@ -279,6 +281,8 @@ func (s *Server) Start() error {
// Stop closes the listening UDP socket // Stop closes the listening UDP socket
func (s *Server) Stop() error { func (s *Server) Stop() error {
s.srv6.Stop()
if s.conn == nil { if s.conn == nil {
// nothing to do, return silently // nothing to do, return silently
return nil return nil

View file

@ -314,18 +314,30 @@ func (s *V6Server) Start(iface net.Interface) error {
return nil return nil
} }
func v6Create(conf V6ServerConf) *V6Server { // Stop - stop server
func (s *V6Server) Stop() {
if s.srv == nil {
return
}
err := s.srv.Close()
if err != nil {
log.Error("DHCPv6: srv.Close: %s", err)
}
// now server.Serve() will return
}
func v6Create(conf V6ServerConf) (*V6Server, error) {
s := &V6Server{} s := &V6Server{}
s.conf = conf s.conf = conf
if !conf.Enabled { if !conf.Enabled {
return s return s, nil
} }
s.conf.ipStart = net.ParseIP(conf.RangeStart) s.conf.ipStart = net.ParseIP(conf.RangeStart)
if s.conf.ipStart == nil { if s.conf.ipStart == nil {
log.Error("DHCPv6: invalid range-start IP: %s", conf.RangeStart) return nil, fmt.Errorf("DHCPv6: invalid range-start IP: %s", conf.RangeStart)
return nil
} }
if conf.LeaseDuration == 0 { if conf.LeaseDuration == 0 {
@ -335,5 +347,5 @@ func v6Create(conf V6ServerConf) *V6Server {
s.conf.leaseTime = time.Second * time.Duration(conf.LeaseDuration) s.conf.leaseTime = time.Second * time.Duration(conf.LeaseDuration)
} }
return s return s, nil
} }