Date: Tue, 11 Jun 1996 09:16:33 +0000 From: Matt Thomas <matt@lkg.dec.com> To: davidg@root.com Cc: Ted Lemon <mellon@fugue.com>, Jason Thorpe <thorpej@nas.nasa.gov>, freebsd-hackers@freebsd.org Subject: Re: Swapped ethertype in BPF output? Message-ID: <199606110916.JAA24849@whydos.lkg.dec.com> In-Reply-To: Your message of "Mon, 10 Jun 1996 18:34:43 MST." <199606110134.SAA18869@Root.COM>
next in thread | previous in thread | raw e-mail | index | archive | help
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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199606110916.JAA24849>