CLEANUP: ssl/cli: stop using appctx->st2 for "commit ssl cert"

A new entry "state" was added into the commit_cert_ctx struct instead.
This commit is contained in:
Willy Tarreau 2022-05-05 08:15:27 +02:00
parent a645b6a21f
commit cb1b4ed7b6

View File

@ -89,6 +89,12 @@ struct commit_cert_ctx {
struct ckch_store *old_ckchs; struct ckch_store *old_ckchs;
struct ckch_store *new_ckchs; struct ckch_store *new_ckchs;
struct ckch_inst *next_ckchi; struct ckch_inst *next_ckchi;
enum {
CERT_ST_INIT = 0,
CERT_ST_GEN,
CERT_ST_INSERT,
CERT_ST_FIN,
} state;
}; };
@ -1834,7 +1840,7 @@ static void cli_release_commit_cert(struct appctx *appctx)
HA_SPIN_UNLOCK(CKCH_LOCK, &ckch_lock); HA_SPIN_UNLOCK(CKCH_LOCK, &ckch_lock);
if (appctx->st2 != SETCERT_ST_FIN) { if (ctx->state != CERT_ST_FIN) {
/* free every new sni_ctx and the new store, which are not in the trees so no spinlock there */ /* free every new sni_ctx and the new store, which are not in the trees so no spinlock there */
new_ckchs = ctx->new_ckchs; new_ckchs = ctx->new_ckchs;
@ -2017,17 +2023,17 @@ static int cli_io_handler_commit_cert(struct appctx *appctx)
goto error; goto error;
while (1) { while (1) {
switch (appctx->st2) { switch (ctx->state) {
case SETCERT_ST_INIT: case CERT_ST_INIT:
/* This state just print the update message */ /* This state just print the update message */
chunk_printf(trash, "Committing %s", ckchs_transaction.path); chunk_printf(trash, "Committing %s", ckchs_transaction.path);
if (ci_putchk(cs_ic(cs), trash) == -1) { if (ci_putchk(cs_ic(cs), trash) == -1) {
cs_rx_room_blk(cs); cs_rx_room_blk(cs);
goto yield; goto yield;
} }
appctx->st2 = SETCERT_ST_GEN; ctx->state = CERT_ST_GEN;
/* fallthrough */ /* fallthrough */
case SETCERT_ST_GEN: case CERT_ST_GEN:
/* /*
* This state generates the ckch instances with their * This state generates the ckch instances with their
* sni_ctxs and SSL_CTX. * sni_ctxs and SSL_CTX.
@ -2068,9 +2074,9 @@ static int cli_io_handler_commit_cert(struct appctx *appctx)
LIST_APPEND(&new_ckchs->ckch_inst, &new_inst->by_ckchs); LIST_APPEND(&new_ckchs->ckch_inst, &new_inst->by_ckchs);
y++; y++;
} }
appctx->st2 = SETCERT_ST_INSERT; ctx->state = CERT_ST_INSERT;
/* fallthrough */ /* fallthrough */
case SETCERT_ST_INSERT: case CERT_ST_INSERT:
/* The generation is finished, we can insert everything */ /* The generation is finished, we can insert everything */
old_ckchs = ctx->old_ckchs; old_ckchs = ctx->old_ckchs;
@ -2082,9 +2088,9 @@ static int cli_io_handler_commit_cert(struct appctx *appctx)
/* insert everything and remove the previous objects */ /* insert everything and remove the previous objects */
ckch_store_replace(old_ckchs, new_ckchs); ckch_store_replace(old_ckchs, new_ckchs);
appctx->st2 = SETCERT_ST_FIN; ctx->state = CERT_ST_FIN;
/* fallthrough */ /* fallthrough */
case SETCERT_ST_FIN: case CERT_ST_FIN:
/* we achieved the transaction, we can set everything to NULL */ /* we achieved the transaction, we can set everything to NULL */
ha_free(&ckchs_transaction.path); ha_free(&ckchs_transaction.path);
ckchs_transaction.new_ckchs = NULL; ckchs_transaction.new_ckchs = NULL;
@ -2162,7 +2168,7 @@ static int cli_parse_commit_cert(char **args, char *payload, struct appctx *appc
} }
/* init the appctx structure */ /* init the appctx structure */
appctx->st2 = SETCERT_ST_INIT; ctx->state = CERT_ST_INIT;
ctx->next_ckchi = NULL; ctx->next_ckchi = NULL;
ctx->new_ckchs = ckchs_transaction.new_ckchs; ctx->new_ckchs = ckchs_transaction.new_ckchs;
ctx->old_ckchs = ckchs_transaction.old_ckchs; ctx->old_ckchs = ckchs_transaction.old_ckchs;