From owner-freebsd-hackers@freebsd.org Wed Dec 30 04:46:35 2015 Return-Path: Delivered-To: freebsd-hackers@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 65F35A56286 for ; Wed, 30 Dec 2015 04:46:35 +0000 (UTC) (envelope-from mybsdmailing@gmail.com) Received: from mail-oi0-x243.google.com (mail-oi0-x243.google.com [IPv6:2607:f8b0:4003:c06::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 329AF10CE for ; Wed, 30 Dec 2015 04:46:35 +0000 (UTC) (envelope-from mybsdmailing@gmail.com) Received: by mail-oi0-x243.google.com with SMTP id o62so18148597oif.1 for ; Tue, 29 Dec 2015 20:46:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=OE2ajCVg7OH8R5O4cXDHHhuxaW9ERoPnkBOWoZQIXRA=; b=gt4m4qn9wCxUszBAd7pm85d8VdflLw8ilKDpQr98xdTC+HByGQkuLjcfHDbMoBPiat IWqyFTK9gnRSVw0c9syTHndxveFTE5OXZC8jkCTiytS/lFM+xPpD3stoGRrHZFTL0zEm 7N74/yJphh0/RH5heyjPqr6Dzsz7crH7IMQHPceBw5XM7i11W3h9JykW06OCOnR4qeZS 2RcrjxtdPBzgtgrWDvSGY7SUMeu5XJ8/NulXGJa18OK1csuNAxioTJTYASPDBsENmHFK flBOxcmWu33TDZ6mSncgroolY0rN6xx5ObTs2dHrTxbeIgzUFl6LfC5uBvyz0w8J39NW 8s+Q== MIME-Version: 1.0 X-Received: by 10.202.182.133 with SMTP id g127mr35125409oif.41.1451450794386; Tue, 29 Dec 2015 20:46:34 -0800 (PST) Received: by 10.202.177.69 with HTTP; Tue, 29 Dec 2015 20:46:34 -0800 (PST) Date: Tue, 29 Dec 2015 22:46:34 -0600 Message-ID: Subject: BPF Berkeley Packet Filter Question From: Juan Herrera To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.20 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Dec 2015 04:46:35 -0000 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 ? TIA!