mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-09 16:47:18 +02:00
[MEDIUM] moved the sockaddr pointer to the fdtab structure
The stream_sock_* functions had to know about sessions just in order to get the server's address for a connect() operation. This is not desirable, particularly for non-IP protocols (eg: PF_UNIX). Put a pointer to the peer's sockaddr_storage or sockaddr address in the fdtab structure so that we never need to look further. With this small change, the stream_sock.c file is now 100% protocol independant.
This commit is contained in:
parent
d9db9274fe
commit
e94ebd0e37
@ -22,6 +22,7 @@
|
|||||||
#ifndef _TYPES_FD_H
|
#ifndef _TYPES_FD_H
|
||||||
#define _TYPES_FD_H
|
#define _TYPES_FD_H
|
||||||
|
|
||||||
|
#include <sys/socket.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -63,6 +64,8 @@ struct fdtab {
|
|||||||
struct task *owner; /* the session (or proxy) associated with this fd */
|
struct task *owner; /* the session (or proxy) associated with this fd */
|
||||||
unsigned char state; /* the state of this fd */
|
unsigned char state; /* the state of this fd */
|
||||||
unsigned char ev; /* event seen in return of poll() : FD_POLL_* */
|
unsigned char ev; /* event seen in return of poll() : FD_POLL_* */
|
||||||
|
struct sockaddr *peeraddr; /* pointer to peer's network address, or NULL if unset */
|
||||||
|
socklen_t peerlen; /* peer's address length, or 0 if unset */
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -545,7 +545,10 @@ int connect_server(struct session *s)
|
|||||||
fdtab[fd].cb[DIR_RD].b = s->rep;
|
fdtab[fd].cb[DIR_RD].b = s->rep;
|
||||||
fdtab[fd].cb[DIR_WR].f = &stream_sock_write;
|
fdtab[fd].cb[DIR_WR].f = &stream_sock_write;
|
||||||
fdtab[fd].cb[DIR_WR].b = s->req;
|
fdtab[fd].cb[DIR_WR].b = s->req;
|
||||||
|
|
||||||
|
fdtab[fd].peeraddr = (struct sockaddr *)&s->srv_addr;
|
||||||
|
fdtab[fd].peerlen = sizeof(s->srv_addr);
|
||||||
|
|
||||||
EV_FD_SET(fd, DIR_WR); /* for connect status */
|
EV_FD_SET(fd, DIR_WR); /* for connect status */
|
||||||
|
|
||||||
fd_insert(fd);
|
fd_insert(fd);
|
||||||
|
@ -403,6 +403,8 @@ void process_chk(struct task *t, struct timeval *next)
|
|||||||
fdtab[fd].cb[DIR_RD].b = NULL;
|
fdtab[fd].cb[DIR_RD].b = NULL;
|
||||||
fdtab[fd].cb[DIR_WR].f = &event_srv_chk_w;
|
fdtab[fd].cb[DIR_WR].f = &event_srv_chk_w;
|
||||||
fdtab[fd].cb[DIR_WR].b = NULL;
|
fdtab[fd].cb[DIR_WR].b = NULL;
|
||||||
|
fdtab[fd].peeraddr = (struct sockaddr *)&sa;
|
||||||
|
fdtab[fd].peerlen = sizeof(sa);
|
||||||
fdtab[fd].state = FD_STCONN; /* connection in progress */
|
fdtab[fd].state = FD_STCONN; /* connection in progress */
|
||||||
fdtab[fd].ev = 0;
|
fdtab[fd].ev = 0;
|
||||||
EV_FD_SET(fd, DIR_WR); /* for connect status */
|
EV_FD_SET(fd, DIR_WR); /* for connect status */
|
||||||
|
@ -397,6 +397,8 @@ int event_accept(int fd) {
|
|||||||
fdtab[cfd].cb[DIR_RD].b = s->req;
|
fdtab[cfd].cb[DIR_RD].b = s->req;
|
||||||
fdtab[cfd].cb[DIR_WR].f = &stream_sock_write;
|
fdtab[cfd].cb[DIR_WR].f = &stream_sock_write;
|
||||||
fdtab[cfd].cb[DIR_WR].b = s->rep;
|
fdtab[cfd].cb[DIR_WR].b = s->rep;
|
||||||
|
fdtab[cfd].peeraddr = (struct sockaddr *)&s->cli_addr;
|
||||||
|
fdtab[cfd].peerlen = sizeof(s->cli_addr);
|
||||||
fdtab[cfd].ev = 0;
|
fdtab[cfd].ev = 0;
|
||||||
|
|
||||||
if ((p->mode == PR_MODE_HTTP && (s->flags & SN_MONITOR)) ||
|
if ((p->mode == PR_MODE_HTTP && (s->flags & SN_MONITOR)) ||
|
||||||
|
@ -158,6 +158,8 @@ int start_proxies(int verbose)
|
|||||||
fdtab[fd].cb[DIR_RD].b = fdtab[fd].cb[DIR_WR].b = NULL;
|
fdtab[fd].cb[DIR_RD].b = fdtab[fd].cb[DIR_WR].b = NULL;
|
||||||
fdtab[fd].owner = (struct task *)curproxy; /* reference the proxy instead of a task */
|
fdtab[fd].owner = (struct task *)curproxy; /* reference the proxy instead of a task */
|
||||||
fdtab[fd].state = FD_STLISTEN;
|
fdtab[fd].state = FD_STLISTEN;
|
||||||
|
fdtab[fd].peeraddr = NULL;
|
||||||
|
fdtab[fd].peerlen = 0;
|
||||||
fdtab[fd].ev = 0;
|
fdtab[fd].ev = 0;
|
||||||
listeners++;
|
listeners++;
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,6 @@
|
|||||||
#include <types/buffers.h>
|
#include <types/buffers.h>
|
||||||
#include <types/global.h>
|
#include <types/global.h>
|
||||||
#include <types/polling.h>
|
#include <types/polling.h>
|
||||||
#include <types/session.h>
|
|
||||||
|
|
||||||
#include <proto/client.h>
|
#include <proto/client.h>
|
||||||
#include <proto/fd.h>
|
#include <proto/fd.h>
|
||||||
@ -229,8 +228,6 @@ int stream_sock_write(int fd) {
|
|||||||
if (max == 0) {
|
if (max == 0) {
|
||||||
/* may be we have received a connection acknowledgement in TCP mode without data */
|
/* may be we have received a connection acknowledgement in TCP mode without data */
|
||||||
if (likely(fdtab[fd].state == FD_STCONN)) {
|
if (likely(fdtab[fd].state == FD_STCONN)) {
|
||||||
struct session *s = fdtab[fd].owner->context;
|
|
||||||
|
|
||||||
/* We have no data to send to check the connection, and
|
/* We have no data to send to check the connection, and
|
||||||
* getsockopt() will not inform us whether the connection
|
* getsockopt() will not inform us whether the connection
|
||||||
* is still pending. So we'll reuse connect() to check the
|
* is still pending. So we'll reuse connect() to check the
|
||||||
@ -240,7 +237,7 @@ int stream_sock_write(int fd) {
|
|||||||
* - connecting (EALREADY, EINPROGRESS)
|
* - connecting (EALREADY, EINPROGRESS)
|
||||||
* - connected (EISCONN, 0)
|
* - connected (EISCONN, 0)
|
||||||
*/
|
*/
|
||||||
if ((connect(fd, (struct sockaddr *)&s->srv_addr, sizeof(s->srv_addr)) == 0))
|
if ((connect(fd, fdtab[fd].peeraddr, fdtab[fd].peerlen) == 0))
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
|
||||||
if (errno == EALREADY || errno == EINPROGRESS) {
|
if (errno == EALREADY || errno == EINPROGRESS) {
|
||||||
|
Loading…
Reference in New Issue
Block a user