separate link creation / device configuration
This commit is contained in:
parent
ccc45f8368
commit
f00e344a72
@ -85,6 +85,18 @@ func (conf *DsnetConfig) MustAddPeer(peer PeerConfig) {
|
||||
}
|
||||
}
|
||||
|
||||
for _, p := range conf.Peers {
|
||||
if peer.PublicKey.Key == p.PublicKey.Key {
|
||||
ExitFail("%s is not an unique public key", peer.Hostname)
|
||||
}
|
||||
}
|
||||
|
||||
for _, p := range conf.Peers {
|
||||
if peer.PresharedKey.Key == p.PresharedKey.Key {
|
||||
ExitFail("%s is not an unique preshared key", peer.Hostname)
|
||||
}
|
||||
}
|
||||
|
||||
if conf.IPAllocated(peer.IP) {
|
||||
ExitFail("%s is already allocated", peer.IP)
|
||||
}
|
||||
|
13
up.go
13
up.go
@ -10,10 +10,11 @@ import (
|
||||
|
||||
func Up() {
|
||||
conf := MustLoadDsnetConfig()
|
||||
CreateInterface(conf)
|
||||
CreateLink(conf)
|
||||
ConfigureDevice(conf)
|
||||
}
|
||||
|
||||
func CreateInterface(conf *DsnetConfig) {
|
||||
func CreateLink(conf *DsnetConfig) {
|
||||
linkAttrs := netlink.NewLinkAttrs()
|
||||
linkAttrs.Name = conf.InterfaceName
|
||||
|
||||
@ -39,6 +40,11 @@ func CreateInterface(conf *DsnetConfig) {
|
||||
ExitFail("Could not add addr %s to interface %s", addr.IP, err)
|
||||
}
|
||||
|
||||
// bring up interface (UNKNOWN state instead of UP, a wireguard quirk)
|
||||
err = netlink.LinkSetUp(link)
|
||||
}
|
||||
|
||||
func ConfigureDevice(conf *DsnetConfig) {
|
||||
wgConfig := wgtypes.Config{
|
||||
PrivateKey: &conf.PrivateKey.Key,
|
||||
ListenPort: &conf.ListenPort,
|
||||
@ -56,9 +62,6 @@ func CreateInterface(conf *DsnetConfig) {
|
||||
ExitFail("Could not configure device '%s' (%v)", conf.InterfaceName, err)
|
||||
}
|
||||
|
||||
// bring up interface (UNKNOWN state, a wireguard thing)
|
||||
err = netlink.LinkSetUp(link)
|
||||
|
||||
if err != nil {
|
||||
ExitFail("Could not bring up device '%s' (%v)", conf.InterfaceName, err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user