mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-18 00:06:38 +00:00
[management,proxy,client] Add L4 capabilities (TLS/TCP/UDP) (#5530)
This commit is contained in:
29
proxy/internal/tcp/proxyprotocol.go
Normal file
29
proxy/internal/tcp/proxyprotocol.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package tcp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/pires/go-proxyproto"
|
||||
)
|
||||
|
||||
// writeProxyProtoV2 sends a PROXY protocol v2 header to the backend connection,
|
||||
// conveying the real client address.
|
||||
func writeProxyProtoV2(client, backend net.Conn) error {
|
||||
tp := proxyproto.TCPv4
|
||||
if addr, ok := client.RemoteAddr().(*net.TCPAddr); ok && addr.IP.To4() == nil {
|
||||
tp = proxyproto.TCPv6
|
||||
}
|
||||
|
||||
header := &proxyproto.Header{
|
||||
Version: 2,
|
||||
Command: proxyproto.PROXY,
|
||||
TransportProtocol: tp,
|
||||
SourceAddr: client.RemoteAddr(),
|
||||
DestinationAddr: client.LocalAddr(),
|
||||
}
|
||||
if _, err := header.WriteTo(backend); err != nil {
|
||||
return fmt.Errorf("write PROXY protocol v2 header: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user