Skip to content

Commit ccff845

Browse files
authored
Add some debug logs to proxy protoocl parser (#12139)
1 parent 8414924 commit ccff845

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/iocore/net/ProxyProtocol.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ proxy_protocol_v2_parse(ProxyProtocol *pp_info, const swoc::TextView &msg)
235235
uint16_t tlv_len = 0;
236236

237237
if (msg.size() < total_len) {
238+
Dbg(dbg_ctl_proxyprotocol_v2, "The amount of available data is smaller than the expected size");
238239
return 0;
239240
}
240241

@@ -243,6 +244,7 @@ proxy_protocol_v2_parse(ProxyProtocol *pp_info, const swoc::TextView &msg)
243244
case PPv2_CMD_LOCAL: {
244245
// protocol byte should be UNSPEC (\x00) with LOCAL command
245246
if (hdr_v2->fam != PPv2_PROTO_UNSPEC) {
247+
Dbg(dbg_ctl_proxyprotocol_v2, "UNSPEC is unexpected");
246248
return 0;
247249
}
248250

@@ -256,6 +258,7 @@ proxy_protocol_v2_parse(ProxyProtocol *pp_info, const swoc::TextView &msg)
256258
case PPv2_PROTO_TCP4:
257259
case PPv2_PROTO_UDP4:
258260
if (len < PPv2_ADDR_LEN_INET) {
261+
Dbg(dbg_ctl_proxyprotocol_v2, "There is not enough data left for IPv4 info");
259262
return 0;
260263
}
261264
tlv_len = len - PPv2_ADDR_LEN_INET;
@@ -269,6 +272,7 @@ proxy_protocol_v2_parse(ProxyProtocol *pp_info, const swoc::TextView &msg)
269272
case PPv2_PROTO_TCP6:
270273
case PPv2_PROTO_UDP6:
271274
if (len < PPv2_ADDR_LEN_INET6) {
275+
Dbg(dbg_ctl_proxyprotocol_v2, "There is not enough data left for IPv6 info");
272276
return 0;
273277
}
274278
tlv_len = len - PPv2_ADDR_LEN_INET6;
@@ -287,18 +291,21 @@ proxy_protocol_v2_parse(ProxyProtocol *pp_info, const swoc::TextView &msg)
287291
[[fallthrough]];
288292
default:
289293
// unsupported
294+
Dbg(dbg_ctl_proxyprotocol_v2, "Unsupported protocol family (%d)", hdr_v2->fam);
290295
return 0;
291296
}
292297

293298
if (tlv_len > 0) {
294299
if (pp_info->set_additional_data(msg.substr(total_len - tlv_len, tlv_len)) < 0) {
300+
Dbg(dbg_ctl_proxyprotocol_v2, "Failed to parse additional fields");
295301
return 0;
296302
}
297303
}
298304

299305
return total_len;
300306
}
301307
default:
308+
Dbg(dbg_ctl_proxyprotocol_v2, "Unsupported command (%d)", hdr_v2->ver_cmd);
302309
break;
303310
}
304311

@@ -541,9 +548,11 @@ ProxyProtocol::get_tlv(const uint8_t tlvCode) const
541548
int
542549
ProxyProtocol::set_additional_data(std::string_view data)
543550
{
544-
uint16_t len = data.length();
551+
uint16_t len = data.length();
552+
Dbg(dbg_ctl_proxyprotocol_v2, "Parsing %d byte additional data", len);
545553
additional_data = static_cast<char *>(ats_malloc(len));
546554
if (additional_data == nullptr) {
555+
Dbg(dbg_ctl_proxyprotocol_v2, "Memory allocation failed");
547556
return -1;
548557
}
549558
data.copy(additional_data, len);
@@ -553,6 +562,7 @@ ProxyProtocol::set_additional_data(std::string_view data)
553562
while (p != end) {
554563
if (end - p < 3) {
555564
// The size of a TLV entry must be 3 bytes or more
565+
Dbg(dbg_ctl_proxyprotocol_v2, "Remaining data (%ld bytes) is not enough for a TLV field", end - p);
556566
return -2;
557567
}
558568

@@ -567,6 +577,8 @@ ProxyProtocol::set_additional_data(std::string_view data)
567577
// Value
568578
if (end - p < length) {
569579
// Does not have enough data
580+
Dbg(dbg_ctl_proxyprotocol_v2, "Remaining data (%ld bytes) is not enough for a TLV field (ID:%u LEN:%hu)", end - p, type,
581+
length);
570582
return -3;
571583
}
572584
Dbg(dbg_ctl_proxyprotocol, "TLV: ID=%u LEN=%hu", type, length);

0 commit comments

Comments
 (0)