QUIC LCIDM: Add debug calls
authorHugo Landau <hlandau@openssl.org>
Wed, 8 Nov 2023 16:57:55 +0000 (16:57 +0000)
committerHugo Landau <hlandau@openssl.org>
Wed, 6 Dec 2023 10:40:11 +0000 (10:40 +0000)
Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/22673)

include/internal/quic_lcidm.h
ssl/quic/quic_lcidm.c

index e01ac80f9e7d735104d4953fe2e76f1da9439b26..6c040f80be1ca1827ae41247e88fbafac08a7508 100644 (file)
@@ -235,6 +235,23 @@ int ossl_quic_lcidm_lookup(QUIC_LCIDM *lcidm,
                            uint64_t *seq_num,
                            void **opaque);
 
+/*
+ * Debug call to manually remove a specific LCID. Should not be needed in normal
+ * usage. Returns 1 if the LCID was successfully found and removed and 0
+ * otherwise.
+ */
+int ossl_quic_lcidm_debug_remove(QUIC_LCIDM *lcidm,
+                                 const QUIC_CONN_ID *lcid);
+
+/*
+ * Debug call to manually add a numbered LCID with a specific CID value and
+ * sequence number. Should not be needed in normal usage. Returns 1 on success
+ * and 0 on failure.
+ */
+int ossl_quic_lcidm_debug_add(QUIC_LCIDM *lcidm, void *opaque,
+                              const QUIC_CONN_ID *lcid,
+                              uint64_t seq_num);
+
 # endif
 
 #endif
index af61292e571075a2efb637cafb9d4b93a940e4b4..a79eab878153c48a0754064a2fb3ea5cb7c84fe7 100644 (file)
@@ -473,3 +473,41 @@ int ossl_quic_lcidm_lookup(QUIC_LCIDM *lcidm,
 
     return 1;
 }
+
+int ossl_quic_lcidm_debug_remove(QUIC_LCIDM *lcidm,
+                                 const QUIC_CONN_ID *lcid)
+{
+    QUIC_LCID key, *lcid_obj;
+
+    key.cid = *lcid;
+    if ((lcid_obj = lh_QUIC_LCID_retrieve(lcidm->lcids, &key)) == NULL)
+        return 0;
+
+    lcidm_delete_conn_lcid(lcidm, lcid_obj);
+    return 1;
+}
+
+int ossl_quic_lcidm_debug_add(QUIC_LCIDM *lcidm, void *opaque,
+                              const QUIC_CONN_ID *lcid,
+                              uint64_t seq_num)
+{
+    QUIC_LCIDM_CONN *conn;
+    QUIC_LCID key, *lcid_obj;
+
+    if (lcid == NULL || lcid->id_len > QUIC_MAX_CONN_ID_LEN)
+        return 0;
+
+    if ((conn = lcidm_upsert_conn(lcidm, opaque)) == NULL)
+        return 0;
+
+    key.cid = *lcid;
+    if (lh_QUIC_LCID_retrieve(lcidm->lcids, &key) != NULL)
+        return 0;
+
+    if ((lcid_obj = lcidm_conn_new_lcid(lcidm, conn, lcid)) == NULL)
+        return 0;
+
+    lcid_obj->seq_num   = seq_num;
+    lcid_obj->type      = LCID_TYPE_NCID;
+    return 1;
+}