Browse Source

new constant for wireguard interface name

Matthew R. Kasun 2 years ago
parent
commit
770a293049
5 changed files with 9 additions and 6 deletions
  1. 3 3
      logic/gateway.go
  2. 1 1
      logic/metrics/metrics.go
  3. 1 1
      logic/peers.go
  4. 3 0
      models/host.go
  5. 1 1
      models/node.go

+ 3 - 3
logic/gateway.go

@@ -52,7 +52,7 @@ func CreateEgressGateway(gateway models.EgressGatewayRequest) (models.Node, erro
 	postDownCmd := ""
 	postDownCmd := ""
 	ipv4, ipv6 := getNetworkProtocols(gateway.Ranges)
 	ipv4, ipv6 := getNetworkProtocols(gateway.Ranges)
 	logger.Log(3, "creating egress gateway firewall in use is '", host.FirewallInUse, "'")
 	logger.Log(3, "creating egress gateway firewall in use is '", host.FirewallInUse, "'")
-	iface := "netmaker"
+	iface := models.WIREGUARD_INTERFACE
 	if host.OS == "linux" {
 	if host.OS == "linux" {
 		switch host.FirewallInUse {
 		switch host.FirewallInUse {
 		case models.FIREWALL_NFTABLES:
 		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, "'")
 	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
 	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
 		// still have an ingress gateway so preserve it
-		iface := "netmaker"
+		iface := models.WIREGUARD_INTERFACE
 		if host.OS == "linux" {
 		if host.OS == "linux" {
 			switch host.FirewallInUse {
 			switch host.FirewallInUse {
 			case models.FIREWALL_NFTABLES:
 			case models.FIREWALL_NFTABLES:
@@ -209,7 +209,7 @@ func CreateIngressGateway(netid string, nodeid string, failover bool) (models.No
 	node.IngressGatewayRange6 = network.AddressRange6
 	node.IngressGatewayRange6 = network.AddressRange6
 	ipv4, ipv6 := getNetworkProtocols(cidrs)
 	ipv4, ipv6 := getNetworkProtocols(cidrs)
 	logger.Log(3, "creating ingress gateway firewall in use is '", host.FirewallInUse, "'")
 	logger.Log(3, "creating ingress gateway firewall in use is '", host.FirewallInUse, "'")
-	iface := "netmaker"
+	iface := models.WIREGUARD_INTERFACE
 	switch host.FirewallInUse {
 	switch host.FirewallInUse {
 	case models.FIREWALL_NFTABLES:
 	case models.FIREWALL_NFTABLES:
 		// nftables only supported on Linux
 		// nftables only supported on Linux

+ 1 - 1
logic/metrics/metrics.go

@@ -102,7 +102,7 @@ func GetExchangedBytesForNode(node *models.Node, metrics *models.Metrics) error
 		return err
 		return err
 	}
 	}
 	defer wgclient.Close()
 	defer wgclient.Close()
-	device, err := wgclient.Device("netmaker")
+	device, err := wgclient.Device(models.WIREGUARD_INTERFACE)
 	if err != nil {
 	if err != nil {
 		return err
 		return err
 	}
 	}

+ 1 - 1
logic/peers.go

@@ -183,7 +183,7 @@ func GetPeersForProxy(node *models.Node, onlyPeers bool) (manager.ProxyManagerPa
 	proxyPayload.Network = node.Network
 	proxyPayload.Network = node.Network
 	//proxyPayload.InterfaceName = node.Interface
 	//proxyPayload.InterfaceName = node.Interface
 	//hardcode or read from host ??
 	//hardcode or read from host ??
-	proxyPayload.InterfaceName = "netmaker"
+	proxyPayload.InterfaceName = models.WIREGUARD_INTERFACE
 
 
 	return proxyPayload, nil
 	return proxyPayload, nil
 }
 }

+ 3 - 0
models/host.go

@@ -7,6 +7,9 @@ import (
 	"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
 	"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
 )
 )
 
 
+// WIREGUARD_INTERFACE name of wireguard interface
+const WIREGUARD_INTERFACE = "netmaker"
+
 // Host - represents a host on the network
 // Host - represents a host on the network
 type Host struct {
 type Host struct {
 	ID               uuid.UUID        `json:"id" yaml:"id"`
 	ID               uuid.UUID        `json:"id" yaml:"id"`

+ 1 - 1
models/node.go

@@ -583,7 +583,7 @@ func (n *Node) Legacy(h *Host, s *ServerConfig, net *Network) *LegacyNode {
 	//l.AllowedIPs =
 	//l.AllowedIPs =
 	l.PersistentKeepalive = int32(n.PersistentKeepalive)
 	l.PersistentKeepalive = int32(n.PersistentKeepalive)
 	l.AccessKey = ""
 	l.AccessKey = ""
-	l.Interface = "netmaker"
+	l.Interface = WIREGUARD_INTERFACE
 	//l.LastModified =
 	//l.LastModified =
 	//l.ExpirationDateTime
 	//l.ExpirationDateTime
 	//l.LastPeerUpdate
 	//l.LastPeerUpdate