From patchwork Mon Sep 19 16:11:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shmulik Ladkani X-Patchwork-Id: 671833 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 3sd9r044vcz9sBX for ; Tue, 20 Sep 2016 02:11:44 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=C6U7Q65q; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752134AbcISQLj (ORCPT ); Mon, 19 Sep 2016 12:11:39 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:36840 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750971AbcISQLe (ORCPT ); Mon, 19 Sep 2016 12:11:34 -0400 Received: by mail-wm0-f68.google.com with SMTP id b184so15802269wma.3 for ; Mon, 19 Sep 2016 09:11:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7xDYeotgA/ry4SWRtKyCkcUJdCoY0cFJ72d6cQhZUwM=; b=C6U7Q65qyhAX/28tPn8YdsIW4zVQhNSRF6frsw46rno+V/o2modX1plAbUa44YAojP t+9x8fd6CsTk1AE2+3jKUv4tErc6HUX7LiRYo+QD5aRpP1bkXzG2URBc+ZLt0AyUThl3 YuixZ/mjRbU/WXiwDhE6XLsihrRr4QL0IDUpy7JqeE3Ccrtvy6qH5v9AZIata27DMYaG bS7ylqaD7V7IPWPkHebk97TR+1l6WdMM34x3PsVqGjpSp11PtkGUuyfeQ8KDtjZArZEd vXvWKsziLFmbhjIOd+Iqme3MeE6Lpy2KoNT4xVJmlVNs/SMTBkFxNP1VYlwf9YzCL0K+ cQOw== 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=7xDYeotgA/ry4SWRtKyCkcUJdCoY0cFJ72d6cQhZUwM=; b=VjQ+ea+c5MJQnLrnJqFCxTTpqC7VwIau6VuBkIwNZysRkvd1cgewUzb75nxKiRth2N 1WAQq7ShnmS6IMA1zA1Ijp2t9ZvnzlA5X0NUmw/9hKFXTrmUgGgf2EnAXuebmYa6mf/e vcvvrsd1SlxX8UshAIvtEskrawZdJ457MwUXUOg1DBewquvrDDv7pTYcZUUiXXL+fQ/U 4l/2ZRLYIcQpyaZJ1HWqXazaPlYy4xldipOjgTkhJUrODUED6r4Kd1uE/8YCY4OiaAqs IlhK12isloXQl9/6SfukAuFZwMsVotEeccUbMxISXnmyZI/8N8P5bPQIwhFFe5h2jBkV x4tw== X-Gm-Message-State: AE9vXwPUNqZ7Ba6t7XA0jH2IP9//Eau0Sqaz28QiW0N1qQ3MoJkwW3TIP+gM/blaWnI8zw== X-Received: by 10.194.126.133 with SMTP id my5mr23982787wjb.47.1474301492998; Mon, 19 Sep 2016 09:11:32 -0700 (PDT) Received: from halley.home ([188.120.154.95]) by smtp.gmail.com with ESMTPSA id g184sm22835585wme.15.2016.09.19.09.11.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 19 Sep 2016 09:11:32 -0700 (PDT) From: Shmulik Ladkani To: "David S . Miller" Cc: Jiri Pirko , Jamal Hadi Salim , netdev@vger.kernel.org, Shmulik Ladkani Subject: [PATCH v2 2/2] net/sched: act_vlan: Introduce TCA_VLAN_ACT_MODIFY vlan action Date: Mon, 19 Sep 2016 19:11:10 +0300 Message-Id: <1474301470-17965-3-git-send-email-shmulik.ladkani@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1474301470-17965-1-git-send-email-shmulik.ladkani@gmail.com> References: <1474301470-17965-1-git-send-email-shmulik.ladkani@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org TCA_VLAN_ACT_MODIFY allows one to change an existing tag. It accepts same attributes as TCA_VLAN_ACT_PUSH (protocol, id, priority). If packet is vlan tagged, then the tag gets overwritten according to user specified attributes. For example, this allows user to replace a tag's vid while preserving its priority bits (as opposed to "action vlan pop pipe action vlan push"). Signed-off-by: Shmulik Ladkani Acked-by: Jamal Hadi Salim --- v2: - Removed superflous test 'mac_len < VLAN_ETH_HLEN' prior __skb_vlan_pop - Added some code comments include/uapi/linux/tc_act/tc_vlan.h | 1 + net/sched/act_vlan.c | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/tc_act/tc_vlan.h b/include/uapi/linux/tc_act/tc_vlan.h index be72b6e384..bddb272b84 100644 --- a/include/uapi/linux/tc_act/tc_vlan.h +++ b/include/uapi/linux/tc_act/tc_vlan.h @@ -16,6 +16,7 @@ #define TCA_VLAN_ACT_POP 1 #define TCA_VLAN_ACT_PUSH 2 +#define TCA_VLAN_ACT_MODIFY 3 struct tc_vlan { tc_gen; diff --git a/net/sched/act_vlan.c b/net/sched/act_vlan.c index 59a8d3150a..a95c00b119 100644 --- a/net/sched/act_vlan.c +++ b/net/sched/act_vlan.c @@ -30,6 +30,7 @@ static int tcf_vlan(struct sk_buff *skb, const struct tc_action *a, struct tcf_vlan *v = to_vlan(a); int action; int err; + u16 tci; spin_lock(&v->tcf_lock); tcf_lastuse_update(&v->tcf_tm); @@ -48,6 +49,30 @@ static int tcf_vlan(struct sk_buff *skb, const struct tc_action *a, if (err) goto drop; break; + case TCA_VLAN_ACT_MODIFY: + /* No-op if no vlan tag (either hw-accel or in-payload) */ + if (!skb_vlan_tagged(skb)) + goto unlock; + /* extract existing tag (and guarantee no hw-accel tag) */ + if (skb_vlan_tag_present(skb)) { + tci = skb_vlan_tag_get(skb); + skb->vlan_tci = 0; + } else { + /* in-payload vlan tag, pop it */ + err = __skb_vlan_pop(skb, &tci); + if (err) + goto drop; + } + /* replace the vid */ + tci = (tci & ~VLAN_VID_MASK) | v->tcfv_push_vid; + /* replace prio bits, if tcfv_push_prio specified */ + if (v->tcfv_push_prio) { + tci &= ~VLAN_PRIO_MASK; + tci |= v->tcfv_push_prio << VLAN_PRIO_SHIFT; + } + /* put updated tci as hwaccel tag */ + __vlan_hwaccel_put_tag(skb, v->tcfv_push_proto, tci); + break; default: BUG(); } @@ -102,6 +127,7 @@ static int tcf_vlan_init(struct net *net, struct nlattr *nla, case TCA_VLAN_ACT_POP: break; case TCA_VLAN_ACT_PUSH: + case TCA_VLAN_ACT_MODIFY: if (!tb[TCA_VLAN_PUSH_VLAN_ID]) { if (exists) tcf_hash_release(*a, bind); @@ -185,7 +211,8 @@ static int tcf_vlan_dump(struct sk_buff *skb, struct tc_action *a, if (nla_put(skb, TCA_VLAN_PARMS, sizeof(opt), &opt)) goto nla_put_failure; - if (v->tcfv_action == TCA_VLAN_ACT_PUSH && + if ((v->tcfv_action == TCA_VLAN_ACT_PUSH || + v->tcfv_action == TCA_VLAN_ACT_MODIFY) && (nla_put_u16(skb, TCA_VLAN_PUSH_VLAN_ID, v->tcfv_push_vid) || nla_put_be16(skb, TCA_VLAN_PUSH_VLAN_PROTOCOL, v->tcfv_push_proto) ||