blob: 3482c3c2037d8c35a3825bc1b16ff573c9d60905 [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 *);
6#else
7#include <linux/err.h>
8#include <linux/errno.h>
9struct file;
10struct socket;
11static inline struct socket *tap_get_socket(struct file *f)
12{
13 return ERR_PTR(-EINVAL);
14}
Sainath Grandhi9a393b52017-02-10 16:03:51 -080015#endif /* CONFIG_TAP */
Sainath Grandhi635b8c82017-02-10 16:03:47 -080016
Sainath Grandhi6fe3faf2017-02-10 16:03:49 -080017#include <net/sock.h>
18#include <linux/skb_array.h>
19
20#define MAX_TAP_QUEUES 256
21
22struct tap_queue;
23
24struct 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
52struct 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 Grandhi635b8c82017-02-10 16:03:47 -080066rx_handler_result_t tap_handle_frame(struct sk_buff **pskb);
Sainath Grandhi6fe3faf2017-02-10 16:03:49 -080067void tap_del_queues(struct tap_dev *tap);
Sainath Grandhid9f1f612017-02-10 16:03:50 -080068int tap_get_minor(dev_t major, struct tap_dev *tap);
69void tap_free_minor(dev_t major, struct tap_dev *tap);
Sainath Grandhi6fe3faf2017-02-10 16:03:49 -080070int tap_queue_resize(struct tap_dev *tap);
Sainath Grandhiebc05ba2017-02-10 16:03:48 -080071int tap_create_cdev(struct cdev *tap_cdev,
72 dev_t *tap_major, const char *device_name);
73void tap_destroy_cdev(dev_t major, struct cdev *tap_cdev);
Sainath Grandhi635b8c82017-02-10 16:03:47 -080074
75#endif /*_LINUX_IF_TAP_H_*/