On Tue, May 08, 2018 at 11:08:28AM +0200, Martin Pieuchot wrote:
> Diff below factorizes some bits of route_input() into rtm_sendup(), a
> function similar to pfkey_sendup(). Both functions will need the same
> MP-safeness love, so it makes sense to reduce differences.
>
> Ok?
OK bluhm@
> Index: net/pfkeyv2.c
> ===================================================================
> RCS file: /cvs/src/sys/net/pfkeyv2.c,v
> retrieving revision 1.176
> diff -u -p -r1.176 pfkeyv2.c
> --- net/pfkeyv2.c 19 Feb 2018 08:59:52 -0000 1.176
> +++ net/pfkeyv2.c 8 May 2018 09:05:04 -0000
> @@ -332,21 +332,21 @@ ret:
> }
>
> int
> -pfkey_sendup(struct keycb *kp, struct mbuf *packet, int more)
> +pfkey_sendup(struct keycb *kp, struct mbuf *m0, int more)
> {
> struct socket *so = kp->rcb.rcb_socket;
> - struct mbuf *packet2;
> + struct mbuf *m;
>
> NET_ASSERT_LOCKED();
>
> if (more) {
> - if (!(packet2 = m_dup_pkt(packet, 0, M_DONTWAIT)))
> + if (!(m = m_dup_pkt(m0, 0, M_DONTWAIT)))
> return (ENOMEM);
> } else
> - packet2 = packet;
> + m = m0;
>
> - if (!sbappendaddr(so, &so->so_rcv, &pfkey_addr, packet2, NULL)) {
> - m_freem(packet2);
> + if (!sbappendaddr(so, &so->so_rcv, &pfkey_addr, m, NULL)) {
> + m_freem(m);
> return (ENOBUFS);
> }
>
> Index: net/rtsock.c
> ===================================================================
> RCS file: /cvs/src/sys/net/rtsock.c,v
> retrieving revision 1.263
> diff -u -p -r1.263 rtsock.c
> --- net/rtsock.c 24 Apr 2018 06:19:47 -0000 1.263
> +++ net/rtsock.c 7 May 2018 21:44:19 -0000
> @@ -113,7 +113,8 @@ int route_usrreq(struct socket *, int, s
> void route_input(struct mbuf *m0, struct socket *, sa_family_t);
> int route_arp_conflict(struct rtentry *, struct rt_addrinfo *);
> int route_cleargateway(struct rtentry *, void *, unsigned int);
> -void route_senddesync(void *);
> +void rtm_senddesync(void *);
> +int rtm_sendup(struct socket *, struct mbuf *, int);
>
> int rtm_getifa(struct rt_addrinfo *, unsigned int);
> int rtm_output(struct rt_msghdr *, struct rtentry **, struct rt_addrinfo *,
> @@ -240,7 +241,7 @@ route_attach(struct socket *so, int prot
> rp = &rop->rcb;
> so->so_pcb = rop;
> /* Init the timeout structure */
> - timeout_set(&rop->timeout, route_senddesync, rop);
> + timeout_set(&rop->timeout, rtm_senddesync, rop);
> refcnt_init(&rop->refcnt);
>
> if (curproc == NULL)
> @@ -373,7 +374,7 @@ route_ctloutput(int op, struct socket *s
> }
>
> void
> -route_senddesync(void *data)
> +rtm_senddesync(void *data)
> {
> struct routecb *rop;
> struct mbuf *desync_mbuf;
> @@ -479,47 +480,47 @@ route_input(struct mbuf *m0, struct sock
> continue;
>
> if (last) {
> - struct mbuf *n;
> - if ((n = m_copym(m, 0, M_COPYALL, M_NOWAIT)) != NULL) {
> - if (sbspace(last, &last->so_rcv) < (2*MSIZE) ||
> - sbappendaddr(last, &last->so_rcv,
> - &route_src, n, (struct mbuf *)NULL) == 0) {
> - /*
> - * Flag socket as desync'ed and
> - * flush required
> - */
> - sotoroutecb(last)->flags |=
> - ROUTECB_FLAG_DESYNC |
> - ROUTECB_FLAG_FLUSH;
> - route_senddesync(sotoroutecb(last));
> - m_freem(n);
> - } else {
> - sorwakeup(last);
> - }
> - }
> + rtm_sendup(last, m, 1);
> refcnt_rele_wake(&sotoroutecb(last)->refcnt);
> }
> /* keep a reference for last */
> refcnt_take(&rop->refcnt);
> last = rop->rcb.rcb_socket;
> }
> +
> if (last) {
> - if (sbspace(last, &last->so_rcv) < (2 * MSIZE) ||
> - sbappendaddr(last, &last->so_rcv, &route_src,
> - m, (struct mbuf *)NULL) == 0) {
> - /* Flag socket as desync'ed and flush required */
> - sotoroutecb(last)->flags |=
> - ROUTECB_FLAG_DESYNC | ROUTECB_FLAG_FLUSH;
> - route_senddesync(sotoroutecb(last));
> - m_freem(m);
> - } else {
> - sorwakeup(last);
> - }
> + rtm_sendup(last, m, 0);
> refcnt_rele_wake(&sotoroutecb(last)->refcnt);
> } else
> m_freem(m);
>
> SRPL_LEAVE(&sr);
> +}
> +
> +int
> +rtm_sendup(struct socket *so, struct mbuf *m0, int more)
> +{
> + struct routecb *rop = sotoroutecb(so);
> + struct mbuf *m;
> +
> + if (more) {
> + m = m_copym(m0, 0, M_COPYALL, M_NOWAIT);
> + if (m == NULL)
> + return (ENOMEM);
> + } else
> + m = m0;
> +
> + if (sbspace(so, &so->so_rcv) < (2 * MSIZE) ||
> + sbappendaddr(so, &so->so_rcv, &route_src, m, NULL) == 0) {
> + /* Flag socket as desync'ed and flush required */
> + rop->flags |= ROUTECB_FLAG_DESYNC | ROUTECB_FLAG_FLUSH;
> + rtm_senddesync(rop);
> + m_freem(m);
> + return (ENOBUFS);
> + }
> +
> + sorwakeup(so);
> + return (0);
> }
>
> struct rt_msghdr *