diff --git a/include/proto/stream_interface.h b/include/proto/stream_interface.h index 9a619f862..83c389a83 100644 --- a/include/proto/stream_interface.h +++ b/include/proto/stream_interface.h @@ -52,6 +52,11 @@ static inline const struct sock_ops *si_data(struct stream_interface *si) return si->conn.data; } +static inline int si_fd(struct stream_interface *si) +{ + return si->conn.t.sock.fd; +} + static inline void clear_target(struct target *dest) { dest->type = TARG_TYPE_NONE; @@ -121,7 +126,7 @@ static inline void si_get_from_addr(struct stream_interface *si) if (!si_ctrl(si) || !si_ctrl(si)->get_src) return; - if (si_ctrl(si)->get_src(si->fd, (struct sockaddr *)&si->addr.from, + if (si_ctrl(si)->get_src(si_fd(si), (struct sockaddr *)&si->addr.from, sizeof(si->addr.from), si->target.type != TARG_TYPE_CLIENT) == -1) return; @@ -137,7 +142,7 @@ static inline void si_get_to_addr(struct stream_interface *si) if (!si_ctrl(si) || !si_ctrl(si)->get_dst) return; - if (si_ctrl(si)->get_dst(si->fd, (struct sockaddr *)&si->addr.to, + if (si_ctrl(si)->get_dst(si_fd(si), (struct sockaddr *)&si->addr.to, sizeof(si->addr.to), si->target.type != TARG_TYPE_CLIENT) == -1) return; diff --git a/include/types/stream_interface.h b/include/types/stream_interface.h index d573c585e..ccaa1ebaa 100644 --- a/include/types/stream_interface.h +++ b/include/types/stream_interface.h @@ -105,6 +105,11 @@ struct stream_interface; struct connection { const struct sock_ops *data; /* operations at the data layer */ const struct protocol *ctrl; /* operations at the control layer, generally a protocol */ + union { /* definitions which depend on connection type */ + struct { /*** information used by socket-based connections ***/ + int fd; /* file descriptor for a stream driver when known */ + } sock; + } t; }; struct target { @@ -158,7 +163,6 @@ struct stream_interface { struct target target; /* the target to connect to (server, proxy, applet, ...) */ int conn_retries; /* number of connect retries left */ int send_proxy_ofs; /* <0 = offset to (re)send from the end, >0 = send all */ - int fd; /* file descriptor for a stream driver when known */ struct { int state; /* applet state, initialized to zero */ void *private; /* may be used by any function above */ diff --git a/src/dumpstats.c b/src/dumpstats.c index 65f076da9..8a816789b 100644 --- a/src/dumpstats.c +++ b/src/dumpstats.c @@ -3347,7 +3347,7 @@ static int stats_dump_full_sess_to_buffer(struct stream_interface *si) &sess->si[0], sess->si[0].state, sess->si[0].flags, - sess->si[0].fd, + si_fd(&sess->si[0]), sess->si[0].exp ? tick_is_expired(sess->si[0].exp, now_ms) ? "" : human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), @@ -3359,7 +3359,7 @@ static int stats_dump_full_sess_to_buffer(struct stream_interface *si) &sess->si[1], sess->si[1].state, sess->si[1].flags, - sess->si[1].fd, + si_fd(&sess->si[1]), sess->si[1].exp ? tick_is_expired(sess->si[1].exp, now_ms) ? "" : human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), @@ -3590,7 +3590,7 @@ static int stats_dump_sess_to_buffer(struct stream_interface *si) " s0=[%d,%1xh,fd=%d,ex=%s]", curr_sess->si[0].state, curr_sess->si[0].flags, - curr_sess->si[0].fd, + si_fd(&curr_sess->si[0]), curr_sess->si[0].exp ? human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), TICKS_TO_MS(1000)) : ""); @@ -3599,7 +3599,7 @@ static int stats_dump_sess_to_buffer(struct stream_interface *si) " s1=[%d,%1xh,fd=%d,ex=%s]", curr_sess->si[1].state, curr_sess->si[1].flags, - curr_sess->si[1].fd, + si_fd(&curr_sess->si[1]), curr_sess->si[1].exp ? human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), TICKS_TO_MS(1000)) : ""); diff --git a/src/frontend.c b/src/frontend.c index d2a9e70bf..63a2c1ffd 100644 --- a/src/frontend.c +++ b/src/frontend.c @@ -52,7 +52,7 @@ */ int frontend_accept(struct session *s) { - int cfd = s->si[0].fd; + int cfd = si_fd(&s->si[0]); tv_zero(&s->logs.tv_request); s->logs.t_queue = -1; diff --git a/src/peers.c b/src/peers.c index db22a843d..6fcf2f301 100644 --- a/src/peers.c +++ b/src/peers.c @@ -1149,7 +1149,7 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio s->req = s->rep = NULL; /* will be allocated later */ - s->si[0].fd = -1; + s->si[0].conn.t.sock.fd = -1; s->si[0].owner = t; s->si[0].state = s->si[0].prev_state = SI_ST_EST; s->si[0].err_type = SI_ET_NONE; @@ -1167,7 +1167,7 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio stream_int_register_handler(&s->si[0], &peer_applet); - s->si[1].fd = -1; /* just to help with debugging */ + s->si[1].conn.t.sock.fd = -1; /* just to help with debugging */ s->si[1].owner = t; s->si[1].state = s->si[1].prev_state = SI_ST_ASS; s->si[1].conn_retries = p->conn_retries; diff --git a/src/proto_http.c b/src/proto_http.c index 850589eb6..189fcf3ac 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -2211,7 +2211,7 @@ int http_wait_for_request(struct session *s, struct buffer *req, int an_bit) * previously disabled it, otherwise we might cause the client * to delay next data. */ - setsockopt(s->si[0].fd, IPPROTO_TCP, TCP_QUICKACK, &one, sizeof(one)); + setsockopt(si_fd(&s->si[0]), IPPROTO_TCP, TCP_QUICKACK, &one, sizeof(one)); } #endif @@ -3406,7 +3406,7 @@ int http_process_request(struct session *s, struct buffer *req, int an_bit) if ((s->listener->options & LI_O_NOQUICKACK) && ((msg->flags & HTTP_MSGF_TE_CHNK) || (msg->body_len > req->i - txn->req.eoh - 2))) - setsockopt(s->si[0].fd, IPPROTO_TCP, TCP_QUICKACK, &one, sizeof(one)); + setsockopt(si_fd(&s->si[0]), IPPROTO_TCP, TCP_QUICKACK, &one, sizeof(one)); #endif } @@ -3759,7 +3759,7 @@ void http_end_txn_clean_session(struct session *s) clear_target(&s->target); s->req->cons->state = s->req->cons->prev_state = SI_ST_INI; - s->req->cons->fd = -1; /* just to help with debugging */ + s->req->cons->conn.t.sock.fd = -1; /* just to help with debugging */ s->req->cons->err_type = SI_ET_NONE; s->req->cons->conn_retries = 0; /* used for logging too */ s->req->cons->err_loc = NULL; @@ -7293,7 +7293,7 @@ void debug_hdr(const char *dir, struct session *t, const char *start, const char { int len, max; len = sprintf(trash, "%08x:%s.%s[%04x:%04x]: ", t->uniq_id, t->be->id, - dir, (unsigned short)t->req->prod->fd, (unsigned short)t->req->cons->fd); + dir, (unsigned short)si_fd(t->req->prod), (unsigned short)si_fd(t->req->cons)); max = end - start; UBOUND(max, trashlen - len - 1); len += strlcpy2(trash + len, start, max + 1); diff --git a/src/proto_tcp.c b/src/proto_tcp.c index 02b20dd4a..ccd9e4861 100644 --- a/src/proto_tcp.c +++ b/src/proto_tcp.c @@ -237,7 +237,7 @@ int tcp_connect_server(struct stream_interface *si) return SN_ERR_INTERNAL; } - if ((fd = si->fd = socket(si->addr.to.ss_family, SOCK_STREAM, IPPROTO_TCP)) == -1) { + if ((fd = si->conn.t.sock.fd = socket(si->addr.to.ss_family, SOCK_STREAM, IPPROTO_TCP)) == -1) { qfprintf(stderr, "Cannot get a server socket.\n"); if (errno == ENFILE) @@ -555,7 +555,7 @@ static int tcp_connect_write(int fd) si->send_proxy_ofs = -ret; /* first call */ /* we have to send trash from (ret+sp for -sp bytes) */ - ret = send(si->fd, trash + ret + si->send_proxy_ofs, -si->send_proxy_ofs, + ret = send(fd, trash + ret + si->send_proxy_ofs, -si->send_proxy_ofs, (b->flags & BF_OUT_EMPTY) ? 0 : MSG_MORE); if (ret == 0) diff --git a/src/session.c b/src/session.c index 8a2704148..6db9f31c5 100644 --- a/src/session.c +++ b/src/session.c @@ -161,7 +161,7 @@ int session_accept(struct listener *l, int cfd, struct sockaddr_storage *addr) } /* this part should be common with other protocols */ - s->si[0].fd = cfd; + s->si[0].conn.t.sock.fd = cfd; s->si[0].owner = t; s->si[0].state = s->si[0].prev_state = SI_ST_EST; s->si[0].err_type = SI_ET_NONE; @@ -185,7 +185,7 @@ int session_accept(struct listener *l, int cfd, struct sockaddr_storage *addr) /* pre-initialize the other side's stream interface to an INIT state. The * callbacks will be initialized before attempting to connect. */ - s->si[1].fd = -1; /* just to help with debugging */ + s->si[1].conn.t.sock.fd = -1; /* just to help with debugging */ s->si[1].owner = t; s->si[1].state = s->si[1].prev_state = SI_ST_INI; s->si[1].err_type = SI_ET_NONE; @@ -543,7 +543,7 @@ static int sess_update_st_con_tcp(struct session *s, struct stream_interface *si si->exp = TICK_ETERNITY; si->state = SI_ST_CER; si->flags &= ~SI_FL_CAP_SPLICE; - fd_delete(si->fd); + fd_delete(si_fd(si)); if (si->release) si->release(si); @@ -2079,8 +2079,8 @@ struct task *process_session(struct task *t) s->si[1].prev_state == SI_ST_EST) { len = sprintf(trash, "%08x:%s.srvcls[%04x:%04x]\n", s->uniq_id, s->be->id, - (unsigned short)s->si[0].fd, - (unsigned short)s->si[1].fd); + (unsigned short)si_fd(&s->si[0]), + (unsigned short)si_fd(&s->si[1])); if (write(1, trash, len) < 0) /* shut gcc warning */; } @@ -2088,8 +2088,8 @@ struct task *process_session(struct task *t) s->si[0].prev_state == SI_ST_EST) { len = sprintf(trash, "%08x:%s.clicls[%04x:%04x]\n", s->uniq_id, s->be->id, - (unsigned short)s->si[0].fd, - (unsigned short)s->si[1].fd); + (unsigned short)si_fd(&s->si[0]), + (unsigned short)si_fd(&s->si[1])); if (write(1, trash, len) < 0) /* shut gcc warning */; } } @@ -2196,7 +2196,7 @@ struct task *process_session(struct task *t) int len; len = sprintf(trash, "%08x:%s.closed[%04x:%04x]\n", s->uniq_id, s->be->id, - (unsigned short)s->req->prod->fd, (unsigned short)s->req->cons->fd); + (unsigned short)si_fd(s->req->prod), (unsigned short)si_fd(s->req->cons)); if (write(1, trash, len) < 0) /* shut gcc warning */; } diff --git a/src/sock_raw.c b/src/sock_raw.c index 143d14511..1205b2e49 100644 --- a/src/sock_raw.c +++ b/src/sock_raw.c @@ -84,7 +84,7 @@ static void sock_raw_chk_snd(struct stream_interface *si); static int sock_raw_splice_in(struct buffer *b, struct stream_interface *si) { static int splice_detects_close; - int fd = si->fd; + int fd = si_fd(si); int ret; unsigned long max; int retval = 1; @@ -526,7 +526,7 @@ static int sock_raw_write_loop(struct stream_interface *si, struct buffer *b) #if defined(CONFIG_HAP_LINUX_SPLICE) while (b->pipe) { - ret = splice(b->pipe->cons, NULL, si->fd, NULL, b->pipe->data, + ret = splice(b->pipe->cons, NULL, si_fd(si), NULL, b->pipe->data, SPLICE_F_MOVE|SPLICE_F_NONBLOCK); if (ret <= 0) { if (ret == 0 || errno == EAGAIN) { @@ -601,21 +601,21 @@ static int sock_raw_write_loop(struct stream_interface *si, struct buffer *b) if (b->flags & BF_SEND_DONTWAIT) send_flag &= ~MSG_MORE; - ret = send(si->fd, bo_ptr(b), max, send_flag); + ret = send(si_fd(si), bo_ptr(b), max, send_flag); } else { int skerr; socklen_t lskerr = sizeof(skerr); - ret = getsockopt(si->fd, SOL_SOCKET, SO_ERROR, &skerr, &lskerr); + ret = getsockopt(si_fd(si), SOL_SOCKET, SO_ERROR, &skerr, &lskerr); if (ret == -1 || skerr) ret = -1; else - ret = send(si->fd, bo_ptr(b), max, MSG_DONTWAIT); + ret = send(si_fd(si), bo_ptr(b), max, MSG_DONTWAIT); } if (ret > 0) { - if (fdtab[si->fd].state == FD_STCONN) { - fdtab[si->fd].state = FD_STREADY; + if (fdtab[si_fd(si)].state == FD_STCONN) { + fdtab[si_fd(si)].state = FD_STREADY; si->exp = TICK_ETERNITY; } @@ -788,12 +788,12 @@ static void sock_raw_shutw(struct stream_interface *si) } else if (si->flags & SI_FL_NOLINGER) { si->flags &= ~SI_FL_NOLINGER; - setsockopt(si->fd, SOL_SOCKET, SO_LINGER, + setsockopt(si_fd(si), SOL_SOCKET, SO_LINGER, (struct linger *) &nolinger, sizeof(struct linger)); } else if (!(si->flags & SI_FL_NOHALF)) { - EV_FD_CLR(si->fd, DIR_WR); - shutdown(si->fd, SHUT_WR); + EV_FD_CLR(si_fd(si), DIR_WR); + shutdown(si_fd(si), SHUT_WR); if (!(si->ib->flags & (BF_SHUTR|BF_DONT_READ))) return; @@ -804,7 +804,7 @@ static void sock_raw_shutw(struct stream_interface *si) /* we may have to close a pending connection, and mark the * response buffer as shutr */ - fd_delete(si->fd); + fd_delete(si_fd(si)); /* fall through */ case SI_ST_CER: case SI_ST_QUE: @@ -841,7 +841,7 @@ static void sock_raw_shutr(struct stream_interface *si) return; if (si->ob->flags & BF_SHUTW) { - fd_delete(si->fd); + fd_delete(si_fd(si)); si->state = SI_ST_DIS; si->exp = TICK_ETERNITY; @@ -853,7 +853,7 @@ static void sock_raw_shutr(struct stream_interface *si) /* we want to immediately forward this close to the write side */ return sock_raw_shutw(si); } - EV_FD_CLR(si->fd, DIR_RD); + EV_FD_CLR(si_fd(si), DIR_RD); return; } @@ -867,7 +867,7 @@ static void sock_raw_data_finish(struct stream_interface *si) { struct buffer *ib = si->ib; struct buffer *ob = si->ob; - int fd = si->fd; + int fd = si_fd(si); DPRINTF(stderr,"[%u] %s: fd=%d owner=%p ib=%p, ob=%p, exp(r,w)=%u,%u ibf=%08x obf=%08x ibh=%d ibt=%d obh=%d obd=%d si=%d\n", now_ms, __FUNCTION__, @@ -949,7 +949,7 @@ static void sock_raw_chk_rcv(struct stream_interface *si) DPRINTF(stderr,"[%u] %s: fd=%d owner=%p ib=%p, ob=%p, exp(r,w)=%u,%u ibf=%08x obf=%08x ibh=%d ibt=%d obh=%d obd=%d si=%d\n", now_ms, __FUNCTION__, - si->fd, fdtab[si->fd].owner, + si_fd(si), fdtab[si_fd(si)].owner, ib, si->ob, ib->rex, si->ob->wex, ib->flags, si->ob->flags, @@ -962,12 +962,12 @@ static void sock_raw_chk_rcv(struct stream_interface *si) /* stop reading */ if ((ib->flags & (BF_FULL|BF_HIJACK|BF_DONT_READ)) == BF_FULL) si->flags |= SI_FL_WAIT_ROOM; - EV_FD_COND_C(si->fd, DIR_RD); + EV_FD_COND_C(si_fd(si), DIR_RD); } else { /* (re)start reading */ si->flags &= ~SI_FL_WAIT_ROOM; - EV_FD_COND_S(si->fd, DIR_RD); + EV_FD_COND_S(si_fd(si), DIR_RD); } } @@ -984,7 +984,7 @@ static void sock_raw_chk_snd(struct stream_interface *si) DPRINTF(stderr,"[%u] %s: fd=%d owner=%p ib=%p, ob=%p, exp(r,w)=%u,%u ibf=%08x obf=%08x ibh=%d ibt=%d obh=%d obd=%d si=%d\n", now_ms, __FUNCTION__, - si->fd, fdtab[si->fd].owner, + si_fd(si), fdtab[si_fd(si)].owner, si->ib, ob, si->ib->rex, ob->wex, si->ib->flags, ob->flags, @@ -998,7 +998,7 @@ static void sock_raw_chk_snd(struct stream_interface *si) if (!ob->pipe && /* spliced data wants to be forwarded ASAP */ (!(si->flags & SI_FL_WAIT_DATA) || /* not waiting for data */ - (fdtab[si->fd].ev & FD_POLL_OUT))) /* we'll be called anyway */ + (fdtab[si_fd(si)].ev & FD_POLL_OUT))) /* we'll be called anyway */ return; retval = sock_raw_write_loop(si, ob); @@ -1011,9 +1011,9 @@ static void sock_raw_chk_snd(struct stream_interface *si) /* Write error on the file descriptor. We mark the FD as STERROR so * that we don't use it anymore and we notify the task. */ - fdtab[si->fd].state = FD_STERROR; - fdtab[si->fd].ev &= ~FD_POLL_STICKY; - EV_FD_REM(si->fd); + fdtab[si_fd(si)].state = FD_STERROR; + fdtab[si_fd(si)].ev &= ~FD_POLL_STICKY; + EV_FD_REM(si_fd(si)); si->flags |= SI_FL_ERR; goto out_wakeup; } @@ -1043,7 +1043,7 @@ static void sock_raw_chk_snd(struct stream_interface *si) /* Otherwise there are remaining data to be sent in the buffer, * which means we have to poll before doing so. */ - EV_FD_COND_S(si->fd, DIR_WR); + EV_FD_COND_S(si_fd(si), DIR_WR); si->flags &= ~SI_FL_WAIT_DATA; if (!tick_isset(ob->wex)) ob->wex = tick_add_ifset(now_ms, ob->wto);