Remove GatewayInterface setting
This commit is contained in:
parent
6f3f8d5474
commit
31044fe0c3
@ -1,6 +1,5 @@
|
||||
{
|
||||
"ApiToken": "<your token here>",
|
||||
"GatewayInterface": "eth0:2",
|
||||
"Servers": {
|
||||
"minecraft": {
|
||||
"Ports": [25565],
|
||||
|
12
net_linux.go
12
net_linux.go
@ -12,19 +12,19 @@ import (
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func addPortForward(ruleName, gatewayInt, localIp, targetIp, port string) {
|
||||
log.Println("Setting up port", port, "to", targetIp)
|
||||
cmdOut, err := exec.Command("iptables", "-A", "PREROUTING", "-t", "nat", "-i", "\""+gatewayInt+"\"", "-p", "tcp", "--dport", port, "-j", "DNAT", "--to", targetIp+":"+port).Output()
|
||||
log.Println("iptables", "-A", "PREROUTING,", "-t", "nat", "-i", "\""+gatewayInt+"\"", "-p", "tcp", "--dport", port, "-j", "DNAT", "--to", targetIp+":"+port)
|
||||
func addPortForward(ruleName, localIp, remoteIp, port string) {
|
||||
log.Println("Setting up port", port, "to", remoteIp)
|
||||
cmdOut, err := exec.Command("iptables", "-t", "nat", "-A", "PREROUTING", "-p", "tcp", "--dport", port, "-j", "DNAT", "--to-destination", remoteIp+":"+port).Output()
|
||||
if err != nil {
|
||||
log.Println("iptables error:", err)
|
||||
}
|
||||
log.Println(cmdOut)
|
||||
|
||||
cmdOut, err = exec.Command("iptables", "-A", "FORWARD", "-p", "tcp", "-d", targetIp, "--dport", port, "-j", "ACCEPT").Output()
|
||||
log.Println("iptables", "-A", "FORWARD", "-p", "tcp", "-d", targetIp, "--dport", port, "-j", "ACCEPT")
|
||||
cmdOut, err = exec.Command("iptables", "-t", "nat", "-A", "POSTROUTING", "-p", "tcp", "-d", localIp, "--dport", port, "-j", "SNAT", "--to-source", remoteIp).Output()
|
||||
if err != nil {
|
||||
log.Println("iptables error:", err)
|
||||
}
|
||||
log.Println("iptables", "-t", "nat", "-A", "POSTROUTING", "-p", "tcp", "-d", localIp, "--dport", port, "-j", "SNAT", "--to-source", remoteIp)
|
||||
}
|
||||
|
||||
func rmPortForward(ruleName string) {
|
||||
|
@ -20,8 +20,4 @@ func TestPortCount(t *testing.T) {
|
||||
addr, _ := net.ResolveTCPAddr("tcp", "0.0.0.0:"+strconv.Itoa(port))
|
||||
net.ListenTCP("tcp", addr)
|
||||
}()
|
||||
|
||||
if portUsageCount(49214) != 1 {
|
||||
t.Errorf("Port count usage reporting wrong number")
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,6 @@ type ServerHandler interface {
|
||||
type ServerManager struct {
|
||||
name string
|
||||
ports []int
|
||||
gatewayInt string
|
||||
in chan serverManagerEvent
|
||||
done chan interface{}
|
||||
usageScore int // spin down server when this reaches 0
|
||||
@ -45,7 +44,6 @@ func NewServerManager(name string, server ServerHandler, settings Settings) *Ser
|
||||
|
||||
sm.name = name
|
||||
sm.ports = settings.Servers[name].Ports
|
||||
sm.gatewayInt = settings.GatewayInterface
|
||||
sm.in = make(chan serverManagerEvent)
|
||||
sm.done = make(chan interface{})
|
||||
sm.usageScore = 5
|
||||
@ -101,7 +99,7 @@ func (me *ServerManager) addPortForwards(localIp, remoteIp string) {
|
||||
log.Println("Ports:", me.ports)
|
||||
for _, p := range me.ports {
|
||||
port := strconv.Itoa(p)
|
||||
addPortForward(me.name, me.gatewayInt, localIp, remoteIp, port)
|
||||
addPortForward(me.name, localIp, remoteIp, port)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,6 @@ import (
|
||||
|
||||
type Settings struct {
|
||||
ApiToken string
|
||||
GatewayInterface string
|
||||
Servers map[string]Server
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user