FreeBSD/sys/netipsec/key.c
/*
 * SADB_X_PROMISC processing
 *
 * m will always be freed.
 */
SADB_X_PROMISC processing
m will always be freed.
SADB_X_PROMISC processing m will always be freed .
static int
key_promisc(struct socket *so, struct mbuf *m, const struct sadb_msghdr *mhp)
{
	int olen;
	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"));
	olen = PFKEY_UNUNIT64(mhp->msg->sadb_msg_len);
	if (olen < sizeof(struct sadb_msg)) {
#if 1
		return key_senderror(so, m, EINVAL);
#else
		m_freem(m);
		return 0;
#endif
	} else if (olen == sizeof(struct sadb_msg)) {
		struct keycb *kp;
		if ((kp = (struct keycb *)sotorawcb(so)) == NULL)
			return key_senderror(so, m, EINVAL);
		mhp->msg->sadb_msg_errno = 0;
		switch (mhp->msg->sadb_msg_satype) {
		case 0:
		case 1:
			kp->kp_promisc = mhp->msg->sadb_msg_satype;
			break;
		default:
			return key_senderror(so, m, EINVAL);
		}
		mhp->msg->sadb_msg_errno = 0;
		return key_sendup_mbuf(so, m, KEY_SENDUP_ALL);
	} else {
		m_adj(m, PFKEY_ALIGN8(sizeof(struct sadb_msg)));
		return key_sendup_mbuf(so, m, KEY_SENDUP_ALL);
	}
}
static int key_promisc ( struct socket * so , struct mbuf * m , const struct sadb_msghdr * mhp ) { int olen ; IPSEC_ASSERT ( so != NULL , ( " " ) ) ; IPSEC_ASSERT ( m != NULL , ( " " ) ) ; IPSEC_ASSERT ( mhp != NULL , ( " " ) ) ; IPSEC_ASSERT ( mhp -> msg != NULL , ( " " ) ) ; olen = PFKEY_UNUNIT64 ( mhp -> msg -> sadb_msg_len ) ; if ( olen < sizeof ( struct sadb_msg ) ) { #if 1 return key_senderror ( so , m , EINVAL ) ; #else m_freem ( m ) ; return 0 ; #endif } else if ( olen == sizeof ( struct sadb_msg ) ) { struct keycb * kp ; if ( ( kp = ( struct keycb * ) sotorawcb ( so ) ) == NULL ) return key_senderror ( so , m , EINVAL ) ; mhp -> msg -> sadb_msg_errno = 0 ; switch ( mhp -> msg -> sadb_msg_satype ) { case 0 : case 1 : kp -> kp_promisc = mhp -> msg -> sadb_msg_satype ; break ; default : return key_senderror ( so , m , EINVAL ) ; } mhp -> msg -> sadb_msg_errno = 0 ; return key_sendup_mbuf ( so , m , KEY_SENDUP_ALL ) ; } else { m_adj ( m , PFKEY_ALIGN8 ( sizeof ( struct sadb_msg ) ) ) ; return key_sendup_mbuf ( so , m , KEY_SENDUP_ALL ) ; } }
SADB_X_PROMISC processing
 m will always be freed.
SADB_X_PROMISC processing m will always be freed .
/* enable/disable promisc mode */ /* send the original message back to everyone */ /* send packet as is */ /* TODO: if sadb_msg_seq is specified, send to specific pid */