diff --git a/include/proto/stream_interface.h b/include/proto/stream_interface.h index 83c389a83..632300a9e 100644 --- a/include/proto/stream_interface.h +++ b/include/proto/stream_interface.h @@ -114,6 +114,8 @@ static inline struct server *target_srv(struct target *t) static inline void stream_interface_prepare(struct stream_interface *si, const struct sock_ops *ops) { si->conn.data = ops; + si->conn.data_st = 0; + si->conn.data_ctx = NULL; } diff --git a/include/types/stream_interface.h b/include/types/stream_interface.h index ccaa1ebaa..2afefb5eb 100644 --- a/include/types/stream_interface.h +++ b/include/types/stream_interface.h @@ -110,6 +110,8 @@ struct connection { int fd; /* file descriptor for a stream driver when known */ } sock; } t; + int data_st; /* data layer state, initialized to zero */ + void *data_ctx; /* general purpose pointer, initialized to NULL */ }; struct target { @@ -164,8 +166,6 @@ struct stream_interface { int conn_retries; /* number of connect retries left */ int send_proxy_ofs; /* <0 = offset to (re)send from the end, >0 = send all */ struct { - int state; /* applet state, initialized to zero */ - void *private; /* may be used by any function above */ unsigned int st0, st1; /* may be used by any function above */ union { struct { diff --git a/src/dumpstats.c b/src/dumpstats.c index 8a816789b..6b4c84e79 100644 --- a/src/dumpstats.c +++ b/src/dumpstats.c @@ -125,7 +125,7 @@ static int stats_accept(struct session *s) /* we have a dedicated I/O handler for the stats */ stream_int_register_handler(&s->si[1], &cli_applet); copy_target(&s->target, &s->si[1].target); // for logging only - s->si[1].applet.private = s; + s->si[1].conn.data_ctx = s; s->si[1].applet.st1 = 0; s->si[1].applet.st0 = STAT_CLI_INIT; @@ -417,7 +417,7 @@ static int dump_binary(struct chunk *out, const char *buf, int bsize) static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si, struct proxy *proxy, struct proxy *target) { - struct session *s = si->applet.private; + struct session *s = si->conn.data_ctx; chunk_printf(msg, "# table: %s, type: %s, size:%d, used:%d\n", proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current); @@ -506,7 +506,7 @@ static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_int static void stats_sock_table_key_request(struct stream_interface *si, char **args, bool show) { - struct session *s = si->applet.private; + struct session *s = si->conn.data_ctx; struct proxy *px = si->applet.ctx.table.target; struct stksess *ts; uint32_t uint32_key; @@ -623,7 +623,7 @@ static void stats_sock_table_data_request(struct stream_interface *si, char **ar static void stats_sock_table_request(struct stream_interface *si, char **args, bool show) { si->applet.ctx.table.data_type = -1; - si->applet.state = STAT_ST_INIT; + si->conn.data_st = STAT_ST_INIT; si->applet.ctx.table.target = NULL; si->applet.ctx.table.proxy = NULL; si->applet.ctx.table.entry = NULL; @@ -745,7 +745,7 @@ static struct server *expect_server_admin(struct session *s, struct stream_inter */ static int stats_sock_parse_request(struct stream_interface *si, char *line) { - struct session *s = si->applet.private; + struct session *s = si->conn.data_ctx; char *args[MAX_STATS_ARGS + 1]; int arg; @@ -784,17 +784,17 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line) si->applet.ctx.stats.flags |= STAT_SHOW_STAT; si->applet.ctx.stats.flags |= STAT_FMT_CSV; - si->applet.state = STAT_ST_INIT; + si->conn.data_st = STAT_ST_INIT; si->applet.st0 = STAT_CLI_O_INFO; // stats_dump_raw_to_buffer } else if (strcmp(args[1], "info") == 0) { si->applet.ctx.stats.flags |= STAT_SHOW_INFO; si->applet.ctx.stats.flags |= STAT_FMT_CSV; - si->applet.state = STAT_ST_INIT; + si->conn.data_st = STAT_ST_INIT; si->applet.st0 = STAT_CLI_O_INFO; // stats_dump_raw_to_buffer } else if (strcmp(args[1], "sess") == 0) { - si->applet.state = STAT_ST_INIT; + si->conn.data_st = STAT_ST_INIT; if (s->listener->perm.ux.level < ACCESS_LVL_OPER) { si->applet.ctx.cli.msg = stats_permission_denied_msg; si->applet.st0 = STAT_CLI_PRINT; @@ -819,7 +819,7 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line) else si->applet.ctx.errors.iid = -1; si->applet.ctx.errors.px = NULL; - si->applet.state = STAT_ST_INIT; + si->conn.data_st = STAT_ST_INIT; si->applet.st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer } else if (strcmp(args[1], "table") == 0) { @@ -1567,10 +1567,10 @@ static int stats_dump_raw_to_buffer(struct stream_interface *si) chunk_init(&msg, trash, trashlen); - switch (si->applet.state) { + switch (si->conn.data_st) { case STAT_ST_INIT: /* the function had not been called yet */ - si->applet.state = STAT_ST_HEAD; + si->conn.data_st = STAT_ST_HEAD; /* fall through */ case STAT_ST_HEAD: @@ -1580,7 +1580,7 @@ static int stats_dump_raw_to_buffer(struct stream_interface *si) return 0; } - si->applet.state = STAT_ST_INFO; + si->conn.data_st = STAT_ST_INFO; /* fall through */ case STAT_ST_INFO: @@ -1633,7 +1633,7 @@ static int stats_dump_raw_to_buffer(struct stream_interface *si) si->applet.ctx.stats.px = proxy; si->applet.ctx.stats.px_st = STAT_PX_ST_INIT; si->applet.ctx.stats.sv = NULL; - si->applet.state = STAT_ST_LIST; + si->conn.data_st = STAT_ST_LIST; /* fall through */ case STAT_ST_LIST: @@ -1654,11 +1654,11 @@ static int stats_dump_raw_to_buffer(struct stream_interface *si) /* here, we just have reached the last proxy */ } - si->applet.state = STAT_ST_END; + si->conn.data_st = STAT_ST_END; /* fall through */ case STAT_ST_END: - si->applet.state = STAT_ST_FIN; + si->conn.data_st = STAT_ST_FIN; /* fall through */ case STAT_ST_FIN: @@ -1666,7 +1666,7 @@ static int stats_dump_raw_to_buffer(struct stream_interface *si) default: /* unknown state ! */ - si->applet.state = STAT_ST_FIN; + si->conn.data_st = STAT_ST_FIN; return 1; } } @@ -1678,12 +1678,12 @@ static int stats_dump_raw_to_buffer(struct stream_interface *si) */ static int stats_http_redir(struct stream_interface *si, struct uri_auth *uri) { - struct session *s = si->applet.private; + struct session *s = si->conn.data_ctx; struct chunk msg; chunk_init(&msg, trash, trashlen); - switch (si->applet.state) { + switch (si->conn.data_st) { case STAT_ST_INIT: chunk_printf(&msg, "HTTP/1.0 303 See Other\r\n" @@ -1709,7 +1709,7 @@ static int stats_http_redir(struct stream_interface *si, struct uri_auth *uri) if (!(s->flags & SN_FINST_MASK)) s->flags |= SN_FINST_R; - si->applet.state = STAT_ST_FIN; + si->conn.data_st = STAT_ST_FIN; return 1; } return 1; @@ -1723,7 +1723,7 @@ static int stats_http_redir(struct stream_interface *si, struct uri_auth *uri) */ static void http_stats_io_handler(struct stream_interface *si) { - struct session *s = si->applet.private; + struct session *s = si->conn.data_ctx; struct buffer *req = si->ob; struct buffer *res = si->ib; @@ -1779,7 +1779,7 @@ static void http_stats_io_handler(struct stream_interface *si) */ static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri) { - struct session *s = si->applet.private; + struct session *s = si->conn.data_ctx; struct buffer *rep = si->ib; struct proxy *px; struct chunk msg; @@ -1787,7 +1787,7 @@ static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri) chunk_init(&msg, trash, trashlen); - switch (si->applet.state) { + switch (si->conn.data_st) { case STAT_ST_INIT: chunk_printf(&msg, "HTTP/1.0 200 OK\r\n" @@ -1813,11 +1813,11 @@ static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri) if (s->txn.meth == HTTP_METH_HEAD) { /* that's all we return in case of HEAD request */ - si->applet.state = STAT_ST_FIN; + si->conn.data_st = STAT_ST_FIN; return 1; } - si->applet.state = STAT_ST_HEAD; /* let's start producing data */ + si->conn.data_st = STAT_ST_HEAD; /* let's start producing data */ /* fall through */ case STAT_ST_HEAD: @@ -1921,7 +1921,7 @@ static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri) if (bi_putchk(rep, &msg) == -1) return 0; - si->applet.state = STAT_ST_INFO; + si->conn.data_st = STAT_ST_INFO; /* fall through */ case STAT_ST_INFO: @@ -2099,7 +2099,7 @@ static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri) si->applet.ctx.stats.px = proxy; si->applet.ctx.stats.px_st = STAT_PX_ST_INIT; - si->applet.state = STAT_ST_LIST; + si->conn.data_st = STAT_ST_LIST; /* fall through */ case STAT_ST_LIST: @@ -2118,7 +2118,7 @@ static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri) } /* here, we just have reached the last proxy */ - si->applet.state = STAT_ST_END; + si->conn.data_st = STAT_ST_END; /* fall through */ case STAT_ST_END: @@ -2128,7 +2128,7 @@ static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri) return 0; } - si->applet.state = STAT_ST_FIN; + si->conn.data_st = STAT_ST_FIN; /* fall through */ case STAT_ST_FIN: @@ -2136,7 +2136,7 @@ static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri) default: /* unknown state ! */ - si->applet.state = STAT_ST_FIN; + si->conn.data_st = STAT_ST_FIN; return -1; } } @@ -2149,7 +2149,7 @@ static int stats_dump_http(struct stream_interface *si, struct uri_auth *uri) */ static int stats_dump_proxy(struct stream_interface *si, struct proxy *px, struct uri_auth *uri) { - struct session *s = si->applet.private; + struct session *s = si->conn.data_ctx; struct buffer *rep = si->ib; struct server *sv, *svs; /* server and server-state, server-state=server or server->track */ struct listener *l; @@ -3454,7 +3454,7 @@ static int stats_dump_sess_to_buffer(struct stream_interface *si) /* If we're forced to shut down, we might have to remove our * reference to the last session being dumped. */ - if (si->applet.state == STAT_ST_LIST) { + if (si->conn.data_st == STAT_ST_LIST) { if (!LIST_ISEMPTY(&si->applet.ctx.sess.bref.users)) { LIST_DEL(&si->applet.ctx.sess.bref.users); LIST_INIT(&si->applet.ctx.sess.bref.users); @@ -3465,7 +3465,7 @@ static int stats_dump_sess_to_buffer(struct stream_interface *si) chunk_init(&msg, trash, trashlen); - switch (si->applet.state) { + switch (si->conn.data_st) { case STAT_ST_INIT: /* the function had not been called yet, let's prepare the * buffer for a response. We initialize the current session @@ -3476,7 +3476,7 @@ static int stats_dump_sess_to_buffer(struct stream_interface *si) */ LIST_INIT(&si->applet.ctx.sess.bref.users); si->applet.ctx.sess.bref.ref = sessions.n; - si->applet.state = STAT_ST_LIST; + si->conn.data_st = STAT_ST_LIST; /* fall through */ case STAT_ST_LIST: @@ -3641,11 +3641,11 @@ static int stats_dump_sess_to_buffer(struct stream_interface *si) return 1; } - si->applet.state = STAT_ST_FIN; + si->conn.data_st = STAT_ST_FIN; /* fall through */ default: - si->applet.state = STAT_ST_FIN; + si->conn.data_st = STAT_ST_FIN; return 1; } } @@ -3657,14 +3657,14 @@ static int stats_dump_sess_to_buffer(struct stream_interface *si) */ static int stats_table_request(struct stream_interface *si, bool show) { - struct session *s = si->applet.private; + struct session *s = si->conn.data_ctx; struct chunk msg; struct ebmb_node *eb; int dt; bool skip_entry; /* - * We have 3 possible states in si->applet.state : + * We have 3 possible states in si->conn.data_st : * - STAT_ST_INIT : the first call * - STAT_ST_INFO : the proxy pointer points to the next table to * dump, the entry pointer is NULL ; @@ -3677,7 +3677,7 @@ static int stats_table_request(struct stream_interface *si, bool show) if (unlikely(si->ib->flags & (BF_WRITE_ERROR|BF_SHUTW))) { /* in case of abort, remove any refcount we might have set on an entry */ - if (si->applet.state == STAT_ST_LIST) { + if (si->conn.data_st == STAT_ST_LIST) { si->applet.ctx.table.entry->ref_cnt--; stksess_kill_if_expired(&si->applet.ctx.table.proxy->table, si->applet.ctx.table.entry); } @@ -3686,22 +3686,22 @@ static int stats_table_request(struct stream_interface *si, bool show) chunk_init(&msg, trash, trashlen); - while (si->applet.state != STAT_ST_FIN) { - switch (si->applet.state) { + while (si->conn.data_st != STAT_ST_FIN) { + switch (si->conn.data_st) { case STAT_ST_INIT: si->applet.ctx.table.proxy = si->applet.ctx.table.target; if (!si->applet.ctx.table.proxy) si->applet.ctx.table.proxy = proxy; si->applet.ctx.table.entry = NULL; - si->applet.state = STAT_ST_INFO; + si->conn.data_st = STAT_ST_INFO; break; case STAT_ST_INFO: if (!si->applet.ctx.table.proxy || (si->applet.ctx.table.target && si->applet.ctx.table.proxy != si->applet.ctx.table.target)) { - si->applet.state = STAT_ST_END; + si->conn.data_st = STAT_ST_END; break; } @@ -3717,7 +3717,7 @@ static int stats_table_request(struct stream_interface *si, bool show) if (eb) { si->applet.ctx.table.entry = ebmb_entry(eb, struct stksess, key); si->applet.ctx.table.entry->ref_cnt++; - si->applet.state = STAT_ST_LIST; + si->conn.data_st = STAT_ST_LIST; break; } } @@ -3797,11 +3797,11 @@ static int stats_table_request(struct stream_interface *si, bool show) stksess_kill(&si->applet.ctx.table.proxy->table, si->applet.ctx.table.entry); si->applet.ctx.table.proxy = si->applet.ctx.table.proxy->next; - si->applet.state = STAT_ST_INFO; + si->conn.data_st = STAT_ST_INFO; break; case STAT_ST_END: - si->applet.state = STAT_ST_FIN; + si->conn.data_st = STAT_ST_FIN; break; } } diff --git a/src/peers.c b/src/peers.c index 6fcf2f301..721eecbaf 100644 --- a/src/peers.c +++ b/src/peers.c @@ -185,9 +185,9 @@ static void peer_session_release(struct stream_interface *si) { struct task *t = (struct task *)si->owner; struct session *s = (struct session *)t->context; - struct peer_session *ps = (struct peer_session *)si->applet.private; + struct peer_session *ps = (struct peer_session *)si->conn.data_ctx; - /* si->applet.private is not a peer session */ + /* si->conn.data_ctx is not a peer session */ if (si->applet.st0 < PEER_SESSION_SENDSUCCESS) return; @@ -227,7 +227,7 @@ static void peer_io_handler(struct stream_interface *si) switchstate: switch(si->applet.st0) { case PEER_SESSION_ACCEPT: - si->applet.private = NULL; + si->conn.data_ctx = NULL; si->applet.st0 = PEER_SESSION_GETVERSION; /* fall through */ case PEER_SESSION_GETVERSION: @@ -333,12 +333,12 @@ switchstate: goto switchstate; } - si->applet.private = curpeer; + si->conn.data_ctx = curpeer; si->applet.st0 = PEER_SESSION_GETTABLE; /* fall through */ } case PEER_SESSION_GETTABLE: { - struct peer *curpeer = (struct peer *)si->applet.private; + struct peer *curpeer = (struct peer *)si->conn.data_ctx; struct shared_table *st; struct peer_session *ps = NULL; unsigned long key_type; @@ -349,12 +349,12 @@ switchstate: if (reql <= 0) { /* closed or EOL not found */ if (reql == 0) goto out; - si->applet.private = NULL; + si->conn.data_ctx = NULL; si->applet.st0 = PEER_SESSION_END; goto switchstate; } - /* Re init si->applet.private to null, to handle correctly a release case */ - si->applet.private = NULL; + /* Re init si->conn.data_ctx to null, to handle correctly a release case */ + si->conn.data_ctx = NULL; if (trash[reql-1] != '\n') { /* Incomplete line, we quit */ @@ -380,7 +380,7 @@ switchstate: p = strchr(p+1, ' '); if (!p) { - si->applet.private = NULL; + si->conn.data_ctx = NULL; si->applet.st0 = PEER_SESSION_EXIT; si->applet.st1 = PEER_SESSION_ERRPROTO; goto switchstate; @@ -439,12 +439,12 @@ switchstate: goto switchstate; } - si->applet.private = ps; + si->conn.data_ctx = ps; si->applet.st0 = PEER_SESSION_SENDSUCCESS; /* fall through */ } case PEER_SESSION_SENDSUCCESS:{ - struct peer_session *ps = (struct peer_session *)si->applet.private; + struct peer_session *ps = (struct peer_session *)si->conn.data_ctx; repl = snprintf(trash, trashlen, "%d\n", PEER_SESSION_SUCCESSCODE); repl = bi_putblk(si->ib, trash, repl); @@ -494,7 +494,7 @@ switchstate: goto switchstate; } case PEER_SESSION_CONNECT: { - struct peer_session *ps = (struct peer_session *)si->applet.private; + struct peer_session *ps = (struct peer_session *)si->conn.data_ctx; /* Send headers */ repl = snprintf(trash, trashlen, @@ -524,7 +524,7 @@ switchstate: /* fall through */ } case PEER_SESSION_GETSTATUS: { - struct peer_session *ps = (struct peer_session *)si->applet.private; + struct peer_session *ps = (struct peer_session *)si->conn.data_ctx; if (si->ib->flags & BF_WRITE_PARTIAL) ps->statuscode = PEER_SESSION_CONNECTEDCODE; @@ -595,7 +595,7 @@ switchstate: /* fall through */ } case PEER_SESSION_WAITMSG: { - struct peer_session *ps = (struct peer_session *)si->applet.private; + struct peer_session *ps = (struct peer_session *)si->conn.data_ctx; char c; int totl = 0; @@ -1064,7 +1064,7 @@ static void peer_session_forceshutdown(struct session * session) /* call release to reinit resync states if needed */ peer_session_release(oldsi); oldsi->applet.st0 = PEER_SESSION_END; - oldsi->applet.private = NULL; + oldsi->conn.data_ctx = NULL; task_wakeup(session->task, TASK_WOKEN_MSG); } @@ -1079,7 +1079,7 @@ int peer_accept(struct session *s) /* we have a dedicated I/O handler for the stats */ stream_int_register_handler(&s->si[1], &peer_applet); copy_target(&s->target, &s->si[1].target); // for logging only - s->si[1].applet.private = s; + s->si[1].conn.data_ctx = s; s->si[1].applet.st0 = PEER_SESSION_ACCEPT; tv_zero(&s->logs.tv_request); @@ -1162,7 +1162,7 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio s->si[0].flags = SI_FL_NONE; if (s->fe->options2 & PR_O2_INDEPSTR) s->si[0].flags |= SI_FL_INDEP_STR; - s->si[0].applet.private = (void *)ps; + s->si[0].conn.data_ctx = (void *)ps; s->si[0].applet.st0 = PEER_SESSION_CONNECT; stream_int_register_handler(&s->si[0], &peer_applet); diff --git a/src/proto_http.c b/src/proto_http.c index 189fcf3ac..7cf413d77 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -2967,7 +2967,7 @@ int http_process_req_common(struct session *s, struct buffer *req, int an_bit, s s->task->nice = -32; /* small boost for HTTP statistics */ stream_int_register_handler(s->rep->prod, &http_stats_applet); copy_target(&s->target, &s->rep->prod->target); // for logging only - s->rep->prod->applet.private = s; + s->rep->prod->conn.data_ctx = s; s->rep->prod->applet.st0 = s->rep->prod->applet.st1 = 0; req->analysers = 0; if (s->fe == s->be) /* report it if the request was intercepted by the frontend */ diff --git a/src/stream_interface.c b/src/stream_interface.c index c70ee35e7..1005eafa1 100644 --- a/src/stream_interface.c +++ b/src/stream_interface.c @@ -341,7 +341,6 @@ struct task *stream_int_register_handler(struct stream_interface *si, struct si_ stream_interface_prepare(si, &stream_int_embedded); si->conn.ctrl = NULL; set_target_applet(&si->target, app); - si->applet.state = 0; si->release = app->release; si->flags |= SI_FL_WAIT_DATA; return si->owner;