blob: 0d7b56d913087590d7db17d7b29290b048812162 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Sainath Grandhi635b8c82017-02-10 16:03:47 -08002#ifndef _LINUX_IF_TAP_H_
3#define _LINUX_IF_TAP_H_
4
Sainath Grandhi9a393b52017-02-10 16:03:51 -08005#if IS_ENABLED(CONFIG_TAP)
Sainath Grandhi635b8c82017-02-10 16:03:47 -08006struct socket *tap_get_socket(struct file *);
Jason Wang49f96fd2017-05-17 12:14:42 +08007struct skb_array *tap_get_skb_array(struct file *file);
Sainath Grandhi635b8c82017-02-10 16:03:47 -08008#else
9#include <linux/err.h>
10#include <linux/errno.h>
11struct file;
12struct socket;
13static inline struct socket *tap_get_socket(struct file *f)
14{
15 return ERR_PTR(-EINVAL);
16}
Jason Wang49f96fd2017-05-17 12:14:42 +080017static inline struct skb_array *tap_get_skb_array(struct file *f)
18{
19 return ERR_PTR(-EINVAL);
20}
Sainath Grandhi9a393b52017-02-10 16:03:51 -080021#endif /* CONFIG_TAP */
Sainath Grandhi635b8c82017-02-10 16:03:47 -080022
Sainath Grandhi6fe3faf2017-02-10 16:03:49 -080023#include <net/sock.h>
24#include <linux/skb_array.h>
25
26#define MAX_TAP_QUEUES 256
27
28struct tap_queue;
29
30struct tap_dev {
31 struct net_device *dev;
32 u16 flags;
33 /* This array tracks active taps. */
34 struct tap_queue __rcu *taps[MAX_TAP_QUEUES];
35 /* This list tracks all taps (both enabled and disabled) */
36 struct list_head queue_list;
37 int numvtaps;
38 int numqueues;
39 netdev_features_t tap_features;
40 int minor;
41
42 void (*update_features)(struct tap_dev *tap, netdev_features_t features);
43 void (*count_tx_dropped)(struct tap_dev *tap);
44 void (*count_rx_dropped)(struct tap_dev *tap);
45};
46
47/*
48 * A tap queue is the central object of tap module, it connects
49 * an open character device to virtual interface. There can be
50 * multiple queues on one interface, which map back to queues
51 * implemented in hardware on the underlying device.
52 *
53 * tap_proto is used to allocate queues through the sock allocation
54 * mechanism.
55 *
56 */
57
58struct tap_queue {
59 struct sock sk;
60 struct socket sock;
61 struct socket_wq wq;
62 int vnet_hdr_sz;
63 struct tap_dev __rcu *tap;
64 struct file *file;
65 unsigned int flags;
66 u16 queue_index;
67 bool enabled;
68 struct list_head next;
69 struct skb_array skb_array;
70};
71
Sainath Grandhi635b8c82017-02-10 16:03:47 -080072rx_handler_result_t tap_handle_frame(struct sk_buff **pskb);
Sainath Grandhi6fe3faf2017-02-10 16:03:49 -080073void tap_del_queues(struct tap_dev *tap);
Sainath Grandhid9f1f612017-02-10 16:03:50 -080074int tap_get_minor(dev_t major, struct tap_dev *tap);
75void tap_free_minor(dev_t major, struct tap_dev *tap);
Sainath Grandhi6fe3faf2017-02-10 16:03:49 -080076int tap_queue_resize(struct tap_dev *tap);
Sainath Grandhiebc05ba2017-02-10 16:03:48 -080077int tap_create_cdev(struct cdev *tap_cdev,
78 dev_t *tap_major, const char *device_name);
79void tap_destroy_cdev(dev_t major, struct cdev *tap_cdev);
Sainath Grandhi635b8c82017-02-10 16:03:47 -080080
81#endif /*_LINUX_IF_TAP_H_*/