aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/send.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* send: calculate inner checksums for all protocolsAndrejs Hanins2018-10-271-5/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I'm using GRE tunnel (transparent Ethernet bridging flavor) over WireGuard interface to be able to bridge L2 network segments. The typical protocol chain looks like this IP->GRE->EthernetHeader->IP->UDP. UDP here is the packet sent from the L2 network segment which is tunneled using GRE over Wireguard. Indeed, there is a checksum inside UDP header which is, as a rule, kept partially calculated while packet travels through network stack and outer protocols are added until the packet reaches WG device which exposes NETIF_F_HW_CSUM feature meaning it can handle checksum offload for all protocols. But the problem here is that skb_checksum_setup called from encrypt_packet handles only TCP/UDP protocols under top level IP, but in my case there is a GRE protocol there, so skb_checksum_help is not called and packet continues its life with unfinished (broken) checksum and gets encrypted as-is. When such packet is received by other side and reaches L2 networks it's seen there with a broken checksum inside the UDP header. The fact that Wireguard on the receiving side sets skb->ip_summed to CHECKSUM_UNNECESSARY partially mitigates the problem by telling network stack on the receiving side that validation of the checksum is not necessary, so local TCP stack, for example, works fine. But it doesn't help in situations when packet needs to be forwarded further (sent out from the box). In this case there is no way we can tell next hop that checksum verification for this packet is not necessary, we just send it out with bad checksum and packet gets dropped on the next hop box. I think the issue of the original code was the wrong usage of skb_checksum_setup, simply because it's not needed in this case. Instead, we can just rely on ip_summed skb field to see if partial checksum needs to be finalized or not. Note that many other drivers in kernel follow this approach. In summary: - skb_checksum_setup can only handle TCP/UDP protocols under top level IP header, packets with other protocols (like GRE) are sent out by Wireguard with unfinished partial checksums which causes problems on receiving side (bad checksums). - encrypt_packet gets skb prepared by network stack, so there is no need to setup the checksum from scratch, but just perform hw checksum offload using software helper skb_checksum_help for packet which explicitly require it as denoted by CHECKSUM_PARTIAL. Signed-off-by: Andrejs Hanins <ahanins@gmail.com>
* send: consider dropped stage packets to be droppedJason A. Donenfeld2018-10-271-0/+8
| | | | Suggested-by: Andrew Lunn <andrew@lunn.ch>
* global: do not allow compiler to reorder is_valid or is_deadJason A. Donenfeld2018-10-251-5/+6
| | | | Suggested-by: Jann Horn <jann@thejh.net>
* global: give if statements brackets and other cleanupsJason A. Donenfeld2018-10-091-2/+2
|
* global: more nitsJason A. Donenfeld2018-10-081-10/+11
|
* global: rename struct wireguard_ to struct wg_Jason A. Donenfeld2018-10-081-18/+18
| | | | | | This required a bit of pruning of our christmas trees. Suggested-by: Jiri Pirko <jiri@resnulli.us>
* global: prefix functions used in callbacks with wg_Jason A. Donenfeld2018-10-081-10/+10
| | | | Suggested-by: Jiri Pirko <jiri@resnulli.us>
* global: style nitsJason A. Donenfeld2018-10-071-2/+3
|
* global: prefix all functions with wg_Jason A. Donenfeld2018-10-021-66/+67
| | | | | | | | | | | | | 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.
* crypto: pass simd by referenceJason A. Donenfeld2018-09-171-5/+6
|
* global: remove non-essential inline annotationsJason A. Donenfeld2018-09-161-6/+5
|
* send/receive: reduce number of sg entriesJason A. Donenfeld2018-09-161-1/+1
| | | | This reduces stack usage to quell warnings on powerpc.
* global: prefer sizeof(*pointer) when possibleJason A. Donenfeld2018-09-041-10/+6
| | | | Suggested-by: Sultan Alsawaf <sultanxda@gmail.com>
* crypto: import zincJason A. Donenfeld2018-09-031-1/+1
|
* global: run through clang-formatJason A. Donenfeld2018-08-281-67/+136
| | | | | | | 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.
* crypto: move simd context to specific typeJason A. Donenfeld2018-08-061-6/+6
| | | | Suggested-by: Andy Lutomirski <luto@kernel.org>
* send: switch handshake stamp to an atomicJason A. Donenfeld2018-08-041-11/+9
| | | | | | | | | | | 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-14/+20
| | | | | Completely rework peer removal to ensure peers don't jump between contexts and create races.
* queueing: ensure strictly ordered loads and storesJason A. Donenfeld2018-08-021-1/+1
| | | | | | | We don't want a consumer to read plaintext when it's supposed to be reading ciphertext, which means we need to synchronize across cores. Suggested-by: Jann Horn <jann@thejh.net>
* send: address of variable is never nullJason A. Donenfeld2018-07-311-1/+1
| | | | Reported-by: Jann Horn <jann@thejh.net>
* peer: simplify rcu reference countsJason A. Donenfeld2018-07-311-2/+2
| | | | | | | Use RCU reference counts only when we must, and otherwise use a more reasonably named function. Reported-by: Jann Horn <jann@thejh.net>
* global: use fast boottime instead of normal boottimeJason A. Donenfeld2018-06-231-2/+2
| | | | Generally if we're inaccurate by a few nanoseconds, it doesn't matter.
* global: use ktime boottime instead of jiffiesJason A. Donenfeld2018-06-231-7/+6
| | | | | | | | 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: fix a few typosJonathan Neuschäfer2018-06-221-1/+1
| | | | Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
* simd: encapsulate fpu amortization into nice functionsJason A. Donenfeld2018-06-171-7/+4
|
* queueing: re-enable preemption periodically to lower latencyJason A. Donenfeld2018-06-161-0/+6
|
* queueing: remove useless spinlocks on scJason A. Donenfeld2018-06-161-2/+0
| | | | Since these are the only consumers, there's no need for locking.
* timers: clear send_keepalive timer on sending handshake responseJason A. Donenfeld2018-05-191-0/+3
| | | | | | We reorganize this into also doing so on sending keepalives itself, which means the state machine is much more consistent, even if this was already implied.
* send: simplify skb_padding with nice macroJason A. Donenfeld2018-04-161-4/+3
|
* send: account for route-based MTUJason A. Donenfeld2018-04-151-3/+4
| | | | | | | | | | It might be that a particular route has a different MTU than the interface, via `ip route add ... dev wg0 mtu 1281`, for example. In this case, it's important that we don't accidently pad beyond the end of the MTU. We accomplish that in this patch by carrying forward the MTU from the dst if it exists. We also add a unit test for this issue. Reported-by: Roman Mamedov <rm.wg@romanrm.net>
* 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: style nitsJason A. Donenfeld2017-10-311-6/+12
|
* global: infuriating kernel iterator styleJason A. Donenfeld2017-10-311-5/+5
| | | | | | | | | | | | | | | | | One types: for (i = 0 ... So one should also type: for_each_obj (obj ... But the upstream kernel style guidelines are insane, and so we must instead do: for_each_obj(obj ... Ugly, but one must choose his battles wisely.
* global: accept decent check_patch.pl suggestionsJason A. Donenfeld2017-10-311-3/+4
|
* stats: more robust accountingJason A. Donenfeld2017-10-311-0/+1
|
* send: improve dead packet control flowJason A. Donenfeld2017-10-171-6/+3
|
* send: do not requeue if packet is deadJason A. Donenfeld2017-10-111-1/+6
|
* queueing: cleanup skb_paddingJason A. Donenfeld2017-10-051-0/+14
|
* queueing: move from ctx to cbJason A. Donenfeld2017-10-051-54/+49
|
* queueing: use ptr_ring instead of linked listsJason A. Donenfeld2017-10-051-6/+15
|
* send: put keypair referenceJason A. Donenfeld2017-10-051-0/+1
|
* global: add space around variable declarationsJason A. Donenfeld2017-10-031-0/+1
|
* queueing: rename cpumask functionJason A. Donenfeld2017-09-191-1/+1
|
* send: don't take uninitialized lockJason A. Donenfeld2017-09-191-3/+3
| | | | | | Packets is a local, which means we need to use the functions that don't take a spinlock, since otherwise we'll be using a spinlock in an undefined state.
* queueing: no need to memzero structJason A. Donenfeld2017-09-191-1/+2
|
* queue: entirely rework parallel systemJason A. Donenfeld2017-09-181-60/+174
| | | | | | | | | | 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.
* send: no need to check for NULL since ref is validJason A. Donenfeld2017-09-161-3/+0
|
* noise: infer initiator or not from handshake stateJason A. Donenfeld2017-08-041-1/+1
| | | | Suggested-by: Mathias Hall-Andersen <mathias@hall-andersen.dk>