Date: Sat, 15 Sep 2007 20:04:22 GMT From: Kip Macy <kmacy@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 126441 for review Message-ID: <200709152004.l8FK4MKI000278@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=126441 Change 126441 by kmacy@kmacy_home:ethng on 2007/09/15 20:04:04 put ether_input on a diet for the common case, move most error handling to the end of the function Affected files ... .. //depot/projects/ethng/src/sys/net/if_ethersubr.c#2 edit Differences ... ==== //depot/projects/ethng/src/sys/net/if_ethersubr.c#2 (text+ko) ==== @@ -512,58 +512,36 @@ struct ether_header *eh; u_short etype; - if ((ifp->if_flags & IFF_UP) == 0) { - m_freem(m); - return; - } + if ((ifp->if_flags & IFF_UP) == 0) + goto out; + #ifdef DIAGNOSTIC if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) { if_printf(ifp, "discard frame at !IFF_DRV_RUNNING\n"); - m_freem(m); - return; + goto out; } #endif /* * Do consistency checks to verify assumptions * made by code past this point. */ - if ((m->m_flags & M_PKTHDR) == 0) { - if_printf(ifp, "discard frame w/o packet header\n"); - ifp->if_ierrors++; - m_freem(m); - return; - } - if (m->m_len < ETHER_HDR_LEN) { - /* XXX maybe should pullup? */ - if_printf(ifp, "discard frame w/o leading ethernet " - "header (len %u pkt len %u)\n", - m->m_len, m->m_pkthdr.len); - ifp->if_ierrors++; - m_freem(m); - return; - } + if ((m->m_flags & M_PKTHDR) == 0) + goto err_out_print; + if (m->m_len < ETHER_HDR_LEN) + goto err_out_print; + eh = mtod(m, struct ether_header *); etype = ntohs(eh->ether_type); #ifdef DIAGNOSTIC if (m->m_pkthdr.len > ETHER_MAX_FRAME(ifp, etype, m->m_flags & M_HASFCS) && (ifp->if_capenable & IFCAP_LRO) == 0) { - if_printf(ifp, "discard oversize frame " - "(ether type %x flags %x len %u > max %lu)\n", - etype, m->m_flags, m->m_pkthdr.len, - ETHER_MAX_FRAME(ifp, etype, - m->m_flags & M_HASFCS)); - ifp->if_ierrors++; - m_freem(m); - return; + goto err_out_print } #endif - if (m->m_pkthdr.rcvif == NULL) { - if_printf(ifp, "discard frame w/o interface pointer\n"); - ifp->if_ierrors++; - m_freem(m); - return; - } + if (m->m_pkthdr.rcvif == NULL) + goto err_out_print; + #ifdef DIAGNOSTIC if (m->m_pkthdr.rcvif != ifp) { if_printf(ifp, "Warning, frame marked as received on %s\n", @@ -605,10 +583,8 @@ ifp->if_ibytes += m->m_pkthdr.len; /* Allow monitor mode to claim this frame, after stats are updated. */ - if (ifp->if_flags & IFF_MONITOR) { - m_freem(m); - return; - } + if (ifp->if_flags & IFF_MONITOR) + goto out; /* Handle input from a lagg(4) port */ if (ifp->if_type == IFT_IEEE8023ADLAG) { @@ -635,9 +611,7 @@ #ifdef DIAGNOSTIC if_printf(ifp, "cannot pullup VLAN header\n"); #endif - ifp->if_ierrors++; - m_freem(m); - return; + goto err_out; } evl = mtod(m, struct ether_vlan_header *); @@ -704,6 +678,33 @@ random_harvest(m, 16, 3, 0, RANDOM_NET); ether_demux(ifp, m); + return; +err_out_print: + eh = mtod(m, struct ether_header *); + etype = ntohs(eh->ether_type); + + if ((m->m_flags & M_PKTHDR) == 0) + if_printf(ifp, "discard frame w/o packet header\n"); + if (m->m_len < ETHER_HDR_LEN) + if_printf(ifp, "discard frame w/o leading ethernet " + "header (len %u pkt len %u)\n", + m->m_len, m->m_pkthdr.len); +#ifdef DIAGNOSTIC + if (m->m_pkthdr.len > + ETHER_MAX_FRAME(ifp, etype, m->m_flags & M_HASFCS) && + (ifp->if_capenable & IFCAP_LRO) == 0) + if_printf(ifp, "discard oversize frame " + "(ether type %x flags %x len %u > max %lu)\n", + etype, m->m_flags, m->m_pkthdr.len, + ETHER_MAX_FRAME(ifp, etype, + m->m_flags & M_HASFCS)); +#endif + if (m->m_pkthdr.rcvif == NULL) + if_printf(ifp, "discard frame w/o interface pointer\n"); +err_out: + ifp->if_ierrors++; +out: + m_freem(m); } /*
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200709152004.l8FK4MKI000278>