summaryrefslogtreecommitdiffstatshomepage
path: root/src/socket.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/socket.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/socket.c')
-rw-r--r--src/socket.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/socket.c b/src/socket.c
index 332a682..40f8b8d 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -207,12 +207,12 @@ int socket_send_buffer_as_reply_to_skb(struct wireguard_device *wg, struct sk_bu
int socket_endpoint_from_skb(struct endpoint *endpoint, struct sk_buff *skb)
{
memset(endpoint, 0, sizeof(struct endpoint));
- if (ip_hdr(skb)->version == 4) {
+ if (skb->protocol == htons(ETH_P_IP)) {
endpoint->addr4.sin_family = AF_INET;
endpoint->addr4.sin_port = udp_hdr(skb)->source;
endpoint->addr4.sin_addr.s_addr = ip_hdr(skb)->saddr;
endpoint->src4.s_addr = ip_hdr(skb)->daddr;
- } else if (ip_hdr(skb)->version == 6) {
+ } else if (skb->protocol == htons(ETH_P_IPV6)) {
endpoint->addr6.sin6_family = AF_INET6;
endpoint->addr6.sin6_port = udp_hdr(skb)->source;
endpoint->addr6.sin6_addr = ipv6_hdr(skb)->saddr;