From owner-freebsd-net@FreeBSD.ORG Thu May 26 10:37:05 2005 Return-Path: X-Original-To: freebsd-net@freebsd.org Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BDB6316A41C for ; Thu, 26 May 2005 10:37:05 +0000 (GMT) (envelope-from mjl@luckie.org.nz) Received: from grunt13.ihug.co.nz (grunt13.ihug.co.nz [203.109.254.60]) by mx1.FreeBSD.org (Postfix) with ESMTP id 72EC143D48 for ; Thu, 26 May 2005 10:37:04 +0000 (GMT) (envelope-from mjl@luckie.org.nz) Received: from 203-173-150-184.bliink.ihug.co.nz (lycra.luckie.org.nz) [203.173.150.184] by grunt13.ihug.co.nz with esmtp (Exim 3.35 #1 (Debian)) id 1DbFja-0002Cr-00; Thu, 26 May 2005 22:37:03 +1200 Received: from 203-173-155-132.bliink.ihug.co.nz ([203.173.155.132] helo=[192.168.1.6]) by lycra.luckie.org.nz with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.51 (FreeBSD)) id 1DbFj5-0003I8-AX for freebsd-net@freebsd.org; Thu, 26 May 2005 22:36:31 +1200 Message-ID: <4295A6CA.8080409@luckie.org.nz> Date: Thu, 26 May 2005 22:36:58 +1200 From: Matthew Luckie User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.7) Gecko/20050501 X-Accept-Language: en-us, en MIME-Version: 1.0 To: freebsd-net@freebsd.org Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Subject: bpf writes on tun device X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 May 2005 10:37:05 -0000 Hi I would like to use the BPF device to write packets on a tun device, which is bpf type DLT_NULL. I'm aware that the man page (for 4.X and 5.X) says that BPF writes are only supported on Ethernet and SLIP links. I did notice, though, that the tunoutput function in sys/net/if_tun.c has some BPF code, and the cvs log says that write support was added back in revision 1.10 of the if_tun.c code 9 odd years ago. /* BPF write needs to be handled specially */ if (dst->sa_family == AF_UNSPEC) { dst->sa_family = *(mtod(m0, int *)); m0->m_len -= sizeof(int); m0->m_pkthdr.len -= sizeof(int); m0->m_data += sizeof(int); } it expects the BPF writer to supply an integer defining the address family of the packet embedded in the packet we wish to write. I can successfully write BPF packets up to 1500 bytes in size (1496 IP bytes without the address family integer). Writes larger than this return EMSGSIZE. I presume this is because of the following code in bpfwrite: if (datlen > ifp->if_mtu) { m_freem(m); return (EMSGSIZE); } although I haven't figured out how I manage to write 1514 bytes to an ethernet (1500 IP bytes + 14 for the ethernet header). I've got my code at http://www.wand.net.nz/~mjl12/bpf_null_tx.c which forms an ICMP echo request packet. This is on a FreeBSD 4.10 machine. I have two questions: 1. Should I be able to send IP MTU sized packets on tun devices, on any FreeBSD releases? 2. How come the bpf check against the interface MTU succeeds for ethernet writes of 1514, despite if->if_mtu seemingly being set to 1500 in if_ethersubr.c? Thanks Matthew