Browse Source

Merge pull request #334 from ivulit/master

tags/v2.1.11^2^2
Sergei Arkhipov 2 months ago
parent
commit
45ce5c2f61
No account linked to committer's email address

+ 8
- 0
example.config.toml View File

@@ -59,6 +59,14 @@ prefer-ip = "prefer-ipv6"
59 59
 # access.
60 60
 domain-fronting-port = 443
61 61
 
62
+# By default, mtg resolves the fronting hostname (from the secret) via DNS
63
+# to establish a TCP connection. If DNS resolution of that hostname is blocked,
64
+# you can specify an IP address to connect to directly. The hostname is still
65
+# used for SNI in the TLS handshake.
66
+#
67
+# default value is not set (DNS resolution is used).
68
+# domain-fronting-ip = "142.250.185.112"
69
+
62 70
 # FakeTLS can compare timestamps to prevent probes. Each message has
63 71
 # encrypted timestamp. So, mtg can compare this timestamp and decide if
64 72
 # we need to proceed with connection or not.

+ 1
- 0
internal/cli/run_proxy.go View File

@@ -260,6 +260,7 @@ func runProxy(conf *config.Config, version string) error { //nolint: funlen
260 260
 
261 261
 		Secret:             conf.Secret,
262 262
 		DomainFrontingPort: conf.DomainFrontingPort.Get(mtglib.DefaultDomainFrontingPort),
263
+		DomainFrontingIP:   conf.DomainFrontingIP.String(),
263 264
 		PreferIP:           conf.PreferIP.Get(mtglib.DefaultPreferIP),
264 265
 
265 266
 		AllowFallbackOnUnknownDC: conf.AllowFallbackOnUnknownDC.Get(false),

+ 7
- 0
internal/cli/simple_run.go View File

@@ -18,6 +18,7 @@ type SimpleRun struct {
18 18
 	TCPBuffer           string        `kong:"name='tcp-buffer',short='b',default='4KB',help='Deprecated and ignored'"`                                                 //nolint: lll
19 19
 	PreferIP            string        `kong:"name='prefer-ip',short='i',default='prefer-ipv6',help='IP preference. By default we prefer IPv6 with fallback to IPv4.'"` //nolint: lll
20 20
 	DomainFrontingPort  uint64        `kong:"name='domain-fronting-port',short='p',default='443',help='A port to access for domain fronting.'"`                        //nolint: lll
21
+	DomainFrontingIP    string        `kong:"name='domain-fronting-ip',help='An IP address to use for domain fronting instead of resolving the hostname via DNS.'"`       //nolint: lll
21 22
 	DOHIP               net.IP        `kong:"name='doh-ip',short='n',default='1.1.1.1',help='IP address of DNS-over-HTTP to use.'"`                                    //nolint: lll
22 23
 	Timeout             time.Duration `kong:"name='timeout',short='t',default='10s',help='Network timeout to use'"`                                                    //nolint: lll
23 24
 	Socks5Proxies       []string      `kong:"name='socks5-proxy',short='s',help='Socks5 proxies to use for network access.'"`                                          //nolint: lll
@@ -47,6 +48,12 @@ func (s *SimpleRun) Run(cli *CLI, version string) error { //nolint: cyclop,funle
47 48
 		return fmt.Errorf("incorrect domain-fronting-port: %w", err)
48 49
 	}
49 50
 
51
+	if s.DomainFrontingIP != "" {
52
+		if err := conf.DomainFrontingIP.Set(s.DomainFrontingIP); err != nil {
53
+			return fmt.Errorf("incorrect domain-fronting-ip: %w", err)
54
+		}
55
+	}
56
+
50 57
 	if err := conf.Network.DOHIP.Set(s.DOHIP.String()); err != nil {
51 58
 		return fmt.Errorf("incorrect doh-ip: %w", err)
52 59
 	}

+ 1
- 0
internal/config/config.go View File

@@ -28,6 +28,7 @@ type Config struct {
28 28
 	ProxyProtocolListener    TypeBool        `json:"proxyProtocolListener"`
29 29
 	PreferIP                 TypePreferIP    `json:"preferIp"`
30 30
 	DomainFrontingPort       TypePort        `json:"domainFrontingPort"`
31
+	DomainFrontingIP         TypeIP          `json:"domainFrontingIp"`
31 32
 	TolerateTimeSkewness     TypeDuration    `json:"tolerateTimeSkewness"`
32 33
 	Concurrency              TypeConcurrency `json:"concurrency"`
33 34
 	Defense                  struct {

+ 1
- 0
internal/config/parse.go View File

@@ -16,6 +16,7 @@ type tomlConfig struct {
16 16
 	ProxyProtocolListener    bool   `toml:"proxy-protocol-listener" json:"proxyProtocolListener"`
17 17
 	PreferIP                 string `toml:"prefer-ip" json:"preferIp,omitempty"`
18 18
 	DomainFrontingPort       uint   `toml:"domain-fronting-port" json:"domainFrontingPort,omitempty"`
19
+	DomainFrontingIP         string `toml:"domain-fronting-ip" json:"domainFrontingIp,omitempty"`
19 20
 	TolerateTimeSkewness     string `toml:"tolerate-time-skewness" json:"tolerateTimeSkewness,omitempty"`
20 21
 	Concurrency              uint   `toml:"concurrency" json:"concurrency,omitempty"`
21 22
 	Defense                  struct {

+ 9
- 1
mtglib/proxy.go View File

@@ -27,6 +27,7 @@ type Proxy struct {
27 27
 	allowFallbackOnUnknownDC bool
28 28
 	tolerateTimeSkewness     time.Duration
29 29
 	domainFrontingPort       int
30
+	domainFrontingIP         string
30 31
 	workerPool               *ants.PoolWithFunc
31 32
 	telegram                 *dc.Telegram
32 33
 
@@ -40,8 +41,14 @@ type Proxy struct {
40 41
 }
41 42
 
42 43
 // DomainFrontingAddress returns a host:port pair for a fronting domain.
44
+// If DomainFrontingIP is set, it is used instead of resolving the hostname.
43 45
 func (p *Proxy) DomainFrontingAddress() string {
44
-	return net.JoinHostPort(p.secret.Host, strconv.Itoa(p.domainFrontingPort))
46
+	host := p.secret.Host
47
+	if p.domainFrontingIP != "" {
48
+		host = p.domainFrontingIP
49
+	}
50
+
51
+	return net.JoinHostPort(host, strconv.Itoa(p.domainFrontingPort))
45 52
 }
46 53
 
47 54
 // ServeConn serves a connection. We do not check IP blocklist and concurrency
@@ -317,6 +324,7 @@ func NewProxy(opts ProxyOpts) (*Proxy, error) {
317 324
 		eventStream:              opts.EventStream,
318 325
 		logger:                   opts.getLogger("proxy"),
319 326
 		domainFrontingPort:       opts.getDomainFrontingPort(),
327
+		domainFrontingIP:         opts.DomainFrontingIP,
320 328
 		tolerateTimeSkewness:     opts.getTolerateTimeSkewness(),
321 329
 		allowFallbackOnUnknownDC: opts.AllowFallbackOnUnknownDC,
322 330
 		telegram:                 tg,

+ 9
- 0
mtglib/proxy_opts.go View File

@@ -93,6 +93,15 @@ type ProxyOpts struct {
93 93
 	// This is an optional setting.
94 94
 	DomainFrontingPort uint
95 95
 
96
+	// DomainFrontingIP is an IP address to use when connecting to the fronting
97
+	// domain instead of resolving the hostname from the secret via DNS.
98
+	//
99
+	// This is useful when DNS resolution of the fronting host is blocked.
100
+	// The hostname from the secret is still used for SNI in the TLS handshake.
101
+	//
102
+	// This is an optional setting.
103
+	DomainFrontingIP string
104
+
96 105
 	// AllowFallbackOnUnknownDC defines how proxy behaves if unknown DC was
97 106
 	// requested. If this setting is set to false, then such connection will be
98 107
 	// rejected. Otherwise, proxy will chose any DC.

Loading…
Cancel
Save