Skip to content

Commit 84e089d

Browse files
Moved ProxyProtocolVersion_t to an enum class.
1 parent 3c3ca54 commit 84e089d

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

iocore/net/I_NetVConnection.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -646,10 +646,10 @@ class NetVConnection : public AnnotatedVConnection
646646
NetVConnection(const NetVConnection &) = delete;
647647
NetVConnection &operator=(const NetVConnection &) = delete;
648648

649-
enum ProxyProtocolVersion_t {
650-
PROXY_VERSION_UNDEFINED,
651-
PROXY_V1,
652-
PROXY_V2,
649+
enum class ProxyProtocolVersion {
650+
UNDEFINED,
651+
V1,
652+
V2,
653653
};
654654

655655
enum ProxyProtocolData_t {
@@ -695,12 +695,12 @@ class NetVConnection : public AnnotatedVConnection
695695
}
696696

697697
void
698-
set_proxy_protocol_version(ProxyProtocolVersion_t ver)
698+
set_proxy_protocol_version(const ProxyProtocolVersion ver)
699699
{
700700
pp_info.proxy_protocol_version = ver;
701701
}
702702

703-
ProxyProtocolVersion_t
703+
ProxyProtocolVersion
704704
get_proxy_protocol_version()
705705
{
706706
return pp_info.proxy_protocol_version;
@@ -733,7 +733,7 @@ class NetVConnection : public AnnotatedVConnection
733733
};
734734

735735
typedef struct _ProxyProtocol {
736-
ProxyProtocolVersion_t proxy_protocol_version = PROXY_VERSION_UNDEFINED;
736+
ProxyProtocolVersion proxy_protocol_version = ProxyProtocolVersion::UNDEFINED;
737737
uint16_t ip_family;
738738
IpEndpoint src_addr;
739739
uint16_t src_port;

iocore/net/P_NetVConnection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ TS_INLINE sockaddr const *
2727
NetVConnection::get_remote_addr()
2828
{
2929
if (!got_remote_addr) {
30-
if (pp_info.proxy_protocol_version != PROXY_VERSION_UNDEFINED) {
30+
if (pp_info.proxy_protocol_version != ProxyProtocolVersion::UNDEFINED) {
3131
set_remote_addr(get_proxy_protocol_src_addr());
3232
} else {
3333
set_remote_addr();

iocore/net/ProxyProtocol.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ ssl_has_proxy_v1(NetVConnection *sslvc, char *buffer, int64_t *r)
3737
Debug("ssl", "Consuming %" PRId64 " characters of the PROXY header from %p to %p", nl + 1, buffer, nlp);
3838
char local_buf[PROXY_V1_CONNECTION_HEADER_LEN_MAX + 1];
3939
memcpy(local_buf, buffer, nl + 1);
40-
memmove(buffer, buffer + nl + 1, nl + 1);
4140
*r -= nl + 1;
4241
if (*r <= 0) {
4342
*r = -EAGAIN;
43+
} else {
44+
Debug("ssl", "Moving %" PRId64 " characters remaining in the buffer from %p to %p", *r, buffer + nl + 1, buffer);
45+
memmove(buffer, buffer + nl + 1, *r);
4446
}
4547
return (proxy_protov1_parse(sslvc, local_buf));
4648
}
@@ -58,7 +60,7 @@ http_has_proxy_v1(IOBufferReader *reader, NetVConnection *netvc)
5860
end = reader->memcpy(buf, sizeof(buf), 0 /* offset */);
5961
nbytes = end - buf;
6062

61-
// Client must send at least 15 bytes to get a reasonable match.
63+
// Client must send at least 4 bytes to get a reasonable match.
6264
if (nbytes < (long)PROXY_V1_CONNECTION_HEADER_LEN_MIN) {
6365
return false;
6466
}
@@ -135,7 +137,7 @@ proxy_protov1_parse(NetVConnection *netvc, char *buf)
135137
// otherwise increment our field counter and tok another field
136138
// cnt shoud never get greater than 5, but just in case...
137139
if (cnt >= 5) {
138-
netvc->set_proxy_protocol_version(NetVConnection::PROXY_V1);
140+
netvc->set_proxy_protocol_version(NetVConnection::ProxyProtocolVersion::V1);
139141
return true;
140142
} else {
141143
++cnt;

proxy/http/HttpTransact.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5564,7 +5564,7 @@ HttpTransact::initialize_state_variables_from_request(State *s, HTTPHdr *obsolet
55645564
if (vc) {
55655565
s->request_data.incoming_port = vc->get_local_port();
55665566
s->pp_info.proxy_protocol_version = vc->get_proxy_protocol_version();
5567-
if (s->pp_info.proxy_protocol_version != NetVConnection::PROXY_VERSION_UNDEFINED) {
5567+
if (s->pp_info.proxy_protocol_version != NetVConnection::ProxyProtocolVersion::UNDEFINED) {
55685568
ats_ip_copy(s->pp_info.src_addr, vc->pp_info.src_addr);
55695569
ats_ip_copy(s->pp_info.dst_addr, vc->pp_info.dst_addr);
55705570
}

0 commit comments

Comments
 (0)