forked from fossabot/clash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e622d8d
commit bd2ea2b
Showing
11 changed files
with
119 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//go:build linux | ||
// +build linux | ||
|
||
package dialer | ||
|
||
import ( | ||
"net" | ||
"syscall" | ||
) | ||
|
||
func bindMarkToDialer(mark int, dialer *net.Dialer, _ string, _ net.IP) { | ||
dialer.Control = bindMarkToControl(mark, dialer.Control) | ||
} | ||
|
||
func bindMarkToListenConfig(mark int, lc *net.ListenConfig, _, address string) { | ||
lc.Control = bindMarkToControl(mark, lc.Control) | ||
} | ||
|
||
func bindMarkToControl(mark int, chain controlFn) controlFn { | ||
return func(network, address string, c syscall.RawConn) (err error) { | ||
defer func() { | ||
if err == nil && chain != nil { | ||
err = chain(network, address, c) | ||
} | ||
}() | ||
|
||
ipStr, _, err := net.SplitHostPort(address) | ||
if err == nil { | ||
ip := net.ParseIP(ipStr) | ||
if ip != nil && !ip.IsGlobalUnicast() { | ||
return | ||
} | ||
} | ||
|
||
return c.Control(func(fd uintptr) { | ||
switch network { | ||
case "tcp4", "udp4": | ||
syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_MARK, mark) | ||
case "tcp6", "udp6": | ||
syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_MARK, mark) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//go:build !linux | ||
// +build !linux | ||
|
||
package dialer | ||
|
||
import ( | ||
"net" | ||
"sync" | ||
|
||
"github.com/Dreamacro/clash/log" | ||
) | ||
|
||
var printMarkWarnOnce sync.Once | ||
|
||
func printMarkWarn() { | ||
printMarkWarnOnce.Do(func() { | ||
log.Warnln("Routing mark on socket is not supported on current platform") | ||
}) | ||
} | ||
|
||
func bindMarkToDialer(mark int, dialer *net.Dialer, _ string, _ net.IP) { | ||
printMarkWarn() | ||
} | ||
|
||
func bindMarkToListenConfig(mark int, lc *net.ListenConfig, _, address string) { | ||
printMarkWarn() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters