if (promex_filter_metric(appctx, prefix, name))
continue;
- if (!px)
- px = proxies_list;
-
+ px = main_proxies_cond_first(px);
while (px) {
struct promex_label labels[PROMEX_MAX_LABELS-1] = {};
enum promex_mt_type type;
&val, labels, &out, max))
goto full;
next_px:
- px = px->next;
+ px = main_proxies_next(px);
}
ctx->flags |= PROMEX_FL_METRIC_HDR;
}
if (promex_filter_metric(appctx, prefix, name))
continue;
- if (!px)
- px = proxies_list;
-
+ px = main_proxies_cond_first(px);
while (px) {
struct promex_label labels[PROMEX_MAX_LABELS-1] = {};
struct promex_metric metric;
goto full;
next_px2:
- px = px->next;
+ px = main_proxies_next(px);
}
ctx->flags |= PROMEX_FL_METRIC_HDR;
}
if (promex_filter_metric(appctx, prefix, name))
continue;
- if (!px)
- px = proxies_list;
-
+ px = main_proxies_cond_first(px);
while (px) {
struct promex_label labels[PROMEX_MAX_LABELS-1] = {};
int lb_idx = 0;
li = NULL;
next_px:
- px = px->next;
+ px = main_proxies_next(px);
}
ctx->flags |= PROMEX_FL_METRIC_HDR;
}
if (promex_filter_metric(appctx, prefix, name))
continue;
- if (!px)
- px = proxies_list;
-
+ px = main_proxies_cond_first(px);
while (px) {
struct promex_label labels[PROMEX_MAX_LABELS-1] = {};
struct promex_metric metric;
li = NULL;
next_px2:
- px = px->next;
+ px = main_proxies_next(px);
}
ctx->flags |= PROMEX_FL_METRIC_HDR;
}
&val, labels, &out, max))
goto full;
next_px:
- px = watcher_next(&ctx->px_watch, px->next);
+ px = watcher_next(&ctx->px_watch, main_proxies_next(px));
}
watcher_detach(&ctx->px_watch);
ctx->flags |= PROMEX_FL_METRIC_HDR;
/* Prepare a new iteration for the next stat column.
* Update ctx.p[0] via watcher.
*/
- watcher_attach(&ctx->px_watch, proxies_list);
- px = proxies_list;
+ px = main_proxies_first();
+ watcher_attach(&ctx->px_watch, px);
}
/* Skip extra counters */
goto full;
next_px2:
- px = watcher_next(&ctx->px_watch, px->next);
+ px = watcher_next(&ctx->px_watch, main_proxies_next(px));
}
watcher_detach(&ctx->px_watch);
ctx->flags |= PROMEX_FL_METRIC_HDR;
/* Prepare a new iteration for the next stat column.
* Update ctx.p[0] via watcher.
*/
- watcher_attach(&ctx->px_watch, proxies_list);
- px = proxies_list;
+ px = main_proxies_first();
+ watcher_attach(&ctx->px_watch, px);
}
ctx->field_num += mod->stats_count;
next_px:
watcher_detach(&ctx->srv_watch);
- px = watcher_next(&ctx->px_watch, px->next);
+ px = watcher_next(&ctx->px_watch, main_proxies_next(px));
if (px) {
/* Update ctx.p[1] via watcher. */
watcher_attach(&ctx->srv_watch, px->srv);
/* Prepare a new iteration for the next stat column.
* Update ctx.p[0]/p[1] via px_watch/srv_watch.
*/
- watcher_attach(&ctx->px_watch, proxies_list);
- px = proxies_list;
+ px = main_proxies_first();
+ watcher_attach(&ctx->px_watch, px);
if (likely(px)) {
watcher_attach(&ctx->srv_watch, px->srv);
sv = ctx->p[1];
next_px2:
watcher_detach(&ctx->srv_watch);
- px = watcher_next(&ctx->px_watch, px->next);
+ px = watcher_next(&ctx->px_watch, main_proxies_next(px));
if (px) {
/* Update ctx.p[1] via watcher. */
watcher_attach(&ctx->srv_watch, px->srv);
/* Prepare a new iteration for the next stat column.
* Update ctx.p[0]/p[1] via px_watch/srv_watch.
*/
- watcher_attach(&ctx->px_watch, proxies_list);
- px = proxies_list;
+ px = main_proxies_first();
+ watcher_attach(&ctx->px_watch, px);
if (likely(px)) {
watcher_attach(&ctx->srv_watch, px->srv);
sv = ctx->p[1];
static int promex_dump_metrics(struct appctx *appctx, struct htx *htx)
{
struct promex_ctx *ctx = appctx->svcctx;
+ struct proxy *px;
int ret;
switch (appctx->st1) {
if (ctx->flags & PROMEX_FL_SCOPE_BACK) {
/* Update ctx.p[0] via watcher. */
- watcher_attach(&ctx->px_watch, proxies_list);
+ px = main_proxies_first();
+ watcher_attach(&ctx->px_watch, px);
}
__fallthrough;
if (ctx->flags & PROMEX_FL_SCOPE_SERVER) {
/* Update ctx.p[0] via watcher. */
- watcher_attach(&ctx->px_watch, proxies_list);
- if (likely(proxies_list)) {
+ px = main_proxies_first();
+ watcher_attach(&ctx->px_watch, px);
+ if (likely(px)) {
/* Update ctx.p[1] via watcher. */
- watcher_attach(&ctx->srv_watch, proxies_list->srv);
+ watcher_attach(&ctx->srv_watch, px->srv);
}
}
__fallthrough;
proxies_list = px;
}
+/* Returns first entry in main proxies list or NULL if empty. */
+static inline struct proxy *main_proxies_first(void)
+{
+ return proxies_list;
+}
+
+/* Returns first entry in main proxies list unless <px> is already set. This is
+ * useful when iterating over proxies with possible task yielding interruption.
+ */
+static inline struct proxy *main_proxies_cond_first(struct proxy *px)
+{
+ if (!px)
+ px = proxies_list;
+ return px;
+}
+
+/* Return next entry after <px> in main proxies list or NULL if reaching end of list. */
+static inline struct proxy *main_proxies_next(const struct proxy *px)
+{
+ return px->next;
+}
+
#endif /* _HAPROXY_PROXY_H */
/*
} else {
ctx->specific_name = NULL;
ctx->specific_ctx = NULL;
- ctx->pp = proxies_list;
+ ctx->pp = main_proxies_first();
ctx->b = NULL;
ctx->state = SHOW_ECH_ALL;
}
bind_conf = ctx->b;
p = ctx->pp;
- for (; p; p = p->next) {
+ for (; p; p = main_proxies_next(p)) {
if (!(p->cap & PR_CAP_FE) || LIST_ISEMPTY(&p->conf.bind))
continue;
lua_pushstring(L, ctx->next->id);
hlua_fcn_new_proxy(L, ctx->next);
- ctx->next = watcher_next(&ctx->px_watch, ctx->next->next);
+ ctx->next = watcher_next(&ctx->px_watch, main_proxies_next(ctx->next));
for (;
ctx->next && !hlua_listable_proxies_match(ctx->next, ctx->capabilities);
- ctx->next = watcher_next(&ctx->px_watch, ctx->next->next))
+ ctx->next = watcher_next(&ctx->px_watch, main_proxies_next(ctx->next)))
;
return 2;
ctx->next = NULL;
watcher_init(&ctx->px_watch, &ctx->next, offsetof(struct proxy, watcher_list));
- for (watcher_attach(&ctx->px_watch, proxies_list);
+ for (watcher_attach(&ctx->px_watch, main_proxies_first());
ctx->next && !hlua_listable_proxies_match(ctx->next, ctx->capabilities);
- ctx->next = watcher_next(&ctx->px_watch, ctx->next->next))
+ ctx->next = watcher_next(&ctx->px_watch, main_proxies_next(ctx->next)))
;
lua_pushcclosure(L, hlua_listable_proxies_pairs_iterator, 1);
ctx->state = SHOW_SRV_LIST;
if (!ctx->px)
- watcher_attach(&ctx->px_watch, proxies_list);
+ watcher_attach(&ctx->px_watch, main_proxies_first());
}
- for (; ctx->px; watcher_next(&ctx->px_watch, ctx->px->next)) {
+ for (; ctx->px; watcher_next(&ctx->px_watch, main_proxies_next(ctx->px))) {
curproxy = ctx->px;
/* servers are only in backends */
if ((curproxy->cap & PR_CAP_BE) && !(curproxy->cap & PR_CAP_INT)) {
watcher_init(&ctx->px_watch, &ctx->px, offsetof(struct proxy, watcher_list));
/* This will automatically update ctx->px pointer. */
- watcher_attach(&ctx->px_watch, proxies_list);
+ watcher_attach(&ctx->px_watch, main_proxies_first());
}
- for (; ctx->px; watcher_next(&ctx->px_watch, ctx->px->next)) {
- curproxy = ctx->px;
+ for (; ctx->px; watcher_next(&ctx->px_watch, main_proxies_next(ctx->px))) {
+ curproxy = appctx->svcctx;
/* looking for non-internal backends only */
if ((curproxy->cap & (PR_CAP_BE|PR_CAP_INT)) != PR_CAP_BE)
while (!MT_LIST_ISEMPTY(&px->watcher_list)) {
px_watch = MT_LIST_NEXT(&px->watcher_list, struct watcher *, el);
- watcher_next(px_watch, px->next);
+ watcher_next(px_watch, main_proxies_next(px));
}
ceb32_item_delete(&used_proxy_id, conf.uuid_node, uuid, px);
if (applet_putchk(appctx, &trash) == -1)
goto cant_send;
- watcher_attach(&ctx->px_watch, proxies_list);
+ watcher_attach(&ctx->px_watch, main_proxies_first());
ctx->bol = 0;
ctx->ptr = -1;
}
ctx->ptr = -1;
ctx->flag ^= 1;
if (!(ctx->flag & 1))
- watcher_next(&ctx->px_watch, ctx->px->next);
+ watcher_next(&ctx->px_watch, main_proxies_next(ctx->px));
}
/* dump complete */
return 1;
/* ctx->bind is NULL only once we finished dumping a frontend or when starting
- * so let's dump the header in these cases*/
+ * so let's dump the header in these cases.
+ */
if (ctx->bind == NULL && (ctx->options & SHOW_SNI_OPT_1FRONTEND ||
- (!(ctx->options & SHOW_SNI_OPT_1FRONTEND) && ctx->px == proxies_list)))
+ (!(ctx->options & SHOW_SNI_OPT_1FRONTEND) && ctx->px == main_proxies_first())))
chunk_appendf(trash, "# Frontend/Bind\tSNI\tNegative Filter\tType\tFilename\tNotAfter\tNotBefore\n");
if (applet_putchk(appctx, trash) == -1)
goto yield;
- for (px = ctx->px; px; px = px->next) {
-
+ for (px = ctx->px; px; px = main_proxies_next(px)) {
/* only check the frontends which are not internal proxies */
if (!(px->cap & PR_CAP_FE) || (px->cap & PR_CAP_INT))
continue;
struct show_sni_ctx *ctx = applet_reserve_svcctx(appctx, sizeof(*ctx));
int cur_arg = 3;
- ctx->px = proxies_list;
+ ctx->px = main_proxies_first();
/* look for the right <frontend> to display */
/* dump proxies */
/* obj1 is updated and returned through watcher_next() */
for (px = ctx->obj1; px;
- px = watcher_next(&ctx->px_watch, px->next)) {
+ px = watcher_next(&ctx->px_watch, main_proxies_next(px))) {
if (stats_is_full(appctx, buf, htx))
goto full;
ctx->state = STAT_STATE_LIST;
/* Update ctx->obj1 via watcher to point on the first proxy. */
if (domain == STATS_DOMAIN_PROXY)
- watcher_attach(&ctx->px_watch, proxies_list);
+ watcher_attach(&ctx->px_watch, main_proxies_first());
__fallthrough;