From owner-freebsd-net@freebsd.org Wed Dec 30 08:46:49 2015 Return-Path: Delivered-To: freebsd-net@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id CF180A55692 for ; Wed, 30 Dec 2015 08:46:49 +0000 (UTC) (envelope-from julian@freebsd.org) Received: from vps1.elischer.org (vps1.elischer.org [204.109.63.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "vps1.elischer.org", Issuer "CA Cert Signing Authority" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id AEF011F93 for ; Wed, 30 Dec 2015 08:46:49 +0000 (UTC) (envelope-from julian@freebsd.org) Received: from Julian-MBP3.local (ppp121-45-250-125.lns20.per4.internode.on.net [121.45.250.125]) (authenticated bits=0) by vps1.elischer.org (8.15.2/8.15.2) with ESMTPSA id tBU8kjbG033279 (version=TLSv1.2 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Wed, 30 Dec 2015 00:46:47 -0800 (PST) (envelope-from julian@freebsd.org) Subject: Re: BPF Berkeley Packet Filter To: Juan Herrera , freebsd-net@freebsd.org References: From: Julian Elischer Message-ID: <568399EF.2090409@freebsd.org> Date: Wed, 30 Dec 2015 16:46:39 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Dec 2015 08:46:49 -0000 On 30/12/2015 12:22 PM, Juan Herrera wrote: > Hello BSD folks, > > I am developing a networking application in C and I have a question > regarding BPF (Berkeley Packet Filters), > I will give you an idea of the app first, I need to send a packet from > machine A to machine B (any kind of packet) so for this I wrote a packet > generator application which will send a packet to machine B, but before > sending the packet I need to append some metadata values at the end of the > packet, already done, so in machine B I have a raw socket listener app > ready to receive incoming packets from machine A, however I want to > implement filtering with BPF on machine B, but as my metadata was appended > at the end of the packet (have to be at the end), I need to read the packet > length with(using) Berkeley Packet Filter to match a specific field to > filter one of the bytes at the end of my packet (metadata appended), in > other words I need to know the incoming packet length to filtered against > one of the metadatas fields and be able to drop the packet before reaching > user space applications(drop it in kernel space). > > So my question is, Can I use BPF to read the packet length to do what I > want? you mean can you use a bpf filter to act upon a trailer? yes you can look at the man page for BPF_LD and BPF_LEN > > Thank you in advance! > > Happy Holidays! > _______________________________________________ > freebsd-net@freebsd.org mailing list > https://lists.freebsd.org/mailman/listinfo/freebsd-net > To unsubscribe, send any mail to "freebsd-net-unsubscribe@freebsd.org" >