Skip to content

Commit

Permalink
Add additional error logging for wireguard re-up
Browse files Browse the repository at this point in the history
  • Loading branch information
NHAS committed Apr 28, 2024
1 parent 3b099d5 commit 6ec5dff
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions commands/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ func (g *registration) Check() error {
switch g.action {
case "add":
if g.username == "" {
return errors.New("Username must be supplied")
return errors.New("username must be supplied")
}

case "del":
if g.token == "" && g.username == "" {
return errors.New("Token or username must be supplied")
return errors.New("token or username must be supplied")
}
case "list":
default:
Expand Down
1 change: 1 addition & 0 deletions internal/router/statemachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ func clusterState(errorsChan chan<- error) func(string) {
hasDied = true
log.Println("Cluster has entered dead state, tearing down: ", hasDied)
TearDown(false)
log.Println("cluster finished tearing down")
}
case "healthy":
if hasDied {
Expand Down
12 changes: 6 additions & 6 deletions internal/router/wireguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,24 @@ func setupWireguard(devices []data.Device) error {

conn, err := netlink.Dial(unix.NETLINK_ROUTE, nil)
if err != nil {
return err
return fmt.Errorf("failed to connect to netlink: err: %s", err)
}
defer conn.Close()

ip, network, err := net.ParseCIDR(config.Values.Wireguard.Address)
if err != nil {
return err
return fmt.Errorf("failed to parse wireguard address: err: %s", err)
}
network.IP = ip.To4()[:4] // Stop netlink freaking out at a ipv6 length ipv4 address

err = addWg(conn, config.Values.Wireguard.DevName, *network, config.Values.Wireguard.MTU)
if err != nil {
return err
return fmt.Errorf("failed to create wireguard device: err: %s", err)
}

key, err := wgtypes.ParseKey(config.Values.Wireguard.PrivateKey)
if err != nil {
return err
return fmt.Errorf("failed to parse wireguard private key: err: %s", err)
}
c.PrivateKey = &key

Expand Down Expand Up @@ -108,12 +108,12 @@ func setupWireguard(devices []data.Device) error {
var err error
ctrl, err = wgctrl.New()
if err != nil {
return fmt.Errorf("cannot start wireguard control %v", err)
return fmt.Errorf("cannot start wireguard control: err: %s", err)
}

err = ctrl.ConfigureDevice(config.Values.Wireguard.DevName, c)
if err != nil {
return fmt.Errorf("cannot configure wireguard device %v", err)
return fmt.Errorf("cannot configure wireguard device: err: %s", err)

}

Expand Down

0 comments on commit 6ec5dff

Please sign in to comment.