KVM: PPC: Remove unused kvm_unmap_hva callback
[linux/fpc-iii.git] / net / vmw_vsock / af_vsock_tap.c
blob98f09b5393668e1e8ac6bfd5b03e4cf5ffd903b7
1 /*
2 * Tap functions for AF_VSOCK sockets.
4 * Code based on net/netlink/af_netlink.c tap functions.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #include <linux/module.h>
13 #include <net/sock.h>
14 #include <net/af_vsock.h>
15 #include <linux/if_arp.h>
17 static DEFINE_SPINLOCK(vsock_tap_lock);
18 static struct list_head vsock_tap_all __read_mostly =
19 LIST_HEAD_INIT(vsock_tap_all);
21 int vsock_add_tap(struct vsock_tap *vt)
23 if (unlikely(vt->dev->type != ARPHRD_VSOCKMON))
24 return -EINVAL;
26 __module_get(vt->module);
28 spin_lock(&vsock_tap_lock);
29 list_add_rcu(&vt->list, &vsock_tap_all);
30 spin_unlock(&vsock_tap_lock);
32 return 0;
34 EXPORT_SYMBOL_GPL(vsock_add_tap);
36 int vsock_remove_tap(struct vsock_tap *vt)
38 struct vsock_tap *tmp;
39 bool found = false;
41 spin_lock(&vsock_tap_lock);
43 list_for_each_entry(tmp, &vsock_tap_all, list) {
44 if (vt == tmp) {
45 list_del_rcu(&vt->list);
46 found = true;
47 goto out;
51 pr_warn("vsock_remove_tap: %p not found\n", vt);
52 out:
53 spin_unlock(&vsock_tap_lock);
55 synchronize_net();
57 if (found)
58 module_put(vt->module);
60 return found ? 0 : -ENODEV;
62 EXPORT_SYMBOL_GPL(vsock_remove_tap);
64 static int __vsock_deliver_tap_skb(struct sk_buff *skb,
65 struct net_device *dev)
67 int ret = 0;
68 struct sk_buff *nskb = skb_clone(skb, GFP_ATOMIC);
70 if (nskb) {
71 dev_hold(dev);
73 nskb->dev = dev;
74 ret = dev_queue_xmit(nskb);
75 if (unlikely(ret > 0))
76 ret = net_xmit_errno(ret);
78 dev_put(dev);
81 return ret;
84 static void __vsock_deliver_tap(struct sk_buff *skb)
86 int ret;
87 struct vsock_tap *tmp;
89 list_for_each_entry_rcu(tmp, &vsock_tap_all, list) {
90 ret = __vsock_deliver_tap_skb(skb, tmp->dev);
91 if (unlikely(ret))
92 break;
96 void vsock_deliver_tap(struct sk_buff *build_skb(void *opaque), void *opaque)
98 struct sk_buff *skb;
100 rcu_read_lock();
102 if (likely(list_empty(&vsock_tap_all)))
103 goto out;
105 skb = build_skb(opaque);
106 if (skb) {
107 __vsock_deliver_tap(skb);
108 consume_skb(skb);
111 out:
112 rcu_read_unlock();
114 EXPORT_SYMBOL_GPL(vsock_deliver_tap);