Skip to content

Commit

Permalink
Set Mark for outbound proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
zonyitoo authored and Max Lv committed May 6, 2021
1 parent 7bd24b2 commit ddd7ab4
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ var (
server = flag.Bool("server", false, "Run in server mode")
logLevel = flag.String("loglevel", "", "loglevel for v2ray: debug, info, warning (default), error, none.")
version = flag.Bool("version", false, "Show current version of v2ray-plugin")
fwmark = flag.Int("fwmark", 0, "Set SO_MARK option for outbound sockets.")
)

func homeDir() string {
Expand Down Expand Up @@ -150,8 +151,16 @@ func generateConfig() (*core.Config, error) {
Settings: serial.ToTypedMessage(transportSettings),
}},
}
if *fastOpen {
streamConfig.SocketSettings = &internet.SocketConfig{Tfo: internet.SocketConfig_Enable}
if *fastOpen || *fwmark != 0 {
socketConfig := &internet.SocketConfig{}
if *fastOpen {
socketConfig.Tfo = internet.SocketConfig_Enable
}
if *fwmark != 0 {
socketConfig.Mark = int32(*fwmark)
}

streamConfig.SocketSettings = socketConfig
}
if *tlsEnabled {
tlsConfig := tls.Config{ServerName: *host}
Expand Down Expand Up @@ -325,6 +334,14 @@ func startV2Ray() (core.Server, error) {
*vpn = true
}

if c, b := opts.Get("fwmark"); b {
if i, err := strconv.Atoi(c); err == nil {
*fwmark = i
} else {
logWarn("failed to parse fwmark, use default value")
}
}

if *vpn {
registerControlFunc()
}
Expand Down

0 comments on commit ddd7ab4

Please sign in to comment.