xref: /kernel/linux/linux-6.6/include/linux/if_tap.h (revision 62306a36)
162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef _LINUX_IF_TAP_H_
362306a36Sopenharmony_ci#define _LINUX_IF_TAP_H_
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#include <net/sock.h>
662306a36Sopenharmony_ci#include <linux/skb_array.h>
762306a36Sopenharmony_ci
862306a36Sopenharmony_cistruct file;
962306a36Sopenharmony_cistruct socket;
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_TAP)
1262306a36Sopenharmony_cistruct socket *tap_get_socket(struct file *);
1362306a36Sopenharmony_cistruct ptr_ring *tap_get_ptr_ring(struct file *file);
1462306a36Sopenharmony_ci#else
1562306a36Sopenharmony_ci#include <linux/err.h>
1662306a36Sopenharmony_ci#include <linux/errno.h>
1762306a36Sopenharmony_cistatic inline struct socket *tap_get_socket(struct file *f)
1862306a36Sopenharmony_ci{
1962306a36Sopenharmony_ci	return ERR_PTR(-EINVAL);
2062306a36Sopenharmony_ci}
2162306a36Sopenharmony_cistatic inline struct ptr_ring *tap_get_ptr_ring(struct file *f)
2262306a36Sopenharmony_ci{
2362306a36Sopenharmony_ci	return ERR_PTR(-EINVAL);
2462306a36Sopenharmony_ci}
2562306a36Sopenharmony_ci#endif /* CONFIG_TAP */
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci/*
2862306a36Sopenharmony_ci * Maximum times a tap device can be opened. This can be used to
2962306a36Sopenharmony_ci * configure the number of receive queue, e.g. for multiqueue virtio.
3062306a36Sopenharmony_ci */
3162306a36Sopenharmony_ci#define MAX_TAP_QUEUES 256
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_cistruct tap_queue;
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_cistruct tap_dev {
3662306a36Sopenharmony_ci	struct net_device	*dev;
3762306a36Sopenharmony_ci	u16			flags;
3862306a36Sopenharmony_ci	/* This array tracks active taps. */
3962306a36Sopenharmony_ci	struct tap_queue    __rcu *taps[MAX_TAP_QUEUES];
4062306a36Sopenharmony_ci	/* This list tracks all taps (both enabled and disabled) */
4162306a36Sopenharmony_ci	struct list_head	queue_list;
4262306a36Sopenharmony_ci	int			numvtaps;
4362306a36Sopenharmony_ci	int			numqueues;
4462306a36Sopenharmony_ci	netdev_features_t	tap_features;
4562306a36Sopenharmony_ci	int			minor;
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci	void (*update_features)(struct tap_dev *tap, netdev_features_t features);
4862306a36Sopenharmony_ci	void (*count_tx_dropped)(struct tap_dev *tap);
4962306a36Sopenharmony_ci	void (*count_rx_dropped)(struct tap_dev *tap);
5062306a36Sopenharmony_ci};
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci/*
5362306a36Sopenharmony_ci * A tap queue is the central object of tap module, it connects
5462306a36Sopenharmony_ci * an open character device to virtual interface. There can be
5562306a36Sopenharmony_ci * multiple queues on one interface, which map back to queues
5662306a36Sopenharmony_ci * implemented in hardware on the underlying device.
5762306a36Sopenharmony_ci *
5862306a36Sopenharmony_ci * tap_proto is used to allocate queues through the sock allocation
5962306a36Sopenharmony_ci * mechanism.
6062306a36Sopenharmony_ci *
6162306a36Sopenharmony_ci */
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_cistruct tap_queue {
6462306a36Sopenharmony_ci	struct sock sk;
6562306a36Sopenharmony_ci	struct socket sock;
6662306a36Sopenharmony_ci	int vnet_hdr_sz;
6762306a36Sopenharmony_ci	struct tap_dev __rcu *tap;
6862306a36Sopenharmony_ci	struct file *file;
6962306a36Sopenharmony_ci	unsigned int flags;
7062306a36Sopenharmony_ci	u16 queue_index;
7162306a36Sopenharmony_ci	bool enabled;
7262306a36Sopenharmony_ci	struct list_head next;
7362306a36Sopenharmony_ci	struct ptr_ring ring;
7462306a36Sopenharmony_ci};
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_cirx_handler_result_t tap_handle_frame(struct sk_buff **pskb);
7762306a36Sopenharmony_civoid tap_del_queues(struct tap_dev *tap);
7862306a36Sopenharmony_ciint tap_get_minor(dev_t major, struct tap_dev *tap);
7962306a36Sopenharmony_civoid tap_free_minor(dev_t major, struct tap_dev *tap);
8062306a36Sopenharmony_ciint tap_queue_resize(struct tap_dev *tap);
8162306a36Sopenharmony_ciint tap_create_cdev(struct cdev *tap_cdev, dev_t *tap_major,
8262306a36Sopenharmony_ci		    const char *device_name, struct module *module);
8362306a36Sopenharmony_civoid tap_destroy_cdev(dev_t major, struct cdev *tap_cdev);
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci#endif /*_LINUX_IF_TAP_H_*/
86