optimize: disable send_redirects for Real Direct

This commit is contained in:
mzz2017
2023-02-26 05:07:42 +08:00
parent 5cf6dca509
commit 27d77d2b42
7 changed files with 71 additions and 14 deletions

View File

@ -87,12 +87,16 @@ 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 {
if os.IsNotExist(err) {
// Kernel does not support.
return nil
}
return err
}
if bytes.Equal(bytes.TrimSpace(b), []byte("1")) {
return nil
}
return fmt.Errorf("ipforward on %v is off: %v; see https://github.com/v2rayA/dae#enable-ip-forwarding", ifname, path)
return fmt.Errorf("ipforward on %v is off: %v; see https://github.com/v2rayA/dae#kernel-parameters", ifname, path)
}
func CheckIpforward(ifname string) error {
@ -105,6 +109,32 @@ func CheckIpforward(ifname string) error {
return nil
}
func checkSendRedirects(ifname string, ipversion consts.IpVersionStr) error {
path := fmt.Sprintf("/proc/sys/net/ipv%v/conf/%v/send_redirects", ipversion, ifname)
b, err := os.ReadFile(path)
if err != nil {
if os.IsNotExist(err) {
// Kernel does not support.
return nil
}
return err
}
if bytes.Equal(bytes.TrimSpace(b), []byte("0")) {
return nil
}
return fmt.Errorf("send_directs on %v is on: %v; see https://github.com/v2rayA/dae#kernel-parameters", ifname, path)
}
func CheckSendRedirects(ifname string) error {
if err := checkSendRedirects(ifname, consts.IpVersionStr_4); err != nil {
return err
}
if err := checkSendRedirects(ifname, consts.IpVersionStr_6); err != nil {
return err
}
return nil
}
func MagicNetwork(network string, mark uint32) string {
if mark == 0 {
return network