Reset to the original
[linux-2.6.git] / linux-2.6-594-new_ns_pid.patch
1 diff -Nurb linux-2.6.22-593/net/core/net-sysfs.c linux-2.6.22-594/net/core/net-sysfs.c
2 --- linux-2.6.22-593/net/core/net-sysfs.c       2008-02-29 09:01:43.000000000 -0500
3 +++ linux-2.6.22-594/net/core/net-sysfs.c       2008-02-29 09:20:20.000000000 -0500
4 @@ -190,6 +190,41 @@
5         return netdev_store(device, attr, buf, len, change_mtu);
6  }
7  
8 +static ssize_t show_new_ns_pid(struct device *cd, struct device_attribute *attr, char *buf)
9 +{
10 +       return -EPERM;
11 +}
12 +
13 +static int change_new_ns_pid(struct net_device *dev, unsigned long new_ns_pid)
14 +{
15 +       struct task_struct *tsk;
16 +       int err;
17 +       struct net *net=NULL;
18 +       /* Look up the network namespace */
19 +       err = -ESRCH;
20 +       rcu_read_lock();
21 +       tsk = find_task_by_pid(new_ns_pid);
22 +       if (tsk) {
23 +               task_lock(tsk);
24 +               if (tsk->nsproxy) {
25 +                       err = 0;
26 +                       net = get_net(tsk->nsproxy->net_ns);
27 +               }
28 +               task_unlock(tsk);
29 +       }
30 +       rcu_read_unlock();
31 +       /* If I found a network namespace move the device */
32 +       if (!err) {
33 +               err = dev_change_net_namespace(dev, net, NULL);
34 +               put_net(net);
35 +       }
36 +       return err;
37 +}
38 +static ssize_t store_new_ns_pid(struct device *cd, struct device_attribute *attr, const char *buf, size_t len)
39 +{
40 +       return netdev_store(cd, attr, buf, len, change_new_ns_pid);
41 +}
42 +
43  NETDEVICE_SHOW(flags, fmt_hex);
44  
45  static int change_flags(struct net_device *dev, unsigned long new_flags)
46 @@ -249,6 +284,7 @@
47         __ATTR(tx_queue_len, S_IRUGO | S_IWUSR, show_tx_queue_len,
48                store_tx_queue_len),
49         __ATTR(weight, S_IRUGO | S_IWUSR, show_weight, store_weight),
50 +       __ATTR(new_ns_pid, S_IWUSR, show_new_ns_pid, store_new_ns_pid),
51         {}
52  };
53