vserver 2.0 rc7
[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/config.h>
15 #include <linux/sched.h>
16 #include <linux/vs_context.h>
17 #include <linux/vs_network.h>
18 #include <linux/vserver/legacy.h>
19 // #include <linux/vserver/namespace.h>
20 #include <linux/namespace.h>
21 #include <linux/err.h>
22
23 #include <asm/errno.h>
24 #include <asm/uaccess.h>
25
26
27 extern struct nx_info *create_nx_info(void);
28
29 /*  set ipv4 root (syscall) */
30
31 int vc_set_ipv4root(uint32_t nbip, void __user *data)
32 {
33         int i, err = -EPERM;
34         struct vcmd_set_ipv4root_v3 vc_data;
35         struct nx_info *new_nxi, *nxi = current->nx_info;
36
37         if (nbip < 0 || nbip > NB_IPV4ROOT)
38                 return -EINVAL;
39         if (copy_from_user (&vc_data, data, sizeof(vc_data)))
40                 return -EFAULT;
41
42         if (!nxi || nxi->ipv4[0] == 0 || capable(CAP_NET_ADMIN))
43                 /* We are allowed to change everything */
44                 err = 0;
45         else if (nxi) {
46                 int found = 0;
47
48                 /* We are allowed to select a subset of the currently
49                    installed IP numbers. No new one are allowed
50                    We can't change the broadcast address though */
51                 for (i=0; i<nbip; i++) {
52                         int j;
53                         __u32 nxip = vc_data.nx_mask_pair[i].ip;
54                         for (j=0; j<nxi->nbipv4; j++) {
55                                 if (nxip == nxi->ipv4[j]) {
56                                         found++;
57                                         break;
58                                 }
59                         }
60                 }
61                 if ((found == nbip) &&
62                         (vc_data.broadcast == nxi->v4_bcast))
63                         err = 0;
64         }
65         if (err)
66                 return err;
67
68         new_nxi = create_nx_info();
69         if (IS_ERR(new_nxi))
70                 return -EINVAL;
71
72         new_nxi->nbipv4 = nbip;
73         for (i=0; i<nbip; i++) {
74                 new_nxi->ipv4[i] = vc_data.nx_mask_pair[i].ip;
75                 new_nxi->mask[i] = vc_data.nx_mask_pair[i].mask;
76         }
77         new_nxi->v4_bcast = vc_data.broadcast;
78         if (nxi)
79                 printk("!!! switching nx_info %p->%p\n", nxi, new_nxi);
80
81         nx_migrate_task(current, new_nxi);
82         put_nx_info(new_nxi);
83         return 0;
84 }
85
86