设置 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/bjdgyc/anylink/sessdata"
"github.com/google/gopacket" "github.com/google/gopacket"
"github.com/google/gopacket/layers" "github.com/google/gopacket/layers"
gosysctl "github.com/lorenzosaino/go-sysctl"
"github.com/songgao/packets/ethernet" "github.com/songgao/packets/ethernet"
"github.com/songgao/water" "github.com/songgao/water"
"github.com/songgao/water/waterutil" "github.com/songgao/water/waterutil"
@ -88,8 +89,12 @@ func LinkTap(cSess *sessdata.ConnSession) error {
return err return err
} }
cmdstr3 := fmt.Sprintf("sysctl -w net.ipv6.conf.%s.disable_ipv6=1", ifce.Name()) // cmdstr3 := fmt.Sprintf("sysctl -w net.ipv6.conf.%s.disable_ipv6=1", ifce.Name())
execCmd([]string{cmdstr3}) // 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 allTapRead(ifce, cSess)
go allTapWrite(ifce, cSess) go allTapWrite(ifce, cSess)

View File

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

View File

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