aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/peer.h (follow)
Commit message (Collapse)AuthorAgeFilesLines
* allowedips: maintain per-peer list of allowedipsJason A. Donenfeld2019-02-261-0/+1
| | | | | | | | This makes `wg show` and `wg showconf` and the like significantly faster, since we don't have to iterate through every node of the trie for every single peer. It also makes netlink cursor resumption much less problematic, since we're just iterating through a list, rather than having to save a traversal stack.
* netlink: use __kernel_timespec for handshake timeJason A. Donenfeld2019-01-231-1/+1
|
* global: update copyrightJason A. Donenfeld2019-01-071-1/+1
|
* timers: it is always reasonable to remove a timerJason A. Donenfeld2018-10-271-1/+1
| | | | | | | | | | | | | | If struct timer_list has not been setup, it is zeroed, in which case timer_pending is false, so calling del_timer is safe. Calling del_timer is also safe on a timer that has already been del_timer'd. And calling del_timer is safe after a peer is dead, since the whole point of it being dead is that no more timers are created and all contexts eventually stop. Finally del_timer uses a lock, which means it's safe to call it concurrently. Therefore, we do not need any guards around calls to del_timer. While we're at it, we can get rid of the old lingering timers_enabled boolean which wasn't doing anything anyway anymore.
* global: rename struct wireguard_ to struct wg_Jason A. Donenfeld2018-10-081-16/+11
| | | | | | This required a bit of pruning of our christmas trees. Suggested-by: Jiri Pirko <jiri@resnulli.us>
* global: prefix all functions with wg_Jason A. Donenfeld2018-10-021-10/+10
| | | | | | | | | | | | | I understand why this must be done, though I'm not so happy about having to do it. In some places, it puts us over 80 chars and we have to break lines up in further ugly ways. And in general, I think this makes things harder to read. Yet another thing we must do to please upstream. Maybe this can be replaced in the future by some kind of automatic module namespacing logic in the linker, or even combined with LTO and aggressive symbol stripping. Suggested-by: Andrew Lunn <andrew@lunn.ch>
* global: put SPDX identifier on its own lineJason A. Donenfeld2018-09-201-2/+2
| | | | | The kernel has very specific rules correlating file type with comment type, and also SPDX identifiers can't be merged with other comments.
* global: run through clang-formatJason A. Donenfeld2018-08-281-6/+15
| | | | | | | This is the worst commit in the whole repo, making the code much less readable, but so it goes with upstream maintainers. We are now woefully wrapped at 80 columns.
* send: switch handshake stamp to an atomicJason A. Donenfeld2018-08-041-1/+1
| | | | | | | | | | | Rather than abusing the handshake lock, we're much better off just using a boring atomic64 for this. It's simpler and performs better. Also, while we're at it, we set the handshake stamp both before and after the calculations, in case the calculations block for a really long time waiting for the RNG to initialize. Otherwise it's possible that when the RNG finally initializes, two handshakes are sent back to back, which isn't sensible.
* peer: ensure destruction doesn't raceJason A. Donenfeld2018-08-031-0/+1
| | | | | Completely rework peer removal to ensure peers don't jump between contexts and create races.
* queueing: keep reference to peer after setting atomic state bitJason A. Donenfeld2018-08-011-1/+2
| | | | | | | | After we atomic_set, the peer is allowed to be freed, which means if we want to continue to reference it, we need to bump the reference count. This was introduced a few commits ago by b713ab0e when implementing some simplification suggestions.
* peer: simplify rcu reference countsJason A. Donenfeld2018-07-311-3/+5
| | | | | | | Use RCU reference counts only when we must, and otherwise use a more reasonably named function. Reported-by: Jann Horn <jann@thejh.net>
* receive: use NAPI on the receive pathJonathan Neuschäfer2018-07-081-0/+1
| | | | | | Suggested-by: Jason A. Donenfeld <Jason@zx2c4.com> [Jason: fixed up the flushing of the rx_queue in peer_remove] Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
* global: use fast boottime instead of normal boottimeJason A. Donenfeld2018-06-231-1/+1
| | | | Generally if we're inaccurate by a few nanoseconds, it doesn't matter.
* global: use ktime boottime instead of jiffiesJason A. Donenfeld2018-06-231-2/+2
| | | | | | | | Since this is a network protocol, expirations need to be accounted for, even across system suspend. On real systems, this isn't a problem, since we're clearing all keys before suspend. But on Android, where we don't do that, this is something of a problem. So, we switch to using boottime instead of jiffies.
* global: year bumpJason A. Donenfeld2018-01-031-1/+1
|
* global: add SPDX tags to all filesGreg Kroah-Hartman2017-12-091-1/+4
| | | | | | | | | | | | | It's good to have SPDX identifiers in all files as the Linux kernel developers are working to add these identifiers to all files. Update all files with the correct SPDX license identifier based on the license text of the project or based on the license in the file itself. The SPDX identifier is a legally binding shorthand, which can be used instead of the full boiler plate text. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Modified-by: Jason A. Donenfeld <Jason@zx2c4.com>
* global: switch from timeval to timespecJason A. Donenfeld2017-11-221-1/+1
| | | | | | | | | | | | | | | | | | | This gets us nanoseconds instead of microseconds, which is better, and we can do this pretty much without freaking out existing userspace, which doesn't actually make use of the nano/micro seconds field: zx2c4@thinkpad ~ $ cat a.c void main() { puts(sizeof(struct timeval) == sizeof(struct timespec) ? "success" : "failure"); } zx2c4@thinkpad ~ $ gcc a.c -m64 && ./a.out success zx2c4@thinkpad ~ $ gcc a.c -m32 && ./a.out success This doesn't solve y2038 problem, but timespec64 isn't yet a thing in userspace.
* peer: store total number of peers instead of iteratingJason A. Donenfeld2017-10-311-2/+0
| | | | | | This is faster, since it means adding a new peer is O(1) instead of O(n). It's also safe to do because we're holding the device_update_lock on both the ++ and the --.
* peer: get rid of peer_for_each magicJason A. Donenfeld2017-10-311-30/+0
| | | | | | | | | Since the peer list is protected by the device_update_lock, and since items are removed from the peer list before putting their final reference, we don't actually need to take a reference when iterating. This allows us to simplify the macro considerably. Suggested-by: Johannes Berg <johannes@sipsolutions.net>
* global: accept decent check_patch.pl suggestionsJason A. Donenfeld2017-10-311-1/+3
|
* global: use _WG prefix for include guardsJason A. Donenfeld2017-10-031-3/+3
| | | | Suggested-by: Sultan Alsawaf <sultanxda@gmail.com>
* peer: rearrange structsJason A. Donenfeld2017-09-191-4/+4
|
* queue: entirely rework parallel systemJason A. Donenfeld2017-09-181-9/+6
| | | | | | | | | | This removes our dependency on padata and moves to a different mode of multiprocessing that is more efficient. This began as Samuel Holland's GSoC project and was gradually reworked/redesigned/rebased into this present commit, which is a combination of his initial contribution and my subsequent rewriting and redesigning.
* socket: improve reply-to-src algorithmJason A. Donenfeld2017-08-231-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We store the destination IP of incoming packets as the source IP of outgoing packets. When we send outgoing packets, we then ask the routing table for which interface to use and which source address, given our inputs of the destination address and a suggested source address. This all is good and fine, since it means we'll successfully reply using the correct source address, correlating with the destination address for incoming packets. However, what happens when default routes change? Or when interface IP addresses change? Prior to this commit, after getting the response from the routing table of the source address, destination address, and interface, we would then make sure that the source address actually belonged to the outbound interface. If it didn't, we'd reset our source address to zero and re-ask the routing table, in which case the routing table would then give us the default IP address for sending that packet. This worked mostly fine for most purposes, but there was a problem: what if WireGuard legitimately accepted an inbound packet on a default interface using an IP of another interface? In this case, falling back to asking for the default source IP was not a good strategy, since it'd nearly always mean we'd fail to reply using the right source. So, this commit changes the algorithm slightly. Rather than falling back to using the default IP if the preferred source IP doesn't belong to the outbound interface, we have two checks: we make sure that the source IP address belongs to _some_ interface on the system, no matter which one (so long as it's within the network namespace), and we check whether or not the interface of an incoming packet matches the returned interface for the outbound traffic. If both these conditions are true, then we proceed with using this source IP address. If not, we fall back to the default IP address.
* timers: rename confusingly named functions and variablesJason A. Donenfeld2017-08-041-1/+1
| | | | Suggested-by: Mathias Hall-Andersen <mathias@hall-andersen.dk>
* peer: use iterator macro instead of callbackJason A. Donenfeld2017-05-301-3/+28
|
* noise: redesign preshared key modeJason A. Donenfeld2017-05-171-1/+1
|
* compat: backport siphash & dst_cache from mainlineJason A. Donenfeld2017-02-131-2/+0
|
* timers: use simpler uninit sync techniqueJason A. Donenfeld2017-02-071-0/+1
|
* Update copyrightJason A. Donenfeld2017-01-101-1/+1
|
* peer: don't use sockaddr_storage to reduce memory usageJason A. Donenfeld2016-12-131-1/+1
|
* global: move to consistent use of uN instead of uintN_t for kernel codeJason A. Donenfeld2016-12-111-3/+3
|
* headers: cleanup noticesJason A. Donenfeld2016-11-211-1/+1
|
* socket: keep track of src address in sending packetsJason A. Donenfeld2016-11-151-1/+13
|
* data: we care about per-peer, not per-device, inflight encryptionsJason A. Donenfeld2016-11-061-0/+3
|
* c89: the static keyword is okay in c99, but not in c89Jason A. Donenfeld2016-11-051-1/+1
|
* compat: stub out dst_cache for old kernelsJason A. Donenfeld2016-11-041-0/+2
|
* socket: use dst_cache instead of handrolled cacheJason A. Donenfeld2016-11-041-5/+2
|
* timers: take reference like a lookup tableJason A. Donenfeld2016-11-031-0/+2
|
* timers: only have initiator rekeyJason A. Donenfeld2016-10-191-1/+2
| | | | | | | | | If it's time to rekey, and the responder sends a message, the initator will begin the rekeying when sending his response message. In the worst case, this response message will actually just be the keepalive. This generally works well, with the one edge case of the message arriving less than 10 seconds before key expiration, in which the keepalive is not sufficient. In this case, we simply rehandshake immediately.
* timers: always delay handshakes for responderJason A. Donenfeld2016-10-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With the prior behavior, when sending a packet, we checked to see if it was about time to start a new handshake, and if we were past a certain time, we started it. For the responder, we made that time a bit further in the future than for the initiator, to prevent the thundering herd problem of them both starting at the same time. However, this was flawed. If both parties stopped communicating after 2.2 minutes, and then one party decided to initiate a TCP connection before the 3 minute mark, the currently open session would be used. However, because it was after the 2.2 minute mark, both peers would try to initiate a handshake upon sending their first packet. The errant flow was as follows: 1. Peer A sends SYN. 2. Peer A sees that his key is getting old and initiates new handshake. 3. Peer B receives SYN and sends ACK. 4. Peer B sees that his key is getting old and initiates new handshake. Since these events happened after the 2.2 minute mark, there's no delay between handshake initiations, and problems begin. The new behavior is changed to: 1. Peer A sends SYN. 2. Peer A sees that his key is getting old and initiates new handshake. 3. Peer B receives SYN and sends ACK. 4. Peer B sees that his key is getting old and schedules a delayed handshake for 12.5 seconds in the future. 5. Peer B receives handshake initiation and cancels scheduled handshake.
* send: requeue jobs for later if padata is fullJason A. Donenfeld2016-10-051-0/+1
|
* Rework headers and includesJason A. Donenfeld2016-09-291-1/+3
|
* c: specify static array size in function paramsJason A. Donenfeld2016-08-021-1/+1
| | | | | | | | | | | | | | | The C standard states: A declaration of a parameter as ``array of type'' shall be adjusted to ``qualified pointer to type'', where the type qualifiers (if any) are those specified within the [ and ] of the array type derivation. If the keyword static also appears within the [ and ] of the array type derivation, then for each call to the function, the value of the corresponding actual argument shall provide access to the first element of an array with at least as many elements as specified by the size expression. By changing void func(int array[4]) to void func(int array[static 4]), we automatically get the compiler checking argument sizes for us, which is quite nice.
* persistent keepalive: use unsigned long to avoid multiplication in hotpathJason A. Donenfeld2016-07-101-1/+1
|
* persistent keepalive: add kernel mechanismJason A. Donenfeld2016-07-081-1/+2
|
* Initial commitJason A. Donenfeld2016-06-251-0/+55