From cd3770c5feb038f3904fdb4aa04e09da122f74e3 Mon Sep 17 00:00:00 2001 From: Michael Tuexen Date: Fri, 8 Sep 2023 13:13:43 +0200 Subject: [PATCH] sctp: cleanup SCTP AUTH related notification This makes consistent use of the parameters and ensures that all SCTP AUTH related notifications are using sctp_ulp_notify(). No functional change intended. MFC after: 3 days --- sys/netinet/sctp_auth.c | 32 ++++++++++++++++---------------- sys/netinet/sctp_auth.h | 2 +- sys/netinet/sctputil.c | 15 ++++++--------- 3 files changed, 23 insertions(+), 26 deletions(-) diff --git a/sys/netinet/sctp_auth.c b/sys/netinet/sctp_auth.c index 67f0d26fa0d5..3c1962233347 100644 --- a/sys/netinet/sctp_auth.c +++ b/sys/netinet/sctp_auth.c @@ -575,7 +575,7 @@ sctp_auth_key_release(struct sctp_tcb *stcb, uint16_t key_id, int so_locked) if ((skey->refcount <= 2) && (skey->deactivated)) { /* notify ULP that key is no longer used */ sctp_ulp_notify(SCTP_NOTIFY_AUTH_FREE_KEY, stcb, - key_id, 0, so_locked); + 0, &key_id, so_locked); SCTPDBG(SCTP_DEBUG_AUTH2, "%s: stcb %p key %u no longer used, %d\n", __func__, (void *)stcb, key_id, skey->refcount); @@ -1312,7 +1312,7 @@ sctp_deact_sharedkey(struct sctp_tcb *stcb, uint16_t keyid) /* are there other refcount holders on the key? */ if (skey->refcount == 1) { /* no other users, send a notification for this key */ - sctp_ulp_notify(SCTP_NOTIFY_AUTH_FREE_KEY, stcb, keyid, 0, + sctp_ulp_notify(SCTP_NOTIFY_AUTH_FREE_KEY, stcb, 0, &keyid, SCTP_SO_LOCKED); } @@ -1654,15 +1654,10 @@ sctp_handle_auth(struct sctp_tcb *stcb, struct sctp_auth_chunk *auth, return (-1); } /* generate a notification if this is a new key id */ - if (stcb->asoc.authinfo.recv_keyid != shared_key_id) - /* - * sctp_ulp_notify(SCTP_NOTIFY_AUTH_NEW_KEY, stcb, - * shared_key_id, (void - * *)stcb->asoc.authinfo.recv_keyid); - */ - sctp_notify_authentication(stcb, SCTP_AUTH_NEW_KEY, - shared_key_id, stcb->asoc.authinfo.recv_keyid, - SCTP_SO_NOT_LOCKED); + if (stcb->asoc.authinfo.recv_keyid != shared_key_id) { + sctp_ulp_notify(SCTP_NOTIFY_AUTH_NEW_KEY, stcb, 0, + &shared_key_id, SCTP_SO_NOT_LOCKED); + } /* compute a new recv assoc key and cache it */ if (stcb->asoc.authinfo.recv_key != NULL) sctp_free_key(stcb->asoc.authinfo.recv_key); @@ -1705,7 +1700,7 @@ sctp_handle_auth(struct sctp_tcb *stcb, struct sctp_auth_chunk *auth, */ void sctp_notify_authentication(struct sctp_tcb *stcb, uint32_t indication, - uint16_t keyid, uint16_t alt_keyid, int so_locked) + uint16_t keyid, int so_locked) { struct mbuf *m_notify; struct sctp_authkey_event *auth; @@ -1714,8 +1709,7 @@ sctp_notify_authentication(struct sctp_tcb *stcb, uint32_t indication, if ((stcb == NULL) || (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) || (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) || - (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET) - ) { + (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET)) { /* If the socket is gone we are out of here */ return; } @@ -1737,7 +1731,12 @@ sctp_notify_authentication(struct sctp_tcb *stcb, uint32_t indication, auth->auth_flags = 0; auth->auth_length = sizeof(*auth); auth->auth_keynumber = keyid; - auth->auth_altkeynumber = alt_keyid; + /* XXXMT: The following is BSD specific. */ + if (indication == SCTP_AUTH_NEW_KEY) { + auth->auth_altkeynumber = stcb->asoc.authinfo.recv_keyid; + } else { + auth->auth_altkeynumber = 0; + } auth->auth_indication = indication; auth->auth_assoc_id = sctp_get_associd(stcb); @@ -1757,7 +1756,8 @@ sctp_notify_authentication(struct sctp_tcb *stcb, uint32_t indication, /* not that we need this */ control->tail_mbuf = m_notify; sctp_add_to_readq(stcb->sctp_ep, stcb, control, - &stcb->sctp_socket->so_rcv, 1, SCTP_READ_LOCK_NOT_HELD, so_locked); + &stcb->sctp_socket->so_rcv, 1, + SCTP_READ_LOCK_NOT_HELD, so_locked); } /*- diff --git a/sys/netinet/sctp_auth.h b/sys/netinet/sctp_auth.h index 8bfdbaa6d4f6..279ecb6831cd 100644 --- a/sys/netinet/sctp_auth.h +++ b/sys/netinet/sctp_auth.h @@ -212,7 +212,7 @@ sctp_handle_auth(struct sctp_tcb *stcb, struct sctp_auth_chunk *ch, struct mbuf *m, uint32_t offset); extern void sctp_notify_authentication(struct sctp_tcb *stcb, - uint32_t indication, uint16_t keyid, uint16_t alt_keyid, int so_locked); + uint32_t indication, uint16_t keyid, int so_locked); extern int sctp_validate_init_auth_params(struct mbuf *m, int offset, int limit); diff --git a/sys/netinet/sctputil.c b/sys/netinet/sctputil.c index 381f67f40b99..ea960a3e6376 100644 --- a/sys/netinet/sctputil.c +++ b/sys/netinet/sctputil.c @@ -4197,19 +4197,16 @@ sctp_ulp_notify(uint32_t notification, struct sctp_tcb *stcb, sctp_notify_shutdown_event(stcb); break; case SCTP_NOTIFY_AUTH_NEW_KEY: - sctp_notify_authentication(stcb, SCTP_AUTH_NEW_KEY, error, - (uint16_t)(uintptr_t)data, - so_locked); + sctp_notify_authentication(stcb, SCTP_AUTH_NEW_KEY, + *(uint16_t *)data, so_locked); break; case SCTP_NOTIFY_AUTH_FREE_KEY: - sctp_notify_authentication(stcb, SCTP_AUTH_FREE_KEY, error, - (uint16_t)(uintptr_t)data, - so_locked); + sctp_notify_authentication(stcb, SCTP_AUTH_FREE_KEY, + *(uint16_t *)data, so_locked); break; case SCTP_NOTIFY_NO_PEER_AUTH: - sctp_notify_authentication(stcb, SCTP_AUTH_NO_AUTH, error, - (uint16_t)(uintptr_t)data, - so_locked); + sctp_notify_authentication(stcb, SCTP_AUTH_NO_AUTH, + 0, so_locked); break; case SCTP_NOTIFY_SENDER_DRY: sctp_notify_sender_dry_event(stcb, so_locked);