Merge pull request 'Add keepalive to wesher' (#1) from keepalive into master
Reviewed-on: https://git.weko.io/resilien/wesher/pulls/1
This commit is contained in:
commit
b4a5b61255
|
@ -145,6 +145,7 @@ All options can be passed either as command-line flags or environment variables:
|
||||||
| `--interface DEV` | WESHER_INTERFACE | name of the wireguard interface to create and manage | `wgoverlay` |
|
| `--interface DEV` | WESHER_INTERFACE | name of the wireguard interface to create and manage | `wgoverlay` |
|
||||||
| `--no-etc-hosts` | WESHER_NO_ETC_HOSTS | whether to skip writing hosts entries for each node in mesh | `false` |
|
| `--no-etc-hosts` | WESHER_NO_ETC_HOSTS | whether to skip writing hosts entries for each node in mesh | `false` |
|
||||||
| `--log-level LEVEL` | WESHER_LOG_LEVEL | set the verbosity (one of debug/info/warn/error) | `warn` |
|
| `--log-level LEVEL` | WESHER_LOG_LEVEL | set the verbosity (one of debug/info/warn/error) | `warn` |
|
||||||
|
| `--keepalive-interval INTERVAL` | WESHER_KEEPALIVE_INTERVAL | interval for which to send keepalive packets | `30s` |
|
||||||
|
|
||||||
## Running multiple clusters
|
## Running multiple clusters
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ type config struct {
|
||||||
NoEtcHosts bool `id:"no-etc-hosts" desc:"disable writing of entries to /etc/hosts"`
|
NoEtcHosts bool `id:"no-etc-hosts" desc:"disable writing of entries to /etc/hosts"`
|
||||||
LogLevel string `id:"log-level" desc:"set the verbosity (debug/info/warn/error)" default:"warn"`
|
LogLevel string `id:"log-level" desc:"set the verbosity (debug/info/warn/error)" default:"warn"`
|
||||||
Version bool `desc:"display current version and exit"`
|
Version bool `desc:"display current version and exit"`
|
||||||
|
KeepaliveInterval string `id:"keepalive-interval" desc:"interval for which to send keepalive packets" default:"30s"`
|
||||||
|
|
||||||
// for easier local testing; will break etchosts entry
|
// for easier local testing; will break etchosts entry
|
||||||
UseIPAsName bool `id:"ip-as-name" default:"false" opts:"hidden"`
|
UseIPAsName bool `id:"ip-as-name" default:"false" opts:"hidden"`
|
||||||
|
|
8
main.go
8
main.go
|
@ -39,7 +39,13 @@ func main() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Fatal("could not create cluster")
|
logrus.WithError(err).Fatal("could not create cluster")
|
||||||
}
|
}
|
||||||
wgstate, localNode, err := wg.New(config.Interface, config.WireguardPort, config.BaseMtu, (*net.IPNet)(config.OverlayNet), cluster.LocalName)
|
|
||||||
|
keepaliveDuration, err := time.ParseDuration(config.KeepaliveInterval)
|
||||||
|
if err != nil {
|
||||||
|
logrus.WithError(err).Fatal("could not parse time duration for keepalive")
|
||||||
|
}
|
||||||
|
|
||||||
|
wgstate, localNode, err := wg.New(config.Interface, config.WireguardPort, config.BaseMtu, (*net.IPNet)(config.OverlayNet), cluster.LocalName, &keepaliveDuration)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Fatal("could not instantiate wireguard controller")
|
logrus.WithError(err).Fatal("could not instantiate wireguard controller")
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"hash/fnv"
|
"hash/fnv"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/costela/wesher/common"
|
"github.com/costela/wesher/common"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
@ -21,12 +22,13 @@ type State struct {
|
||||||
Mtu int
|
Mtu int
|
||||||
PrivKey wgtypes.Key
|
PrivKey wgtypes.Key
|
||||||
PubKey wgtypes.Key
|
PubKey wgtypes.Key
|
||||||
|
KeepaliveInterval *time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new Wesher Wireguard state
|
// New creates a new Wesher Wireguard state
|
||||||
// The Wireguard keys are generated for every new interface
|
// The Wireguard keys are generated for every new interface
|
||||||
// The interface must later be setup using SetUpInterface
|
// The interface must later be setup using SetUpInterface
|
||||||
func New(iface string, port int, mtu int, ipnet *net.IPNet, name string) (*State, *common.Node, error) {
|
func New(iface string, port int, mtu int, ipnet *net.IPNet, name string, keepaliveInterval *time.Duration) (*State, *common.Node, error) {
|
||||||
client, err := wgctrl.New()
|
client, err := wgctrl.New()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, errors.Wrap(err, "could not instantiate wireguard client")
|
return nil, nil, errors.Wrap(err, "could not instantiate wireguard client")
|
||||||
|
@ -45,6 +47,7 @@ func New(iface string, port int, mtu int, ipnet *net.IPNet, name string) (*State
|
||||||
Mtu: mtu,
|
Mtu: mtu,
|
||||||
PrivKey: privKey,
|
PrivKey: privKey,
|
||||||
PubKey: pubKey,
|
PubKey: pubKey,
|
||||||
|
KeepaliveInterval: keepaliveInterval,
|
||||||
}
|
}
|
||||||
state.assignOverlayAddr(ipnet, name)
|
state.assignOverlayAddr(ipnet, name)
|
||||||
|
|
||||||
|
@ -193,6 +196,7 @@ func (s *State) nodesToPeerConfigs(nodes []common.Node) ([]wgtypes.PeerConfig, e
|
||||||
Port: s.Port,
|
Port: s.Port,
|
||||||
},
|
},
|
||||||
AllowedIPs: append([]net.IPNet{node.OverlayAddr}, node.Routes...),
|
AllowedIPs: append([]net.IPNet{node.OverlayAddr}, node.Routes...),
|
||||||
|
PersistentKeepaliveInterval: s.KeepaliveInterval,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return peerCfgs, nil
|
return peerCfgs, nil
|
||||||
|
|
Loading…
Reference in New Issue