summaryrefslogtreecommitdiffstats
path: root/sys/netinet/raw_ip.c
diff options
context:
space:
mode:
authordhill <dhill@openbsd.org>2017-02-01 20:59:47 +0000
committerdhill <dhill@openbsd.org>2017-02-01 20:59:47 +0000
commit490e07389287ee0220d61374d4494b51bf6c4492 (patch)
tree9fac3a8a03787a9dd2622cff8c29c632a3dfefa7 /sys/netinet/raw_ip.c
parentAdd a missing sizeof(*lines) factor to previous commit to ensure we zero (diff)
downloadwireguard-openbsd-490e07389287ee0220d61374d4494b51bf6c4492.tar.xz
wireguard-openbsd-490e07389287ee0220d61374d4494b51bf6c4492.zip
In sogetopt, preallocate an mbuf to avoid using sleeping mallocs with
the netlock held. This also changes the prototypes of the *ctloutput functions to take an mbuf instead of an mbuf pointer. help, guidance from bluhm@ and mpi@ ok bluhm@
Diffstat (limited to 'sys/netinet/raw_ip.c')
-rw-r--r--sys/netinet/raw_ip.c36
1 files changed, 17 insertions, 19 deletions
diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c
index a9d55bfc7ea..b3d0d7acd9e 100644
--- a/sys/netinet/raw_ip.c
+++ b/sys/netinet/raw_ip.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: raw_ip.c,v 1.94 2017/01/29 19:58:47 bluhm Exp $ */
+/* $OpenBSD: raw_ip.c,v 1.95 2017/02/01 20:59:47 dhill Exp $ */
/* $NetBSD: raw_ip.c,v 1.25 1996/02/18 18:58:33 christos Exp $ */
/*
@@ -299,7 +299,7 @@ rip_output(struct mbuf *m, ...)
*/
int
rip_ctloutput(int op, struct socket *so, int level, int optname,
- struct mbuf **mp)
+ struct mbuf *m)
{
struct inpcb *inp = sotoinpcb(so);
int error = 0;
@@ -307,7 +307,7 @@ rip_ctloutput(int op, struct socket *so, int level, int optname,
if (level != IPPROTO_IP) {
if (op == PRCO_SETOPT)
- (void) m_free(*mp);
+ (void) m_free(m);
return (EINVAL);
}
@@ -316,28 +316,27 @@ rip_ctloutput(int op, struct socket *so, int level, int optname,
case IP_HDRINCL:
error = 0;
if (op == PRCO_SETOPT) {
- if (*mp == NULL || (*mp)->m_len < sizeof (int))
+ if (m == NULL || m->m_len < sizeof (int))
error = EINVAL;
- else if (*mtod(*mp, int *))
+ else if (*mtod(m, int *))
inp->inp_flags |= INP_HDRINCL;
else
inp->inp_flags &= ~INP_HDRINCL;
- m_free(*mp);
+ m_free(m);
} else {
- *mp = m_get(M_WAIT, M_SOOPTS);
- (*mp)->m_len = sizeof(int);
- *mtod(*mp, int *) = inp->inp_flags & INP_HDRINCL;
+ m->m_len = sizeof(int);
+ *mtod(m, int *) = inp->inp_flags & INP_HDRINCL;
}
return (error);
case IP_DIVERTFL:
switch (op) {
case PRCO_SETOPT:
- if (*mp == NULL || (*mp)->m_len < sizeof (int)) {
+ if (m == NULL || m->m_len < sizeof (int)) {
error = EINVAL;
break;
}
- dir = *mtod(*mp, int *);
+ dir = *mtod(m, int *);
if (inp->inp_divertfl > 0)
error = ENOTSUP;
else if ((dir & IPPROTO_DIVERT_RESP) ||
@@ -349,9 +348,8 @@ rip_ctloutput(int op, struct socket *so, int level, int optname,
break;
case PRCO_GETOPT:
- *mp = m_get(M_WAIT, M_SOOPTS);
- (*mp)->m_len = sizeof(int);
- *mtod(*mp, int *) = inp->inp_divertfl;
+ m->m_len = sizeof(int);
+ *mtod(m, int *) = inp->inp_divertfl;
break;
default:
@@ -360,7 +358,7 @@ rip_ctloutput(int op, struct socket *so, int level, int optname,
}
if (op == PRCO_SETOPT)
- (void)m_free(*mp);
+ (void)m_free(m);
return (error);
case MRT_INIT:
@@ -376,10 +374,10 @@ rip_ctloutput(int op, struct socket *so, int level, int optname,
#ifdef MROUTING
switch (op) {
case PRCO_SETOPT:
- error = ip_mrouter_set(so, optname, mp);
+ error = ip_mrouter_set(so, optname, m);
break;
case PRCO_GETOPT:
- error = ip_mrouter_get(so, optname, mp);
+ error = ip_mrouter_get(so, optname, m);
break;
default:
error = EINVAL;
@@ -388,11 +386,11 @@ rip_ctloutput(int op, struct socket *so, int level, int optname,
return (error);
#else
if (op == PRCO_SETOPT)
- m_free(*mp);
+ m_free(m);
return (EOPNOTSUPP);
#endif
}
- return (ip_ctloutput(op, so, level, optname, mp));
+ return (ip_ctloutput(op, so, level, optname, m));
}
u_long rip_sendspace = RIPSNDQ;