mirror of
https://github.com/daeuniverse/dae.git
synced 2025-01-22 02:07:50 +07:00
feat: add ipforward check
This commit is contained in:
parent
c54a5a0c30
commit
e758f332d2
@ -105,14 +105,14 @@ func Run(log *logrus.Logger, param *config.Params) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func readConfig(cfgFile string) (params *config.Params, entries []string, err error) {
|
||||
func readConfig(cfgFile string) (params *config.Params, includes []string, err error) {
|
||||
merger := config.NewMerger(cfgFile)
|
||||
sections, entries, err := merger.Merge()
|
||||
sections, includes, err := merger.Merge()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if params, err = config.New(sections); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return params, entries, nil
|
||||
return params, includes, nil
|
||||
}
|
||||
|
@ -226,6 +226,10 @@ tryRuleAddAgain:
|
||||
}
|
||||
|
||||
func (c *ControlPlaneCore) bindLan(ifname string) error {
|
||||
err := CheckIpforward(ifname)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.log.Infof("Bind to LAN: %v", ifname)
|
||||
link, err := netlink.LinkByName(ifname)
|
||||
if err != nil {
|
||||
|
@ -6,6 +6,7 @@
|
||||
package control
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"github.com/v2rayA/dae/common"
|
||||
@ -13,6 +14,7 @@ import (
|
||||
internal "github.com/v2rayA/dae/pkg/ebpf_internal"
|
||||
"golang.org/x/sys/unix"
|
||||
"net/netip"
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
@ -60,3 +62,25 @@ func RetrieveOriginalDest(oob []byte) netip.AddrPort {
|
||||
}
|
||||
return netip.AddrPort{}
|
||||
}
|
||||
|
||||
func checkIpforward(ifname string, ipversion consts.IpVersionStr) error {
|
||||
path := fmt.Sprintf("/proc/sys/net/ipv%v/conf/%v/forwarding", ipversion, ifname)
|
||||
b, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if bytes.Equal(bytes.TrimSpace(b), []byte("1")) {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("ipforward on %v is off: %v", ifname, path)
|
||||
}
|
||||
|
||||
func CheckIpforward(ifname string) error {
|
||||
if err := checkIpforward(ifname, consts.IpVersionStr_4); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := checkIpforward(ifname, consts.IpVersionStr_6); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user