CLEANUP: proxy: make the proxy lookup functions more user-friendly
First, findproxy() was renamed proxy_find_by_name() so that its explicit that a name is required for the lookup. Second, we give this function the ability to search for tables if needed. Third we now provide inline wrappers to pass the appropriate PR_CAP_* flags and to explicitly look up a frontend, backend or table.
This commit is contained in:
parent
e45288c0ca
commit
9e0bb1013e
|
@ -49,7 +49,7 @@ const char *proxy_cap_str(int cap);
|
|||
const char *proxy_mode_str(int mode);
|
||||
void proxy_store_name(struct proxy *px);
|
||||
struct proxy *findproxy_mode(const char *name, int mode, int cap);
|
||||
struct proxy *findproxy(const char *name, int cap);
|
||||
struct proxy *proxy_find_by_name(const char *name, int cap, int table);
|
||||
struct server *findserver(const struct proxy *px, const char *name);
|
||||
int proxy_cfg_ensure_no_http(struct proxy *curproxy);
|
||||
void init_new_proxy(struct proxy *p);
|
||||
|
@ -65,6 +65,30 @@ static inline const char *proxy_type_str(struct proxy *proxy)
|
|||
return proxy_cap_str(proxy->cap);
|
||||
}
|
||||
|
||||
/* Find the frontend having name <name>. The name may also start with a '#' to
|
||||
* reference a numeric id. NULL is returned if not found.
|
||||
*/
|
||||
static inline struct proxy *proxy_fe_by_name(const char *name)
|
||||
{
|
||||
return proxy_find_by_name(name, PR_CAP_FE, 0);
|
||||
}
|
||||
|
||||
/* Find the backend having name <name>. The name may also start with a '#' to
|
||||
* reference a numeric id. NULL is returned if not found.
|
||||
*/
|
||||
static inline struct proxy *proxy_be_by_name(const char *name)
|
||||
{
|
||||
return proxy_find_by_name(name, PR_CAP_BE, 0);
|
||||
}
|
||||
|
||||
/* Find the table having name <name>. The name may also start with a '#' to
|
||||
* reference a numeric id. NULL is returned if not found.
|
||||
*/
|
||||
static inline struct proxy *proxy_tbl_by_name(const char *name)
|
||||
{
|
||||
return proxy_find_by_name(name, 0, 1);
|
||||
}
|
||||
|
||||
/* this function initializes all timeouts for proxy p */
|
||||
static inline void proxy_reset_timeouts(struct proxy *proxy)
|
||||
{
|
||||
|
|
|
@ -7080,7 +7080,7 @@ int check_config_validity()
|
|||
curproxy->be_rsp_ana |= AN_RES_STORE_RULES;
|
||||
|
||||
if (mrule->table.name)
|
||||
target = findproxy(mrule->table.name, 0);
|
||||
target = proxy_tbl_by_name(mrule->table.name);
|
||||
else
|
||||
target = curproxy;
|
||||
|
||||
|
@ -7113,7 +7113,7 @@ int check_config_validity()
|
|||
curproxy->be_rsp_ana |= AN_RES_STORE_RULES;
|
||||
|
||||
if (mrule->table.name)
|
||||
target = findproxy(mrule->table.name, 0);
|
||||
target = proxy_tbl_by_name(mrule->table.name);
|
||||
else
|
||||
target = curproxy;
|
||||
|
||||
|
@ -7147,7 +7147,7 @@ int check_config_validity()
|
|||
continue;
|
||||
|
||||
if (trule->act_prm.trk_ctr.table.n)
|
||||
target = findproxy(trule->act_prm.trk_ctr.table.n, 0);
|
||||
target = proxy_tbl_by_name(trule->act_prm.trk_ctr.table.n);
|
||||
else
|
||||
target = curproxy;
|
||||
|
||||
|
@ -7186,7 +7186,7 @@ int check_config_validity()
|
|||
continue;
|
||||
|
||||
if (trule->act_prm.trk_ctr.table.n)
|
||||
target = findproxy(trule->act_prm.trk_ctr.table.n, 0);
|
||||
target = proxy_tbl_by_name(trule->act_prm.trk_ctr.table.n);
|
||||
else
|
||||
target = curproxy;
|
||||
|
||||
|
@ -7225,7 +7225,7 @@ int check_config_validity()
|
|||
continue;
|
||||
|
||||
if (hrqrule->act_prm.trk_ctr.table.n)
|
||||
target = findproxy(hrqrule->act_prm.trk_ctr.table.n, 0);
|
||||
target = proxy_tbl_by_name(hrqrule->act_prm.trk_ctr.table.n);
|
||||
else
|
||||
target = curproxy;
|
||||
|
||||
|
@ -7579,7 +7579,7 @@ int check_config_validity()
|
|||
}
|
||||
|
||||
if (pname) {
|
||||
px = findproxy(pname, PR_CAP_BE);
|
||||
px = proxy_be_by_name(pname);
|
||||
if (!px) {
|
||||
Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n",
|
||||
proxy_type_str(curproxy), curproxy->id,
|
||||
|
|
|
@ -924,7 +924,7 @@ static struct proxy *expect_frontend_admin(struct stream *s, struct stream_inter
|
|||
return NULL;
|
||||
}
|
||||
|
||||
px = findproxy(arg, PR_CAP_FE);
|
||||
px = proxy_fe_by_name(arg);
|
||||
if (!px) {
|
||||
appctx->ctx.cli.msg = "No such frontend.\n";
|
||||
appctx->st0 = STAT_CLI_PRINT;
|
||||
|
@ -4622,7 +4622,7 @@ static int stats_process_http_post(struct stream_interface *si)
|
|||
|
||||
/* Now we can check the key to see what to do */
|
||||
if (!px && (strcmp(key, "b") == 0)) {
|
||||
if ((px = findproxy(value, PR_CAP_BE)) == NULL) {
|
||||
if ((px = proxy_be_by_name(value)) == NULL) {
|
||||
/* the backend name is unknown or ambiguous (duplicate names) */
|
||||
appctx->ctx.stats.st_code = STAT_STATUS_ERRP;
|
||||
goto out;
|
||||
|
|
|
@ -632,7 +632,7 @@ __LJMP int hlua_lua2arg_check(lua_State *L, int first, struct arg *argp,
|
|||
WILL_LJMP(luaL_argerror(L, first + idx, "string expected"));
|
||||
memcpy(trash.str, argp[idx].data.str.str, argp[idx].data.str.len);
|
||||
trash.str[argp[idx].data.str.len] = 0;
|
||||
argp[idx].data.prx = findproxy(trash.str, PR_CAP_FE);
|
||||
argp[idx].data.prx = proxy_fe_by_name(trash.str);
|
||||
if (!argp[idx].data.prx)
|
||||
WILL_LJMP(luaL_argerror(L, first + idx, "frontend doesn't exist"));
|
||||
argp[idx].type = ARGT_FE;
|
||||
|
@ -643,7 +643,7 @@ __LJMP int hlua_lua2arg_check(lua_State *L, int first, struct arg *argp,
|
|||
WILL_LJMP(luaL_argerror(L, first + idx, "string expected"));
|
||||
memcpy(trash.str, argp[idx].data.str.str, argp[idx].data.str.len);
|
||||
trash.str[argp[idx].data.str.len] = 0;
|
||||
argp[idx].data.prx = findproxy(trash.str, PR_CAP_BE);
|
||||
argp[idx].data.prx = proxy_be_by_name(trash.str);
|
||||
if (!argp[idx].data.prx)
|
||||
WILL_LJMP(luaL_argerror(L, first + idx, "backend doesn't exist"));
|
||||
argp[idx].type = ARGT_BE;
|
||||
|
@ -669,7 +669,7 @@ __LJMP int hlua_lua2arg_check(lua_State *L, int first, struct arg *argp,
|
|||
if (sname) {
|
||||
*sname++ = '\0';
|
||||
pname = trash.str;
|
||||
px = findproxy(pname, PR_CAP_BE);
|
||||
px = proxy_be_by_name(pname);
|
||||
if (!px)
|
||||
WILL_LJMP(luaL_argerror(L, first + idx, "backend doesn't exist"));
|
||||
}
|
||||
|
|
15
src/proxy.c
15
src/proxy.c
|
@ -106,7 +106,7 @@ int get_backend_server(const char *bk_name, const char *sv_name,
|
|||
if (*sv_name == '#')
|
||||
sid = atoi(sv_name + 1);
|
||||
|
||||
p = findproxy(bk_name, PR_CAP_BE);
|
||||
p = proxy_be_by_name(bk_name);
|
||||
if (bk)
|
||||
*bk = p;
|
||||
if (!p)
|
||||
|
@ -390,10 +390,11 @@ struct proxy *findproxy_mode(const char *name, int mode, int cap) {
|
|||
|
||||
/* Returns a pointer to the proxy matching either name <name>, or id <name> if
|
||||
* <name> begins with a '#'. NULL is returned if no match is found, as well as
|
||||
* if multiple matches are found (eg: too large capabilities mask).
|
||||
* if multiple matches are found (eg: too large capabilities mask). If <table>
|
||||
* is non-zero, it only considers proxies having a table.
|
||||
*/
|
||||
struct proxy *findproxy(const char *name, int cap) {
|
||||
|
||||
struct proxy *proxy_find_by_name(const char *name, int cap, int table)
|
||||
{
|
||||
struct proxy *curproxy, *target = NULL;
|
||||
int pid = -1;
|
||||
|
||||
|
@ -411,6 +412,9 @@ struct proxy *findproxy(const char *name, int cap) {
|
|||
if ((curproxy->cap & cap) != cap)
|
||||
continue;
|
||||
|
||||
if (table && !curproxy->table.size)
|
||||
continue;
|
||||
|
||||
if (target)
|
||||
return NULL;
|
||||
|
||||
|
@ -429,6 +433,9 @@ struct proxy *findproxy(const char *name, int cap) {
|
|||
if ((curproxy->cap & cap) != cap)
|
||||
continue;
|
||||
|
||||
if (table && !curproxy->table.size)
|
||||
continue;
|
||||
|
||||
if (target)
|
||||
return NULL;
|
||||
|
||||
|
|
|
@ -1128,7 +1128,7 @@ int smp_resolve_args(struct proxy *p)
|
|||
*sname++ = '\0';
|
||||
pname = arg->data.str.str;
|
||||
|
||||
px = findproxy(pname, PR_CAP_BE);
|
||||
px = proxy_be_by_name(pname);
|
||||
if (!px) {
|
||||
Alert("parsing [%s:%d] : unable to find proxy '%s' referenced in arg %d of %s%s%s%s '%s' %s proxy '%s'.\n",
|
||||
cur->file, cur->line, pname,
|
||||
|
@ -1158,7 +1158,7 @@ int smp_resolve_args(struct proxy *p)
|
|||
case ARGT_FE:
|
||||
if (arg->data.str.len) {
|
||||
pname = arg->data.str.str;
|
||||
px = findproxy(pname, PR_CAP_FE);
|
||||
px = proxy_fe_by_name(pname);
|
||||
}
|
||||
|
||||
if (!px) {
|
||||
|
@ -1186,7 +1186,7 @@ int smp_resolve_args(struct proxy *p)
|
|||
case ARGT_BE:
|
||||
if (arg->data.str.len) {
|
||||
pname = arg->data.str.str;
|
||||
px = findproxy(pname, PR_CAP_BE);
|
||||
px = proxy_be_by_name(pname);
|
||||
}
|
||||
|
||||
if (!px) {
|
||||
|
|
|
@ -1053,7 +1053,7 @@ static int process_switching_rules(struct stream *s, struct channel *req, int an
|
|||
struct chunk *tmp = get_trash_chunk();
|
||||
if (!build_logline(s, tmp->str, tmp->size, &rule->be.expr))
|
||||
break;
|
||||
backend = findproxy(tmp->str, PR_CAP_BE);
|
||||
backend = proxy_be_by_name(tmp->str);
|
||||
if (!backend)
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue