-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
transaction_proxy.go
67 lines (61 loc) · 1.34 KB
/
transaction_proxy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package msmtpd
import (
"net"
"strconv"
"go.opentelemetry.io/otel/attribute"
)
// Additional documentation:
// http://www.haproxy.org/download/1.8/doc/proxy-protocol.txt
// Example: `PROXY TCP4 8.8.8.8 127.0.0.1 443 25`
func (t *Transaction) handlePROXY(cmd command) {
t.LogTrace("Proxy command: %s", cmd.line)
if !t.server.EnableProxyProtocol {
t.reply(550, "Proxy Protocol not enabled")
return
}
if len(cmd.fields) < 6 {
t.reply(502, "malformed proxy command")
return
}
var (
newAddr net.IP
newTCPPort uint64
err error
)
switch cmd.fields[1] {
case "TCP4":
break
case "TCP6":
break
default:
t.reply(502, "unable to decode proxy protocol - only TCP4/TCP6 is supported")
return
}
newAddr = net.ParseIP(cmd.fields[2])
if newAddr == nil {
t.reply(502, "malformed network address")
return
}
newTCPPort, err = strconv.ParseUint(cmd.fields[4], 10, 16)
if err != nil {
t.reply(502, "malformed port in proxy command")
return
}
tcpAddr, ok := t.Addr.(*net.TCPAddr)
if !ok {
t.reply(502, "unsupported network connection")
return
}
if newAddr != nil {
tcpAddr.IP = newAddr
}
if newTCPPort != 0 {
tcpAddr.Port = int(newTCPPort)
}
t.LogInfo("Proxy processed: new address - %s:%v",
tcpAddr.IP, tcpAddr.Port,
)
t.Addr = tcpAddr
t.Span.SetAttributes(attribute.String("PROXY", cmd.line))
t.welcome()
}