From owner-freebsd-hackers Tue Jun 11 00:38:47 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id AAA11043 for hackers-outgoing; Tue, 11 Jun 1996 00:38:47 -0700 (PDT) Received: from toccata.fugue.com (toccata.fugue.com [204.254.239.2]) by freefall.freebsd.org (8.7.5/8.7.3) with SMTP id AAA11038 for ; Tue, 11 Jun 1996 00:38:44 -0700 (PDT) Received: from localhost (mellon@localhost) by toccata.fugue.com (8.6.12/8.6.11) with SMTP id AAA29287; Tue, 11 Jun 1996 00:38:33 -0700 Message-Id: <199606110738.AAA29287@toccata.fugue.com> To: davidg@root.com cc: Jason Thorpe , freebsd-hackers@freebsd.org Subject: Re: Swapped ethertype in BPF output? In-reply-to: Your message of "Mon, 10 Jun 1996 18:16:41 PDT." <199606110116.SAA18815@Root.COM> Date: Tue, 11 Jun 1996 00:38:32 -0700 From: Ted Lemon Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk > ehh, uhh, well, send me a context diff for however people want it in the > kernel. :-) Be careful what you ask for - you may get it! :') I believe that the patch below is the right way to solve the problem, although I'm by no means positive, since I don't have a FreeBSD machine to check it on. The patch is on the latest FreeBSD kernel snapshot (960606). It's not clear to me how this worked in 4.4BSD. The code just after the 4.4BSD merge in the NetBSD tree does the right thing, albeit in a slightly less efficient way. But this may be based on the previous NetBSD code, which is also correct. The changes below actually only do a runtime swap for AF_ISO and AF_CCITT (as if anybody cared) - otherwise the swap is done on a constant (ETHERTYPE_XXX) at compile time. So in addition to being (IMHO) correct, these changes make the code slightly faster. Not that I can claim credit for this - the changes are analogous to changes made by mycroft in the NetBSD tree. _MelloN_ *** sys/net/if_ethersubr.c~ Wed Jun 5 12:49:24 1996 --- sys/net/if_ethersubr.c Tue Jun 11 00:19:52 1996 *************** *** 145,154 **** mcopy = m_copy(m, 0, (int)M_COPYALL); off = m->m_pkthdr.len - m->m_len; ! type = ETHERTYPE_IP; break; #endif #ifdef NS case AF_NS: ! type = ETHERTYPE_NS; bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host), (caddr_t)edst, sizeof (edst)); --- 145,154 ---- mcopy = m_copy(m, 0, (int)M_COPYALL); off = m->m_pkthdr.len - m->m_len; ! type = htons (ETHERTYPE_IP); break; #endif #ifdef NS case AF_NS: ! type = htons (ETHERTYPE_NS); bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host), (caddr_t)edst, sizeof (edst)); *************** *** 190,194 **** if (m == NULL) return (0); ! type = m->m_pkthdr.len; l = mtod(m, struct llc *); l->llc_dsap = l->llc_ssap = LLC_ISO_LSAP; --- 190,194 ---- if (m == NULL) return (0); ! type = htons (m->m_pkthdr.len); l = mtod(m, struct llc *); l->llc_dsap = l->llc_ssap = LLC_ISO_LSAP; *************** *** 226,230 **** } } ! type = m->m_pkthdr.len; #ifdef LLC_DEBUG { --- 226,230 ---- } } ! type = htons (m->m_pkthdr.len); #ifdef LLC_DEBUG { *************** *** 267,271 **** senderr(ENOBUFS); eh = mtod(m, struct ether_header *); - type = htons((u_short)type); (void)memcpy(&eh->ether_type, &type, sizeof(eh->ether_type)); --- 267,270 ----