All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] act_vlan: Introduce TCA_VLAN_ACT_MODIFY vlan action
@ 2016-09-18 14:33 Shmulik Ladkani
  2016-09-18 14:33 ` [PATCH net-next 1/2] net: skbuff: Export __skb_vlan_pop Shmulik Ladkani
  2016-09-18 14:33 ` [PATCH net-next 2/2] net/sched: act_vlan: Introduce TCA_VLAN_ACT_MODIFY vlan action Shmulik Ladkani
  0 siblings, 2 replies; 4+ messages in thread
From: Shmulik Ladkani @ 2016-09-18 14:33 UTC (permalink / raw)
  To: David S . Miller; +Cc: Jiri Pirko, Jamal Hadi Salim, netdev, Shmulik Ladkani

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").

Shmulik Ladkani (2):
  net: skbuff: Export __skb_vlan_pop
  net/sched: act_vlan: Introduce TCA_VLAN_ACT_MODIFY vlan action

 include/linux/skbuff.h              |  1 +
 include/uapi/linux/tc_act/tc_vlan.h |  1 +
 net/core/skbuff.c                   |  7 +++++--
 net/sched/act_vlan.c                | 29 ++++++++++++++++++++++++++++-
 4 files changed, 35 insertions(+), 3 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH net-next 1/2] net: skbuff: Export __skb_vlan_pop
  2016-09-18 14:33 [PATCH net-next 0/2] act_vlan: Introduce TCA_VLAN_ACT_MODIFY vlan action Shmulik Ladkani
@ 2016-09-18 14:33 ` Shmulik Ladkani
  2016-09-18 14:33 ` [PATCH net-next 2/2] net/sched: act_vlan: Introduce TCA_VLAN_ACT_MODIFY vlan action Shmulik Ladkani
  1 sibling, 0 replies; 4+ messages in thread
From: Shmulik Ladkani @ 2016-09-18 14:33 UTC (permalink / raw)
  To: David S . Miller; +Cc: Jiri Pirko, Jamal Hadi Salim, netdev, Shmulik Ladkani

This exports the functionality of extracting the tag from the payload,
without moving next vlan tag into hw accel tag.

Signed-off-by: Shmulik Ladkani <shmulik.ladkani@gmail.com>
---
 include/linux/skbuff.h | 1 +
 net/core/skbuff.c      | 7 +++++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 4c5662f05b..000c5301b8 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -3075,6 +3075,7 @@ bool skb_gso_validate_mtu(const struct sk_buff *skb, unsigned int mtu);
 struct sk_buff *skb_segment(struct sk_buff *skb, netdev_features_t features);
 struct sk_buff *skb_vlan_untag(struct sk_buff *skb);
 int skb_ensure_writable(struct sk_buff *skb, int write_len);
+int __skb_vlan_pop(struct sk_buff *skb, u16 *vlan_tci);
 int skb_vlan_pop(struct sk_buff *skb);
 int skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci);
 struct sk_buff *pskb_extract(struct sk_buff *skb, int off, int to_copy,
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index cc2c004838..2937088844 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -4493,8 +4493,10 @@ int skb_ensure_writable(struct sk_buff *skb, int write_len)
 }
 EXPORT_SYMBOL(skb_ensure_writable);
 
-/* remove VLAN header from packet and update csum accordingly. */
-static int __skb_vlan_pop(struct sk_buff *skb, u16 *vlan_tci)
+/* remove VLAN header from packet and update csum accordingly.
+ * expects a non skb_vlan_tag_present skb with a vlan tag payload
+ */
+int __skb_vlan_pop(struct sk_buff *skb, u16 *vlan_tci)
 {
 	struct vlan_hdr *vhdr;
 	unsigned int offset = skb->data - skb_mac_header(skb);
@@ -4525,6 +4527,7 @@ pull:
 
 	return err;
 }
+EXPORT_SYMBOL(__skb_vlan_pop);
 
 int skb_vlan_pop(struct sk_buff *skb)
 {
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH net-next 2/2] net/sched: act_vlan: Introduce TCA_VLAN_ACT_MODIFY vlan action
  2016-09-18 14:33 [PATCH net-next 0/2] act_vlan: Introduce TCA_VLAN_ACT_MODIFY vlan action Shmulik Ladkani
  2016-09-18 14:33 ` [PATCH net-next 1/2] net: skbuff: Export __skb_vlan_pop Shmulik Ladkani
@ 2016-09-18 14:33 ` Shmulik Ladkani
  2016-09-18 19:41   ` Jamal Hadi Salim
  1 sibling, 1 reply; 4+ messages in thread
From: Shmulik Ladkani @ 2016-09-18 14:33 UTC (permalink / raw)
  To: David S . Miller; +Cc: Jiri Pirko, Jamal Hadi Salim, netdev, Shmulik Ladkani

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 <shmulik.ladkani@gmail.com>
---
 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..e5eeaa7a01 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:
+		if (!skb_vlan_tagged(skb))
+			goto unlock;
+		/* extract existing tag (and guarantee no hwaccel tag) */
+		if (skb_vlan_tag_present(skb)) {
+			tci = skb_vlan_tag_get(skb);
+			skb->vlan_tci = 0;
+		} else {
+			if (skb->mac_len < VLAN_ETH_HLEN)
+				goto unlock;
+			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) ||
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next 2/2] net/sched: act_vlan: Introduce TCA_VLAN_ACT_MODIFY vlan action
  2016-09-18 14:33 ` [PATCH net-next 2/2] net/sched: act_vlan: Introduce TCA_VLAN_ACT_MODIFY vlan action Shmulik Ladkani
@ 2016-09-18 19:41   ` Jamal Hadi Salim
  0 siblings, 0 replies; 4+ messages in thread
From: Jamal Hadi Salim @ 2016-09-18 19:41 UTC (permalink / raw)
  To: Shmulik Ladkani, David S . Miller; +Cc: Jiri Pirko, netdev

On 16-09-18 10:33 AM, Shmulik Ladkani wrote:
> 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 <shmulik.ladkani@gmail.com>
> ---
>  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..e5eeaa7a01 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:
> +		if (!skb_vlan_tagged(skb))
> +			goto unlock;
> +		/* extract existing tag (and guarantee no hwaccel tag) */
> +		if (skb_vlan_tag_present(skb)) {
> +			tci = skb_vlan_tag_get(skb);
> +			skb->vlan_tci = 0;
> +		} else {
> +			if (skb->mac_len < VLAN_ETH_HLEN)
> +				goto unlock;
> +			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) ||
>


Nice. If you didnt do it I would have ;->

Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>

cheers,
jamal

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-09-18 19:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-18 14:33 [PATCH net-next 0/2] act_vlan: Introduce TCA_VLAN_ACT_MODIFY vlan action Shmulik Ladkani
2016-09-18 14:33 ` [PATCH net-next 1/2] net: skbuff: Export __skb_vlan_pop Shmulik Ladkani
2016-09-18 14:33 ` [PATCH net-next 2/2] net/sched: act_vlan: Introduce TCA_VLAN_ACT_MODIFY vlan action Shmulik Ladkani
2016-09-18 19:41   ` Jamal Hadi Salim

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.