From patchwork Sat Oct 27 12:26:17 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 194614 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id A77CA2C00A7 for ; Sat, 27 Oct 2012 23:26:29 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752330Ab2J0M0X (ORCPT ); Sat, 27 Oct 2012 08:26:23 -0400 Received: from mail-ee0-f46.google.com ([74.125.83.46]:56412 "EHLO mail-ee0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752112Ab2J0M0W (ORCPT ); Sat, 27 Oct 2012 08:26:22 -0400 Received: by mail-ee0-f46.google.com with SMTP id b15so1424323eek.19 for ; Sat, 27 Oct 2012 05:26:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:from:to:cc:content-type:date:message-id:mime-version :x-mailer:content-transfer-encoding; bh=CA1w2yhFHQF/fahGtU0XwGzkDA+jMIRrGUe+iv2qNmY=; b=Ub6iITmgz4xFFerPT99kw+/hdHoF2xCr+lB5uA6F9pvvDpmN/lHRwd3XE3xnXgkY9T qGs5sixVV2vFmIgiBH0/SOhFv9Yi2D/OADqqOg0pmDu8iAUbWw11Ny3gbIGSMTYvXKNV twxd6MAccrcqe7LuYxYzagecNbewaP5CZGnX7rj9c986fDXJ+PnfWl8HL5c1JdavXD4a u1Z6jsH1OLZQWDJ5L0rNoggVuhBzPp3buNtp/ul7TTvTt6oJRg0K65ttO9dGeWIpYb1T S6JyqcZrqvq0nXMx/N0Mhki7c6EUfNfEMXr603dgpcEMAPT9xEXJCTfLKIsfkO4h+kVN ce5A== Received: by 10.14.184.1 with SMTP id r1mr42198005eem.4.1351340781193; Sat, 27 Oct 2012 05:26:21 -0700 (PDT) Received: from [172.28.90.158] ([172.28.90.158]) by mx.google.com with ESMTPS id t7sm8980860eel.14.2012.10.27.05.26.18 (version=SSLv3 cipher=OTHER); Sat, 27 Oct 2012 05:26:19 -0700 (PDT) Subject: [PATCH net-next 1/2] net: filter: add vlan tag access From: Eric Dumazet To: David Miller Cc: Ani Sinha , netdev , Daniel Borkmann Date: Sat, 27 Oct 2012 14:26:17 +0200 Message-ID: <1351340777.30380.273.camel@edumazet-glaptop> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Eric Dumazet BPF filters lack ability to access skb->vlan_tci This patch adds two new ancillary accessors : SKF_AD_VLAN_TAG (44) mapped to vlan_tx_tag_get(skb) SKF_AD_VLAN_TAG_PRESENT (48) mapped to vlan_tx_tag_present(skb) This allows libpcap/tcpdump to use a kernel filter instead of having to fallback to accept all packets, then filter them in user space. Signed-off-by: Eric Dumazet Suggested-by: Ani Sinha Suggested-by: Daniel Borkmann --- include/linux/filter.h | 2 ++ include/uapi/linux/filter.h | 4 +++- net/core/filter.c | 9 +++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/include/linux/filter.h b/include/linux/filter.h index 24d251f..c9f0005 100644 --- a/include/linux/filter.h +++ b/include/linux/filter.h @@ -123,6 +123,8 @@ enum { BPF_S_ANC_CPU, BPF_S_ANC_ALU_XOR_X, BPF_S_ANC_SECCOMP_LD_W, + BPF_S_ANC_VLAN_TAG, + BPF_S_ANC_VLAN_TAG_PRESENT, }; #endif /* __LINUX_FILTER_H__ */ diff --git a/include/uapi/linux/filter.h b/include/uapi/linux/filter.h index 3d79224..9cfde69 100644 --- a/include/uapi/linux/filter.h +++ b/include/uapi/linux/filter.h @@ -127,7 +127,9 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */ #define SKF_AD_RXHASH 32 #define SKF_AD_CPU 36 #define SKF_AD_ALU_XOR_X 40 -#define SKF_AD_MAX 44 +#define SKF_AD_VLAN_TAG 44 +#define SKF_AD_VLAN_TAG_PRESENT 48 +#define SKF_AD_MAX 52 #define SKF_NET_OFF (-0x100000) #define SKF_LL_OFF (-0x200000) diff --git a/net/core/filter.c b/net/core/filter.c index 3d92ebb..5a114d4 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -39,6 +39,7 @@ #include #include #include +#include /* No hurry in this branch * @@ -341,6 +342,12 @@ load_b: case BPF_S_ANC_CPU: A = raw_smp_processor_id(); continue; + case BPF_S_ANC_VLAN_TAG: + A = vlan_tx_tag_get(skb); + continue; + case BPF_S_ANC_VLAN_TAG_PRESENT: + A = !!vlan_tx_tag_present(skb); + continue; case BPF_S_ANC_NLATTR: { struct nlattr *nla; @@ -600,6 +607,8 @@ int sk_chk_filter(struct sock_filter *filter, unsigned int flen) ANCILLARY(RXHASH); ANCILLARY(CPU); ANCILLARY(ALU_XOR_X); + ANCILLARY(VLAN_TAG); + ANCILLARY(VLAN_TAG_PRESENT); } } ftest->code = code;