From owner-freebsd-net@freebsd.org Wed Dec 30 04:22:22 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 79CEBA55B1F for ; Wed, 30 Dec 2015 04:22:22 +0000 (UTC) (envelope-from mybsdmailing@gmail.com) Received: from mail-oi0-x244.google.com (mail-oi0-x244.google.com [IPv6:2607:f8b0:4003:c06::244]) (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 497E31AC6 for ; Wed, 30 Dec 2015 04:22:22 +0000 (UTC) (envelope-from mybsdmailing@gmail.com) Received: by mail-oi0-x244.google.com with SMTP id o124so18565226oia.3 for ; Tue, 29 Dec 2015 20:22:22 -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=FoMiyz2agraBNPq/Gaw4VCA2b5MNwZ4nrPvY2HNhaQ4=; b=UXnsfM8jJQMi2hwOQHNmc+OG/+30d5nMYu4hcA7Sfwh6gwj11QScl/3lT8CNcc8rwG vx/TZsuYTFLysXH1SiXpvQMBtgOPcwmGcFAisvME9EkVRWIFF77wlGEhEFKt7K/vlded urcp91cL2JaRDR5Vc4pIdX8dghEHc8gHU3+lcwoS3dejPNf1P5FqV2F5L+pEJueexRTq F/reyvUfJrFhSifjFVmqhDEHF5yp0HrER1MgzJK04qv0/+MLfl7iholPB81kpLJP8anE gdl8GPHa3W52Orc8+oE/2MO7NXofBygbvAcPlgBP3i/AuYA3PZiyXaAbAFxM0Mbm4HqL oIGA== MIME-Version: 1.0 X-Received: by 10.202.79.5 with SMTP id d5mr33689855oib.121.1451449341504; Tue, 29 Dec 2015 20:22:21 -0800 (PST) Received: by 10.202.177.69 with HTTP; Tue, 29 Dec 2015 20:22:21 -0800 (PST) Date: Tue, 29 Dec 2015 22:22:21 -0600 Message-ID: Subject: BPF Berkeley Packet Filter From: Juan Herrera To: freebsd-net@freebsd.org Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.20 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 04:22:22 -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 to do what I want? Thank you in advance! Happy Holidays!