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