From 770a2930495c5b74c42a1461fdb1c33a4a48d7ad Mon Sep 17 00:00:00 2001 From: "Matthew R. Kasun" Date: Wed, 21 Dec 2022 03:31:37 -0500 Subject: [PATCH] new constant for wireguard interface name --- logic/gateway.go | 6 +++--- logic/metrics/metrics.go | 2 +- logic/peers.go | 2 +- models/host.go | 3 +++ models/node.go | 2 +- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/logic/gateway.go b/logic/gateway.go index 354fac8a..b3415329 100644 --- a/logic/gateway.go +++ b/logic/gateway.go @@ -52,7 +52,7 @@ func CreateEgressGateway(gateway models.EgressGatewayRequest) (models.Node, erro postDownCmd := "" ipv4, ipv6 := getNetworkProtocols(gateway.Ranges) logger.Log(3, "creating egress gateway firewall in use is '", host.FirewallInUse, "'") - iface := "netmaker" + iface := models.WIREGUARD_INTERFACE if host.OS == "linux" { switch host.FirewallInUse { case models.FIREWALL_NFTABLES: @@ -154,7 +154,7 @@ func DeleteEgressGateway(network, nodeid string) (models.Node, error) { logger.Log(3, "deleting egress gateway firewall in use is '", host.FirewallInUse, "'") if node.IsIngressGateway { // check if node is still an ingress gateway before completely deleting postdown/up rules // still have an ingress gateway so preserve it - iface := "netmaker" + iface := models.WIREGUARD_INTERFACE if host.OS == "linux" { switch host.FirewallInUse { case models.FIREWALL_NFTABLES: @@ -209,7 +209,7 @@ func CreateIngressGateway(netid string, nodeid string, failover bool) (models.No node.IngressGatewayRange6 = network.AddressRange6 ipv4, ipv6 := getNetworkProtocols(cidrs) logger.Log(3, "creating ingress gateway firewall in use is '", host.FirewallInUse, "'") - iface := "netmaker" + iface := models.WIREGUARD_INTERFACE switch host.FirewallInUse { case models.FIREWALL_NFTABLES: // nftables only supported on Linux diff --git a/logic/metrics/metrics.go b/logic/metrics/metrics.go index 3e5e731c..38973207 100644 --- a/logic/metrics/metrics.go +++ b/logic/metrics/metrics.go @@ -102,7 +102,7 @@ func GetExchangedBytesForNode(node *models.Node, metrics *models.Metrics) error return err } defer wgclient.Close() - device, err := wgclient.Device("netmaker") + device, err := wgclient.Device(models.WIREGUARD_INTERFACE) if err != nil { return err } diff --git a/logic/peers.go b/logic/peers.go index 72cfe79c..ce9a7dc8 100644 --- a/logic/peers.go +++ b/logic/peers.go @@ -183,7 +183,7 @@ func GetPeersForProxy(node *models.Node, onlyPeers bool) (manager.ProxyManagerPa proxyPayload.Network = node.Network //proxyPayload.InterfaceName = node.Interface //hardcode or read from host ?? - proxyPayload.InterfaceName = "netmaker" + proxyPayload.InterfaceName = models.WIREGUARD_INTERFACE return proxyPayload, nil } diff --git a/models/host.go b/models/host.go index ecad264e..5f8235bc 100644 --- a/models/host.go +++ b/models/host.go @@ -7,6 +7,9 @@ import ( "golang.zx2c4.com/wireguard/wgctrl/wgtypes" ) +// WIREGUARD_INTERFACE name of wireguard interface +const WIREGUARD_INTERFACE = "netmaker" + // Host - represents a host on the network type Host struct { ID uuid.UUID `json:"id" yaml:"id"` diff --git a/models/node.go b/models/node.go index c9fc9d78..fd4f6d33 100644 --- a/models/node.go +++ b/models/node.go @@ -583,7 +583,7 @@ func (n *Node) Legacy(h *Host, s *ServerConfig, net *Network) *LegacyNode { //l.AllowedIPs = l.PersistentKeepalive = int32(n.PersistentKeepalive) l.AccessKey = "" - l.Interface = "netmaker" + l.Interface = WIREGUARD_INTERFACE //l.LastModified = //l.ExpirationDateTime //l.LastPeerUpdate