diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-06-30 17:15:34 -0600 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-06-30 19:44:12 -0600 |
commit | d9e60cad625e96a916b7950e9706f7fa3c563c60 (patch) | |
tree | 8abc09e13efa87e95184a87285d5f897b5a6fb72 | |
parent | f4367ebaef9244fc777875be2c765cc03a1b5b72 (diff) |
compat: backport ip_tunnel_parse_protocol and ip_tunnel_header_ops
These are required for moving wg_examine_packet_protocol out of
wireguard and into upstream.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r-- | src/compat/compat.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/compat/compat.h b/src/compat/compat.h index 06d2666..ea6d624 100644 --- a/src/compat/compat.h +++ b/src/compat/compat.h @@ -1043,6 +1043,28 @@ static inline void skb_reset_redirect(struct sk_buff *skb) #define pre_exit exit #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 8, 0) +#include <linux/skbuff.h> +static inline __be16 ip_tunnel_parse_protocol(const 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; +} +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 1, 0) || defined(ISRHEL8) +static const struct header_ops ip_tunnel_header_ops = { .parse_protocol = ip_tunnel_parse_protocol }; +#else +#define header_ops hard_header_len +#define ip_tunnel_header_ops *(char *)0 - (char *)0 +#endif +#endif + #if defined(ISUBUNTU1604) || defined(ISRHEL7) #include <linux/siphash.h> #ifndef _WG_LINUX_SIPHASH_H |