Core: Add support for systemd socket activation.

This change adds support for socket activation of certain SOCK_STREAM
listeners in Asterisk:
* AMI / AMI over TLS
* CLI
* HTTP / HTTPS

Example systemd units are provided.  This support extends to any socket
which is initialized using ast_tcptls_server_start, so any unknown
modules using this function will support socket activation.

Asterisk continues to function as normal if socket activation is not
enabled or if systemd development headers are not available during
build.

ASTERISK-27063 #close

Change-Id: Id814ee6a892f4b80d018365c8ad8d89063474f4d
This commit is contained in:
Corey Farrell
2017-06-18 20:24:04 -04:00
parent 58d50025a0
commit 70d2ccb9da
13 changed files with 384 additions and 3 deletions

View File

@@ -24,6 +24,7 @@
#define _ASTERISK_IO_H
#include "asterisk/poll-compat.h"
#include "asterisk/netsock2.h"
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
@@ -148,6 +149,29 @@ int ast_get_termcols(int fd);
*/
int ast_sd_notify(const char *state);
/*!
* \brief Find a listening file descriptor provided by socket activation.
* \param type SOCK_STREAM or SOCK_DGRAM
* \param addr The socket address of the bound listener.
* \retval <0 No match.
* \retval >0 File Descriptor matching sockaddr.
*
* \note This function returns -1 if systemd's development headers were not
* detected on the system.
*/
int ast_sd_get_fd(int type, const struct ast_sockaddr *addr);
/*!
* \brief Find a listening AF_LOCAL file descriptor provided by socket activation.
* \param type SOCK_STREAM or SOCK_DGRAM
* \param path The path of the listener.
* \retval <0 No match.
* \retval >0 File Descriptor matching path.
*
* \note This function returns -1 if systemd's development headers were not
* detected on the system.
*/
int ast_sd_get_fd_un(int type, const char *path);
#if defined(__cplusplus) || defined(c_plusplus)
}

View File

@@ -128,6 +128,22 @@ static inline void ast_sockaddr_setnull(struct ast_sockaddr *addr)
addr->len = 0;
}
/*!
* \brief
* Copies the data from a sockaddr to an ast_sockaddr
*
* \param dst The destination ast_sockaddr
* \param src The source sockaddr
* \param len Length of the value stored in sockaddr
* \retval void
*/
static inline void ast_sockaddr_copy_sockaddr(struct ast_sockaddr *dst,
struct sockaddr *src, socklen_t len)
{
memcpy(dst, src, len);
dst->len = len;
}
/*!
* \since 1.8
*