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