Skip to content

Commit 5a6d9f6

Browse files
authored
Merge pull request #4092 from fatedier/dev
bump v0.56.0
2 parents a5b7abf + f16ef00 commit 5a6d9f6

32 files changed

+317
-57
lines changed

.github/workflows/golangci-lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
uses: golangci/golangci-lint-action@v4
2424
with:
2525
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
26-
version: v1.56
26+
version: v1.57
2727

2828
# Optional: golangci-lint command line arguments.
2929
# args: --issues-exit-code=0

.golangci.yml

+9-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
service:
2-
golangci-lint-version: 1.56.x # use the fixed version to not introduce new linters unexpectedly
2+
golangci-lint-version: 1.57.x # use the fixed version to not introduce new linters unexpectedly
33

44
run:
55
concurrency: 4
@@ -8,23 +8,6 @@ run:
88
build-tags:
99
- integ
1010
- integfuzz
11-
# which dirs to skip: they won't be analyzed;
12-
# can use regexp here: generated.*, regexp is applied on full path;
13-
# default value is empty list, but next dirs are always skipped independently
14-
# from this option's value:
15-
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
16-
skip-dirs:
17-
- genfiles$
18-
- vendor$
19-
- bin$
20-
21-
# which files to skip: they will be analyzed, but issues from them
22-
# won't be reported. Default value is empty list, but there is
23-
# no need to include all autogenerated files, we confidently recognize
24-
# autogenerated files. If it's not please let us know.
25-
skip-files:
26-
- ".*\\.pb\\.go"
27-
- ".*\\.gen\\.go"
2811

2912
linters:
3013
disable-all: true
@@ -136,6 +119,14 @@ issues:
136119
- unparam
137120
text: "is always false"
138121

122+
exclude-dirs:
123+
- genfiles$
124+
- vendor$
125+
- bin$
126+
exclude-files:
127+
- ".*\\.pb\\.go"
128+
- ".*\\.gen\\.go"
129+
139130
# Independently from option `exclude` we use default exclude patterns,
140131
# it can be disabled by this option. To list all
141132
# excluded by default patterns execute `golangci-lint run --help`.

Makefile.cross-compiles

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export PATH := $(PATH):`go env GOPATH`/bin
22
export GO111MODULE=on
33
LDFLAGS := -s -w
44

5-
os-archs=darwin:amd64 darwin:arm64 freebsd:amd64 linux:amd64 linux:arm linux:arm64 windows:amd64 windows:arm64 linux:mips64 linux:mips64le linux:mips:softfloat linux:mipsle:softfloat linux:riscv64
5+
os-archs=darwin:amd64 darwin:arm64 freebsd:amd64 linux:amd64 linux:arm linux:arm64 windows:amd64 windows:arm64 linux:mips64 linux:mips64le linux:mips:softfloat linux:mipsle:softfloat linux:riscv64 android:arm64
66

77
all: build
88

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ frp also offers a P2P connect mode.
7878
* [URL Routing](#url-routing)
7979
* [TCP Port Multiplexing](#tcp-port-multiplexing)
8080
* [Connecting to frps via PROXY](#connecting-to-frps-via-proxy)
81+
* [Port range mapping](#port-range-mapping)
8182
* [Client Plugins](#client-plugins)
8283
* [Server Manage Plugins](#server-manage-plugins)
8384
* [SSH Tunnel Gateway](#ssh-tunnel-gateway)
@@ -1158,6 +1159,24 @@ serverPort = 7000
11581159
transport.proxyURL = "http://user:[email protected]:8080"
11591160
```
11601161

1162+
### Port range mapping
1163+
1164+
*Added in v0.56.0*
1165+
1166+
We can use the range syntax of Go template combined with the built-in `parseNumberRangePair` function to achieve port range mapping.
1167+
1168+
The following example, when run, will create 8 proxies named `test-6000, test-6001 ... test-6007`, each mapping the remote port to the local port.
1169+
1170+
```
1171+
{{- range $_, $v := parseNumberRangePair "6000-6006,6007" "6000-6006,6007" }}
1172+
[[proxies]]
1173+
name = "tcp-{{ $v.First }}"
1174+
type = "tcp"
1175+
localPort = {{ $v.First }}
1176+
remotePort = {{ $v.Second }}
1177+
{{- end }}
1178+
```
1179+
11611180
### Client Plugins
11621181

11631182
frpc only forwards requests to local TCP or UDP ports by default.

Release.md

+25-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,25 @@
1-
No feature changes, just a fix for the issue of no released assets in version 0.55.0.
1+
### Features
2+
3+
* Support range ports mapping in TOML/YAML/JSON configuration file by using go template syntax.
4+
5+
For example:
6+
7+
```
8+
{{- range $_, $v := parseNumberRangePair "6000-6006,6007" "6000-6006,6007" }}
9+
[[proxies]]
10+
name = "tcp-{{ $v.First }}"
11+
type = "tcp"
12+
localPort = {{ $v.First }}
13+
remotePort = {{ $v.Second }}
14+
{{- end }}
15+
```
16+
17+
This will create 8 proxies such as `tcp-6000, tcp-6001, ... tcp-6007`.
18+
19+
* Health check supports custom request headers.
20+
* Enable compatibility mode for the Android system to solve the issues of incorrect log time caused by time zone problems and default DNS resolution failures.
21+
22+
### Fixes
23+
24+
* Fix the issue of incorrect interval time for rotating the log by day.
25+
* Disable quic-go's ECN support by default. It may cause issues on certain operating systems.

client/health/health.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ type Monitor struct {
4040
addr string
4141

4242
// For http
43-
url string
44-
43+
url string
44+
header http.Header
4545
failedTimes uint64
4646
statusOK bool
4747
statusNormalFn func()
@@ -73,13 +73,19 @@ func NewMonitor(ctx context.Context, cfg v1.HealthCheckConfig, addr string,
7373
}
7474
url = s + cfg.Path
7575
}
76+
header := make(http.Header)
77+
for _, h := range cfg.HTTPHeaders {
78+
header.Set(h.Name, h.Value)
79+
}
80+
7681
return &Monitor{
7782
checkType: cfg.Type,
7883
interval: time.Duration(cfg.IntervalSeconds) * time.Second,
7984
timeout: time.Duration(cfg.TimeoutSeconds) * time.Second,
8085
maxFailedTimes: cfg.MaxFailed,
8186
addr: addr,
8287
url: url,
88+
header: header,
8389
statusOK: false,
8490
statusNormalFn: statusNormalFn,
8591
statusFailedFn: statusFailedFn,
@@ -163,6 +169,8 @@ func (monitor *Monitor) doHTTPCheck(ctx context.Context) error {
163169
if err != nil {
164170
return err
165171
}
172+
req.Header = monitor.header
173+
req.Host = monitor.header.Get("Host")
166174
resp, err := http.DefaultClient.Do(req)
167175
if err != nil {
168176
return err

client/service.go

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"errors"
2020
"fmt"
2121
"net"
22+
"os"
2223
"runtime"
2324
"sync"
2425
"time"
@@ -40,6 +41,12 @@ import (
4041

4142
func init() {
4243
crypto.DefaultSalt = "frp"
44+
// Disable quic-go's receive buffer warning.
45+
os.Setenv("QUIC_GO_DISABLE_RECEIVE_BUFFER_WARNING", "true")
46+
// Disable quic-go's ECN support by default. It may cause issues on certain operating systems.
47+
if os.Getenv("QUIC_GO_DISABLE_ECN") == "" {
48+
os.Setenv("QUIC_GO_DISABLE_ECN", "true")
49+
}
4350
}
4451

4552
type cancelErr struct {

cmd/frpc/main.go

+2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ package main
1717
import (
1818
_ "github.com/fatedier/frp/assets/frpc"
1919
"github.com/fatedier/frp/cmd/frpc/sub"
20+
"github.com/fatedier/frp/pkg/util/system"
2021
)
2122

2223
func main() {
24+
system.EnableCompatibilityMode()
2325
sub.Execute()
2426
}

cmd/frps/main.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@
1515
package main
1616

1717
import (
18-
"github.com/fatedier/golib/crypto"
19-
2018
_ "github.com/fatedier/frp/assets/frps"
2119
_ "github.com/fatedier/frp/pkg/metrics"
20+
"github.com/fatedier/frp/pkg/util/system"
2221
)
2322

2423
func main() {
25-
crypto.DefaultSalt = "frp"
24+
system.EnableCompatibilityMode()
2625
Execute()
2726
}

conf/frpc_full_example.toml

+4
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ healthCheck.path = "/status"
216216
healthCheck.intervalSeconds = 10
217217
healthCheck.maxFailed = 3
218218
healthCheck.timeoutSeconds = 3
219+
# set health check headers
220+
healthCheck.httpHeaders=[
221+
{ name = "x-from-where", value = "frp" }
222+
]
219223

220224
[[proxies]]
221225
name = "web02"

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.22
55
require (
66
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
77
github.com/coreos/go-oidc/v3 v3.6.0
8-
github.com/fatedier/golib v0.4.0
8+
github.com/fatedier/golib v0.4.2
99
github.com/google/uuid v1.3.0
1010
github.com/gorilla/mux v1.8.0
1111
github.com/gorilla/websocket v1.5.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
2424
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
2525
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
2626
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
27-
github.com/fatedier/golib v0.4.0 h1:lafvYRMhFmqrfIUChKy/f5AXqs1eDSk+GAUtLexN5bU=
28-
github.com/fatedier/golib v0.4.0/go.mod h1:gpu+1vXxtJ072NYaNsn/YWgojDL8Ap2kFZQtbzT2qkg=
27+
github.com/fatedier/golib v0.4.2 h1:k+ZBdUFTTipnP1RHfEhGbzyShRdz/rZtFGnjpXG9D9c=
28+
github.com/fatedier/golib v0.4.2/go.mod h1:gpu+1vXxtJ072NYaNsn/YWgojDL8Ap2kFZQtbzT2qkg=
2929
github.com/fatedier/yamux v0.0.0-20230628132301-7aca4898904d h1:ynk1ra0RUqDWQfvFi5KtMiSobkVQ3cNc0ODb8CfIETo=
3030
github.com/fatedier/yamux v0.0.0-20230628132301-7aca4898904d/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
3131
github.com/go-jose/go-jose/v3 v3.0.1 h1:pWmKFVtt+Jl0vBZTIpz/eAKwsm6LkIxDVVbFHKkchhA=

pkg/config/load.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ func DetectLegacyINIFormatFromFile(path string) bool {
8080
}
8181

8282
func RenderWithTemplate(in []byte, values *Values) ([]byte, error) {
83-
tmpl, err := template.New("frp").Parse(string(in))
83+
tmpl, err := template.New("frp").Funcs(template.FuncMap{
84+
"parseNumberRange": parseNumberRange,
85+
"parseNumberRangePair": parseNumberRangePair,
86+
}).Parse(string(in))
8487
if err != nil {
8588
return nil, err
8689
}

pkg/config/template.go

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2024 The frp Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package config
16+
17+
import (
18+
"fmt"
19+
20+
"github.com/fatedier/frp/pkg/util/util"
21+
)
22+
23+
type NumberPair struct {
24+
First int64
25+
Second int64
26+
}
27+
28+
func parseNumberRangePair(firstRangeStr, secondRangeStr string) ([]NumberPair, error) {
29+
firstRangeNumbers, err := util.ParseRangeNumbers(firstRangeStr)
30+
if err != nil {
31+
return nil, err
32+
}
33+
secondRangeNumbers, err := util.ParseRangeNumbers(secondRangeStr)
34+
if err != nil {
35+
return nil, err
36+
}
37+
if len(firstRangeNumbers) != len(secondRangeNumbers) {
38+
return nil, fmt.Errorf("first and second range numbers are not in pairs")
39+
}
40+
pairs := make([]NumberPair, 0, len(firstRangeNumbers))
41+
for i := 0; i < len(firstRangeNumbers); i++ {
42+
pairs = append(pairs, NumberPair{
43+
First: firstRangeNumbers[i],
44+
Second: secondRangeNumbers[i],
45+
})
46+
}
47+
return pairs, nil
48+
}
49+
50+
func parseNumberRange(firstRangeStr string) ([]int64, error) {
51+
return util.ParseRangeNumbers(firstRangeStr)
52+
}

pkg/config/v1/common.go

+5
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,8 @@ type HTTPPluginOptions struct {
129129
type HeaderOperations struct {
130130
Set map[string]string `json:"set,omitempty"`
131131
}
132+
133+
type HTTPHeader struct {
134+
Name string `json:"name"`
135+
Value string `json:"value"`
136+
}

pkg/config/v1/proxy.go

+3
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ type HealthCheckConfig struct {
9797
// Path specifies the path to send health checks to if the
9898
// health check type is "http".
9999
Path string `json:"path,omitempty"`
100+
// HTTPHeaders specifies the headers to send with the health request, if
101+
// the health check type is "http".
102+
HTTPHeaders []HTTPHeader `json:"httpHeaders,omitempty"`
100103
}
101104

102105
type DomainConfig struct {

pkg/nathole/nathole.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package nathole
1717
import (
1818
"context"
1919
"fmt"
20-
"math/rand"
20+
"math/rand/v2"
2121
"net"
2222
"slices"
2323
"strconv"
@@ -341,7 +341,7 @@ func sendSidMessage(
341341
TransactionID: transactionID,
342342
Sid: sid,
343343
Response: false,
344-
Nonce: strings.Repeat("0", rand.Intn(20)),
344+
Nonce: strings.Repeat("0", rand.IntN(20)),
345345
}
346346
buf, err := EncodeMessage(m, key)
347347
if err != nil {
@@ -398,7 +398,7 @@ func sendSidMessageToRandomPorts(
398398
used := sets.New[int]()
399399
getUnusedPort := func() int {
400400
for i := 0; i < 10; i++ {
401-
port := rand.Intn(65535-1024) + 1024
401+
port := rand.IntN(65535-1024) + 1024
402402
if !used.Has(port) {
403403
used.Insert(port)
404404
return port

pkg/util/net/dns.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ func SetDefaultDNSAddress(dnsAddress string) {
2626
// Change default dns server
2727
net.DefaultResolver = &net.Resolver{
2828
PreferGo: true,
29-
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
30-
return net.Dial("udp", dnsAddress)
29+
Dial: func(ctx context.Context, network, _ string) (net.Conn, error) {
30+
return net.Dial(network, dnsAddress)
3131
},
3232
}
3333
}

pkg/util/system/system.go

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2024 The frp Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
//go:build !android
16+
17+
package system
18+
19+
// EnableCompatibilityMode enables compatibility mode for different system.
20+
// For example, on Android, the inability to obtain the correct time zone will result in incorrect log time output.
21+
func EnableCompatibilityMode() {
22+
}

0 commit comments

Comments
 (0)