diff --git a/libnvme/src/nvme/fabrics.c b/libnvme/src/nvme/fabrics.c index 129aa134d3..cd8062e176 100644 --- a/libnvme/src/nvme/fabrics.c +++ b/libnvme/src/nvme/fabrics.c @@ -1096,6 +1096,34 @@ __public int nvmf_connect_ctrl(nvme_ctrl_t c) return 0; } +static void nvmf_update_tls_concat(struct nvmf_disc_log_entry *e, + nvme_ctrl_t c, nvme_host_t h) +{ + if (e->trtype != NVMF_TRTYPE_TCP || + e->tsas.tcp.sectype == NVMF_TCP_SECTYPE_NONE) + return; + + if (e->treq & NVMF_TREQ_REQUIRED) { + nvme_msg(h->ctx, LOG_DEBUG, + "setting --tls due to treq %s and sectype %s\n", + nvmf_treq_str(e->treq), + nvmf_sectype_str(e->tsas.tcp.sectype)); + + c->cfg.tls = true; + return; + } + + if (e->treq & NVMF_TREQ_NOT_REQUIRED) { + nvme_msg(h->ctx, LOG_DEBUG, + "setting --concat due to treq %s and sectype %s\n", + nvmf_treq_str(e->treq), + nvmf_sectype_str(e->tsas.tcp.sectype)); + + c->cfg.concat = true; + return; + } +} + static int nvmf_connect_disc_entry(nvme_host_t h, struct nvmf_disc_log_entry *e, struct nvmf_context *fctx, @@ -1189,18 +1217,8 @@ static int nvmf_connect_disc_entry(nvme_host_t h, nvmf_check_option(h->ctx, disable_sqflow)) c->cfg.disable_sqflow = true; - if (e->trtype == NVMF_TRTYPE_TCP && - e->tsas.tcp.sectype != NVMF_TCP_SECTYPE_NONE) { - if (e->treq & NVMF_TREQ_REQUIRED) { - nvme_msg(h->ctx, LOG_DEBUG, "setting --tls due to treq %s and sectype %s\n", - nvmf_treq_str(e->treq), nvmf_sectype_str(e->tsas.tcp.sectype)); - c->cfg.tls = true; - } else if (e->treq & NVMF_TREQ_NOT_REQUIRED) { - nvme_msg(h->ctx, LOG_DEBUG, "setting --concat due to treq %s and sectype %s\n", - nvmf_treq_str(e->treq), nvmf_sectype_str(e->tsas.tcp.sectype)); - c->cfg.concat = true; - } - } + /* update tls or concat */ + nvmf_update_tls_concat(e, c, h); ret = nvmf_add_ctrl(h, c, cfg); if (!ret) { @@ -2552,11 +2570,8 @@ static int nbft_connect(struct nvme_global_ctx *ctx, if (ss && ss->unavailable && saved_log_level < 1) nvme_set_logging_level(ctx, -1, false, false); - if (e) { - if (e->trtype == NVMF_TRTYPE_TCP && - e->tsas.tcp.sectype != NVMF_TCP_SECTYPE_NONE) - cfg->tls = true; - } + /* Update tls or concat */ + nvmf_update_tls_concat(e, c, h); ret = nvmf_add_ctrl(h, c, cfg); diff --git a/libnvme/src/nvme/tree.c b/libnvme/src/nvme/tree.c index 010dd3ce93..1cae0bd8ac 100644 --- a/libnvme/src/nvme/tree.c +++ b/libnvme/src/nvme/tree.c @@ -1702,10 +1702,9 @@ static void nvme_read_sysfs_tls(struct nvme_global_ctx *ctx, nvme_ctrl_t c) key = nvme_get_ctrl_attr(c, "tls_key"); if (!key) { - /* tls_key is only present if --tls has been used. */ + /* tls_key is only present if --tls or --concat has been used */ return; } - c->cfg.tls = true; keyring = nvme_get_ctrl_attr(c, "tls_keyring"); nvme_ctrl_set_keyring(c, keyring);