Skip to content

Commit

Permalink
Cleanup SCTP AUTH related notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
tuexen committed Sep 8, 2023
1 parent 7efafe6 commit 9358fda
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
36 changes: 18 additions & 18 deletions usrsctplib/netinet/sctp_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -1334,8 +1334,8 @@ 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_SO_LOCKED);
sctp_ulp_notify(SCTP_NOTIFY_AUTH_FREE_KEY, stcb, 0, &keyid,
SCTP_SO_LOCKED);
}

/* mark the key as deactivated */
Expand Down Expand Up @@ -1679,15 +1679,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);
Expand Down Expand Up @@ -1730,7 +1725,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;
Expand All @@ -1739,8 +1734,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;
}
Expand All @@ -1750,7 +1744,7 @@ sctp_notify_authentication(struct sctp_tcb *stcb, uint32_t indication,
return;

m_notify = sctp_get_mbuf_for_msg(sizeof(struct sctp_authkey_event),
0, M_NOWAIT, 1, MT_HEADER);
0, M_NOWAIT, 1, MT_HEADER);
if (m_notify == NULL)
/* no space left */
return;
Expand All @@ -1762,7 +1756,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);

Expand All @@ -1782,7 +1781,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);
}

/*-
Expand Down
2 changes: 1 addition & 1 deletion usrsctplib/netinet/sctp_auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ extern struct mbuf *sctp_add_auth_chunk(struct mbuf *m, struct mbuf **m_end,
extern int 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);
extern void sctp_initialize_auth_params(struct sctp_inpcb *inp,
Expand Down
15 changes: 6 additions & 9 deletions usrsctplib/netinet/sctputil.c
Original file line number Diff line number Diff line change
Expand Up @@ -4396,19 +4396,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);
Expand Down

0 comments on commit 9358fda

Please sign in to comment.