BUG/MINOR: connection: parse PROXY TLV for LOCAL mode

conn_recv_proxy() is responsible to parse PROXY protocol header. For v2
of the protocol, TLVs parsing is implemented. However, this step was
only done inside 'PROXY' command label. TLVs were never extracted for
'LOCAL' command mode.

Fix this by extracting TLV parsing loop outside of the switch case. Of
notable importance, tlv_offset is updated on LOCAL label to point to
first TLV location.

This bug should be backported up to 2.9 at least. It should even
probably be backported to every stable versions. Note however that this
code has changed much over time. It may be useful to use option
'--ignore-all-space' to have a clearer overview of the git diff.
This commit is contained in:
Amaury Denoyelle 2024-05-14 16:36:59 +02:00
parent eb89a7da33
commit 8b72270e95

View File

@ -1129,6 +1129,17 @@ int conn_recv_proxy(struct connection *conn, int flag)
break; break;
} }
/* unsupported protocol, keep local connection address */
break;
case 0x00: /* LOCAL command */
/* keep local connection address for LOCAL */
tlv_offset = PP2_HEADER_LEN;
break;
default:
goto bad_header; /* not a supported command */
}
/* TLV parsing */ /* TLV parsing */
while (tlv_offset < total_v2_len) { while (tlv_offset < total_v2_len) {
struct ist tlv; struct ist tlv;
@ -1217,7 +1228,6 @@ int conn_recv_proxy(struct connection *conn, int flag)
LIST_APPEND(&conn->tlv_list, &new_tlv->list); LIST_APPEND(&conn->tlv_list, &new_tlv->list);
} }
/* Verify that the PROXYv2 header ends at a TLV boundary. /* Verify that the PROXYv2 header ends at a TLV boundary.
* This is can not be true, because the TLV parsing already * This is can not be true, because the TLV parsing already
* verifies that a TLV does not exceed the total length and * verifies that a TLV does not exceed the total length and
@ -1225,15 +1235,6 @@ int conn_recv_proxy(struct connection *conn, int flag)
*/ */
BUG_ON(tlv_offset != total_v2_len); BUG_ON(tlv_offset != total_v2_len);
/* unsupported protocol, keep local connection address */
break;
case 0x00: /* LOCAL command */
/* keep local connection address for LOCAL */
break;
default:
goto bad_header; /* not a supported command */
}
trash.data = total_v2_len; trash.data = total_v2_len;
goto eat_header; goto eat_header;