From f1f0123e88adadd09a074577a66eedcdcfa047bc Mon Sep 17 00:00:00 2001 From: dwmalone Date: Sun, 26 Jun 2005 18:11:11 +0000 Subject: Fix some long standing bugs in writing to the BPF device attached to a DLT_NULL interface. In particular: 1) Consistently use type u_int32_t for the header of a DLT_NULL device - it continues to represent the address family as always. 2) In the DLT_NULL case get bpf_movein to store the u_int32_t in a sockaddr rather than in the mbuf, to be consistent with all the DLT types. 3) Consequently fix a bug in bpf_movein/bpfwrite which only permitted packets up to 4 bytes less than the MTU to be written. 4) Fix all DLT_NULL devices to have the code required to allow writing to their bpf devices. 5) Move the code to allow writing to if_lo from if_simloop to looutput, because it only applies to DLT_NULL devices but was being applied to other devices that use if_simloop possibly incorrectly. PR: 82157 Submitted by: Matthew Luckie Approved by: re (scottl) --- sys/net/if_disc.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'sys/net/if_disc.c') diff --git a/sys/net/if_disc.c b/sys/net/if_disc.c index 7789b29..d94eeeb 100644 --- a/sys/net/if_disc.c +++ b/sys/net/if_disc.c @@ -102,7 +102,7 @@ disc_clone_create(struct if_clone *ifc, int unit) ifp->if_addrlen = 0; ifp->if_snd.ifq_maxlen = 20; if_attach(ifp); - bpfattach(ifp, DLT_NULL, sizeof(u_int)); + bpfattach(ifp, DLT_NULL, sizeof(u_int32_t)); mtx_lock(&disc_mtx); LIST_INSERT_HEAD(&disc_softc_list, sc, sc_list); mtx_unlock(&disc_mtx); @@ -176,15 +176,14 @@ static int discoutput(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, struct rtentry *rt) { + u_int32_t af; M_ASSERTPKTHDR(m); - /* BPF write needs to be handled specially */ + /* BPF writes need to be handled specially. */ if (dst->sa_family == AF_UNSPEC) { - dst->sa_family = *(mtod(m, int *)); - m->m_len -= sizeof(int); - m->m_pkthdr.len -= sizeof(int); - m->m_data += sizeof(int); + bcopy(dst->sa_data, &af, sizeof(af)); + dst->sa_family = af; } if (ifp->if_bpf) { -- cgit v1.1