if_tun.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Universal TUN/TAP device driver.
  4. * Copyright (C) 1999-2000 Maxim Krasnyansky <max_mk@yahoo.com>
  5. */
  6. #ifndef __IF_TUN_H
  7. #define __IF_TUN_H
  8. #include <uapi/linux/if_tun.h>
  9. #include <uapi/linux/virtio_net.h>
  10. #define TUN_XDP_FLAG 0x1UL
  11. #define TUN_MSG_UBUF 1
  12. #define TUN_MSG_PTR 2
  13. struct tun_msg_ctl {
  14. unsigned short type;
  15. unsigned short num;
  16. void *ptr;
  17. };
  18. struct tun_xdp_hdr {
  19. int buflen;
  20. struct virtio_net_hdr gso;
  21. };
  22. #if defined(CONFIG_TUN) || defined(CONFIG_TUN_MODULE)
  23. struct socket *tun_get_socket(struct file *);
  24. struct ptr_ring *tun_get_tx_ring(struct file *file);
  25. static inline bool tun_is_xdp_frame(void *ptr)
  26. {
  27. return (unsigned long)ptr & TUN_XDP_FLAG;
  28. }
  29. static inline void *tun_xdp_to_ptr(struct xdp_frame *xdp)
  30. {
  31. return (void *)((unsigned long)xdp | TUN_XDP_FLAG);
  32. }
  33. static inline struct xdp_frame *tun_ptr_to_xdp(void *ptr)
  34. {
  35. return (void *)((unsigned long)ptr & ~TUN_XDP_FLAG);
  36. }
  37. void tun_ptr_free(void *ptr);
  38. #else
  39. #include <linux/err.h>
  40. #include <linux/errno.h>
  41. struct file;
  42. struct socket;
  43. static inline struct socket *tun_get_socket(struct file *f)
  44. {
  45. return ERR_PTR(-EINVAL);
  46. }
  47. static inline struct ptr_ring *tun_get_tx_ring(struct file *f)
  48. {
  49. return ERR_PTR(-EINVAL);
  50. }
  51. static inline bool tun_is_xdp_frame(void *ptr)
  52. {
  53. return false;
  54. }
  55. static inline void *tun_xdp_to_ptr(struct xdp_frame *xdp)
  56. {
  57. return NULL;
  58. }
  59. static inline struct xdp_frame *tun_ptr_to_xdp(void *ptr)
  60. {
  61. return NULL;
  62. }
  63. static inline void tun_ptr_free(void *ptr)
  64. {
  65. }
  66. #endif /* CONFIG_TUN */
  67. #endif /* __IF_TUN_H */