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

Function key_dump

freebsd/netipsec/key.c:7561–7637  ·  view source on GitHub ↗

* SADB_DUMP processing * dump all entries including status of DEAD in SAD. * receive * * from the ikmpd, and dump all secasvar leaves * and send, * ..... * to the ikmpd. * * m will always be freed. */

Source from the content-addressed store, hash-verified

7559 * m will always be freed.
7560 */
7561static int
7562key_dump(struct socket *so, struct mbuf *m, const struct sadb_msghdr *mhp)
7563{
7564 SAHTREE_RLOCK_TRACKER;
7565 struct secashead *sah;
7566 struct secasvar *sav;
7567 struct mbuf *n;
7568 uint32_t cnt;
7569 uint8_t proto, satype;
7570
7571 IPSEC_ASSERT(so != NULL, ("null socket"));
7572 IPSEC_ASSERT(m != NULL, ("null mbuf"));
7573 IPSEC_ASSERT(mhp != NULL, ("null msghdr"));
7574 IPSEC_ASSERT(mhp->msg != NULL, ("null msg"));
7575
7576 /* map satype to proto */
7577 if ((proto = key_satype2proto(mhp->msg->sadb_msg_satype)) == 0) {
7578 ipseclog((LOG_DEBUG, "%s: invalid satype is passed.\n",
7579 __func__));
7580 return key_senderror(so, m, EINVAL);
7581 }
7582
7583 /* count sav entries to be sent to the userland. */
7584 cnt = 0;
7585 SAHTREE_RLOCK();
7586 TAILQ_FOREACH(sah, &V_sahtree, chain) {
7587 if (mhp->msg->sadb_msg_satype != SADB_SATYPE_UNSPEC &&
7588 proto != sah->saidx.proto)
7589 continue;
7590
7591 TAILQ_FOREACH(sav, &sah->savtree_larval, chain)
7592 cnt++;
7593 TAILQ_FOREACH(sav, &sah->savtree_alive, chain)
7594 cnt++;
7595 }
7596
7597 if (cnt == 0) {
7598 SAHTREE_RUNLOCK();
7599 return key_senderror(so, m, ENOENT);
7600 }
7601
7602 /* send this to the userland, one at a time. */
7603 TAILQ_FOREACH(sah, &V_sahtree, chain) {
7604 if (mhp->msg->sadb_msg_satype != SADB_SATYPE_UNSPEC &&
7605 proto != sah->saidx.proto)
7606 continue;
7607
7608 /* map proto to satype */
7609 if ((satype = key_proto2satype(sah->saidx.proto)) == 0) {
7610 SAHTREE_RUNLOCK();
7611 ipseclog((LOG_DEBUG, "%s: there was invalid proto in "
7612 "SAD.\n", __func__));
7613 return key_senderror(so, m, EINVAL);
7614 }
7615 TAILQ_FOREACH(sav, &sah->savtree_larval, chain) {
7616 n = key_setdumpsa(sav, SADB_DUMP, satype,
7617 --cnt, mhp->msg->sadb_msg_pid);
7618 if (n == NULL) {

Callers

nothing calls this directly

Calls 6

key_satype2protoFunction · 0.85
key_senderrorFunction · 0.85
key_proto2satypeFunction · 0.85
key_setdumpsaFunction · 0.85
key_sendup_mbufFunction · 0.85
m_freemFunction · 0.50

Tested by

no test coverage detected