This commit is contained in:
arm64v8a
2022-08-24 14:48:20 +08:00
parent ffef5ab07e
commit c991be78a7
2 changed files with 27 additions and 0 deletions

View File

@@ -72,6 +72,7 @@ func ServeProtect(path string, fwmark int) {
log.Println("getOneFd:", err) log.Println("getOneFd:", err)
return return
} }
defer syscall.Close(fd)
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_MARK, fwmark); err != nil { if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_MARK, fwmark); err != nil {
log.Println("syscall.SetsockoptInt:", err) log.Println("syscall.SetsockoptInt:", err)

View File

@@ -2,9 +2,13 @@ package main
import ( import (
"flag" "flag"
"io"
"log" "log"
"nekoray_core/protect_server" "nekoray_core/protect_server"
"net"
"net/http"
"os" "os"
"syscall"
"github.com/jsimonetti/rtnetlink" "github.com/jsimonetti/rtnetlink"
linuxcap "kernel.org/pub/linux/libs/security/libcap/cap" linuxcap "kernel.org/pub/linux/libs/security/libcap/cap"
@@ -63,5 +67,27 @@ func ToolBox() {
log.Println(protectListenPath, protectFwMark) log.Println(protectListenPath, protectFwMark)
protect_server.ServeProtect(protectListenPath, protectFwMark) protect_server.ServeProtect(protectListenPath, protectFwMark)
} }
case "btd": // Test the permission
{
d := &net.Dialer{
Control: func(network, address string, c syscall.RawConn) (err error) {
c.Control(func(fd uintptr) {
err = syscall.BindToDevice(int(fd), os.Args[3])
})
return
},
}
c := http.Client{
Transport: &http.Transport{
DialContext: d.DialContext,
},
}
resp, err := c.Get(os.Args[4])
if err != nil {
log.Fatalln(err)
}
io.Copy(os.Stdout, resp.Body)
resp.Body.Close()
}
} }
} }