blob: d1b5173ad8f02d806ce8fcff4b28591ae1b9bce7 [file] [log] [blame]
Sainath Grandhi635b8c82017-02-10 16:03:47 -08001#ifndef _LINUX_IF_TAP_H_
2#define _LINUX_IF_TAP_H_
3
Sainath Grandhi9a393b52017-02-10 16:03:51 -08004#if IS_ENABLED(CONFIG_TAP)
Sainath Grandhi635b8c82017-02-10 16:03:47 -08005struct socket *tap_get_socket(struct file *);
Jason Wang49f96fd2017-05-17 12:14:42 +08006struct skb_array *tap_get_skb_array(struct file *file);
Sainath Grandhi635b8c82017-02-10 16:03:47 -08007#else
8#include <linux/err.h>
9#include <linux/errno.h>
10struct file;
11struct socket;
12static inline struct socket *tap_get_socket(struct file *f)
13{
14 return ERR_PTR(-EINVAL);
15}
Jason Wang49f96fd2017-05-17 12:14:42 +080016static inline struct skb_array *tap_get_skb_array(struct file *f)
17{
18 return ERR_PTR(-EINVAL);
19}
Sainath Grandhi9a393b52017-02-10 16:03:51 -080020#endif /* CONFIG_TAP */
Sainath Grandhi635b8c82017-02-10 16:03:47 -080021
Sainath Grandhi6fe3faf2017-02-10 16:03:49 -080022#include <net/sock.h>
23#include <linux/skb_array.h>
24
Girish Moodalbail88ca59d2017-10-25 12:26:43 -070025/*
26 * Maximum times a tap device can be opened. This can be used to
27 * configure the number of receive queue, e.g. for multiqueue virtio.
28 */
Sainath Grandhi6fe3faf2017-02-10 16:03:49 -080029#define MAX_TAP_QUEUES 256
30
31struct tap_queue;
32
33struct tap_dev {
34 struct net_device *dev;
35 u16 flags;
36 /* This array tracks active taps. */
37 struct tap_queue __rcu *taps[MAX_TAP_QUEUES];
38 /* This list tracks all taps (both enabled and disabled) */
39 struct list_head queue_list;
40 int numvtaps;
41 int numqueues;
42 netdev_features_t tap_features;
43 int minor;
44
45 void (*update_features)(struct tap_dev *tap, netdev_features_t features);
46 void (*count_tx_dropped)(struct tap_dev *tap);
47 void (*count_rx_dropped)(struct tap_dev *tap);
48};
49
50/*
51 * A tap queue is the central object of tap module, it connects
52 * an open character device to virtual interface. There can be
53 * multiple queues on one interface, which map back to queues
54 * implemented in hardware on the underlying device.
55 *
56 * tap_proto is used to allocate queues through the sock allocation
57 * mechanism.
58 *
59 */
60
61struct tap_queue {
62 struct sock sk;
63 struct socket sock;
64 struct socket_wq wq;
65 int vnet_hdr_sz;
66 struct tap_dev __rcu *tap;
67 struct file *file;
68 unsigned int flags;
69 u16 queue_index;
70 bool enabled;
71 struct list_head next;
72 struct skb_array skb_array;
73};
74
Sainath Grandhi635b8c82017-02-10 16:03:47 -080075rx_handler_result_t tap_handle_frame(struct sk_buff **pskb);
Sainath Grandhi6fe3faf2017-02-10 16:03:49 -080076void tap_del_queues(struct tap_dev *tap);
Sainath Grandhid9f1f612017-02-10 16:03:50 -080077int tap_get_minor(dev_t major, struct tap_dev *tap);
78void tap_free_minor(dev_t major, struct tap_dev *tap);
Sainath Grandhi6fe3faf2017-02-10 16:03:49 -080079int tap_queue_resize(struct tap_dev *tap);
Sainath Grandhiebc05ba2017-02-10 16:03:48 -080080int tap_create_cdev(struct cdev *tap_cdev,
81 dev_t *tap_major, const char *device_name);
82void tap_destroy_cdev(dev_t major, struct cdev *tap_cdev);
Sainath Grandhi635b8c82017-02-10 16:03:47 -080083
84#endif /*_LINUX_IF_TAP_H_*/