net/sched: act_mirred: refactor the handle of xmit
Subsystems (3)
PATCH v2 1/2 net/sched: act_mirred: refactor the handle of xmit
From: wenxu <[email protected]>
This one is prepare for the next patch.
---
v2: 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 v2 2/2 net/sched: act_frag: add implict packet fragment support.
From: wenxu <[email protected]>
Currently kernel tc subsystem can do conntrack in cat_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: make tcf_frag_xmit_hook_in_use static
and set frag xmit hook in the act_ct directly.
include/net/act_api.h | 23 ++++++ net/sched/Kconfig | 12 +++ net/sched/Makefile | 1 + net/sched/act_ct.c | 3 + net/sched/act_frag.c | 207 +++++++++++++++++++++++++++++++++++++++++++++++++ net/sched/act_mirred.c | 10 ++- 6 files changed, 253 insertions(+), 3 deletions(-) create mode 100644 net/sched/act_frag.c
include/net/act_api.h +23 -0
@@ -239,6 +239,29 @@ 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); + +#if IS_ENABLED (CONFIG_NET_ACT_FRAG ) +int tcf_exec_frag_xmit_hook (struct sk_buff *skb,int (*xmit)(struct sk_buff *skb)); +void tcf_set_frag_xmit_hook (void ); +void tcf_clear_frag_xmit_hook (void ); +bool tcf_frag_xmit_hook_enabled (void ); +#else +static inline int tcf_exec_frag_xmit_hook (struct sk_buff *skb,int (*xmit)(struct sk_buff *skb)) +{ +return 0 ; +} +static inline void tcf_set_frag_xmit_hook (void ) +{ +} +static inline void tcf_clear_frag_xmit_hook (void ) +{ +} +static inline bool tcf_frag_xmit_hook_enabled (void ) +{ +return false; +} +#endif +#endif /* CONFIG_NET_CLS_ACT */ static inline void tcf_action_stats_update(struct tc_action *a, u64 bytes,
net/sched/Kconfig +12 -0
@@ -974,9 +974,21 @@ 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 "send packets do frag" + depends on NET_CLS_ACT + help + Say Y here to allow sending the packets to do frag + + 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_ct.c +3 -0
@@ -1541,6 +1541,8 @@ static int __init ct_init_module(void)if (err) goto err_register; +tcf_set_frag_xmit_hook (); +return 0 ; err_register:
@@ -1552,6 +1554,7 @@ static int __init ct_init_module(void) static void __exit ct_cleanup_module(void) { +tcf_clear_frag_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 +207 -0
207 lines not on this page · raw message
net/sched/act_mirred.c +7 -3
@@ -209,10 +209,14 @@ static int tcf_mirred_forward(bool want_ingress, struct sk_buff *skb) {int err; -if (!want_ingress) - err =dev_queue_xmit (skb); -else +if (!want_ingress) { +if (tcf_frag_xmit_hook_enabled ()) + err =tcf_exec_frag_xmit_hook (skb, dev_queue_xmit); +else + err =dev_queue_xmit (skb); + }else { err =netif_receive_skb (skb); + }return err; }
Signature · 1 line
1.8.3.1
Re: [PATCH v2 net-next 2/2] net/sched: act_frag: add implict packet fragment support.
On Thu, Nov 05, 2020 at 03:52:27PM +0800, [email protected] wrote:
We cross-posted :)
I think my comments on the v1 still applies, btw.
...
Quoted 3 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.
...
include/net/act_api.h int tcf_action_check_ctrlact(int action, struct tcf_proto *tp, · line 247
Quoted 12 lines
include/net/act_api.h +6
-0@@ -239,6 +239,29 @@ 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); + +#if IS_ENABLED (CONFIG_NET_ACT_FRAG ) +int tcf_exec_frag_xmit_hook (struct sk_buff *skb,int (*xmit)(struct sk_buff *skb)); +void tcf_set_frag_xmit_hook (void ); +void tcf_clear_frag_xmit_hook (void ); +bool tcf_frag_xmit_hook_enabled (void );
Now it's naming the hook after frag action, but it's meant to be generic. It got confusing on what is local to act_frag or not due to that.
Re: [PATCH v2 net-next 2/2] net/sched: act_frag: add implict packet fragment support.
Quoted 10 lines · Marcelo Ricardo Leitner
On Thu, Nov 05, 2020 at 03:52:27PM +0800, [email protected] wrote:
We cross-posted :)
I think my comments on the v1 still applies, btw....
Quoted 3 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....
Quoted 15 lines
include/net/act_api.h int tcf_action_check_ctrlact(int action, struct tcf_proto *tp, · line 247
Quoted 12 lines
include/net/act_api.h +6
-0@@ -239,6 +239,29 @@ 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); + +#if IS_ENABLED (CONFIG_NET_ACT_FRAG ) +int tcf_exec_frag_xmit_hook (struct sk_buff *skb,int (*xmit)(struct sk_buff *skb)); +void tcf_set_frag_xmit_hook (void ); +void tcf_clear_frag_xmit_hook (void ); +bool tcf_frag_xmit_hook_enabled (void );Now it's naming the hook after frag action, but it's meant to be generic. It got confusing on what is local to
act_fragor not due to that.
You are right. For more gneric the tcf_xx-xmit_hook should put back to common place and not only used for act_frag.