All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHv2 net-next 0/5] net: move more duplicate code of ovs and tc conntrack into nf_conntrack_ovs
@ 2023-02-07 22:52 Xin Long
  2023-02-07 22:52 ` [PATCHv2 net-next 1/5] net: create nf_conntrack_ovs for ovs and tc use Xin Long
                   ` (6 more replies)
  0 siblings, 7 replies; 18+ messages in thread
From: Xin Long @ 2023-02-07 22:52 UTC (permalink / raw)
  To: network dev, dev
  Cc: davem, kuba, Eric Dumazet, Paolo Abeni, Pravin B Shelar,
	Jamal Hadi Salim, Cong Wang, Jiri Pirko, Pablo Neira Ayuso,
	Florian Westphal, Marcelo Ricardo Leitner, Ilya Maximets,
	Aaron Conole

We've moved some duplicate code into nf_nat_ovs in:

  "net: eliminate the duplicate code in the ct nat functions of ovs and tc"

This patchset addresses more code duplication in the conntrack of ovs
and tc then creates nf_conntrack_ovs for them, and four functions will
be extracted and moved into it:

  nf_ct_handle_fragments()
  nf_ct_skb_network_trim()
  nf_ct_helper()
  nf_ct_add_helper()

v1->v2:
  - In patch 1/5, fix the wrong option name 'NF_NF_CONNTRACK' used in
    net/openvswitch/Kconfig, found by kernel test robot.

Xin Long (5):
  net: create nf_conntrack_ovs for ovs and tc use
  net: extract nf_ct_skb_network_trim function to nf_conntrack_ovs
  openvswitch: move key and ovs_cb update out of handle_fragments
  net: sched: move frag check and tc_skb_cb update out of
    handle_fragments
  net: extract nf_ct_handle_fragments to nf_conntrack_ovs

 include/net/netfilter/nf_conntrack.h |   4 +
 net/netfilter/Kconfig                |   3 +
 net/netfilter/Makefile               |   1 +
 net/netfilter/nf_conntrack_helper.c  |  98 ---------------
 net/netfilter/nf_conntrack_ovs.c     | 178 +++++++++++++++++++++++++++
 net/openvswitch/Kconfig              |   1 +
 net/openvswitch/conntrack.c          |  80 ++----------
 net/sched/Kconfig                    |   1 +
 net/sched/act_ct.c                   |  76 ++----------
 9 files changed, 207 insertions(+), 235 deletions(-)
 create mode 100644 net/netfilter/nf_conntrack_ovs.c

-- 
2.31.1


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

* [PATCHv2 net-next 1/5] net: create nf_conntrack_ovs for ovs and tc use
  2023-02-07 22:52 [PATCHv2 net-next 0/5] net: move more duplicate code of ovs and tc conntrack into nf_conntrack_ovs Xin Long
@ 2023-02-07 22:52 ` Xin Long
  2023-02-08 10:15   ` Simon Horman
  2023-02-09 14:59   ` Aaron Conole
  2023-02-07 22:52 ` [PATCHv2 net-next 2/5] net: extract nf_ct_skb_network_trim function to nf_conntrack_ovs Xin Long
                   ` (5 subsequent siblings)
  6 siblings, 2 replies; 18+ messages in thread
From: Xin Long @ 2023-02-07 22:52 UTC (permalink / raw)
  To: network dev, dev
  Cc: davem, kuba, Eric Dumazet, Paolo Abeni, Pravin B Shelar,
	Jamal Hadi Salim, Cong Wang, Jiri Pirko, Pablo Neira Ayuso,
	Florian Westphal, Marcelo Ricardo Leitner, Ilya Maximets,
	Aaron Conole

Similar to nf_nat_ovs created by Commit ebddb1404900 ("net: move the
nat function to nf_nat_ovs for ovs and tc"), this patch is to create
nf_conntrack_ovs to get these functions shared by OVS and TC only.

There are nf_ct_helper() and nf_ct_add_helper() from nf_conntrak_helper
in this patch, and will be more in the following patches.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 net/netfilter/Kconfig               |   3 +
 net/netfilter/Makefile              |   1 +
 net/netfilter/nf_conntrack_helper.c |  98 --------------------------
 net/netfilter/nf_conntrack_ovs.c    | 104 ++++++++++++++++++++++++++++
 net/openvswitch/Kconfig             |   1 +
 net/sched/Kconfig                   |   1 +
 6 files changed, 110 insertions(+), 98 deletions(-)
 create mode 100644 net/netfilter/nf_conntrack_ovs.c

diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
index f71b41c7ce2f..4d6737160857 100644
--- a/net/netfilter/Kconfig
+++ b/net/netfilter/Kconfig
@@ -189,6 +189,9 @@ config NF_CONNTRACK_LABELS
 	  to connection tracking entries.  It can be used with xtables connlabel
 	  match and the nftables ct expression.
 
+config NF_CONNTRACK_OVS
+	bool
+
 config NF_CT_PROTO_DCCP
 	bool 'DCCP protocol connection tracking support'
 	depends on NETFILTER_ADVANCED
diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
index ba2a6b5e93d9..5ffef1cd6143 100644
--- a/net/netfilter/Makefile
+++ b/net/netfilter/Makefile
@@ -11,6 +11,7 @@ nf_conntrack-$(CONFIG_NF_CONNTRACK_TIMEOUT) += nf_conntrack_timeout.o
 nf_conntrack-$(CONFIG_NF_CONNTRACK_TIMESTAMP) += nf_conntrack_timestamp.o
 nf_conntrack-$(CONFIG_NF_CONNTRACK_EVENTS) += nf_conntrack_ecache.o
 nf_conntrack-$(CONFIG_NF_CONNTRACK_LABELS) += nf_conntrack_labels.o
+nf_conntrack-$(CONFIG_NF_CONNTRACK_OVS) += nf_conntrack_ovs.o
 nf_conntrack-$(CONFIG_NF_CT_PROTO_DCCP) += nf_conntrack_proto_dccp.o
 nf_conntrack-$(CONFIG_NF_CT_PROTO_SCTP) += nf_conntrack_proto_sctp.o
 nf_conntrack-$(CONFIG_NF_CT_PROTO_GRE) += nf_conntrack_proto_gre.o
diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
index 48ea6d0264b5..0c4db2f2ac43 100644
--- a/net/netfilter/nf_conntrack_helper.c
+++ b/net/netfilter/nf_conntrack_helper.c
@@ -242,104 +242,6 @@ int __nf_ct_try_assign_helper(struct nf_conn *ct, struct nf_conn *tmpl,
 }
 EXPORT_SYMBOL_GPL(__nf_ct_try_assign_helper);
 
-/* 'skb' should already be pulled to nh_ofs. */
-int nf_ct_helper(struct sk_buff *skb, struct nf_conn *ct,
-		 enum ip_conntrack_info ctinfo, u16 proto)
-{
-	const struct nf_conntrack_helper *helper;
-	const struct nf_conn_help *help;
-	unsigned int protoff;
-	int err;
-
-	if (ctinfo == IP_CT_RELATED_REPLY)
-		return NF_ACCEPT;
-
-	help = nfct_help(ct);
-	if (!help)
-		return NF_ACCEPT;
-
-	helper = rcu_dereference(help->helper);
-	if (!helper)
-		return NF_ACCEPT;
-
-	if (helper->tuple.src.l3num != NFPROTO_UNSPEC &&
-	    helper->tuple.src.l3num != proto)
-		return NF_ACCEPT;
-
-	switch (proto) {
-	case NFPROTO_IPV4:
-		protoff = ip_hdrlen(skb);
-		proto = ip_hdr(skb)->protocol;
-		break;
-	case NFPROTO_IPV6: {
-		u8 nexthdr = ipv6_hdr(skb)->nexthdr;
-		__be16 frag_off;
-		int ofs;
-
-		ofs = ipv6_skip_exthdr(skb, sizeof(struct ipv6hdr), &nexthdr,
-				       &frag_off);
-		if (ofs < 0 || (frag_off & htons(~0x7)) != 0) {
-			pr_debug("proto header not found\n");
-			return NF_ACCEPT;
-		}
-		protoff = ofs;
-		proto = nexthdr;
-		break;
-	}
-	default:
-		WARN_ONCE(1, "helper invoked on non-IP family!");
-		return NF_DROP;
-	}
-
-	if (helper->tuple.dst.protonum != proto)
-		return NF_ACCEPT;
-
-	err = helper->help(skb, protoff, ct, ctinfo);
-	if (err != NF_ACCEPT)
-		return err;
-
-	/* Adjust seqs after helper.  This is needed due to some helpers (e.g.,
-	 * FTP with NAT) adusting the TCP payload size when mangling IP
-	 * addresses and/or port numbers in the text-based control connection.
-	 */
-	if (test_bit(IPS_SEQ_ADJUST_BIT, &ct->status) &&
-	    !nf_ct_seq_adjust(skb, ct, ctinfo, protoff))
-		return NF_DROP;
-	return NF_ACCEPT;
-}
-EXPORT_SYMBOL_GPL(nf_ct_helper);
-
-int nf_ct_add_helper(struct nf_conn *ct, const char *name, u8 family,
-		     u8 proto, bool nat, struct nf_conntrack_helper **hp)
-{
-	struct nf_conntrack_helper *helper;
-	struct nf_conn_help *help;
-	int ret = 0;
-
-	helper = nf_conntrack_helper_try_module_get(name, family, proto);
-	if (!helper)
-		return -EINVAL;
-
-	help = nf_ct_helper_ext_add(ct, GFP_KERNEL);
-	if (!help) {
-		nf_conntrack_helper_put(helper);
-		return -ENOMEM;
-	}
-#if IS_ENABLED(CONFIG_NF_NAT)
-	if (nat) {
-		ret = nf_nat_helper_try_module_get(name, family, proto);
-		if (ret) {
-			nf_conntrack_helper_put(helper);
-			return ret;
-		}
-	}
-#endif
-	rcu_assign_pointer(help->helper, helper);
-	*hp = helper;
-	return ret;
-}
-EXPORT_SYMBOL_GPL(nf_ct_add_helper);
-
 /* appropriate ct lock protecting must be taken by caller */
 static int unhelp(struct nf_conn *ct, void *me)
 {
diff --git a/net/netfilter/nf_conntrack_ovs.c b/net/netfilter/nf_conntrack_ovs.c
new file mode 100644
index 000000000000..eff4d53f8b8c
--- /dev/null
+++ b/net/netfilter/nf_conntrack_ovs.c
@@ -0,0 +1,104 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Support ct functions for openvswitch and used by OVS and TC conntrack. */
+
+#include <net/netfilter/nf_conntrack_helper.h>
+#include <net/netfilter/nf_conntrack_seqadj.h>
+#include <net/ip.h>
+
+/* 'skb' should already be pulled to nh_ofs. */
+int nf_ct_helper(struct sk_buff *skb, struct nf_conn *ct,
+		 enum ip_conntrack_info ctinfo, u16 proto)
+{
+	const struct nf_conntrack_helper *helper;
+	const struct nf_conn_help *help;
+	unsigned int protoff;
+	int err;
+
+	if (ctinfo == IP_CT_RELATED_REPLY)
+		return NF_ACCEPT;
+
+	help = nfct_help(ct);
+	if (!help)
+		return NF_ACCEPT;
+
+	helper = rcu_dereference(help->helper);
+	if (!helper)
+		return NF_ACCEPT;
+
+	if (helper->tuple.src.l3num != NFPROTO_UNSPEC &&
+	    helper->tuple.src.l3num != proto)
+		return NF_ACCEPT;
+
+	switch (proto) {
+	case NFPROTO_IPV4:
+		protoff = ip_hdrlen(skb);
+		proto = ip_hdr(skb)->protocol;
+		break;
+	case NFPROTO_IPV6: {
+		u8 nexthdr = ipv6_hdr(skb)->nexthdr;
+		__be16 frag_off;
+		int ofs;
+
+		ofs = ipv6_skip_exthdr(skb, sizeof(struct ipv6hdr), &nexthdr,
+				       &frag_off);
+		if (ofs < 0 || (frag_off & htons(~0x7)) != 0) {
+			pr_debug("proto header not found\n");
+			return NF_ACCEPT;
+		}
+		protoff = ofs;
+		proto = nexthdr;
+		break;
+	}
+	default:
+		WARN_ONCE(1, "helper invoked on non-IP family!");
+		return NF_DROP;
+	}
+
+	if (helper->tuple.dst.protonum != proto)
+		return NF_ACCEPT;
+
+	err = helper->help(skb, protoff, ct, ctinfo);
+	if (err != NF_ACCEPT)
+		return err;
+
+	/* Adjust seqs after helper.  This is needed due to some helpers (e.g.,
+	 * FTP with NAT) adusting the TCP payload size when mangling IP
+	 * addresses and/or port numbers in the text-based control connection.
+	 */
+	if (test_bit(IPS_SEQ_ADJUST_BIT, &ct->status) &&
+	    !nf_ct_seq_adjust(skb, ct, ctinfo, protoff))
+		return NF_DROP;
+	return NF_ACCEPT;
+}
+EXPORT_SYMBOL_GPL(nf_ct_helper);
+
+int nf_ct_add_helper(struct nf_conn *ct, const char *name, u8 family,
+		     u8 proto, bool nat, struct nf_conntrack_helper **hp)
+{
+	struct nf_conntrack_helper *helper;
+	struct nf_conn_help *help;
+	int ret = 0;
+
+	helper = nf_conntrack_helper_try_module_get(name, family, proto);
+	if (!helper)
+		return -EINVAL;
+
+	help = nf_ct_helper_ext_add(ct, GFP_KERNEL);
+	if (!help) {
+		nf_conntrack_helper_put(helper);
+		return -ENOMEM;
+	}
+#if IS_ENABLED(CONFIG_NF_NAT)
+	if (nat) {
+		ret = nf_nat_helper_try_module_get(name, family, proto);
+		if (ret) {
+			nf_conntrack_helper_put(helper);
+			return ret;
+		}
+	}
+#endif
+	rcu_assign_pointer(help->helper, helper);
+	*hp = helper;
+	return ret;
+}
+EXPORT_SYMBOL_GPL(nf_ct_add_helper);
diff --git a/net/openvswitch/Kconfig b/net/openvswitch/Kconfig
index 747d537a3f06..29a7081858cd 100644
--- a/net/openvswitch/Kconfig
+++ b/net/openvswitch/Kconfig
@@ -15,6 +15,7 @@ config OPENVSWITCH
 	select NET_MPLS_GSO
 	select DST_CACHE
 	select NET_NSH
+	select NF_CONNTRACK_OVS if NF_CONNTRACK
 	select NF_NAT_OVS if NF_NAT
 	help
 	  Open vSwitch is a multilayer Ethernet switch targeted at virtualized
diff --git a/net/sched/Kconfig b/net/sched/Kconfig
index f5acb535413d..4f7b52f5a11c 100644
--- a/net/sched/Kconfig
+++ b/net/sched/Kconfig
@@ -984,6 +984,7 @@ config NET_ACT_TUNNEL_KEY
 config NET_ACT_CT
 	tristate "connection tracking tc action"
 	depends on NET_CLS_ACT && NF_CONNTRACK && (!NF_NAT || NF_NAT) && NF_FLOW_TABLE
+	select NF_CONNTRACK_OVS
 	select NF_NAT_OVS if NF_NAT
 	help
 	  Say Y here to allow sending the packets to conntrack module.
-- 
2.31.1


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

* [PATCHv2 net-next 2/5] net: extract nf_ct_skb_network_trim function to nf_conntrack_ovs
  2023-02-07 22:52 [PATCHv2 net-next 0/5] net: move more duplicate code of ovs and tc conntrack into nf_conntrack_ovs Xin Long
  2023-02-07 22:52 ` [PATCHv2 net-next 1/5] net: create nf_conntrack_ovs for ovs and tc use Xin Long
@ 2023-02-07 22:52 ` Xin Long
  2023-02-08 10:15   ` Simon Horman
  2023-02-09 15:00   ` Aaron Conole
  2023-02-07 22:52 ` [PATCHv2 net-next 3/5] openvswitch: move key and ovs_cb update out of handle_fragments Xin Long
                   ` (4 subsequent siblings)
  6 siblings, 2 replies; 18+ messages in thread
From: Xin Long @ 2023-02-07 22:52 UTC (permalink / raw)
  To: network dev, dev
  Cc: davem, kuba, Eric Dumazet, Paolo Abeni, Pravin B Shelar,
	Jamal Hadi Salim, Cong Wang, Jiri Pirko, Pablo Neira Ayuso,
	Florian Westphal, Marcelo Ricardo Leitner, Ilya Maximets,
	Aaron Conole

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>
---
 include/net/netfilter/nf_conntrack.h |  2 ++
 net/netfilter/nf_conntrack_ovs.c     | 26 ++++++++++++++++++++
 net/openvswitch/conntrack.c          | 36 ++++------------------------
 net/sched/act_ct.c                   | 27 +--------------------
 4 files changed, 33 insertions(+), 58 deletions(-)

diff --git a/include/net/netfilter/nf_conntrack.h b/include/net/netfilter/nf_conntrack.h
index 6a2019aaa464..a6e89d7212f8 100644
--- a/include/net/netfilter/nf_conntrack.h
+++ b/include/net/netfilter/nf_conntrack.h
@@ -362,6 +362,8 @@ static inline struct nf_conntrack_net *nf_ct_pernet(const struct net *net)
 	return net_generic(net, nf_conntrack_net_id);
 }
 
+int nf_ct_skb_network_trim(struct sk_buff *skb, int family);
+
 #define NF_CT_STAT_INC(net, count)	  __this_cpu_inc((net)->ct.stat->count)
 #define NF_CT_STAT_INC_ATOMIC(net, count) this_cpu_inc((net)->ct.stat->count)
 #define NF_CT_STAT_ADD_ATOMIC(net, count, v) this_cpu_add((net)->ct.stat->count, (v))
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);
diff --git a/net/openvswitch/conntrack.c b/net/openvswitch/conntrack.c
index 2172930b1f17..47a58657b1e4 100644
--- a/net/openvswitch/conntrack.c
+++ b/net/openvswitch/conntrack.c
@@ -1090,36 +1090,6 @@ static int ovs_ct_commit(struct net *net, struct sw_flow_key *key,
 	return 0;
 }
 
-/* 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.
- */
-static int ovs_skb_network_trim(struct sk_buff *skb)
-{
-	unsigned int len;
-	int err;
-
-	switch (skb->protocol) {
-	case htons(ETH_P_IP):
-		len = skb_ip_totlen(skb);
-		break;
-	case htons(ETH_P_IPV6):
-		len = sizeof(struct ipv6hdr)
-			+ ntohs(ipv6_hdr(skb)->payload_len);
-		break;
-	default:
-		len = skb->len;
-	}
-
-	err = pskb_trim_rcsum(skb, len);
-	if (err)
-		kfree_skb(skb);
-
-	return err;
-}
-
 /* Returns 0 on success, -EINPROGRESS if 'skb' is stolen, or other nonzero
  * value if 'skb' is freed.
  */
@@ -1134,9 +1104,11 @@ int ovs_ct_execute(struct net *net, struct sk_buff *skb,
 	nh_ofs = skb_network_offset(skb);
 	skb_pull_rcsum(skb, nh_ofs);
 
-	err = ovs_skb_network_trim(skb);
-	if (err)
+	err = nf_ct_skb_network_trim(skb, info->family);
+	if (err) {
+		kfree_skb(skb);
 		return err;
+	}
 
 	if (key->ip.frag != OVS_FRAG_TYPE_NONE) {
 		err = handle_fragments(net, key, info->zone.id, skb);
diff --git a/net/sched/act_ct.c b/net/sched/act_ct.c
index b126f03c1bb6..0a1ecc972a8b 100644
--- a/net/sched/act_ct.c
+++ b/net/sched/act_ct.c
@@ -726,31 +726,6 @@ static bool tcf_ct_skb_nfct_cached(struct net *net, struct sk_buff *skb,
 	return false;
 }
 
-/* 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.
- */
-static int tcf_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);
-}
-
 static u8 tcf_ct_skb_nf_family(struct sk_buff *skb)
 {
 	u8 family = NFPROTO_UNSPEC;
@@ -1011,7 +986,7 @@ TC_INDIRECT_SCOPE int tcf_ct_act(struct sk_buff *skb, const struct tc_action *a,
 	if (err)
 		goto drop;
 
-	err = tcf_ct_skb_network_trim(skb, family);
+	err = nf_ct_skb_network_trim(skb, family);
 	if (err)
 		goto drop;
 
-- 
2.31.1


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

* [PATCHv2 net-next 3/5] openvswitch: move key and ovs_cb update out of handle_fragments
  2023-02-07 22:52 [PATCHv2 net-next 0/5] net: move more duplicate code of ovs and tc conntrack into nf_conntrack_ovs Xin Long
  2023-02-07 22:52 ` [PATCHv2 net-next 1/5] net: create nf_conntrack_ovs for ovs and tc use Xin Long
  2023-02-07 22:52 ` [PATCHv2 net-next 2/5] net: extract nf_ct_skb_network_trim function to nf_conntrack_ovs Xin Long
@ 2023-02-07 22:52 ` Xin Long
  2023-02-08 10:16   ` Simon Horman
  2023-02-09 15:01   ` Aaron Conole
  2023-02-07 22:52 ` [PATCHv2 net-next 4/5] net: sched: move frag check and tc_skb_cb " Xin Long
                   ` (3 subsequent siblings)
  6 siblings, 2 replies; 18+ messages in thread
From: Xin Long @ 2023-02-07 22:52 UTC (permalink / raw)
  To: network dev, dev
  Cc: davem, kuba, Eric Dumazet, Paolo Abeni, Pravin B Shelar,
	Jamal Hadi Salim, Cong Wang, Jiri Pirko, Pablo Neira Ayuso,
	Florian Westphal, Marcelo Ricardo Leitner, Ilya Maximets,
	Aaron Conole

This patch has no functional changes and just moves key and ovs_cb update
out of handle_fragments, and skb_clear_hash() and skb->ignore_df change
into handle_fragments(), to make it easier to move the duplicate code
from handle_fragments() into nf_conntrack_ovs later.

Note that it changes to pass info->family to handle_fragments() instead
of key for the packet type check, as info->family is set according to
key->eth.type in ovs_ct_copy_action() when creating the action.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 net/openvswitch/conntrack.c | 37 +++++++++++++++++++++++++------------
 1 file changed, 25 insertions(+), 12 deletions(-)

diff --git a/net/openvswitch/conntrack.c b/net/openvswitch/conntrack.c
index 47a58657b1e4..962e2f70e597 100644
--- a/net/openvswitch/conntrack.c
+++ b/net/openvswitch/conntrack.c
@@ -437,13 +437,12 @@ static int ovs_ct_set_labels(struct nf_conn *ct, struct sw_flow_key *key,
 /* Returns 0 on success, -EINPROGRESS if 'skb' is stolen, or other nonzero
  * value if 'skb' is freed.
  */
-static int handle_fragments(struct net *net, struct sw_flow_key *key,
-			    u16 zone, struct sk_buff *skb)
+static int handle_fragments(struct net *net, struct sk_buff *skb,
+			    u16 zone, u8 family, u8 *proto, u16 *mru)
 {
-	struct ovs_skb_cb ovs_cb = *OVS_CB(skb);
 	int err;
 
-	if (key->eth.type == htons(ETH_P_IP)) {
+	if (family == NFPROTO_IPV4) {
 		enum ip_defrag_users user = IP_DEFRAG_CONNTRACK_IN + zone;
 
 		memset(IPCB(skb), 0, sizeof(struct inet_skb_parm));
@@ -451,9 +450,9 @@ static int handle_fragments(struct net *net, struct sw_flow_key *key,
 		if (err)
 			return err;
 
-		ovs_cb.mru = IPCB(skb)->frag_max_size;
+		*mru = IPCB(skb)->frag_max_size;
 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
-	} else if (key->eth.type == htons(ETH_P_IPV6)) {
+	} else if (family == NFPROTO_IPV6) {
 		enum ip6_defrag_users user = IP6_DEFRAG_CONNTRACK_IN + zone;
 
 		memset(IP6CB(skb), 0, sizeof(struct inet6_skb_parm));
@@ -464,22 +463,35 @@ static int handle_fragments(struct net *net, struct sw_flow_key *key,
 			return err;
 		}
 
-		key->ip.proto = ipv6_hdr(skb)->nexthdr;
-		ovs_cb.mru = IP6CB(skb)->frag_max_size;
+		*proto = ipv6_hdr(skb)->nexthdr;
+		*mru = IP6CB(skb)->frag_max_size;
 #endif
 	} else {
 		kfree_skb(skb);
 		return -EPFNOSUPPORT;
 	}
 
+	skb_clear_hash(skb);
+	skb->ignore_df = 1;
+
+	return 0;
+}
+
+static int ovs_ct_handle_fragments(struct net *net, struct sw_flow_key *key,
+				   u16 zone, int family, struct sk_buff *skb)
+{
+	struct ovs_skb_cb ovs_cb = *OVS_CB(skb);
+	int err;
+
+	err = handle_fragments(net, skb, zone, family, &key->ip.proto, &ovs_cb.mru);
+	if (err)
+		return err;
+
 	/* The key extracted from the fragment that completed this datagram
 	 * likely didn't have an L4 header, so regenerate it.
 	 */
 	ovs_flow_key_update_l3l4(skb, key);
-
 	key->ip.frag = OVS_FRAG_TYPE_NONE;
-	skb_clear_hash(skb);
-	skb->ignore_df = 1;
 	*OVS_CB(skb) = ovs_cb;
 
 	return 0;
@@ -1111,7 +1123,8 @@ int ovs_ct_execute(struct net *net, struct sk_buff *skb,
 	}
 
 	if (key->ip.frag != OVS_FRAG_TYPE_NONE) {
-		err = handle_fragments(net, key, info->zone.id, skb);
+		err = ovs_ct_handle_fragments(net, key, info->zone.id,
+					      info->family, skb);
 		if (err)
 			return err;
 	}
-- 
2.31.1


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

* [PATCHv2 net-next 4/5] net: sched: move frag check and tc_skb_cb update out of handle_fragments
  2023-02-07 22:52 [PATCHv2 net-next 0/5] net: move more duplicate code of ovs and tc conntrack into nf_conntrack_ovs Xin Long
                   ` (2 preceding siblings ...)
  2023-02-07 22:52 ` [PATCHv2 net-next 3/5] openvswitch: move key and ovs_cb update out of handle_fragments Xin Long
@ 2023-02-07 22:52 ` Xin Long
  2023-02-08 10:16   ` Simon Horman
  2023-02-07 22:52 ` [PATCHv2 net-next 5/5] net: extract nf_ct_handle_fragments to nf_conntrack_ovs Xin Long
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 18+ messages in thread
From: Xin Long @ 2023-02-07 22:52 UTC (permalink / raw)
  To: network dev, dev
  Cc: davem, kuba, Eric Dumazet, Paolo Abeni, Pravin B Shelar,
	Jamal Hadi Salim, Cong Wang, Jiri Pirko, Pablo Neira Ayuso,
	Florian Westphal, Marcelo Ricardo Leitner, Ilya Maximets,
	Aaron Conole

This patch has no functional changes and just moves frag check and
tc_skb_cb update out of handle_fragments, to make it easier to move
the duplicate code from handle_fragments() into nf_conntrack_ovs later.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 net/sched/act_ct.c | 71 +++++++++++++++++++++++++---------------------
 1 file changed, 39 insertions(+), 32 deletions(-)

diff --git a/net/sched/act_ct.c b/net/sched/act_ct.c
index 0a1ecc972a8b..9f133ed93815 100644
--- a/net/sched/act_ct.c
+++ b/net/sched/act_ct.c
@@ -778,29 +778,10 @@ static int tcf_ct_ipv6_is_fragment(struct sk_buff *skb, bool *frag)
 	return 0;
 }
 
-static int tcf_ct_handle_fragments(struct net *net, struct sk_buff *skb,
-				   u8 family, u16 zone, bool *defrag)
+static int handle_fragments(struct net *net, struct sk_buff *skb,
+			    u16 zone, u8 family, u16 *mru)
 {
-	enum ip_conntrack_info ctinfo;
-	struct nf_conn *ct;
-	int err = 0;
-	bool frag;
-	u16 mru;
-
-	/* Previously seen (loopback)? Ignore. */
-	ct = nf_ct_get(skb, &ctinfo);
-	if ((ct && !nf_ct_is_template(ct)) || ctinfo == IP_CT_UNTRACKED)
-		return 0;
-
-	if (family == NFPROTO_IPV4)
-		err = tcf_ct_ipv4_is_fragment(skb, &frag);
-	else
-		err = tcf_ct_ipv6_is_fragment(skb, &frag);
-	if (err || !frag)
-		return err;
-
-	skb_get(skb);
-	mru = tc_skb_cb(skb)->mru;
+	int err;
 
 	if (family == NFPROTO_IPV4) {
 		enum ip_defrag_users user = IP_DEFRAG_CONNTRACK_IN + zone;
@@ -812,10 +793,8 @@ static int tcf_ct_handle_fragments(struct net *net, struct sk_buff *skb,
 		if (err && err != -EINPROGRESS)
 			return err;
 
-		if (!err) {
-			*defrag = true;
-			mru = IPCB(skb)->frag_max_size;
-		}
+		if (!err)
+			*mru = IPCB(skb)->frag_max_size;
 	} else { /* NFPROTO_IPV6 */
 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
 		enum ip6_defrag_users user = IP6_DEFRAG_CONNTRACK_IN + zone;
@@ -825,18 +804,14 @@ static int tcf_ct_handle_fragments(struct net *net, struct sk_buff *skb,
 		if (err && err != -EINPROGRESS)
 			goto out_free;
 
-		if (!err) {
-			*defrag = true;
-			mru = IP6CB(skb)->frag_max_size;
-		}
+		if (!err)
+			*mru = IP6CB(skb)->frag_max_size;
 #else
 		err = -EOPNOTSUPP;
 		goto out_free;
 #endif
 	}
 
-	if (err != -EINPROGRESS)
-		tc_skb_cb(skb)->mru = mru;
 	skb_clear_hash(skb);
 	skb->ignore_df = 1;
 	return err;
@@ -846,6 +821,38 @@ static int tcf_ct_handle_fragments(struct net *net, struct sk_buff *skb,
 	return err;
 }
 
+static int tcf_ct_handle_fragments(struct net *net, struct sk_buff *skb,
+				   u8 family, u16 zone, bool *defrag)
+{
+	enum ip_conntrack_info ctinfo;
+	struct nf_conn *ct;
+	int err = 0;
+	bool frag;
+	u16 mru;
+
+	/* Previously seen (loopback)? Ignore. */
+	ct = nf_ct_get(skb, &ctinfo);
+	if ((ct && !nf_ct_is_template(ct)) || ctinfo == IP_CT_UNTRACKED)
+		return 0;
+
+	if (family == NFPROTO_IPV4)
+		err = tcf_ct_ipv4_is_fragment(skb, &frag);
+	else
+		err = tcf_ct_ipv6_is_fragment(skb, &frag);
+	if (err || !frag)
+		return err;
+
+	skb_get(skb);
+	err = handle_fragments(net, skb, zone, family, &mru);
+	if (err)
+		return err;
+
+	*defrag = true;
+	tc_skb_cb(skb)->mru = mru;
+
+	return 0;
+}
+
 static void tcf_ct_params_free(struct tcf_ct_params *params)
 {
 	if (params->helper) {
-- 
2.31.1


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

* [PATCHv2 net-next 5/5] net: extract nf_ct_handle_fragments to nf_conntrack_ovs
  2023-02-07 22:52 [PATCHv2 net-next 0/5] net: move more duplicate code of ovs and tc conntrack into nf_conntrack_ovs Xin Long
                   ` (3 preceding siblings ...)
  2023-02-07 22:52 ` [PATCHv2 net-next 4/5] net: sched: move frag check and tc_skb_cb " Xin Long
@ 2023-02-07 22:52 ` Xin Long
  2023-02-08 10:17   ` Simon Horman
  2023-02-09 15:08   ` Aaron Conole
  2023-02-10  6:21 ` [PATCHv2 net-next 0/5] net: move more duplicate code of ovs and tc conntrack into nf_conntrack_ovs Jakub Kicinski
  2023-02-11  0:30 ` patchwork-bot+netdevbpf
  6 siblings, 2 replies; 18+ messages in thread
From: Xin Long @ 2023-02-07 22:52 UTC (permalink / raw)
  To: network dev, dev
  Cc: davem, kuba, Eric Dumazet, Paolo Abeni, Pravin B Shelar,
	Jamal Hadi Salim, Cong Wang, Jiri Pirko, Pablo Neira Ayuso,
	Florian Westphal, Marcelo Ricardo Leitner, Ilya Maximets,
	Aaron Conole

Now handle_fragments() in OVS and TC have the similar code, and
this patch removes the duplicate code by moving the function
to nf_conntrack_ovs.

Note that skb_clear_hash(skb) or skb->ignore_df = 1 should be
done only when defrag returns 0, as it does in other places
in kernel.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 include/net/netfilter/nf_conntrack.h |  2 ++
 net/netfilter/nf_conntrack_ovs.c     | 48 ++++++++++++++++++++++++++++
 net/openvswitch/conntrack.c          | 45 +-------------------------
 net/sched/act_ct.c                   | 46 ++------------------------
 4 files changed, 53 insertions(+), 88 deletions(-)

diff --git a/include/net/netfilter/nf_conntrack.h b/include/net/netfilter/nf_conntrack.h
index a6e89d7212f8..7bbab8f2b73d 100644
--- a/include/net/netfilter/nf_conntrack.h
+++ b/include/net/netfilter/nf_conntrack.h
@@ -363,6 +363,8 @@ static inline struct nf_conntrack_net *nf_ct_pernet(const struct net *net)
 }
 
 int nf_ct_skb_network_trim(struct sk_buff *skb, int family);
+int nf_ct_handle_fragments(struct net *net, struct sk_buff *skb,
+			   u16 zone, u8 family, u8 *proto, u16 *mru);
 
 #define NF_CT_STAT_INC(net, count)	  __this_cpu_inc((net)->ct.stat->count)
 #define NF_CT_STAT_INC_ATOMIC(net, count) this_cpu_inc((net)->ct.stat->count)
diff --git a/net/netfilter/nf_conntrack_ovs.c b/net/netfilter/nf_conntrack_ovs.c
index c60ef71d1aea..52b776bdf526 100644
--- a/net/netfilter/nf_conntrack_ovs.c
+++ b/net/netfilter/nf_conntrack_ovs.c
@@ -3,6 +3,8 @@
 
 #include <net/netfilter/nf_conntrack_helper.h>
 #include <net/netfilter/nf_conntrack_seqadj.h>
+#include <net/netfilter/ipv6/nf_defrag_ipv6.h>
+#include <net/ipv6_frag.h>
 #include <net/ip.h>
 
 /* 'skb' should already be pulled to nh_ofs. */
@@ -128,3 +130,49 @@ int nf_ct_skb_network_trim(struct sk_buff *skb, int family)
 	return pskb_trim_rcsum(skb, len);
 }
 EXPORT_SYMBOL_GPL(nf_ct_skb_network_trim);
+
+/* Returns 0 on success, -EINPROGRESS if 'skb' is stolen, or other nonzero
+ * value if 'skb' is freed.
+ */
+int nf_ct_handle_fragments(struct net *net, struct sk_buff *skb,
+			   u16 zone, u8 family, u8 *proto, u16 *mru)
+{
+	int err;
+
+	if (family == NFPROTO_IPV4) {
+		enum ip_defrag_users user = IP_DEFRAG_CONNTRACK_IN + zone;
+
+		memset(IPCB(skb), 0, sizeof(struct inet_skb_parm));
+		local_bh_disable();
+		err = ip_defrag(net, skb, user);
+		local_bh_enable();
+		if (err)
+			return err;
+
+		*mru = IPCB(skb)->frag_max_size;
+#if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
+	} else if (family == NFPROTO_IPV6) {
+		enum ip6_defrag_users user = IP6_DEFRAG_CONNTRACK_IN + zone;
+
+		memset(IP6CB(skb), 0, sizeof(struct inet6_skb_parm));
+		err = nf_ct_frag6_gather(net, skb, user);
+		if (err) {
+			if (err != -EINPROGRESS)
+				kfree_skb(skb);
+			return err;
+		}
+
+		*proto = ipv6_hdr(skb)->nexthdr;
+		*mru = IP6CB(skb)->frag_max_size;
+#endif
+	} else {
+		kfree_skb(skb);
+		return -EPFNOSUPPORT;
+	}
+
+	skb_clear_hash(skb);
+	skb->ignore_df = 1;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(nf_ct_handle_fragments);
diff --git a/net/openvswitch/conntrack.c b/net/openvswitch/conntrack.c
index 962e2f70e597..5d40ad02cabc 100644
--- a/net/openvswitch/conntrack.c
+++ b/net/openvswitch/conntrack.c
@@ -434,56 +434,13 @@ static int ovs_ct_set_labels(struct nf_conn *ct, struct sw_flow_key *key,
 	return 0;
 }
 
-/* Returns 0 on success, -EINPROGRESS if 'skb' is stolen, or other nonzero
- * value if 'skb' is freed.
- */
-static int handle_fragments(struct net *net, struct sk_buff *skb,
-			    u16 zone, u8 family, u8 *proto, u16 *mru)
-{
-	int err;
-
-	if (family == NFPROTO_IPV4) {
-		enum ip_defrag_users user = IP_DEFRAG_CONNTRACK_IN + zone;
-
-		memset(IPCB(skb), 0, sizeof(struct inet_skb_parm));
-		err = ip_defrag(net, skb, user);
-		if (err)
-			return err;
-
-		*mru = IPCB(skb)->frag_max_size;
-#if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
-	} else if (family == NFPROTO_IPV6) {
-		enum ip6_defrag_users user = IP6_DEFRAG_CONNTRACK_IN + zone;
-
-		memset(IP6CB(skb), 0, sizeof(struct inet6_skb_parm));
-		err = nf_ct_frag6_gather(net, skb, user);
-		if (err) {
-			if (err != -EINPROGRESS)
-				kfree_skb(skb);
-			return err;
-		}
-
-		*proto = ipv6_hdr(skb)->nexthdr;
-		*mru = IP6CB(skb)->frag_max_size;
-#endif
-	} else {
-		kfree_skb(skb);
-		return -EPFNOSUPPORT;
-	}
-
-	skb_clear_hash(skb);
-	skb->ignore_df = 1;
-
-	return 0;
-}
-
 static int ovs_ct_handle_fragments(struct net *net, struct sw_flow_key *key,
 				   u16 zone, int family, struct sk_buff *skb)
 {
 	struct ovs_skb_cb ovs_cb = *OVS_CB(skb);
 	int err;
 
-	err = handle_fragments(net, skb, zone, family, &key->ip.proto, &ovs_cb.mru);
+	err = nf_ct_handle_fragments(net, skb, zone, family, &key->ip.proto, &ovs_cb.mru);
 	if (err)
 		return err;
 
diff --git a/net/sched/act_ct.c b/net/sched/act_ct.c
index 9f133ed93815..9cc0bc7c71ed 100644
--- a/net/sched/act_ct.c
+++ b/net/sched/act_ct.c
@@ -778,49 +778,6 @@ static int tcf_ct_ipv6_is_fragment(struct sk_buff *skb, bool *frag)
 	return 0;
 }
 
-static int handle_fragments(struct net *net, struct sk_buff *skb,
-			    u16 zone, u8 family, u16 *mru)
-{
-	int err;
-
-	if (family == NFPROTO_IPV4) {
-		enum ip_defrag_users user = IP_DEFRAG_CONNTRACK_IN + zone;
-
-		memset(IPCB(skb), 0, sizeof(struct inet_skb_parm));
-		local_bh_disable();
-		err = ip_defrag(net, skb, user);
-		local_bh_enable();
-		if (err && err != -EINPROGRESS)
-			return err;
-
-		if (!err)
-			*mru = IPCB(skb)->frag_max_size;
-	} else { /* NFPROTO_IPV6 */
-#if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
-		enum ip6_defrag_users user = IP6_DEFRAG_CONNTRACK_IN + zone;
-
-		memset(IP6CB(skb), 0, sizeof(struct inet6_skb_parm));
-		err = nf_ct_frag6_gather(net, skb, user);
-		if (err && err != -EINPROGRESS)
-			goto out_free;
-
-		if (!err)
-			*mru = IP6CB(skb)->frag_max_size;
-#else
-		err = -EOPNOTSUPP;
-		goto out_free;
-#endif
-	}
-
-	skb_clear_hash(skb);
-	skb->ignore_df = 1;
-	return err;
-
-out_free:
-	kfree_skb(skb);
-	return err;
-}
-
 static int tcf_ct_handle_fragments(struct net *net, struct sk_buff *skb,
 				   u8 family, u16 zone, bool *defrag)
 {
@@ -828,6 +785,7 @@ static int tcf_ct_handle_fragments(struct net *net, struct sk_buff *skb,
 	struct nf_conn *ct;
 	int err = 0;
 	bool frag;
+	u8 proto;
 	u16 mru;
 
 	/* Previously seen (loopback)? Ignore. */
@@ -843,7 +801,7 @@ static int tcf_ct_handle_fragments(struct net *net, struct sk_buff *skb,
 		return err;
 
 	skb_get(skb);
-	err = handle_fragments(net, skb, zone, family, &mru);
+	err = nf_ct_handle_fragments(net, skb, zone, family, &proto, &mru);
 	if (err)
 		return err;
 
-- 
2.31.1


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

* Re: [PATCHv2 net-next 1/5] net: create nf_conntrack_ovs for ovs and tc use
  2023-02-07 22:52 ` [PATCHv2 net-next 1/5] net: create nf_conntrack_ovs for ovs and tc use Xin Long
@ 2023-02-08 10:15   ` Simon Horman
  2023-02-09 14:59   ` Aaron Conole
  1 sibling, 0 replies; 18+ messages in thread
From: Simon Horman @ 2023-02-08 10:15 UTC (permalink / raw)
  To: Xin Long
  Cc: network dev, dev, davem, kuba, Eric Dumazet, Paolo Abeni,
	Pravin B Shelar, Jamal Hadi Salim, Cong Wang, Jiri Pirko,
	Pablo Neira Ayuso, Florian Westphal, Marcelo Ricardo Leitner,
	Ilya Maximets, Aaron Conole

On Tue, Feb 07, 2023 at 05:52:06PM -0500, Xin Long wrote:
> Similar to nf_nat_ovs created by Commit ebddb1404900 ("net: move the
> nat function to nf_nat_ovs for ovs and tc"), this patch is to create
> nf_conntrack_ovs to get these functions shared by OVS and TC only.
> 
> There are nf_ct_helper() and nf_ct_add_helper() from nf_conntrak_helper
> in this patch, and will be more in the following patches.
> 
> Signed-off-by: Xin Long <lucien.xin@gmail.com>

Reviewed-by: Simon Horman <simon.horman@corigine.com>


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

* Re: [PATCHv2 net-next 2/5] net: extract nf_ct_skb_network_trim function to nf_conntrack_ovs
  2023-02-07 22:52 ` [PATCHv2 net-next 2/5] net: extract nf_ct_skb_network_trim function to nf_conntrack_ovs Xin Long
@ 2023-02-08 10:15   ` Simon Horman
  2023-02-09 15:00   ` Aaron Conole
  1 sibling, 0 replies; 18+ messages in thread
From: Simon Horman @ 2023-02-08 10:15 UTC (permalink / raw)
  To: Xin Long
  Cc: network dev, dev, davem, kuba, Eric Dumazet, Paolo Abeni,
	Pravin B Shelar, Jamal Hadi Salim, Cong Wang, Jiri Pirko,
	Pablo Neira Ayuso, Florian Westphal, Marcelo Ricardo Leitner,
	Ilya Maximets, Aaron Conole

On Tue, Feb 07, 2023 at 05:52:07PM -0500, Xin Long wrote:
> 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>


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

* Re: [PATCHv2 net-next 3/5] openvswitch: move key and ovs_cb update out of handle_fragments
  2023-02-07 22:52 ` [PATCHv2 net-next 3/5] openvswitch: move key and ovs_cb update out of handle_fragments Xin Long
@ 2023-02-08 10:16   ` Simon Horman
  2023-02-09 15:01   ` Aaron Conole
  1 sibling, 0 replies; 18+ messages in thread
From: Simon Horman @ 2023-02-08 10:16 UTC (permalink / raw)
  To: Xin Long
  Cc: network dev, dev, davem, kuba, Eric Dumazet, Paolo Abeni,
	Pravin B Shelar, Jamal Hadi Salim, Cong Wang, Jiri Pirko,
	Pablo Neira Ayuso, Florian Westphal, Marcelo Ricardo Leitner,
	Ilya Maximets, Aaron Conole

On Tue, Feb 07, 2023 at 05:52:08PM -0500, Xin Long wrote:
> This patch has no functional changes and just moves key and ovs_cb update
> out of handle_fragments, and skb_clear_hash() and skb->ignore_df change
> into handle_fragments(), to make it easier to move the duplicate code
> from handle_fragments() into nf_conntrack_ovs later.
> 
> Note that it changes to pass info->family to handle_fragments() instead
> of key for the packet type check, as info->family is set according to
> key->eth.type in ovs_ct_copy_action() when creating the action.
> 
> Signed-off-by: Xin Long <lucien.xin@gmail.com>

Reviewed-by: Simon Horman <simon.horman@corigine.com>


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

* Re: [PATCHv2 net-next 4/5] net: sched: move frag check and tc_skb_cb update out of handle_fragments
  2023-02-07 22:52 ` [PATCHv2 net-next 4/5] net: sched: move frag check and tc_skb_cb " Xin Long
@ 2023-02-08 10:16   ` Simon Horman
  0 siblings, 0 replies; 18+ messages in thread
From: Simon Horman @ 2023-02-08 10:16 UTC (permalink / raw)
  To: Xin Long
  Cc: network dev, dev, davem, kuba, Eric Dumazet, Paolo Abeni,
	Pravin B Shelar, Jamal Hadi Salim, Cong Wang, Jiri Pirko,
	Pablo Neira Ayuso, Florian Westphal, Marcelo Ricardo Leitner,
	Ilya Maximets, Aaron Conole

On Tue, Feb 07, 2023 at 05:52:09PM -0500, Xin Long wrote:
> This patch has no functional changes and just moves frag check and
> tc_skb_cb update out of handle_fragments, to make it easier to move
> the duplicate code from handle_fragments() into nf_conntrack_ovs later.
> 
> Signed-off-by: Xin Long <lucien.xin@gmail.com>

Reviewed-by: Simon Horman <simon.horman@corigine.com>


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

* Re: [PATCHv2 net-next 5/5] net: extract nf_ct_handle_fragments to nf_conntrack_ovs
  2023-02-07 22:52 ` [PATCHv2 net-next 5/5] net: extract nf_ct_handle_fragments to nf_conntrack_ovs Xin Long
@ 2023-02-08 10:17   ` Simon Horman
  2023-02-09 15:08   ` Aaron Conole
  1 sibling, 0 replies; 18+ messages in thread
From: Simon Horman @ 2023-02-08 10:17 UTC (permalink / raw)
  To: Xin Long
  Cc: network dev, dev, davem, kuba, Eric Dumazet, Paolo Abeni,
	Pravin B Shelar, Jamal Hadi Salim, Cong Wang, Jiri Pirko,
	Pablo Neira Ayuso, Florian Westphal, Marcelo Ricardo Leitner,
	Ilya Maximets, Aaron Conole

On Tue, Feb 07, 2023 at 05:52:10PM -0500, Xin Long wrote:
> Now handle_fragments() in OVS and TC have the similar code, and
> this patch removes the duplicate code by moving the function
> to nf_conntrack_ovs.
> 
> Note that skb_clear_hash(skb) or skb->ignore_df = 1 should be
> done only when defrag returns 0, as it does in other places
> in kernel.
> 
> Signed-off-by: Xin Long <lucien.xin@gmail.com>

Reviewed-by: Simon Horman <simon.horman@corigine.com>


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

* Re: [PATCHv2 net-next 1/5] net: create nf_conntrack_ovs for ovs and tc use
  2023-02-07 22:52 ` [PATCHv2 net-next 1/5] net: create nf_conntrack_ovs for ovs and tc use Xin Long
  2023-02-08 10:15   ` Simon Horman
@ 2023-02-09 14:59   ` Aaron Conole
  1 sibling, 0 replies; 18+ messages in thread
From: Aaron Conole @ 2023-02-09 14:59 UTC (permalink / raw)
  To: Xin Long
  Cc: network dev, dev, davem, kuba, Eric Dumazet, Paolo Abeni,
	Pravin B Shelar, Jamal Hadi Salim, Cong Wang, Jiri Pirko,
	Pablo Neira Ayuso, Florian Westphal, Marcelo Ricardo Leitner,
	Ilya Maximets

Xin Long <lucien.xin@gmail.com> writes:

> Similar to nf_nat_ovs created by Commit ebddb1404900 ("net: move the
> nat function to nf_nat_ovs for ovs and tc"), this patch is to create
> nf_conntrack_ovs to get these functions shared by OVS and TC only.
>
> There are nf_ct_helper() and nf_ct_add_helper() from nf_conntrak_helper
> in this patch, and will be more in the following patches.
>
> Signed-off-by: Xin Long <lucien.xin@gmail.com>
> ---

Reviewed-by: Aaron Conole <aconole@redhat.com>


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

* Re: [PATCHv2 net-next 2/5] net: extract nf_ct_skb_network_trim function to nf_conntrack_ovs
  2023-02-07 22:52 ` [PATCHv2 net-next 2/5] net: extract nf_ct_skb_network_trim function to nf_conntrack_ovs Xin Long
  2023-02-08 10:15   ` Simon Horman
@ 2023-02-09 15:00   ` Aaron Conole
  1 sibling, 0 replies; 18+ messages in thread
From: Aaron Conole @ 2023-02-09 15:00 UTC (permalink / raw)
  To: Xin Long
  Cc: network dev, dev, davem, kuba, Eric Dumazet, Paolo Abeni,
	Pravin B Shelar, Jamal Hadi Salim, Cong Wang, Jiri Pirko,
	Pablo Neira Ayuso, Florian Westphal, Marcelo Ricardo Leitner,
	Ilya Maximets

Xin Long <lucien.xin@gmail.com> writes:

> 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: Aaron Conole <aconole@redhat.com>


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

* Re: [PATCHv2 net-next 3/5] openvswitch: move key and ovs_cb update out of handle_fragments
  2023-02-07 22:52 ` [PATCHv2 net-next 3/5] openvswitch: move key and ovs_cb update out of handle_fragments Xin Long
  2023-02-08 10:16   ` Simon Horman
@ 2023-02-09 15:01   ` Aaron Conole
  1 sibling, 0 replies; 18+ messages in thread
From: Aaron Conole @ 2023-02-09 15:01 UTC (permalink / raw)
  To: Xin Long
  Cc: network dev, dev, davem, kuba, Eric Dumazet, Paolo Abeni,
	Pravin B Shelar, Jamal Hadi Salim, Cong Wang, Jiri Pirko,
	Pablo Neira Ayuso, Florian Westphal, Marcelo Ricardo Leitner,
	Ilya Maximets

Xin Long <lucien.xin@gmail.com> writes:

> This patch has no functional changes and just moves key and ovs_cb update
> out of handle_fragments, and skb_clear_hash() and skb->ignore_df change
> into handle_fragments(), to make it easier to move the duplicate code
> from handle_fragments() into nf_conntrack_ovs later.
>
> Note that it changes to pass info->family to handle_fragments() instead
> of key for the packet type check, as info->family is set according to
> key->eth.type in ovs_ct_copy_action() when creating the action.
>
> Signed-off-by: Xin Long <lucien.xin@gmail.com>
> ---

Reviewed-by: Aaron Conole <aconole@redhat.com>


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

* Re: [PATCHv2 net-next 5/5] net: extract nf_ct_handle_fragments to nf_conntrack_ovs
  2023-02-07 22:52 ` [PATCHv2 net-next 5/5] net: extract nf_ct_handle_fragments to nf_conntrack_ovs Xin Long
  2023-02-08 10:17   ` Simon Horman
@ 2023-02-09 15:08   ` Aaron Conole
  1 sibling, 0 replies; 18+ messages in thread
From: Aaron Conole @ 2023-02-09 15:08 UTC (permalink / raw)
  To: Xin Long
  Cc: network dev, dev, davem, kuba, Eric Dumazet, Paolo Abeni,
	Pravin B Shelar, Jamal Hadi Salim, Cong Wang, Jiri Pirko,
	Pablo Neira Ayuso, Florian Westphal, Marcelo Ricardo Leitner,
	Ilya Maximets

Xin Long <lucien.xin@gmail.com> writes:

> Now handle_fragments() in OVS and TC have the similar code, and
> this patch removes the duplicate code by moving the function
> to nf_conntrack_ovs.
>
> Note that skb_clear_hash(skb) or skb->ignore_df = 1 should be
> done only when defrag returns 0, as it does in other places
> in kernel.
>
> Signed-off-by: Xin Long <lucien.xin@gmail.com>
> ---

Reviewed-by: Aaron Conole <aconole@redhat.com>


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

* Re: [PATCHv2 net-next 0/5] net: move more duplicate code of ovs and tc conntrack into nf_conntrack_ovs
  2023-02-07 22:52 [PATCHv2 net-next 0/5] net: move more duplicate code of ovs and tc conntrack into nf_conntrack_ovs Xin Long
                   ` (4 preceding siblings ...)
  2023-02-07 22:52 ` [PATCHv2 net-next 5/5] net: extract nf_ct_handle_fragments to nf_conntrack_ovs Xin Long
@ 2023-02-10  6:21 ` Jakub Kicinski
  2023-02-10 10:35   ` Florian Westphal
  2023-02-11  0:30 ` patchwork-bot+netdevbpf
  6 siblings, 1 reply; 18+ messages in thread
From: Jakub Kicinski @ 2023-02-10  6:21 UTC (permalink / raw)
  To: Pablo Neira Ayuso
  Cc: Xin Long, network dev, dev, davem, Eric Dumazet, Paolo Abeni,
	Pravin B Shelar, Jamal Hadi Salim, Cong Wang, Jiri Pirko,
	Florian Westphal, Marcelo Ricardo Leitner, Ilya Maximets,
	Aaron Conole

On Tue,  7 Feb 2023 17:52:05 -0500 Xin Long wrote:
> We've moved some duplicate code into nf_nat_ovs in:
> 
>   "net: eliminate the duplicate code in the ct nat functions of ovs and tc"
> 
> This patchset addresses more code duplication in the conntrack of ovs
> and tc then creates nf_conntrack_ovs for them, and four functions will
> be extracted and moved into it:
> 
>   nf_ct_handle_fragments()
>   nf_ct_skb_network_trim()
>   nf_ct_helper()
>   nf_ct_add_helper()

Hi Pablo, do you prefer to take this or should we?

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

* Re: [PATCHv2 net-next 0/5] net: move more duplicate code of ovs and tc conntrack into nf_conntrack_ovs
  2023-02-10  6:21 ` [PATCHv2 net-next 0/5] net: move more duplicate code of ovs and tc conntrack into nf_conntrack_ovs Jakub Kicinski
@ 2023-02-10 10:35   ` Florian Westphal
  0 siblings, 0 replies; 18+ messages in thread
From: Florian Westphal @ 2023-02-10 10:35 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Pablo Neira Ayuso, Xin Long, network dev, dev, davem,
	Eric Dumazet, Paolo Abeni, Pravin B Shelar, Jamal Hadi Salim,
	Cong Wang, Jiri Pirko, Florian Westphal, Marcelo Ricardo Leitner,
	Ilya Maximets, Aaron Conole

Jakub Kicinski <kuba@kernel.org> wrote:
> On Tue,  7 Feb 2023 17:52:05 -0500 Xin Long wrote:
> > We've moved some duplicate code into nf_nat_ovs in:
> > 
> >   "net: eliminate the duplicate code in the ct nat functions of ovs and tc"
> > 
> > This patchset addresses more code duplication in the conntrack of ovs
> > and tc then creates nf_conntrack_ovs for them, and four functions will
> > be extracted and moved into it:
> > 
> >   nf_ct_handle_fragments()
> >   nf_ct_skb_network_trim()
> >   nf_ct_helper()
> >   nf_ct_add_helper()
> 
> Hi Pablo, do you prefer to take this or should we?

Looks like Pablo is very busy atm, I have no objections
if this is applied to net-next.

You may add
Acked-by: Florian Westphal <fw@strlen.de>

if you like.

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

* Re: [PATCHv2 net-next 0/5] net: move more duplicate code of ovs and tc conntrack into nf_conntrack_ovs
  2023-02-07 22:52 [PATCHv2 net-next 0/5] net: move more duplicate code of ovs and tc conntrack into nf_conntrack_ovs Xin Long
                   ` (5 preceding siblings ...)
  2023-02-10  6:21 ` [PATCHv2 net-next 0/5] net: move more duplicate code of ovs and tc conntrack into nf_conntrack_ovs Jakub Kicinski
@ 2023-02-11  0:30 ` patchwork-bot+netdevbpf
  6 siblings, 0 replies; 18+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-02-11  0:30 UTC (permalink / raw)
  To: Xin Long
  Cc: netdev, dev, davem, kuba, edumazet, pabeni, pshelar, jhs,
	xiyou.wangcong, jiri, pablo, fw, marcelo.leitner, i.maximets,
	aconole

Hello:

This series was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Tue,  7 Feb 2023 17:52:05 -0500 you wrote:
> We've moved some duplicate code into nf_nat_ovs in:
> 
>   "net: eliminate the duplicate code in the ct nat functions of ovs and tc"
> 
> This patchset addresses more code duplication in the conntrack of ovs
> and tc then creates nf_conntrack_ovs for them, and four functions will
> be extracted and moved into it:
> 
> [...]

Here is the summary with links:
  - [PATCHv2,net-next,1/5] net: create nf_conntrack_ovs for ovs and tc use
    https://git.kernel.org/netdev/net-next/c/c0c3ab63de60
  - [PATCHv2,net-next,2/5] net: extract nf_ct_skb_network_trim function to nf_conntrack_ovs
    https://git.kernel.org/netdev/net-next/c/67fc5d7ffbd4
  - [PATCHv2,net-next,3/5] openvswitch: move key and ovs_cb update out of handle_fragments
    https://git.kernel.org/netdev/net-next/c/1b83bf4489cb
  - [PATCHv2,net-next,4/5] net: sched: move frag check and tc_skb_cb update out of handle_fragments
    https://git.kernel.org/netdev/net-next/c/558d95e7e11c
  - [PATCHv2,net-next,5/5] net: extract nf_ct_handle_fragments to nf_conntrack_ovs
    https://git.kernel.org/netdev/net-next/c/0785407e78d4

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2023-02-11  0:30 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-07 22:52 [PATCHv2 net-next 0/5] net: move more duplicate code of ovs and tc conntrack into nf_conntrack_ovs Xin Long
2023-02-07 22:52 ` [PATCHv2 net-next 1/5] net: create nf_conntrack_ovs for ovs and tc use Xin Long
2023-02-08 10:15   ` Simon Horman
2023-02-09 14:59   ` Aaron Conole
2023-02-07 22:52 ` [PATCHv2 net-next 2/5] net: extract nf_ct_skb_network_trim function to nf_conntrack_ovs Xin Long
2023-02-08 10:15   ` Simon Horman
2023-02-09 15:00   ` Aaron Conole
2023-02-07 22:52 ` [PATCHv2 net-next 3/5] openvswitch: move key and ovs_cb update out of handle_fragments Xin Long
2023-02-08 10:16   ` Simon Horman
2023-02-09 15:01   ` Aaron Conole
2023-02-07 22:52 ` [PATCHv2 net-next 4/5] net: sched: move frag check and tc_skb_cb " Xin Long
2023-02-08 10:16   ` Simon Horman
2023-02-07 22:52 ` [PATCHv2 net-next 5/5] net: extract nf_ct_handle_fragments to nf_conntrack_ovs Xin Long
2023-02-08 10:17   ` Simon Horman
2023-02-09 15:08   ` Aaron Conole
2023-02-10  6:21 ` [PATCHv2 net-next 0/5] net: move more duplicate code of ovs and tc conntrack into nf_conntrack_ovs Jakub Kicinski
2023-02-10 10:35   ` Florian Westphal
2023-02-11  0:30 ` patchwork-bot+netdevbpf

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.