Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tap: Renaming tap related APIs, data structures, macros

Renaming tap related APIs, data structures and macros in tap.c from macvtap_.* to tap_.*

Signed-off-by: Sainath Grandhi <sainath.grandhi@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Sainath Grandhi and committed by
David S. Miller
635b8c8e a8e04698

+202 -201
+9 -9
drivers/net/macvtap_main.c
··· 1 1 #include <linux/etherdevice.h> 2 2 #include <linux/if_macvlan.h> 3 - #include <linux/if_macvtap.h> 3 + #include <linux/if_tap.h> 4 4 #include <linux/if_vlan.h> 5 5 #include <linux/interrupt.h> 6 6 #include <linux/nsproxy.h> ··· 62 62 */ 63 63 vlan->tap_features = TUN_OFFLOADS; 64 64 65 - err = netdev_rx_handler_register(dev, macvtap_handle_frame, vlan); 65 + err = netdev_rx_handler_register(dev, tap_handle_frame, vlan); 66 66 if (err) 67 67 return err; 68 68 ··· 82 82 struct list_head *head) 83 83 { 84 84 netdev_rx_handler_unregister(dev); 85 - macvtap_del_queues(dev); 85 + tap_del_queues(dev); 86 86 macvlan_dellink(dev, head); 87 87 } 88 88 ··· 121 121 * been registered but before register_netdevice has 122 122 * finished running. 123 123 */ 124 - err = macvtap_get_minor(vlan); 124 + err = tap_get_minor(vlan); 125 125 if (err) 126 126 return notifier_from_errno(err); 127 127 ··· 129 129 classdev = device_create(&macvtap_class, &dev->dev, devt, 130 130 dev, tap_name); 131 131 if (IS_ERR(classdev)) { 132 - macvtap_free_minor(vlan); 132 + tap_free_minor(vlan); 133 133 return notifier_from_errno(PTR_ERR(classdev)); 134 134 } 135 135 err = sysfs_create_link(&dev->dev.kobj, &classdev->kobj, ··· 144 144 sysfs_remove_link(&dev->dev.kobj, tap_name); 145 145 devt = MKDEV(MAJOR(macvtap_major), vlan->minor); 146 146 device_destroy(&macvtap_class, devt); 147 - macvtap_free_minor(vlan); 147 + tap_free_minor(vlan); 148 148 break; 149 149 case NETDEV_CHANGE_TX_QUEUE_LEN: 150 - if (macvtap_queue_resize(vlan)) 150 + if (tap_queue_resize(vlan)) 151 151 return NOTIFY_BAD; 152 152 break; 153 153 } ··· 159 159 .notifier_call = macvtap_device_event, 160 160 }; 161 161 162 - extern struct file_operations macvtap_fops; 162 + extern struct file_operations tap_fops; 163 163 static int macvtap_init(void) 164 164 { 165 165 int err; ··· 169 169 if (err) 170 170 goto out1; 171 171 172 - cdev_init(&macvtap_cdev, &macvtap_fops); 172 + cdev_init(&macvtap_cdev, &tap_fops); 173 173 err = cdev_add(&macvtap_cdev, macvtap_major, MACVTAP_NUM_DEVS); 174 174 if (err) 175 175 goto out2;
+166 -166
drivers/net/tap.c
··· 24 24 #include <linux/skb_array.h> 25 25 26 26 /* 27 - * A macvtap queue is the central object of this driver, it connects 27 + * A tap queue is the central object of this driver, it connects 28 28 * an open character device to a macvlan interface. There can be 29 29 * multiple queues on one interface, which map back to queues 30 30 * implemented in hardware on the underlying device. 31 31 * 32 - * macvtap_proto is used to allocate queues through the sock allocation 32 + * tap_proto is used to allocate queues through the sock allocation 33 33 * mechanism. 34 34 * 35 35 */ 36 - struct macvtap_queue { 36 + struct tap_queue { 37 37 struct sock sk; 38 38 struct socket sock; 39 39 struct socket_wq wq; ··· 47 47 struct skb_array skb_array; 48 48 }; 49 49 50 - #define MACVTAP_FEATURES (IFF_VNET_HDR | IFF_MULTI_QUEUE) 50 + #define TAP_IFFEATURES (IFF_VNET_HDR | IFF_MULTI_QUEUE) 51 51 52 - #define MACVTAP_VNET_LE 0x80000000 53 - #define MACVTAP_VNET_BE 0x40000000 52 + #define TAP_VNET_LE 0x80000000 53 + #define TAP_VNET_BE 0x40000000 54 54 55 55 #ifdef CONFIG_TUN_VNET_CROSS_LE 56 - static inline bool macvtap_legacy_is_little_endian(struct macvtap_queue *q) 56 + static inline bool tap_legacy_is_little_endian(struct tap_queue *q) 57 57 { 58 - return q->flags & MACVTAP_VNET_BE ? false : 58 + return q->flags & TAP_VNET_BE ? false : 59 59 virtio_legacy_is_little_endian(); 60 60 } 61 61 62 - static long macvtap_get_vnet_be(struct macvtap_queue *q, int __user *sp) 62 + static long tap_get_vnet_be(struct tap_queue *q, int __user *sp) 63 63 { 64 - int s = !!(q->flags & MACVTAP_VNET_BE); 64 + int s = !!(q->flags & TAP_VNET_BE); 65 65 66 66 if (put_user(s, sp)) 67 67 return -EFAULT; ··· 69 69 return 0; 70 70 } 71 71 72 - static long macvtap_set_vnet_be(struct macvtap_queue *q, int __user *sp) 72 + static long tap_set_vnet_be(struct tap_queue *q, int __user *sp) 73 73 { 74 74 int s; 75 75 ··· 77 77 return -EFAULT; 78 78 79 79 if (s) 80 - q->flags |= MACVTAP_VNET_BE; 80 + q->flags |= TAP_VNET_BE; 81 81 else 82 - q->flags &= ~MACVTAP_VNET_BE; 82 + q->flags &= ~TAP_VNET_BE; 83 83 84 84 return 0; 85 85 } 86 86 #else 87 - static inline bool macvtap_legacy_is_little_endian(struct macvtap_queue *q) 87 + static inline bool tap_legacy_is_little_endian(struct tap_queue *q) 88 88 { 89 89 return virtio_legacy_is_little_endian(); 90 90 } 91 91 92 - static long macvtap_get_vnet_be(struct macvtap_queue *q, int __user *argp) 92 + static long tap_get_vnet_be(struct tap_queue *q, int __user *argp) 93 93 { 94 94 return -EINVAL; 95 95 } 96 96 97 - static long macvtap_set_vnet_be(struct macvtap_queue *q, int __user *argp) 97 + static long tap_set_vnet_be(struct tap_queue *q, int __user *argp) 98 98 { 99 99 return -EINVAL; 100 100 } 101 101 #endif /* CONFIG_TUN_VNET_CROSS_LE */ 102 102 103 - static inline bool macvtap_is_little_endian(struct macvtap_queue *q) 103 + static inline bool tap_is_little_endian(struct tap_queue *q) 104 104 { 105 - return q->flags & MACVTAP_VNET_LE || 106 - macvtap_legacy_is_little_endian(q); 105 + return q->flags & TAP_VNET_LE || 106 + tap_legacy_is_little_endian(q); 107 107 } 108 108 109 - static inline u16 macvtap16_to_cpu(struct macvtap_queue *q, __virtio16 val) 109 + static inline u16 tap16_to_cpu(struct tap_queue *q, __virtio16 val) 110 110 { 111 - return __virtio16_to_cpu(macvtap_is_little_endian(q), val); 111 + return __virtio16_to_cpu(tap_is_little_endian(q), val); 112 112 } 113 113 114 - static inline __virtio16 cpu_to_macvtap16(struct macvtap_queue *q, u16 val) 114 + static inline __virtio16 cpu_to_tap16(struct tap_queue *q, u16 val) 115 115 { 116 - return __cpu_to_virtio16(macvtap_is_little_endian(q), val); 116 + return __cpu_to_virtio16(tap_is_little_endian(q), val); 117 117 } 118 118 119 - static struct proto macvtap_proto = { 120 - .name = "macvtap", 119 + static struct proto tap_proto = { 120 + .name = "tap", 121 121 .owner = THIS_MODULE, 122 - .obj_size = sizeof (struct macvtap_queue), 122 + .obj_size = sizeof(struct tap_queue), 123 123 }; 124 124 125 - #define MACVTAP_NUM_DEVS (1U << MINORBITS) 125 + #define TAP_NUM_DEVS (1U << MINORBITS) 126 126 static DEFINE_MUTEX(minor_lock); 127 127 DEFINE_IDR(minor_idr); 128 128 129 129 #define GOODCOPY_LEN 128 130 130 131 - static const struct proto_ops macvtap_socket_ops; 131 + static const struct proto_ops tap_socket_ops; 132 132 133 133 #define RX_OFFLOADS (NETIF_F_GRO | NETIF_F_LRO) 134 134 #define TAP_FEATURES (NETIF_F_GSO | NETIF_F_SG | NETIF_F_FRAGLIST) 135 135 136 - static struct macvlan_dev *macvtap_get_vlan_rcu(const struct net_device *dev) 136 + static struct macvlan_dev *tap_get_vlan_rcu(const struct net_device *dev) 137 137 { 138 138 return rcu_dereference(dev->rx_handler_data); 139 139 } 140 140 141 141 /* 142 142 * RCU usage: 143 - * The macvtap_queue and the macvlan_dev are loosely coupled, the 143 + * The tap_queue and the macvlan_dev are loosely coupled, the 144 144 * pointers from one to the other can only be read while rcu_read_lock 145 145 * or rtnl is held. 146 146 * 147 - * Both the file and the macvlan_dev hold a reference on the macvtap_queue 147 + * Both the file and the macvlan_dev hold a reference on the tap_queue 148 148 * through sock_hold(&q->sk). When the macvlan_dev goes away first, 149 149 * q->vlan becomes inaccessible. When the files gets closed, 150 - * macvtap_get_queue() fails. 150 + * tap_get_queue() fails. 151 151 * 152 152 * There may still be references to the struct sock inside of the 153 153 * queue from outbound SKBs, but these never reference back to the ··· 155 155 * when both our references and any pending SKBs are gone. 156 156 */ 157 157 158 - static int macvtap_enable_queue(struct net_device *dev, struct file *file, 159 - struct macvtap_queue *q) 158 + static int tap_enable_queue(struct net_device *dev, struct file *file, 159 + struct tap_queue *q) 160 160 { 161 161 struct macvlan_dev *vlan = netdev_priv(dev); 162 162 int err = -EINVAL; ··· 177 177 } 178 178 179 179 /* Requires RTNL */ 180 - static int macvtap_set_queue(struct net_device *dev, struct file *file, 181 - struct macvtap_queue *q) 180 + static int tap_set_queue(struct net_device *dev, struct file *file, 181 + struct tap_queue *q) 182 182 { 183 183 struct macvlan_dev *vlan = netdev_priv(dev); 184 184 185 - if (vlan->numqueues == MAX_MACVTAP_QUEUES) 185 + if (vlan->numqueues == MAX_TAP_QUEUES) 186 186 return -EBUSY; 187 187 188 188 rcu_assign_pointer(q->vlan, vlan); ··· 201 201 return 0; 202 202 } 203 203 204 - static int macvtap_disable_queue(struct macvtap_queue *q) 204 + static int tap_disable_queue(struct tap_queue *q) 205 205 { 206 206 struct macvlan_dev *vlan; 207 - struct macvtap_queue *nq; 207 + struct tap_queue *nq; 208 208 209 209 ASSERT_RTNL(); 210 210 if (!q->enabled) ··· 236 236 * Using the spinlock makes sure that we don't get 237 237 * to the queue again after destroying it. 238 238 */ 239 - static void macvtap_put_queue(struct macvtap_queue *q) 239 + static void tap_put_queue(struct tap_queue *q) 240 240 { 241 241 struct macvlan_dev *vlan; 242 242 ··· 245 245 246 246 if (vlan) { 247 247 if (q->enabled) 248 - BUG_ON(macvtap_disable_queue(q)); 248 + BUG_ON(tap_disable_queue(q)); 249 249 250 250 vlan->numqueues--; 251 251 RCU_INIT_POINTER(q->vlan, NULL); ··· 266 266 * Cache vlan->numvtaps since it can become zero during the execution 267 267 * of this function. 268 268 */ 269 - static struct macvtap_queue *macvtap_get_queue(struct net_device *dev, 270 - struct sk_buff *skb) 269 + static struct tap_queue *tap_get_queue(struct net_device *dev, 270 + struct sk_buff *skb) 271 271 { 272 272 struct macvlan_dev *vlan = netdev_priv(dev); 273 - struct macvtap_queue *tap = NULL; 273 + struct tap_queue *tap = NULL; 274 274 /* Access to taps array is protected by rcu, but access to numvtaps 275 275 * isn't. Below we use it to lookup a queue, but treat it as a hint 276 276 * and validate that the result isn't NULL - in case we are ··· 313 313 * that it holds on all queues and safely set the pointer 314 314 * from the queues to NULL. 315 315 */ 316 - void macvtap_del_queues(struct net_device *dev) 316 + void tap_del_queues(struct net_device *dev) 317 317 { 318 318 struct macvlan_dev *vlan = netdev_priv(dev); 319 - struct macvtap_queue *q, *tmp; 319 + struct tap_queue *q, *tmp; 320 320 321 321 ASSERT_RTNL(); 322 322 list_for_each_entry_safe(q, tmp, &vlan->queue_list, next) { ··· 329 329 } 330 330 BUG_ON(vlan->numvtaps); 331 331 BUG_ON(vlan->numqueues); 332 - /* guarantee that any future macvtap_set_queue will fail */ 333 - vlan->numvtaps = MAX_MACVTAP_QUEUES; 332 + /* guarantee that any future tap_set_queue will fail */ 333 + vlan->numvtaps = MAX_TAP_QUEUES; 334 334 } 335 335 336 - rx_handler_result_t macvtap_handle_frame(struct sk_buff **pskb) 336 + rx_handler_result_t tap_handle_frame(struct sk_buff **pskb) 337 337 { 338 338 struct sk_buff *skb = *pskb; 339 339 struct net_device *dev = skb->dev; 340 340 struct macvlan_dev *vlan; 341 - struct macvtap_queue *q; 341 + struct tap_queue *q; 342 342 netdev_features_t features = TAP_FEATURES; 343 343 344 - vlan = macvtap_get_vlan_rcu(dev); 344 + vlan = tap_get_vlan_rcu(dev); 345 345 if (!vlan) 346 346 return RX_HANDLER_PASS; 347 347 348 - q = macvtap_get_queue(dev, skb); 348 + q = tap_get_queue(dev, skb); 349 349 if (!q) 350 350 return RX_HANDLER_PASS; 351 351 ··· 409 409 return RX_HANDLER_CONSUMED; 410 410 } 411 411 412 - int macvtap_get_minor(struct macvlan_dev *vlan) 412 + int tap_get_minor(struct macvlan_dev *vlan) 413 413 { 414 414 int retval = -ENOMEM; 415 415 416 416 mutex_lock(&minor_lock); 417 - retval = idr_alloc(&minor_idr, vlan, 1, MACVTAP_NUM_DEVS, GFP_KERNEL); 417 + retval = idr_alloc(&minor_idr, vlan, 1, TAP_NUM_DEVS, GFP_KERNEL); 418 418 if (retval >= 0) { 419 419 vlan->minor = retval; 420 420 } else if (retval == -ENOSPC) { 421 - netdev_err(vlan->dev, "Too many macvtap devices\n"); 421 + netdev_err(vlan->dev, "Too many tap devices\n"); 422 422 retval = -EINVAL; 423 423 } 424 424 mutex_unlock(&minor_lock); 425 425 return retval < 0 ? retval : 0; 426 426 } 427 427 428 - void macvtap_free_minor(struct macvlan_dev *vlan) 428 + void tap_free_minor(struct macvlan_dev *vlan) 429 429 { 430 430 mutex_lock(&minor_lock); 431 431 if (vlan->minor) { ··· 435 435 mutex_unlock(&minor_lock); 436 436 } 437 437 438 - static struct net_device *dev_get_by_macvtap_minor(int minor) 438 + static struct net_device *dev_get_by_tap_minor(int minor) 439 439 { 440 440 struct net_device *dev = NULL; 441 441 struct macvlan_dev *vlan; ··· 450 450 return dev; 451 451 } 452 452 453 - static void macvtap_sock_write_space(struct sock *sk) 453 + static void tap_sock_write_space(struct sock *sk) 454 454 { 455 455 wait_queue_head_t *wqueue; 456 456 ··· 463 463 wake_up_interruptible_poll(wqueue, POLLOUT | POLLWRNORM | POLLWRBAND); 464 464 } 465 465 466 - static void macvtap_sock_destruct(struct sock *sk) 466 + static void tap_sock_destruct(struct sock *sk) 467 467 { 468 - struct macvtap_queue *q = container_of(sk, struct macvtap_queue, sk); 468 + struct tap_queue *q = container_of(sk, struct tap_queue, sk); 469 469 470 470 skb_array_cleanup(&q->skb_array); 471 471 } 472 472 473 - static int macvtap_open(struct inode *inode, struct file *file) 473 + static int tap_open(struct inode *inode, struct file *file) 474 474 { 475 475 struct net *net = current->nsproxy->net_ns; 476 476 struct net_device *dev; 477 - struct macvtap_queue *q; 477 + struct tap_queue *q; 478 478 int err = -ENODEV; 479 479 480 480 rtnl_lock(); 481 - dev = dev_get_by_macvtap_minor(iminor(inode)); 481 + dev = dev_get_by_tap_minor(iminor(inode)); 482 482 if (!dev) 483 483 goto err; 484 484 485 485 err = -ENOMEM; 486 - q = (struct macvtap_queue *)sk_alloc(net, AF_UNSPEC, GFP_KERNEL, 487 - &macvtap_proto, 0); 486 + q = (struct tap_queue *)sk_alloc(net, AF_UNSPEC, GFP_KERNEL, 487 + &tap_proto, 0); 488 488 if (!q) 489 489 goto err; 490 490 ··· 493 493 q->sock.type = SOCK_RAW; 494 494 q->sock.state = SS_CONNECTED; 495 495 q->sock.file = file; 496 - q->sock.ops = &macvtap_socket_ops; 496 + q->sock.ops = &tap_socket_ops; 497 497 sock_init_data(&q->sock, &q->sk); 498 - q->sk.sk_write_space = macvtap_sock_write_space; 499 - q->sk.sk_destruct = macvtap_sock_destruct; 498 + q->sk.sk_write_space = tap_sock_write_space; 499 + q->sk.sk_destruct = tap_sock_destruct; 500 500 q->flags = IFF_VNET_HDR | IFF_NO_PI | IFF_TAP; 501 501 q->vnet_hdr_sz = sizeof(struct virtio_net_hdr); 502 502 503 503 /* 504 - * so far only KVM virtio_net uses macvtap, enable zero copy between 504 + * so far only KVM virtio_net uses tap, enable zero copy between 505 505 * guest kernel and host kernel when lower device supports zerocopy 506 506 * 507 507 * The macvlan supports zerocopy iff the lower device supports zero ··· 514 514 if (skb_array_init(&q->skb_array, dev->tx_queue_len, GFP_KERNEL)) 515 515 goto err_array; 516 516 517 - err = macvtap_set_queue(dev, file, q); 517 + err = tap_set_queue(dev, file, q); 518 518 if (err) 519 519 goto err_queue; 520 520 ··· 535 535 return err; 536 536 } 537 537 538 - static int macvtap_release(struct inode *inode, struct file *file) 538 + static int tap_release(struct inode *inode, struct file *file) 539 539 { 540 - struct macvtap_queue *q = file->private_data; 541 - macvtap_put_queue(q); 540 + struct tap_queue *q = file->private_data; 541 + tap_put_queue(q); 542 542 return 0; 543 543 } 544 544 545 - static unsigned int macvtap_poll(struct file *file, poll_table * wait) 545 + static unsigned int tap_poll(struct file *file, poll_table *wait) 546 546 { 547 - struct macvtap_queue *q = file->private_data; 547 + struct tap_queue *q = file->private_data; 548 548 unsigned int mask = POLLERR; 549 549 550 550 if (!q) ··· 565 565 return mask; 566 566 } 567 567 568 - static inline struct sk_buff *macvtap_alloc_skb(struct sock *sk, size_t prepad, 569 - size_t len, size_t linear, 568 + static inline struct sk_buff *tap_alloc_skb(struct sock *sk, size_t prepad, 569 + size_t len, size_t linear, 570 570 int noblock, int *err) 571 571 { 572 572 struct sk_buff *skb; ··· 589 589 } 590 590 591 591 /* Neighbour code has some assumptions on HH_DATA_MOD alignment */ 592 - #define MACVTAP_RESERVE HH_DATA_OFF(ETH_HLEN) 592 + #define TAP_RESERVE HH_DATA_OFF(ETH_HLEN) 593 593 594 594 /* Get packet from user space buffer */ 595 - static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m, 596 - struct iov_iter *from, int noblock) 595 + static ssize_t tap_get_user(struct tap_queue *q, struct msghdr *m, 596 + struct iov_iter *from, int noblock) 597 597 { 598 - int good_linear = SKB_MAX_HEAD(MACVTAP_RESERVE); 598 + int good_linear = SKB_MAX_HEAD(TAP_RESERVE); 599 599 struct sk_buff *skb; 600 600 struct macvlan_dev *vlan; 601 601 unsigned long total_len = iov_iter_count(from); ··· 621 621 goto err; 622 622 iov_iter_advance(from, vnet_hdr_len - sizeof(vnet_hdr)); 623 623 if ((vnet_hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) && 624 - macvtap16_to_cpu(q, vnet_hdr.csum_start) + 625 - macvtap16_to_cpu(q, vnet_hdr.csum_offset) + 2 > 626 - macvtap16_to_cpu(q, vnet_hdr.hdr_len)) 627 - vnet_hdr.hdr_len = cpu_to_macvtap16(q, 628 - macvtap16_to_cpu(q, vnet_hdr.csum_start) + 629 - macvtap16_to_cpu(q, vnet_hdr.csum_offset) + 2); 624 + tap16_to_cpu(q, vnet_hdr.csum_start) + 625 + tap16_to_cpu(q, vnet_hdr.csum_offset) + 2 > 626 + tap16_to_cpu(q, vnet_hdr.hdr_len)) 627 + vnet_hdr.hdr_len = cpu_to_tap16(q, 628 + tap16_to_cpu(q, vnet_hdr.csum_start) + 629 + tap16_to_cpu(q, vnet_hdr.csum_offset) + 2); 630 630 err = -EINVAL; 631 - if (macvtap16_to_cpu(q, vnet_hdr.hdr_len) > len) 631 + if (tap16_to_cpu(q, vnet_hdr.hdr_len) > len) 632 632 goto err; 633 633 } 634 634 ··· 640 640 struct iov_iter i; 641 641 642 642 copylen = vnet_hdr.hdr_len ? 643 - macvtap16_to_cpu(q, vnet_hdr.hdr_len) : GOODCOPY_LEN; 643 + tap16_to_cpu(q, vnet_hdr.hdr_len) : GOODCOPY_LEN; 644 644 if (copylen > good_linear) 645 645 copylen = good_linear; 646 646 else if (copylen < ETH_HLEN) ··· 654 654 655 655 if (!zerocopy) { 656 656 copylen = len; 657 - linear = macvtap16_to_cpu(q, vnet_hdr.hdr_len); 657 + linear = tap16_to_cpu(q, vnet_hdr.hdr_len); 658 658 if (linear > good_linear) 659 659 linear = good_linear; 660 660 else if (linear < ETH_HLEN) 661 661 linear = ETH_HLEN; 662 662 } 663 663 664 - skb = macvtap_alloc_skb(&q->sk, MACVTAP_RESERVE, copylen, 665 - linear, noblock, &err); 664 + skb = tap_alloc_skb(&q->sk, TAP_RESERVE, copylen, 665 + linear, noblock, &err); 666 666 if (!skb) 667 667 goto err; 668 668 ··· 680 680 681 681 if (vnet_hdr_len) { 682 682 err = virtio_net_hdr_to_skb(skb, &vnet_hdr, 683 - macvtap_is_little_endian(q)); 683 + tap_is_little_endian(q)); 684 684 if (err) 685 685 goto err_kfree; 686 686 } ··· 728 728 return err; 729 729 } 730 730 731 - static ssize_t macvtap_write_iter(struct kiocb *iocb, struct iov_iter *from) 731 + static ssize_t tap_write_iter(struct kiocb *iocb, struct iov_iter *from) 732 732 { 733 733 struct file *file = iocb->ki_filp; 734 - struct macvtap_queue *q = file->private_data; 734 + struct tap_queue *q = file->private_data; 735 735 736 - return macvtap_get_user(q, NULL, from, file->f_flags & O_NONBLOCK); 736 + return tap_get_user(q, NULL, from, file->f_flags & O_NONBLOCK); 737 737 } 738 738 739 739 /* Put packet to the user space buffer */ 740 - static ssize_t macvtap_put_user(struct macvtap_queue *q, 741 - const struct sk_buff *skb, 742 - struct iov_iter *iter) 740 + static ssize_t tap_put_user(struct tap_queue *q, 741 + const struct sk_buff *skb, 742 + struct iov_iter *iter) 743 743 { 744 744 int ret; 745 745 int vnet_hdr_len = 0; ··· 753 753 return -EINVAL; 754 754 755 755 if (virtio_net_hdr_from_skb(skb, &vnet_hdr, 756 - macvtap_is_little_endian(q), true)) 756 + tap_is_little_endian(q), true)) 757 757 BUG(); 758 758 759 759 if (copy_to_iter(&vnet_hdr, sizeof(vnet_hdr), iter) != ··· 792 792 return ret ? ret : total; 793 793 } 794 794 795 - static ssize_t macvtap_do_read(struct macvtap_queue *q, 796 - struct iov_iter *to, 797 - int noblock) 795 + static ssize_t tap_do_read(struct tap_queue *q, 796 + struct iov_iter *to, 797 + int noblock) 798 798 { 799 799 DEFINE_WAIT(wait); 800 800 struct sk_buff *skb; ··· 827 827 finish_wait(sk_sleep(&q->sk), &wait); 828 828 829 829 if (skb) { 830 - ret = macvtap_put_user(q, skb, to); 830 + ret = tap_put_user(q, skb, to); 831 831 if (unlikely(ret < 0)) 832 832 kfree_skb(skb); 833 833 else ··· 836 836 return ret; 837 837 } 838 838 839 - static ssize_t macvtap_read_iter(struct kiocb *iocb, struct iov_iter *to) 839 + static ssize_t tap_read_iter(struct kiocb *iocb, struct iov_iter *to) 840 840 { 841 841 struct file *file = iocb->ki_filp; 842 - struct macvtap_queue *q = file->private_data; 842 + struct tap_queue *q = file->private_data; 843 843 ssize_t len = iov_iter_count(to), ret; 844 844 845 - ret = macvtap_do_read(q, to, file->f_flags & O_NONBLOCK); 845 + ret = tap_do_read(q, to, file->f_flags & O_NONBLOCK); 846 846 ret = min_t(ssize_t, ret, len); 847 847 if (ret > 0) 848 848 iocb->ki_pos = ret; 849 849 return ret; 850 850 } 851 851 852 - static struct macvlan_dev *macvtap_get_vlan(struct macvtap_queue *q) 852 + static struct macvlan_dev *tap_get_vlan(struct tap_queue *q) 853 853 { 854 854 struct macvlan_dev *vlan; 855 855 ··· 861 861 return vlan; 862 862 } 863 863 864 - static void macvtap_put_vlan(struct macvlan_dev *vlan) 864 + static void tap_put_vlan(struct macvlan_dev *vlan) 865 865 { 866 866 dev_put(vlan->dev); 867 867 } 868 868 869 - static int macvtap_ioctl_set_queue(struct file *file, unsigned int flags) 869 + static int tap_ioctl_set_queue(struct file *file, unsigned int flags) 870 870 { 871 - struct macvtap_queue *q = file->private_data; 871 + struct tap_queue *q = file->private_data; 872 872 struct macvlan_dev *vlan; 873 873 int ret; 874 874 875 - vlan = macvtap_get_vlan(q); 875 + vlan = tap_get_vlan(q); 876 876 if (!vlan) 877 877 return -EINVAL; 878 878 879 879 if (flags & IFF_ATTACH_QUEUE) 880 - ret = macvtap_enable_queue(vlan->dev, file, q); 880 + ret = tap_enable_queue(vlan->dev, file, q); 881 881 else if (flags & IFF_DETACH_QUEUE) 882 - ret = macvtap_disable_queue(q); 882 + ret = tap_disable_queue(q); 883 883 else 884 884 ret = -EINVAL; 885 885 886 - macvtap_put_vlan(vlan); 886 + tap_put_vlan(vlan); 887 887 return ret; 888 888 } 889 889 890 - static int set_offload(struct macvtap_queue *q, unsigned long arg) 890 + static int set_offload(struct tap_queue *q, unsigned long arg) 891 891 { 892 892 struct macvlan_dev *vlan; 893 893 netdev_features_t features; ··· 919 919 * setting the TSO bit means that the userspace wants to 920 920 * accept TSO frames and turning it off means that user space 921 921 * does not support TSO. 922 - * For macvtap, we have to invert it to mean the same thing. 922 + * For tap, we have to invert it to mean the same thing. 923 923 * When user space turns off TSO, we turn off GSO/LRO so that 924 924 * user-space will not receive TSO frames. 925 925 */ ··· 941 941 /* 942 942 * provide compatibility with generic tun/tap interface 943 943 */ 944 - static long macvtap_ioctl(struct file *file, unsigned int cmd, 945 - unsigned long arg) 944 + static long tap_ioctl(struct file *file, unsigned int cmd, 945 + unsigned long arg) 946 946 { 947 - struct macvtap_queue *q = file->private_data; 947 + struct tap_queue *q = file->private_data; 948 948 struct macvlan_dev *vlan; 949 949 void __user *argp = (void __user *)arg; 950 950 struct ifreq __user *ifr = argp; ··· 962 962 return -EFAULT; 963 963 964 964 ret = 0; 965 - if ((u & ~MACVTAP_FEATURES) != (IFF_NO_PI | IFF_TAP)) 965 + if ((u & ~TAP_IFFEATURES) != (IFF_NO_PI | IFF_TAP)) 966 966 ret = -EINVAL; 967 967 else 968 - q->flags = (q->flags & ~MACVTAP_FEATURES) | u; 968 + q->flags = (q->flags & ~TAP_IFFEATURES) | u; 969 969 970 970 return ret; 971 971 972 972 case TUNGETIFF: 973 973 rtnl_lock(); 974 - vlan = macvtap_get_vlan(q); 974 + vlan = tap_get_vlan(q); 975 975 if (!vlan) { 976 976 rtnl_unlock(); 977 977 return -ENOLINK; ··· 982 982 if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) || 983 983 put_user(u, &ifr->ifr_flags)) 984 984 ret = -EFAULT; 985 - macvtap_put_vlan(vlan); 985 + tap_put_vlan(vlan); 986 986 rtnl_unlock(); 987 987 return ret; 988 988 ··· 990 990 if (get_user(u, &ifr->ifr_flags)) 991 991 return -EFAULT; 992 992 rtnl_lock(); 993 - ret = macvtap_ioctl_set_queue(file, u); 993 + ret = tap_ioctl_set_queue(file, u); 994 994 rtnl_unlock(); 995 995 return ret; 996 996 997 997 case TUNGETFEATURES: 998 - if (put_user(IFF_TAP | IFF_NO_PI | MACVTAP_FEATURES, up)) 998 + if (put_user(IFF_TAP | IFF_NO_PI | TAP_IFFEATURES, up)) 999 999 return -EFAULT; 1000 1000 return 0; 1001 1001 ··· 1022 1022 return 0; 1023 1023 1024 1024 case TUNGETVNETLE: 1025 - s = !!(q->flags & MACVTAP_VNET_LE); 1025 + s = !!(q->flags & TAP_VNET_LE); 1026 1026 if (put_user(s, sp)) 1027 1027 return -EFAULT; 1028 1028 return 0; ··· 1031 1031 if (get_user(s, sp)) 1032 1032 return -EFAULT; 1033 1033 if (s) 1034 - q->flags |= MACVTAP_VNET_LE; 1034 + q->flags |= TAP_VNET_LE; 1035 1035 else 1036 - q->flags &= ~MACVTAP_VNET_LE; 1036 + q->flags &= ~TAP_VNET_LE; 1037 1037 return 0; 1038 1038 1039 1039 case TUNGETVNETBE: 1040 - return macvtap_get_vnet_be(q, sp); 1040 + return tap_get_vnet_be(q, sp); 1041 1041 1042 1042 case TUNSETVNETBE: 1043 - return macvtap_set_vnet_be(q, sp); 1043 + return tap_set_vnet_be(q, sp); 1044 1044 1045 1045 case TUNSETOFFLOAD: 1046 1046 /* let the user check for future flags */ ··· 1055 1055 1056 1056 case SIOCGIFHWADDR: 1057 1057 rtnl_lock(); 1058 - vlan = macvtap_get_vlan(q); 1058 + vlan = tap_get_vlan(q); 1059 1059 if (!vlan) { 1060 1060 rtnl_unlock(); 1061 1061 return -ENOLINK; ··· 1066 1066 copy_to_user(&ifr->ifr_hwaddr.sa_data, vlan->dev->dev_addr, ETH_ALEN) || 1067 1067 put_user(u, &ifr->ifr_hwaddr.sa_family)) 1068 1068 ret = -EFAULT; 1069 - macvtap_put_vlan(vlan); 1069 + tap_put_vlan(vlan); 1070 1070 rtnl_unlock(); 1071 1071 return ret; 1072 1072 ··· 1074 1074 if (copy_from_user(&sa, &ifr->ifr_hwaddr, sizeof(sa))) 1075 1075 return -EFAULT; 1076 1076 rtnl_lock(); 1077 - vlan = macvtap_get_vlan(q); 1077 + vlan = tap_get_vlan(q); 1078 1078 if (!vlan) { 1079 1079 rtnl_unlock(); 1080 1080 return -ENOLINK; 1081 1081 } 1082 1082 ret = dev_set_mac_address(vlan->dev, &sa); 1083 - macvtap_put_vlan(vlan); 1083 + tap_put_vlan(vlan); 1084 1084 rtnl_unlock(); 1085 1085 return ret; 1086 1086 ··· 1090 1090 } 1091 1091 1092 1092 #ifdef CONFIG_COMPAT 1093 - static long macvtap_compat_ioctl(struct file *file, unsigned int cmd, 1094 - unsigned long arg) 1093 + static long tap_compat_ioctl(struct file *file, unsigned int cmd, 1094 + unsigned long arg) 1095 1095 { 1096 - return macvtap_ioctl(file, cmd, (unsigned long)compat_ptr(arg)); 1096 + return tap_ioctl(file, cmd, (unsigned long)compat_ptr(arg)); 1097 1097 } 1098 1098 #endif 1099 1099 1100 - const struct file_operations macvtap_fops = { 1100 + const struct file_operations tap_fops = { 1101 1101 .owner = THIS_MODULE, 1102 - .open = macvtap_open, 1103 - .release = macvtap_release, 1104 - .read_iter = macvtap_read_iter, 1105 - .write_iter = macvtap_write_iter, 1106 - .poll = macvtap_poll, 1102 + .open = tap_open, 1103 + .release = tap_release, 1104 + .read_iter = tap_read_iter, 1105 + .write_iter = tap_write_iter, 1106 + .poll = tap_poll, 1107 1107 .llseek = no_llseek, 1108 - .unlocked_ioctl = macvtap_ioctl, 1108 + .unlocked_ioctl = tap_ioctl, 1109 1109 #ifdef CONFIG_COMPAT 1110 - .compat_ioctl = macvtap_compat_ioctl, 1110 + .compat_ioctl = tap_compat_ioctl, 1111 1111 #endif 1112 1112 }; 1113 1113 1114 - static int macvtap_sendmsg(struct socket *sock, struct msghdr *m, 1115 - size_t total_len) 1114 + static int tap_sendmsg(struct socket *sock, struct msghdr *m, 1115 + size_t total_len) 1116 1116 { 1117 - struct macvtap_queue *q = container_of(sock, struct macvtap_queue, sock); 1118 - return macvtap_get_user(q, m, &m->msg_iter, m->msg_flags & MSG_DONTWAIT); 1117 + struct tap_queue *q = container_of(sock, struct tap_queue, sock); 1118 + return tap_get_user(q, m, &m->msg_iter, m->msg_flags & MSG_DONTWAIT); 1119 1119 } 1120 1120 1121 - static int macvtap_recvmsg(struct socket *sock, struct msghdr *m, 1122 - size_t total_len, int flags) 1121 + static int tap_recvmsg(struct socket *sock, struct msghdr *m, 1122 + size_t total_len, int flags) 1123 1123 { 1124 - struct macvtap_queue *q = container_of(sock, struct macvtap_queue, sock); 1124 + struct tap_queue *q = container_of(sock, struct tap_queue, sock); 1125 1125 int ret; 1126 1126 if (flags & ~(MSG_DONTWAIT|MSG_TRUNC)) 1127 1127 return -EINVAL; 1128 - ret = macvtap_do_read(q, &m->msg_iter, flags & MSG_DONTWAIT); 1128 + ret = tap_do_read(q, &m->msg_iter, flags & MSG_DONTWAIT); 1129 1129 if (ret > total_len) { 1130 1130 m->msg_flags |= MSG_TRUNC; 1131 1131 ret = flags & MSG_TRUNC ? ret : total_len; ··· 1133 1133 return ret; 1134 1134 } 1135 1135 1136 - static int macvtap_peek_len(struct socket *sock) 1136 + static int tap_peek_len(struct socket *sock) 1137 1137 { 1138 - struct macvtap_queue *q = container_of(sock, struct macvtap_queue, 1138 + struct tap_queue *q = container_of(sock, struct tap_queue, 1139 1139 sock); 1140 1140 return skb_array_peek_len(&q->skb_array); 1141 1141 } 1142 1142 1143 1143 /* Ops structure to mimic raw sockets with tun */ 1144 - static const struct proto_ops macvtap_socket_ops = { 1145 - .sendmsg = macvtap_sendmsg, 1146 - .recvmsg = macvtap_recvmsg, 1147 - .peek_len = macvtap_peek_len, 1144 + static const struct proto_ops tap_socket_ops = { 1145 + .sendmsg = tap_sendmsg, 1146 + .recvmsg = tap_recvmsg, 1147 + .peek_len = tap_peek_len, 1148 1148 }; 1149 1149 1150 1150 /* Get an underlying socket object from tun file. Returns error unless file is 1151 1151 * attached to a device. The returned object works like a packet socket, it 1152 1152 * can be used for sock_sendmsg/sock_recvmsg. The caller is responsible for 1153 1153 * holding a reference to the file for as long as the socket is in use. */ 1154 - struct socket *macvtap_get_socket(struct file *file) 1154 + struct socket *tap_get_socket(struct file *file) 1155 1155 { 1156 - struct macvtap_queue *q; 1157 - if (file->f_op != &macvtap_fops) 1156 + struct tap_queue *q; 1157 + if (file->f_op != &tap_fops) 1158 1158 return ERR_PTR(-EINVAL); 1159 1159 q = file->private_data; 1160 1160 if (!q) 1161 1161 return ERR_PTR(-EBADFD); 1162 1162 return &q->sock; 1163 1163 } 1164 - EXPORT_SYMBOL_GPL(macvtap_get_socket); 1164 + EXPORT_SYMBOL_GPL(tap_get_socket); 1165 1165 1166 - int macvtap_queue_resize(struct macvlan_dev *vlan) 1166 + int tap_queue_resize(struct macvlan_dev *vlan) 1167 1167 { 1168 1168 struct net_device *dev = vlan->dev; 1169 - struct macvtap_queue *q; 1169 + struct tap_queue *q; 1170 1170 struct skb_array **arrays; 1171 1171 int n = vlan->numqueues; 1172 1172 int ret, i = 0;
+2 -1
drivers/vhost/net.c
··· 24 24 #include <linux/if_arp.h> 25 25 #include <linux/if_tun.h> 26 26 #include <linux/if_macvlan.h> 27 + #include <linux/if_tap.h> 27 28 #include <linux/if_vlan.h> 28 29 29 30 #include <net/sock.h> ··· 961 960 sock = tun_get_socket(file); 962 961 if (!IS_ERR(sock)) 963 962 return sock; 964 - sock = macvtap_get_socket(file); 963 + sock = tap_get_socket(file); 965 964 if (IS_ERR(sock)) 966 965 fput(file); 967 966 return sock;
+2 -15
include/linux/if_macvlan.h
··· 9 9 #include <net/netlink.h> 10 10 #include <linux/u64_stats_sync.h> 11 11 12 - #if IS_ENABLED(CONFIG_MACVTAP) 13 - struct socket *macvtap_get_socket(struct file *); 14 - #else 15 - #include <linux/err.h> 16 - #include <linux/errno.h> 17 - struct file; 18 - struct socket; 19 - static inline struct socket *macvtap_get_socket(struct file *f) 20 - { 21 - return ERR_PTR(-EINVAL); 22 - } 23 - #endif /* CONFIG_MACVTAP */ 24 - 25 12 struct macvlan_port; 26 13 struct macvtap_queue; 27 14 ··· 16 29 * Maximum times a macvtap device can be opened. This can be used to 17 30 * configure the number of receive queue, e.g. for multiqueue virtio. 18 31 */ 19 - #define MAX_MACVTAP_QUEUES 256 32 + #define MAX_TAP_QUEUES 256 20 33 21 34 #define MACVLAN_MC_FILTER_BITS 8 22 35 #define MACVLAN_MC_FILTER_SZ (1 << MACVLAN_MC_FILTER_BITS) ··· 36 49 enum macvlan_mode mode; 37 50 u16 flags; 38 51 /* This array tracks active taps. */ 39 - struct macvtap_queue __rcu *taps[MAX_MACVTAP_QUEUES]; 52 + struct tap_queue __rcu *taps[MAX_TAP_QUEUES]; 40 53 /* This list tracks all taps (both enabled and disabled) */ 41 54 struct list_head queue_list; 42 55 int numvtaps;
-10
include/linux/if_macvtap.h
··· 1 - #ifndef _LINUX_IF_MACVTAP_H_ 2 - #define _LINUX_IF_MACVTAP_H_ 3 - 4 - rx_handler_result_t macvtap_handle_frame(struct sk_buff **pskb); 5 - void macvtap_del_queues(struct net_device *dev); 6 - int macvtap_get_minor(struct macvlan_dev *vlan); 7 - void macvtap_free_minor(struct macvlan_dev *vlan); 8 - int macvtap_queue_resize(struct macvlan_dev *vlan); 9 - 10 - #endif /*_LINUX_IF_MACVTAP_H_*/
+23
include/linux/if_tap.h
··· 1 + #ifndef _LINUX_IF_TAP_H_ 2 + #define _LINUX_IF_TAP_H_ 3 + 4 + #if IS_ENABLED(CONFIG_MACVTAP) 5 + struct socket *tap_get_socket(struct file *); 6 + #else 7 + #include <linux/err.h> 8 + #include <linux/errno.h> 9 + struct file; 10 + struct socket; 11 + static inline struct socket *tap_get_socket(struct file *f) 12 + { 13 + return ERR_PTR(-EINVAL); 14 + } 15 + #endif /* CONFIG_MACVTAP */ 16 + 17 + rx_handler_result_t tap_handle_frame(struct sk_buff **pskb); 18 + void tap_del_queues(struct net_device *dev); 19 + int tap_get_minor(struct macvlan_dev *vlan); 20 + void tap_free_minor(struct macvlan_dev *vlan); 21 + int tap_queue_resize(struct macvlan_dev *vlan); 22 + 23 + #endif /*_LINUX_IF_TAP_H_*/