设置 gosysctl

This commit is contained in:
bjdgyc 2025-03-03 13:09:34 +08:00
parent e9622fa543
commit 13498fc125
3 changed files with 21 additions and 6 deletions

View File

@ -10,6 +10,7 @@ import (
"github.com/bjdgyc/anylink/sessdata"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
gosysctl "github.com/lorenzosaino/go-sysctl"
"github.com/songgao/packets/ethernet"
"github.com/songgao/water"
"github.com/songgao/water/waterutil"
@ -88,8 +89,12 @@ func LinkTap(cSess *sessdata.ConnSession) error {
return err
}
cmdstr3 := fmt.Sprintf("sysctl -w net.ipv6.conf.%s.disable_ipv6=1", ifce.Name())
execCmd([]string{cmdstr3})
// cmdstr3 := fmt.Sprintf("sysctl -w net.ipv6.conf.%s.disable_ipv6=1", ifce.Name())
// execCmd([]string{cmdstr3})
err = gosysctl.Set(fmt.Sprintf("net.ipv6.conf.%s.disable_ipv6", ifce.Name()), "1")
if err != nil {
base.Warn(err)
}
go allTapRead(ifce, cSess)
go allTapWrite(ifce, cSess)

View File

@ -7,6 +7,7 @@ import (
"github.com/bjdgyc/anylink/pkg/utils"
"github.com/bjdgyc/anylink/sessdata"
"github.com/coreos/go-iptables/iptables"
gosysctl "github.com/lorenzosaino/go-sysctl"
"github.com/songgao/water"
)
@ -100,8 +101,12 @@ func LinkTun(cSess *sessdata.ConnSession) error {
return err
}
cmdstr3 := fmt.Sprintf("sysctl -w net.ipv6.conf.%s.disable_ipv6=1", ifce.Name())
execCmd([]string{cmdstr3})
// cmdstr3 := fmt.Sprintf("sysctl -w net.ipv6.conf.%s.disable_ipv6=1", ifce.Name())
// execCmd([]string{cmdstr3})
err = gosysctl.Set(fmt.Sprintf("net.ipv6.conf.%s.disable_ipv6", ifce.Name()), "1")
if err != nil {
base.Warn(err)
}
go tunRead(ifce, cSess)
go tunWrite(ifce, cSess)

View File

@ -11,6 +11,7 @@ import (
"github.com/bjdgyc/anylink/base"
"github.com/bjdgyc/anylink/pkg/utils"
"github.com/bjdgyc/anylink/sessdata"
gosysctl "github.com/lorenzosaino/go-sysctl"
)
// link vtap
@ -64,8 +65,12 @@ func LinkMacvtap(cSess *sessdata.ConnSession) error {
base.Error(err)
return err
}
cmdstr3 := fmt.Sprintf("sysctl -w net.ipv6.conf.%s.disable_ipv6=1", ifName)
execCmd([]string{cmdstr3})
// cmdstr3 := fmt.Sprintf("sysctl -w net.ipv6.conf.%s.disable_ipv6=1", ifName)
// execCmd([]string{cmdstr3})
err = gosysctl.Set(fmt.Sprintf("net.ipv6.conf.%s.disable_ipv6", ifName), "1")
if err != nil {
base.Warn(err)
}
return createVtap(cSess, ifName)
}