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/vserver/legacy.h>
15 #include <linux/vserver/context.h>
16 #include <linux/vserver/namespace.h>
17 #include <linux/vserver.h>
18 #include <linux/sched.h>
19 #include <linux/namespace.h>
21 #include <asm/errno.h>
22 #include <asm/uaccess.h>
26 static int vx_set_initpid(struct vx_info *vxi, int pid)
31 vxi->vx_initpid = pid;
35 int vc_new_s_context(uint32_t ctx, void __user *data)
38 struct vcmd_new_s_context_v1 vc_data;
39 struct vx_info *new_vxi;
41 if (copy_from_user(&vc_data, data, sizeof(vc_data)))
44 /* legacy hack, will be removed soon */
46 /* assign flags and initpid */
47 if (!current->vx_info)
50 if (vc_data.flags & VX_INFO_INIT)
51 ret = vx_set_initpid(current->vx_info, current->tgid);
53 /* We keep the same vx_id, but lower the capabilities */
54 current->vx_info->vx_bcaps &= (~vc_data.remove_cap);
55 // current->cap_bset &= (~vc_data.remove_cap);
56 ret = vx_current_xid();
57 current->vx_info->vx_flags |= vc_data.flags;
62 if (!vx_check(0, VX_ADMIN) ||
63 !capable(CAP_SYS_ADMIN) || vx_flags(VX_INFO_LOCK, 0))
66 /* ugly hack for Spectator */
72 if (((ctx > MAX_S_CONTEXT) && (ctx != VX_DYNAMIC_ID)) ||
76 if ((ctx == VX_DYNAMIC_ID) || (ctx < MIN_D_CONTEXT))
77 new_vxi = find_or_create_vx_info(ctx);
79 new_vxi = find_vx_info(ctx);
83 new_vxi->vx_flags &= ~(VXF_STATE_SETUP|VXF_STATE_INIT);
85 ret = vx_migrate_task(current, new_vxi);
87 current->vx_info->vx_bcaps &= (~vc_data.remove_cap);
88 // current->cap_bset &= (~vc_data.remove_cap);
89 new_vxi->vx_flags |= vc_data.flags;
90 if (vc_data.flags & VX_INFO_INIT)
91 vx_set_initpid(new_vxi, current->tgid);
92 if (vc_data.flags & VX_INFO_NAMESPACE)
93 vx_set_namespace(new_vxi,
94 current->namespace, current->fs);
95 if (vc_data.flags & VX_INFO_NPROC)
96 new_vxi->limit.rlim[RLIMIT_NPROC] =
97 current->rlim[RLIMIT_NPROC].rlim_max;
100 put_vx_info(new_vxi);
106 /* set ipv4 root (syscall) */
108 int vc_set_ipv4root(uint32_t nbip, void __user *data)
111 struct vcmd_set_ipv4root_v3 vc_data;
112 struct nx_info *new_nxi, *nxi = current->nx_info;
114 if (nbip < 0 || nbip > NB_IPV4ROOT)
116 if (copy_from_user (&vc_data, data, sizeof(vc_data)))
119 if (!nxi || nxi->ipv4[0] == 0 || capable(CAP_NET_ADMIN))
120 // We are allowed to change everything
125 // We are allowed to select a subset of the currently
126 // installed IP numbers. No new one allowed
127 // We can't change the broadcast address though
128 for (i=0; i<nbip; i++) {
130 __u32 nxip = vc_data.nx_mask_pair[i].ip;
131 for (j=0; j<nxi->nbipv4; j++) {
132 if (nxip == nxi->ipv4[j]) {
138 if ((found == nbip) &&
139 (vc_data.broadcast == nxi->v4_bcast))
145 new_nxi = create_nx_info();
149 new_nxi->nbipv4 = nbip;
150 for (i=0; i<nbip; i++) {
151 new_nxi->ipv4[i] = vc_data.nx_mask_pair[i].ip;
152 new_nxi->mask[i] = vc_data.nx_mask_pair[i].mask;
154 new_nxi->v4_bcast = vc_data.broadcast;
155 current->nx_info = new_nxi;
156 current->nid = new_nxi->nx_id;