aboutsummaryrefslogtreecommitdiff
path: root/sys/netipsec/keysock.c
diff options
context:
space:
mode:
authorAndrey V. Elsukov <ae@FreeBSD.org>2018-03-11 19:14:01 +0000
committerAndrey V. Elsukov <ae@FreeBSD.org>2018-03-11 19:14:01 +0000
commit017a5e581a4eabf0ba0d10ea5bb168ce0e00946a (patch)
tree78028231559f1c5c51e38b6a3c90ea20051c1f75 /sys/netipsec/keysock.c
parent67e2a29216b2cdff96bd8f2a81f114b63aa8c08b (diff)
downloadsrc-017a5e581a4eabf0ba0d10ea5bb168ce0e00946a.tar.gz
src-017a5e581a4eabf0ba0d10ea5bb168ce0e00946a.zip
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
Notes
Notes: svn path=/head/; revision=330779
Diffstat (limited to 'sys/netipsec/keysock.c')
-rw-r--r--sys/netipsec/keysock.c60
1 files changed, 20 insertions, 40 deletions
diff --git a/sys/netipsec/keysock.c b/sys/netipsec/keysock.c
index fc17113992e8..7f8b0e51c59e 100644
--- a/sys/netipsec/keysock.c
+++ b/sys/netipsec/keysock.c
@@ -178,7 +178,6 @@ key_sendup_mbuf(struct socket *so, struct mbuf *m, int target)
{
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 target)
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@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;
- }
-
- if ((error = key_sendup0(rp, n, 0)) != 0) {
- m_freem(m);
- mtx_unlock(&rawcb_mtx);
- return error;
+ /* Try send to another socket */
+ continue;
}
- 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);
}
/*