if_tap.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_IF_TAP_H_
  3. #define _LINUX_IF_TAP_H_
  4. #if IS_ENABLED(CONFIG_TAP)
  5. struct socket *tap_get_socket(struct file *);
  6. struct ptr_ring *tap_get_ptr_ring(struct file *file);
  7. #else
  8. #include <linux/err.h>
  9. #include <linux/errno.h>
  10. struct file;
  11. struct socket;
  12. static inline struct socket *tap_get_socket(struct file *f)
  13. {
  14. return ERR_PTR(-EINVAL);
  15. }
  16. static inline struct ptr_ring *tap_get_ptr_ring(struct file *f)
  17. {
  18. return ERR_PTR(-EINVAL);
  19. }
  20. #endif /* CONFIG_TAP */
  21. #include <net/sock.h>
  22. #include <linux/skb_array.h>
  23. /*
  24. * Maximum times a tap device can be opened. This can be used to
  25. * configure the number of receive queue, e.g. for multiqueue virtio.
  26. */
  27. #define MAX_TAP_QUEUES 256
  28. struct tap_queue;
  29. struct tap_dev {
  30. struct net_device *dev;
  31. u16 flags;
  32. /* This array tracks active taps. */
  33. struct tap_queue __rcu *taps[MAX_TAP_QUEUES];
  34. /* This list tracks all taps (both enabled and disabled) */
  35. struct list_head queue_list;
  36. int numvtaps;
  37. int numqueues;
  38. netdev_features_t tap_features;
  39. int minor;
  40. void (*update_features)(struct tap_dev *tap, netdev_features_t features);
  41. void (*count_tx_dropped)(struct tap_dev *tap);
  42. void (*count_rx_dropped)(struct tap_dev *tap);
  43. };
  44. /*
  45. * A tap queue is the central object of tap module, it connects
  46. * an open character device to virtual interface. There can be
  47. * multiple queues on one interface, which map back to queues
  48. * implemented in hardware on the underlying device.
  49. *
  50. * tap_proto is used to allocate queues through the sock allocation
  51. * mechanism.
  52. *
  53. */
  54. struct tap_queue {
  55. struct sock sk;
  56. struct socket sock;
  57. int vnet_hdr_sz;
  58. struct tap_dev __rcu *tap;
  59. struct file *file;
  60. unsigned int flags;
  61. u16 queue_index;
  62. bool enabled;
  63. struct list_head next;
  64. struct ptr_ring ring;
  65. };
  66. rx_handler_result_t tap_handle_frame(struct sk_buff **pskb);
  67. void tap_del_queues(struct tap_dev *tap);
  68. int tap_get_minor(dev_t major, struct tap_dev *tap);
  69. void tap_free_minor(dev_t major, struct tap_dev *tap);
  70. int tap_queue_resize(struct tap_dev *tap);
  71. int tap_create_cdev(struct cdev *tap_cdev, dev_t *tap_major,
  72. const char *device_name, struct module *module);
  73. void tap_destroy_cdev(dev_t major, struct cdev *tap_cdev);
  74. #endif /*_LINUX_IF_TAP_H_*/