restore PROXY protocol support

support for PROXY was removed in 43e28e2fef. After discussion,
it's worth keeping around in case of client compatibility issues,
and until /rehash support is more mature.
This commit is contained in:
Shivaram Lingamneni
2017-09-11 01:04:08 -04:00
committed by Daniel Oaks
parent 8cd016e4c0
commit 99f02ede20
6 changed files with 46 additions and 1 deletions
+10
View File
@@ -66,6 +66,7 @@ type Client struct {
nickMaskCasefolded string
nickMaskString string // cache for nickmask string since it's used with lots of replies
operName string
proxiedIP string // actual remote IP if using the PROXY protocol
quitMessageSent bool
quitMutex sync.Mutex
quitTimer *time.Timer
@@ -147,11 +148,19 @@ func NewClient(server *Server, conn net.Conn, isTLS bool) *Client {
// IP returns the IP address of this client.
func (client *Client) IP() net.IP {
if client.proxiedIP != "" {
return net.ParseIP(client.proxiedIP)
}
return net.ParseIP(IPString(client.socket.conn.RemoteAddr()))
}
// IPString returns the IP address of this client as a string.
func (client *Client) IPString() string {
if client.proxiedIP != "" {
return client.proxiedIP
}
ip := client.IP().String()
if 0 < len(ip) && ip[0] == ':' {
ip = "0" + ip
@@ -185,6 +194,7 @@ func (client *Client) run() {
var msg ircmsg.IrcMessage
// Set the hostname for this client
// (may be overridden by a later PROXY command from stunnel)
client.rawHostname = AddrLookupHostname(client.socket.conn.RemoteAddr())
for {