mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-06 15:17:01 +02:00
MINOR: protocol: add a real family for existing FDs
At some places (log fd@XXX, bind fd@XXX) we support using an explicit file descriptor number, that is placed into the sockaddr for later use. The problem is that till now it was done with an AF_UNSPEC family, which is also used for other situations like missing info or rings (for logs). Let's create an "official" family AF_CUST_EXISTING_FD for this case so that we are certain the FD can be found in the address when it is set.
This commit is contained in:
parent
1e984b73f0
commit
a5b325f92c
@ -37,10 +37,11 @@ struct connection;
|
|||||||
* Custom network family for str2sa parsing. Should be ok to do this since
|
* Custom network family for str2sa parsing. Should be ok to do this since
|
||||||
* sa_family_t is standardized as an unsigned integer
|
* sa_family_t is standardized as an unsigned integer
|
||||||
*/
|
*/
|
||||||
#define AF_CUST_SOCKPAIR (AF_MAX + 1)
|
#define AF_CUST_EXISTING_FD (AF_MAX + 1)
|
||||||
#define AF_CUST_UDP4 (AF_MAX + 2)
|
#define AF_CUST_SOCKPAIR (AF_MAX + 2)
|
||||||
#define AF_CUST_UDP6 (AF_MAX + 3)
|
#define AF_CUST_UDP4 (AF_MAX + 3)
|
||||||
#define AF_CUST_MAX (AF_MAX + 4)
|
#define AF_CUST_UDP6 (AF_MAX + 4)
|
||||||
|
#define AF_CUST_MAX (AF_MAX + 5)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Test in case AF_CUST_MAX overflows the sa_family_t (unsigned int)
|
* Test in case AF_CUST_MAX overflows the sa_family_t (unsigned int)
|
||||||
|
@ -156,7 +156,7 @@ int str2listener(char *str, struct proxy *curproxy, struct bind_conf *bind_conf,
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (ss2->ss_family == AF_UNSPEC) {
|
else if (ss2->ss_family == AF_CUST_EXISTING_FD) {
|
||||||
socklen_t addr_len;
|
socklen_t addr_len;
|
||||||
inherited = 1;
|
inherited = 1;
|
||||||
|
|
||||||
|
27
src/log.c
27
src/log.c
@ -1754,14 +1754,14 @@ static inline void __do_send_log(struct logsrv *logsrv, int nblogger, int level,
|
|||||||
while (size && (message[size-1] == '\n' || (message[size-1] == 0)))
|
while (size && (message[size-1] == '\n' || (message[size-1] == 0)))
|
||||||
size--;
|
size--;
|
||||||
|
|
||||||
if (logsrv->type == LOG_TARGET_FD) {
|
if (logsrv->type == LOG_TARGET_BUFFER) {
|
||||||
/* the socket's address is a file descriptor */
|
|
||||||
plogfd = (int *)&((struct sockaddr_in *)&logsrv->addr)->sin_addr.s_addr;
|
|
||||||
}
|
|
||||||
else if (logsrv->type == LOG_TARGET_BUFFER) {
|
|
||||||
plogfd = NULL;
|
plogfd = NULL;
|
||||||
goto send;
|
goto send;
|
||||||
}
|
}
|
||||||
|
else if (logsrv->addr.ss_family == AF_CUST_EXISTING_FD) {
|
||||||
|
/* the socket's address is a file descriptor */
|
||||||
|
plogfd = (int *)&((struct sockaddr_in *)&logsrv->addr)->sin_addr.s_addr;
|
||||||
|
}
|
||||||
else if (logsrv->addr.ss_family == AF_UNIX)
|
else if (logsrv->addr.ss_family == AF_UNIX)
|
||||||
plogfd = &logfdunix;
|
plogfd = &logfdunix;
|
||||||
else
|
else
|
||||||
@ -1790,18 +1790,23 @@ static inline void __do_send_log(struct logsrv *logsrv, int nblogger, int level,
|
|||||||
|
|
||||||
msg_header = build_log_header(logsrv->format, level, facility, metadata, &nbelem);
|
msg_header = build_log_header(logsrv->format, level, facility, metadata, &nbelem);
|
||||||
send:
|
send:
|
||||||
if (logsrv->addr.ss_family == AF_UNSPEC) {
|
if (logsrv->type == LOG_TARGET_BUFFER) {
|
||||||
struct ist msg;
|
struct ist msg;
|
||||||
|
|
||||||
msg = ist2(message, size);
|
msg = ist2(message, size);
|
||||||
if (msg.len > logsrv->maxlen)
|
if (msg.len > logsrv->maxlen)
|
||||||
msg.len = logsrv->maxlen;
|
msg.len = logsrv->maxlen;
|
||||||
|
|
||||||
if (logsrv->type == LOG_TARGET_BUFFER) {
|
sent = sink_write(logsrv->sink, &msg, 1, level, logsrv->facility, metadata);
|
||||||
sent = sink_write(logsrv->sink, &msg, 1, level, logsrv->facility, metadata);
|
}
|
||||||
}
|
else if (logsrv->addr.ss_family == AF_CUST_EXISTING_FD) {
|
||||||
else /* LOG_TARGET_FD */
|
struct ist msg;
|
||||||
sent = fd_write_frag_line(*plogfd, logsrv->maxlen, msg_header, nbelem, &msg, 1, 1);
|
|
||||||
|
msg = ist2(message, size);
|
||||||
|
if (msg.len > logsrv->maxlen)
|
||||||
|
msg.len = logsrv->maxlen;
|
||||||
|
|
||||||
|
sent = fd_write_frag_line(*plogfd, logsrv->maxlen, msg_header, nbelem, &msg, 1, 1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
@ -861,7 +861,8 @@ struct sockaddr_storage *str2ip2(const char *str, struct sockaddr_storage *sa, i
|
|||||||
* <fqdn> was filled, indicating the need for a resolution.
|
* <fqdn> was filled, indicating the need for a resolution.
|
||||||
*
|
*
|
||||||
* When a file descriptor is passed, its value is put into the s_addr part of
|
* When a file descriptor is passed, its value is put into the s_addr part of
|
||||||
* the address when cast to sockaddr_in and the address family is AF_UNSPEC.
|
* the address when cast to sockaddr_in and the address family is
|
||||||
|
* AF_CUST_EXISTING_FD.
|
||||||
*/
|
*/
|
||||||
struct sockaddr_storage *str2sa_range(const char *str, int *port, int *low, int *high, char **err, const char *pfx, char **fqdn, int resolve)
|
struct sockaddr_storage *str2sa_range(const char *str, int *port, int *low, int *high, char **err, const char *pfx, char **fqdn, int resolve)
|
||||||
{
|
{
|
||||||
@ -957,8 +958,8 @@ struct sockaddr_storage *str2sa_range(const char *str, int *port, int *low, int
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* we return AF_UNSPEC if we use a file descriptor number */
|
/* we return AF_CUST_EXISTING_FD if we use a file descriptor number */
|
||||||
ss.ss_family = AF_UNSPEC;
|
ss.ss_family = AF_CUST_EXISTING_FD;
|
||||||
}
|
}
|
||||||
else if (ss.ss_family == AF_UNIX) {
|
else if (ss.ss_family == AF_UNIX) {
|
||||||
struct sockaddr_un *un = (struct sockaddr_un *)&ss;
|
struct sockaddr_un *un = (struct sockaddr_un *)&ss;
|
||||||
|
Loading…
Reference in New Issue
Block a user