diff mbox series

[net-next,1/2] skb: skb_vlan_push gets VLAN_HLEN as an argument

Message ID 20240711070828.2741351-2-boris.sukholitko@broadcom.com (mailing list archive)
State Deferred
Delegated to: Netdev Maintainers
Headers show
Series tc: adjust network header after second vlan push | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 869 this patch: 869
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 2 maintainers not CCed: bpf@vger.kernel.org dev@openvswitch.org
netdev/build_clang success Errors and warnings before: 933 this patch: 933
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 5902 this patch: 5902
netdev/checkpatch warning WARNING: line length of 81 exceeds 80 columns WARNING: line length of 82 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 119 this patch: 119
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-07-11--18-00 (tests: 696)

Commit Message

Boris Sukholitko July 11, 2024, 7:08 a.m. UTC
In case of vlan tagged packet, skb_vlan_push flushes current vlan header
into skb packet buffer. It also advances skb->mac_len by VLAN_HLEN
amount.

Some of the callers of skb_vlan_push (e.g. net/sched/act_vlan.c)
may want to reset skb network header by themselves.

To allow this we pass VLAN_HLEN as an argument to skb_vlan_push.

Signed-off-by: Boris Sukholitko <boris.sukholitko@broadcom.com>
---
 include/linux/skbuff.h    | 2 +-
 net/core/filter.c         | 2 +-
 net/core/skbuff.c         | 4 ++--
 net/openvswitch/actions.c | 3 ++-
 net/sched/act_vlan.c      | 3 ++-
 5 files changed, 8 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 9c29bdd5596d..e13f44fe33df 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -4046,7 +4046,7 @@  int skb_ensure_writable(struct sk_buff *skb, unsigned int write_len);
 int skb_ensure_writable_head_tail(struct sk_buff *skb, struct net_device *dev);
 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);
+int skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci, u16 hlen);
 int skb_eth_pop(struct sk_buff *skb);
 int skb_eth_push(struct sk_buff *skb, const unsigned char *dst,
 		 const unsigned char *src);
diff --git a/net/core/filter.c b/net/core/filter.c
index d767880c276d..bb14574422b5 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -3187,7 +3187,7 @@  BPF_CALL_3(bpf_skb_vlan_push, struct sk_buff *, skb, __be16, vlan_proto,
 		vlan_proto = htons(ETH_P_8021Q);
 
 	bpf_push_mac_rcsum(skb);
-	ret = skb_vlan_push(skb, vlan_proto, vlan_tci);
+	ret = skb_vlan_push(skb, vlan_proto, vlan_tci, VLAN_HLEN);
 	bpf_pull_mac_rcsum(skb);
 
 	bpf_compute_data_pointers(skb);
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 83f8cd8aa2d1..9c69c9bff55c 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -6223,7 +6223,7 @@  EXPORT_SYMBOL(skb_vlan_pop);
 /* Push a vlan tag either into hwaccel or into payload (if hwaccel tag present).
  * Expects skb->data at mac header.
  */
-int skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci)
+int skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci, u16 hlen)
 {
 	if (skb_vlan_tag_present(skb)) {
 		int offset = skb->data - skb_mac_header(skb);
@@ -6241,7 +6241,7 @@  int skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci)
 			return err;
 
 		skb->protocol = skb->vlan_proto;
-		skb->mac_len += VLAN_HLEN;
+		skb->mac_len += hlen;
 
 		skb_postpush_rcsum(skb, skb->data + (2 * ETH_ALEN), VLAN_HLEN);
 	}
diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c
index 101f9a23792c..34909aca3526 100644
--- a/net/openvswitch/actions.c
+++ b/net/openvswitch/actions.c
@@ -244,7 +244,8 @@  static int push_vlan(struct sk_buff *skb, struct sw_flow_key *key,
 		key->eth.vlan.tpid = vlan->vlan_tpid;
 	}
 	return skb_vlan_push(skb, vlan->vlan_tpid,
-			     ntohs(vlan->vlan_tci) & ~VLAN_CFI_MASK);
+			     ntohs(vlan->vlan_tci) & ~VLAN_CFI_MASK,
+			     VLAN_HLEN);
 }
 
 /* 'src' is already properly masked. */
diff --git a/net/sched/act_vlan.c b/net/sched/act_vlan.c
index 22f4b1e8ade9..f60cf7062572 100644
--- a/net/sched/act_vlan.c
+++ b/net/sched/act_vlan.c
@@ -50,7 +50,8 @@  TC_INDIRECT_SCOPE int tcf_vlan_act(struct sk_buff *skb,
 		break;
 	case TCA_VLAN_ACT_PUSH:
 		err = skb_vlan_push(skb, p->tcfv_push_proto, p->tcfv_push_vid |
-				    (p->tcfv_push_prio << VLAN_PRIO_SHIFT));
+				    (p->tcfv_push_prio << VLAN_PRIO_SHIFT),
+				    VLAN_HLEN);
 		if (err)
 			goto drop;
 		break;