From 6bab28be395026e100ee844ee9540c3b04457258 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Fri, 6 Oct 2017 16:44:31 +0200 Subject: 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 Signed-off-by: Jason A. Donenfeld --- src/socket.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src') 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; -- cgit v1.2.3