diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2017-10-06 16:44:31 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2017-10-06 16:44:31 +0200 |
commit | 961d655b161c62aa97b4220106f1c34dbeadb9ee (patch) | |
tree | 7ce5a05c2fe01ca49e32d73207ff627c593f9c82 /src/socket.c | |
parent | socket: compare while unlocked first (diff) | |
download | wireguard-monolithic-historical-961d655b161c62aa97b4220106f1c34dbeadb9ee.tar.xz wireguard-monolithic-historical-961d655b161c62aa97b4220106f1c34dbeadb9ee.zip |
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>
Diffstat (limited to 'src/socket.c')
-rw-r--r-- | src/socket.c | 10 |
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; |