summaryrefslogtreecommitdiffstats
path: root/net/netfilter/nf_conntrack_ovs.c
diff options
context:
space:
mode:
authorXin Long <lucien.xin@gmail.com>2023-02-07 17:52:07 -0500
committerJakub Kicinski <kuba@kernel.org>2023-02-10 16:23:03 -0800
commit67fc5d7ffbd4f9cf52adf166f5bc9a35fef37f24 (patch)
tree9e881e3ed7c81476940bb886408b157809964cf2 /net/netfilter/nf_conntrack_ovs.c
parentc0c3ab63de603b40f89a9c0d7217209a8840d053 (diff)
downloadlinux-67fc5d7ffbd4f9cf52adf166f5bc9a35fef37f24.tar.gz
linux-67fc5d7ffbd4f9cf52adf166f5bc9a35fef37f24.tar.bz2
linux-67fc5d7ffbd4f9cf52adf166f5bc9a35fef37f24.zip
net: extract nf_ct_skb_network_trim function to nf_conntrack_ovs
There are almost the same code in ovs_skb_network_trim() and tcf_ct_skb_network_trim(), this patch extracts them into a function nf_ct_skb_network_trim() and moves the function to nf_conntrack_ovs. Signed-off-by: Xin Long <lucien.xin@gmail.com> Reviewed-by: Simon Horman <simon.horman@corigine.com> Reviewed-by: Aaron Conole <aconole@redhat.com> Acked-by: Florian Westphal <fw@strlen.de> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'net/netfilter/nf_conntrack_ovs.c')
-rw-r--r--net/netfilter/nf_conntrack_ovs.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/net/netfilter/nf_conntrack_ovs.c b/net/netfilter/nf_conntrack_ovs.c
index eff4d53f8b8c..c60ef71d1aea 100644
--- a/net/netfilter/nf_conntrack_ovs.c
+++ b/net/netfilter/nf_conntrack_ovs.c
@@ -102,3 +102,29 @@ int nf_ct_add_helper(struct nf_conn *ct, const char *name, u8 family,
return ret;
}
EXPORT_SYMBOL_GPL(nf_ct_add_helper);
+
+/* Trim the skb to the length specified by the IP/IPv6 header,
+ * removing any trailing lower-layer padding. This prepares the skb
+ * for higher-layer processing that assumes skb->len excludes padding
+ * (such as nf_ip_checksum). The caller needs to pull the skb to the
+ * network header, and ensure ip_hdr/ipv6_hdr points to valid data.
+ */
+int nf_ct_skb_network_trim(struct sk_buff *skb, int family)
+{
+ unsigned int len;
+
+ switch (family) {
+ case NFPROTO_IPV4:
+ len = skb_ip_totlen(skb);
+ break;
+ case NFPROTO_IPV6:
+ len = sizeof(struct ipv6hdr)
+ + ntohs(ipv6_hdr(skb)->payload_len);
+ break;
+ default:
+ len = skb->len;
+ }
+
+ return pskb_trim_rcsum(skb, len);
+}
+EXPORT_SYMBOL_GPL(nf_ct_skb_network_trim);