Pull request: all: imp ipset, add tests

Closes #2611.

Squashed commit of the following:

commit f72577757e5cd0299863ccc01780ad9307adc6ea
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Fri Jun 18 17:32:41 2021 +0300

    dnsforward: imp err msgs

commit ed8d6dd4b5d7171dfbd57742b53bf96be6cbec29
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Fri Jun 18 17:00:49 2021 +0300

    all: imp ipset code

commit 887b3268bae496f4ad616b277f5e28d3ee24a370
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Fri Jun 18 16:09:08 2021 +0300

    dnsforward: imp ipset, add tests
This commit is contained in:
Ainar Garipov
2021-06-18 17:55:01 +03:00
parent dbe8b92dfc
commit 3ee0369cb9
11 changed files with 837 additions and 451 deletions

View File

@@ -5,7 +5,6 @@ import (
"fmt"
"net"
"net/http"
"os"
"runtime"
"strings"
"sync"
@@ -203,7 +202,7 @@ func (s *Server) Close() {
s.queryLog = nil
s.dnsProxy = nil
if err := s.ipset.Close(); err != nil {
if err := s.ipset.close(); err != nil {
log.Error("closing ipset: %s", err)
}
}
@@ -451,26 +450,15 @@ func (s *Server) Prepare(config *ServerConfig) error {
// --
s.initDefaultSettings()
// Initialize IPSET configuration
// Initialize ipset configuration
// --
err := s.ipset.init(s.conf.IPSETList)
err := s.ipset.init(s.conf.IpsetList)
if err != nil {
if !errors.Is(err, os.ErrInvalid) && !errors.Is(err, os.ErrPermission) {
return fmt.Errorf("cannot initialize ipset: %w", err)
}
// ipset cannot currently be initialized if the server was
// installed from Snap or when the user or the binary doesn't
// have the required permissions, or when the kernel doesn't
// support netfilter.
//
// Log and go on.
//
// TODO(a.garipov): The Snap problem can probably be solved if
// we add the netlink-connector interface plug.
log.Info("warning: cannot initialize ipset: %s", err)
return err
}
log.Debug("inited ipset")
// Prepare DNS servers settings
// --
err = s.prepareUpstreamSettings()