svn commit: r330779 - head/sys/netipsec

Andrey V. Elsukov ae at FreeBSD.org
Sun Mar 11 19:14:02 UTC 2018


Author: ae
Date: Sun Mar 11 19:14:01 2018
New Revision: 330779
URL: https://svnweb.freebsd.org/changeset/base/330779

Log:
  Rework key_sendup_mbuf() a bit:
  
  o count in_nomem counter when we have failed to allocate mbuf for
    promisc socket;
  o count in_msgtarget counter when we have secussfully sent data to socket;
  o Since we are sending messages in a loop, returning error on first fail
    interrupts the loop, and all remaining sockets will not receive this
    message. So, do not return error when we have failed to send data to ALL
    or REGISTERED target. Return error only for KEY_SENDUP_ONE case. Now,
    when some socket has overfilled its receive buffer, this will not break
    other sockets.
  
  MFC after:	2 weeks

Modified:
  head/sys/netipsec/keysock.c

Modified: head/sys/netipsec/keysock.c
==============================================================================
--- head/sys/netipsec/keysock.c	Sun Mar 11 18:54:45 2018	(r330778)
+++ head/sys/netipsec/keysock.c	Sun Mar 11 19:14:01 2018	(r330779)
@@ -178,7 +178,6 @@ key_sendup_mbuf(struct socket *so, struct mbuf *m, int
 {
 	struct mbuf *n;
 	struct keycb *kp;
-	int sendup;
 	struct rawcb *rp;
 	int error = 0;
 
@@ -217,69 +216,50 @@ key_sendup_mbuf(struct socket *so, struct mbuf *m, int
 			continue;
 		}
 
-		kp = (struct keycb *)rp;
-
 		/*
 		 * If you are in promiscuous mode, and when you get broadcasted
 		 * reply, you'll get two PF_KEY messages.
 		 * (based on pf_key at inner.net message on 14 Oct 1998)
 		 */
-		if (((struct keycb *)rp)->kp_promisc) {
-			if ((n = m_copym(m, 0, M_COPYALL, M_NOWAIT)) != NULL) {
-				(void)key_sendup0(rp, n, 1);
-				n = NULL;
-			}
+		kp = (struct keycb *)rp;
+		if (kp->kp_promisc) {
+			n = m_copym(m, 0, M_COPYALL, M_NOWAIT);
+			if (n != NULL)
+				key_sendup0(rp, n, 1);
+			else
+				PFKEYSTAT_INC(in_nomem);
 		}
 
 		/* the exact target will be processed later */
 		if (so && sotorawcb(so) == rp)
 			continue;
 
-		sendup = 0;
-		switch (target) {
-		case KEY_SENDUP_ONE:
-			/* the statement has no effect */
-			if (so && sotorawcb(so) == rp)
-				sendup++;
-			break;
-		case KEY_SENDUP_ALL:
-			sendup++;
-			break;
-		case KEY_SENDUP_REGISTERED:
-			if (kp->kp_registered)
-				sendup++;
-			break;
-		}
-		PFKEYSTAT_INC(in_msgtarget[target]);
-
-		if (!sendup)
+		if (target == KEY_SENDUP_ONE || (
+		    target == KEY_SENDUP_REGISTERED && kp->kp_registered == 0))
 			continue;
 
-		if ((n = m_copym(m, 0, M_COPYALL, M_NOWAIT)) == NULL) {
-			m_freem(m);
+		/* KEY_SENDUP_ALL + KEY_SENDUP_REGISTERED */
+		n = m_copym(m, 0, M_COPYALL, M_NOWAIT);
+		if (n == NULL) {
 			PFKEYSTAT_INC(in_nomem);
-			mtx_unlock(&rawcb_mtx);
-			return ENOBUFS;
+			/* Try send to another socket */
+			continue;
 		}
 
-		if ((error = key_sendup0(rp, n, 0)) != 0) {
-			m_freem(m);
-			mtx_unlock(&rawcb_mtx);
-			return error;
-		}
-
-		n = NULL;
+		if (key_sendup0(rp, n, 0) == 0)
+			PFKEYSTAT_INC(in_msgtarget[target]);
 	}
 
-	if (so) {
+	if (so)	{ /* KEY_SENDUP_ONE */
 		error = key_sendup0(sotorawcb(so), m, 0);
-		m = NULL;
+		if (error == 0)
+			PFKEYSTAT_INC(in_msgtarget[KEY_SENDUP_ONE]);
 	} else {
 		error = 0;
 		m_freem(m);
 	}
 	mtx_unlock(&rawcb_mtx);
-	return error;
+	return (error);
 }
 
 /*


More information about the svn-src-all mailing list