summaryrefslogtreecommitdiffstats
path: root/sys/net/if_tun.c
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>2000-10-15 18:49:17 +0000
committerbrian <brian@FreeBSD.org>2000-10-15 18:49:17 +0000
commit74f5353c0ac526e57acb8db53662db6508a63355 (patch)
tree955d4fffb0ed2d00a3f0437072b9a34d0c1c702e /sys/net/if_tun.c
parent76e5fb2ac326d7c6ad69e329420821c2ff95a645 (diff)
downloadFreeBSD-src-74f5353c0ac526e57acb8db53662db6508a63355.zip
FreeBSD-src-74f5353c0ac526e57acb8db53662db6508a63355.tar.gz
BPF wants packets in host byte order whereas TUN_IFHEAD wants them
in network byte order. When we've got TUN_IFHEAD set, swap the AF byte order before passing a packet to bpf_mtap().
Diffstat (limited to 'sys/net/if_tun.c')
-rw-r--r--sys/net/if_tun.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/sys/net/if_tun.c b/sys/net/if_tun.c
index 4b47ec6..f7a2f86 100644
--- a/sys/net/if_tun.c
+++ b/sys/net/if_tun.c
@@ -361,7 +361,7 @@ tunoutput(ifp, m0, dst, rt)
* try to free it or keep a pointer to it).
*/
struct mbuf m;
- u_int af = dst->sa_family;
+ uint32_t af = dst->sa_family;
m.m_next = m0;
m.m_len = 4;
@@ -618,7 +618,7 @@ tunwrite(dev, uio, flag)
struct ifnet *ifp = &tp->tun_if;
struct mbuf *top, **mp, *m;
int error=0, tlen, mlen;
- u_int32_t family;
+ uint32_t family;
TUNDEBUG("%s%d: tunwrite\n", ifp->if_name, ifp->if_unit);
@@ -665,13 +665,20 @@ tunwrite(dev, uio, flag)
top->m_pkthdr.rcvif = ifp;
if (ifp->if_bpf) {
- if (tp->tun_flags & TUN_IFHEAD)
+ if (tp->tun_flags & TUN_IFHEAD) {
/*
* Conveniently, we already have a 4-byte address
* family prepended to our packet !
+ * Inconveniently, it's in the wrong byte order !
*/
+ if ((top = m_pullup(top, sizeof(family))) == NULL)
+ return ENOBUFS;
+ *mtod(top, u_int32_t *) =
+ ntohl(*mtod(top, u_int32_t *));
bpf_mtap(ifp, top);
- else {
+ *mtod(top, u_int32_t *) =
+ htonl(*mtod(top, u_int32_t *));
+ } else {
/*
* We need to prepend the address family as
* a four byte field. Cons up a dummy header
@@ -680,7 +687,7 @@ tunwrite(dev, uio, flag)
* try to free it or keep a pointer to it).
*/
struct mbuf m;
- u_int af = AF_INET;
+ uint32_t af = AF_INET;
m.m_next = top;
m.m_len = 4;
OpenPOWER on IntegriCloud