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.
This commit is contained in:
Willy Tarreau 2021-10-06 09:05:08 +02:00
parent fd1c17ff46
commit dbf78025a0
2 changed files with 65 additions and 61 deletions

View File

@ -26,10 +26,11 @@
#include <string.h> #include <string.h>
#include <haproxy/api.h> #include <haproxy/api.h>
#include <haproxy/cli-t.h>
#include <haproxy/list.h>
#include <haproxy/listener-t.h> #include <haproxy/listener-t.h>
struct proxy;
struct task;
/* adjust the listener's state and its proxy's listener counters if needed */ /* adjust the listener's state and its proxy's listener counters if needed */
void listener_set_state(struct listener *l, enum li_state st); 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); void bind_recount_thread_bits(struct bind_conf *conf);
unsigned int bind_map_thread_id(const struct bind_conf *conf, unsigned int r); unsigned int bind_map_thread_id(const struct bind_conf *conf, unsigned int r);
struct bind_conf *bind_conf_alloc(struct proxy *fe, const char *file,
/* allocate an bind_conf struct for a bind line, and chain it to the frontend <fe>. int line, const char *arg, struct xprt_ops *xprt);
* If <arg> is not NULL, it is duplicated into ->arg to store useful config const char *listener_state_str(const struct listener *l);
* 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 task *accept_queue_process(struct task *t, void *context, unsigned int state); 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); struct task *manage_global_listener_queue(struct task *t, void *context, unsigned int state);

View File

@ -21,6 +21,7 @@
#include <haproxy/api.h> #include <haproxy/api.h>
#include <haproxy/activity.h> #include <haproxy/activity.h>
#include <haproxy/cfgparse.h> #include <haproxy/cfgparse.h>
#include <haproxy/cli-t.h>
#include <haproxy/connection.h> #include <haproxy/connection.h>
#include <haproxy/errors.h> #include <haproxy/errors.h>
#include <haproxy/fd.h> #include <haproxy/fd.h>
@ -1284,6 +1285,64 @@ const char *bind_find_best_kw(const char *word)
return best_ptr; return best_ptr;
} }
/* allocate an bind_conf struct for a bind line, and chain it to the frontend <fe>.
* If <arg> 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. */ /* All supported sample and ACL keywords must be declared here. */
/************************************************************************/ /************************************************************************/