Silence warnings, check length
This commit is contained in:
+1
-1
@@ -110,7 +110,7 @@ protected:
|
|||||||
b[12], b[13], b[14], b[15]);
|
b[12], b[13], b[14], b[15]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {buf, ipLength};
|
return {buf, (unsigned int) ipLength};
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns the remote IP address or empty string on failure */
|
/* Returns the remote IP address or empty string on failure */
|
||||||
|
|||||||
+1
-1
@@ -188,7 +188,7 @@ private:
|
|||||||
ProxyParser *pp = (ProxyParser *) reserved;
|
ProxyParser *pp = (ProxyParser *) reserved;
|
||||||
|
|
||||||
/* Parse PROXY protocol */
|
/* Parse PROXY protocol */
|
||||||
auto [done, offset] = pp->parse({data, length});
|
auto [done, offset] = pp->parse({data, (unsigned int) length});
|
||||||
if (!done) {
|
if (!done) {
|
||||||
return {0, user};
|
return {0, user};
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+2
-2
@@ -167,10 +167,10 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/* If we have proxy support */
|
/* If we have proxy support; returns the proxed source address as reported by the proxy. */
|
||||||
#ifdef WITH_PROXY
|
#ifdef WITH_PROXY
|
||||||
std::string_view getProxiedRemoteAddress() {
|
std::string_view getProxiedRemoteAddress() {
|
||||||
return getHttpResponseData()->proxyParser.getSourceIp();
|
return getHttpResponseData()->proxyParser.getSourceAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string_view getProxiedRemoteAddressAsText() {
|
std::string_view getProxiedRemoteAddressAsText() {
|
||||||
|
|||||||
+12
-11
@@ -50,22 +50,19 @@ T _cond_byte_swap(T value) {
|
|||||||
|
|
||||||
struct ProxyParser {
|
struct ProxyParser {
|
||||||
private:
|
private:
|
||||||
union proxy_addr addr;
|
union proxy_addr addr = {};
|
||||||
uint8_t family;
|
uint8_t family = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/* Returns 4 or 16 bytes */
|
/* Returns 4 or 16 bytes source address */
|
||||||
std::string_view getSourceIp() {
|
std::string_view getSourceAddress() {
|
||||||
|
|
||||||
// ipv4 (ipv6 = 2)
|
|
||||||
if ((family & 0xf0) >> 4 == 1) {
|
if ((family & 0xf0) >> 4 == 1) {
|
||||||
|
/* Family 1 is INET4 */
|
||||||
return {(char *) &addr.ipv4_addr.src_addr, 4};
|
return {(char *) &addr.ipv4_addr.src_addr, 4};
|
||||||
} else {
|
} else {
|
||||||
|
/* Family 2 is INET6 */
|
||||||
return {(char *) &addr.ipv6_addr.src_addr, 16};
|
return {(char *) &addr.ipv6_addr.src_addr, 16};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns [done, consumed] where done = false on failure */
|
/* Returns [done, consumed] where done = false on failure */
|
||||||
@@ -78,13 +75,11 @@ public:
|
|||||||
|
|
||||||
/* HTTP does not start with \r, but PROXY always does */
|
/* HTTP does not start with \r, but PROXY always does */
|
||||||
if (data[0] != '\r') {
|
if (data[0] != '\r') {
|
||||||
//printf("This is HTTP\n");
|
|
||||||
/* This is HTTP, so be done */
|
/* This is HTTP, so be done */
|
||||||
return {true, 0};
|
return {true, 0};
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We assume we are parsing PROXY V2 here */
|
/* We assume we are parsing PROXY V2 here */
|
||||||
printf("This is PROXY v2\n");
|
|
||||||
|
|
||||||
/* We require 16 bytes here */
|
/* We require 16 bytes here */
|
||||||
if (data.length() < 16) {
|
if (data.length() < 16) {
|
||||||
@@ -99,11 +94,17 @@ public:
|
|||||||
return {false, 0};
|
return {false, 0};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If we have version 2 */
|
||||||
|
|
||||||
printf("Version: %d\n", (header.ver_cmd & 0xf0) >> 4);
|
printf("Version: %d\n", (header.ver_cmd & 0xf0) >> 4);
|
||||||
printf("Command: %d\n", (header.ver_cmd & 0x0f));
|
printf("Command: %d\n", (header.ver_cmd & 0x0f));
|
||||||
|
|
||||||
uint16_t hostLength = _cond_byte_swap<uint16_t>(header.len);
|
uint16_t hostLength = _cond_byte_swap<uint16_t>(header.len);
|
||||||
|
|
||||||
|
if (data.length() < 16 + hostLength) {
|
||||||
|
return {false, 0};
|
||||||
|
}
|
||||||
|
|
||||||
printf("Length: %d\n", hostLength);
|
printf("Length: %d\n", hostLength);
|
||||||
|
|
||||||
printf("Family: %d\n", (header.fam & 0xf0) >> 4);
|
printf("Family: %d\n", (header.fam & 0xf0) >> 4);
|
||||||
|
|||||||
Reference in New Issue
Block a user