| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#ifndef _NET_OVPN_DCO_OVPNBIND_H_ |
| 9 |
#define _NET_OVPN_DCO_OVPNBIND_H_ |
| 10 |
|
| 11 |
#include "addr.h" |
| 12 |
#include "rcu.h" |
| 13 |
|
| 14 |
#include <net/ip.h> |
| 15 |
#include <linux/skbuff.h> |
| 16 |
#include <linux/spinlock.h> |
| 17 |
|
| 18 |
struct ovpn_peer; |
| 19 |
|
| 20 |
struct ovpn_bind { |
| 21 |
struct ovpn_sockaddr sa; |
| 22 |
|
| 23 |
union { |
| 24 |
struct in_addr ipv4; |
| 25 |
struct in6_addr ipv6; |
| 26 |
} local; |
| 27 |
|
| 28 |
struct rcu_head rcu; |
| 29 |
}; |
| 30 |
|
| 31 |
static inline bool ovpn_bind_skb_src_match(const struct ovpn_bind *bind, struct sk_buff *skb) |
| 32 |
{ |
| 33 |
const unsigned short family = skb_protocol_to_family(skb); |
| 34 |
const struct ovpn_sockaddr *sa = &bind->sa; |
| 35 |
|
| 36 |
if (unlikely(!bind)) |
| 37 |
return false; |
| 38 |
|
| 39 |
if (unlikely(sa->in4.sin_family != family)) |
| 40 |
return false; |
| 41 |
|
| 42 |
switch (family) { |
| 43 |
case AF_INET: |
| 44 |
if (unlikely(sa->in4.sin_addr.s_addr != ip_hdr(skb)->saddr)) |
| 45 |
return false; |
| 46 |
|
| 47 |
if (unlikely(sa->in4.sin_port != udp_hdr(skb)->source)) |
| 48 |
return false; |
| 49 |
break; |
| 50 |
case AF_INET6: |
| 51 |
if (unlikely(!ipv6_addr_equal(&sa->in6.sin6_addr, &ipv6_hdr(skb)->saddr))) |
| 52 |
return false; |
| 53 |
|
| 54 |
if (unlikely(sa->in6.sin6_port != udp_hdr(skb)->source)) |
| 55 |
return false; |
| 56 |
break; |
| 57 |
default: |
| 58 |
return false; |
| 59 |
} |
| 60 |
|
| 61 |
return true; |
| 62 |
} |
| 63 |
|
| 64 |
struct ovpn_bind *ovpn_bind_from_sockaddr(const struct sockaddr_storage *sa); |
| 65 |
void ovpn_bind_reset(struct ovpn_peer *peer, struct ovpn_bind *bind); |
| 66 |
|
| 67 |
#endif |