2 * linux/kernel/vserver/legacy.c
4 * Virtual Server: Legacy Funtions
6 * Copyright (C) 2001-2003 Jacques Gelinas
7 * Copyright (C) 2003-2004 Herbert Pƶtzl
9 * V0.01 broken out from vcontext.c V0.05
13 #include <linux/config.h>
14 #include <linux/sched.h>
15 #include <linux/namespace.h>
16 #include <linux/vserver/legacy.h>
17 #include <linux/vserver/namespace.h>
18 #include <linux/vserver.h>
19 #include <linux/vs_base.h>
20 #include <linux/vs_context.h>
21 #include <linux/vs_network.h>
23 #include <asm/errno.h>
24 #include <asm/uaccess.h>
28 static int vx_set_initpid(struct vx_info *vxi, int pid)
33 vxi->vx_initpid = pid;
37 int vc_new_s_context(uint32_t ctx, void __user *data)
40 struct vcmd_new_s_context_v1 vc_data;
41 struct vx_info *new_vxi;
43 if (copy_from_user(&vc_data, data, sizeof(vc_data)))
46 /* legacy hack, will be removed soon */
48 /* assign flags and initpid */
49 if (!current->vx_info)
52 if (vc_data.flags & VX_INFO_INIT)
53 ret = vx_set_initpid(current->vx_info, current->tgid);
55 /* We keep the same vx_id, but lower the capabilities */
56 current->vx_info->vx_bcaps &= (~vc_data.remove_cap);
57 // current->cap_bset &= (~vc_data.remove_cap);
58 ret = vx_current_xid();
59 current->vx_info->vx_flags |= vc_data.flags;
64 if (!vx_check(0, VX_ADMIN) ||
65 !capable(CAP_SYS_ADMIN) || vx_flags(VX_INFO_PRIVATE, 0))
68 /* ugly hack for Spectator */
74 if (((ctx > MAX_S_CONTEXT) && (ctx != VX_DYNAMIC_ID)) ||
78 if ((ctx == VX_DYNAMIC_ID) || (ctx < MIN_D_CONTEXT))
79 new_vxi = locate_or_create_vx_info(ctx);
81 new_vxi = locate_vx_info(ctx);
85 new_vxi->vx_flags &= ~(VXF_STATE_SETUP|VXF_STATE_INIT);
87 ret = vx_migrate_task(current, new_vxi);
89 current->vx_info->vx_bcaps &= (~vc_data.remove_cap);
90 // current->cap_bset &= (~vc_data.remove_cap);
91 new_vxi->vx_flags |= vc_data.flags;
92 if (vc_data.flags & VX_INFO_INIT)
93 vx_set_initpid(new_vxi, current->tgid);
94 if (vc_data.flags & VX_INFO_NAMESPACE)
95 vx_set_namespace(new_vxi,
96 current->namespace, current->fs);
97 if (vc_data.flags & VX_INFO_NPROC)
98 new_vxi->limit.rlim[RLIMIT_NPROC] =
99 current->rlim[RLIMIT_NPROC].rlim_max;
100 ret = new_vxi->vx_id;
102 put_vx_info(new_vxi);
107 extern struct nx_info *create_nx_info(void);
109 /* set ipv4 root (syscall) */
111 int vc_set_ipv4root(uint32_t nbip, void __user *data)
114 struct vcmd_set_ipv4root_v3 vc_data;
115 struct nx_info *new_nxi, *nxi = current->nx_info;
117 if (nbip < 0 || nbip > NB_IPV4ROOT)
119 if (copy_from_user (&vc_data, data, sizeof(vc_data)))
122 if (!nxi || nxi->ipv4[0] == 0 || capable(CAP_NET_ADMIN))
123 // We are allowed to change everything
128 // We are allowed to select a subset of the currently
129 // installed IP numbers. No new one allowed
130 // We can't change the broadcast address though
131 for (i=0; i<nbip; i++) {
133 __u32 nxip = vc_data.nx_mask_pair[i].ip;
134 for (j=0; j<nxi->nbipv4; j++) {
135 if (nxip == nxi->ipv4[j]) {
141 if ((found == nbip) &&
142 (vc_data.broadcast == nxi->v4_bcast))
148 new_nxi = create_nx_info();
152 new_nxi->nbipv4 = nbip;
153 for (i=0; i<nbip; i++) {
154 new_nxi->ipv4[i] = vc_data.nx_mask_pair[i].ip;
155 new_nxi->mask[i] = vc_data.nx_mask_pair[i].mask;
157 new_nxi->v4_bcast = vc_data.broadcast;
158 // current->nx_info = new_nxi;
160 printk("!!! switching nx_info %p->%p\n", nxi, new_nxi);
161 clr_nx_info(¤t->nx_info);
163 nx_migrate_task(current, new_nxi);
164 // set_nx_info(¤t->nx_info, new_nxi);
165 // current->nid = new_nxi->nx_id;
166 put_nx_info(new_nxi);