aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-06-30 17:12:06 -0600
committerJason A. Donenfeld <Jason@zx2c4.com>2020-06-30 17:17:05 -0600
commitf4367ebaef9244fc777875be2c765cc03a1b5b72 (patch)
tree7a016e8585275d761e849b812fb6be5e53eb2aab
parentdevice: implement header_ops->parse_protocol for AF_PACKET (diff)
downloadwireguard-linux-compat-f4367ebaef9244fc777875be2c765cc03a1b5b72.tar.xz
wireguard-linux-compat-f4367ebaef9244fc777875be2c765cc03a1b5b72.zip
queueing: make use of ip_tunnel_parse_protocol
Now that wg_examine_packet_protocol has been added for general consumption as ip_tunnel_parse_protocol, it's possible to remove wg_examine_packet_protocol and simply use the new ip_tunnel_parse_protocol function directly. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--src/queueing.h19
-rw-r--r--src/receive.c2
2 files changed, 3 insertions, 18 deletions
diff --git a/src/queueing.h b/src/queueing.h
index e88eb93..bab170b 100644
--- a/src/queueing.h
+++ b/src/queueing.h
@@ -11,6 +11,7 @@
#include <linux/skbuff.h>
#include <linux/ip.h>
#include <linux/ipv6.h>
+#include <net/ip_tunnels.h>
struct wg_device;
struct wg_peer;
@@ -65,25 +66,9 @@ struct packet_cb {
#define PACKET_CB(skb) ((struct packet_cb *)((skb)->cb))
#define PACKET_PEER(skb) (PACKET_CB(skb)->keypair->entry.peer)
-/* Returns either the correct skb->protocol value, or 0 if invalid. */
-static inline __be16 wg_examine_packet_protocol(struct sk_buff *skb)
-{
- if (skb_network_header(skb) >= skb->head &&
- (skb_network_header(skb) + sizeof(struct iphdr)) <=
- skb_tail_pointer(skb) &&
- ip_hdr(skb)->version == 4)
- return htons(ETH_P_IP);
- if (skb_network_header(skb) >= skb->head &&
- (skb_network_header(skb) + sizeof(struct ipv6hdr)) <=
- skb_tail_pointer(skb) &&
- ipv6_hdr(skb)->version == 6)
- return htons(ETH_P_IPV6);
- return 0;
-}
-
static inline bool wg_check_packet_protocol(struct sk_buff *skb)
{
- __be16 real_protocol = wg_examine_packet_protocol(skb);
+ __be16 real_protocol = ip_tunnel_parse_protocol(skb);
return real_protocol && skb->protocol == real_protocol;
}
diff --git a/src/receive.c b/src/receive.c
index 4f7141a..172ef82 100644
--- a/src/receive.c
+++ b/src/receive.c
@@ -392,7 +392,7 @@ static void wg_packet_consume_data_done(struct wg_peer *peer,
#ifndef COMPAT_CANNOT_USE_CSUM_LEVEL
skb->csum_level = ~0; /* All levels */
#endif
- skb->protocol = wg_examine_packet_protocol(skb);
+ skb->protocol = ip_tunnel_parse_protocol(skb);
if (skb->protocol == htons(ETH_P_IP)) {
len = ntohs(ip_hdr(skb)->tot_len);
if (unlikely(len < sizeof(struct iphdr)))