On Tue, Jan 31, 2017 at 12:14:35PM -0500, David Hill wrote:
> with mpi@'s suggestion to pass a struct mbuf *
We call mbuf variables m and mbuf pointer mp. So you should rename
*mp to m.
The different policy who has to free the mbuf with
if (op == PRCO_SETOPT)
m_free(*mp);
is not nice. I think it would be better if all the freeing is
done in sosetopt and sogetopt. But this requires more thought
and should not be in this diff. A possible next step.
bluhm
>
> Index: kern/uipc_socket.c
> ===================================================================
> RCS file: /cvs/src/sys/kern/uipc_socket.c,v
> retrieving revision 1.175
> diff -u -p -r1.175 uipc_socket.c
> --- kern/uipc_socket.c 27 Jan 2017 20:31:42 -0000 1.175
> +++ kern/uipc_socket.c 31 Jan 2017 17:09:42 -0000
> @@ -1560,7 +1560,7 @@ sosetopt(struct socket *so, int level, i
> if (so->so_proto && so->so_proto->pr_ctloutput) {
> NET_LOCK(s);
> error = (*so->so_proto->pr_ctloutput)(PRCO_SETOPT, so,
> - level, optname, &m0);
> + level, optname, m0);
> NET_UNLOCK(s);
> return (error);
> }
> @@ -1707,7 +1707,7 @@ sosetopt(struct socket *so, int level, i
> level = dom->dom_protosw->pr_protocol;
> NET_LOCK(s);
> error = (*so->so_proto->pr_ctloutput)
> - (PRCO_SETOPT, so, level, optname, &m0);
> + (PRCO_SETOPT, so, level, optname, m0);
> NET_UNLOCK(s);
> return (error);
> }
> @@ -1739,7 +1739,7 @@ sosetopt(struct socket *so, int level, i
> if (error == 0 && so->so_proto && so->so_proto->pr_ctloutput) {
> NET_LOCK(s);
> (*so->so_proto->pr_ctloutput)(PRCO_SETOPT, so,
> - level, optname, &m0);
> + level, optname, m0);
> NET_UNLOCK(s);
> m = NULL; /* freed by protocol */
> }
> @@ -1758,11 +1758,19 @@ sogetopt(struct socket *so, int level, i
>
> if (level != SOL_SOCKET) {
> if (so->so_proto && so->so_proto->pr_ctloutput) {
> + m = m_get(M_WAIT, MT_SOOPTS);
> + m->m_len = 0;
> +
> NET_LOCK(s);
> error = (*so->so_proto->pr_ctloutput)(PRCO_GETOPT, so,
> - level, optname, mp);
> + level, optname, m);
> NET_UNLOCK(s);
> - return (error);
> + if (error) {
> + m_free(m);
> + return (error);
> + }
> + *mp = m;
> + return (0);
> } else
> return (ENOPROTOOPT);
> } else {
> @@ -1835,7 +1843,6 @@ sogetopt(struct socket *so, int level, i
> }
>
> case SO_RTABLE:
> - (void)m_free(m);
> if (so->so_proto && so->so_proto->pr_domain &&
> so->so_proto->pr_domain->dom_protosw &&
> so->so_proto->pr_ctloutput) {
> @@ -1844,12 +1851,16 @@ sogetopt(struct socket *so, int level, i
> level = dom->dom_protosw->pr_protocol;
> NET_LOCK(s);
> error = (*so->so_proto->pr_ctloutput)
> - (PRCO_GETOPT, so, level, optname, mp);
> + (PRCO_GETOPT, so, level, optname, m);
> NET_UNLOCK(s);
> - return (error);
> + if (error) {
> + (void)m_free(m);
> + return (error);
> + }
> + break;
> }
> + (void)m_free(m);
> return (ENOPROTOOPT);
> - break;
>
> #ifdef SOCKET_SPLICE
> case SO_SPLICE:
> @@ -1880,7 +1891,6 @@ sogetopt(struct socket *so, int level, i
> }
> (void)m_free(m);
> return (EOPNOTSUPP);
> - break;
>
> default:
> (void)m_free(m);
> Index: net/rtsock.c
> ===================================================================
> RCS file: /cvs/src/sys/net/rtsock.c,v
> retrieving revision 1.221
> diff -u -p -r1.221 rtsock.c
> --- net/rtsock.c 31 Jan 2017 10:24:41 -0000 1.221
> +++ net/rtsock.c 31 Jan 2017 17:09:42 -0000
> @@ -98,7 +98,7 @@ struct walkarg {
> caddr_t w_where, w_tmem;
> };
>
> -int route_ctloutput(int, struct socket *, int, int, struct mbuf **);
> +int route_ctloutput(int, struct socket *, int, int, struct mbuf *);
> void route_input(struct mbuf *m0, sa_family_t);
> int route_arp_conflict(struct rtentry *, struct rt_addrinfo *);
> int route_cleargateway(struct rtentry *, void *, unsigned int);
> @@ -234,17 +234,17 @@ route_usrreq(struct socket *so, int req,
>
> int
> route_ctloutput(int op, struct socket *so, int level, int optname,
> - struct mbuf **mp)
> + struct mbuf *mp)
> {
> struct routecb *rop = sotoroutecb(so);
> - struct mbuf *m = *mp;
> + struct mbuf *m = mp;
> int error = 0;
> unsigned int tid;
>
> if (level != AF_ROUTE) {
> error = EINVAL;
> - if (op == PRCO_SETOPT && *mp)
> - m_free(*mp);
> + if (op == PRCO_SETOPT && mp)
> + m_free(mp);
> return (error);
> }
>
> @@ -277,12 +277,10 @@ route_ctloutput(int op, struct socket *s
> case PRCO_GETOPT:
> switch (optname) {
> case ROUTE_MSGFILTER:
> - *mp = m = m_get(M_WAIT, MT_SOOPTS);
> m->m_len = sizeof(unsigned int);
> *mtod(m, unsigned int *) = rop->msgfilter;
> break;
> case ROUTE_TABLEFILTER:
> - *mp = m = m_get(M_WAIT, MT_SOOPTS);
> m->m_len = sizeof(unsigned int);
> *mtod(m, unsigned int *) = rop->rtableid;
> break;
> Index: netinet/ip_mroute.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet/ip_mroute.c,v
> retrieving revision 1.107
> diff -u -p -r1.107 ip_mroute.c
> --- netinet/ip_mroute.c 12 Jan 2017 08:22:42 -0000 1.107
> +++ netinet/ip_mroute.c 31 Jan 2017 17:09:42 -0000
> @@ -173,7 +173,7 @@ mfc_find(struct ifnet *ifp, struct in_ad
> * Handle MRT setsockopt commands to modify the multicast routing tables.
> */
> int
> -ip_mrouter_set(struct socket *so, int optname, struct mbuf **mp)
> +ip_mrouter_set(struct socket *so, int optname, struct mbuf *mp)
> {
> struct inpcb *inp = sotoinpcb(so);
> int error;
> @@ -184,32 +184,32 @@ ip_mrouter_set(struct socket *so, int op
> else
> switch (optname) {
> case MRT_INIT:
> - error = ip_mrouter_init(so, *mp);
> + error = ip_mrouter_init(so, mp);
> break;
> case MRT_DONE:
> error = ip_mrouter_done(so);
> break;
> case MRT_ADD_VIF:
> - error = add_vif(so, *mp);
> + error = add_vif(so, mp);
> break;
> case MRT_DEL_VIF:
> - error = del_vif(so, *mp);
> + error = del_vif(so, mp);
> break;
> case MRT_ADD_MFC:
> - error = add_mfc(so, *mp);
> + error = add_mfc(so, mp);
> break;
> case MRT_DEL_MFC:
> - error = del_mfc(so, *mp);
> + error = del_mfc(so, mp);
> break;
> case MRT_API_CONFIG:
> - error = set_api_config(so, *mp);
> + error = set_api_config(so, mp);
> break;
> default:
> error = ENOPROTOOPT;
> break;
> }
>
> - m_free(*mp);
> + m_free(mp);
> return (error);
> }
>
> @@ -217,7 +217,7 @@ ip_mrouter_set(struct socket *so, int op
> * Handle MRT getsockopt commands
> */
> int
> -ip_mrouter_get(struct socket *so, int optname, struct mbuf **mp)
> +ip_mrouter_get(struct socket *so, int optname, struct mbuf *mp)
> {
> struct inpcb *inp = sotoinpcb(so);
> int error;
> @@ -225,25 +225,20 @@ ip_mrouter_get(struct socket *so, int op
> if (so != ip_mrouter[inp->inp_rtableid])
> error = ENOPROTOOPT;
> else {
> - *mp = m_get(M_WAIT, MT_SOOPTS);
> -
> switch (optname) {
> case MRT_VERSION:
> - error = get_version(*mp);
> + error = get_version(mp);
> break;
> case MRT_API_SUPPORT:
> - error = get_api_support(*mp);
> + error = get_api_support(mp);
> break;
> case MRT_API_CONFIG:
> - error = get_api_config(*mp);
> + error = get_api_config(mp);
> break;
> default:
> error = ENOPROTOOPT;
> break;
> }
> -
> - if (error)
> - m_free(*mp);
> }
>
> return (error);
> Index: netinet/ip_mroute.h
> ===================================================================
> RCS file: /cvs/src/sys/netinet/ip_mroute.h,v
> retrieving revision 1.27
> diff -u -p -r1.27 ip_mroute.h
> --- netinet/ip_mroute.h 12 Jan 2017 08:22:42 -0000 1.27
> +++ netinet/ip_mroute.h 31 Jan 2017 17:09:42 -0000
> @@ -223,8 +223,8 @@ struct igmpmsg {
> struct in_addr im_src, im_dst;
> };
>
> -int ip_mrouter_set(struct socket *, int, struct mbuf **);
> -int ip_mrouter_get(struct socket *, int, struct mbuf **);
> +int ip_mrouter_set(struct socket *, int, struct mbuf *);
> +int ip_mrouter_get(struct socket *, int, struct mbuf *);
> int mrt_ioctl(struct socket *, u_long, caddr_t);
> int mrt_sysctl_vif(void *, size_t *);
> int mrt_sysctl_mfc(void *, size_t *);
> Index: netinet/ip_output.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet/ip_output.c,v
> retrieving revision 1.334
> diff -u -p -r1.334 ip_output.c
> --- netinet/ip_output.c 10 Jan 2017 09:01:18 -0000 1.334
> +++ netinet/ip_output.c 31 Jan 2017 17:09:42 -0000
> @@ -845,10 +845,10 @@ 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 *mp)
> {
> struct inpcb *inp = sotoinpcb(so);
> - struct mbuf *m = *mp;
> + struct mbuf *m = mp;
> int optval = 0;
> struct proc *p = curproc; /* XXX */
> int error = 0;
> @@ -857,7 +857,7 @@ ip_ctloutput(int op, struct socket *so,
> if (level != IPPROTO_IP) {
> error = EINVAL;
> if (op == PRCO_SETOPT)
> - (void) m_free(*mp);
> + (void) m_free(mp);
> } else switch (op) {
> case PRCO_SETOPT:
> switch (optname) {
> @@ -1081,7 +1081,6 @@ ip_ctloutput(int op, struct socket *so,
> 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 +1101,6 @@ ip_ctloutput(int op, struct socket *so,
> case IP_RECVRTABLE:
> case IP_IPSECFLOWINFO:
> case IP_IPDEFTTL:
> - *mp = m = m_get(M_WAIT, MT_SOOPTS);
> m->m_len = sizeof(int);
> switch (optname) {
>
> @@ -1163,7 +1161,6 @@ ip_ctloutput(int op, struct socket *so,
> break;
>
> case IP_PORTRANGE:
> - *mp = m = m_get(M_WAIT, MT_SOOPTS);
> m->m_len = sizeof(int);
>
> if (inp->inp_flags & INP_HIGHPORT)
> @@ -1180,12 +1177,10 @@ ip_ctloutput(int op, struct socket *so,
> 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);
> +#ifndef IPSEC
> *mtod(m, int *) = IPSEC_LEVEL_NONE;
> #else
> - m->m_len = sizeof(int);
> switch (optname) {
> case IP_AUTH_LEVEL:
> optval = inp->inp_seclevel[SL_AUTH];
> @@ -1210,12 +1205,10 @@ ip_ctloutput(int op, struct socket *so,
> 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_mo
> * 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 *mp)
> {
> u_char *ttl;
> u_char *loop;
> @@ -1632,13 +1625,10 @@ ip_getmoptions(int optname, struct ip_mo
> 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(mp, struct in_addr *);
> + mp->m_len = sizeof(struct in_addr);
> if (imo == NULL || (ifp = if_get(imo->imo_ifidx)) == NULL)
> addr->s_addr = INADDR_ANY;
> else {
> @@ -1650,15 +1640,15 @@ ip_getmoptions(int optname, struct ip_mo
> return (0);
>
> case IP_MULTICAST_TTL:
> - ttl = mtod(*mp, u_char *);
> - (*mp)->m_len = 1;
> + ttl = mtod(mp, u_char *);
> + mp->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(mp, u_char *);
> + mp->m_len = 1;
> *loop = (imo == NULL) ? IP_DEFAULT_MULTICAST_LOOP
> : imo->imo_loop;
> return (0);
> Index: netinet/ip_var.h
> ===================================================================
> RCS file: /cvs/src/sys/netinet/ip_var.h,v
> retrieving revision 1.67
> diff -u -p -r1.67 ip_var.h
> --- netinet/ip_var.h 29 Jan 2017 19:58:47 -0000 1.67
> +++ netinet/ip_var.h 31 Jan 2017 17:09:42 -0000
> @@ -219,13 +219,13 @@ extern struct pool ipqent_pool;
> struct route;
> struct inpcb;
>
> -int ip_ctloutput(int, struct socket *, int, int, struct mbuf **);
> +int ip_ctloutput(int, struct socket *, int, int, struct mbuf *);
> void ip_drain(void);
> void ip_flush(void);
> int ip_fragment(struct mbuf *, struct ifnet *, u_long);
> void ip_freef(struct ipq *);
> void ip_freemoptions(struct ip_moptions *);
> -int ip_getmoptions(int, struct ip_moptions *, struct mbuf **);
> +int ip_getmoptions(int, struct ip_moptions *, struct mbuf *);
> void ip_init(void);
> struct mbuf*
> ip_insertoptions(struct mbuf *, struct mbuf *, int *);
> @@ -250,7 +250,7 @@ void ip_savecontrol(struct inpcb *, str
> void ipintr(void);
> void ipv4_input(struct mbuf *);
> void ip_forward(struct mbuf *, struct ifnet *, struct rtentry *, int);
> -int rip_ctloutput(int, struct socket *, int, int, struct mbuf **);
> +int rip_ctloutput(int, struct socket *, int, int, struct mbuf *);
> void rip_init(void);
> int rip_input(struct mbuf **, int *, int);
> int rip_output(struct mbuf *, ...);
> Index: netinet/raw_ip.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet/raw_ip.c,v
> retrieving revision 1.94
> diff -u -p -r1.94 raw_ip.c
> --- netinet/raw_ip.c 29 Jan 2017 19:58:47 -0000 1.94
> +++ netinet/raw_ip.c 31 Jan 2017 17:09:42 -0000
> @@ -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 *mp)
> {
> struct inpcb *inp = sotoinpcb(so);
> int error = 0;
> @@ -307,7 +307,7 @@ rip_ctloutput(int op, struct socket *so,
>
> if (level != IPPROTO_IP) {
> if (op == PRCO_SETOPT)
> - (void) m_free(*mp);
> + (void) m_free(mp);
> return (EINVAL);
> }
>
> @@ -316,28 +316,27 @@ rip_ctloutput(int op, struct socket *so,
> case IP_HDRINCL:
> error = 0;
> if (op == PRCO_SETOPT) {
> - if (*mp == NULL || (*mp)->m_len < sizeof (int))
> + if (mp == NULL || mp->m_len < sizeof (int))
> error = EINVAL;
> - else if (*mtod(*mp, int *))
> + else if (*mtod(mp, int *))
> inp->inp_flags |= INP_HDRINCL;
> else
> inp->inp_flags &= ~INP_HDRINCL;
> - m_free(*mp);
> + m_free(mp);
> } else {
> - *mp = m_get(M_WAIT, M_SOOPTS);
> - (*mp)->m_len = sizeof(int);
> - *mtod(*mp, int *) = inp->inp_flags & INP_HDRINCL;
> + mp->m_len = sizeof(int);
> + *mtod(mp, 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 (mp == NULL || mp->m_len < sizeof (int)) {
> error = EINVAL;
> break;
> }
> - dir = *mtod(*mp, int *);
> + dir = *mtod(mp, 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,
> break;
>
> case PRCO_GETOPT:
> - *mp = m_get(M_WAIT, M_SOOPTS);
> - (*mp)->m_len = sizeof(int);
> - *mtod(*mp, int *) = inp->inp_divertfl;
> + mp->m_len = sizeof(int);
> + *mtod(mp, int *) = inp->inp_divertfl;
> break;
>
> default:
> @@ -360,7 +358,7 @@ rip_ctloutput(int op, struct socket *so,
> }
>
> if (op == PRCO_SETOPT)
> - (void)m_free(*mp);
> + (void)m_free(mp);
> return (error);
>
> case MRT_INIT:
> @@ -388,7 +386,7 @@ rip_ctloutput(int op, struct socket *so,
> return (error);
> #else
> if (op == PRCO_SETOPT)
> - m_free(*mp);
> + m_free(mp);
> return (EOPNOTSUPP);
> #endif
> }
> Index: netinet/tcp_usrreq.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet/tcp_usrreq.c,v
> retrieving revision 1.142
> diff -u -p -r1.142 tcp_usrreq.c
> --- netinet/tcp_usrreq.c 10 Jan 2017 09:01:18 -0000 1.142
> +++ netinet/tcp_usrreq.c 31 Jan 2017 17:09:43 -0000
> @@ -449,7 +449,7 @@ tcp_usrreq(struct socket *so, int req, s
>
> int
> tcp_ctloutput(int op, struct socket *so, int level, int optname,
> - struct mbuf **mp)
> + struct mbuf *mp)
> {
> int error = 0;
> struct inpcb *inp;
> @@ -460,7 +460,7 @@ tcp_ctloutput(int op, struct socket *so,
> inp = sotoinpcb(so);
> if (inp == NULL) {
> if (op == PRCO_SETOPT)
> - (void) m_free(*mp);
> + (void) m_free(mp);
> return (ECONNRESET);
> }
> if (level != IPPROTO_TCP) {
> @@ -484,7 +484,7 @@ tcp_ctloutput(int op, struct socket *so,
> switch (op) {
>
> case PRCO_SETOPT:
> - m = *mp;
> + m = mp;
> switch (optname) {
>
> case TCP_NODELAY:
> @@ -573,7 +573,7 @@ tcp_ctloutput(int op, struct socket *so,
> break;
>
> case PRCO_GETOPT:
> - *mp = m = m_get(M_WAIT, MT_SOOPTS);
> + m = mp;
> m->m_len = sizeof(int);
>
> switch (optname) {
> Index: netinet/tcp_var.h
> ===================================================================
> RCS file: /cvs/src/sys/netinet/tcp_var.h,v
> retrieving revision 1.120
> diff -u -p -r1.120 tcp_var.h
> --- netinet/tcp_var.h 29 Jan 2017 19:58:47 -0000 1.120
> +++ netinet/tcp_var.h 31 Jan 2017 17:09:43 -0000
> @@ -602,7 +602,7 @@ int tcp_freeq(struct tcpcb *);
> void tcp6_ctlinput(int, struct sockaddr *, u_int, void *);
> #endif
> void tcp_ctlinput(int, struct sockaddr *, u_int, void *);
> -int tcp_ctloutput(int, struct socket *, int, int, struct mbuf **);
> +int tcp_ctloutput(int, struct socket *, int, int, struct mbuf *);
> struct tcpcb *
> tcp_disconnect(struct tcpcb *);
> struct tcpcb *
> Index: netinet6/icmp6.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet6/icmp6.c,v
> retrieving revision 1.197
> diff -u -p -r1.197 icmp6.c
> --- netinet6/icmp6.c 19 Jan 2017 14:49:19 -0000 1.197
> +++ netinet6/icmp6.c 31 Jan 2017 17:09:43 -0000
> @@ -1802,11 +1802,11 @@ fail:
> */
> int
> icmp6_ctloutput(int op, struct socket *so, int level, int optname,
> - struct mbuf **mp)
> + struct mbuf *mp)
> {
> int error = 0;
> struct inpcb *in6p = sotoinpcb(so);
> - struct mbuf *m = *mp;
> + struct mbuf *m = mp;
>
> if (level != IPPROTO_ICMPV6) {
> if (op == PRCO_SETOPT)
> @@ -1853,7 +1853,6 @@ icmp6_ctloutput(int op, struct socket *s
> error = EINVAL;
> break;
> }
> - *mp = m = m_get(M_WAIT, MT_SOOPTS);
> m->m_len = sizeof(struct icmp6_filter);
> p = mtod(m, struct icmp6_filter *);
> bcopy(in6p->inp_icmp6filt, p,
> Index: netinet6/ip6_mroute.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet6/ip6_mroute.c,v
> retrieving revision 1.107
> diff -u -p -r1.107 ip6_mroute.c
> --- netinet6/ip6_mroute.c 6 Jan 2017 10:02:57 -0000 1.107
> +++ netinet6/ip6_mroute.c 31 Jan 2017 17:09:43 -0000
> @@ -245,12 +245,10 @@ ip6_mrouter_set(int cmd, struct socket *
> * Handle MRT getsockopt commands
> */
> int
> -ip6_mrouter_get(int cmd, struct socket *so, struct mbuf **mp)
> +ip6_mrouter_get(int cmd, struct socket *so, struct mbuf *mp)
> {
> if (so != ip6_mrouter)
> return (EPERM);
> -
> - *mp = m_get(M_WAIT, MT_SOOPTS);
>
> switch (cmd) {
> default:
> Index: netinet6/ip6_mroute.h
> ===================================================================
> RCS file: /cvs/src/sys/netinet6/ip6_mroute.h,v
> retrieving revision 1.17
> diff -u -p -r1.17 ip6_mroute.h
> --- netinet6/ip6_mroute.h 22 Dec 2016 11:04:44 -0000 1.17
> +++ netinet6/ip6_mroute.h 31 Jan 2017 17:09:43 -0000
> @@ -247,7 +247,7 @@ struct rtdetq { /* XXX: rtdetq is also
> #define MAX_UPQ6 4 /* max. no of pkts in upcall Q */
>
> int ip6_mrouter_set(int, struct socket *, struct mbuf *);
> -int ip6_mrouter_get(int, struct socket *, struct mbuf **);
> +int ip6_mrouter_get(int, struct socket *, struct mbuf *);
> int ip6_mrouter_done(void);
> void ip6_mrouter_detach(struct ifnet *);
> int mrt6_ioctl(u_long, caddr_t);
> Index: netinet6/ip6_output.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet6/ip6_output.c,v
> retrieving revision 1.222
> diff -u -p -r1.222 ip6_output.c
> --- netinet6/ip6_output.c 27 Jan 2017 02:55:36 -0000 1.222
> +++ netinet6/ip6_output.c 31 Jan 2017 17:09:43 -0000
> @@ -117,10 +117,10 @@ struct ip6_exthdrs {
> };
>
> int ip6_pcbopt(int, u_char *, int, struct ip6_pktopts **, int, int);
> -int ip6_getpcbopt(struct ip6_pktopts *, int, struct mbuf **);
> +int ip6_getpcbopt(struct ip6_pktopts *, int, struct mbuf *);
> int ip6_setpktopt(int, u_char *, int, struct ip6_pktopts *, int, int, int);
> int ip6_setmoptions(int, struct ip6_moptions **, struct mbuf *);
> -int ip6_getmoptions(int, struct ip6_moptions *, struct mbuf **);
> +int ip6_getmoptions(int, struct ip6_moptions *, struct mbuf *);
> int ip6_copyexthdr(struct mbuf **, caddr_t, int);
> int ip6_insertfraghdr(struct mbuf *, struct mbuf *, int,
> struct ip6_frag **);
> @@ -1048,12 +1048,12 @@ ip6_getpmtu(struct rtentry *rt, struct i
> */
> int
> ip6_ctloutput(int op, struct socket *so, int level, int optname,
> - struct mbuf **mp)
> + struct mbuf *mp)
> {
> int privileged, optdatalen, uproto;
> void *optdata;
> struct inpcb *inp = sotoinpcb(so);
> - struct mbuf *m = *mp;
> + struct mbuf *m = mp;
> int error, optval;
> struct proc *p = curproc; /* For IPSec and rdomain */
> u_int rtid = 0;
> @@ -1475,7 +1475,6 @@ do { \
> }
> if (error)
> break;
> - *mp = m = m_get(M_WAIT, MT_SOOPTS);
> m->m_len = sizeof(int);
> *mtod(m, int *) = optval;
> break;
> @@ -1515,7 +1514,6 @@ do { \
> optdatalen = sizeof(mtuinfo);
> if (optdatalen > MCLBYTES)
> return (EMSGSIZE); /* XXX */
> - *mp = m = m_get(M_WAIT, MT_SOOPTS);
> if (optdatalen > MLEN)
> MCLGET(m, M_WAIT);
> m->m_len = optdatalen;
> @@ -1552,7 +1550,6 @@ do { \
> case IPV6_ESP_TRANS_LEVEL:
> case IPV6_ESP_NETWORK_LEVEL:
> case IPV6_IPCOMP_LEVEL:
> - *mp = m = m_get(M_WAIT, MT_SOOPTS);
> #ifndef IPSEC
> m->m_len = sizeof(int);
> *mtod(m, int *) = IPSEC_LEVEL_NONE;
> @@ -1581,12 +1578,10 @@ do { \
> #endif
> break;
> case SO_RTABLE:
> - *mp = m = m_get(M_WAIT, MT_SOOPTS);
> m->m_len = sizeof(u_int);
> *mtod(m, u_int *) = optval;
> break;
> case IPV6_PIPEX:
> - *mp = m = m_get(M_WAIT, MT_SOOPTS);
> m->m_len = sizeof(int);
> *mtod(m, int *) = optval;
> break;
> @@ -1600,23 +1595,23 @@ do { \
> } else {
> error = EINVAL;
> if (op == PRCO_SETOPT)
> - (void)m_free(*mp);
> + (void)m_free(mp);
> }
> return (error);
> }
>
> int
> ip6_raw_ctloutput(int op, struct socket *so, int level, int optname,
> - struct mbuf **mp)
> + struct mbuf *mp)
> {
> int error = 0, optval;
> const int icmp6off = offsetof(struct icmp6_hdr, icmp6_cksum);
> struct inpcb *inp = sotoinpcb(so);
> - struct mbuf *m = *mp;
> + struct mbuf *m = mp;
>
> if (level != IPPROTO_IPV6) {
> if (op == PRCO_SETOPT)
> - (void)m_free(*mp);
> + (void)m_free(mp);
> return (EINVAL);
> }
>
> @@ -1653,7 +1648,6 @@ ip6_raw_ctloutput(int op, struct socket
> else
> optval = inp->inp_cksum6;
>
> - *mp = m = m_get(M_WAIT, MT_SOOPTS);
> m->m_len = sizeof(int);
> *mtod(m, int *) = optval;
> break;
> @@ -1682,7 +1676,6 @@ ip6_raw_ctloutput(int op, struct socket
> void
> ip6_initpktopts(struct ip6_pktopts *opt)
> {
> -
> bzero(opt, sizeof(*opt));
> opt->ip6po_hlim = -1; /* -1 means default hop limit */
> opt->ip6po_tclass = -1; /* -1 means default traffic class */
> @@ -1706,7 +1699,7 @@ ip6_pcbopt(int optname, u_char *buf, int
> }
>
> int
> -ip6_getpcbopt(struct ip6_pktopts *pktopt, int optname, struct mbuf **mp)
> +ip6_getpcbopt(struct ip6_pktopts *pktopt, int optname, struct mbuf *mp)
> {
> void *optdata = NULL;
> int optdatalen = 0;
> @@ -1715,7 +1708,7 @@ ip6_getpcbopt(struct ip6_pktopts *pktopt
> struct in6_pktinfo null_pktinfo;
> int deftclass = 0, on;
> int defminmtu = IP6PO_MINMTU_MCASTONLY;
> - struct mbuf *m;
> + struct mbuf *m = mp;
>
> switch (optname) {
> case IPV6_PKTINFO:
> @@ -1787,7 +1780,6 @@ ip6_getpcbopt(struct ip6_pktopts *pktopt
>
> if (optdatalen > MCLBYTES)
> return (EMSGSIZE); /* XXX */
> - *mp = m = m_get(M_WAIT, MT_SOOPTS);
> if (optdatalen > MLEN)
> MCLGET(m, M_WAIT);
> m->m_len = optdatalen;
> @@ -2169,17 +2161,14 @@ ip6_setmoptions(int optname, struct ip6_
> * Return the IP6 multicast options in response to user getsockopt().
> */
> int
> -ip6_getmoptions(int optname, struct ip6_moptions *im6o, struct mbuf **mp)
> +ip6_getmoptions(int optname, struct ip6_moptions *im6o, struct mbuf *mp)
> {
> u_int *hlim, *loop, *ifindex;
>
> - *mp = m_get(M_WAIT, MT_SOOPTS);
> -
> switch (optname) {
> -
> case IPV6_MULTICAST_IF:
> - ifindex = mtod(*mp, u_int *);
> - (*mp)->m_len = sizeof(u_int);
> + ifindex = mtod(mp, u_int *);
> + mp->m_len = sizeof(u_int);
> if (im6o == NULL || im6o->im6o_ifidx == 0)
> *ifindex = 0;
> else
> @@ -2187,8 +2176,8 @@ ip6_getmoptions(int optname, struct ip6_
> return (0);
>
> case IPV6_MULTICAST_HOPS:
> - hlim = mtod(*mp, u_int *);
> - (*mp)->m_len = sizeof(u_int);
> + hlim = mtod(mp, u_int *);
> + mp->m_len = sizeof(u_int);
> if (im6o == NULL)
> *hlim = ip6_defmcasthlim;
> else
> @@ -2196,8 +2185,8 @@ ip6_getmoptions(int optname, struct ip6_
> return (0);
>
> case IPV6_MULTICAST_LOOP:
> - loop = mtod(*mp, u_int *);
> - (*mp)->m_len = sizeof(u_int);
> + loop = mtod(mp, u_int *);
> + mp->m_len = sizeof(u_int);
> if (im6o == NULL)
> *loop = ip6_defmcasthlim;
> else
> Index: netinet6/ip6_var.h
> ===================================================================
> RCS file: /cvs/src/sys/netinet6/ip6_var.h,v
> retrieving revision 1.65
> diff -u -p -r1.65 ip6_var.h
> --- netinet6/ip6_var.h 2 Dec 2016 11:16:04 -0000 1.65
> +++ netinet6/ip6_var.h 31 Jan 2017 17:09:43 -0000
> @@ -241,7 +241,7 @@ extern int ip6_auto_linklocal;
> struct in6pcb;
> struct inpcb;
>
> -int icmp6_ctloutput(int, struct socket *, int, int, struct mbuf **);
> +int icmp6_ctloutput(int, struct socket *, int, int, struct mbuf *);
>
> void ip6_init(void);
> void ip6intr(void);
> @@ -264,8 +264,8 @@ void ip6_mloopback(struct ifnet *, struc
> int ip6_output(struct mbuf *, struct ip6_pktopts *, struct route_in6 *, int,
> struct ip6_moptions *, struct inpcb *);
> int ip6_fragment(struct mbuf *, int, u_char, u_long);
> -int ip6_ctloutput(int, struct socket *, int, int, struct mbuf **);
> -int ip6_raw_ctloutput(int, struct socket *, int, int, struct mbuf **);
> +int ip6_ctloutput(int, struct socket *, int, int, struct mbuf *);
> +int ip6_raw_ctloutput(int, struct socket *, int, int, struct mbuf *);
> void ip6_initpktopts(struct ip6_pktopts *);
> int ip6_setpktopts(struct mbuf *, struct ip6_pktopts *,
> struct ip6_pktopts *, int, int);
> @@ -285,7 +285,7 @@ void frag6_drain(void);
> void rip6_init(void);
> int rip6_input(struct mbuf **mp, int *offp, int proto);
> void rip6_ctlinput(int, struct sockaddr *, u_int, void *);
> -int rip6_ctloutput(int, struct socket *, int, int, struct mbuf **);
> +int rip6_ctloutput(int, struct socket *, int, int, struct mbuf *);
> int rip6_output(struct mbuf *, ...);
> int rip6_usrreq(struct socket *,
> int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *);
> Index: netinet6/raw_ip6.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet6/raw_ip6.c,v
> retrieving revision 1.103
> diff -u -p -r1.103 raw_ip6.c
> --- netinet6/raw_ip6.c 23 Jan 2017 16:31:24 -0000 1.103
> +++ netinet6/raw_ip6.c 31 Jan 2017 17:09:43 -0000
> @@ -474,7 +474,7 @@ rip6_output(struct mbuf *m, ...)
> */
> int
> rip6_ctloutput(int op, struct socket *so, int level, int optname,
> - struct mbuf **mp)
> + struct mbuf *mp)
> {
> struct inpcb *inp = sotoinpcb(so);
> int error = 0;
> @@ -487,11 +487,11 @@ rip6_ctloutput(int op, struct socket *so
> case IP_DIVERTFL:
> switch (op) {
> case PRCO_SETOPT:
> - if (*mp == NULL || (*mp)->m_len < sizeof(int)) {
> + if (mp == NULL || mp->m_len < sizeof(int)) {
> error = EINVAL;
> break;
> }
> - dir = *mtod(*mp, int *);
> + dir = *mtod(mp, int *);
> if (inp->inp_divertfl > 0)
> error = ENOTSUP;
> else if ((dir & IPPROTO_DIVERT_RESP) ||
> @@ -502,9 +502,8 @@ rip6_ctloutput(int op, struct socket *so
> break;
>
> case PRCO_GETOPT:
> - *mp = m_get(M_WAIT, M_SOOPTS);
> - (*mp)->m_len = sizeof(int);
> - *mtod(*mp, int *) = inp->inp_divertfl;
> + mp->m_len = sizeof(int);
> + *mtod(mp, int *) = inp->inp_divertfl;
> break;
>
> default:
> @@ -513,7 +512,7 @@ rip6_ctloutput(int op, struct socket *so
> }
>
> if (op == PRCO_SETOPT)
> - (void)m_free(*mp);
> + (void)m_free(mp);
> return (error);
>
> #ifdef MROUTING
> @@ -524,8 +523,8 @@ rip6_ctloutput(int op, struct socket *so
> case MRT6_ADD_MFC:
> case MRT6_DEL_MFC:
> if (op == PRCO_SETOPT) {
> - error = ip6_mrouter_set(optname, so, *mp);
> - m_free(*mp);
> + error = ip6_mrouter_set(optname, so, mp);
> + m_free(mp);
> } else if (op == PRCO_GETOPT)
> error = ip6_mrouter_get(optname, so, mp);
> else
> @@ -547,7 +546,7 @@ rip6_ctloutput(int op, struct socket *so
>
> default:
> if (op == PRCO_SETOPT)
> - m_free(*mp);
> + m_free(mp);
> return EINVAL;
> }
> }
> Index: sys/protosw.h
> ===================================================================
> RCS file: /cvs/src/sys/sys/protosw.h,v
> retrieving revision 1.21
> diff -u -p -r1.21 protosw.h
> --- sys/protosw.h 29 Jan 2017 19:58:47 -0000 1.21
> +++ sys/protosw.h 31 Jan 2017 17:09:43 -0000
> @@ -75,7 +75,7 @@ struct protosw {
> /* control input (from below) */
> void (*pr_ctlinput)(int, struct sockaddr *, u_int, void *);
> /* control output (from above) */
> - int (*pr_ctloutput)(int, struct socket *, int, int, struct mbuf **);
> + int (*pr_ctloutput)(int, struct socket *, int, int, struct mbuf *);
>
> /* user-protocol hook */
> /* user request: see list below */