Source-Changes-HG archive

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

[src/trunk]: src/sys/net Add a mutex for global variables of if_ethersubr.c



details:   https://anonhg.NetBSD.org/src/rev/1a62b49a38aa
branches:  trunk
changeset: 797806:1a62b49a38aa
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Mon Jul 28 14:24:48 2014 +0000

description:
Add a mutex for global variables of if_ethersubr.c

To initialize the mutex, we introduce etherinit that is called from ifinit1.

diffstat:

 sys/net/if.c           |   6 ++++--
 sys/net/if_ether.h     |   3 ++-
 sys/net/if_ethersubr.c |  13 +++++++++++--
 3 files changed, 17 insertions(+), 5 deletions(-)

diffs (94 lines):

diff -r c0d0a220d87a -r 1a62b49a38aa sys/net/if.c
--- a/sys/net/if.c      Mon Jul 28 12:59:39 2014 +0000
+++ b/sys/net/if.c      Mon Jul 28 14:24:48 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.c,v 1.285 2014/07/01 10:16:02 ozaki-r Exp $ */
+/*     $NetBSD: if.c,v 1.286 2014/07/28 14:24:48 ozaki-r Exp $ */
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.285 2014/07/01 10:16:02 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.286 2014/07/28 14:24:48 ozaki-r Exp $");
 
 #include "opt_inet.h"
 
@@ -252,6 +252,8 @@
 
        if_pfil = pfil_head_create(PFIL_TYPE_IFNET, NULL);
        KASSERT(if_pfil != NULL);
+
+       etherinit();
 }
 
 ifnet_t *
diff -r c0d0a220d87a -r 1a62b49a38aa sys/net/if_ether.h
--- a/sys/net/if_ether.h        Mon Jul 28 12:59:39 2014 +0000
+++ b/sys/net/if_ether.h        Mon Jul 28 14:24:48 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ether.h,v 1.63 2014/06/10 09:38:30 joerg Exp $      */
+/*     $NetBSD: if_ether.h,v 1.64 2014/07/28 14:24:48 ozaki-r Exp $    */
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -324,6 +324,7 @@
 /* test if any VLAN is configured for this interface */
 #define VLAN_ATTACHED(ec)      ((ec)->ec_nvlans > 0)
 
+void   etherinit(void);
 void   ether_ifattach(struct ifnet *, const uint8_t *);
 void   ether_ifdetach(struct ifnet *);
 int    ether_mediachange(struct ifnet *);
diff -r c0d0a220d87a -r 1a62b49a38aa sys/net/if_ethersubr.c
--- a/sys/net/if_ethersubr.c    Mon Jul 28 12:59:39 2014 +0000
+++ b/sys/net/if_ethersubr.c    Mon Jul 28 14:24:48 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ethersubr.c,v 1.202 2014/06/30 10:03:41 ozaki-r Exp $       */
+/*     $NetBSD: if_ethersubr.c,v 1.203 2014/07/28 14:24:48 ozaki-r Exp $       */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.202 2014/06/30 10:03:41 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.203 2014/07/28 14:24:48 ozaki-r Exp $");
 
 #include "opt_inet.h"
 #include "opt_atalk.h"
@@ -175,6 +175,7 @@
 static struct timeval bigpktppslim_last;
 static int bigpktppslim = 2;   /* XXX */
 static int bigpktpps_count;
+static kmutex_t bigpktpps_lock __cacheline_aligned;
 
 
 const uint8_t etherbroadcastaddr[ETHER_ADDR_LEN] =
@@ -603,11 +604,13 @@
         */
        if (etype != ETHERTYPE_MPLS && m->m_pkthdr.len >
            ETHER_MAX_FRAME(ifp, etype, m->m_flags & M_HASFCS)) {
+               mutex_enter(&bigpktpps_lock);
                if (ppsratecheck(&bigpktppslim_last, &bigpktpps_count,
                            bigpktppslim)) {
                        printf("%s: discarding oversize frame (len=%d)\n",
                            ifp->if_xname, m->m_pkthdr.len);
                }
+               mutex_exit(&bigpktpps_lock);
                m_freem(m);
                return;
        }
@@ -1532,3 +1535,9 @@
                       ether_multicast_sysctl, 0, NULL, 0,
                       CTL_CREATE, CTL_EOL);
 }
+
+void
+etherinit(void)
+{
+       mutex_init(&bigpktpps_lock, MUTEX_DEFAULT, IPL_NET);
+}



Home | Main Index | Thread Index | Old Index