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