From 5820a3669031b2f4de58577953ed3135aaaa1f62 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 22 Dec 2016 15:59:02 +0100 Subject: [PATCH] MEDIUM: spoe: don't create a dummy listener for outgoing connections The code currently creates a listener only to ensure that sess->li is properly populated, and to retrieve the frontend (which is also available directly from the session). It turns out that the current infrastructure (for a large part) already supports not having any listener on a session (since Lua does the same), except for the following places which were not yet converted : - session_count_new() : used by session_accept_fd, ie never for spoe - session_accept_fd() : never used here, an applet initiates the session - session_prepare_log_prefix() : embryonic sessions only, thus unused - session_kill_embryonic() : same - conn_complete_session() : same - build_log_line() for fields %cp, %fp and %ft : unused here but may change - http_wait_for_request() and subsequent functions : unused here Thus for now it's as safe to run SPOE without listener as it is for Lua, and this was an obstacle against some cleanups of the listener code. The places above should be plugged so that it becomes save over the long term as well. An alternative in the future might be to create a dummy listener that outgoing connections could use just to avoid keeping a null here. --- src/flt_spoe.c | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/src/flt_spoe.c b/src/flt_spoe.c index aa6414abfd..519d6bb5f5 100644 --- a/src/flt_spoe.c +++ b/src/flt_spoe.c @@ -1557,8 +1557,6 @@ create_spoe_appctx(struct spoe_config *conf) struct session *sess; struct task *task; struct stream *strm; - struct listener *l = LIST_NEXT(&conf->agent_fe.conf.listeners, - struct listener *, by_fe); if ((appctx = appctx_new(&spoe_applet)) == NULL) goto out_error; @@ -1575,7 +1573,7 @@ create_spoe_appctx(struct spoe_config *conf) APPCTX_SPOE(appctx).max_frame_size = global.tune.bufsize; task_wakeup(APPCTX_SPOE(appctx).task, TASK_WOKEN_INIT); - sess = session_new(&conf->agent_fe, l, &appctx->obj_type); + sess = session_new(&conf->agent_fe, NULL, &appctx->obj_type); if (!sess) goto out_free_spoe; @@ -1585,8 +1583,6 @@ create_spoe_appctx(struct spoe_config *conf) if ((strm = stream_new(sess, task, &appctx->obj_type)) == NULL) goto out_free_task; - strm->target = sess->listener->default_target; - strm->req.analysers |= sess->listener->analysers; stream_set_backend(strm, conf->agent->b.be); /* applet is waiting for data */ @@ -2306,7 +2302,6 @@ static int spoe_init(struct proxy *px, struct flt_conf *fconf) { struct spoe_config *conf = fconf->conf; - struct listener *l; memset(&conf->agent_fe, 0, sizeof(conf->agent_fe)); init_new_proxy(&conf->agent_fe); @@ -2324,26 +2319,12 @@ spoe_init(struct proxy *px, struct flt_conf *fconf) conf->agent_fe.default_target = &spoe_applet.obj_type; conf->agent_fe.fe_req_ana = AN_REQ_SWITCHING_RULES; - if ((l = calloc(1, sizeof(*l))) == NULL) { - Alert("spoe_init : out of memory.\n"); - goto out_error; - } - l->obj_type = OBJ_TYPE_LISTENER; - l->obj_type = OBJ_TYPE_LISTENER; - l->frontend = &conf->agent_fe; - l->state = LI_READY; - l->analysers = conf->agent_fe.fe_req_ana; - LIST_ADDQ(&conf->agent_fe.conf.listeners, &l->by_fe); - if (!sighandler_registered) { signal_register_fct(0, sig_stop_spoe, 0); sighandler_registered = 1; } return 0; - - out_error: - return -1; } /* Free ressources allocated by the SPOE filter. */ -- 2.39.5