Skip to content

Commit 981cfa7

Browse files
committed
tunnel: linkmtu, tunmtu as separate inputs
1 parent 6d1c431 commit 981cfa7

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

intra/tun2socks.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,30 +66,34 @@ func init() {
6666
// Connect creates firestack-administered tunnel.
6767
// `fd` is the TUN device. The tunnel acquires an additional reference to it, which is
6868
// released by Disconnect(), so the caller must close `fd` and Disconnect() to close the TUN device.
69-
// `mtu` is the MTU of the TUN device.
69+
// `linkmtu` is the MTU of the underlying link (actual network). If <= 0, it is assumed to be same as `tunmtu`.
70+
// `tunmtu` is the MTU of the TUN device. This can be "faked", ie set to values larger than linkmtu. Typically, its value is same as `linkmtu`.
7071
// `ifaddrs` is a comma-separated list of interface addresses with prefix lengths, "ip/prefixlen".
7172
// `fakedns` is a comman-separated list of the nameservers that the system believes it is using, in "host:port" style.
7273
// `bdg` is a kotlin object that implements the Bridge interface.
7374
// `dtr` is the DefaultDNS (see: intra.NewDefaultDNS); can be nil. Changeable via intra.AddDefaultTransport.
7475
// Throws an exception if the TUN file descriptor cannot be opened, or if the tunnel fails to
7576
// connect.
76-
func Connect(fd, mtu int, ifaddrs, fakedns string, dtr DefaultDNS, bdg Bridge) (t Tunnel, err error) {
77-
return NewTunnel(fd, mtu, ifaddrs, fakedns, dtr, bdg)
77+
func Connect(fd, linkmtu, tunmtu int, ifaddrs, fakedns string, dtr DefaultDNS, bdg Bridge) (t Tunnel, err error) {
78+
if linkmtu <= 0 {
79+
NewTunnel(fd, tunmtu, ifaddrs, fakedns, dtr, bdg)
80+
}
81+
return NewTunnel2(fd, linkmtu, tunmtu, ifaddrs, fakedns, dtr, bdg)
7882
}
7983

80-
// Connect2 is like Connect, but assumes defaults for ifaddrs and fakedns
81-
// as ["10.111.222.1/24", "fd66:f83a:c650::0/120"] and ["10.111.222.3", "fd66:f83a:c650::3"]
84+
// Connect2 is like Connect, but assumes defaults for linkmtu, ifaddrs, and fakedns
85+
// as -1, ["10.111.222.1/24", "fd66:f83a:c650::0/120"], and ["10.111.222.3", "fd66:f83a:c650::3"]
8286
// respectively.
83-
func Connect2(fd, mtu int, dtr DefaultDNS, bdg Bridge) (t Tunnel, err error) {
87+
func Connect2(fd, tunmtu int, dtr DefaultDNS, bdg Bridge) (t Tunnel, err error) {
8488
// usually, 10.111.222.0/24 / [fd66:f83a:c650::0]/120
8589
// github.com/celzero/rethink-app/blob/59aa0daae/app/src/main/java/com/celzero/bravedns/service/BraveVPNService.kt#L2813
86-
return NewTunnel(fd, mtu, "10.111.222.1/24,fd66:f83a:c650::0/120", "10.111.222.3,fd66:f83a:c650::3", nil, bdg)
90+
return Connect(fd, -1, tunmtu, "10.111.222.1/24,fd66:f83a:c650::0/120", "10.111.222.3,fd66:f83a:c650::3", nil, bdg)
8791
}
8892

8993
// Connect3 is like Connect2, but does not require passing a Default DNS resolver.
9094
// The tunnel will instead attempt to use the system DNS resolver (best effort).
91-
func Connect3(fd, mtu int, bdg Bridge) (t Tunnel, err error) {
92-
return Connect2(fd, mtu, nil, bdg)
95+
func Connect3(fd, tunmtu int, bdg Bridge) (t Tunnel, err error) {
96+
return Connect2(fd, tunmtu, nil, bdg)
9397
}
9498

9599
// ControlledRouter creates a [backend.Router] over a [backend.Internet] proxy (like [backend.Exit]),

0 commit comments

Comments
 (0)