Mstdlib-1.24.0
|
Enumerations | |
enum | M_io_proxy_protocol_flags_t { M_IO_PROXY_PROTOCOL_FLAG_NONE = 0 , M_IO_PROXY_PROTOCOL_FLAG_V1 = 1 << 0 , M_IO_PROXY_PROTOCOL_FLAG_V2 = 1 << 1 } |
Functions | |
M_io_error_t | M_io_proxy_protocol_inbound_add (M_io_t *io, size_t *layer_id, M_uint32 flags) |
M_io_error_t | M_io_proxy_protocol_outbound_add (M_io_t *io, size_t *layer_id, M_uint32 flags) |
M_bool | M_io_proxy_protocol_relayed (M_io_t *io) |
const char * | M_io_proxy_protocol_source_ipaddr (M_io_t *io) |
const char * | M_io_proxy_protocol_dest_ipaddr (M_io_t *io) |
M_uint16 | M_io_proxy_protocol_source_port (M_io_t *io) |
M_uint16 | M_io_proxy_protocol_dest_port (M_io_t *io) |
M_io_net_type_t | M_io_proxy_protocol_proxied_type (M_io_t *io) |
const char * | M_io_proxy_protocol_get_ipaddr (M_io_t *io) |
M_bool | M_io_proxy_protocol_set_connect_timeout_ms (M_io_t *io, M_uint64 timeout_ms) |
M_bool | M_io_proxy_protocol_set_source_endpoints (M_io_t *io, const char *source_ipaddr, const char *dest_ipaddr, M_uint16 source_port, M_uint16 dest_port) |
Inbound or outbound connection layer for handling The PROXY protocol as defined by HAProxy.
Supports versions:
Source is the client connecting to the system (Client). Destination is the server accepting the connection which will then relay using proxy protocol (proxy server). There can be multiple proxies in a chain between the source and the final server that is going to process the data. A such the destination address may not be the connection address for the final server's connection.
This server accepts inbound connections, and sends the data to another system using the proxy protocol. The inbound client is not using proxy protocol. The server the proxy is relaying the data to is using proxy protocol.
client <-> proxy server example (sends proxy protocol) <-> final server (receives proxy protocol)
This is a basic echo server where any data received is echoed back out. The server only accepts connections that use proxy protocol.
Flags controlling behavior.
M_io_error_t M_io_proxy_protocol_inbound_add | ( | M_io_t * | io, |
size_t * | layer_id, | ||
M_uint32 | flags | ||
) |
Add an inbound handler for proxy protocol connections.
The system will look for the PROXY protocol data upon connect. If Proxy protocol data is not present this is considered an error condition per the proxy protocol spec. An error event will be generated instead of a connect event in this situation.
This should be added to an io
object created by M_io_accept
during a server M_EVENT_TYPE_ACCEPT
event. It should not be added to the server io
object created by M_io_net_server_create
.
The proxy protocol data will be parsed and accessible though the relevant helper functions.
[in] | io | io object. |
[out] | layer_id | Layer id this is added at. |
[in] | flags | M_io_proxy_protocol_flags_t flags. |
M_io_error_t M_io_proxy_protocol_outbound_add | ( | M_io_t * | io, |
size_t * | layer_id, | ||
M_uint32 | flags | ||
) |
Add an outbound handler for proxy protocol connections.
Information about the proxyed endpoints (source and destination) need to be set before the connect event. If endpoints are not set the connection is assumed to be local where any data is being sent by the proxy itself and not being relayed on behalf of another client.
[in] | io | io object. |
[out] | layer_id | Layer id this is added at. |
[in] | flags | M_io_proxy_protocol_flags_t flags. |
M_bool M_io_proxy_protocol_relayed | ( | M_io_t * | io | ) |
Whether data is being is being relayed via a proxy.
A connection is relayed when the data is being sent on behalf of another system (proxied). When it is not relayed it is a local connection that has been established by the proxy for the proxy's own communication with the system. Typically, this is used for health checking.
return M_TRUE if relayed. Otherwise, M_FALSE.
const char * M_io_proxy_protocol_source_ipaddr | ( | M_io_t * | io | ) |
Source IP address.
IP address of the client that connected to the proxy.
[in] | io | io object. |
const char * M_io_proxy_protocol_dest_ipaddr | ( | M_io_t * | io | ) |
Destination IP address.
IP address of the proxy server that is relaying the client's (source) data.
[in] | io | io object. |
M_uint16 M_io_proxy_protocol_source_port | ( | M_io_t * | io | ) |
Source port.
Ephemeral port the client is connecting out on.
[in] | io | io object. |
M_uint16 M_io_proxy_protocol_dest_port | ( | M_io_t * | io | ) |
Destination port.
Destination port the client is connecting to.
[in] | io | io object. |
M_io_net_type_t M_io_proxy_protocol_proxied_type | ( | M_io_t * | io | ) |
Connection type that was used between source and destination.
[in] | io | io object. |
const char * M_io_proxy_protocol_get_ipaddr | ( | M_io_t * | io | ) |
Get the IP address of the client falling back to the network connection.
When using proxy protocol this should be used instead of M_io_net_get_ipaddr
in most instances. This can be used even when proxy protocol is not in use. This is especially useful when using an internal IP based blacklist for denying connections to a client as part of an intrusion prevention system (IPS).
This function is the equivalent of checking M_io_proxy_protocol_relayed
and then calling either M_io_proxy_protocol_source_ipaddr
or M_io_net_get_ipaddr
based on whether the connection is relayed.
This is a conscience especially for instances where proxy protocol could be used. For example, a configuration option or when some but not all connections will use the protocol. This function allows for use in both scenerios and will always return the correct IP address for the client, whether proxied for not.
param[in] io io object.
M_bool M_io_proxy_protocol_set_connect_timeout_ms | ( | M_io_t * | io, |
M_uint64 | timeout_ms | ||
) |
Set connect timeout.
This is the timeout to wait for a connection to receive all proxy protocol data. This timeout applies after the net connect timeout.
Proxy protocol is designed for all data to fit within a single TCP frame. Meaning, the data should not buffer between multiple events. As such the default timeout is 500 ms. This function can be used to increase that timeout for obscenely slow connections.
Connect timeout applies to both inbound and outbound (receiving and writing), the proxy data.
param[in] io io object. param[in] timeout_ms Timeout in milliseconds.
M_bool M_io_proxy_protocol_set_source_endpoints | ( | M_io_t * | io, |
const char * | source_ipaddr, | ||
const char * | dest_ipaddr, | ||
M_uint16 | source_port, | ||
M_uint16 | dest_port | ||
) |
Source and destination information that will be sent on connect.
Only applies to outbound connections.
The source and destination IP address must be the same address family (IPv4/IPv6). If IP addresses are NULL
the connection is assumed to be local (not proxied data).
This can be called multiple times setting or clearing proxy client information. However, the information is only sent on connect. Multiple inbound connections cannot be multiplexed on the same outbound connection. If changing endpoint information the outbound connection needs to disconnect first.
This should be called using an inbound network connection to determine the connection information.
[in] | io | io object. |
[in] | source_ipaddr | Source ipaddress |
[in] | dest_ipaddr | Destination ipaddress |
[in] | source_port | Source port |
[in] | dest_port | Destination port |