proxy_protocol.c File Reference

This file contains PROXY protocol functions. More...

Data Structures

struct  proxy_protocol_data
 Internal struct initialized with function pointers for writing uint16 and uint32. More...
 
struct  proxy_protocol_lookup_table
 Internal lookup table; could be further generic like sldns_lookup_table for all the future generic stuff. More...
 

Functions

void pp_init (void(*write_uint16)(void *buf, uint16_t data), void(*write_uint32)(void *buf, uint32_t data))
 Initialize the internal proxy structure. More...
 
const char * pp_lookup_error (enum pp_parse_errors error)
 Lookup the parsing error description. More...
 
size_t pp2_write_to_buf (uint8_t *buf, size_t buflen, struct sockaddr_in *src, int stream)
 Write a PROXYv2 header at the current position of the buffer. More...
 
int pp2_read_header (uint8_t *buf, size_t buflen)
 Read a PROXYv2 header from the current position of the buffer. More...
 

Variables

struct proxy_protocol_data pp_data
 
static struct proxy_protocol_lookup_table pp_parse_errors_data []
 Internal parsing error text; could be exposed with pp_lookup_error. More...
 

Detailed Description

This file contains PROXY protocol functions.

Function Documentation

◆ pp_init()

void pp_init ( void(*)(void *buf, uint16_t data)  write_uint16,
void(*)(void *buf, uint32_t data)  write_uint32 
)

Initialize the internal proxy structure.

Parameters
write_uint16pointer to a function that can write uint16.
write_uint32pointer to a function that can write uint32.

Referenced by main().

◆ pp_lookup_error()

const char* pp_lookup_error ( enum pp_parse_errors  error)

Lookup the parsing error description.

Parameters
errorparsing error from pp2_read_header.
Returns
the description.

References error(), and pp_parse_errors_data.

Referenced by comm_point_tcp_handle_read(), and ssl_handle_read().

◆ pp2_write_to_buf()

size_t pp2_write_to_buf ( uint8_t *  buf,
size_t  buflen,
struct sockaddr_in *  src,
int  stream 
)

Write a PROXYv2 header at the current position of the buffer.

Parameters
bufpointer to the buffer to write data to.
buflenavailable size on the buffer.
srcthe source address.
streamif the protocol is stream or datagram.
Returns
1 on success, 0 on failure.

References PP2_HEADER_SIZE, and PP2_SIG.

◆ pp2_read_header()

int pp2_read_header ( uint8_t *  buf,
size_t  buflen 
)

Read a PROXYv2 header from the current position of the buffer.

It does initial validation and returns a pointer to the buffer position on success.

Parameters
bufpointer to the buffer data to read from.
buflenavailable size on the buffer.
Returns
parsing error, 0 on success.

References PP2_HEADER_SIZE.

Referenced by comm_point_tcp_handle_read(), consume_pp2_header(), and ssl_handle_read().

Variable Documentation

◆ pp_parse_errors_data

struct proxy_protocol_lookup_table pp_parse_errors_data[]
static
Initial value:
= {
{ PP_PARSE_NOERROR, "no parse error" },
{ PP_PARSE_SIZE, "not enough space for header" },
{ PP_PARSE_WRONG_HEADERv2, "could not match PROXYv2 header" },
{ PP_PARSE_UNKNOWN_CMD, "unknown command" },
{ PP_PARSE_UNKNOWN_FAM_PROT, "unknown family and protocol" },
}

Internal parsing error text; could be exposed with pp_lookup_error.

Referenced by pp_lookup_error().