Pull request: dhcpd: fix dbload panic
Closes #2991. Squashed commit of the following: commit cd820a9a903d628aa5964f8f973edc7bb7993ae5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Apr 21 14:34:45 2021 +0300 dhcpd: fix err handling commit 775b834683f0edb5954b20fedb896e6af1fa843e Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Apr 21 14:21:41 2021 +0300 dhcpd: fix build for go1.15 commit 8441d6fffa72cc6890fad2df76559e21819786d6 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Apr 21 14:05:08 2021 +0300 dhcpd: fix dbload panic
This commit is contained in:
parent
2e4e1973d9
commit
aee09d29e9
12
Makefile
12
Makefile
|
@ -9,6 +9,10 @@ CLIENT_BETA_DIR = client2
|
|||
CLIENT_DIR = client
|
||||
COMMIT = $$(git rev-parse --short HEAD)
|
||||
DIST_DIR = dist
|
||||
# TODO(a.garipov): Find out a way to make this work in GNU Make.
|
||||
#
|
||||
# GO = $${GO:-go}
|
||||
#
|
||||
GO = go
|
||||
GOPROXY = https://goproxy.cn|https://proxy.golang.org|direct
|
||||
GPG_KEY = devteam@adguard.com
|
||||
|
@ -93,10 +97,10 @@ go-check: go-tools go-lint go-test
|
|||
# A quick check to make sure that all supported operating systems can be
|
||||
# typechecked and built successfully.
|
||||
go-os-check:
|
||||
env GOOS='darwin' go vet ./internal/...
|
||||
env GOOS='freebsd' go vet ./internal/...
|
||||
env GOOS='linux' go vet ./internal/...
|
||||
env GOOS='windows' go vet ./internal/...
|
||||
env GOOS='darwin' $(GO) vet ./internal/...
|
||||
env GOOS='freebsd' $(GO) vet ./internal/...
|
||||
env GOOS='linux' $(GO) vet ./internal/...
|
||||
env GOOS='windows' $(GO) vet ./internal/...
|
||||
|
||||
openapi-lint: ; cd ./openapi/ && $(YARN) test
|
||||
openapi-show: ; cd ./openapi/ && $(YARN) start
|
||||
|
|
|
@ -242,16 +242,14 @@ func (s *Server) WriteDiskConfig(c *ServerConfig) {
|
|||
}
|
||||
|
||||
// Start will listen on port 67 and serve DHCP requests.
|
||||
func (s *Server) Start() error {
|
||||
err := s.srv4.Start()
|
||||
func (s *Server) Start() (err error) {
|
||||
err = s.srv4.Start()
|
||||
if err != nil {
|
||||
log.Error("DHCPv4: start: %s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
err = s.srv6.Start()
|
||||
if err != nil {
|
||||
log.Error("DHCPv6: start: %s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -51,6 +51,12 @@ func (s *v4Server) WriteDiskConfig6(c *V6ServerConf) {
|
|||
|
||||
// ResetLeases - reset leases
|
||||
func (s *v4Server) ResetLeases(leases []*Lease) {
|
||||
if !s.conf.Enabled {
|
||||
return
|
||||
}
|
||||
|
||||
s.leasedOffsets = newBitSet()
|
||||
s.leaseHosts = aghstrings.NewSet()
|
||||
s.leases = nil
|
||||
|
||||
for _, l := range leases {
|
||||
|
@ -826,7 +832,9 @@ func (s *v4Server) packetHandler(conn net.PacketConn, peer net.Addr, req *dhcpv4
|
|||
}
|
||||
|
||||
// Start starts the IPv4 DHCP server.
|
||||
func (s *v4Server) Start() error {
|
||||
func (s *v4Server) Start() (err error) {
|
||||
defer agherr.Annotate("dhcpv4: %w", &err)
|
||||
|
||||
if !s.conf.Enabled {
|
||||
return nil
|
||||
}
|
||||
|
@ -834,14 +842,14 @@ func (s *v4Server) Start() error {
|
|||
ifaceName := s.conf.InterfaceName
|
||||
iface, err := net.InterfaceByName(ifaceName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("dhcpv4: finding interface %s by name: %w", ifaceName, err)
|
||||
return fmt.Errorf("finding interface %s by name: %w", ifaceName, err)
|
||||
}
|
||||
|
||||
log.Debug("dhcpv4: starting...")
|
||||
|
||||
dnsIPAddrs, err := ifaceDNSIPAddrs(iface, ipVersion4, defaultMaxAttempts, defaultBackoff)
|
||||
if err != nil {
|
||||
return fmt.Errorf("dhcpv4: interface %s: %w", ifaceName, err)
|
||||
return fmt.Errorf("interface %s: %w", ifaceName, err)
|
||||
}
|
||||
|
||||
if len(dnsIPAddrs) == 0 {
|
||||
|
@ -863,8 +871,18 @@ func (s *v4Server) Start() error {
|
|||
log.Info("dhcpv4: listening")
|
||||
|
||||
go func() {
|
||||
err = s.srv.Serve()
|
||||
log.Debug("dhcpv4: srv.Serve: %s", err)
|
||||
serr := s.srv.Serve()
|
||||
// TODO(a.garipov): Uncomment in Go 1.16.
|
||||
//
|
||||
// if errors.Is(serr, net.ErrClosed) {
|
||||
// log.Info("dhcpv4: server is closed")
|
||||
//
|
||||
// return
|
||||
// }
|
||||
|
||||
if serr != nil {
|
||||
log.Error("dhcpv4: srv.Serve: %s", serr)
|
||||
}
|
||||
}()
|
||||
|
||||
// Signal to the clients containers in packages home and dnsforward that
|
||||
|
|
|
@ -332,7 +332,10 @@ func run(args options) {
|
|||
}()
|
||||
|
||||
if Context.dhcpServer != nil {
|
||||
_ = Context.dhcpServer.Start()
|
||||
err = Context.dhcpServer.Start()
|
||||
if err != nil {
|
||||
log.Error("starting dhcp server: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue