Add routing verbose option in code
This commit is contained in:
@@ -10,7 +10,9 @@ import (
|
|||||||
|
|
||||||
func (r *routing) addRouteVia(destination net.IPNet, gateway net.IP, iface string, table int) error {
|
func (r *routing) addRouteVia(destination net.IPNet, gateway net.IP, iface string, table int) error {
|
||||||
destinationStr := destination.String()
|
destinationStr := destination.String()
|
||||||
r.logger.Info("adding route for %s", destinationStr)
|
if r.verbose {
|
||||||
|
r.logger.Info("adding route for %s", destinationStr)
|
||||||
|
}
|
||||||
if r.debug {
|
if r.debug {
|
||||||
fmt.Printf("ip route replace %s via %s dev %s table %d\n", destinationStr, gateway, iface, table)
|
fmt.Printf("ip route replace %s via %s dev %s table %d\n", destinationStr, gateway, iface, table)
|
||||||
}
|
}
|
||||||
@@ -33,7 +35,9 @@ 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) {
|
func (r *routing) deleteRouteVia(destination net.IPNet, gateway net.IP, iface string, table int) (err error) {
|
||||||
destinationStr := destination.String()
|
destinationStr := destination.String()
|
||||||
r.logger.Info("deleting route for %s", destinationStr)
|
if r.verbose {
|
||||||
|
r.logger.Info("deleting route for %s", destinationStr)
|
||||||
|
}
|
||||||
if r.debug {
|
if r.debug {
|
||||||
fmt.Printf("ip route delete %s via %s dev %s table %d\n", destinationStr, gateway, iface, table)
|
fmt.Printf("ip route delete %s via %s dev %s table %d\n", destinationStr, gateway, iface, table)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,9 @@ func (r *routing) DefaultRoute() (defaultInterface string, defaultGateway net.IP
|
|||||||
}
|
}
|
||||||
attributes := link.Attrs()
|
attributes := link.Attrs()
|
||||||
defaultInterface = attributes.Name
|
defaultInterface = attributes.Name
|
||||||
r.logger.Info("default route found: interface %s, gateway %s", defaultInterface, defaultGateway.String())
|
if r.verbose {
|
||||||
|
r.logger.Info("default route found: interface %s, gateway %s", defaultInterface, defaultGateway.String())
|
||||||
|
}
|
||||||
return defaultInterface, defaultGateway, nil
|
return defaultInterface, defaultGateway, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,7 +79,9 @@ func (r *routing) LocalSubnet() (defaultSubnet net.IPNet, err error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
defaultSubnet = *route.Dst
|
defaultSubnet = *route.Dst
|
||||||
r.logger.Info("local subnet found: %s", defaultSubnet.String())
|
if r.verbose {
|
||||||
|
r.logger.Info("local subnet found: %s", defaultSubnet.String())
|
||||||
|
}
|
||||||
return defaultSubnet, nil
|
return defaultSubnet, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,21 +13,28 @@ type Routing interface {
|
|||||||
LocalSubnet() (defaultSubnet net.IPNet, err error)
|
LocalSubnet() (defaultSubnet net.IPNet, err error)
|
||||||
VPNDestinationIP() (ip net.IP, err error)
|
VPNDestinationIP() (ip net.IP, err error)
|
||||||
VPNLocalGatewayIP() (ip net.IP, err error)
|
VPNLocalGatewayIP() (ip net.IP, err error)
|
||||||
|
SetVerbose(verbose bool)
|
||||||
SetDebug()
|
SetDebug()
|
||||||
}
|
}
|
||||||
|
|
||||||
type routing struct {
|
type routing struct {
|
||||||
logger logging.Logger
|
logger logging.Logger
|
||||||
debug bool
|
verbose bool
|
||||||
|
debug bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewConfigurator creates a new Configurator instance.
|
// NewConfigurator creates a new Configurator instance.
|
||||||
func NewRouting(logger logging.Logger) Routing {
|
func NewRouting(logger logging.Logger) Routing {
|
||||||
return &routing{
|
return &routing{
|
||||||
logger: logger.WithPrefix("routing: "),
|
logger: logger.WithPrefix("routing: "),
|
||||||
|
verbose: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *routing) SetVerbose(verbose bool) {
|
||||||
|
c.verbose = verbose
|
||||||
|
}
|
||||||
|
|
||||||
func (c *routing) SetDebug() {
|
func (c *routing) SetDebug() {
|
||||||
c.debug = true
|
c.debug = true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user