On 09/07/15(Thu) 09:00, Martin Pieuchot wrote:
> Most of the network interrupt paths are now free from global list
> iterations. The rule I tried to follow is simple. If you already
> have an ifp pointer and need a per-ifp resource use it, otherwise
> do a route lookup.
>
> Diff below converts one of the few remaining iteration on the global
> list of interfaces (&ifnet).
>
> Tests and oks are welcome.
Anybody?
> Index: netinet/ip_ipip.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet/ip_ipip.c,v
> retrieving revision 1.60
> diff -u -p -r1.60 ip_ipip.c
> --- netinet/ip_ipip.c 16 Jun 2015 11:09:40 -0000 1.60
> +++ netinet/ip_ipip.c 9 Jul 2015 06:52:35 -0000
> @@ -145,11 +145,8 @@ void
> ipip_input(struct mbuf *m, int iphlen, struct ifnet *gifp, int proto)
> {
> struct sockaddr_in *sin;
> - struct ifnet *ifp;
> - struct ifaddr *ifa;
> struct niqueue *ifq = NULL;
> struct ip *ipo;
> - u_int rdomain;
> #ifdef INET6
> struct sockaddr_in6 *sin6;
> struct ip6_hdr *ip6;
> @@ -295,45 +292,33 @@ ipip_input(struct mbuf *m, int iphlen, s
> }
>
> /* Check for local address spoofing. */
> - if (((ifp = if_get(m->m_pkthdr.ph_ifidx)) == NULL ||
> - !(ifp->if_flags & IFF_LOOPBACK)) && ipip_allow != 2) {
> - rdomain = rtable_l2(m->m_pkthdr.ph_rtableid);
> - TAILQ_FOREACH(ifp, &ifnet, if_list) {
> - if (ifp->if_rdomain != rdomain)
> - continue;
> - TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) {
> - if (ipo) {
> - if (ifa->ifa_addr->sa_family !=
> - AF_INET)
> - continue;
> -
> - sin = (struct sockaddr_in *)
> - ifa->ifa_addr;
> - if (sin->sin_addr.s_addr ==
> - ipo->ip_src.s_addr) {
> - ipipstat.ipips_spoof++;
> - m_freem(m);
> - return;
> - }
> - }
> -#ifdef INET6
> - if (ip6) {
> - if (ifa->ifa_addr->sa_family !=
> - AF_INET6)
> - continue;
> -
> - sin6 = (struct sockaddr_in6 *)
> - ifa->ifa_addr;
> - if (IN6_ARE_ADDR_EQUAL(&sin6->sin6_addr,
> - &ip6->ip6_src)) {
> - ipipstat.ipips_spoof++;
> - m_freem(m);
> - return;
> - }
> -
> - }
> + if (ipip_allow != 2) {
> + struct sockaddr_storage ss;
> + struct rtentry *rt;
> +
> + if (ipo) {
> + sin = (struct sockaddr_in *)&ss;
> + sin->sin_family = AF_INET;
> + sin->sin_len = sizeof(*sin);
> + sin->sin_addr = ipo->ip_src;
> +#ifdef INET6
> + } else if (ip6) {
> + sin6 = (struct sockaddr_in6 *)&ss;
> + sin6->sin6_family = AF_INET6;
> + sin6->sin6_len = sizeof(*sin6);
> + sin6->sin6_addr = ip6->ip6_src;
> #endif /* INET6 */
> + }
> + rt = rtalloc((struct sockaddr *)&ss, 0,
> + m->m_pkthdr.ph_rtableid);
> + if (rt != NULL) {
> + if (rt->rt_flags & RTF_LOCAL) {
> + ipipstat.ipips_spoof++;
> + m_freem(m);
> + rtfree(rt);
> + return;
> }
> + rtfree(rt);
> }
> }
>
>