0001
0002
0003
0004
0005
0006 #ifndef __IF_TUN_H
0007 #define __IF_TUN_H
0008
0009 #include <uapi/linux/if_tun.h>
0010 #include <uapi/linux/virtio_net.h>
0011
0012 #define TUN_XDP_FLAG 0x1UL
0013
0014 #define TUN_MSG_UBUF 1
0015 #define TUN_MSG_PTR 2
0016 struct tun_msg_ctl {
0017 unsigned short type;
0018 unsigned short num;
0019 void *ptr;
0020 };
0021
0022 struct tun_xdp_hdr {
0023 int buflen;
0024 struct virtio_net_hdr gso;
0025 };
0026
0027 #if defined(CONFIG_TUN) || defined(CONFIG_TUN_MODULE)
0028 struct socket *tun_get_socket(struct file *);
0029 struct ptr_ring *tun_get_tx_ring(struct file *file);
0030 static inline bool tun_is_xdp_frame(void *ptr)
0031 {
0032 return (unsigned long)ptr & TUN_XDP_FLAG;
0033 }
0034 static inline void *tun_xdp_to_ptr(struct xdp_frame *xdp)
0035 {
0036 return (void *)((unsigned long)xdp | TUN_XDP_FLAG);
0037 }
0038 static inline struct xdp_frame *tun_ptr_to_xdp(void *ptr)
0039 {
0040 return (void *)((unsigned long)ptr & ~TUN_XDP_FLAG);
0041 }
0042 void tun_ptr_free(void *ptr);
0043 #else
0044 #include <linux/err.h>
0045 #include <linux/errno.h>
0046 struct file;
0047 struct socket;
0048 static inline struct socket *tun_get_socket(struct file *f)
0049 {
0050 return ERR_PTR(-EINVAL);
0051 }
0052 static inline struct ptr_ring *tun_get_tx_ring(struct file *f)
0053 {
0054 return ERR_PTR(-EINVAL);
0055 }
0056 static inline bool tun_is_xdp_frame(void *ptr)
0057 {
0058 return false;
0059 }
0060 static inline void *tun_xdp_to_ptr(struct xdp_frame *xdp)
0061 {
0062 return NULL;
0063 }
0064 static inline struct xdp_frame *tun_ptr_to_xdp(void *ptr)
0065 {
0066 return NULL;
0067 }
0068 static inline void tun_ptr_free(void *ptr)
0069 {
0070 }
0071 #endif
0072 #endif