|
|
@@ -11,6 +11,7 @@ import (
|
|
|
"os/exec"
|
|
|
"path/filepath"
|
|
|
"strconv"
|
|
|
+ "strings"
|
|
|
"sync"
|
|
|
"sync/atomic"
|
|
|
"syscall"
|
|
|
@@ -24,6 +25,7 @@ type EoIPInstance struct {
|
|
|
TunnelID int `json:"tunnel_id"` // 1 - 65535
|
|
|
RemoteAddress string `json:"remote_address"` // Remote MikroTik IPv4
|
|
|
LocalAddress string `json:"local_address"` // Local router IPv4 (optional)
|
|
|
+ IPAddress string `json:"ip_address,omitempty"` // Overlay IP/CIDR (e.g. "172.16.33.254/30")
|
|
|
MACAddress string `json:"mac_address"` // e.g. "02:64:83:6b:46:44"
|
|
|
MTU int `json:"mtu"` // default 1500
|
|
|
ClampMSS bool `json:"clamp_mss"` // Clamp TCP MSS for PMTUD
|
|
|
@@ -127,6 +129,12 @@ func (m *EoIPManager) Save(inst *EoIPInstance) error {
|
|
|
inst.ID = fmt.Sprintf("eoip-%d", time.Now().UnixNano())
|
|
|
}
|
|
|
|
|
|
+ // Smart detection: if user put CIDR into LocalAddress by mistake, move it to IPAddress
|
|
|
+ if strings.Contains(inst.LocalAddress, "/") && inst.IPAddress == "" {
|
|
|
+ inst.IPAddress = inst.LocalAddress
|
|
|
+ inst.LocalAddress = ""
|
|
|
+ }
|
|
|
+
|
|
|
// Stop previous worker if exists
|
|
|
if w, exists := m.workers[inst.ID]; exists {
|
|
|
w.stop()
|
|
|
@@ -237,6 +245,20 @@ func (m *EoIPManager) updateStats(t *EoIPInstance) {
|
|
|
}
|
|
|
t.RxHuman = formatBytes(t.RxBytes)
|
|
|
t.TxHuman = formatBytes(t.TxBytes)
|
|
|
+
|
|
|
+ // Detect any bound IPv4 if not explicitly saved in JSON
|
|
|
+ if t.IPAddress == "" {
|
|
|
+ if ifi, err := net.InterfaceByName(t.Name); err == nil {
|
|
|
+ if addrs, err := ifi.Addrs(); err == nil {
|
|
|
+ for _, a := range addrs {
|
|
|
+ if ipNet, ok := a.(*net.IPNet); ok && ipNet.IP.To4() != nil {
|
|
|
+ t.IPAddress = ipNet.String()
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// -------------------------------------------------------------
|
|
|
@@ -293,6 +315,11 @@ func newEoIPTunnelWorker(inst *EoIPInstance) (*eoipTunnelWorker, error) {
|
|
|
_ = exec.Command("ip", "link", "set", inst.Name, "up").Run()
|
|
|
_ = exec.Command("ip", "link", "set", peerName, "up").Run()
|
|
|
|
|
|
+ // 4b. Assign Overlay IP address if specified
|
|
|
+ if inst.IPAddress != "" {
|
|
|
+ _ = exec.Command("ip", "addr", "add", inst.IPAddress, "dev", inst.Name).Run()
|
|
|
+ }
|
|
|
+
|
|
|
// 5. TCP MSS Clamping
|
|
|
if inst.ClampMSS {
|
|
|
_ = exec.Command("iptables", "-t", "mangle", "-A", "FORWARD", "-o", inst.Name, "-p", "tcp", "--tcp-flags", "SYN,RST", "SYN", "-j", "TCPMSS", "--clamp-mss-to-pmtu").Run()
|