FreeBSD/sys/netipsec/key.c
/*
 * SADB_DUMP processing
 * dump all entries including status of DEAD in SAD.
 * receive
 *   <base>
 * from the ikmpd, and dump all secasvar leaves
 * and send,
 *   <base> .....
 * to the ikmpd.
 *
 * m will always be freed.
 */
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.
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 .
static int
key_dump(struct socket *so, struct mbuf *m, const struct sadb_msghdr *mhp)
{
	struct secashead *sah;
	struct secasvar *sav;
	u_int16_t proto;
	u_int stateidx;
	u_int8_t satype;
	u_int8_t state;
	int cnt;
	struct sadb_msg *newmsg;
	struct mbuf *n;
	IPSEC_ASSERT(so != NULL, ("null socket"));
	IPSEC_ASSERT(m != NULL, ("null mbuf"));
	IPSEC_ASSERT(mhp != NULL, ("null msghdr"));
	IPSEC_ASSERT(mhp->msg != NULL, ("null msg"));
	if ((proto = key_satype2proto(mhp->msg->sadb_msg_satype)) == 0) {
		ipseclog((LOG_DEBUG, "%s: invalid satype is passed.\n",
			__func__));
		return key_senderror(so, m, EINVAL);
	}
	cnt = 0;
	SAHTREE_LOCK();
	LIST_FOREACH(sah, &V_sahtree, chain) {
		if (mhp->msg->sadb_msg_satype != SADB_SATYPE_UNSPEC
		 && proto != sah->saidx.proto)
			continue;
		for (stateidx = 0;
		     stateidx < _ARRAYLEN(saorder_state_any);
		     stateidx++) {
			state = saorder_state_any[stateidx];
			LIST_FOREACH(sav, &sah->savtree[state], chain) {
				cnt++;
			}
		}
	}
	if (cnt == 0) {
		SAHTREE_UNLOCK();
		return key_senderror(so, m, ENOENT);
	}
	newmsg = NULL;
	LIST_FOREACH(sah, &V_sahtree, chain) {
		if (mhp->msg->sadb_msg_satype != SADB_SATYPE_UNSPEC
		 && proto != sah->saidx.proto)
			continue;
		if ((satype = key_proto2satype(sah->saidx.proto)) == 0) {
			SAHTREE_UNLOCK();
			ipseclog((LOG_DEBUG, "%s: there was invalid proto in "
				"SAD.\n", __func__));
			return key_senderror(so, m, EINVAL);
		}
		for (stateidx = 0;
		     stateidx < _ARRAYLEN(saorder_state_any);
		     stateidx++) {
			state = saorder_state_any[stateidx];
			LIST_FOREACH(sav, &sah->savtree[state], chain) {
				n = key_setdumpsa(sav, SADB_DUMP, satype,
				    --cnt, mhp->msg->sadb_msg_pid);
				if (!n) {
					SAHTREE_UNLOCK();
					return key_senderror(so, m, ENOBUFS);
				}
				key_sendup_mbuf(so, n, KEY_SENDUP_ONE);
			}
		}
	}
	SAHTREE_UNLOCK();
	m_freem(m);
	return 0;
}
static int key_dump ( struct socket * so , struct mbuf * m , const struct sadb_msghdr * mhp ) { struct secashead * sah ; struct secasvar * sav ; u_int16_t proto ; u_int stateidx ; u_int8_t satype ; u_int8_t state ; int cnt ; struct sadb_msg * newmsg ; struct mbuf * n ; IPSEC_ASSERT ( so != NULL , ( " " ) ) ; IPSEC_ASSERT ( m != NULL , ( " " ) ) ; IPSEC_ASSERT ( mhp != NULL , ( " " ) ) ; IPSEC_ASSERT ( mhp -> msg != NULL , ( " " ) ) ; if ( ( proto = key_satype2proto ( mhp -> msg -> sadb_msg_satype ) ) == 0 ) { ipseclog ( ( LOG_DEBUG , " \n " , __func__ ) ) ; return key_senderror ( so , m , EINVAL ) ; } cnt = 0 ; SAHTREE_LOCK ( ) ; LIST_FOREACH ( sah , & V_sahtree , chain ) { if ( mhp -> msg -> sadb_msg_satype != SADB_SATYPE_UNSPEC && proto != sah -> saidx . proto ) continue ; for ( stateidx = 0 ; stateidx < _ARRAYLEN ( saorder_state_any ) ; stateidx ++ ) { state = saorder_state_any [ stateidx ] ; LIST_FOREACH ( sav , & sah -> savtree [ state ] , chain ) { cnt ++ ; } } } if ( cnt == 0 ) { SAHTREE_UNLOCK ( ) ; return key_senderror ( so , m , ENOENT ) ; } newmsg = NULL ; LIST_FOREACH ( sah , & V_sahtree , chain ) { if ( mhp -> msg -> sadb_msg_satype != SADB_SATYPE_UNSPEC && proto != sah -> saidx . proto ) continue ; if ( ( satype = key_proto2satype ( sah -> saidx . proto ) ) == 0 ) { SAHTREE_UNLOCK ( ) ; ipseclog ( ( LOG_DEBUG , " " " \n " , __func__ ) ) ; return key_senderror ( so , m , EINVAL ) ; } for ( stateidx = 0 ; stateidx < _ARRAYLEN ( saorder_state_any ) ; stateidx ++ ) { state = saorder_state_any [ stateidx ] ; LIST_FOREACH ( sav , & sah -> savtree [ state ] , chain ) { n = key_setdumpsa ( sav , SADB_DUMP , satype , -- cnt , mhp -> msg -> sadb_msg_pid ) ; if ( ! n ) { SAHTREE_UNLOCK ( ) ; return key_senderror ( so , m , ENOBUFS ) ; } key_sendup_mbuf ( so , n , KEY_SENDUP_ONE ) ; } } } SAHTREE_UNLOCK ( ) ; m_freem ( m ) ; return 0 ; }
SADB_DUMP processing
 dump all entries including status of DEAD in SAD.
SADB_DUMP processing dump all entries including status of DEAD in SAD .
/* map satype to proto */ /* count sav entries to be sent to the userland. */ /* send this to the userland, one at a time. */ /* map proto to satype */