* No need to do anything with addresses. */
goto done;
}
- if(header->fam_prot == 0x00) {
+ if(header->fam_prot == PP2_UNSPEC_UNSPEC) {
/* Unspecified family and protocol. This could be used for
* health checks by proxies.
* No need to do anything with addresses. */
}
/* Read the proxied address */
switch(header->fam_prot) {
- case 0x11: /* AF_INET|STREAM */
- case 0x12: /* AF_INET|DGRAM */
+ case PP2_INET_STREAM:
+ case PP2_INET_DGRAM:
{
struct sockaddr_in* addr =
(struct sockaddr_in*)&rep->client_addr;
}
/* Ignore the destination address; it should be us. */
break;
- case 0x21: /* AF_INET6|STREAM */
- case 0x22: /* AF_INET6|DGRAM */
+ case PP2_INET6_STREAM:
+ case PP2_INET6_DGRAM:
{
struct sockaddr_in6* addr =
(struct sockaddr_in6*)&rep->client_addr;
break;
default:
log_err("proxy_protocol: unsupported family and "
- "protocol");
+ "protocol 0x%x", (int)header->fam_prot);
return 0;
}
rep->is_proxied = 1;
/* version and command */
*buf = (PP2_VERSION << 4) | PP2_CMD_PROXY;
buf++;
- if(af==AF_INET) {
+ switch(af) {
+ case AF_INET:
/* family and protocol */
*buf = (PP2_AF_INET<<4) |
(stream?PP2_PROT_STREAM:PP2_PROT_DGRAM);
/* dst addr */
/* dst port */
(*pp_data.write_uint16)(buf, 12);
- } else {
+ break;
#ifdef INET6
+ case AF_INET6:
/* family and protocol */
*buf = (PP2_AF_INET6<<4) |
(stream?PP2_PROT_STREAM:PP2_PROT_DGRAM);
buf += 2;
/* dst port */
(*pp_data.write_uint16)(buf, 0);
-#else
- return 0;
+ break;
#endif /* INET6 */
+ case AF_UNIX:
+ /* fallthrough */
+ default:
+ return 0;
}
return expected_size;
}
return PP_PARSE_UNKNOWN_CMD;
}
/* Check for supported family and protocol */
- if(header->fam_prot != 0x00 /* AF_UNSPEC|UNSPEC */ &&
- header->fam_prot != 0x11 /* AF_INET|STREAM */ &&
- header->fam_prot != 0x12 /* AF_INET|DGRAM */ &&
- header->fam_prot != 0x21 /* AF_INET6|STREAM */ &&
- header->fam_prot != 0x22 /* AF_INET6|DGRAM */ &&
- header->fam_prot != 0x31 /* AF_UNIX|STREAM */ &&
- header->fam_prot != 0x32 /* AF_UNIX|DGRAM */) {
+ if(header->fam_prot != PP2_UNSPEC_UNSPEC &&
+ header->fam_prot != PP2_INET_STREAM &&
+ header->fam_prot != PP2_INET_DGRAM &&
+ header->fam_prot != PP2_INET6_STREAM &&
+ header->fam_prot != PP2_INET6_DGRAM &&
+ header->fam_prot != PP2_UNIX_STREAM &&
+ header->fam_prot != PP2_UNIX_DGRAM) {
return PP_PARSE_UNKNOWN_FAM_PROT;
}
/* We have a correct header */
#define PP2_SIG "\x0D\x0A\x0D\x0A\x00\x0D\x0A\x51\x55\x49\x54\x0A"
#define PP2_SIG_LEN 12
-/** PROXYv2 version */
+/** PROXYv2 version (protocol value) */
#define PP2_VERSION 0x2
/**
- * PROXYv2 command.
+ * PROXYv2 command (protocol value).
*/
enum pp2_command {
PP2_CMD_LOCAL = 0x0,
};
/**
- * PROXYv2 address family.
+ * PROXYv2 address family (protocol value).
*/
enum pp2_af {
PP2_AF_UNSPEC = 0x0,
};
/**
- * PROXYv2 protocol.
+ * PROXYv2 protocol (protocol value).
*/
enum pp2_protocol {
PP2_PROT_UNSPEC = 0x0,
PP2_PROT_DGRAM = 0x2
};
+/**
+ * Expected combinations of address family and protocol values used in checks.
+ */
+enum pp2_af_protocol_combination {
+ PP2_UNSPEC_UNSPEC = (PP2_AF_UNSPEC<<4)|PP2_PROT_UNSPEC,
+ PP2_INET_STREAM = (PP2_AF_INET<<4)|PP2_PROT_STREAM,
+ PP2_INET_DGRAM = (PP2_AF_INET<<4)|PP2_PROT_DGRAM,
+ PP2_INET6_STREAM = (PP2_AF_INET6<<4)|PP2_PROT_STREAM,
+ PP2_INET6_DGRAM = (PP2_AF_INET6<<4)|PP2_PROT_DGRAM,
+ PP2_UNIX_STREAM = (PP2_AF_UNIX<<4)|PP2_PROT_STREAM,
+ PP2_UNIX_DGRAM = (PP2_AF_UNIX<<4)|PP2_PROT_DGRAM
+};
+
/**
* PROXYv2 header.
*/