Skip to content

Commit a12d7f3

Browse files
zx2c4davem330
authored andcommitted
wireguard: device: use icmp_ndo_send helper
Because wireguard is calling icmp from network device context, it should use the ndo helper so that the rate limiting applies correctly. This commit adds a small test to the wireguard test suite to ensure that the new functions continue doing the right thing in the context of wireguard. It does this by setting up a condition that will definately evoke an icmp error message from the driver, but along a nat'd path. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 67c9a7e commit a12d7f3

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

‎drivers/net/wireguard/device.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ static netdev_tx_t wg_xmit(struct sk_buff *skb, struct net_device *dev)
203203
err:
204204
++dev->stats.tx_errors;
205205
if (skb->protocol == htons(ETH_P_IP))
206-
icmp_send(skb, ICMP_DEST_UNREACH, ICMP_HOST_UNREACH, 0);
206+
icmp_ndo_send(skb, ICMP_DEST_UNREACH, ICMP_HOST_UNREACH, 0);
207207
else if (skb->protocol == htons(ETH_P_IPV6))
208-
icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_ADDR_UNREACH, 0);
208+
icmpv6_ndo_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_ADDR_UNREACH, 0);
209209
kfree_skb(skb);
210210
return ret;
211211
}

‎tools/testing/selftests/wireguard/netns.sh‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
set -e
2525

2626
exec 3>&1
27+
export LANG=C
2728
export WG_HIDE_KEYS=never
2829
netns0="wg-test-$$-0"
2930
netns1="wg-test-$$-1"
@@ -297,7 +298,17 @@ ip1 -4 rule add table main suppress_prefixlength 0
297298
n1 ping -W 1 -c 100 -f 192.168.99.7
298299
n1 ping -W 1 -c 100 -f abab::1111
299300

301+
# Have ns2 NAT into wg0 packets from ns0, but return an icmp error along the right route.
302+
n2 iptables -t nat -A POSTROUTING -s 10.0.0.0/24 -d 192.168.241.0/24 -j SNAT --to 192.168.241.2
303+
n0 iptables -t filter -A INPUT \! -s 10.0.0.0/24 -i vethrs -j DROP # Manual rpfilter just to be explicit.
304+
n2 bash -c 'printf 1 > /proc/sys/net/ipv4/ip_forward'
305+
ip0 -4 route add 192.168.241.1 via 10.0.0.100
306+
n2 wg set wg0 peer "$pub1" remove
307+
[[ $(! n0 ping -W 1 -c 1 192.168.241.1 || false) == *"From 10.0.0.100 icmp_seq=1 Destination Host Unreachable"* ]]
308+
300309
n0 iptables -t nat -F
310+
n0 iptables -t filter -F
311+
n2 iptables -t nat -F
301312
ip0 link del vethrc
302313
ip0 link del vethrs
303314
ip1 link del wg0

0 commit comments

Comments
 (0)