Maintenance: improve error codes in IP routing

This commit is contained in:
Quentin McGaw
2021-05-10 17:33:31 +00:00
parent 5a0418bba6
commit 810ff62c26
5 changed files with 103 additions and 53 deletions

View File

@@ -2,6 +2,7 @@ package main
import (
"context"
"errors"
"fmt"
"net"
"net/http"
@@ -45,6 +46,10 @@ var (
buildDate = "an unknown date"
)
var (
errSetupRouting = errors.New("cannot setup routing")
)
func main() {
buildInfo := models.BuildInformation{
Version: version,
@@ -204,12 +209,12 @@ func _main(ctx context.Context, buildInfo models.BuildInformation,
firewallConf.SetNetworkInformation(defaultInterface, defaultGateway, localNetworks, defaultIP)
if err := routingConf.Setup(); err != nil {
return err
return fmt.Errorf("%w: %s", errSetupRouting, err)
}
defer func() {
routingConf.SetVerbose(false)
if err := routingConf.TearDown(); err != nil {
logger.Error(err)
logger.Error("cannot teardown routing: " + err.Error())
}
}()