Skip to content

Commit b967c32

Browse files
committed
tlshd: Add tlshd_genl_put_handshake_parms() API
Manage dynamically-allocated resources in struct tlshd_handshake_parms by adding a function to release these resources before the handshake child process exits. This improves the ability of tlshd to dynamically allocate and manage memory containing variably-sized arguments such as hostnames, arrays, and socket addresses. The parms.peername and parms.peeraddr fields will be included in the set of dynamically-allocated resources, so add the new "release" API call /after/ the handshake completion notice. Signed-off-by: Chuck Lever <[email protected]>
1 parent d0ffb5f commit b967c32

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/tlshd/handshake.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,5 @@ void tlshd_service_socket(void)
183183
out:
184184
tlshd_genl_done(&parms);
185185
tlshd_log_completion(&parms);
186-
187-
if (parms.keyring)
188-
keyctl_unlink(parms.keyring, KEY_SPEC_SESSION_KEYRING);
189-
190-
free(parms.peerids);
186+
tlshd_genl_put_handshake_parms(&parms);
191187
}

src/tlshd/netlink.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,18 @@ int tlshd_genl_get_handshake_parms(struct tlshd_handshake_parms *parms)
405405
return ret;
406406
}
407407

408+
/**
409+
* tlshd_genl_put_handshake_parms - Release handshake resources
410+
* @parms: handshake parameters to be released
411+
*
412+
*/
413+
void tlshd_genl_put_handshake_parms(struct tlshd_handshake_parms *parms)
414+
{
415+
if (parms->keyring)
416+
keyctl_unlink(parms->keyring, KEY_SPEC_SESSION_KEYRING);
417+
free(parms->peerids);
418+
}
419+
408420
static int tlshd_genl_put_remote_peerids(struct nl_msg *msg,
409421
struct tlshd_handshake_parms *parms)
410422
{
@@ -423,7 +435,7 @@ static int tlshd_genl_put_remote_peerids(struct nl_msg *msg,
423435
}
424436

425437
/**
426-
* tlshd_genl_done - Indicate anon handshake has completed successfully
438+
* tlshd_genl_done - Indicate handshake has completed successfully
427439
* @parms: buffer filled in with parameters
428440
*
429441
*/

src/tlshd/tlshd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ void tlshd_log_nl_error(const char *msg, int err);
116116
/* netlink.c */
117117
extern void tlshd_genl_dispatch(void);
118118
extern int tlshd_genl_get_handshake_parms(struct tlshd_handshake_parms *parms);
119+
extern void tlshd_genl_put_handshake_parms(struct tlshd_handshake_parms *parms);
119120
extern void tlshd_genl_done(struct tlshd_handshake_parms *parms);
120121

121122
/* server.c */

0 commit comments

Comments
 (0)