Skip to content
Snippets Groups Projects
Commit 0d9078d6 authored by David Fifield's avatar David Fifield
Browse files

Dial the (Ext)ORPort with a random srcaddr in 127.0.5.0/24.

This is a hack to attempt to conserve emphemeral port numbers.
snowflake#40201 (comment 2839394)
parent a3913ad2
No related branches found
No related tags found
No related merge requests found
......@@ -3,3 +3,5 @@ module gitlab.torproject.org/dcf/extor-static-cookie
go 1.15
require git.torproject.org/pluggable-transports/goptlib.git v1.2.0
replace git.torproject.org/pluggable-transports/goptlib.git v1.2.0 => gitlab.torproject.org/dcf/goptlib v0.0.0-20220930193603-cd79bbc900ad
......@@ -25,6 +25,7 @@ import (
"fmt"
"io"
"io/ioutil"
"math/rand"
"net"
"os"
"os/signal"
......@@ -160,13 +161,29 @@ func handler(conn *net.TCPConn, ptInfo *pt.ServerInfo, cookie authCookie) error
return err
}
or, err := pt.DialOr(ptInfo, metadata.Useraddr, metadata.Transport)
or, err := pt.DialOrWithDialer(&net.Dialer{
LocalAddr: localAddr(),
}, ptInfo, metadata.Useraddr, metadata.Transport)
if err != nil {
return err
}
defer or.Close()
return proxy(conn, or)
return proxy(conn, or.(*net.TCPConn))
}
// localAddr returns a random localhost IP address, suitable to be used as the
// LocalAddr in a net.Dialer in a call to pt.DialOrWithDialer.
//
// The reason for using multiple source addresses when dialing the ORPort is to
// conserve ephemeral ports:
// https://bugs.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/40198
func localAddr() net.Addr {
var b byte
for b == 0 {
b = byte(rand.Uint32())
}
return &net.TCPAddr{IP: net.IPv4(127, 0, 5, b)}
}
// proxy copies from a to b and from b to a, persisting until both copies have
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment