net/sched: act_mirred: refactor the handle of xmit
Subsystems (3)
PATCH v3 1/2 net/sched: act_mirred: refactor the handle of xmit
From: wenxu <[email protected]>
This one is prepare for the next patch.
---
v3: no change
include/net/sch_generic.h | 5 ----- net/sched/act_mirred.c | 21 +++++++++++++++------ 2 files changed, 15 insertions(+), 11 deletions(-)
include/net/sch_generic.h +0 -5
@@ -1281,9 +1281,4 @@ void mini_qdisc_pair_init(struct mini_Qdisc_pair *miniqp, struct Qdisc *qdisc,void mini_qdisc_pair_block_init (struct mini_Qdisc_pair *miniqp,struct tcf_block *block); -static inline int skb_tc_reinsert (struct sk_buff *skb,struct tcf_result *res) -{ -return res->ingress ?netif_receive_skb (skb) :dev_queue_xmit (skb); -} -#endif
net/sched/act_mirred.c +15 -6
@@ -205,6 +205,18 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla,return err; } +static int tcf_mirred_forward (bool want_ingress,struct sk_buff *skb) +{ +int err; + +if (!want_ingress) + err =dev_queue_xmit (skb); +else + err =netif_receive_skb (skb); + +return err; +} +static int tcf_mirred_act (struct sk_buff *skb,const struct tc_action *a,struct tcf_result *res) {
@@ -287,18 +299,15 @@ static int tcf_mirred_act(struct sk_buff *skb, const struct tc_action *a,/* let's the caller reinsert the packet, if possible */ if (use_reinsert) { res->ingress = want_ingress; -if (skb_tc_reinsert (skb, res)) + err =tcf_mirred_forward (res->ingress, skb); +if (err)tcf_action_inc_overlimit_qstats (&m->common);__this_cpu_dec (mirred_rec_level);return TC_ACT_CONSUMED ; } } -if (!want_ingress) - err =dev_queue_xmit (skb2); -else - err =netif_receive_skb (skb2); - + err =tcf_mirred_forward (want_ingress, skb2);if (err) { out:tcf_action_inc_overlimit_qstats (&m->common);
Signature · 1 line
1.8.3.1
PATCH v3 2/2 net/sched: act_frag: add implict packet fragment support.
From: wenxu <[email protected]>
Currently kernel tc subsystem can do conntrack in act_ct. But when several fragment packets go through the act_ct, function tcf_ct_handle_fragments will defrag the packets to a big one. But the last action will redirect mirred to a device which maybe lead the reassembly big packet over the mtu of target device.
This patch add support for a xmit hook to mirred, that gets executed before xmiting the packet. Then, when act_ct gets loaded, it configs that hook. The frag xmit hook maybe reused by other modules.
---
v2: Fix the crash for act_frag module without load
v3: modify the kconfig describe and put tcf_xmit_hook_is_enabled in the tcf_dev_queue_xmit, and xchg atomic for tcf_xmit_hook
include/net/act_api.h | 17 ++++++ net/sched/Kconfig | 13 ++++ net/sched/Makefile | 1 + net/sched/act_api.c | 51 ++++++++++++++++ net/sched/act_ct.c | 7 +++ net/sched/act_frag.c | 162 +++++++++++++++++++++++++++++++++++++++++++++++++ net/sched/act_mirred.c | 2 +- 7 files changed, 252 insertions(+), 1 deletion(-) create mode 100644 net/sched/act_frag.c
include/net/act_api.h +17 -0
@@ -239,6 +239,23 @@ int tcf_action_check_ctrlact(int action, struct tcf_proto *tp, struct netlink_ext_ack *newchain);struct tcf_chain *tcf_action_set_ctrlact (struct tc_action *a,int action,struct tcf_chain *newchain); + +int tcf_dev_queue_xmit (struct sk_buff *skb,int (*xmit)(struct sk_buff *skb)); +int tcf_set_xmit_hook (int (*xmit_hook)(struct sk_buff *skb, +int (*xmit)(struct sk_buff *skb))); +void tcf_clear_xmit_hook (void ); + +#if IS_ENABLED (CONFIG_NET_ACT_FRAG ) +int tcf_frag_xmit_hook (struct sk_buff *skb,int (*xmit)(struct sk_buff *skb)); +#else +static inline int tcf_frag_xmit_hook (struct sk_buff *skb, +int (*xmit)(struct sk_buff *skb)) +{ +return 0 ; +} +#endif + +#endif /* CONFIG_NET_CLS_ACT */ static inline void tcf_action_stats_update(struct tc_action *a, u64 bytes,
net/sched/Kconfig +13 -0
@@ -974,9 +974,22 @@ config NET_ACT_TUNNEL_KEY To compile this code as a module, choose M here: the module will be called act_tunnel_key. +config NET_ACT_FRAG + tristate "Packet fragmentation" + depends on NET_CLS_ACT + help + Say Y here to allow fragmenting big packets when outputting + with the mirred action. + + If unsure, say N. + + To compile this code as a module, choose M here: the + module will be called act_frag. + config NET_ACT_CT tristate "connection tracking tc action" depends on NET_CLS_ACT && NF_CONNTRACK && NF_NAT && NF_FLOW_TABLE + depends on NET_ACT_FRAG help Say Y here to allow sending the packets to conntrack module.
net/sched/Makefile +1 -0
@@ -29,6 +29,7 @@ obj-$(CONFIG_NET_IFE_SKBMARK) += act_meta_mark.o obj-$(CONFIG_NET_IFE_SKBPRIO) += act_meta_skbprio.o obj-$(CONFIG_NET_IFE_SKBTCINDEX) += act_meta_skbtcindex.o obj-$(CONFIG_NET_ACT_TUNNEL_KEY)+= act_tunnel_key.o +obj-$(CONFIG_NET_ACT_FRAG) += act_frag.o obj-$(CONFIG_NET_ACT_CT) += act_ct.o obj-$(CONFIG_NET_ACT_GATE) += act_gate.o obj-$(CONFIG_NET_SCH_FIFO) += sch_fifo.o
net/sched/act_api.c +51 -0
57 lines not on this page · raw message
net/sched/act_ct.c +7 -0
@@ -1541,8 +1541,14 @@ static int __init ct_init_module(void)if (err) goto err_register; + err =tcf_set_xmit_hook (tcf_frag_xmit_hook); +if (err) + goto err_action; +return 0 ; +err_action: +tcf_unregister_action (&act_ct_ops, &ct_net_ops); err_register:tcf_ct_flow_tables_uninit (); err_tbl_init:
@@ -1552,6 +1558,7 @@ static int __init ct_init_module(void) static void __exit ct_cleanup_module(void) { +tcf_clear_xmit_hook ();tcf_unregister_action (&act_ct_ops, &ct_net_ops);tcf_ct_flow_tables_uninit ();destroy_workqueue (act_ct_wq);
net/sched/act_frag.c new file +162 -0
162 lines not on this page · raw message
net/sched/act_mirred.c +1 -1
@@ -210,7 +210,7 @@ static int tcf_mirred_forward(bool want_ingress, struct sk_buff *skb)int err;if (!want_ingress) - err =dev_queue_xmit (skb); + err =tcf_dev_queue_xmit (skb, dev_queue_xmit);else err =netif_receive_skb (skb);
Signature · 1 line
1.8.3.1
Re: [PATCH v3 net-next 2/2] net/sched: act_frag: add implict packet fragment support.
hello wenxu!
Quoted 14 lines · On Thu, 2020-11-05 at 18:41 +0800, [email protected] wrote:
From: wenxu <[email protected]>
Currently kernel tc subsystem can do conntrack in
act_ct. But when several fragment packets go through theact_ct, functiontcf_ct_handle_fragmentswill defrag the packets to a big one. But the last action will redirect mirred to a device which maybe lead the reassembly big packet over the mtu of target device.This patch add support for a xmit hook to mirred, that gets executed before xmiting the packet. Then, when
act_ctgets loaded, it configs that hook. The frag xmit hook maybe reused by other modules.Signed-off-by wenxu <[email protected]>---
[...]
net/sched/act_frag.c line 91
Quoted 10 lines
net/sched/act_frag.c new file +10
-0+ +static int tcf_fragment (struct net *net,struct sk_buff *skb, +u16 mru,int (*xmit)(struct sk_buff *skb)) +{ +if (skb_network_offset (skb) >VLAN_ETH_HLEN ) { +net_warn_ratelimited ("L2 header too long to fragment\n" ); + goto err; + } + +if (skb->protocol ==htons (ETH_P_IP )) {
small nit: use of skb->protocol here may lead to "ambiguous" results: a VLAN "accelerated" packet is properly processed, while the same VLAN packet with "non-accelerated" tag is not processed because skb->protocol is htons(ETH_P_8021Q). Can I suggest use of skb_protocol(), that has been introduced recently by Toke [1] ?
net/sched/act_frag.c line 106
Quoted 3 lines
net/sched/act_frag.c new file +3
-0+ip_do_fragment (net, skb->sk, skb, tcf_frag_xmit); +refdst_drop (orig_dst); + }else if (skb->protocol ==htons (ETH_P_IPV6 )) {
same here,
Quoted 9 lines
net/sched/act_frag.c new file +9
-0+unsigned long orig_dst; +struct rt6_info tcf_frag_rt; + +tcf_frag_prepare_frag (skb, xmit); +memset (&tcf_frag_rt,0 ,sizeof (tcf_frag_rt)); +dst_init (&tcf_frag_rt.dst, &tcf_frag_dst_ops,NULL ,1 , +DST_OBSOLETE_NONE ,DST_NOCOUNT ); + tcf_frag_rt.dst.dev = skb->dev; +
net/sched/act_frag.c line 125
Quoted 10 lines
net/sched/act_frag.c new file +10
-0+ orig_dst = skb->_skb_refdst; +skb_dst_set_noref (skb, &tcf_frag_rt.dst); +IP6CB (skb)->frag_max_size = mru; + + ipv6_stub->ipv6_fragment (net, skb->sk, skb, tcf_frag_xmit); +refdst_drop (orig_dst); + }else { +net_warn_ratelimited ("Failed fragment ->%s: eth=%04x, MRU=%d, MTU=%d.\n" , +netdev_name (skb->dev),ntohs (skb->protocol), + mru, skb->dev->mtu);
and here (even though it's just a printout).
thanks!
Signature · 3 lines
davide [1] https://lore.kernel.org/netdev/[email protected]/
Jakub Kicinski
maintainerRe: [PATCH v3 net-next 2/2] net/sched: act_frag: add implict packet fragment support.
In reply to [email protected]Quoted 8 lines · On Thu, 5 Nov 2020 18:41:33 +0800 [email protected] wrote:
From: wenxu <[email protected]>
Currently kernel tc subsystem can do conntrack in
act_ct. But when several fragment packets go through theact_ct, functiontcf_ct_handle_fragmentswill defrag the packets to a big one. But the last action will redirect mirred to a device which maybe lead the reassembly big packet over the mtu of target device.
Quoted 5 lines
This patch add support for a xmit hook to mirred, that gets executed before xmiting the packet. Then, when
act_ctgets loaded, it configs that hook. The frag xmit hook maybe reused by other modules.Signed-off-by wenxu <[email protected]>
CHECK: Please don't use multiple blank lines
#53: FILE: include/net/act_api.h:258:
+
+
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #186:
new file mode 100644
WARNING: line length of 95 exceeds 80 columns
#224: FILE: net/sched/act_frag.c:34:
+ __vlan_hwaccel_put_tag(skb, data->vlan_proto, data->vlan_tci & ~VLAN_CFI_MASK);
WARNING: line length of 81 exceeds 80 columns
#314: FILE: net/sched/act_frag.c:124:
+ netdev_name(skb->dev), ntohs(skb->protocol),
Re: [PATCH v3 net-next 2/2] net/sched: act_frag: add implict packet fragment support.
In reply to [email protected]Quoted 1 line · On Thu, Nov 05, 2020 at 06:41:33PM +0800, [email protected] wrote:
From: wenxu <[email protected]>
I see Davide's and Jakub's comments. Other than those, I don't have further comments. LGTM!