Skip to content

Commit

Permalink
conntrack: Add rcu support.
Browse files Browse the repository at this point in the history
For performance and code simplification reasons, add rcu support for
conntrack. The array of hmaps is replaced by a cmap as part of this
conversion.  Using a single map also simplifies the handling of NAT
and allows the removal of the nat_conn map and friends.  Per connection
entry locks are introduced, which are needed in a few code paths.

Signed-off-by: Darrell Ball <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
darball1 authored and blp committed May 9, 2019
1 parent fe772f5 commit 967bb5c
Show file tree
Hide file tree
Showing 7 changed files with 457 additions and 859 deletions.
27 changes: 10 additions & 17 deletions lib/conntrack-icmp.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2016 Nicira, Inc.
* Copyright (c) 2015-2019 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,14 +24,14 @@
#include "conntrack-private.h"
#include "dp-packet.h"

enum icmp_state {
enum OVS_PACKED_ENUM icmp_state {
ICMPS_FIRST,
ICMPS_REPLY,
};

struct conn_icmp {
struct conn up;
enum icmp_state state;
enum icmp_state state; /* 'conn' lock protected. */
};

static const enum ct_timeout icmp_timeouts[] = {
Expand All @@ -46,16 +46,12 @@ conn_icmp_cast(const struct conn *conn)
}

static enum ct_update_res
icmp_conn_update(struct conn *conn_, struct conntrack_bucket *ctb,
icmp_conn_update(struct conntrack *ct, struct conn *conn_,
struct dp_packet *pkt OVS_UNUSED, bool reply, long long now)
{
struct conn_icmp *conn = conn_icmp_cast(conn_);

if (reply && conn->state != ICMPS_REPLY) {
conn->state = ICMPS_REPLY;
}

conn_update_expiration(ctb, &conn->up, icmp_timeouts[conn->state], now);
conn->state = reply ? ICMPS_REPLY : ICMPS_FIRST;
conn_update_expiration(ct, &conn->up, icmp_timeouts[conn->state], now);

return CT_UPDATE_VALID;
}
Expand All @@ -79,15 +75,12 @@ icmp6_valid_new(struct dp_packet *pkt)
}

static struct conn *
icmp_new_conn(struct conntrack_bucket *ctb, struct dp_packet *pkt OVS_UNUSED,
long long now)
icmp_new_conn(struct conntrack *ct, struct dp_packet *pkt OVS_UNUSED,
long long now)
{
struct conn_icmp *conn;

conn = xzalloc(sizeof *conn);
struct conn_icmp *conn = xzalloc(sizeof *conn);
conn->state = ICMPS_FIRST;

conn_init_expiration(ctb, &conn->up, icmp_timeouts[conn->state], now);
conn_init_expiration(ct, &conn->up, icmp_timeouts[conn->state], now);

return &conn->up;
}
Expand Down
14 changes: 7 additions & 7 deletions lib/conntrack-other.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2016 Nicira, Inc.
* Copyright (c) 2015-2019 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,15 +19,15 @@
#include "conntrack-private.h"
#include "dp-packet.h"

enum other_state {
enum OVS_PACKED_ENUM other_state {
OTHERS_FIRST,
OTHERS_MULTIPLE,
OTHERS_BIDIR,
};

struct conn_other {
struct conn up;
enum other_state state;
enum other_state state; /* 'conn' lock protected. */
};

static const enum ct_timeout other_timeouts[] = {
Expand All @@ -43,7 +43,7 @@ conn_other_cast(const struct conn *conn)
}

static enum ct_update_res
other_conn_update(struct conn *conn_, struct conntrack_bucket *ctb,
other_conn_update(struct conntrack *ct, struct conn *conn_,
struct dp_packet *pkt OVS_UNUSED, bool reply, long long now)
{
struct conn_other *conn = conn_other_cast(conn_);
Expand All @@ -54,7 +54,7 @@ other_conn_update(struct conn *conn_, struct conntrack_bucket *ctb,
conn->state = OTHERS_MULTIPLE;
}

conn_update_expiration(ctb, &conn->up, other_timeouts[conn->state], now);
conn_update_expiration(ct, &conn->up, other_timeouts[conn->state], now);

return CT_UPDATE_VALID;
}
Expand All @@ -66,15 +66,15 @@ other_valid_new(struct dp_packet *pkt OVS_UNUSED)
}

static struct conn *
other_new_conn(struct conntrack_bucket *ctb, struct dp_packet *pkt OVS_UNUSED,
other_new_conn(struct conntrack *ct, struct dp_packet *pkt OVS_UNUSED,
long long now)
{
struct conn_other *conn;

conn = xzalloc(sizeof *conn);
conn->state = OTHERS_FIRST;

conn_init_expiration(ctb, &conn->up, other_timeouts[conn->state], now);
conn_init_expiration(ct, &conn->up, other_timeouts[conn->state], now);

return &conn->up;
}
Expand Down
Loading

0 comments on commit 967bb5c

Please sign in to comment.