From e8d255dd8211778306edd31d1379052ab7750b67 Mon Sep 17 00:00:00 2001 From: nsayer Date: Tue, 30 Mar 1999 23:45:14 +0000 Subject: Merge from RELENG_2_2, per luigi. Fixes the ntoh?() issue for the firewall code when called from the bridge code. PR: 10818 Submitted by: nsayer Obtained from: luigi --- sys/net/bridge.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'sys/net') diff --git a/sys/net/bridge.c b/sys/net/bridge.c index c04fd09..b2dbe83 100644 --- a/sys/net/bridge.c +++ b/sys/net/bridge.c @@ -87,6 +87,9 @@ #include #include /* for struct arpcom */ +#include +#include +#include #include /* for struct arpcom */ #include "opt_ipfw.h" @@ -519,13 +522,38 @@ bdg_forward (struct mbuf **m0, struct ifnet *dst) } dummy = 0 ; - off= (*ip_fw_chk_ptr)(NULL, 0, src, &dummy, &m, &rule, NULL /*next hop */ ) ; + /* + * before calling the firewall, swap fields the same as IP does. + * here we assume the pkt is an IP one and the header is contiguous + */ + eh = mtod(m, struct ether_header *); + ip = (struct ip *)(eh + 1 ) ; + NTOHS(ip->ip_len); + NTOHS(ip->ip_id); + NTOHS(ip->ip_off); + + /* + * The third parameter to the firewall code is the dst. interface. + * Since we apply checks only on input pkts we use NULL. + */ + off = (*ip_fw_chk_ptr)(NULL, 0, NULL, &dummy, &m, &rule, NULL) ; if (m == NULL) { /* pkt discarded by firewall */ - printf("-- bdg: firewall discarded pkt\n"); if (canfree) *m0 = NULL ; return 0 ; } + /* + * on return, the mbuf pointer might have changed. Restore + * *m0 (if it was the same as m), eh, ip and then + * restore original ordering. + */ + eh = mtod(m, struct ether_header *); + ip = (struct ip *)(eh + 1 ) ; + if (canfree) /* m was a reference to *m0, so update *m0 */ + *m0 = m ; + HTONS(ip->ip_len); + HTONS(ip->ip_id); + HTONS(ip->ip_off); if (off == 0) { if (canfree == 0) m_freem(m); @@ -544,7 +572,6 @@ bdg_forward (struct mbuf **m0, struct ifnet *dst) } #endif /* if none of the above matches, we have to drop the pkt */ - printf("-- bdg: fw: drop\n"); if (m) m_freem(m); if (canfree && m != *m0) { -- cgit v1.1