From 2f12227690cf9a979a9a148109c96ab4f6ee6c0e Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sun, 25 Jun 2017 16:24:23 +0200 Subject: global: cleanup IP header checking This way is more correct and ensures we're within the skb head. --- src/socket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/socket.c') 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; -- cgit v1.2.3-59-g8ed1b