[Openvpn-devel,v7] Factor out lookup_session_by_mda_key_id into its own method
Commit Message
From: Arne Schwabe <arne@rfc2549.org>
This makes the code a bit easier to read and also allows reusing
the function later.
Change-Id: Ib7d9aa61fd878d7e025e9d1050c563dd114eb438
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1854
---
This change was reviewed on Gerrit and approved by at least one
developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1854
This mail reflects revision 7 of this Change.
Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <frank@lichtenheld.com>
@@ -4014,6 +4014,24 @@
}
}
+static struct tls_session *
+lookup_session_by_mda_key_id(struct tls_multi *multi,
+ const unsigned int mda_key_id)
+{
+ if (multi->session[TM_INITIAL].key[KS_PRIMARY].mda_key_id == mda_key_id)
+ {
+ return &multi->session[TM_INITIAL];
+ }
+ else if (multi->session[TM_ACTIVE].key[KS_PRIMARY].mda_key_id == mda_key_id)
+ {
+ return &multi->session[TM_ACTIVE];
+ }
+ else
+ {
+ return NULL;
+ }
+}
+
static bool
management_client_pending_auth(void *arg, const unsigned long cid, const unsigned int mda_key_id,
const char *extra, unsigned int timeout)
@@ -4024,17 +4042,9 @@
if (mi)
{
struct tls_multi *multi = mi->context.c2.tls_multi;
- struct tls_session *session;
+ struct tls_session *session = lookup_session_by_mda_key_id(multi, mda_key_id);
- if (multi->session[TM_INITIAL].key[KS_PRIMARY].mda_key_id == mda_key_id)
- {
- session = &multi->session[TM_INITIAL];
- }
- else if (multi->session[TM_ACTIVE].key[KS_PRIMARY].mda_key_id == mda_key_id)
- {
- session = &multi->session[TM_ACTIVE];
- }
- else
+ if (!session)
{
return false;
}