From patchwork Tue Feb 23 12:49:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jamal Hadi Salim X-Patchwork-Id: 586847 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 34DF9140B9E for ; Tue, 23 Feb 2016 23:49:59 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=mojatatu-com.20150623.gappssmtp.com header.i=@mojatatu-com.20150623.gappssmtp.com header.b=IVV6xVtg; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751956AbcBWMtl (ORCPT ); Tue, 23 Feb 2016 07:49:41 -0500 Received: from mail-ig0-f173.google.com ([209.85.213.173]:33957 "EHLO mail-ig0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751785AbcBWMtg (ORCPT ); Tue, 23 Feb 2016 07:49:36 -0500 Received: by mail-ig0-f173.google.com with SMTP id g6so110365331igt.1 for ; Tue, 23 Feb 2016 04:49:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=oajfiW5GlWz/Sr2qo+BW7MCUHg9vh1kxOOr4E25TlCs=; b=IVV6xVtg2ad+Pv+bpJ+4VRwYCui5IV9ZaAAmbaqSUAwahr5Ft8RC+1WXfX3V9iFbP0 pONarkc9rByNhLMCqUm/xD4PrTmXgiotmJmB0iHexqjA7439yCSmOBQXqZlBwtlssFho atbixaX/9nSDOvYtps3/v8MSbsGJ6JudB0BsXiJOKZ1CtIFv/8GIdEgosWVpVWSFxsRI HIhT9A1+Sw5yu/bW2zZhQDujSFRJyhERQeT4E6XIEKjZDcR51YTcWfUhSXaCsZZxLmxK Ms2fZ7TrxlYmM9fl31RZqcU7w+CSYWX2ijGyFe/3m1wQOK66zxoj9TsMahnaTl98bZyB ooYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=oajfiW5GlWz/Sr2qo+BW7MCUHg9vh1kxOOr4E25TlCs=; b=jIiFVfSEPjCnT/clXgTqkDqe8puf091CVPZ3EopjLJI+7TJs5LCgzx6kL39AAzTqQ6 BFGHOamMf7+q5wLSkp4/T7PEWbA9yhXTychZDZc75Xr1eycIFdapCuNBtP8uALAffTVc a0boGZhyTazSkXyG0l5XL8PwbQ93jcdSnkauPR6eu8uR/eq9nGd2R6ztEBXgjW3zVAEj 53FlFcAZgUOJXQB+xgVvjLRIXSz5fjhPTQpfnISTFRWj4yqdiCRvpAzA2ph9cSkKM534 lt2H0UUA197tDwMX/myIMAYOQohk61UOSOUaAgEtOFegjvsYebdnUzedEWuUbbV+B1P1 6j3A== X-Gm-Message-State: AG10YORSGH9W56NSkWosi25B8WuOmIvpT1mEZ6Lc7CpvcDMkLXYUTPyqUOi7tU7iGOhzXg== X-Received: by 10.50.157.68 with SMTP id wk4mr18045776igb.0.1456231775941; Tue, 23 Feb 2016 04:49:35 -0800 (PST) Received: from jhs-UX303LB.lan ([23.233.30.50]) by smtp.gmail.com with ESMTPSA id j94sm13365630iod.26.2016.02.23.04.49.34 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 23 Feb 2016 04:49:35 -0800 (PST) From: Jamal Hadi Salim X-Google-Original-From: Jamal Hadi Salim To: davem@davemloft.net Cc: netdev@vger.kernel.org, daniel@iogearbox.net, xiyou.wangcong@gmail.com, alexei.starovoitov@gmail.com, john.fastabend@gmail.com, dj@verizon.com, Jamal Hadi Salim Subject: [net-next PATCH v2 2/5] Support to encoding decoding skb mark on IFE action Date: Tue, 23 Feb 2016 07:49:17 -0500 Message-Id: <1456231760-2513-3-git-send-email-jhs@emojatatu.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1456231760-2513-1-git-send-email-jhs@emojatatu.com> References: <1456231760-2513-1-git-send-email-jhs@emojatatu.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jamal Hadi Salim Example usage: Set the skb using skbedit then allow it to be encoded sudo tc qdisc add dev $ETH root handle 1: prio sudo tc filter add dev $ETH parent 1: protocol ip prio 10 \ u32 match ip protocol 1 0xff flowid 1:2 \ action skbedit mark 17 \ action ife encode \ allow mark \ dst 02:15:15:15:15:15 Note: You dont need the skbedit action if you are already encoding the skb mark earlier. A zero skb mark will not be allowed Alternative hard code static mark of 0x12 every time the filter matches sudo $TC filter add dev $ETH parent 1: protocol ip prio 10 \ u32 match ip protocol 1 0xff flowid 1:2 \ action ife encode \ type 0xDEAD \ use mark 0x12 \ dst 02:15:15:15:15:15 Signed-off-by: Jamal Hadi Salim --- net/sched/Kconfig | 5 +++ net/sched/Makefile | 1 + net/sched/act_meta_mark.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 net/sched/act_meta_mark.c diff --git a/net/sched/Kconfig b/net/sched/Kconfig index 4d48ef5..85854c0 100644 --- a/net/sched/Kconfig +++ b/net/sched/Kconfig @@ -751,6 +751,11 @@ config NET_ACT_IFE To compile this code as a module, choose M here: the module will be called act_ife. +config NET_IFE_SKBMARK + tristate "Support to encoding decoding skb mark on IFE action" + depends on NET_ACT_IFE + ---help--- + config NET_CLS_IND bool "Incoming device classification" depends on NET_CLS_U32 || NET_CLS_FW diff --git a/net/sched/Makefile b/net/sched/Makefile index 3d17667..3f7a182 100644 --- a/net/sched/Makefile +++ b/net/sched/Makefile @@ -20,6 +20,7 @@ obj-$(CONFIG_NET_ACT_VLAN) += act_vlan.o obj-$(CONFIG_NET_ACT_BPF) += act_bpf.o obj-$(CONFIG_NET_ACT_CONNMARK) += act_connmark.o obj-$(CONFIG_NET_ACT_IFE) += act_ife.o +obj-$(CONFIG_NET_IFE_SKBMARK) += act_meta_mark.o obj-$(CONFIG_NET_SCH_FIFO) += sch_fifo.o obj-$(CONFIG_NET_SCH_CBQ) += sch_cbq.o obj-$(CONFIG_NET_SCH_HTB) += sch_htb.o diff --git a/net/sched/act_meta_mark.c b/net/sched/act_meta_mark.c new file mode 100644 index 0000000..20e7ace --- /dev/null +++ b/net/sched/act_meta_mark.c @@ -0,0 +1,79 @@ +/* + * net/sched/act_meta_mark.c IFE skb->mark metadata module + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + * + * copyright Jamal Hadi Salim (2015) + * +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int skbmark_encode(struct sk_buff *skb, void *skbdata, + struct tcf_meta_info *e) +{ + u32 ifemark = skb->mark; + + return encode_meta_u32(ifemark, skbdata, e); +} + +static int skbmark_decode(struct sk_buff *skb, void *data, u16 len) +{ + u32 ifemark = *(u32 *) data; + + skb->mark = ntohl(ifemark); + return 0; +} + +static int skbmark_check(struct sk_buff *skb, struct tcf_meta_info *e) +{ + return check_meta_u32(skb->mark, e); +} + +static struct tcf_meta_ops ife_skbmark_ops = { + .metaid = IFE_META_SKBMARK, + .metatype = NLA_U32, + .name = "skbmark", + .synopsis = "skb mark 32 bit metadata", + .check_presence = skbmark_check, + .encode = skbmark_encode, + .decode = skbmark_decode, + .get = get_meta_u32, + .alloc = alloc_meta_u32, + .release = release_meta_gen, + .validate = validate_meta_u32, + .owner = THIS_MODULE, +}; + +static int __init ifemark_init_module(void) +{ + return register_ife_op(&ife_skbmark_ops); +} + +static void __exit ifemark_cleanup_module(void) +{ + unregister_ife_op(&ife_skbmark_ops); +} + +module_init(ifemark_init_module); +module_exit(ifemark_cleanup_module); + +MODULE_AUTHOR("Jamal Hadi Salim(2015)"); +MODULE_DESCRIPTION("Inter-FE skb mark metadata module"); +MODULE_LICENSE("GPL"); +MODULE_ALIAS_IFE_META(IFE_META_SKBMARK);