[fix]
This commit is contained in:
parent
e1a1f87dd4
commit
0ecc9f4941
6 changed files with 10 additions and 7 deletions
|
@ -79,7 +79,7 @@ func patchConfigs(w http.ResponseWriter, r *http.Request) {
|
||||||
P.ReCreateMixed(pointerOrDefault(general.MixedPort, ports.MixedPort), tcpIn, udpIn)
|
P.ReCreateMixed(pointerOrDefault(general.MixedPort, ports.MixedPort), tcpIn, udpIn)
|
||||||
|
|
||||||
if general.Tun != nil {
|
if general.Tun != nil {
|
||||||
err := P.ReCreateTun(*general.Tun, nil, nil)
|
err := P.ReCreateTun(*general.Tun, tcpIn, udpIn)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.Infoln("Recreate tun success.")
|
log.Infoln("Recreate tun success.")
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package dev
|
package dev
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
|
@ -49,8 +50,10 @@ func addLinuxSystemRoute(net string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
cmd := exec.Command("route", "add", "-net", net, "198.18.0.1")
|
cmd := exec.Command("route", "add", "-net", net, "198.18.0.1")
|
||||||
|
var stderr bytes.Buffer
|
||||||
|
cmd.Stderr = &stderr
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
log.Errorln("[auto route] Failed to add system route: %s, cmd: %s", err.Error(), cmd.String())
|
log.Errorln("[auto route] Failed to add system route: %s: %s , cmd: %s", err.Error(), stderr.String(), cmd.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ type tunLinux struct {
|
||||||
|
|
||||||
// OpenTunDevice return a TunDevice according a URL
|
// OpenTunDevice return a TunDevice according a URL
|
||||||
func OpenTunDevice(tunAddress string, autoRoute bool) (TunDevice, error) {
|
func OpenTunDevice(tunAddress string, autoRoute bool) (TunDevice, error) {
|
||||||
deviceURL, _ := url.Parse("dev://clash0")
|
deviceURL, _ := url.Parse("dev://utun")
|
||||||
mtu, _ := strconv.ParseInt(deviceURL.Query().Get("mtu"), 0, 32)
|
mtu, _ := strconv.ParseInt(deviceURL.Query().Get("mtu"), 0, 32)
|
||||||
|
|
||||||
t := &tunLinux{
|
t := &tunLinux{
|
||||||
|
@ -204,7 +204,7 @@ func (t *tunLinux) configInterface() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// set netmask for tun
|
// set netmask for tun
|
||||||
netmask := []byte{255, 255, 255, 0}
|
netmask := []byte{255, 255, 0, 0}
|
||||||
copy(ifr[unix.IFNAMSIZ+4:], netmask)
|
copy(ifr[unix.IFNAMSIZ+4:], netmask)
|
||||||
|
|
||||||
_, _, errno = unix.Syscall(
|
_, _, errno = unix.Syscall(
|
||||||
|
|
|
@ -50,7 +50,7 @@ func OpenTunDevice(tunAddress string, autoRoute bool) (TunDevice, error) {
|
||||||
log.Warnln("Error parese GUID from string: %v", err)
|
log.Warnln("Error parese GUID from string: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
interfaceName := "Clash.Mini"
|
interfaceName := "Meta Tunnel"
|
||||||
mtu := 9000
|
mtu := 9000
|
||||||
|
|
||||||
tun, err := CreateTUN(interfaceName, mtu, tunAddress, autoRoute)
|
tun, err := CreateTUN(interfaceName, mtu, tunAddress, autoRoute)
|
||||||
|
|
|
@ -48,7 +48,7 @@ type gvisorAdapter struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GvisorAdapter create GvisorAdapter
|
// GvisorAdapter create GvisorAdapter
|
||||||
func NewAdapter(device dev.TunDevice, conf config.Tun, tunAddress string, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.PacketAdapter) (ipstack.TunAdapter, error) {
|
func NewAdapter(device dev.TunDevice, conf config.Tun, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.PacketAdapter) (ipstack.TunAdapter, error) {
|
||||||
ipstack := stack.New(stack.Options{
|
ipstack := stack.New(stack.Options{
|
||||||
NetworkProtocols: []stack.NetworkProtocolFactory{ipv4.NewProtocol, ipv6.NewProtocol},
|
NetworkProtocols: []stack.NetworkProtocolFactory{ipv4.NewProtocol, ipv6.NewProtocol},
|
||||||
TransportProtocols: []stack.TransportProtocolFactory{tcp.NewProtocol, udp.NewProtocol},
|
TransportProtocols: []stack.TransportProtocolFactory{tcp.NewProtocol, udp.NewProtocol},
|
||||||
|
|
|
@ -47,7 +47,7 @@ func New(conf config.Tun, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.Pack
|
||||||
if strings.EqualFold(stack, "system") {
|
if strings.EqualFold(stack, "system") {
|
||||||
tunAdapter, err = system.NewAdapter(device, conf, mtu, tunAddress, tunAddress, func() {}, tcpIn, udpIn)
|
tunAdapter, err = system.NewAdapter(device, conf, mtu, tunAddress, tunAddress, func() {}, tcpIn, udpIn)
|
||||||
} else if strings.EqualFold(stack, "gvisor") {
|
} else if strings.EqualFold(stack, "gvisor") {
|
||||||
tunAdapter, err = gvisor.NewAdapter(device, conf, tunAddress, tcpIn, udpIn)
|
tunAdapter, err = gvisor.NewAdapter(device, conf, tcpIn, udpIn)
|
||||||
} else {
|
} else {
|
||||||
err = fmt.Errorf("can not support tun ip stack: %s, only support \"lwip\" \"system\" and \"gvisor\"", stack)
|
err = fmt.Errorf("can not support tun ip stack: %s, only support \"lwip\" \"system\" and \"gvisor\"", stack)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue