aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/cookie.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-06-25 16:24:23 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2017-06-26 12:35:06 +0200
commit3b2b6e7c1eb6a8d24c057e7f032e5cd4fea191fe (patch)
treea9fca6dd1a0443e9e4096d9c44867630c36624b9 /src/cookie.c
parentdevice: remove icmp conntrack hacks (diff)
downloadwireguard-linux-compat-3b2b6e7c1eb6a8d24c057e7f032e5cd4fea191fe.tar.xz
wireguard-linux-compat-3b2b6e7c1eb6a8d24c057e7f032e5cd4fea191fe.zip
global: cleanup IP header checking
This way is more correct and ensures we're within the skb head. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/cookie.c')
-rw-r--r--src/cookie.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/cookie.c b/src/cookie.c
index 0e9c211..33beea8 100644
--- a/src/cookie.c
+++ b/src/cookie.c
@@ -85,9 +85,9 @@ static void make_cookie(u8 cookie[COOKIE_LEN], struct sk_buff *skb, struct cooki
down_read(&checker->secret_lock);
blake2s_init_key(&state, COOKIE_LEN, checker->secret, NOISE_HASH_LEN);
- if (ip_hdr(skb)->version == 4)
+ if (skb->protocol == htons(ETH_P_IP))
blake2s_update(&state, (u8 *)&ip_hdr(skb)->saddr, sizeof(struct in_addr));
- else if (ip_hdr(skb)->version == 6)
+ else if (skb->protocol == htons(ETH_P_IPV6))
blake2s_update(&state, (u8 *)&ipv6_hdr(skb)->saddr, sizeof(struct in6_addr));
blake2s_update(&state, (u8 *)&udp_hdr(skb)->source, sizeof(__be16));
blake2s_final(&state, cookie, COOKIE_LEN);