IP_STATUS_FILE and routing improvements (#130)
- Obtains VPN public IP address from routing table - Logs and writes VPN Public IP address to `/ip` as soon as VPN is up - Obtain port forward, logs it and writes it as soon as VPN is up - Routing fully refactored and tested - Routing reads from `/proc/net/route` - Routing mutates the routes using `ip route ...`
This commit is contained in:
30
internal/routing/routing.go
Normal file
30
internal/routing/routing.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package routing
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"github.com/qdm12/golibs/command"
|
||||
"github.com/qdm12/golibs/files"
|
||||
"github.com/qdm12/golibs/logging"
|
||||
)
|
||||
|
||||
type Routing interface {
|
||||
AddRoutesVia(subnets []net.IPNet, defaultGateway net.IP, defaultInterface string) error
|
||||
DefaultRoute() (defaultInterface string, defaultGateway net.IP, defaultSubnet net.IPNet, err error)
|
||||
CurrentPublicIP(defaultInterface string) (ip net.IP, err error)
|
||||
}
|
||||
|
||||
type routing struct {
|
||||
commander command.Commander
|
||||
logger logging.Logger
|
||||
fileManager files.FileManager
|
||||
}
|
||||
|
||||
// NewConfigurator creates a new Configurator instance
|
||||
func NewRouting(logger logging.Logger, fileManager files.FileManager) Routing {
|
||||
return &routing{
|
||||
commander: command.NewCommander(),
|
||||
logger: logger.WithPrefix("routing: "),
|
||||
fileManager: fileManager,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user