From ede3a2773d93013d337178aff3e4e21c2d6c50a0 Mon Sep 17 00:00:00 2001 From: Andrew Thompson Date: Sun, 3 Jul 2005 18:24:03 +0000 Subject: [PATCH] Check the alignment of the IP header before passing the packet up to the packet filter. This would cause a panic on architectures that require strict alignment such as sparc64, ia64 and ppc. This uses the code block from if_bridge and the newly added macro IP_HDR_ALIGNED_P(). This /might/ be a temporary messure before all NIC drivers are educated to align the header themself. PR: ia64/81284 Obtained from: NetBSD (if_bridge) Approved by: re (dwhite), mlaier (mentor) --- sys/net/bridge.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sys/net/bridge.c b/sys/net/bridge.c index 82a24fa87674..211f0e5bceb0 100644 --- a/sys/net/bridge.c +++ b/sys/net/bridge.c @@ -1025,6 +1025,19 @@ bdg_forward(struct mbuf *m0, struct ifnet *dst) bcopy(eh, &save_eh, ETHER_HDR_LEN); /* local copy for restore */ m_adj(m0, ETHER_HDR_LEN); /* temporarily strip header */ + /* + * Check that the IP header is aligned before passing up to the packet + * filter. + */ + if (ntohs(save_eh.ether_type) == ETHERTYPE_IP && + IP_HDR_ALIGNED_P(mtod(m0, caddr_t)) == 0) { + if ((m0 = m_copyup(m0, sizeof(struct ip), + (max_linkhdr + 3) & ~3)) == NULL) { + bdg_dropped++; + return NULL; + } + } + /* * NetBSD-style generic packet filter, pfil(9), hooks. * Enables ipf(8) in bridging.