unbound: util/proxy_protocol.c File Reference

unbound 0.1

Data Structures | Functions | Variables
proxy_protocol.c File Reference

This file contains PROXY protocol functions. More...

`#include "util/proxy_protocol.h"`

## 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.
const char * | pp_lookup_error (enum pp_parse_errors error)
| Lookup the parsing error description.
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.
int | pp2_read_header (uint8_t *buf, size_t buflen)
| Read a PROXYv2 header from the current position of the buffer.

## 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.

## Detailed Description

This file contains PROXY protocol functions.

## Function Documentation

## ◆ pp_init()

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

Initialize the internal proxy structure.

Parameters

  write_uint16 | pointer to a function that can write uint16.
  write_uint32 | pointer to a function that can write uint32.

Referenced by libworker_setup(), main(), and worker_init().

## ◆ pp_lookup_error()

const char * pp_lookup_error | ( | enum pp_parse_errors | error | ) |

Lookup the parsing error description.

Parameters

  error | parsing 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

  buf | pointer to the buffer to write data to.
  buflen | available size on the buffer.
  src | the source address.
  stream | if the protocol is stream or datagram.

Returns
  1 on success, 0 on failure.

References PP2_HEADER_SIZE, PP2_SIG, and PP2_VERSION.

## ◆ 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

  buf | pointer to the buffer data to read from.
  buflen | available size on the buffer.

Returns
  parsing error, 0 on success.

References PP2_HEADER_SIZE, PP2_SIG, and PP2_VERSION.

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().