forked from riobard/go-shadowsocks2
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
tcp_linux.go
28 lines (23 loc) · 922 Bytes
/
tcp_linux.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package main
import (
"net"
"github.com/shadowsocks/go-shadowsocks2/nfutil"
"github.com/shadowsocks/go-shadowsocks2/socks"
)
func getOrigDst(c net.Conn, ipv6 bool) (socks.Addr, error) {
if tc, ok := c.(*net.TCPConn); ok {
addr, err := nfutil.GetOrigDst(tc, ipv6)
return socks.ParseAddr(addr.String()), err
}
panic("not a TCP connection")
}
// Listen on addr for netfilter redirected TCP connections
func redirLocal(addr, server string, shadow func(net.Conn) net.Conn) {
logf("TCP redirect %s <-> %s", addr, server)
tcpLocal(addr, server, shadow, func(c net.Conn) (socks.Addr, error) { return getOrigDst(c, false) })
}
// Listen on addr for netfilter redirected TCP IPv6 connections.
func redir6Local(addr, server string, shadow func(net.Conn) net.Conn) {
logf("TCP6 redirect %s <-> %s", addr, server)
tcpLocal(addr, server, shadow, func(c net.Conn) (socks.Addr, error) { return getOrigDst(c, true) })
}