Merge pull request #573 from gravitl/bugfix_v0.9.3_post_cmds

Bugfix v0.9.3 post cmds
This commit is contained in:
dcarns 2022-01-04 14:05:56 -05:00 committed by GitHub
commit b937b0ff92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 63 additions and 36 deletions

View file

@ -249,6 +249,14 @@ func GetPeersList(networkName string, excludeRelayed bool, relayedNodeAddr strin
network, err := GetNetwork(networkName)
if err == nil {
peerNode.AllowedIPs = append(peerNode.AllowedIPs, network.AddressRange)
var _, egressNetworkNodes, err = getNetworkEgressAndNodes(networkName)
if err == nil {
for _, egress := range egressNetworkNodes {
if egress.Address != relayedNodeAddr {
peerNode.AllowedIPs = append(peerNode.AllowedIPs, egress.EgressGatewayRanges...)
}
}
}
} else {
peerNode.AllowedIPs = append(peerNode.AllowedIPs, peerNode.RelayAddrs...)
}

View file

@ -87,7 +87,7 @@ func initWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
if !ncutils.IsKernel() {
var newConf string
newConf, _ = ncutils.CreateWireGuardConf(node.Address, key.String(), strconv.FormatInt(int64(node.ListenPort), 10), node.MTU, servercfg.GetCoreDNSAddr(), node.PersistentKeepalive, peers)
newConf, _ = ncutils.CreateWireGuardConf(node, key.String(), strconv.FormatInt(int64(node.ListenPort), 10), servercfg.GetCoreDNSAddr(), peers)
confPath := ncutils.GetNetclientPathSpecific() + ifacename + ".conf"
logger.Log(1, "writing wg conf file to:", confPath)
err = ioutil.WriteFile(confPath, []byte(newConf), 0644)

View file

@ -205,7 +205,8 @@ func List(cfg config.ClientConfig) error {
// Uninstall - runs uninstall command from cli
func Uninstall() error {
ncutils.PrintLog("uninstalling netclient", 0)
ncutils.PrintLog("uninstalling netclient...", 0)
err := functions.Uninstall()
ncutils.PrintLog("uninstalled netclient", 0)
return err
}

View file

@ -7,6 +7,7 @@ import (
"strconv"
"strings"
"github.com/gravitl/netmaker/models"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
)
@ -33,12 +34,12 @@ func GetEmbedded() error {
return nil
}
// CreateUserSpaceConf - creates a user space WireGuard conf
func CreateUserSpaceConf(address string, privatekey string, listenPort string, mtu int32, perskeepalive int32, peers []wgtypes.PeerConfig) (string, error) {
peersString, err := parsePeers(perskeepalive, peers)
// CreateWireGuardConf - creates a WireGuard conf string
func CreateWireGuardConf(node *models.Node, privatekey string, listenPort string, dns string, peers []wgtypes.PeerConfig) (string, error) {
peersString, err := parsePeers(node.PersistentKeepalive, peers)
var listenPortString string
if mtu <= 0 {
mtu = 1280
if node.MTU <= 0 {
node.MTU = 1280
}
if listenPort != "" {
listenPortString += "ListenPort = " + listenPort
@ -55,9 +56,9 @@ MTU = %s
%s
`,
address+"/32",
node.Address+"/32",
privatekey,
strconv.Itoa(int(mtu)),
strconv.Itoa(int(node.MTU)),
listenPortString,
peersString)
return config, nil

View file

@ -3,13 +3,15 @@ package ncutils
import (
"context"
"fmt"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
"log"
"os/exec"
"strconv"
"strings"
"syscall"
"time"
"github.com/gravitl/netmaker/models"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
)
// RunCmdFormatted - run a command formatted for freebsd
@ -41,12 +43,12 @@ func RunCmd(command string, printerr bool) (string, error) {
return string(out), err
}
// CreateUserSpaceConf - creates a user space WireGuard conf
func CreateUserSpaceConf(address string, privatekey string, listenPort string, mtu int32, perskeepalive int32, peers []wgtypes.PeerConfig) (string, error) {
peersString, err := parsePeers(perskeepalive, peers)
// CreateWireGuardConf - creates a WireGuard conf string
func CreateWireGuardConf(node *models.Node, privatekey string, listenPort string, dns string, peers []wgtypes.PeerConfig) (string, error) {
peersString, err := parsePeers(node.PersistentKeepalive, peers)
var listenPortString string
if mtu <= 0 {
mtu = 1280
if node.MTU <= 0 {
node.MTU = 1280
}
if listenPort != "" {
listenPortString += "ListenPort = " + listenPort
@ -63,9 +65,9 @@ MTU = %s
%s
`,
address+"/32",
node.Address+"/32",
privatekey,
strconv.Itoa(int(mtu)),
strconv.Itoa(int(node.MTU)),
listenPortString,
peersString)
return config, nil

View file

@ -6,6 +6,7 @@ import (
"strconv"
"strings"
"github.com/gravitl/netmaker/models"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
)
@ -33,15 +34,23 @@ func GetEmbedded() error {
}
// CreateWireGuardConf - creates a user space WireGuard conf
func CreateWireGuardConf(address string, privatekey string, listenPort string, mtu int32, dns string, perskeepalive int32, peers []wgtypes.PeerConfig) (string, error) {
peersString, err := parsePeers(perskeepalive, peers)
var listenPortString string
if mtu <= 0 {
mtu = 1280
func CreateWireGuardConf(node *models.Node, privatekey string, listenPort string, dns string, peers []wgtypes.PeerConfig) (string, error) {
peersString, err := parsePeers(node.PersistentKeepalive, peers)
var listenPortString, postDownString, postUpString string
if node.MTU <= 0 {
node.MTU = 1280
}
if node.PostDown != "" {
postDownString = fmt.Sprintf("PostDown = %s", node.PostDown)
}
if node.PostUp != "" {
postUpString = fmt.Sprintf("PostUp = %s", node.PostUp)
}
if listenPort != "" {
listenPortString += "ListenPort = " + listenPort
listenPortString = fmt.Sprintf("ListenPort = %s", listenPort)
}
if err != nil {
return "", err
}
@ -51,14 +60,18 @@ DNS = %s
PrivateKey = %s
MTU = %s
%s
%s
%s
%s
`,
address+"/32",
node.Address+"/32",
dns,
privatekey,
strconv.Itoa(int(mtu)),
strconv.Itoa(int(node.MTU)),
postDownString,
postUpString,
listenPortString,
peersString)
return config, nil

View file

@ -10,6 +10,7 @@ import (
"strings"
"syscall"
"github.com/gravitl/netmaker/models"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
)
@ -47,12 +48,12 @@ func RunCmdFormatted(command string, printerr bool) (string, error) {
return string(out), err
}
// CreateUserSpaceConf - creates a user space WireGuard conf
func CreateUserSpaceConf(address string, privatekey string, listenPort string, mtu int32, perskeepalive int32, peers []wgtypes.PeerConfig) (string, error) {
peersString, err := parsePeers(perskeepalive, peers)
// CreateWireGuardConf - creates a WireGuard conf string
func CreateWireGuardConf(node *models.Node, privatekey string, listenPort string, dns string, peers []wgtypes.PeerConfig) (string, error) {
peersString, err := parsePeers(node.PersistentKeepalive, peers)
var listenPortString string
if mtu <= 0 {
mtu = 1280
if node.MTU <= 0 {
node.MTU = 1280
}
if listenPort != "" {
listenPortString += "ListenPort = " + listenPort
@ -69,9 +70,9 @@ MTU = %s
%s
`,
address+"/32",
node.Address+"/32",
privatekey,
strconv.Itoa(int(mtu)),
strconv.Itoa(int(node.MTU)),
listenPortString,
peersString)
return config, nil

View file

@ -149,9 +149,9 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
}
var newConf string
if node.UDPHolePunch != "yes" {
newConf, _ = ncutils.CreateWireGuardConf(node.Address, key.String(), strconv.FormatInt(int64(node.ListenPort), 10), node.MTU, nameserver, node.PersistentKeepalive, peers)
newConf, _ = ncutils.CreateWireGuardConf(node, key.String(), strconv.FormatInt(int64(node.ListenPort), 10), nameserver, peers)
} else {
newConf, _ = ncutils.CreateWireGuardConf(node.Address, key.String(), "", node.MTU, nameserver, node.PersistentKeepalive, peers)
newConf, _ = ncutils.CreateWireGuardConf(node, key.String(), "", nameserver, peers)
}
confPath := ncutils.GetNetclientPathSpecific() + ifacename + ".conf"
ncutils.PrintLog("writing wg conf file to: "+confPath, 1)
@ -182,7 +182,7 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
} else {
d, _ := wgclient.Device(deviceiface)
for d != nil && d.Name == deviceiface {
_ = RemoveConf(ifacename, false) // remove interface first
RemoveConf(ifacename, false) // remove interface first
time.Sleep(time.Second >> 2)
d, _ = wgclient.Device(deviceiface)
}

View file

@ -1,6 +1,7 @@
package wireguard
import (
"fmt"
"io/ioutil"
"log"
"os"
@ -86,7 +87,7 @@ func SyncWGQuickConf(iface string, confPath string) error {
// RemoveWGQuickConf - calls wg-quick down
func RemoveWGQuickConf(confPath string, printlog bool) error {
_, err := ncutils.RunCmd("wg-quick down "+confPath, printlog)
_, err := ncutils.RunCmd(fmt.Sprintf("wg-quick down %s", confPath), printlog)
return err
}