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
|
CLIENT_DIR = client
|
||||||
COMMIT = $$(git rev-parse --short HEAD)
|
COMMIT = $$(git rev-parse --short HEAD)
|
||||||
DIST_DIR = dist
|
DIST_DIR = dist
|
||||||
|
# TODO(a.garipov): Find out a way to make this work in GNU Make.
|
||||||
|
#
|
||||||
|
# GO = $${GO:-go}
|
||||||
|
#
|
||||||
GO = go
|
GO = go
|
||||||
GOPROXY = https://goproxy.cn|https://proxy.golang.org|direct
|
GOPROXY = https://goproxy.cn|https://proxy.golang.org|direct
|
||||||
GPG_KEY = devteam@adguard.com
|
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
|
# A quick check to make sure that all supported operating systems can be
|
||||||
# typechecked and built successfully.
|
# typechecked and built successfully.
|
||||||
go-os-check:
|
go-os-check:
|
||||||
env GOOS='darwin' go vet ./internal/...
|
env GOOS='darwin' $(GO) vet ./internal/...
|
||||||
env GOOS='freebsd' go vet ./internal/...
|
env GOOS='freebsd' $(GO) vet ./internal/...
|
||||||
env GOOS='linux' go vet ./internal/...
|
env GOOS='linux' $(GO) vet ./internal/...
|
||||||
env GOOS='windows' go vet ./internal/...
|
env GOOS='windows' $(GO) vet ./internal/...
|
||||||
|
|
||||||
openapi-lint: ; cd ./openapi/ && $(YARN) test
|
openapi-lint: ; cd ./openapi/ && $(YARN) test
|
||||||
openapi-show: ; cd ./openapi/ && $(YARN) start
|
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.
|
// Start will listen on port 67 and serve DHCP requests.
|
||||||
func (s *Server) Start() error {
|
func (s *Server) Start() (err error) {
|
||||||
err := s.srv4.Start()
|
err = s.srv4.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("DHCPv4: start: %s", err)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.srv6.Start()
|
err = s.srv6.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("DHCPv6: start: %s", err)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,12 @@ func (s *v4Server) WriteDiskConfig6(c *V6ServerConf) {
|
||||||
|
|
||||||
// ResetLeases - reset leases
|
// ResetLeases - reset leases
|
||||||
func (s *v4Server) ResetLeases(leases []*Lease) {
|
func (s *v4Server) ResetLeases(leases []*Lease) {
|
||||||
|
if !s.conf.Enabled {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
s.leasedOffsets = newBitSet()
|
||||||
|
s.leaseHosts = aghstrings.NewSet()
|
||||||
s.leases = nil
|
s.leases = nil
|
||||||
|
|
||||||
for _, l := range leases {
|
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.
|
// 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 {
|
if !s.conf.Enabled {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -834,14 +842,14 @@ func (s *v4Server) Start() error {
|
||||||
ifaceName := s.conf.InterfaceName
|
ifaceName := s.conf.InterfaceName
|
||||||
iface, err := net.InterfaceByName(ifaceName)
|
iface, err := net.InterfaceByName(ifaceName)
|
||||||
if err != nil {
|
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...")
|
log.Debug("dhcpv4: starting...")
|
||||||
|
|
||||||
dnsIPAddrs, err := ifaceDNSIPAddrs(iface, ipVersion4, defaultMaxAttempts, defaultBackoff)
|
dnsIPAddrs, err := ifaceDNSIPAddrs(iface, ipVersion4, defaultMaxAttempts, defaultBackoff)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("dhcpv4: interface %s: %w", ifaceName, err)
|
return fmt.Errorf("interface %s: %w", ifaceName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(dnsIPAddrs) == 0 {
|
if len(dnsIPAddrs) == 0 {
|
||||||
|
@ -863,8 +871,18 @@ func (s *v4Server) Start() error {
|
||||||
log.Info("dhcpv4: listening")
|
log.Info("dhcpv4: listening")
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
err = s.srv.Serve()
|
serr := s.srv.Serve()
|
||||||
log.Debug("dhcpv4: srv.Serve: %s", err)
|
// 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
|
// Signal to the clients containers in packages home and dnsforward that
|
||||||
|
|
|
@ -332,7 +332,10 @@ func run(args options) {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if Context.dhcpServer != nil {
|
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