ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Linux-Clone/README
(Generate patch)

Comparing Linux-Clone/README (file contents):
Revision 1.3 by root, Thu Nov 2 07:31:16 2017 UTC vs.
Revision 1.4 by root, Tue Sep 6 10:57:02 2022 UTC

4 4
5SYNOPSIS 5SYNOPSIS
6 use Linux::Clone; 6 use Linux::Clone;
7 7
8DESCRIPTION 8DESCRIPTION
9 This module exposes the linux clone(2), unshare(2) and related syscalls 9 This module exposes the linux clone(2), unshare(2) and some related
10 to Perl. 10 syscalls to Perl.
11 11
12 $retval = unshare $flags 12 $retval = unshare $flags
13 The following CLONE_ flag values (without CLONE_ prefix) are 13 The following CLONE_ flag values (without CLONE_ prefix) are
14 supported for unshare, if found, in this release. See the 14 supported for unshare, if found, in this release. See the
15 documentation for unshare(2) for more info on what they do: 15 documentation for unshare(2) for more info on what they do:
25 Linux::Clone::NEWPID 25 Linux::Clone::NEWPID
26 Linux::Clone::NEWUTS 26 Linux::Clone::NEWUTS
27 Linux::Clone::NEWIPC 27 Linux::Clone::NEWIPC
28 Linux::Clone::NEWNET 28 Linux::Clone::NEWNET
29 Linux::Clone::NEWCGROUP 29 Linux::Clone::NEWCGROUP
30 Linux::Clone::NEWTIME
30 31
31 Example: unshare the network namespace and prove that by calling 32 Example: unshare the network namespace and prove that by calling
32 ifconfig, showing only an unconfigured lo interface. 33 ifconfig, showing only the unconfigured lo interface.
33 34
34 Linux::Clone::unshare Linux::Clone::NEWNET 35 Linux::Clone::unshare Linux::Clone::NEWNET
35 and "unshare: $!"; 36 and "unshare: $!";
37 Linux::Clone::configure_loopback;
36 system "ifconfig -a"; 38 system "ifconfig";
37 39
38 Example: unshare the network namespace, initialise the loopback 40 Example: unshare the network namespace, initialise the loopback
39 interface, create a veth interface pair, put one interface into the 41 interface, create a veth interface pair, put one interface into the
40 parent processes namespace (use ifconfig -a from another shell), 42 parent processes namespace (use ifconfig -a from another shell),
41 configure the other interface with 192.168.99.2 -> 192.168.99.1 and 43 configure the other interface with 192.168.99.2 -> 192.168.99.1 and
45 47
46 # unshare our network namespace 48 # unshare our network namespace
47 Linux::Clone::unshare Linux::Clone::NEWNET 49 Linux::Clone::unshare Linux::Clone::NEWNET
48 and "unshare: $!"; 50 and "unshare: $!";
49 51
52 Linux::Clone::configure_loopback;
53
50 my $ppid = getppid; 54 my $ppid = getppid;
51 55
52 system " 56 system "
53 # configure loopback interface
54 ip link set lo up
55 ip route add 127.0.0.0/8 dev lo
56
57 # create veth pair 57 # create veth pair
58 ip link add name veth_master type veth peer name veth_slave 58 ip link add name veth_master type veth peer name veth_slave
59 59
60 # move veth_master to our parent process' namespace 60 # move veth_master to our parent process' namespace
61 ip link set veth_master netns $ppid 61 ip link set veth_master netns $ppid
84 use Linux::Clone; 84 use Linux::Clone;
85 85
86 Linux::Clone::unshare Linux::Clone::NEWNS 86 Linux::Clone::unshare Linux::Clone::NEWNS
87 and die "unshare: $!"; 87 and die "unshare: $!";
88 88
89 # now bind-mount /lib over /etc and ls -l /etc - scary 89 # now bind-mount /lib over /etc and ls -l /etc - looks scary
90 system "mount -n --bind /lib /etc"; 90 system "mount -n --bind /lib /etc";
91 system "ls -l /etc"; 91 system "ls -l /etc";
92 92
93 $retval = Linux::Clone::clone $coderef, $stacksize, $flags[, $ptid, 93 $retval = Linux::Clone::clone $coderef, $stacksize, $flags[, $ptid,
94 $tls, $ctid] 94 $tls, $ctid]
120 Linux::Clone::VFORK 120 Linux::Clone::VFORK
121 Linux::Clone::SETTLS (not yet implemented) 121 Linux::Clone::SETTLS (not yet implemented)
122 Linux::Clone::PARENT_SETTID (not yet implemented) 122 Linux::Clone::PARENT_SETTID (not yet implemented)
123 Linux::Clone::CHILD_SETTID (not yet implemented) 123 Linux::Clone::CHILD_SETTID (not yet implemented)
124 Linux::Clone::CHILD_CLEARTID (not yet implemented) 124 Linux::Clone::CHILD_CLEARTID (not yet implemented)
125 Linux::Clone::PIDFD (not yet implemented)
125 Linux::Clone::DETACHED 126 Linux::Clone::DETACHED
126 Linux::Clone::UNTRACED 127 Linux::Clone::UNTRACED
127 Linux::Clone::IO 128 Linux::Clone::IO
129 Linux::Clone::CSIGNAL exit signal mask
128 130
129 Note that for practical reasons you basically must not use 131 Note that for practical reasons you basically must not use
130 "Linux::Clone::VM" or "Linux::Clone::VFORK", as perl is unlikely to 132 "Linux::Clone::VM" or "Linux::Clone::VFORK", as perl is unlikely to
131 cope with that. 133 cope with that.
132 134
140 Linux::Clone::setns $fh_or_fd[, $nstype] 142 Linux::Clone::setns $fh_or_fd[, $nstype]
141 Calls setns(2) on the file descriptor (or file handle) $fh_or_fd. If 143 Calls setns(2) on the file descriptor (or file handle) $fh_or_fd. If
142 $nstype is missing, then 0 is used. 144 $nstype is missing, then 0 is used.
143 145
144 The argument $nstype can be 0, "Linux::Clone::NEWIPC", 146 The argument $nstype can be 0, "Linux::Clone::NEWIPC",
145 "Linux::Clone::NEWNET", "Linux::Clone::NEUTS", 147 "Linux::Clone::NEWNET", "Linux::Clone::NEWUTS",
146 "Linux::Clone::NEWCGROUP", "Linux::Clone::NEWNS", 148 "Linux::Clone::NEWCGROUP", "Linux::Clone::NEWNS",
147 "Linux::Clone::NEWPID" or "Linux::Clone::NEWUSER". 149 "Linux::Clone::NEWPID" or "Linux::Clone::NEWUSER".
148 150
149 Linux::Clone::pivot_root $new_root, $old_root 151 Linux::Clone::pivot_root $new_root, $old_root
150 Calls pivot_root(2) - refer to its manpage for details. 152 Calls pivot_root(2) - refer to its manpage for details.
155 The following $type constants are available if the kcmp syscall 157 The following $type constants are available if the kcmp syscall
156 number was available during compilation: 158 number was available during compilation:
157 159
158 "Linux::Clone::KCMP_FILE", "Linux::Clone::KCMP_VM", 160 "Linux::Clone::KCMP_FILE", "Linux::Clone::KCMP_VM",
159 "Linux::Clone::KCMP_FILES", "Linux::Clone::KCMP_FS", 161 "Linux::Clone::KCMP_FILES", "Linux::Clone::KCMP_FS",
160 "Linux::Clone::KCMP_SIGHAND", "Linux::Clone::KCMP_IO" and 162 "Linux::Clone::KCMP_SIGHAND", "Linux::Clone::KCMP_IO",
161 "Linux::Clone::KCMP_SYSVSEM". 163 "Linux::Clone::KCMP_SYSVSEM" and "Linux::Clone::KCMP_EPOLL_TFD".
164
165 Linux::Clone::configure_loopback
166 Configures a working loopback interface (basically, does the
167 equivalent of "ifconfig lo up" which automatically adds ipv4/ipv6
168 addresses and routes), which can be useful to get a network
169 namespace going.
170
171 Dies on error and returns nothing.
172
173 "ioctl" symbols
174 The following ioctl symbols are also provided by this module (see
175 ioctl_ns(8)).
176
177 Linux::Clone::NS_GET_USERNS
178 Linux::Clone::NS_GET_PARENT
179 Linux::Clone::NS_GET_NSTYPE
180 Linux::Clone::NS_OWNER_UID
181
182SEE ALSO
183 IO::AIO has some related functions, such as "pidfd_send_signal", and
184 some unrelated functions that might be useful.
185
186 namspaces(7), cgroup_namespaces(7), pid_namespaces(7),
187 user_namespaces(7), time_namespaces(7), ip-netns(8), switch_root(8),
188 ioctl_ns(2), lsns(8)Q
162 189
163AUTHOR 190AUTHOR
164 Marc Lehmann <schmorp@schmorp.de> 191 Marc Lehmann <schmorp@schmorp.de>
165 http://home.schmorp.de/ 192 http://home.schmorp.de/
166 193

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines