Local outbound address

Get or set the local IP address for outbound connections.

Synopsis

#include <ts/ts.h>
sockaddr const *TSHttpTxnOutgoingAddrGet(TSHttpTxn txnp)
TSReturnCode TSHttpTxnOutgoingAddrSet(TSHttpTxn txnp, sockaddr const *addr)

Description

These functions concern the local IP address and port, that is the address and port on the Traffic Server side of outbound connections (network connections from Traffic Server to another socket).

The address and optional the port can be set with TSHttpTxnOutgoingAddrSet(). This must be done before the outbound connection is made, that is, earlier than the TS_HTTP_SEND_REQUEST_HDR_HOOK. A good choice is the TS_HTTP_POST_REMAP_HOOK, since it is a hook that is always called, and it is the latest hook that is called before the connection is made. The addr must be populated with the IP address and port to be used. If the port is not relevant it can be set to zero, which means use any available local port. This function returns TS_SUCCESS on success and TS_ERROR on failure.

Even on a successful call to TSHttpTxnOutgoingAddrSet(), the local IP address may not match what was passing addr if session sharing is enabled.

Conversely TSHttpTxnOutgoingAddrGet() retrieves the local address and must be called in the TS_HTTP_SEND_REQUEST_HDR_HOOK or later, after the outbound connection has been established. It returns a pointer to a sockaddr which contains the local IP address and port. If there is no valid outbound connection, addr will be NULL. The returned pointer is a transient pointer and must not be referenced after the callback in which TSHttpTxnOutgoingAddrGet() was called.