From owner-freebsd-hackers Tue Jun 11 06:20:13 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id GAA18203 for hackers-outgoing; Tue, 11 Jun 1996 06:20:13 -0700 (PDT) Received: from mail13.digital.com (mail13.digital.com [192.208.46.30]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id GAA18184 for ; Tue, 11 Jun 1996 06:20:11 -0700 (PDT) Received: from muggsy.lkg.dec.com by mail13.digital.com (8.7.5/UNX 1.2/1.0/WV) id JAA12661; Tue, 11 Jun 1996 09:12:26 -0400 (EDT) Received: from whydos.lkg.dec.com by muggsy.lkg.dec.com (5.65/DEC-Ultrix/4.3) with SMTP id AA07110; Tue, 11 Jun 1996 09:12:17 -0400 Received: from localhost (localhost [127.0.0.1]) by whydos.lkg.dec.com (8.6.12/8.6.12) with SMTP id JAA24849; Tue, 11 Jun 1996 09:16:46 GMT Message-Id: <199606110916.JAA24849@whydos.lkg.dec.com> X-Authentication-Warning: whydos.lkg.dec.com: Host localhost didn't use HELO protocol X-Mailer: exmh version 1.6.5 12/11/95 To: davidg@root.com Cc: Ted Lemon , Jason Thorpe , freebsd-hackers@freebsd.org Subject: Re: Swapped ethertype in BPF output? In-Reply-To: Your message of "Mon, 10 Jun 1996 18:34:43 MST." <199606110134.SAA18869@Root.COM> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Tue, 11 Jun 1996 09:16:33 +0000 From: Matt Thomas Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk I think the input side is OK. It's just the output side that's broken. This is due to the ether_type being in host order when ether_output is called with a dst sockaddr of AF_UNSPEC. Under NetBSD and BSD/OS the ether_type is in network order. Since arp is the primary caller of ether_output with an AF_UNSPEC dst sockaddr. Note that FDDI does not suffer from this problem. bpf calls fddi_output with a sockaddr of AF_IMPLINK which tells fddi_output to not touch the packet expect for the source address. The attached diffs (relative to 2.1.0-RELEASE sources) show one possible solution. Matt Thomas Internet: matt@3am-software.com 3am Software Foundry WWW URL: http://www.3am-software.com/bio/matt.html Westford, MA Disclaimer: I disavow all knowledge of this message --- net/if_ethersubr.c.orig Sun Jun 11 19:31:39 1995 +++ net/if_ethersubr.c Tue Jun 11 09:08:21 1996 @@ -144,12 +144,12 @@ 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; - type = ETHERTYPE_IP; + type = htons(ETHERTYPE_IP); break; #endif #ifdef NS case AF_NS: - type = ETHERTYPE_NS; + type = htons(ETHERTYPE_NS); bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host), (caddr_t)edst, sizeof (edst)); if (!bcmp((caddr_t)edst, (caddr_t)&ns_thishost, sizeof(edst))) @@ -189,7 +189,7 @@ M_PREPEND(m, 3, M_DONTWAIT); if (m == NULL) return (0); - type = m->m_pkthdr.len; + type = htons(m->m_pkthdr.len); l = mtod(m, struct llc *); l->llc_dsap = l->llc_ssap = LLC_ISO_LSAP; l->llc_control = LLC_UI; @@ -225,7 +225,7 @@ (caddr_t)eh->ether_shost, sizeof (edst)); } } - type = m->m_pkthdr.len; + type = htons(m->m_pkthdr.len); #ifdef LLC_DEBUG { int i; @@ -266,7 +266,6 @@ if (m == 0) senderr(ENOBUFS); eh = mtod(m, struct ether_header *); - type = htons((u_short)type); (void)memcpy(&eh->ether_type, &type, sizeof(eh->ether_type)); (void)memcpy(eh->ether_dhost, edst, sizeof (edst)); --- netinet/if_ether.c.orig Sun Jul 23 05:26:13 1995 +++ netinet/if_ether.c Tue Jun 11 09:07:03 1996 @@ -262,7 +262,7 @@ eh = (struct ether_header *)sa.sa_data; bzero((caddr_t)ea, sizeof (*ea)); (void)memcpy(eh->ether_dhost, etherbroadcastaddr, sizeof(eh->ether_dhost)); - eh->ether_type = ETHERTYPE_ARP; /* if_output will swap */ + eh->ether_type = htons(ETHERTYPE_ARP); /* if_output will not swap */ ea->arp_hrd = htons(ARPHRD_ETHER); ea->arp_pro = htons(ETHERTYPE_IP); ea->arp_hln = sizeof(ea->arp_sha); /* hardware address length */ @@ -526,7 +526,7 @@ ea->arp_pro = htons(ETHERTYPE_IP); /* let's be sure! */ eh = (struct ether_header *)sa.sa_data; (void)memcpy(eh->ether_dhost, ea->arp_tha, sizeof(eh->ether_dhost)); - eh->ether_type = ETHERTYPE_ARP; + eh->ether_type = htons(ETHERTYPE_ARP); sa.sa_family = AF_UNSPEC; sa.sa_len = sizeof(sa); (*ac->ac_if.if_output)(&ac->ac_if, m, &sa, (struct rtentry *)0);