aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/routingtable.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
commit2f12227690cf9a979a9a148109c96ab4f6ee6c0e (patch)
tree40c09b45766dd5f67f50d5986a6e75b90a7d3ede /src/routingtable.c
parentdevice: remove icmp conntrack hacks (diff)
downloadwireguard-monolithic-historical-2f12227690cf9a979a9a148109c96ab4f6ee6c0e.tar.xz
wireguard-monolithic-historical-2f12227690cf9a979a9a148109c96ab4f6ee6c0e.zip
global: cleanup IP header checking
This way is more correct and ensures we're within the skb head.
Diffstat (limited to 'src/routingtable.c')
-rw-r--r--src/routingtable.c23
1 files changed, 4 insertions, 19 deletions
diff --git a/src/routingtable.c b/src/routingtable.c
index ce94a99..a6abb61 100644
--- a/src/routingtable.c
+++ b/src/routingtable.c
@@ -322,25 +322,12 @@ int routing_table_walk_ips_by_peer_sleepable(struct routing_table *table, void *
return ret;
}
-static inline bool has_valid_ip_header(struct sk_buff *skb)
-{
- if (unlikely(skb->len < sizeof(struct iphdr)))
- return false;
- else if (unlikely(skb->len < sizeof(struct ipv6hdr) && ip_hdr(skb)->version == 6))
- return false;
- else if (unlikely(ip_hdr(skb)->version != 4 && ip_hdr(skb)->version != 6))
- return false;
- return true;
-}
-
/* Returns a strong reference to a peer */
struct wireguard_peer *routing_table_lookup_dst(struct routing_table *table, struct sk_buff *skb)
{
- if (unlikely(!has_valid_ip_header(skb)))
- return NULL;
- if (ip_hdr(skb)->version == 4)
+ if (skb->protocol == htons(ETH_P_IP))
return lookup(table->root4, 32, &ip_hdr(skb)->daddr);
- else if (ip_hdr(skb)->version == 6)
+ else if (skb->protocol == htons(ETH_P_IPV6))
return lookup(table->root6, 128, &ipv6_hdr(skb)->daddr);
return NULL;
}
@@ -348,11 +335,9 @@ struct wireguard_peer *routing_table_lookup_dst(struct routing_table *table, str
/* Returns a strong reference to a peer */
struct wireguard_peer *routing_table_lookup_src(struct routing_table *table, struct sk_buff *skb)
{
- if (unlikely(!has_valid_ip_header(skb)))
- return NULL;
- if (ip_hdr(skb)->version == 4)
+ if (skb->protocol == htons(ETH_P_IP))
return lookup(table->root4, 32, &ip_hdr(skb)->saddr);
- else if (ip_hdr(skb)->version == 6)
+ else if (skb->protocol == htons(ETH_P_IPV6))
return lookup(table->root6, 128, &ipv6_hdr(skb)->saddr);
return NULL;
}