net: move vlan pop/push functions into common code
Subsystems (4)
Jiri Pirko
maintainerPATCH 1/2 net: move vlan pop/push functions into common code
So it can be used from out of openvswitch code.
Did couple of cosmetic changes on the way, namely variable naming and adding support for 8021AD proto.
--- include/linux/skbuff.h | 2 ++ net/core/skbuff.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++ net/openvswitch/actions.c | 76 ++--------------------------------------- 3 files changed, 90 insertions(+), 74 deletions(-)
include/linux/skbuff.h +2 -0
@@ -2673,6 +2673,8 @@ void skb_scrub_packet(struct sk_buff *skb, bool xnet);unsigned int skb_gso_transport_seglen (const struct sk_buff *skb);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_vlan_pop (struct sk_buff *skb); +int skb_vlan_push (struct sk_buff *skb,__be16 vlan_proto,u16 vlan_tci);struct skb_checksum_ops {__wsum (*update)(const void *mem,int len,__wsum wsum);
net/core/skbuff.c +86 -0
92 lines not on this page · raw message
net/openvswitch/actions.c +2 -74
88 lines not on this page · raw message
Signature · 1 line
1.9.3
Jiri Pirko
maintainerPATCH 2/2 sched: introduce vlan action
This tc action allows to work with vlan tagged skbs. Two supported sub-actions are header pop and header push.
--- include/net/tc_act/tc_vlan.h | 27 +++++ include/uapi/linux/tc_act/tc_vlan.h | 35 ++++++ net/sched/Kconfig | 11 ++ net/sched/Makefile | 1 + net/sched/act_vlan.c | 207 ++++++++++++++++++++++++++++++++++++ 5 files changed, 281 insertions(+) create mode 100644 include/net/tc_act/tc_vlan.h create mode 100644 include/uapi/linux/tc_act/tc_vlan.h create mode 100644 net/sched/act_vlan.c
include/net/tc_act/tc_vlan.h new file +27 -0
@@ -0,0 +1,27 @@ +/* +* Copyright (c) 2014 Jiri Pirko <[email protected]> +* +* 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. +*/ + +#ifndef __NET_TC_VLAN_H +#define __NET_TC_VLAN_H + +#include <net/act_api.h> + +#define VLAN_F_POP 0x1 +#define VLAN_F_PUSH 0x2 + +struct tcf_vlan { +struct tcf_common common; +int tcfv_action; +__be16 tcfv_push_vid; +__be16 tcfv_push_proto; +}; +#define to_vlan (a) \ + container_of(a->priv, struct tcf_vlan, common) + +#endif /* __NET_TC_VLAN_H */
include/uapi/linux/tc_act/tc_vlan.h new file +35 -0
@@ -0,0 +1,35 @@ +/* +* Copyright (c) 2014 Jiri Pirko <[email protected]> +* +* 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. +*/ + +#ifndef __LINUX_TC_VLAN_H +#define __LINUX_TC_VLAN_H + +#include <linux/pkt_cls.h> + +#define TCA_ACT_VLAN 12 + +#define TCA_VLAN_ACT_POP 1 +#define TCA_VLAN_ACT_PUSH 2 + +struct tc_vlan { +tc_gen ; +int v_action; +}; + +enum { +TCA_VLAN_UNSPEC , +TCA_VLAN_TM , +TCA_VLAN_PARMS , +TCA_VLAN_PUSH_VLAN_ID , +TCA_VLAN_PUSH_VLAN_PROTOCOL , + __TCA_VLAN_MAX, +}; +#define TCA_VLAN_MAX (__TCA_VLAN_MAX - 1) + +#endif
net/sched/Kconfig +11 -0
@@ -686,6 +686,17 @@ config NET_ACT_CSUM To compile this code as a module, choose M here: the module will be called act_csum. +config NET_ACT_VLAN + tristate "Vlan manipulation" + depends on NET_CLS_ACT + ---help--- + Say Y here to push or pop vlan headers. + + If unsure, say N. + + To compile this code as a module, choose M here: the + module will be called act_vlan. + config NET_CLS_IND bool "Incoming device classification" depends on NET_CLS_U32 || NET_CLS_FW
net/sched/Makefile +1 -0
@@ -16,6 +16,7 @@ obj-$(CONFIG_NET_ACT_PEDIT) += act_pedit.o obj-$(CONFIG_NET_ACT_SIMP) += act_simple.o obj-$(CONFIG_NET_ACT_SKBEDIT) += act_skbedit.o obj-$(CONFIG_NET_ACT_CSUM) += act_csum.o +obj-$(CONFIG_NET_ACT_VLAN) += act_vlan.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
net/sched/act_vlan.c new file +207 -0
207 lines not on this page · raw message
Signature · 1 line
1.9.3
Jamal Hadi Salim
maintainerRe: [patch net-next 2/2] sched: introduce vlan action
Quoted 4 lines · Jiri Pirko
This tc action allows to work with vlan tagged skbs. Two supported sub-actions are header pop and header push.
Signed-off-by Jiri Pirko <[email protected]>
Looks good. I am going to test it - but dont see any obvious issues I from inspection; willing to say:
cheers,
jamal
Re: [patch net-next 2/2] sched: introduce vlan action
In reply to Jiri PirkoQuoted 20 lines · Jiri Pirko
net/sched/act_vlan.c new file +20
-0+static int tcf_vlan_init (struct net *net,struct nlattr *nla, +struct nlattr *est,struct tc_action *a, +int ovr,int bind) +{ +struct nlattr *tb[TCA_VLAN_MAX +1 ]; +struct tc_vlan *parm; +struct tcf_vlan *v; +int action; +__be16 push_vid =0 ; +__be16 push_proto =0 ; +int ret =0 ; +int err; + +if (!nla) +return -EINVAL ; + + err =nla_parse_nested (tb,TCA_VLAN_MAX , nla, vlan_policy); +if (err <0 ) +return err; +
net/sched/act_vlan.c line 96
Quoted 10 lines
net/sched/act_vlan.c new file +10
-0+if (!tb[TCA_VLAN_PARMS ]) +return -EINVAL ; + parm =nla_data (tb[TCA_VLAN_PARMS ]); +switch (parm->v_action) { +case TCA_VLAN_ACT_POP : +break ; +case TCA_VLAN_ACT_PUSH : +if (!tb[TCA_VLAN_PUSH_VLAN_ID ]) +return -EINVAL ; + push_vid =nla_get_u16 (tb[TCA_VLAN_PUSH_VLAN_ID ]);
nla_get_be16() ?
net/sched/act_vlan.c line 99
Quoted 3 lines
net/sched/act_vlan.c new file +3
-0+if (push_vid >=VLAN_VID_MASK ) +return -ERANGE ; +
htons() ?
[...]
Quoted 11 lines
net/sched/act_vlan.c new file +11
-0+static int tcf_vlan_dump (struct sk_buff *skb,struct tc_action *a, +int bind,int ref) +{ +unsigned char *b =skb_tail_pointer (skb); +struct tcf_vlan *v = a->priv; +struct tc_vlan opt = { + .index = v->tcf_index, + .refcnt = v->tcf_refcnt - ref, + .bindcnt = v->tcf_bindcnt - bind, + .action = v->tcf_action, + .v_action = v->tcfv_action,
net/sched/act_vlan.c line 169
Quoted 10 lines
net/sched/act_vlan.c new file +10
-0+ }; +struct tcf_t t; + +if (nla_put (skb,TCA_VLAN_PARMS ,sizeof (opt), &opt)) + goto nla_put_failure; + +if (v->tcfv_action ==TCA_VLAN_ACT_PUSH && +nla_put_u16 (skb,TCA_VLAN_PUSH_VLAN_ID , v->tcfv_push_vid) && +nla_put_u16 (skb,TCA_VLAN_PUSH_VLAN_PROTOCOL , v->tcfv_push_proto)) + goto nla_put_failure;
nla_put_be16() ?
Jiri Pirko
maintainerRe: [patch net-next 2/2] sched: introduce vlan action
Quoted 25 lines · Tue, Nov 11, 2014 at 11:33:21PM CET, [email protected] wrote:
Quoted 24 lines · Jiri Pirko
net/sched/act_vlan.c new file +24
-0+static int tcf_vlan_init (struct net *net,struct nlattr *nla, +struct nlattr *est,struct tc_action *a, +int ovr,int bind) +{ +struct nlattr *tb[TCA_VLAN_MAX +1 ]; +struct tc_vlan *parm; +struct tcf_vlan *v; +int action; +__be16 push_vid =0 ; +__be16 push_proto =0 ; +int ret =0 ; +int err; + +if (!nla) +return -EINVAL ; + + err =nla_parse_nested (tb,TCA_VLAN_MAX , nla, vlan_policy); +if (err <0 ) +return err; + +if (!tb[TCA_VLAN_PARMS ]) +return -EINVAL ; + parm =nla_data (tb[TCA_VLAN_PARMS ]); +switch (parm->v_action) {
Quoted 8 lines
net/sched/act_vlan.c line 96
Quoted 6 lines
net/sched/act_vlan.c new file +6
-0+case TCA_VLAN_ACT_POP : +break ; +case TCA_VLAN_ACT_PUSH : +if (!tb[TCA_VLAN_PUSH_VLAN_ID ]) +return -EINVAL ; + push_vid =nla_get_u16 (tb[TCA_VLAN_PUSH_VLAN_ID ]);
nla_get_be16()?
No. I made this the same as it is done in net/8021q/vlan_netlink.c
Quoted 33 lines
net/sched/act_vlan.c line 99
Quoted 5 lines
net/sched/act_vlan.c new file +3
-0+if (push_vid >=VLAN_VID_MASK ) +return -ERANGE ; +
htons()?[...]
Quoted 11 lines
net/sched/act_vlan.c new file +11
-0+static int tcf_vlan_dump (struct sk_buff *skb,struct tc_action *a, +int bind,int ref) +{ +unsigned char *b =skb_tail_pointer (skb); +struct tcf_vlan *v = a->priv; +struct tc_vlan opt = { + .index = v->tcf_index, + .refcnt = v->tcf_refcnt - ref, + .bindcnt = v->tcf_bindcnt - bind, + .action = v->tcf_action, + .v_action = v->tcfv_action,net/sched/act_vlan.c line 169
Quoted 10 lines
net/sched/act_vlan.c new file +10
-0+ }; +struct tcf_t t; + +if (nla_put (skb,TCA_VLAN_PARMS ,sizeof (opt), &opt)) + goto nla_put_failure; + +if (v->tcfv_action ==TCA_VLAN_ACT_PUSH && +nla_put_u16 (skb,TCA_VLAN_PUSH_VLAN_ID , v->tcfv_push_vid) && +nla_put_u16 (skb,TCA_VLAN_PUSH_VLAN_PROTOCOL , v->tcfv_push_proto)) + goto nla_put_failure;
nla_put_be16()?
Jamal Hadi Salim
maintainerRe: [patch net-next 2/2] sched: introduce vlan action
Quoted 35 lines · Jiri Pirko
Quoted 25 lines · Tue, Nov 11, 2014 at 11:33:21PM CET, [email protected] wrote:
Quoted 24 lines · Jiri Pirko
net/sched/act_vlan.c new file +24
-0+static int tcf_vlan_init (struct net *net,struct nlattr *nla, +struct nlattr *est,struct tc_action *a, +int ovr,int bind) +{ +struct nlattr *tb[TCA_VLAN_MAX +1 ]; +struct tc_vlan *parm; +struct tcf_vlan *v; +int action; +__be16 push_vid =0 ; +__be16 push_proto =0 ; +int ret =0 ; +int err; + +if (!nla) +return -EINVAL ; + + err =nla_parse_nested (tb,TCA_VLAN_MAX , nla, vlan_policy); +if (err <0 ) +return err; + +if (!tb[TCA_VLAN_PARMS ]) +return -EINVAL ; + parm =nla_data (tb[TCA_VLAN_PARMS ]); +switch (parm->v_action) {Quoted 8 lines
net/sched/act_vlan.c line 96
Quoted 6 lines
net/sched/act_vlan.c new file +6
-0+case TCA_VLAN_ACT_POP : +break ; +case TCA_VLAN_ACT_PUSH : +if (!tb[TCA_VLAN_PUSH_VLAN_ID ]) +return -EINVAL ; + push_vid =nla_get_u16 (tb[TCA_VLAN_PUSH_VLAN_ID ]);
nla_get_be16()?
Quoted 2 lines
No. I made this the same as it is done in
net/8021q/vlan_netlink.c
It just happens that user space passes it to you in BE already. So this works out because skb_vlan_push expects that to be in BE as in:
int skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci)
cheers,
jamal
Jamal Hadi Salim
maintainerRe: [patch net-next 2/2] sched: introduce vlan action
Quoted 7 lines · Jamal Hadi Salim
On 11/12/14 07:34, Jiri Pirko wrote:
It just happens that user space passes it to you in BE already. So this works out because
skb_vlan_pushexpects that to be in BE as in:
intskb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci)
Sorry, meant proto is in BE but vlan is in host order.. (grr.. need to test).
cheers,
jamal
Re: [patch net-next 2/2] sched: introduce vlan action
In reply to Jiri PirkoQuoted 3 lines · Jiri Pirko
This tc action allows to work with vlan tagged skbs. Two supported sub-actions are header pop and header push.
Can we add this to skbedit instead of adding a new action?
I know vlan tag is not exactly the skb metadata, but still seems fits in skbedit for me.
Jiri Pirko
maintainerRe: [patch net-next 2/2] sched: introduce vlan action
Quoted 9 lines · Wed, Nov 12, 2014 at 12:18:47AM CET, [email protected] wrote:
Quoted 3 lines · Jiri Pirko
This tc action allows to work with vlan tagged skbs. Two supported sub-actions are header pop and header push.
Can we add this to skbedit instead of adding a new action?
I know vlan tag is not exactly the skb metadata, but still seems fits in skbedit for me.
I was thinking about that as well. It seems much clearer to add a new action.
Jamal Hadi Salim
maintainerRe: [patch net-next 2/2] sched: introduce vlan action
Quoted 8 lines · Jiri Pirko
Quoted 2 lines · Wed, Nov 12, 2014 at 12:18:47AM CET, [email protected] wrote:
I know vlan tag is not exactly the skb metadata, but still seems fits in skbedit for me.
I was thinking about that as well. It seems much clearer to add a new action.
Cong,
I think it is better to have all these "tunneling" activities as a separate action each. It is cleaner from a usability perspective. [e.g. it is not hard to express nat action with pedit action or take checksum out of nat since we have a csum action), but makes sense to have it separate)].
cheers,
jamal
Re: [patch net-next 2/2] sched: introduce vlan action
Quoted 8 lines · Jamal Hadi Salim
Cong,
I think it is better to have all these "tunneling" activities as a separate action each. It is cleaner from a usability perspective. [e.g. it is not hard to express nat action with pedit action or take checksum out of nat since we have a csum action), but makes sense to have it separate)].
Sounds good.
Quoted 40 lines · Jiri Pirko
So it can be used from out of openvswitch code.
Did couple of cosmetic changes on the way, namely variable naming and adding support for 8021AD proto.Signed-off-by Jiri Pirko <[email protected]>--- include/linux/skbuff.h | 2 ++ net/core/skbuff.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++ net/openvswitch/actions.c | 76 ++--------------------------------------- 3 files changed, 90 insertions(+), 74 deletions(-)include/linux/skbuff.h +2
-0@@ -2673,6 +2673,8 @@ void skb_scrub_packet(struct sk_buff *skb, bool xnet);unsigned int skb_gso_transport_seglen (const struct sk_buff *skb);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_vlan_pop (struct sk_buff *skb); +int skb_vlan_push (struct sk_buff *skb,__be16 vlan_proto,u16 vlan_tci);struct skb_checksum_ops {__wsum (*update)(const void *mem,int len,__wsum wsum);net/core/skbuff.c +6
-0@@ -4151,6 +4151,92 @@ err_free: }EXPORT_SYMBOL (skb_vlan_untag); +/* remove VLAN header from packet and update csum accordingly. */ +static int __skb_vlan_pop (struct sk_buff *skb,u16 *vlan_tci) +{ +struct vlan_hdr *vhdr; +int err; +
net/core/skbuff.c err_free: · line 4171
Quoted 10 lines
net/core/skbuff.c +9
-0+if (!pskb_may_pull (skb,VLAN_ETH_HLEN )) +return -ENOMEM ; + +if (!skb_cloned (skb) ||skb_clone_writable (skb,VLAN_ETH_HLEN )) +return 0 ; + + err =pskb_expand_head (skb,0 ,0 ,GFP_ATOMIC ); +if (unlikely (err)) +return err;
All this should be a function of its own (OVS calls this make_writable()).
Its too bad netfilter has a different skb_make_writable()
net/core/skbuff.c err_free: · line 4172
Quoted 4 lines
net/core/skbuff.c +4
-0+ +if (skb->ip_summed ==CHECKSUM_COMPLETE ) + skb->csum =csum_sub (skb->csum,csum_partial (skb->data + + (2 *ETH_ALEN ),VLAN_HLEN ,0 ));
This looks like skb_postpull_rcsum()
BTW, calling csum_partial() for 4 bytes is quite expensive.
Jiri Pirko
maintainerQuoted 55 lines · Tue, Nov 11, 2014 at 02:06:21PM CET, [email protected] wrote:
Quoted 40 lines · Jiri Pirko
So it can be used from out of openvswitch code.
Did couple of cosmetic changes on the way, namely variable naming and adding support for 8021AD proto.Signed-off-by Jiri Pirko <[email protected]>--- include/linux/skbuff.h | 2 ++ net/core/skbuff.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++ net/openvswitch/actions.c | 76 ++--------------------------------------- 3 files changed, 90 insertions(+), 74 deletions(-)include/linux/skbuff.h +2
-0@@ -2673,6 +2673,8 @@ void skb_scrub_packet(struct sk_buff *skb, bool xnet);unsigned int skb_gso_transport_seglen (const struct sk_buff *skb);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_vlan_pop (struct sk_buff *skb); +int skb_vlan_push (struct sk_buff *skb,__be16 vlan_proto,u16 vlan_tci);struct skb_checksum_ops {__wsum (*update)(const void *mem,int len,__wsum wsum);net/core/skbuff.c +6
-0@@ -4151,6 +4151,92 @@ err_free: }EXPORT_SYMBOL (skb_vlan_untag); +/* remove VLAN header from packet and update csum accordingly. */ +static int __skb_vlan_pop (struct sk_buff *skb,u16 *vlan_tci) +{ +struct vlan_hdr *vhdr; +int err; +net/core/skbuff.c err_free: · line 4171
Quoted 10 lines
net/core/skbuff.c +9
-0+if (!pskb_may_pull (skb,VLAN_ETH_HLEN )) +return -ENOMEM ; + +if (!skb_cloned (skb) ||skb_clone_writable (skb,VLAN_ETH_HLEN )) +return 0 ; + + err =pskb_expand_head (skb,0 ,0 ,GFP_ATOMIC ); +if (unlikely (err)) +return err;All this should be a function of its own (OVS calls this
make_writable()).
Quoted 1 line
Its too bad netfilter has a different
skb_make_writable()
How different is that? Looking at it it seems it is doing the same thing. Not sure though...
Quoted 13 lines
net/core/skbuff.c err_free: · line 4172
Quoted 6 lines
net/core/skbuff.c +4
-0+ +if (skb->ip_summed ==CHECKSUM_COMPLETE ) + skb->csum =csum_sub (skb->csum,csum_partial (skb->data + + (2 *ETH_ALEN ),VLAN_HLEN ,0 ));This looks like
skb_postpull_rcsum()BTW, calling
csum_partial()for 4 bytes is quite expensive.
Quoted 99 lines · Jiri Pirko
So it can be used from out of openvswitch code.
Did couple of cosmetic changes on the way, namely variable naming and adding support for 8021AD proto.Signed-off-by Jiri Pirko <[email protected]>--- include/linux/skbuff.h | 2 ++ net/core/skbuff.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++ net/openvswitch/actions.c | 76 ++--------------------------------------- 3 files changed, 90 insertions(+), 74 deletions(-)include/linux/skbuff.h +2
-0@@ -2673,6 +2673,8 @@ void skb_scrub_packet(struct sk_buff *skb, bool xnet);unsigned int skb_gso_transport_seglen (const struct sk_buff *skb);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_vlan_pop (struct sk_buff *skb); +int skb_vlan_push (struct sk_buff *skb,__be16 vlan_proto,u16 vlan_tci);struct skb_checksum_ops {__wsum (*update)(const void *mem,int len,__wsum wsum);net/core/skbuff.c +67
-0@@ -4151,6 +4151,92 @@ err_free: }EXPORT_SYMBOL (skb_vlan_untag); +/* remove VLAN header from packet and update csum accordingly. */ +static int __skb_vlan_pop (struct sk_buff *skb,u16 *vlan_tci) +{ +struct vlan_hdr *vhdr; +int err; + +if (!pskb_may_pull (skb,VLAN_ETH_HLEN )) +return -ENOMEM ; + +if (!skb_cloned (skb) ||skb_clone_writable (skb,VLAN_ETH_HLEN )) +return 0 ; + + err =pskb_expand_head (skb,0 ,0 ,GFP_ATOMIC ); +if (unlikely (err)) +return err; + +if (skb->ip_summed ==CHECKSUM_COMPLETE ) + skb->csum =csum_sub (skb->csum,csum_partial (skb->data + + (2 *ETH_ALEN ),VLAN_HLEN ,0 )); + + vhdr = (struct vlan_hdr *)(skb->data +ETH_HLEN ); + *vlan_tci =ntohs (vhdr->h_vlan_TCI); + +memmove (skb->data +VLAN_HLEN , skb->data,2 *ETH_ALEN ); +__skb_pull (skb,VLAN_HLEN ); + +vlan_set_encap_proto (skb, vhdr); + skb->mac_header +=VLAN_HLEN ; +if (skb_network_offset (skb) <ETH_HLEN ) +skb_set_network_header (skb,ETH_HLEN ); +skb_reset_mac_len (skb); + +return 0 ; +} + +int skb_vlan_pop (struct sk_buff *skb) +{ +u16 vlan_tci; +__be16 vlan_proto; +int err; + +if (likely (vlan_tx_tag_present (skb))) { + skb->vlan_tci =0 ; + }else { +if (unlikely ((skb->protocol !=htons (ETH_P_8021Q ) && + skb->protocol !=htons (ETH_P_8021AD )) || + skb->len <VLAN_ETH_HLEN )) +return 0 ; + + err =__skb_vlan_pop (skb, &vlan_tci); +if (err) +return err; + } +/* move next vlan tag to hw accel tag */ +if (likely ((skb->protocol !=htons (ETH_P_8021Q ) && + skb->protocol !=htons (ETH_P_8021AD )) || + skb->len <VLAN_ETH_HLEN )) +return 0 ; + + vlan_proto = skb->protocol; + err =__skb_vlan_pop (skb, &vlan_tci); +if (unlikely (err)) +return err; + +__vlan_hwaccel_put_tag (skb, vlan_proto, vlan_tci); +return 0 ; +}
net/core/skbuff.c err_free: · line 4230
Quoted 10 lines
net/core/skbuff.c +10
-0+EXPORT_SYMBOL (skb_vlan_pop); + +int skb_vlan_push (struct sk_buff *skb,__be16 vlan_proto,u16 vlan_tci) +{ +if (vlan_tx_tag_present (skb)) { +/* push down current VLAN tag */ +if (!__vlan_put_tag (skb, skb->vlan_proto, +vlan_tx_tag_get (skb))) +return -ENOMEM ; +
Since you are restructuring this code, can you also change __vlan_put_tag() to not free skb on error. So that these two new functions can have common error handling code.
Quoted 108 lines
net/core/skbuff.c +9
-0+if (skb->ip_summed ==CHECKSUM_COMPLETE ) + skb->csum =csum_add (skb->csum,csum_partial (skb->data + + (2 *ETH_ALEN ),VLAN_HLEN ,0 )); + } +__vlan_hwaccel_put_tag (skb, vlan_proto, vlan_tci); +return 0 ; +} +EXPORT_SYMBOL (skb_vlan_push); +/** * alloc_skb_with_frags - allocate skb with page frags * net/openvswitch/actions.c +2
-75@@ -206,86 +206,14 @@ static int set_mpls(struct sk_buff *skb, const __be32 *mpls_lse)return 0 ; } -/* remove VLAN header from packet and update csum accordingly. */ -static int __pop_vlan_tci (struct sk_buff *skb,__be16 *current_tci) -{ -struct vlan_hdr *vhdr; -int err; - - err =make_writable (skb,VLAN_ETH_HLEN ); -if (unlikely (err)) -return err; - -if (skb->ip_summed ==CHECKSUM_COMPLETE ) - skb->csum =csum_sub (skb->csum,csum_partial (skb->data - + (2 *ETH_ALEN ),VLAN_HLEN ,0 )); - - vhdr = (struct vlan_hdr *)(skb->data +ETH_HLEN ); - *current_tci = vhdr->h_vlan_TCI; - -memmove (skb->data +VLAN_HLEN , skb->data,2 *ETH_ALEN ); -__skb_pull (skb,VLAN_HLEN ); - -vlan_set_encap_proto (skb, vhdr); - skb->mac_header +=VLAN_HLEN ; - -if (skb_network_offset (skb) <ETH_HLEN ) -skb_set_network_header (skb,ETH_HLEN ); - -/* Update mac_len for subsequent MPLS actions */ -skb_reset_mac_len (skb); -return 0 ; -} -static int pop_vlan (struct sk_buff *skb) { -__be16 tci; -int err; - -if (likely (vlan_tx_tag_present (skb))) { - skb->vlan_tci =0 ; - }else { -if (unlikely (skb->protocol !=htons (ETH_P_8021Q ) || - skb->len <VLAN_ETH_HLEN )) -return 0 ; - - err =__pop_vlan_tci (skb, &tci); -if (err) -return err; - } -/* move next vlan tag to hw accel tag */ -if (likely (skb->protocol !=htons (ETH_P_8021Q ) || - skb->len <VLAN_ETH_HLEN )) -return 0 ; - - err =__pop_vlan_tci (skb, &tci); -if (unlikely (err)) -return err; - -__vlan_hwaccel_put_tag (skb,htons (ETH_P_8021Q ),ntohs (tci)); -return 0 ; +return skb_vlan_pop (skb); }static int push_vlan (struct sk_buff *skb,const struct ovs_action_push_vlan *vlan) { -if (unlikely (vlan_tx_tag_present (skb))) { -u16 current_tag; - -/* push down current VLAN tag */ - current_tag =vlan_tx_tag_get (skb); - -if (!__vlan_put_tag (skb, skb->vlan_proto, current_tag)) -return -ENOMEM ; -/* Update mac_len for subsequent MPLS actions */ - skb->mac_len +=VLAN_HLEN ; - -if (skb->ip_summed ==CHECKSUM_COMPLETE ) - skb->csum =csum_add (skb->csum,csum_partial (skb->data - + (2 *ETH_ALEN ),VLAN_HLEN ,0 )); - - } -__vlan_hwaccel_put_tag (skb, vlan->vlan_tpid,ntohs (vlan->vlan_tci) & ~VLAN_TAG_PRESENT ); -return 0 ; +return skb_vlan_push (skb, vlan->vlan_tpid,ntohs (vlan->vlan_tci) & ~VLAN_TAG_PRESENT ); } static int set_eth_addr(struct sk_buff *skb, --1.9.3
Jiri Pirko
maintainerQuoted 105 lines · Tue, Nov 11, 2014 at 06:24:15PM CET, [email protected] wrote:
Quoted 104 lines · Jiri Pirko
So it can be used from out of openvswitch code.
Did couple of cosmetic changes on the way, namely variable naming and adding support for 8021AD proto.Signed-off-by Jiri Pirko <[email protected]>--- include/linux/skbuff.h | 2 ++ net/core/skbuff.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++ net/openvswitch/actions.c | 76 ++--------------------------------------- 3 files changed, 90 insertions(+), 74 deletions(-)include/linux/skbuff.h +2
-0@@ -2673,6 +2673,8 @@ void skb_scrub_packet(struct sk_buff *skb, bool xnet);unsigned int skb_gso_transport_seglen (const struct sk_buff *skb);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_vlan_pop (struct sk_buff *skb); +int skb_vlan_push (struct sk_buff *skb,__be16 vlan_proto,u16 vlan_tci);struct skb_checksum_ops {__wsum (*update)(const void *mem,int len,__wsum wsum);net/core/skbuff.c +72
-0@@ -4151,6 +4151,92 @@ err_free: }EXPORT_SYMBOL (skb_vlan_untag); +/* remove VLAN header from packet and update csum accordingly. */ +static int __skb_vlan_pop (struct sk_buff *skb,u16 *vlan_tci) +{ +struct vlan_hdr *vhdr; +int err; + +if (!pskb_may_pull (skb,VLAN_ETH_HLEN )) +return -ENOMEM ; + +if (!skb_cloned (skb) ||skb_clone_writable (skb,VLAN_ETH_HLEN )) +return 0 ; + + err =pskb_expand_head (skb,0 ,0 ,GFP_ATOMIC ); +if (unlikely (err)) +return err; + +if (skb->ip_summed ==CHECKSUM_COMPLETE ) + skb->csum =csum_sub (skb->csum,csum_partial (skb->data + + (2 *ETH_ALEN ),VLAN_HLEN ,0 )); + + vhdr = (struct vlan_hdr *)(skb->data +ETH_HLEN ); + *vlan_tci =ntohs (vhdr->h_vlan_TCI); + +memmove (skb->data +VLAN_HLEN , skb->data,2 *ETH_ALEN ); +__skb_pull (skb,VLAN_HLEN ); + +vlan_set_encap_proto (skb, vhdr); + skb->mac_header +=VLAN_HLEN ; +if (skb_network_offset (skb) <ETH_HLEN ) +skb_set_network_header (skb,ETH_HLEN ); +skb_reset_mac_len (skb); + +return 0 ; +} + +int skb_vlan_pop (struct sk_buff *skb) +{ +u16 vlan_tci; +__be16 vlan_proto; +int err; + +if (likely (vlan_tx_tag_present (skb))) { + skb->vlan_tci =0 ; + }else { +if (unlikely ((skb->protocol !=htons (ETH_P_8021Q ) && + skb->protocol !=htons (ETH_P_8021AD )) || + skb->len <VLAN_ETH_HLEN )) +return 0 ; + + err =__skb_vlan_pop (skb, &vlan_tci); +if (err) +return err; + } +/* move next vlan tag to hw accel tag */ +if (likely ((skb->protocol !=htons (ETH_P_8021Q ) && + skb->protocol !=htons (ETH_P_8021AD )) || + skb->len <VLAN_ETH_HLEN )) +return 0 ; + + vlan_proto = skb->protocol; + err =__skb_vlan_pop (skb, &vlan_tci); +if (unlikely (err)) +return err; + +__vlan_hwaccel_put_tag (skb, vlan_proto, vlan_tci); +return 0 ; +} +EXPORT_SYMBOL (skb_vlan_pop); + +int skb_vlan_push (struct sk_buff *skb,__be16 vlan_proto,u16 vlan_tci) +{ +if (vlan_tx_tag_present (skb)) {
Quoted 8 lines
net/core/skbuff.c err_free: · line 4230
Quoted 5 lines
net/core/skbuff.c +5
-0+/* push down current VLAN tag */ +if (!__vlan_put_tag (skb, skb->vlan_proto, +vlan_tx_tag_get (skb))) +return -ENOMEM ; +Since you are restructuring this code, can you also change
__vlan_put_tag()to not free skb on error. So that these two new functions can have common error handling code.
That is not directly related to this patchset. I believe that should be changed in separate patch later on.
David Miller
maintainerFrom: Jiri Pirko <[email protected]>
Date: Wed, 12 Nov 2014 12:59:33 +0100
Quoted 2 lines
That is not directly related to this patchset. I believe that should be changed in separate patch later on.
+1, but this has been a long standing issue and a large source of bugs.
Quoted 115 lines · Jiri Pirko
Quoted 105 lines · Tue, Nov 11, 2014 at 06:24:15PM CET, [email protected] wrote:
Quoted 104 lines · Jiri Pirko
So it can be used from out of openvswitch code.
Did couple of cosmetic changes on the way, namely variable naming and adding support for 8021AD proto.Signed-off-by Jiri Pirko <[email protected]>--- include/linux/skbuff.h | 2 ++ net/core/skbuff.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++ net/openvswitch/actions.c | 76 ++--------------------------------------- 3 files changed, 90 insertions(+), 74 deletions(-)include/linux/skbuff.h +2
-0@@ -2673,6 +2673,8 @@ void skb_scrub_packet(struct sk_buff *skb, bool xnet);unsigned int skb_gso_transport_seglen (const struct sk_buff *skb);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_vlan_pop (struct sk_buff *skb); +int skb_vlan_push (struct sk_buff *skb,__be16 vlan_proto,u16 vlan_tci);struct skb_checksum_ops {__wsum (*update)(const void *mem,int len,__wsum wsum);net/core/skbuff.c +72
-0@@ -4151,6 +4151,92 @@ err_free: }EXPORT_SYMBOL (skb_vlan_untag); +/* remove VLAN header from packet and update csum accordingly. */ +static int __skb_vlan_pop (struct sk_buff *skb,u16 *vlan_tci) +{ +struct vlan_hdr *vhdr; +int err; + +if (!pskb_may_pull (skb,VLAN_ETH_HLEN )) +return -ENOMEM ; + +if (!skb_cloned (skb) ||skb_clone_writable (skb,VLAN_ETH_HLEN )) +return 0 ; + + err =pskb_expand_head (skb,0 ,0 ,GFP_ATOMIC ); +if (unlikely (err)) +return err; + +if (skb->ip_summed ==CHECKSUM_COMPLETE ) + skb->csum =csum_sub (skb->csum,csum_partial (skb->data + + (2 *ETH_ALEN ),VLAN_HLEN ,0 )); + + vhdr = (struct vlan_hdr *)(skb->data +ETH_HLEN ); + *vlan_tci =ntohs (vhdr->h_vlan_TCI); + +memmove (skb->data +VLAN_HLEN , skb->data,2 *ETH_ALEN ); +__skb_pull (skb,VLAN_HLEN ); + +vlan_set_encap_proto (skb, vhdr); + skb->mac_header +=VLAN_HLEN ; +if (skb_network_offset (skb) <ETH_HLEN ) +skb_set_network_header (skb,ETH_HLEN ); +skb_reset_mac_len (skb); + +return 0 ; +} + +int skb_vlan_pop (struct sk_buff *skb) +{ +u16 vlan_tci; +__be16 vlan_proto; +int err; + +if (likely (vlan_tx_tag_present (skb))) { + skb->vlan_tci =0 ; + }else { +if (unlikely ((skb->protocol !=htons (ETH_P_8021Q ) && + skb->protocol !=htons (ETH_P_8021AD )) || + skb->len <VLAN_ETH_HLEN )) +return 0 ; + + err =__skb_vlan_pop (skb, &vlan_tci); +if (err) +return err; + } +/* move next vlan tag to hw accel tag */ +if (likely ((skb->protocol !=htons (ETH_P_8021Q ) && + skb->protocol !=htons (ETH_P_8021AD )) || + skb->len <VLAN_ETH_HLEN )) +return 0 ; + + vlan_proto = skb->protocol; + err =__skb_vlan_pop (skb, &vlan_tci); +if (unlikely (err)) +return err; + +__vlan_hwaccel_put_tag (skb, vlan_proto, vlan_tci); +return 0 ; +} +EXPORT_SYMBOL (skb_vlan_pop); + +int skb_vlan_push (struct sk_buff *skb,__be16 vlan_proto,u16 vlan_tci) +{ +if (vlan_tx_tag_present (skb)) {Quoted 8 lines
net/core/skbuff.c err_free: · line 4230
Quoted 5 lines
net/core/skbuff.c +5
-0+/* push down current VLAN tag */ +if (!__vlan_put_tag (skb, skb->vlan_proto, +vlan_tx_tag_get (skb))) +return -ENOMEM ; +Since you are restructuring this code, can you also change
__vlan_put_tag()to not free skb on error. So that these two new functions can have common error handling code.
Quoted 2 lines
That is not directly related to this patchset. I believe that should be changed in separate patch later on.
If you are not going to change this then I am not sure how tcf_vlan() (that is introduced in next patch) can have common error handling code.