Skip to content

Commit 28b6e0c

Browse files
Jarno Rajahalmeummakynes
authored andcommitted
openvswitch: Delay conntrack helper call for new connections.
There is no need to help connections that are not confirmed, so we can delay helping new connections to the time when they are confirmed. This change is needed for NAT support, and having this as a separate patch will make the following NAT patch a bit easier to review. Signed-off-by: Jarno Rajahalme <[email protected]> Acked-by: Joe Stringer <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 5b6b929 commit 28b6e0c

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

net/openvswitch/conntrack.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,11 @@ static int __ovs_ct_lookup(struct net *net, struct sw_flow_key *key,
483483
* actually run the packet through conntrack twice unless it's for a
484484
* different zone.
485485
*/
486-
if (!skb_nfct_cached(net, key, info, skb)) {
486+
bool cached = skb_nfct_cached(net, key, info, skb);
487+
enum ip_conntrack_info ctinfo;
488+
struct nf_conn *ct;
489+
490+
if (!cached) {
487491
struct nf_conn *tmpl = info->ct;
488492
int err;
489493

@@ -506,11 +510,18 @@ static int __ovs_ct_lookup(struct net *net, struct sw_flow_key *key,
506510
return -ENOENT;
507511

508512
ovs_ct_update_key(skb, info, key, true);
513+
}
509514

510-
if (ovs_ct_helper(skb, info->family) != NF_ACCEPT) {
511-
WARN_ONCE(1, "helper rejected packet");
512-
return -EINVAL;
513-
}
515+
/* Call the helper only if:
516+
* - nf_conntrack_in() was executed above ("!cached") for a confirmed
517+
* connection, or
518+
* - When committing an unconfirmed connection.
519+
*/
520+
ct = nf_ct_get(skb, &ctinfo);
521+
if (ct && (nf_ct_is_confirmed(ct) ? !cached : info->commit) &&
522+
ovs_ct_helper(skb, info->family) != NF_ACCEPT) {
523+
WARN_ONCE(1, "helper rejected packet");
524+
return -EINVAL;
514525
}
515526

516527
return 0;

0 commit comments

Comments
 (0)