Source-Changes-HG archive

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

[src/trunk]: src/sys/netinet Proper MBUFTRACE handling. Without it, ec_tx_mow...



details:   https://anonhg.NetBSD.org/src/rev/26640fee34be
branches:  trunk
changeset: 328483:26640fee34be
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Fri Apr 04 12:53:04 2014 +0000

description:
Proper MBUFTRACE handling. Without it, ec_tx_mowner, ec_rx_mowner and
ifp->if_mowner would be used uninitialised.

diffstat:

 sys/netinet/ip_carp.c |  35 +++++++++++++++++++++++++++++++++--
 1 files changed, 33 insertions(+), 2 deletions(-)

diffs (100 lines):

diff -r c1f320537de8 -r 26640fee34be sys/netinet/ip_carp.c
--- a/sys/netinet/ip_carp.c     Fri Apr 04 12:45:59 2014 +0000
+++ b/sys/netinet/ip_carp.c     Fri Apr 04 12:53:04 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_carp.c,v 1.52 2014/02/25 18:30:12 pooka Exp $       */
+/*     $NetBSD: ip_carp.c,v 1.53 2014/04/04 12:53:04 bouyer Exp $      */
 /*     $OpenBSD: ip_carp.c,v 1.113 2005/11/04 08:11:54 mcbride Exp $   */
 
 /*
@@ -28,9 +28,10 @@
  */
 
 #include "opt_inet.h"
+#include "opt_mbuftrace.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 1.52 2014/02/25 18:30:12 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 1.53 2014/04/04 12:53:04 bouyer Exp $");
 
 /*
  * TODO:
@@ -159,6 +160,13 @@
 
 #define        CARP_STATINC(x)         _NET_STATINC(carpstat_percpu, x)
 
+#ifdef MBUFTRACE
+static struct mowner carp_proto_mowner_rx = MOWNER_INIT("carp", "rx");
+static struct mowner carp_proto_mowner_tx = MOWNER_INIT("carp", "tx");
+static struct mowner carp_proto6_mowner_rx = MOWNER_INIT("carp6", "rx");
+static struct mowner carp_proto6_mowner_tx = MOWNER_INIT("carp6", "tx");
+#endif
+
 struct carp_if {
        TAILQ_HEAD(, carp_softc) vhif_vrs;
        int vhif_nvrs;
@@ -464,6 +472,7 @@
        va_end(ap);
 
        CARP_STATINC(CARP_STAT_IPACKETS);
+       MCLAIM(m, &carp_proto_mowner_rx);
 
        if (!carp_opts[CARPCTL_ALLOW]) {
                m_freem(m);
@@ -533,6 +542,7 @@
        u_int len;
 
        CARP_STATINC(CARP_STAT_IPACKETS6);
+       MCLAIM(m, &carp_proto6_mowner_rx);
 
        if (!carp_opts[CARPCTL_ALLOW]) {
                m_freem(m);
@@ -801,6 +811,19 @@
        carp_set_enaddr(sc);
        LIST_INIT(&sc->sc_ac.ec_multiaddrs);
        bpf_attach(ifp, DLT_EN10MB, ETHER_HDR_LEN);
+#ifdef MBUFTRACE
+       strlcpy(sc->sc_ac.ec_tx_mowner.mo_name, ifp->if_xname,
+           sizeof(sc->sc_ac.ec_tx_mowner.mo_name));
+       strlcpy(sc->sc_ac.ec_tx_mowner.mo_descr, "tx",
+           sizeof(sc->sc_ac.ec_tx_mowner.mo_descr));
+       strlcpy(sc->sc_ac.ec_rx_mowner.mo_name, ifp->if_xname,
+           sizeof(sc->sc_ac.ec_rx_mowner.mo_name));
+       strlcpy(sc->sc_ac.ec_rx_mowner.mo_descr, "rx",
+           sizeof(sc->sc_ac.ec_rx_mowner.mo_descr));
+       MOWNER_ATTACH(&sc->sc_ac.ec_tx_mowner);
+       MOWNER_ATTACH(&sc->sc_ac.ec_rx_mowner);
+       ifp->if_mowner = &sc->sc_ac.ec_tx_mowner;
+#endif
        return (0);
 }
 
@@ -966,6 +989,7 @@
                        /* XXX maybe less ? */
                        goto retry_later;
                }
+               MCLAIM(m, &carp_proto_mowner_tx);
                len = sizeof(*ip) + sizeof(ch);
                m->m_pkthdr.len = len;
                m->m_pkthdr.rcvif = NULL;
@@ -1046,6 +1070,7 @@
                        /* XXX maybe less ? */
                        goto retry_later;
                }
+               MCLAIM(m, &carp_proto6_mowner_tx);
                len = sizeof(*ip6) + sizeof(ch);
                m->m_pkthdr.len = len;
                m->m_pkthdr.rcvif = NULL;
@@ -2250,6 +2275,12 @@
 {
 
        sysctl_net_inet_carp_setup(NULL);
+#ifdef MBUFTRACE
+       MOWNER_ATTACH(&carp_proto_mowner_rx);
+       MOWNER_ATTACH(&carp_proto_mowner_tx);
+       MOWNER_ATTACH(&carp_proto6_mowner_rx);
+       MOWNER_ATTACH(&carp_proto6_mowner_tx);
+#endif
 }
 
 static void



Home | Main Index | Thread Index | Old Index