svn commit: r331526 - stable/11/sys/netipsec
Andrey V. Elsukov
ae at FreeBSD.org
Sun Mar 25 03:45:03 UTC 2018
Author: ae
Date: Sun Mar 25 03:45:02 2018
New Revision: 331526
URL: https://svnweb.freebsd.org/changeset/base/331526
Log:
MFC r330779:
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.
Modified:
stable/11/sys/netipsec/keysock.c
Directory Properties:
stable/11/ (props changed)
Modified: stable/11/sys/netipsec/keysock.c
==============================================================================
--- stable/11/sys/netipsec/keysock.c Sun Mar 25 03:37:26 2018 (r331525)
+++ stable/11/sys/netipsec/keysock.c Sun Mar 25 03:45:02 2018 (r331526)
@@ -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_copy(m, 0, (int)M_COPYALL)) != 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_copy(m, 0, (int)M_COPYALL)) == 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-stable-11
mailing list