From: Willy Tarreau Date: Wed, 6 Oct 2021 07:05:08 +0000 (+0200) Subject: REORG: listener: move bind_conf_alloc() and listener_state_str() to listener.c X-Git-Tag: v2.5-dev9~81 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dbf78025a0729f17447f8587b4dae391b741d03f;p=thirdparty%2Fhaproxy.git REORG: listener: move bind_conf_alloc() and listener_state_str() to listener.c These functions have no reason for being inlined, and they require some includes with long dependencies. Let's move them to listener.c and trim unused includes in listener.h. --- diff --git a/include/haproxy/listener.h b/include/haproxy/listener.h index 2212ca9271..5bd60c0247 100644 --- a/include/haproxy/listener.h +++ b/include/haproxy/listener.h @@ -26,10 +26,11 @@ #include #include -#include -#include #include +struct proxy; +struct task; + /* adjust the listener's state and its proxy's listener counters if needed */ void listener_set_state(struct listener *l, enum li_state st); @@ -171,65 +172,9 @@ const char *bind_find_best_kw(const char *word); void bind_recount_thread_bits(struct bind_conf *conf); unsigned int bind_map_thread_id(const struct bind_conf *conf, unsigned int r); - -/* allocate an bind_conf struct for a bind line, and chain it to the frontend . - * If is not NULL, it is duplicated into ->arg to store useful config - * information for error reporting. NULL is returned on error. - */ -static inline struct bind_conf *bind_conf_alloc(struct proxy *fe, const char *file, - int line, const char *arg, struct xprt_ops *xprt) -{ - struct bind_conf *bind_conf = calloc(1, sizeof(*bind_conf)); - - if (!bind_conf) - goto err; - - bind_conf->file = strdup(file); - if (!bind_conf->file) - goto err; - bind_conf->line = line; - if (arg) { - bind_conf->arg = strdup(arg); - if (!bind_conf->arg) - goto err; - } - - LIST_APPEND(&fe->conf.bind, &bind_conf->by_fe); - bind_conf->settings.ux.uid = -1; - bind_conf->settings.ux.gid = -1; - bind_conf->settings.ux.mode = 0; - bind_conf->xprt = xprt; - bind_conf->frontend = fe; - bind_conf->severity_output = CLI_SEVERITY_NONE; -#ifdef USE_OPENSSL - HA_RWLOCK_INIT(&bind_conf->sni_lock); - bind_conf->sni_ctx = EB_ROOT; - bind_conf->sni_w_ctx = EB_ROOT; -#endif - LIST_INIT(&bind_conf->listeners); - return bind_conf; - - err: - if (bind_conf) { - ha_free(&bind_conf->file); - ha_free(&bind_conf->arg); - } - ha_free(&bind_conf); - return NULL; -} - -static inline const char *listener_state_str(const struct listener *l) -{ - static const char *states[8] = { - "NEW", "INI", "ASS", "PAU", "LIS", "RDY", "FUL", "LIM", - }; - unsigned int st = l->state; - - if (st >= sizeof(states) / sizeof(*states)) - return "INVALID"; - return states[st]; -} - +struct bind_conf *bind_conf_alloc(struct proxy *fe, const char *file, + int line, const char *arg, struct xprt_ops *xprt); +const char *listener_state_str(const struct listener *l); struct task *accept_queue_process(struct task *t, void *context, unsigned int state); struct task *manage_global_listener_queue(struct task *t, void *context, unsigned int state); diff --git a/src/listener.c b/src/listener.c index 797e866b80..be467ea5d8 100644 --- a/src/listener.c +++ b/src/listener.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -1284,6 +1285,64 @@ const char *bind_find_best_kw(const char *word) return best_ptr; } +/* allocate an bind_conf struct for a bind line, and chain it to the frontend . + * If is not NULL, it is duplicated into ->arg to store useful config + * information for error reporting. NULL is returned on error. + */ +struct bind_conf *bind_conf_alloc(struct proxy *fe, const char *file, + int line, const char *arg, struct xprt_ops *xprt) +{ + struct bind_conf *bind_conf = calloc(1, sizeof(*bind_conf)); + + if (!bind_conf) + goto err; + + bind_conf->file = strdup(file); + if (!bind_conf->file) + goto err; + bind_conf->line = line; + if (arg) { + bind_conf->arg = strdup(arg); + if (!bind_conf->arg) + goto err; + } + + LIST_APPEND(&fe->conf.bind, &bind_conf->by_fe); + bind_conf->settings.ux.uid = -1; + bind_conf->settings.ux.gid = -1; + bind_conf->settings.ux.mode = 0; + bind_conf->xprt = xprt; + bind_conf->frontend = fe; + bind_conf->severity_output = CLI_SEVERITY_NONE; +#ifdef USE_OPENSSL + HA_RWLOCK_INIT(&bind_conf->sni_lock); + bind_conf->sni_ctx = EB_ROOT; + bind_conf->sni_w_ctx = EB_ROOT; +#endif + LIST_INIT(&bind_conf->listeners); + return bind_conf; + + err: + if (bind_conf) { + ha_free(&bind_conf->file); + ha_free(&bind_conf->arg); + } + ha_free(&bind_conf); + return NULL; +} + +const char *listener_state_str(const struct listener *l) +{ + static const char *states[8] = { + "NEW", "INI", "ASS", "PAU", "LIS", "RDY", "FUL", "LIM", + }; + unsigned int st = l->state; + + if (st >= sizeof(states) / sizeof(*states)) + return "INVALID"; + return states[st]; +} + /************************************************************************/ /* All supported sample and ACL keywords must be declared here. */ /************************************************************************/