Merge to Fedora kernel-2.6.18-1.2255_FC5-vs2.0.2.2-rc9 patched with stable patch...
[linux-2.6.git] / kernel / vserver / legacynet.c
1
2 /*
3  *  linux/kernel/vserver/legacynet.c
4  *
5  *  Virtual Server: Legacy Network Funtions
6  *
7  *  Copyright (C) 2001-2003  Jacques Gelinas
8  *  Copyright (C) 2003-2005  Herbert Pƶtzl
9  *
10  *  V0.01  broken out from legacy.c
11  *
12  */
13
14 #include <linux/sched.h>
15 #include <linux/vs_context.h>
16 #include <linux/vs_network.h>
17 #include <linux/vserver/legacy.h>
18 #include <linux/namespace.h>
19 #include <linux/err.h>
20
21 #include <asm/errno.h>
22 #include <asm/uaccess.h>
23
24
25 extern struct nx_info *create_nx_info(void);
26
27 /*  set ipv4 root (syscall) */
28
29 int vc_set_ipv4root(uint32_t nbip, void __user *data)
30 {
31         int i, err = -EPERM;
32         struct vcmd_set_ipv4root_v3 vc_data;
33         struct nx_info *new_nxi, *nxi = current->nx_info;
34
35         if (nbip < 0 || nbip > NB_IPV4ROOT)
36                 return -EINVAL;
37         if (copy_from_user (&vc_data, data, sizeof(vc_data)))
38                 return -EFAULT;
39
40         if (!nxi || nxi->ipv4[0] == 0 || capable(CAP_NET_ADMIN))
41                 /* We are allowed to change everything */
42                 err = 0;
43         else if (nxi) {
44                 int found = 0;
45
46                 /* We are allowed to select a subset of the currently
47                    installed IP numbers. No new one are allowed
48                    We can't change the broadcast address though */
49                 for (i=0; i<nbip; i++) {
50                         int j;
51                         __u32 nxip = vc_data.nx_mask_pair[i].ip;
52                         for (j=0; j<nxi->nbipv4; j++) {
53                                 if (nxip == nxi->ipv4[j]) {
54                                         found++;
55                                         break;
56                                 }
57                         }
58                 }
59                 if ((found == nbip) &&
60                         (vc_data.broadcast == nxi->v4_bcast))
61                         err = 0;
62         }
63         if (err)
64                 return err;
65
66         new_nxi = create_nx_info();
67         if (IS_ERR(new_nxi))
68                 return -EINVAL;
69
70         new_nxi->nbipv4 = nbip;
71         for (i=0; i<nbip; i++) {
72                 new_nxi->ipv4[i] = vc_data.nx_mask_pair[i].ip;
73                 new_nxi->mask[i] = vc_data.nx_mask_pair[i].mask;
74         }
75         new_nxi->v4_bcast = vc_data.broadcast;
76         if (nxi)
77                 printk("!!! switching nx_info %p->%p\n", nxi, new_nxi);
78
79         nx_migrate_task(current, new_nxi);
80         release_nx_info(new_nxi, NULL);
81         put_nx_info(new_nxi);
82         return 0;
83 }
84
85