summaryrefslogtreecommitdiffstats
path: root/sys/netinet/ip_output.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/ip_output.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/ip_output.c')
-rw-r--r--sys/netinet/ip_output.c31
1 files changed, 11 insertions, 20 deletions
diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c
index c1cf4f68cfe..7f276bbf470 100644
--- a/sys/netinet/ip_output.c
+++ b/sys/netinet/ip_output.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip_output.c,v 1.334 2017/01/10 09:01:18 mpi Exp $ */
+/* $OpenBSD: ip_output.c,v 1.335 2017/02/01 20:59:47 dhill Exp $ */
/* $NetBSD: ip_output.c,v 1.28 1996/02/13 23:43:07 christos Exp $ */
/*
@@ -845,10 +845,9 @@ ip_optcopy(struct ip *ip, struct ip *jp)
*/
int
ip_ctloutput(int op, struct socket *so, int level, int optname,
- struct mbuf **mp)
+ struct mbuf *m)
{
struct inpcb *inp = sotoinpcb(so);
- struct mbuf *m = *mp;
int optval = 0;
struct proc *p = curproc; /* XXX */
int error = 0;
@@ -857,7 +856,7 @@ ip_ctloutput(int op, struct socket *so, int level, int optname,
if (level != IPPROTO_IP) {
error = EINVAL;
if (op == PRCO_SETOPT)
- (void) m_free(*mp);
+ (void) m_free(m);
} else switch (op) {
case PRCO_SETOPT:
switch (optname) {
@@ -1081,7 +1080,6 @@ ip_ctloutput(int op, struct socket *so, int level, int optname,
switch (optname) {
case IP_OPTIONS:
case IP_RETOPTS:
- *mp = m = m_get(M_WAIT, MT_SOOPTS);
if (inp->inp_options) {
m->m_len = inp->inp_options->m_len;
memcpy(mtod(m, caddr_t),
@@ -1102,7 +1100,6 @@ ip_ctloutput(int op, struct socket *so, int level, int optname,
case IP_RECVRTABLE:
case IP_IPSECFLOWINFO:
case IP_IPDEFTTL:
- *mp = m = m_get(M_WAIT, MT_SOOPTS);
m->m_len = sizeof(int);
switch (optname) {
@@ -1159,11 +1156,10 @@ ip_ctloutput(int op, struct socket *so, int level, int optname,
case IP_MULTICAST_LOOP:
case IP_ADD_MEMBERSHIP:
case IP_DROP_MEMBERSHIP:
- error = ip_getmoptions(optname, inp->inp_moptions, mp);
+ error = ip_getmoptions(optname, inp->inp_moptions, m);
break;
case IP_PORTRANGE:
- *mp = m = m_get(M_WAIT, MT_SOOPTS);
m->m_len = sizeof(int);
if (inp->inp_flags & INP_HIGHPORT)
@@ -1180,7 +1176,6 @@ ip_ctloutput(int op, struct socket *so, int level, int optname,
case IP_ESP_TRANS_LEVEL:
case IP_ESP_NETWORK_LEVEL:
case IP_IPCOMP_LEVEL:
- *mp = m = m_get(M_WAIT, MT_SOOPTS);
#ifndef IPSEC
m->m_len = sizeof(int);
*mtod(m, int *) = IPSEC_LEVEL_NONE;
@@ -1210,12 +1205,10 @@ ip_ctloutput(int op, struct socket *so, int level, int optname,
error = EOPNOTSUPP;
break;
case SO_RTABLE:
- *mp = m = m_get(M_WAIT, MT_SOOPTS);
m->m_len = sizeof(u_int);
*mtod(m, u_int *) = inp->inp_rtableid;
break;
case IP_PIPEX:
- *mp = m = m_get(M_WAIT, MT_SOOPTS);
m->m_len = sizeof(int);
*mtod(m, int *) = inp->inp_pipex;
break;
@@ -1624,7 +1617,7 @@ ip_setmoptions(int optname, struct ip_moptions **imop, struct mbuf *m,
* Return the IP multicast options in response to user getsockopt().
*/
int
-ip_getmoptions(int optname, struct ip_moptions *imo, struct mbuf **mp)
+ip_getmoptions(int optname, struct ip_moptions *imo, struct mbuf *m)
{
u_char *ttl;
u_char *loop;
@@ -1632,13 +1625,11 @@ ip_getmoptions(int optname, struct ip_moptions *imo, struct mbuf **mp)
struct in_ifaddr *ia;
struct ifnet *ifp;
- *mp = m_get(M_WAIT, MT_SOOPTS);
-
switch (optname) {
case IP_MULTICAST_IF:
- addr = mtod(*mp, struct in_addr *);
- (*mp)->m_len = sizeof(struct in_addr);
+ addr = mtod(m, struct in_addr *);
+ m->m_len = sizeof(struct in_addr);
if (imo == NULL || (ifp = if_get(imo->imo_ifidx)) == NULL)
addr->s_addr = INADDR_ANY;
else {
@@ -1650,15 +1641,15 @@ ip_getmoptions(int optname, struct ip_moptions *imo, struct mbuf **mp)
return (0);
case IP_MULTICAST_TTL:
- ttl = mtod(*mp, u_char *);
- (*mp)->m_len = 1;
+ ttl = mtod(m, u_char *);
+ m->m_len = 1;
*ttl = (imo == NULL) ? IP_DEFAULT_MULTICAST_TTL
: imo->imo_ttl;
return (0);
case IP_MULTICAST_LOOP:
- loop = mtod(*mp, u_char *);
- (*mp)->m_len = 1;
+ loop = mtod(m, u_char *);
+ m->m_len = 1;
*loop = (imo == NULL) ? IP_DEFAULT_MULTICAST_LOOP
: imo->imo_loop;
return (0);