Skip to content

Commit 6769085

Browse files
committed
Test disable firewall for interface
1 parent 209ec12 commit 6769085

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

system.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"net"
66
"net/netip"
7+
"runtime"
78
"syscall"
89
"time"
910

@@ -97,6 +98,12 @@ func (s *System) Close() error {
9798
}
9899

99100
func (s *System) Start() error {
101+
if runtime.GOOS == "windows" {
102+
err := fixFirewall()
103+
if err != nil {
104+
return E.Cause(err, "fix windows firewall for system stack")
105+
}
106+
}
100107
var listener net.ListenConfig
101108
if s.bindInterface {
102109
listener.Control = control.Append(listener.Control, func(network, address string, conn syscall.RawConn) error {

system_windows.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package tun
2+
3+
import (
4+
E "github.com/sagernet/sing/common/exceptions"
5+
"os"
6+
7+
"github.com/sagernet/sing/common/shell"
8+
)
9+
10+
func fixFirewall() error {
11+
profiles := []string{"Public", "Private"}
12+
for _, profile := range profiles {
13+
output, err := shell.Exec("powershell.exe",
14+
"New-NetFirewallRule", "-DisplayName", "sing-box: allow system tun stack for path "+os.Args[0],
15+
"-Direction", "Inbound",
16+
"-Program", os.Args[0],
17+
"-Action", "Allow",
18+
"-Profile", profile,
19+
).CombinedOutput()
20+
if err != nil {
21+
return E.Extend(err, output)
22+
}
23+
}
24+
return nil
25+
}

0 commit comments

Comments
 (0)