Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _LINUX_IF_TAP_H_
0003 #define _LINUX_IF_TAP_H_
0004 
0005 #include <net/sock.h>
0006 #include <linux/skb_array.h>
0007 
0008 struct file;
0009 struct socket;
0010 
0011 #if IS_ENABLED(CONFIG_TAP)
0012 struct socket *tap_get_socket(struct file *);
0013 struct ptr_ring *tap_get_ptr_ring(struct file *file);
0014 #else
0015 #include <linux/err.h>
0016 #include <linux/errno.h>
0017 static inline struct socket *tap_get_socket(struct file *f)
0018 {
0019     return ERR_PTR(-EINVAL);
0020 }
0021 static inline struct ptr_ring *tap_get_ptr_ring(struct file *f)
0022 {
0023     return ERR_PTR(-EINVAL);
0024 }
0025 #endif /* CONFIG_TAP */
0026 
0027 /*
0028  * Maximum times a tap device can be opened. This can be used to
0029  * configure the number of receive queue, e.g. for multiqueue virtio.
0030  */
0031 #define MAX_TAP_QUEUES 256
0032 
0033 struct tap_queue;
0034 
0035 struct tap_dev {
0036     struct net_device   *dev;
0037     u16         flags;
0038     /* This array tracks active taps. */
0039     struct tap_queue    __rcu *taps[MAX_TAP_QUEUES];
0040     /* This list tracks all taps (both enabled and disabled) */
0041     struct list_head    queue_list;
0042     int         numvtaps;
0043     int         numqueues;
0044     netdev_features_t   tap_features;
0045     int         minor;
0046 
0047     void (*update_features)(struct tap_dev *tap, netdev_features_t features);
0048     void (*count_tx_dropped)(struct tap_dev *tap);
0049     void (*count_rx_dropped)(struct tap_dev *tap);
0050 };
0051 
0052 /*
0053  * A tap queue is the central object of tap module, it connects
0054  * an open character device to virtual interface. There can be
0055  * multiple queues on one interface, which map back to queues
0056  * implemented in hardware on the underlying device.
0057  *
0058  * tap_proto is used to allocate queues through the sock allocation
0059  * mechanism.
0060  *
0061  */
0062 
0063 struct tap_queue {
0064     struct sock sk;
0065     struct socket sock;
0066     int vnet_hdr_sz;
0067     struct tap_dev __rcu *tap;
0068     struct file *file;
0069     unsigned int flags;
0070     u16 queue_index;
0071     bool enabled;
0072     struct list_head next;
0073     struct ptr_ring ring;
0074 };
0075 
0076 rx_handler_result_t tap_handle_frame(struct sk_buff **pskb);
0077 void tap_del_queues(struct tap_dev *tap);
0078 int tap_get_minor(dev_t major, struct tap_dev *tap);
0079 void tap_free_minor(dev_t major, struct tap_dev *tap);
0080 int tap_queue_resize(struct tap_dev *tap);
0081 int tap_create_cdev(struct cdev *tap_cdev, dev_t *tap_major,
0082             const char *device_name, struct module *module);
0083 void tap_destroy_cdev(dev_t major, struct cdev *tap_cdev);
0084 
0085 #endif /*_LINUX_IF_TAP_H_*/