Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 29 Jul 2015 15:00:59 +0200
From:      =?UTF-8?Q?Ermal_Lu=C3=A7i?= <eri@freebsd.org>
To:        Gleb Smirnoff <glebius@freebsd.org>
Cc:        =?UTF-8?Q?Olivier_Cochard=2DLabb=C3=A9?= <olivier@cochard.me>,  src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   Re: svn commit: r285051 - head/sys/netinet
Message-ID:  <CAPBZQG3owDM4y4noEa9S044MPuw89QZnkG6Ne7y94iBERp37Pg@mail.gmail.com>
In-Reply-To: <20150728124220.GW72729@FreeBSD.org>
References:  <201507021810.t62IAgCc003272@repo.freebsd.org> <20150728124220.GW72729@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Jul 28, 2015 at 2:42 PM, Gleb Smirnoff <glebius@freebsd.org> wrote:

>   Ermal,
>
>   see comments inlined,
>
> On Thu, Jul 02, 2015 at 06:10:42PM +0000, Ermal Lu=C3=A7i wrote:
> E> Author: eri
> E> Date: Thu Jul  2 18:10:41 2015
> E> New Revision: 285051
> E> URL: https://svnweb.freebsd.org/changeset/base/285051
> E>
> E> Log:
> E>   Avoid doing multiple route lookups for the same destination IP durin=
g
> forwarding
> E>
> E>   ip_forward() does a route lookup for testing this packet can be sent
> to a known destination,
> E>   it also can do another route lookup if it detects that an ICMP
> redirect is needed,
> E>   it forgets all of this and handovers to ip_output() to do the same
> lookup yet again.
> E>
> E>   This optimisation just does one route lookup during the forwarding
> path and handovers that to be considered by ip_output().
> E>
> E>   Differential Revision:     https://reviews.freebsd.org/D2964
> E>   Approved by:       ae, gnn(mentor)
> E>   MFC after: 1 week
> E>
> E> Modified:
> E>   head/sys/netinet/ip_input.c
> E>
> E> Modified: head/sys/netinet/ip_input.c
> E>
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
> E> --- head/sys/netinet/ip_input.c      Thu Jul  2 17:30:59 2015
> (r285050)
> E> +++ head/sys/netinet/ip_input.c      Thu Jul  2 18:10:41 2015
> (r285051)
> E> @@ -897,6 +897,7 @@ ip_forward(struct mbuf *m, int srcrt)
> E>      struct ip *ip =3D mtod(m, struct ip *);
> E>      struct in_ifaddr *ia;
> E>      struct mbuf *mcopy;
> E> +    struct sockaddr_in *sin;
> E>      struct in_addr dest;
> E>      struct route ro;
> E>      int error, type =3D 0, code =3D 0, mtu =3D 0;
> E> @@ -925,7 +926,22 @@ ip_forward(struct mbuf *m, int srcrt)
> E>      }
> E>  #endif
> E>
> E> -    ia =3D ip_rtaddr(ip->ip_dst, M_GETFIB(m));
> E> +    bzero(&ro, sizeof(ro));
> E> +    sin =3D (struct sockaddr_in *)&ro.ro_dst;
> E> +    sin->sin_family =3D AF_INET;
> E> +    sin->sin_len =3D sizeof(*sin);
> E> +    sin->sin_addr =3D ip->ip_dst;
> E> +#ifdef RADIX_MPATH
> E> +    rtalloc_mpath_fib(&ro,
> E> +        ntohl(ip->ip_src.s_addr ^ ip->ip_dst.s_addr),
> E> +        M_GETFIB(m));
> E> +#else
> E> +    in_rtalloc_ign(&ro, 0, M_GETFIB(m));
> E> +#endif
> E> +    if (ro.ro_rt !=3D NULL) {
> E> +            ia =3D ifatoia(ro.ro_rt->rt_ifa);
> E> +            ifa_ref(&ia->ia_ifa);
> E> +    }
> E>  #ifndef IPSEC
> E>      /*
> E>       * 'ia' may be NULL if there is no route for this destination.
> E> @@ -934,6 +950,7 @@ ip_forward(struct mbuf *m, int srcrt)
> E>       */
> E>      if (!srcrt && ia =3D=3D NULL) {
> E>              icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_HOST, 0, 0);
> E> +            RO_RTFREE(&ro);
> E>              return;
> E>      }
>
> Here the ifa reference is leaked upon return.
>
>
Gleb,

the improvement on the ifa_ref not needed is something to look at but the
ifa_ref here is not lost since ia =3D=3D NULL, no?

Maybe i am missing something else.
Also can we put this on a review?


>
> But don't hurry with fixing that :) Actually you don't need to ifa_ref()
> in this function. You acquired a reference on rtentry in in_rtalloc_ign()
> and hold it until RO_RTFREE(). And the rtentry itself always holds a
> reference on the ifa. So, there is no reason to put extra reference on
> the ifa.
>
> The ip_output() was already improved in r262747. And ip_forward() can
> also be. The only place that touches ia after RO_RTFREE() is EMSGSIZE
> handling, this can be moved up before RO_RTFREE().
>
> Here is suggested patch. Ermal and Oliver, can you please test/benchmark
> it?
>
> --
> Totus tuus, Glebius.
>



--=20
Ermal



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAPBZQG3owDM4y4noEa9S044MPuw89QZnkG6Ne7y94iBERp37Pg>