Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Replace ifp of ip_moptions and ip6_moptions with if_index



details:   https://anonhg.NetBSD.org/src/rev/e430aef1264c
branches:  trunk
changeset: 346054:e430aef1264c
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Tue Jun 21 03:28:27 2016 +0000

description:
Replace ifp of ip_moptions and ip6_moptions with if_index

The motivation is the same as the mbuf's rcvif case; avoid having a pointer
of an ifnet object in ip_moptions and ip6_moptions, which is not MP-safe.

ip_moptions and ip6_moptions can be stored in a PCB for inet or inet6
that's life time is different from ifnet one and so an ifnet object can be
disappeared anytime we get it via them. Thus we need to look up an ifnet
object by if_index every time for safe.

diffstat:

 sys/dist/pf/net/if_pfsync.c |  10 +++++-----
 sys/net/if.h                |   9 ++++++++-
 sys/netinet/igmp.c          |   6 +++---
 sys/netinet/in.c            |  21 ++++++++++++++-------
 sys/netinet/in_pcb.c        |  10 ++++++----
 sys/netinet/ip_carp.c       |  12 ++++++------
 sys/netinet/ip_mroute.c     |   6 +++---
 sys/netinet/ip_output.c     |  44 ++++++++++++++++++++++++++++++++------------
 sys/netinet/ip_var.h        |   4 ++--
 sys/netinet6/in6_pcb.c      |  10 ++++++----
 sys/netinet6/in6_src.c      |  12 +++++++-----
 sys/netinet6/ip6_mroute.c   |   6 +++---
 sys/netinet6/ip6_output.c   |  14 +++++++-------
 sys/netinet6/ip6_var.h      |   4 ++--
 sys/netinet6/mld6.c         |   6 +++---
 sys/netinet6/nd6_nbr.c      |   8 ++++----
 16 files changed, 111 insertions(+), 71 deletions(-)

diffs (truncated from 648 to 300 lines):

diff -r 9bff8575cdd1 -r e430aef1264c sys/dist/pf/net/if_pfsync.c
--- a/sys/dist/pf/net/if_pfsync.c       Tue Jun 21 03:07:54 2016 +0000
+++ b/sys/dist/pf/net/if_pfsync.c       Tue Jun 21 03:28:27 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_pfsync.c,v 1.14 2016/06/10 13:31:44 ozaki-r Exp $   */
+/*     $NetBSD: if_pfsync.c,v 1.15 2016/06/21 03:28:27 ozaki-r Exp $   */
 /*     $OpenBSD: if_pfsync.c,v 1.83 2007/06/26 14:44:12 mcbride Exp $  */
 
 /*
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_pfsync.c,v 1.14 2016/06/10 13:31:44 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_pfsync.c,v 1.15 2016/06/21 03:28:27 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -941,7 +941,7 @@
                        }
                        if (imo->imo_num_memberships > 0) {
                                in_delmulti(imo->imo_membership[--imo->imo_num_memberships]);
-                               imo->imo_multicast_ifp = NULL;
+                               imo->imo_multicast_if_index = 0;
                        }
                        break;
                }
@@ -961,7 +961,7 @@
 
                if (imo->imo_num_memberships > 0) {
                        in_delmulti(imo->imo_membership[--imo->imo_num_memberships]);
-                       imo->imo_multicast_ifp = NULL;
+                       imo->imo_multicast_if_index = 0;
                }
 
                if (sc->sc_sync_ifp &&
@@ -983,7 +983,7 @@
                                return (ENOBUFS);
                        }
                        imo->imo_num_memberships++;
-                       imo->imo_multicast_ifp = sc->sc_sync_ifp;
+                       imo->imo_multicast_if_index = if_get_index(sc->sc_sync_ifp);
                        imo->imo_multicast_ttl = PFSYNC_DFLTTL;
                        imo->imo_multicast_loop = 0;
                }
diff -r 9bff8575cdd1 -r e430aef1264c sys/net/if.h
--- a/sys/net/if.h      Tue Jun 21 03:07:54 2016 +0000
+++ b/sys/net/if.h      Tue Jun 21 03:28:27 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.h,v 1.212 2016/06/21 03:07:54 ozaki-r Exp $ */
+/*     $NetBSD: if.h,v 1.213 2016/06/21 03:28:27 ozaki-r Exp $ */
 
 /*-
  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -954,6 +954,13 @@
 void   if_put(const struct ifnet *, struct psref *);
 void   if_acquire_unsafe(struct ifnet *, struct psref *);
 
+static inline if_index_t
+if_get_index(const struct ifnet *ifp)
+{
+
+       return ifp != NULL ? ifp->if_index : 0;
+}
+
 bool   if_held(struct ifnet *);
 
 void   if_input(struct ifnet *, struct mbuf *);
diff -r 9bff8575cdd1 -r e430aef1264c sys/netinet/igmp.c
--- a/sys/netinet/igmp.c        Tue Jun 21 03:07:54 2016 +0000
+++ b/sys/netinet/igmp.c        Tue Jun 21 03:28:27 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: igmp.c,v 1.58 2016/06/10 13:31:44 ozaki-r Exp $        */
+/*     $NetBSD: igmp.c,v 1.59 2016/06/21 03:28:27 ozaki-r Exp $        */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: igmp.c,v 1.58 2016/06/10 13:31:44 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: igmp.c,v 1.59 2016/06/21 03:28:27 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_mrouting.h"
@@ -618,7 +618,7 @@
        m->m_data -= sizeof(struct ip);
        m->m_len += sizeof(struct ip);
 
-       imo.imo_multicast_ifp = inm->inm_ifp;
+       imo.imo_multicast_if_index = if_get_index(inm->inm_ifp);
        imo.imo_multicast_ttl = 1;
 #ifdef RSVP_ISI
        imo.imo_multicast_vif = -1;
diff -r 9bff8575cdd1 -r e430aef1264c sys/netinet/in.c
--- a/sys/netinet/in.c  Tue Jun 21 03:07:54 2016 +0000
+++ b/sys/netinet/in.c  Tue Jun 21 03:28:27 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in.c,v 1.166 2016/05/27 16:44:15 christos Exp $        */
+/*     $NetBSD: in.c,v 1.167 2016/06/21 03:28:27 ozaki-r Exp $ */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.166 2016/05/27 16:44:15 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.167 2016/06/21 03:28:27 ozaki-r Exp $");
 
 #include "arp.h"
 
@@ -1508,16 +1508,23 @@
         */
        if (IN_MULTICAST(sin->sin_addr.s_addr) && mopts != NULL) {
                struct ip_moptions *imo;
-               struct ifnet *ifp;
 
                imo = mopts;
-               if (imo->imo_multicast_ifp != NULL) {
-                       ifp = imo->imo_multicast_ifp;
-                       IFP_TO_IA(ifp, ia);             /* XXX */
-                       if (ia == 0 || ia->ia4_flags & IN_IFF_NOTREADY) {
+               if (imo->imo_multicast_if_index != 0) {
+                       struct ifnet *ifp;
+                       int s = pserialize_read_enter();
+
+                       ifp = if_byindex(imo->imo_multicast_if_index);
+                       if (ifp != NULL) {
+                               IFP_TO_IA(ifp, ia);             /* XXX */
+                       } else
+                               ia = NULL;
+                       if (ia == NULL || ia->ia4_flags & IN_IFF_NOTREADY) {
+                               pserialize_read_exit(s);
                                *errorp = EADDRNOTAVAIL;
                                return NULL;
                        }
+                       pserialize_read_exit(s);
                }
        }
        if (ia->ia_ifa.ifa_getifa != NULL) {
diff -r 9bff8575cdd1 -r e430aef1264c sys/netinet/in_pcb.c
--- a/sys/netinet/in_pcb.c      Tue Jun 21 03:07:54 2016 +0000
+++ b/sys/netinet/in_pcb.c      Tue Jun 21 03:28:27 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in_pcb.c,v 1.163 2016/02/15 14:59:03 rtr Exp $ */
+/*     $NetBSD: in_pcb.c,v 1.164 2016/06/21 03:28:27 ozaki-r Exp $     */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -93,7 +93,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.163 2016/02/15 14:59:03 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.164 2016/06/21 03:28:27 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -694,6 +694,8 @@
 {
        int i, gap;
 
+       KASSERT(ifp != NULL);
+
        if (imo == NULL)
                return;
 
@@ -701,8 +703,8 @@
         * Unselect the outgoing interface if it is being
         * detached.
         */
-       if (imo->imo_multicast_ifp == ifp)
-               imo->imo_multicast_ifp = NULL;
+       if (imo->imo_multicast_if_index == ifp->if_index)
+               imo->imo_multicast_if_index = 0;
 
        /*
         * Drop multicast group membership if we joined
diff -r 9bff8575cdd1 -r e430aef1264c sys/netinet/ip_carp.c
--- a/sys/netinet/ip_carp.c     Tue Jun 21 03:07:54 2016 +0000
+++ b/sys/netinet/ip_carp.c     Tue Jun 21 03:28:27 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_carp.c,v 1.70 2016/06/20 08:08:13 knakahara Exp $   */
+/*     $NetBSD: ip_carp.c,v 1.71 2016/06/21 03:28:27 ozaki-r Exp $     */
 /*     $OpenBSD: ip_carp.c,v 1.113 2005/11/04 08:11:54 mcbride Exp $   */
 
 /*
@@ -33,7 +33,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 1.70 2016/06/20 08:08:13 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 1.71 2016/06/21 03:28:27 ozaki-r Exp $");
 
 /*
  * TODO:
@@ -1532,7 +1532,7 @@
                }
        }
        imo->imo_num_memberships = 0;
-       imo->imo_multicast_ifp = NULL;
+       imo->imo_multicast_if_index = 0;
 
 #ifdef INET6
        while (!LIST_EMPTY(&im6o->im6o_memberships)) {
@@ -1542,7 +1542,7 @@
                LIST_REMOVE(imm, i6mm_chain);
                in6_leavegroup(imm);
        }
-       im6o->im6o_multicast_ifp = NULL;
+       im6o->im6o_multicast_if_index = 0;
 #endif
 
        /* And any other multicast memberships */
@@ -1801,7 +1801,7 @@
 
        imo->imo_membership[0] = tmpimo.imo_membership[0];
        imo->imo_num_memberships = 1;
-       imo->imo_multicast_ifp = &sc->sc_if;
+       imo->imo_multicast_if_index = sc->sc_if.if_index;
        imo->imo_multicast_ttl = CARP_DFLTTL;
        imo->imo_multicast_loop = 0;
        return (0);
@@ -1909,7 +1909,7 @@
        }
 
        /* apply v6 multicast membership */
-       im6o->im6o_multicast_ifp = &sc->sc_if;
+       im6o->im6o_multicast_if_index = sc->sc_if.if_index;
        if (imm)
                LIST_INSERT_HEAD(&im6o->im6o_memberships, imm,
                    i6mm_chain);
diff -r 9bff8575cdd1 -r e430aef1264c sys/netinet/ip_mroute.c
--- a/sys/netinet/ip_mroute.c   Tue Jun 21 03:07:54 2016 +0000
+++ b/sys/netinet/ip_mroute.c   Tue Jun 21 03:28:27 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_mroute.c,v 1.140 2016/06/10 13:27:16 ozaki-r Exp $  */
+/*     $NetBSD: ip_mroute.c,v 1.141 2016/06/21 03:28:27 ozaki-r Exp $  */
 
 /*
  * Copyright (c) 1992, 1993
@@ -93,7 +93,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.140 2016/06/10 13:27:16 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.141 2016/06/21 03:28:27 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2104,7 +2104,7 @@
                /* if physical interface option, extract the options and then send */
                struct ip_moptions imo;
 
-               imo.imo_multicast_ifp = vifp->v_ifp;
+               imo.imo_multicast_if_index = if_get_index(vifp->v_ifp);
                imo.imo_multicast_ttl = mtod(m, struct ip *)->ip_ttl - 1;
                imo.imo_multicast_loop = 1;
 #ifdef RSVP_ISI
diff -r 9bff8575cdd1 -r e430aef1264c sys/netinet/ip_output.c
--- a/sys/netinet/ip_output.c   Tue Jun 21 03:07:54 2016 +0000
+++ b/sys/netinet/ip_output.c   Tue Jun 21 03:28:27 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_output.c,v 1.257 2016/06/20 06:46:38 knakahara Exp $        */
+/*     $NetBSD: ip_output.c,v 1.258 2016/06/21 03:28:27 ozaki-r Exp $  */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.257 2016/06/20 06:46:38 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.258 2016/06/21 03:28:27 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -229,7 +229,7 @@
 {
        struct rtentry *rt;
        struct ip *ip;
-       struct ifnet *ifp;
+       struct ifnet *ifp, *mifp = NULL;
        struct mbuf *m = m0;
        int hlen = sizeof (struct ip);
        int len, error = 0;
@@ -251,6 +251,8 @@
        struct sockaddr *rdst = &u.dst; /* real IP destination, as opposed
                                         * to the nexthop
                                         */
+       struct psref psref;
+       int bound;
 
        len = 0;
 
@@ -324,8 +326,15 @@
                isbroadcast = in_broadcast(dst->sin_addr, ifp);
        } else if ((IN_MULTICAST(ip->ip_dst.s_addr) ||



Home | Main Index | Thread Index | Old Index