MCPcopy Create free account
hub / github.com/F-Stack/f-stack / sctp_insert_sharedkey

Function sctp_insert_sharedkey

freebsd/netinet/sctp_auth.c:499–544  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

497}
498
499int
500sctp_insert_sharedkey(struct sctp_keyhead *shared_keys,
501 sctp_sharedkey_t *new_skey)
502{
503 sctp_sharedkey_t *skey;
504
505 if ((shared_keys == NULL) || (new_skey == NULL))
506 return (EINVAL);
507
508 /* insert into an empty list? */
509 if (LIST_EMPTY(shared_keys)) {
510 LIST_INSERT_HEAD(shared_keys, new_skey, next);
511 return (0);
512 }
513 /* insert into the existing list, ordered by key id */
514 LIST_FOREACH(skey, shared_keys, next) {
515 if (new_skey->keyid < skey->keyid) {
516 /* insert it before here */
517 LIST_INSERT_BEFORE(skey, new_skey, next);
518 return (0);
519 } else if (new_skey->keyid == skey->keyid) {
520 /* replace the existing key */
521 /* verify this key *can* be replaced */
522 if ((skey->deactivated) || (skey->refcount > 1)) {
523 SCTPDBG(SCTP_DEBUG_AUTH1,
524 "can't replace shared key id %u\n",
525 new_skey->keyid);
526 return (EBUSY);
527 }
528 SCTPDBG(SCTP_DEBUG_AUTH1,
529 "replacing shared key id %u\n",
530 new_skey->keyid);
531 LIST_INSERT_BEFORE(skey, new_skey, next);
532 LIST_REMOVE(skey, next);
533 sctp_free_sharedkey(skey);
534 return (0);
535 }
536 if (LIST_NEXT(skey, next) == NULL) {
537 /* belongs at the end of the list */
538 LIST_INSERT_AFTER(skey, new_skey, next);
539 return (0);
540 }
541 }
542 /* shouldn't reach here */
543 return (EINVAL);
544}
545
546void
547sctp_auth_key_acquire(struct sctp_tcb *stcb, uint16_t key_id)

Callers 3

sctp_setoptFunction · 0.85
sctp_inpcb_allocFunction · 0.85
sctp_copy_skeylistFunction · 0.85

Calls 1

sctp_free_sharedkeyFunction · 0.85

Tested by

no test coverage detected