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

Function key_spddump

freebsd/netipsec/key.c:2562–2622  ·  view source on GitHub ↗

* SADB_SPDDUMP processing * receive * * from the user, and dump all SP leaves and send, * ..... * to the ikmpd. * * NOTE: * sadb_msg_satype is considered as mask of policy scopes. * m will always be freed. */

Source from the content-addressed store, hash-verified

2560 * m will always be freed.
2561 */
2562static int
2563key_spddump(struct socket *so, struct mbuf *m, const struct sadb_msghdr *mhp)
2564{
2565 SPTREE_RLOCK_TRACKER;
2566 struct secpolicy *sp;
2567 struct mbuf *n;
2568 int cnt;
2569 u_int dir, scope;
2570
2571 IPSEC_ASSERT(so != NULL, ("null socket"));
2572 IPSEC_ASSERT(m != NULL, ("null mbuf"));
2573 IPSEC_ASSERT(mhp != NULL, ("null msghdr"));
2574 IPSEC_ASSERT(mhp->msg != NULL, ("null msg"));
2575
2576 /* search SPD entry and get buffer size. */
2577 cnt = 0;
2578 scope = key_satype2scopemask(mhp->msg->sadb_msg_satype);
2579 SPTREE_RLOCK();
2580 for (dir = 0; dir < IPSEC_DIR_MAX; dir++) {
2581 if (scope & IPSEC_POLICYSCOPE_GLOBAL) {
2582 TAILQ_FOREACH(sp, &V_sptree[dir], chain)
2583 cnt++;
2584 }
2585 if (scope & IPSEC_POLICYSCOPE_IFNET) {
2586 TAILQ_FOREACH(sp, &V_sptree_ifnet[dir], chain)
2587 cnt++;
2588 }
2589 }
2590
2591 if (cnt == 0) {
2592 SPTREE_RUNLOCK();
2593 return key_senderror(so, m, ENOENT);
2594 }
2595
2596 for (dir = 0; dir < IPSEC_DIR_MAX; dir++) {
2597 if (scope & IPSEC_POLICYSCOPE_GLOBAL) {
2598 TAILQ_FOREACH(sp, &V_sptree[dir], chain) {
2599 --cnt;
2600 n = key_setdumpsp(sp, SADB_X_SPDDUMP, cnt,
2601 mhp->msg->sadb_msg_pid);
2602
2603 if (n != NULL)
2604 key_sendup_mbuf(so, n, KEY_SENDUP_ONE);
2605 }
2606 }
2607 if (scope & IPSEC_POLICYSCOPE_IFNET) {
2608 TAILQ_FOREACH(sp, &V_sptree_ifnet[dir], chain) {
2609 --cnt;
2610 n = key_setdumpsp(sp, SADB_X_SPDDUMP, cnt,
2611 mhp->msg->sadb_msg_pid);
2612
2613 if (n != NULL)
2614 key_sendup_mbuf(so, n, KEY_SENDUP_ONE);
2615 }
2616 }
2617 }
2618
2619 SPTREE_RUNLOCK();

Callers

nothing calls this directly

Calls 5

key_satype2scopemaskFunction · 0.85
key_senderrorFunction · 0.85
key_setdumpspFunction · 0.85
key_sendup_mbufFunction · 0.85
m_freemFunction · 0.50

Tested by

no test coverage detected