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:
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
|
||||
"github.com/vishvananda/netlink"
|
||||
)
|
||||
@@ -18,12 +19,11 @@ var (
|
||||
|
||||
func (r *routing) addRouteVia(destination net.IPNet, gateway net.IP, iface string, table int) error {
|
||||
destinationStr := destination.String()
|
||||
if r.verbose {
|
||||
r.logger.Info("adding route for " + destinationStr)
|
||||
}
|
||||
if r.debug {
|
||||
fmt.Printf("ip route replace %s via %s dev %s table %d\n", destinationStr, gateway, iface, table)
|
||||
}
|
||||
r.logger.Info("adding route for " + destinationStr)
|
||||
r.logger.Debug("ip route replace " + destinationStr +
|
||||
" via " + gateway.String() +
|
||||
" dev " + iface +
|
||||
" table " + strconv.Itoa(table))
|
||||
|
||||
link, err := netlink.LinkByName(iface)
|
||||
if err != nil {
|
||||
@@ -44,12 +44,11 @@ func (r *routing) addRouteVia(destination net.IPNet, gateway net.IP, iface strin
|
||||
|
||||
func (r *routing) deleteRouteVia(destination net.IPNet, gateway net.IP, iface string, table int) (err error) {
|
||||
destinationStr := destination.String()
|
||||
if r.verbose {
|
||||
r.logger.Info("deleting route for " + destinationStr)
|
||||
}
|
||||
if r.debug {
|
||||
fmt.Printf("ip route delete %s via %s dev %s table %d\n", destinationStr, gateway, iface, table)
|
||||
}
|
||||
r.logger.Info("deleting route for " + destinationStr)
|
||||
r.logger.Debug("ip route delete " + destinationStr +
|
||||
" via " + gateway.String() +
|
||||
" dev " + iface +
|
||||
" table " + strconv.Itoa(table))
|
||||
|
||||
link, err := netlink.LinkByName(iface)
|
||||
if err != nil {
|
||||
@@ -69,10 +68,9 @@ func (r *routing) deleteRouteVia(destination net.IPNet, gateway net.IP, iface st
|
||||
}
|
||||
|
||||
func (r *routing) addIPRule(src net.IP, table, priority int) error {
|
||||
if r.debug {
|
||||
fmt.Printf("ip rule add from %s lookup %d pref %d\n",
|
||||
src, table, priority)
|
||||
}
|
||||
r.logger.Debug("ip rule add from " + src.String() +
|
||||
" lookup " + strconv.Itoa(table) +
|
||||
" pref " + strconv.Itoa(priority))
|
||||
|
||||
rule := netlink.NewRule()
|
||||
rule.Src = netlink.NewIPNet(src)
|
||||
@@ -100,10 +98,9 @@ func (r *routing) addIPRule(src net.IP, table, priority int) error {
|
||||
}
|
||||
|
||||
func (r *routing) deleteIPRule(src net.IP, table, priority int) error {
|
||||
if r.debug {
|
||||
fmt.Printf("ip rule del from %s lookup %d pref %d\n",
|
||||
src, table, priority)
|
||||
}
|
||||
r.logger.Debug("ip rule del from " + src.String() +
|
||||
" lookup " + strconv.Itoa(table) +
|
||||
" pref " + strconv.Itoa(priority))
|
||||
|
||||
rule := netlink.NewRule()
|
||||
rule.Src = netlink.NewIPNet(src)
|
||||
|
||||
@@ -49,10 +49,8 @@ func (r *routing) DefaultRoute() (defaultInterface string, defaultGateway net.IP
|
||||
}
|
||||
attributes := link.Attrs()
|
||||
defaultInterface = attributes.Name
|
||||
if r.verbose {
|
||||
r.logger.Info("default route found: interface " + defaultInterface +
|
||||
", gateway " + defaultGateway.String())
|
||||
}
|
||||
r.logger.Info("default route found: interface " + defaultInterface +
|
||||
", gateway " + defaultGateway.String())
|
||||
return defaultInterface, defaultGateway, nil
|
||||
}
|
||||
}
|
||||
@@ -105,9 +103,7 @@ func (r *routing) LocalSubnet() (defaultSubnet net.IPNet, err error) {
|
||||
continue
|
||||
}
|
||||
defaultSubnet = *route.Dst
|
||||
if r.verbose {
|
||||
r.logger.Info("local subnet found: " + defaultSubnet.String())
|
||||
}
|
||||
r.logger.Info("local subnet found: " + defaultSubnet.String())
|
||||
return defaultSubnet, nil
|
||||
}
|
||||
|
||||
@@ -128,9 +124,7 @@ func (r *routing) LocalNetworks() (localNetworks []LocalNetwork, err error) {
|
||||
}
|
||||
|
||||
localLinks[link.Attrs().Index] = struct{}{}
|
||||
if r.verbose {
|
||||
r.logger.Info("local ethernet link found: " + link.Attrs().Name)
|
||||
}
|
||||
r.logger.Info("local ethernet link found: " + link.Attrs().Name)
|
||||
}
|
||||
|
||||
if len(localLinks) == 0 {
|
||||
@@ -152,9 +146,7 @@ func (r *routing) LocalNetworks() (localNetworks []LocalNetwork, err error) {
|
||||
var localNet LocalNetwork
|
||||
|
||||
localNet.IPNet = route.Dst
|
||||
if r.verbose {
|
||||
r.logger.Info("local ipnet found: " + localNet.IPNet.String())
|
||||
}
|
||||
r.logger.Info("local ipnet found: " + localNet.IPNet.String())
|
||||
|
||||
link, err := netlink.LinkByIndex(route.LinkIndex)
|
||||
if err != nil {
|
||||
|
||||
@@ -20,16 +20,10 @@ type Routing interface {
|
||||
DefaultIP() (defaultIP net.IP, err error)
|
||||
VPNDestinationIP() (ip net.IP, err error)
|
||||
VPNLocalGatewayIP() (ip net.IP, err error)
|
||||
|
||||
// Internal state
|
||||
SetVerbose(verbose bool)
|
||||
SetDebug()
|
||||
}
|
||||
|
||||
type routing struct {
|
||||
logger logging.Logger
|
||||
verbose bool
|
||||
debug bool
|
||||
outboundSubnets []net.IPNet
|
||||
stateMutex sync.RWMutex
|
||||
}
|
||||
@@ -37,15 +31,6 @@ type routing struct {
|
||||
// NewRouting creates a new routing instance.
|
||||
func NewRouting(logger logging.Logger) Routing {
|
||||
return &routing{
|
||||
logger: logger,
|
||||
verbose: true,
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *routing) SetVerbose(verbose bool) {
|
||||
r.verbose = verbose
|
||||
}
|
||||
|
||||
func (r *routing) SetDebug() {
|
||||
r.debug = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user