mirror of
https://github.com/fatedier/frp.git
synced 2025-06-15 07:08:22 +00:00
Compare commits
6 Commits
22154c22cb
...
005d8c9a89
Author | SHA1 | Date | |
---|---|---|---|
|
005d8c9a89 | ||
|
e0dd947e6a | ||
|
8b86e1473c | ||
|
b8d3ace113 | ||
|
450b8393bc | ||
|
27db6217ec |
@ -1,5 +1,7 @@
|
|||||||
### Features
|
### Features
|
||||||
|
|
||||||
* `tzdata` is installed by default in the container image, and the time zone can be set using the `TZ` environment variable.
|
* Support metadatas and annotations in frpc proxy commands.
|
||||||
* The `quic-bind-port` command line parameter is supported in frps, which specifies the port for accepting frpc connections using the QUIC protocol.
|
|
||||||
* The vhost HTTP proxy of frps supports the h2c protocol.
|
### Fixes
|
||||||
|
|
||||||
|
* Properly release resources in service.Close() to prevent resource leaks when used as a library.
|
||||||
|
2
go.mod
2
go.mod
@ -5,7 +5,7 @@ go 1.22.0
|
|||||||
require (
|
require (
|
||||||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
|
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
|
||||||
github.com/coreos/go-oidc/v3 v3.10.0
|
github.com/coreos/go-oidc/v3 v3.10.0
|
||||||
github.com/fatedier/golib v0.5.0
|
github.com/fatedier/golib v0.5.1
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
github.com/gorilla/mux v1.8.1
|
github.com/gorilla/mux v1.8.1
|
||||||
github.com/gorilla/websocket v1.5.0
|
github.com/gorilla/websocket v1.5.0
|
||||||
|
4
go.sum
4
go.sum
@ -21,8 +21,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
|
|||||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||||
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||||
github.com/fatedier/golib v0.5.0 h1:hNcH7hgfIFqVWbP+YojCCAj4eO94pPf4dEF8lmq2jWs=
|
github.com/fatedier/golib v0.5.1 h1:hcKAnaw5mdI/1KWRGejxR+i1Hn/NvbY5UsMKDr7o13M=
|
||||||
github.com/fatedier/golib v0.5.0/go.mod h1:W6kIYkIFxHsTzbgqg5piCxIiDo4LzwgTY6R5W8l9NFQ=
|
github.com/fatedier/golib v0.5.1/go.mod h1:W6kIYkIFxHsTzbgqg5piCxIiDo4LzwgTY6R5W8l9NFQ=
|
||||||
github.com/fatedier/yamux v0.0.0-20230628132301-7aca4898904d h1:ynk1ra0RUqDWQfvFi5KtMiSobkVQ3cNc0ODb8CfIETo=
|
github.com/fatedier/yamux v0.0.0-20230628132301-7aca4898904d h1:ynk1ra0RUqDWQfvFi5KtMiSobkVQ3cNc0ODb8CfIETo=
|
||||||
github.com/fatedier/yamux v0.0.0-20230628132301-7aca4898904d/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
|
github.com/fatedier/yamux v0.0.0-20230628132301-7aca4898904d/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
|
||||||
github.com/go-jose/go-jose/v4 v4.0.1 h1:QVEPDE3OluqXBQZDcnNvQrInro2h0e4eqNbnZSWqS6U=
|
github.com/go-jose/go-jose/v4 v4.0.1 h1:QVEPDE3OluqXBQZDcnNvQrInro2h0e4eqNbnZSWqS6U=
|
||||||
|
@ -106,6 +106,8 @@ func registerProxyBaseConfigFlags(cmd *cobra.Command, c *v1.ProxyBaseConfig, opt
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmd.Flags().StringVarP(&c.Name, "proxy_name", "n", "", "proxy name")
|
cmd.Flags().StringVarP(&c.Name, "proxy_name", "n", "", "proxy name")
|
||||||
|
cmd.Flags().StringToStringVarP(&c.Metadatas, "metadatas", "", nil, "metadata key-value pairs (e.g., key1=value1,key2=value2)")
|
||||||
|
cmd.Flags().StringToStringVarP(&c.Annotations, "annotations", "", nil, "annotation key-value pairs (e.g., key1=value1,key2=value2)")
|
||||||
|
|
||||||
if !options.sshMode {
|
if !options.sshMode {
|
||||||
cmd.Flags().StringVarP(&c.LocalIP, "local_ip", "i", "127.0.0.1", "local ip")
|
cmd.Flags().StringVarP(&c.LocalIP, "local_ip", "i", "127.0.0.1", "local ip")
|
||||||
|
@ -18,10 +18,10 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
toml "github.com/pelletier/go-toml/v2"
|
toml "github.com/pelletier/go-toml/v2"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
|
@ -112,6 +112,29 @@ func TestLoadServerConfigStrictMode(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRenderWithTemplate(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
content string
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{"toml", tomlServerContent, tomlServerContent},
|
||||||
|
{"yaml", yamlServerContent, yamlServerContent},
|
||||||
|
{"json", jsonServerContent, jsonServerContent},
|
||||||
|
{"template numeric", `key = {{ 123 }}`, "key = 123"},
|
||||||
|
{"template string", `key = {{ "xyz" }}`, "key = xyz"},
|
||||||
|
{"template quote", `key = {{ printf "%q" "with space" }}`, `key = "with space"`},
|
||||||
|
}
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
require := require.New(t)
|
||||||
|
got, err := RenderWithTemplate([]byte(test.content), nil)
|
||||||
|
require.NoError(err)
|
||||||
|
require.EqualValues(test.want, string(got))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCustomStructStrictMode(t *testing.T) {
|
func TestCustomStructStrictMode(t *testing.T) {
|
||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
|
|
||||||
|
@ -112,6 +112,10 @@ func (g *Gateway) Run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *Gateway) Close() error {
|
||||||
|
return g.ln.Close()
|
||||||
|
}
|
||||||
|
|
||||||
func (g *Gateway) handleConn(conn net.Conn) {
|
func (g *Gateway) handleConn(conn net.Conn) {
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
|
@ -100,6 +100,10 @@ func (v *Muxer) SetRewriteHostFunc(f hostRewriteFunc) *Muxer {
|
|||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v *Muxer) Close() error {
|
||||||
|
return v.listener.Close()
|
||||||
|
}
|
||||||
|
|
||||||
type ChooseEndpointFunc func() (string, error)
|
type ChooseEndpointFunc func() (string, error)
|
||||||
|
|
||||||
type CreateConnFunc func(remoteAddr string) (net.Conn, error)
|
type CreateConnFunc func(remoteAddr string) (net.Conn, error)
|
||||||
|
@ -59,3 +59,13 @@ type ResourceController struct {
|
|||||||
// All server manager plugin
|
// All server manager plugin
|
||||||
PluginManager *plugin.Manager
|
PluginManager *plugin.Manager
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (rc *ResourceController) Close() error {
|
||||||
|
if rc.VhostHTTPSMuxer != nil {
|
||||||
|
rc.VhostHTTPSMuxer.Close()
|
||||||
|
}
|
||||||
|
if rc.TCPMuxHTTPConnectMuxer != nil {
|
||||||
|
rc.TCPMuxHTTPConnectMuxer.Close()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -17,8 +17,7 @@ package proxy
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"sync"
|
||||||
"github.com/fatedier/golib/errors"
|
|
||||||
|
|
||||||
v1 "github.com/fatedier/frp/pkg/config/v1"
|
v1 "github.com/fatedier/frp/pkg/config/v1"
|
||||||
"github.com/fatedier/frp/pkg/msg"
|
"github.com/fatedier/frp/pkg/msg"
|
||||||
@ -32,7 +31,8 @@ type XTCPProxy struct {
|
|||||||
*BaseProxy
|
*BaseProxy
|
||||||
cfg *v1.XTCPProxyConfig
|
cfg *v1.XTCPProxyConfig
|
||||||
|
|
||||||
closeCh chan struct{}
|
closeCh chan struct{}
|
||||||
|
closeOnce sync.Once
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewXTCPProxy(baseProxy *BaseProxy) Proxy {
|
func NewXTCPProxy(baseProxy *BaseProxy) Proxy {
|
||||||
@ -43,6 +43,7 @@ func NewXTCPProxy(baseProxy *BaseProxy) Proxy {
|
|||||||
return &XTCPProxy{
|
return &XTCPProxy{
|
||||||
BaseProxy: baseProxy,
|
BaseProxy: baseProxy,
|
||||||
cfg: unwrapped,
|
cfg: unwrapped,
|
||||||
|
closeCh: make(chan struct{}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,9 +88,9 @@ func (pxy *XTCPProxy) Run() (remoteAddr string, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (pxy *XTCPProxy) Close() {
|
func (pxy *XTCPProxy) Close() {
|
||||||
pxy.BaseProxy.Close()
|
pxy.closeOnce.Do(func() {
|
||||||
pxy.rc.NatHoleController.CloseClient(pxy.GetName())
|
pxy.BaseProxy.Close()
|
||||||
_ = errors.PanicToError(func() {
|
pxy.rc.NatHoleController.CloseClient(pxy.GetName())
|
||||||
close(pxy.closeCh)
|
close(pxy.closeCh)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -386,24 +386,30 @@ func (svr *Service) Run(ctx context.Context) {
|
|||||||
func (svr *Service) Close() error {
|
func (svr *Service) Close() error {
|
||||||
if svr.kcpListener != nil {
|
if svr.kcpListener != nil {
|
||||||
svr.kcpListener.Close()
|
svr.kcpListener.Close()
|
||||||
svr.kcpListener = nil
|
|
||||||
}
|
}
|
||||||
if svr.quicListener != nil {
|
if svr.quicListener != nil {
|
||||||
svr.quicListener.Close()
|
svr.quicListener.Close()
|
||||||
svr.quicListener = nil
|
|
||||||
}
|
}
|
||||||
if svr.websocketListener != nil {
|
if svr.websocketListener != nil {
|
||||||
svr.websocketListener.Close()
|
svr.websocketListener.Close()
|
||||||
svr.websocketListener = nil
|
|
||||||
}
|
}
|
||||||
if svr.tlsListener != nil {
|
if svr.tlsListener != nil {
|
||||||
svr.tlsListener.Close()
|
svr.tlsListener.Close()
|
||||||
svr.tlsConfig = nil
|
}
|
||||||
|
if svr.sshTunnelListener != nil {
|
||||||
|
svr.sshTunnelListener.Close()
|
||||||
}
|
}
|
||||||
if svr.listener != nil {
|
if svr.listener != nil {
|
||||||
svr.listener.Close()
|
svr.listener.Close()
|
||||||
svr.listener = nil
|
|
||||||
}
|
}
|
||||||
|
if svr.webServer != nil {
|
||||||
|
svr.webServer.Close()
|
||||||
|
}
|
||||||
|
if svr.sshTunnelGateway != nil {
|
||||||
|
svr.sshTunnelGateway.Close()
|
||||||
|
}
|
||||||
|
svr.rc.Close()
|
||||||
|
svr.muxer.Close()
|
||||||
svr.ctlManager.Close()
|
svr.ctlManager.Close()
|
||||||
if svr.cancel != nil {
|
if svr.cancel != nil {
|
||||||
svr.cancel()
|
svr.cancel()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user