• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_IF_TAP_H_
3 #define _LINUX_IF_TAP_H_
4 
5 #if IS_ENABLED(CONFIG_TAP)
6 struct socket *tap_get_socket(struct file *);
7 struct skb_array *tap_get_skb_array(struct file *file);
8 #else
9 #include <linux/err.h>
10 #include <linux/errno.h>
11 struct file;
12 struct socket;
tap_get_socket(struct file * f)13 static inline struct socket *tap_get_socket(struct file *f)
14 {
15 	return ERR_PTR(-EINVAL);
16 }
tap_get_skb_array(struct file * f)17 static inline struct skb_array *tap_get_skb_array(struct file *f)
18 {
19 	return ERR_PTR(-EINVAL);
20 }
21 #endif /* CONFIG_TAP */
22 
23 #include <net/sock.h>
24 #include <linux/skb_array.h>
25 
26 #define MAX_TAP_QUEUES 256
27 
28 struct tap_queue;
29 
30 struct 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 
58 struct 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 
72 rx_handler_result_t tap_handle_frame(struct sk_buff **pskb);
73 void tap_del_queues(struct tap_dev *tap);
74 int tap_get_minor(dev_t major, struct tap_dev *tap);
75 void tap_free_minor(dev_t major, struct tap_dev *tap);
76 int tap_queue_resize(struct tap_dev *tap);
77 int tap_create_cdev(struct cdev *tap_cdev, dev_t *tap_major,
78 		    const char *device_name, struct module *module);
79 void tap_destroy_cdev(dev_t major, struct cdev *tap_cdev);
80 
81 #endif /*_LINUX_IF_TAP_H_*/
82