Skip to content

Commit c7f79f2

Browse files
Florian Westphaldavem330
authored andcommitted
openvswitch: 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 precise 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: Aaron Conole <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent aba43bd commit c7f79f2

File tree

1 file changed

+37
-10
lines changed

1 file changed

+37
-10
lines changed

net/openvswitch/conntrack.c

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,8 @@ static int ovs_ct_nat(struct net *net, struct sw_flow_key *key,
679679
action |= BIT(NF_NAT_MANIP_DST);
680680

681681
err = nf_ct_nat(skb, ct, ctinfo, &action, &info->range, info->commit);
682+
if (err != NF_ACCEPT)
683+
return err;
682684

683685
if (action & BIT(NF_NAT_MANIP_SRC))
684686
ovs_nat_update_key(key, skb, NF_NAT_MANIP_SRC);
@@ -697,6 +699,22 @@ static int ovs_ct_nat(struct net *net, struct sw_flow_key *key,
697699
}
698700
#endif
699701

702+
static int verdict_to_errno(unsigned int verdict)
703+
{
704+
switch (verdict & NF_VERDICT_MASK) {
705+
case NF_ACCEPT:
706+
return 0;
707+
case NF_DROP:
708+
return -EINVAL;
709+
case NF_STOLEN:
710+
return -EINPROGRESS;
711+
default:
712+
break;
713+
}
714+
715+
return -EINVAL;
716+
}
717+
700718
/* Pass 'skb' through conntrack in 'net', using zone configured in 'info', if
701719
* not done already. Update key with new CT state after passing the packet
702720
* through conntrack.
@@ -735,7 +753,7 @@ static int __ovs_ct_lookup(struct net *net, struct sw_flow_key *key,
735753

736754
err = nf_conntrack_in(skb, &state);
737755
if (err != NF_ACCEPT)
738-
return -ENOENT;
756+
return verdict_to_errno(err);
739757

740758
/* Clear CT state NAT flags to mark that we have not yet done
741759
* NAT after the nf_conntrack_in() call. We can actually clear
@@ -762,9 +780,12 @@ static int __ovs_ct_lookup(struct net *net, struct sw_flow_key *key,
762780
* the key->ct_state.
763781
*/
764782
if (info->nat && !(key->ct_state & OVS_CS_F_NAT_MASK) &&
765-
(nf_ct_is_confirmed(ct) || info->commit) &&
766-
ovs_ct_nat(net, key, info, skb, ct, ctinfo) != NF_ACCEPT) {
767-
return -EINVAL;
783+
(nf_ct_is_confirmed(ct) || info->commit)) {
784+
int err = ovs_ct_nat(net, key, info, skb, ct, ctinfo);
785+
786+
err = verdict_to_errno(err);
787+
if (err)
788+
return err;
768789
}
769790

770791
/* Userspace may decide to perform a ct lookup without a helper
@@ -795,9 +816,12 @@ static int __ovs_ct_lookup(struct net *net, struct sw_flow_key *key,
795816
* - When committing an unconfirmed connection.
796817
*/
797818
if ((nf_ct_is_confirmed(ct) ? !cached || add_helper :
798-
info->commit) &&
799-
nf_ct_helper(skb, ct, ctinfo, info->family) != NF_ACCEPT) {
800-
return -EINVAL;
819+
info->commit)) {
820+
int err = nf_ct_helper(skb, ct, ctinfo, info->family);
821+
822+
err = verdict_to_errno(err);
823+
if (err)
824+
return err;
801825
}
802826

803827
if (nf_ct_protonum(ct) == IPPROTO_TCP &&
@@ -1001,10 +1025,9 @@ static int ovs_ct_commit(struct net *net, struct sw_flow_key *key,
10011025
/* This will take care of sending queued events even if the connection
10021026
* is already confirmed.
10031027
*/
1004-
if (nf_conntrack_confirm(skb) != NF_ACCEPT)
1005-
return -EINVAL;
1028+
err = nf_conntrack_confirm(skb);
10061029

1007-
return 0;
1030+
return verdict_to_errno(err);
10081031
}
10091032

10101033
/* Returns 0 on success, -EINPROGRESS if 'skb' is stolen, or other nonzero
@@ -1039,6 +1062,10 @@ int ovs_ct_execute(struct net *net, struct sk_buff *skb,
10391062
else
10401063
err = ovs_ct_lookup(net, key, info, skb);
10411064

1065+
/* conntrack core returned NF_STOLEN */
1066+
if (err == -EINPROGRESS)
1067+
return err;
1068+
10421069
skb_push_rcsum(skb, nh_ofs);
10431070
if (err)
10441071
ovs_kfree_skb_reason(skb, OVS_DROP_CONNTRACK);

0 commit comments

Comments
 (0)