Subject: kern/1825: miscellanous if_arcsubr.c cleanup
To: None <gnats-bugs@gnats.netbsd.org>
From: Ignatios Souvatzis <is@beverly.rhein.de>
List: netbsd-bugs
Date: 12/07/1995 13:30:24
>Number:         1825
>Category:       kern
>Synopsis:       miscellanous if_arcsubr.c cleanup and optimizations
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    kern-bug-people (Kernel Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Thu Dec  7 19:35:02 1995
>Last-Modified:
>Originator:     Ignatios Souvatzis
>Organization:
	me, myself and I
>Release:        1.1
>Environment:
	
System: NetBSD beverly.rhein.de 1.1 NetBSD 1.1 (BEVERLY) #: Thu Dec 7 12:56:53 GMT 1995 is@beverly.rhein.de:/usr/src/sys/arch/amiga/compile/BEVERLY amiga


>Description:
	These are a few code style cleanups (to make it -Wall-proof) and 
	a bunch of optimizations by Charles M. Hannum, which I had proofread,
	corrected for an oversight and hm... somehow forgot to submit months ago?
>How-To-Repeat:
	Look at the code, scratch your head and wonder, how NetBSD-ARCnet handling got
	this fast even without the patch.
>Fix:


--- /usr/local/NetBSD-1.1/source/usr/src//sys/net/if_arcsubr.c	Sat Oct 14 02:49:18 1995
+++ if_arcsubr.c	Thu Dec  7 10:47:28 1995
@@ -43,9 +43,11 @@
 #include <sys/kernel.h>
 #include <sys/malloc.h>
 #include <sys/mbuf.h>
+#include <sys/protosw.h>
 #include <sys/socket.h>
-#include <sys/syslog.h>
+#include <sys/ioctl.h>
 #include <sys/errno.h>
+#include <sys/syslog.h>
 
 #include <machine/cpu.h>
 
@@ -65,8 +67,6 @@
 #define	ARC_PHDSMTU	1500
 #endif
 
-/* why isnt this in /sys/sys/mbuf.h?? */
-extern struct mbuf *m_split __P((struct mbuf *, int, int));
 static struct mbuf *arc_defrag __P((struct ifnet *, struct mbuf *));
 
 /*
@@ -100,24 +100,22 @@
 	struct rtentry		*rt;
 	struct arccom		*ac;
 	register struct arc_header *ah;
-	int			off, len;
 	int			s, error, newencoding;
 	u_int8_t		atype, adst;
 	int			tfrags, sflag, fsflag, rsflag;
 
-	if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
+	if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) 
 		senderr(ENETDOWN);
 
 	error = newencoding = 0;
 	ac = (struct arccom *)ifp;
 	m = m0;
-	len = m->m_pkthdr.len;
 	mcopy = m1 = NULL;
 
 	ifp->if_lastchange = time;
-	if (rt = rt0) {
+	if ((rt = rt0)) {
 		if ((rt->rt_flags & RTF_UP) == 0) {
-			if (rt0 = rt = rtalloc1(dst, 1))
+			if ((rt0 = rt = rtalloc1(dst, 1)))
 				rt->rt_refcnt--;
 			else 
 				senderr(EHOSTUNREACH);
@@ -153,7 +151,6 @@
 		/* If broadcasting on a simplex interface, loopback a copy */
 		if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX))
 			mcopy = m_copy(m, 0, (int)M_COPYALL);
-		off = m->m_pkthdr.len - m->m_len;
 		if (ifp->if_flags & IFF_LINK0) {
 			atype = ARCTYPE_IP;
 			newencoding = 1;
@@ -191,8 +188,8 @@
 	if (newencoding) {
 		++ac->ac_seqid; /* make the seqid unique */
 
-		tfrags = (len + 503) / 504;
-		fsflag = 2*tfrags-3;
+		tfrags = (m->m_pkthdr.len + 503) / 504;
+		fsflag = 2 * tfrags - 3;
 		sflag = 0;
 		rsflag = fsflag;
 
@@ -205,10 +202,6 @@
 			M_PREPEND(m, ARC_HDRNEWLEN, M_DONTWAIT);
 			if (m == 0)
 				senderr(ENOBUFS);
-			m = m_pullup(m,ARC_HDRNEWLEN);
-			if (m == 0)
-				senderr(ENOBUFS);
-
 			ah = mtod(m, struct arc_header *);
 			ah->arc_type = atype;
 			ah->arc_dhost = adst;
@@ -226,16 +219,13 @@
 				splx(s);
 				senderr(ENOBUFS);
 			}
+			ifp->if_obytes += m->m_pkthdr.len;
 			IF_ENQUEUE(&ifp->if_snd, m);
 			if ((ifp->if_flags & IFF_OACTIVE) == 0)
 				(*ifp->if_start)(ifp);
 			splx(s);
 	
-			/* we don't count the hardwares lenght bytes here */
-			ifp->if_obytes += 504 + ARC_HDRNEWLEN;
-
 			m = m1;
-			len -= 504;
 			sflag += 2;
 			rsflag = sflag;
 		}
@@ -244,80 +234,55 @@
 		M_PREPEND(m, ARC_HDRNEWLEN, M_DONTWAIT);
 		if (m == 0)
 			senderr(ENOBUFS);
-		m = m_pullup(m, ARC_HDRNEWLEN);
-		if (m == 0)
-			senderr(ENOBUFS);
-
 		ah = mtod(m, struct arc_header *);
 		ah->arc_type = atype;
 		ah->arc_flag = sflag;
-		ah->arc_seqid= ac->ac_seqid;
+		ah->arc_seqid = ac->ac_seqid;
 
 		/* here we can have small, especially forbidden packets */
 
-		if ((len >= ARC_MIN_FORBID_LEN - ARC_HDRNEWLEN + 2) &&
-		    (len <= ARC_MAX_FORBID_LEN - ARC_HDRNEWLEN + 2)) {
-
+		if ((m->m_pkthdr.len >= ARC_MIN_FORBID_LEN + 2) &&
+		    (m->m_pkthdr.len <= ARC_MAX_FORBID_LEN + 2)) {
 			M_PREPEND(m, 4, M_DONTWAIT);
 			if (m == 0)
 				senderr(ENOBUFS);
-				
 			m = m_pullup(m, ARC_HDRNEWLEN);
 			if (m == 0)
 				senderr(ENOBUFS);
-
 			ah = mtod(m, struct arc_header *);
 			ah->arc_type = atype;
 			ah->arc_flag = 0xFF;
-			ah->arc_seqid= 0xFFFF;
-			len += 4;
+			ah->arc_seqid = 0xFFFF;
 		}
 
-		ah->arc_dhost= adst;
-		ah->arc_shost= ac->ac_anaddr;
-
-		s = splimp();
-		/*
-		 * Queue message on interface, and start output if interface
-		 * not yet active.
-		 */
-		if (IF_QFULL(&ifp->if_snd)) {
-			IF_DROP(&ifp->if_snd);
-			splx(s);
-			senderr(ENOBUFS);
-		}
-		IF_ENQUEUE(&ifp->if_snd, m);
-		if ((ifp->if_flags & IFF_OACTIVE) == 0)
-			(*ifp->if_start)(ifp);
-		splx(s);
-	
-		ifp->if_obytes += len + ARC_HDRNEWLEN;
-		
+		ah->arc_dhost = adst;
+		ah->arc_shost = ac->ac_anaddr;
 	} else {
 		M_PREPEND(m, ARC_HDRLEN, M_DONTWAIT);
 		if (m == 0)
 			senderr(ENOBUFS);
 		ah = mtod(m, struct arc_header *);
 		ah->arc_type = atype;
-		ah->arc_dhost= adst;
-		ah->arc_shost= ac->ac_anaddr;
-		s = splimp();
-		/*
-		 * Queue message on interface, and start output if interface
-		 * not yet active.
-		 */
-		if (IF_QFULL(&ifp->if_snd)) {
-			IF_DROP(&ifp->if_snd);
-			splx(s);
-			senderr(ENOBUFS);
-		}
-		IF_ENQUEUE(&ifp->if_snd, m);
-		if ((ifp->if_flags & IFF_OACTIVE) == 0)
-			(*ifp->if_start)(ifp);
+		ah->arc_dhost = adst;
+		ah->arc_shost = ac->ac_anaddr;
+	}
+
+	s = splimp();
+	/*
+	 * Queue message on interface, and start output if interface
+	 * not yet active.
+	 */
+	if (IF_QFULL(&ifp->if_snd)) {
+		IF_DROP(&ifp->if_snd);
 		splx(s);
-	
-		ifp->if_obytes += len + ARC_HDRLEN;
+		senderr(ENOBUFS);
 	}
+	ifp->if_obytes += m->m_pkthdr.len;
+	IF_ENQUEUE(&ifp->if_snd, m);
+	if ((ifp->if_flags & IFF_OACTIVE) == 0)
+		(*ifp->if_start)(ifp);
+	splx(s);
+
 	return (error);
 
 bad:
@@ -484,7 +449,7 @@
  */
 int
 arc_isphds(type)
-	int type;
+	u_int8_t type;
 {
 	return ((type != ARCTYPE_IP_OLD && 
 		 type != ARCTYPE_ARP_OLD));
@@ -529,13 +494,13 @@
 	switch (atype) {
 #ifdef INET
 	case ARCTYPE_IP:
-		m_adj(m,ARC_HDRNEWLEN);
+		m_adj(m, ARC_HDRNEWLEN);
 		schednetisr(NETISR_IP);
 		inq = &ipintrq;
 		break;
 
 	case ARCTYPE_IP_OLD:
-		m_adj(m,ARC_HDRLEN);
+		m_adj(m, ARC_HDRLEN);
 		schednetisr(NETISR_IP);
 		inq = &ipintrq;
 		break;




>Audit-Trail:
>Unformatted: