Merge tag 'wireless-next-2023-11-27' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-block.git] / include / linux / if_tap.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
635b8c8e
SG
2#ifndef _LINUX_IF_TAP_H_
3#define _LINUX_IF_TAP_H_
4
5f10376b
JK
5#include <net/sock.h>
6#include <linux/skb_array.h>
7
8struct file;
9struct socket;
10
9a393b5d 11#if IS_ENABLED(CONFIG_TAP)
635b8c8e 12struct socket *tap_get_socket(struct file *);
5990a305 13struct ptr_ring *tap_get_ptr_ring(struct file *file);
635b8c8e
SG
14#else
15#include <linux/err.h>
16#include <linux/errno.h>
635b8c8e
SG
17static inline struct socket *tap_get_socket(struct file *f)
18{
19 return ERR_PTR(-EINVAL);
20}
5990a305 21static inline struct ptr_ring *tap_get_ptr_ring(struct file *f)
49f96fd0
JW
22{
23 return ERR_PTR(-EINVAL);
24}
9a393b5d 25#endif /* CONFIG_TAP */
635b8c8e 26
88ca59d1
GM
27/*
28 * Maximum times a tap device can be opened. This can be used to
29 * configure the number of receive queue, e.g. for multiqueue virtio.
30 */
6fe3faf8
SG
31#define MAX_TAP_QUEUES 256
32
33struct tap_queue;
34
35struct tap_dev {
36 struct net_device *dev;
37 u16 flags;
38 /* This array tracks active taps. */
39 struct tap_queue __rcu *taps[MAX_TAP_QUEUES];
40 /* This list tracks all taps (both enabled and disabled) */
41 struct list_head queue_list;
42 int numvtaps;
43 int numqueues;
44 netdev_features_t tap_features;
45 int minor;
46
47 void (*update_features)(struct tap_dev *tap, netdev_features_t features);
48 void (*count_tx_dropped)(struct tap_dev *tap);
49 void (*count_rx_dropped)(struct tap_dev *tap);
50};
51
52/*
53 * A tap queue is the central object of tap module, it connects
54 * an open character device to virtual interface. There can be
55 * multiple queues on one interface, which map back to queues
56 * implemented in hardware on the underlying device.
57 *
58 * tap_proto is used to allocate queues through the sock allocation
59 * mechanism.
60 *
61 */
62
63struct tap_queue {
64 struct sock sk;
65 struct socket sock;
6fe3faf8
SG
66 int vnet_hdr_sz;
67 struct tap_dev __rcu *tap;
68 struct file *file;
69 unsigned int flags;
70 u16 queue_index;
71 bool enabled;
72 struct list_head next;
5990a305 73 struct ptr_ring ring;
6fe3faf8
SG
74};
75
635b8c8e 76rx_handler_result_t tap_handle_frame(struct sk_buff **pskb);
6fe3faf8 77void tap_del_queues(struct tap_dev *tap);
d9f1f61c
SG
78int tap_get_minor(dev_t major, struct tap_dev *tap);
79void tap_free_minor(dev_t major, struct tap_dev *tap);
6fe3faf8 80int tap_queue_resize(struct tap_dev *tap);
dea6e19f
GM
81int tap_create_cdev(struct cdev *tap_cdev, dev_t *tap_major,
82 const char *device_name, struct module *module);
ebc05ba7 83void tap_destroy_cdev(dev_t major, struct cdev *tap_cdev);
635b8c8e
SG
84
85#endif /*_LINUX_IF_TAP_H_*/