Skip to content

Commit 3abbd7e

Browse files
Florian Westphaldavem330
authored andcommitted
act_ct: prepare for stolen verdict coming from conntrack and nat engine
At this time, conntrack either returns NF_ACCEPT or NF_DROP. To improve debuging it would be nice to be able to replace NF_DROP verdict with NF_DROP_REASON() helper, This helper releases the skb instantly (so drop_monitor can pinpoint exact location) and returns NF_STOLEN. Prepare call sites to deal with this before introducing such changes in conntrack and nat core. Signed-off-by: Florian Westphal <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 2f5e639 commit 3abbd7e

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

net/sched/act_ct.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,8 @@ static int tcf_ct_act_nat(struct sk_buff *skb,
944944
action |= BIT(NF_NAT_MANIP_DST);
945945

946946
err = nf_ct_nat(skb, ct, ctinfo, &action, range, commit);
947+
if (err != NF_ACCEPT)
948+
return err & NF_VERDICT_MASK;
947949

948950
if (action & BIT(NF_NAT_MANIP_SRC))
949951
tc_skb_cb(skb)->post_ct_snat = 1;
@@ -1035,7 +1037,7 @@ TC_INDIRECT_SCOPE int tcf_ct_act(struct sk_buff *skb, const struct tc_action *a,
10351037
state.pf = family;
10361038
err = nf_conntrack_in(skb, &state);
10371039
if (err != NF_ACCEPT)
1038-
goto out_push;
1040+
goto nf_error;
10391041
}
10401042

10411043
do_nat:
@@ -1047,7 +1049,7 @@ TC_INDIRECT_SCOPE int tcf_ct_act(struct sk_buff *skb, const struct tc_action *a,
10471049

10481050
err = tcf_ct_act_nat(skb, ct, ctinfo, p->ct_action, &p->range, commit);
10491051
if (err != NF_ACCEPT)
1050-
goto drop;
1052+
goto nf_error;
10511053

10521054
if (!nf_ct_is_confirmed(ct) && commit && p->helper && !nfct_help(ct)) {
10531055
err = __nf_ct_try_assign_helper(ct, p->tmpl, GFP_ATOMIC);
@@ -1061,8 +1063,9 @@ TC_INDIRECT_SCOPE int tcf_ct_act(struct sk_buff *skb, const struct tc_action *a,
10611063
}
10621064

10631065
if (nf_ct_is_confirmed(ct) ? ((!cached && !skip_add) || add_helper) : commit) {
1064-
if (nf_ct_helper(skb, ct, ctinfo, family) != NF_ACCEPT)
1065-
goto drop;
1066+
err = nf_ct_helper(skb, ct, ctinfo, family);
1067+
if (err != NF_ACCEPT)
1068+
goto nf_error;
10661069
}
10671070

10681071
if (commit) {
@@ -1075,8 +1078,9 @@ TC_INDIRECT_SCOPE int tcf_ct_act(struct sk_buff *skb, const struct tc_action *a,
10751078
/* This will take care of sending queued events
10761079
* even if the connection is already confirmed.
10771080
*/
1078-
if (nf_conntrack_confirm(skb) != NF_ACCEPT)
1079-
goto drop;
1081+
err = nf_conntrack_confirm(skb);
1082+
if (err != NF_ACCEPT)
1083+
goto nf_error;
10801084
}
10811085

10821086
if (!skip_add)
@@ -1100,6 +1104,21 @@ TC_INDIRECT_SCOPE int tcf_ct_act(struct sk_buff *skb, const struct tc_action *a,
11001104
drop:
11011105
tcf_action_inc_drop_qstats(&c->common);
11021106
return TC_ACT_SHOT;
1107+
1108+
nf_error:
1109+
/* some verdicts store extra data in upper bits, such
1110+
* as errno or queue number.
1111+
*/
1112+
switch (err & NF_VERDICT_MASK) {
1113+
case NF_DROP:
1114+
goto drop;
1115+
case NF_STOLEN:
1116+
tcf_action_inc_drop_qstats(&c->common);
1117+
return TC_ACT_CONSUMED;
1118+
default:
1119+
DEBUG_NET_WARN_ON_ONCE(1);
1120+
goto drop;
1121+
}
11031122
}
11041123

11051124
static const struct nla_policy ct_policy[TCA_CT_MAX + 1] = {

0 commit comments

Comments
 (0)