fix: OpenClash 回环
This commit is contained in:
parent
c95735f083
commit
1af39cb228
2 changed files with 7 additions and 23 deletions
|
@ -38,7 +38,9 @@ func FindUid(network string, srcIP netip.Addr, srcPort int) (int32, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ShouldFindProcess(metadata *C.Metadata) bool {
|
func ShouldFindProcess(metadata *C.Metadata) bool {
|
||||||
if !enableFindProcess || metadata.Process != "" || metadata.ProcessPath != "" {
|
if !enableFindProcess ||
|
||||||
|
metadata.Process != "" ||
|
||||||
|
metadata.ProcessPath != "" {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for _, ip := range localIPs {
|
for _, ip := range localIPs {
|
||||||
|
|
|
@ -4,7 +4,6 @@ package commons
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Dreamacro/clash/common/cmd"
|
|
||||||
"github.com/Dreamacro/clash/listener/tun/device"
|
"github.com/Dreamacro/clash/listener/tun/device"
|
||||||
"github.com/vishvananda/netlink"
|
"github.com/vishvananda/netlink"
|
||||||
"net"
|
"net"
|
||||||
|
@ -46,12 +45,12 @@ func ConfigInterfaceAddress(dev device.Device, addr netip.Prefix, forceMTU int,
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
naddr, err := netlink.ParseAddr(addr.String())
|
nlAddr, err := netlink.ParseAddr(addr.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = netlink.AddrAdd(metaLink, naddr); err != nil && err.Error() != "file exists" {
|
if err = netlink.AddrAdd(metaLink, nlAddr); err != nil && err.Error() != "file exists" {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,23 +58,13 @@ func ConfigInterfaceAddress(dev device.Device, addr netip.Prefix, forceMTU int,
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = netlink.RouteAdd(&netlink.Route{
|
|
||||||
LinkIndex: metaLink.Attrs().Index,
|
|
||||||
Scope: netlink.SCOPE_LINK,
|
|
||||||
Protocol: 2,
|
|
||||||
Src: ip.AsSlice(),
|
|
||||||
Table: 254,
|
|
||||||
}); err != nil && err.Error() != "file exists" {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if autoRoute {
|
if autoRoute {
|
||||||
_ = configInterfaceRouting(metaLink.Attrs().Index, interfaceName, ip)
|
_ = configInterfaceRouting(metaLink.Attrs().Index, ip)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func configInterfaceRouting(index int, interfaceName string, ip netip.Addr) error {
|
func configInterfaceRouting(index int, ip netip.Addr) error {
|
||||||
for _, route := range defaultRoutes {
|
for _, route := range defaultRoutes {
|
||||||
_, ipn, err := net.ParseCIDR(route)
|
_, ipn, err := net.ParseCIDR(route)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -97,11 +86,4 @@ func configInterfaceRouting(index int, interfaceName string, ip netip.Addr) erro
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func execRouterCmd(action, route, interfaceName, linkIP, table string) error {
|
|
||||||
cmdStr := fmt.Sprintf("ip route %s %s dev %s proto kernel scope link src %s table %s", action, route, interfaceName, linkIP, table)
|
|
||||||
|
|
||||||
_, err := cmd.ExecCmd(cmdStr)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func CleanupRule() {}
|
func CleanupRule() {}
|
||||||
|
|
Loading…
Reference in a new issue