Debian Codegraph @

drivers/net/ovpn-dco/skb.h

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* OpenVPN data channel accelerator
3 *
4 * Copyright (C) 2020- OpenVPN, Inc.
5 *
6 * Author: Antonio Quartulli <[email protected]>
7 * James Yonan <[email protected]>
8 */
9
10 #ifndef _NET_OVPN_DCO_SKB_H_
11 #define _NET_OVPN_DCO_SKB_H_
12
13 #include <linux/in.h>
14 #include <linux/in6.h>
15 #include <linux/ip.h>
16 #include <linux/skbuff.h>
17 #include <linux/socket.h>
18 #include <linux/types.h>
19
20 #define OVPN_SKB_CB(skb) ((struct ovpn_skb_cb *)&((skb)->cb))
21
22 struct ovpn_skb_cb {
23 union {
24 struct in_addr ipv4;
25 struct in6_addr ipv6;
26 } local;
27 sa_family_t sa_fam;
28 };
29
30 /* Return IP protocol version from skb header.
31 * Return 0 if protocol is not IPv4/IPv6 or cannot be read.
32 */
33 static inline __be16 ovpn_ip_check_protocol(struct sk_buff *skb)
34 {
35 __be16 proto = 0;
36
37 /* skb could be non-linear,
38 * make sure IP header is in non-fragmented part
39 */
40 if (!pskb_network_may_pull(skb, sizeof(struct iphdr)))
41 return 0;
42
43 if (ip_hdr(skb)->version == 4)
44 proto = htons(ETH_P_IP);
45 else if (ip_hdr(skb)->version == 6)
46 proto = htons(ETH_P_IPV6);
47
48 return proto;
49 }
50
51 #endif /* _NET_OVPN_DCO_SKB_H_ */