summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-10-06 16:44:31 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2017-10-06 16:44:31 +0200
commit6bab28be395026e100ee844ee9540c3b04457258 (patch)
tree10e673762577e1cb132f8b2cc44018415e240acf
parent8dddbdf210d4b478a7b9708e770163a3496e1b40 (diff)
socket: don't bother recomparing afterwards
It doesn't actually matter if this races, so there's no point in making the hot path slower with the stack copy. Suggested-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--src/socket.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/socket.c b/src/socket.c
index b259578..ff9f449 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -237,15 +237,13 @@ static inline bool endpoint_eq(const struct endpoint *a, const struct endpoint *
void socket_set_peer_endpoint(struct wireguard_peer *peer, const struct endpoint *endpoint)
{
- const struct endpoint previous_endpoint = peer->endpoint;
/* First we check unlocked, in order to optimize, since it's pretty rare
- * that an endpoint will change. */
- if (endpoint_eq(endpoint, &previous_endpoint))
+ * that an endpoint will change. If we happen to be mid-write, and two
+ * CPUs wind up writing the same thing or something slightly different,
+ * it doesn't really matter much either. */
+ if (endpoint_eq(endpoint, &peer->endpoint))
return;
write_lock_bh(&peer->endpoint_lock);
- /* Now we double check while locked, in case a different CPU got here first. */
- if (!endpoint_eq(&peer->endpoint, &previous_endpoint))
- goto out;
if (endpoint->addr.sa_family == AF_INET) {
peer->endpoint.addr4 = endpoint->addr4;
peer->endpoint.src4 = endpoint->src4;