Maint: firewall and routing use logger.Debug
- Remove SetVerbose and SetDebug from both - Log routing teardown - Default logging level set to info
This commit is contained in:
@@ -15,13 +15,11 @@ import (
|
||||
|
||||
// Configurator allows to change firewall rules and modify network routes.
|
||||
type Configurator interface {
|
||||
Version(ctx context.Context) (string, error)
|
||||
SetEnabled(ctx context.Context, enabled bool) (err error)
|
||||
SetVPNConnection(ctx context.Context, connection models.OpenVPNConnection) (err error)
|
||||
SetAllowedPort(ctx context.Context, port uint16, intf string) (err error)
|
||||
SetOutboundSubnets(ctx context.Context, subnets []net.IPNet) (err error)
|
||||
RemoveAllowedPort(ctx context.Context, port uint16) (err error)
|
||||
SetDebug()
|
||||
// SetNetworkInformation is meant to be called only once
|
||||
SetNetworkInformation(defaultInterface string, defaultGateway net.IP,
|
||||
localNetworks []routing.LocalNetwork, localIP net.IP)
|
||||
@@ -33,7 +31,6 @@ type configurator struct { //nolint:maligned
|
||||
routing routing.Routing
|
||||
iptablesMutex sync.Mutex
|
||||
ip6tablesMutex sync.Mutex
|
||||
debug bool
|
||||
defaultInterface string
|
||||
defaultGateway net.IP
|
||||
localNetworks []routing.LocalNetwork
|
||||
@@ -65,10 +62,6 @@ func NewConfigurator(logger logging.Logger, routing routing.Routing) Configurato
|
||||
}
|
||||
}
|
||||
|
||||
func (c *configurator) SetDebug() {
|
||||
c.debug = true
|
||||
}
|
||||
|
||||
func (c *configurator) SetNetworkInformation(
|
||||
defaultInterface string, defaultGateway net.IP, localNetworks []routing.LocalNetwork, localIP net.IP) {
|
||||
c.networkInfoMutex.Lock()
|
||||
|
||||
@@ -38,9 +38,9 @@ func (c *configurator) runIP6tablesInstruction(ctx context.Context, instruction
|
||||
}
|
||||
c.ip6tablesMutex.Lock() // only one ip6tables command at once
|
||||
defer c.ip6tablesMutex.Unlock()
|
||||
if c.debug {
|
||||
fmt.Println("ip6tables " + instruction)
|
||||
}
|
||||
|
||||
c.logger.Debug("ip6tables " + instruction)
|
||||
|
||||
flags := strings.Fields(instruction)
|
||||
cmd := exec.CommandContext(ctx, "ip6tables", flags...)
|
||||
if output, err := c.commander.Run(cmd); err != nil {
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/golibs/command"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -46,9 +47,9 @@ func flipRule(rule string) string {
|
||||
}
|
||||
|
||||
// Version obtains the version of the installed iptables.
|
||||
func (c *configurator) Version(ctx context.Context) (string, error) {
|
||||
func Version(ctx context.Context, commander command.Commander) (string, error) {
|
||||
cmd := exec.CommandContext(ctx, "iptables", "--version")
|
||||
output, err := c.commander.Run(cmd)
|
||||
output, err := commander.Run(cmd)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -72,9 +73,9 @@ func (c *configurator) runIptablesInstructions(ctx context.Context, instructions
|
||||
func (c *configurator) runIptablesInstruction(ctx context.Context, instruction string) error {
|
||||
c.iptablesMutex.Lock() // only one iptables command at once
|
||||
defer c.iptablesMutex.Unlock()
|
||||
if c.debug {
|
||||
fmt.Printf("iptables %s\n", instruction)
|
||||
}
|
||||
|
||||
c.logger.Debug("iptables " + instruction)
|
||||
|
||||
flags := strings.Fields(instruction)
|
||||
cmd := exec.CommandContext(ctx, "iptables", flags...)
|
||||
if output, err := c.commander.Run(cmd); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user