2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-25 03:18:36 +00:00

167 Commits

Author SHA1 Message Date
Andrey Vagin
a74605a78d sk-inet: restore option REUSEADDR (v2)
All sockets are created with SO_REUSEADDR, it's needed for restoring.
E.g.: A listen socket is created after a connected socket. Both of them
are binded to one port.

So SO_REUSEADDR should be restored, when all sockets on a port were created.

This code creates a structure for each port of one type of sockets
and accounts a number of sockets, which are not restored yet.

Sockets have a hook post_open(), in which it waits when all sockets for
a defined port would be created and then it will restore SO_REUSEADDR.

struct port contains a type (udp, tcp, etc) and a port number.
It doesn't contain family or addr, because it's extra loads of logic,
which doesn't bring a significant profits.

v2: fix according with comments from Pavel

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-08-20 17:50:08 +04:00
Pavel Emelyanov
2660b810d9 packet: Rings support
There's no way (currently) to check that the ring got restored.
Will do it once we implement mapping of a packet socket and
tcpdump app test.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-08-20 15:32:55 +04:00
Pavel Emelyanov
4ee3345beb packet: Support fanout
This one may be present and may be not, thus it's optional in the image.
The C-binding we use report the field absense in the parsed stream via
the has_xxx field, but in the google docs it's stated, that

	"When a message is parsed, if it does not contain an optional
	 element, the corresponding field in the parsed object is set
	 to the default value for that field."

Thus, I also declare the default value for it to be not zero as 0 is
a valid fanout configuration.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-08-20 15:32:27 +04:00
Pavel Emelyanov
69acf64f57 packet: Add support for mclists
The implementation is rather straightforward. One thing to note
is that non-single membership of each type is not supported. It
can be done, but I'm unaware of any software doing so.

Note: the pb show routine should be tuned to support showing bytes.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-08-15 21:04:49 +04:00
Pavel Emelyanov
fb5a5671c8 sock: Do strict socket family checks when looking up collected socket
We hash socket with inode and family, but search only by inode. Well,
yes, family should match, since all sockets are in one sockfs in kernel,
but let's make sure _we_ did things right by checking the family as well.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-08-15 19:16:12 +04:00
Pavel Emelyanov
4ff60cd870 packet: Switch to use packet diag module
It's in net-next already and does provide all we currently
need (and more). Implementation is like for inet and unix
sockets.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-08-15 17:39:21 +04:00
Pavel Emelyanov
acba1e9bae sock: Cleanup inet sockets collecing
There is no need in 6 receive callbacks -- we can find out family and protocol
(and thus -- type) out of the inet_diag_req_v2 passed through transparent arg
of nlk request engine.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-08-11 22:32:38 +04:00
Andrey Vagin
796d4ceb95 socket: switch netns for collecting sockets
All sockets should be collected in a target net name-space when the -n net
is specified.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-08-11 13:12:43 +04:00
Pavel Emelyanov
216a3a6521 sk: Add level to socket option dump/restore helpers
Packet socket need SOL_PACKET one.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-08-09 17:25:11 +04:00
Pavel Emelyanov
fc7071d05e net: Packet sockets basic support
Support only basic packet socket functionality -- create and bind.
This should be enough to start testing dhclient inside container.
Other stuff (filter, mmaps, fanouts, etc.) will come later.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-08-09 16:17:41 +04:00
Pavel Emelyanov
b0cf603b18 netlink: Pass argument through do_rtnl_req engine
Will need it int netns dumping callbacks later.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-08-02 07:36:12 +04:00
Pavel Emelyanov
cffe1ea172 netlink: Remove handmade rtnl macros/definitions
All we need is (should be) in rtnetlink.h

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-08-02 07:36:12 +04:00
Pavel Emelyanov
b7b5bfdd28 libnetlink: Move the rtnl req routine into libnetlink.c
The function that does socket collecting is actually a rtnl
request sending one. It will be usefull for netns dump/restore,
so move it to generic place.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-08-02 07:36:12 +04:00
Cyrill Gorcunov
0cf04ac781 protobuf: Drop old sk_opts_entry structure
We've switched to SkOptsEntry, no need to carry this
obsolete one.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-07-19 09:44:41 +04:00
Cyrill Gorcunov
eb0f81bc6f protobuf: Convert sk_opts_entry to PB format
This patch prepares the ground for further patches.
sk_opts_entry get converted to PB format but not
yet used anywhere in code. Also a few additional
pb_ helpers are added.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-07-19 09:31:00 +04:00
Cyrill Gorcunov
37131e51b1 sockets: Restore unbound inet sockets v5
v2:
 - Use do_dump_opt in dump_socket to not call
   lookup_socket redundantly

v3:
 - use getsockopt to check that unconnected
   socket has no peername and it's not listening
 - do test only socket protocol since family and
   type will be called in dump_one_inet_fd.

v4:
 - Move proto tests to can_dump_inet_sk
 - Use SOL_TCP/TCP_INFO to gather info about tcp sockets

v5:
 - hash unconnected sockets to run BUG_ON(already-dumped) logic
 - no default value for sk->wqlen, use zero from xzalloc
 - drop bogus xfree on error

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-07-01 14:42:42 +04:00
Pavel Emelyanov
60bd133e53 sk: Do not lookup a socket twice
The socket_desc is being looked up in dump_unix/dump_inet. In
the dump_socket this desc is only required to obtain a family,
which in turn can be done with a getsockopt.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-06-20 19:24:49 +04:00
Cyrill Gorcunov
424a4adb6f sockets, inet: Use general machnism for checkpoint/restore v2
Use fdtype_ops facility to c/r inet sockets.

v2:
 - Use BUG_ON if socket is attempted to be dumped
   several times

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-05-30 12:56:04 +04:00
Cyrill Gorcunov
c26b68dce8 sockets, unix: Use general machnism for checkpoint/restore v2
Use fdtype_ops facility to c/r unix sockets.

v2
 - BUG_ON added in dump_one_unix_fd if socket
   is already dumped since we never should dump
   same socket several times
 - The order of restore remains as it was before,
   the lookup is done via socket inode numbers

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-05-30 12:54:31 +04:00
Stanislav Kinsbursky
41195598cf parasite: remove excessive header deps from parasite.h and friends
The task is not complete - this is just a part of what have to be done. I.e.
looks like a lot of excessive deps can be fixed.

Signed-off-by: Stanislav Kinsbursky <skinsbursky@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-05-30 12:50:18 +04:00
Andrey Vagin
066ec066a0 crtools: remove unused variables (v3)
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-05-18 19:01:21 +04:00
Pavel Emelyanov
33051cd3b3 sockopt: Add basic options dump/restore
Only snd and rcv bufs and timeouts. Just as an example, others will be adder
sequentially.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-05-10 14:29:57 +04:00
Pavel Emelyanov
7f82ae1133 sockets: Prepare for dumping/restoring/showing socket options
Those sitting on the SOL_SOCKET level are common to different
socket families and will be handled in a generic code.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-05-10 14:29:57 +04:00
Pavel Emelyanov
051b0a1f02 tcp: Prepare sk-inet for dumping and restoring tcp connections
First of all -- to make crtools dump/restore established tcp sockets
you have to specify the --tcp-established options. By doing so you
inform crtools that

a) you know, that after dump there will be a netfilter rules blocking
   the dumped connections

b) you guarantee, that before restore this netfilter block is still
   there

What else this patch does is simple -- collects establised sockets and
calls the dump/restore tcp function (now empty) where appropriate.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-28 17:59:21 +04:00
Pavel Emelyanov
52cb8d43b9 sk: Move unix socket code to separate file
Funny, but after this git thinks, that I've renamed the sockets.c
file into sk-unix.c one and fixed it a little bit %)

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-26 15:30:39 +04:00
Pavel Emelyanov
709bbc7f41 sk: Opencode sk_hash_lookup fns
For simpler unix socket code move.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-26 15:30:36 +04:00
Pavel Emelyanov
be6630bf27 sk: Opencode sk_hash_link
For simpler unix socket code move.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-26 15:30:35 +04:00
Pavel Emelyanov
518361dcaa sk: Move inet socket code to separate file
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-26 15:30:31 +04:00
Pavel Emelyanov
8cd64c5ae7 unix: Cleanup ext socket check
Rename the fn and fix indentation.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-26 15:30:30 +04:00
Pavel Emelyanov
fbcb43bd4b unix: Fix external socket dumping
Collect all unix sockets in a list while dumping to check
whether we've missed something early (at the restore time
it can be already late for roll-back).

Plus, fix the checks for external stream sockets.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-26 15:30:28 +04:00
Pavel Emelyanov
3b0a8e7c81 file: Factor out fowners and flags restore
This is common, that opened fd fix its fowner and flags. Make
a cuntion for this. Those that obtain fd with open() don't need
to restore flags though.

A thought -- do we need yet another abstraction between fdinfo and
type-d files?

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-26 15:30:26 +04:00
Pavel Emelyanov
1f94837afb sk: Sanitize socket's fowner and flags restore
The conn job misses fowner restoratio. Other places are ok, but toss
the code for easier next patching.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-26 15:30:25 +04:00
Konstantin Khlebnikov
bef7092834 Replace printf format "0x%x" with "%#x"
printf() has standard flag for adding "0x" prefix before hexadecimal integer.

MOD='[-+]\?[0-9]*.\?[0-9]*[lL]*'
git grep -l "0x%${MOD}x" | xargs -n1 sed -e "s/0x%\(${MOD}\)x/%#\1x/g" -i

Signed-off-by:    Konstantin Khlebnikov <khlebnikov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-24 15:20:24 +04:00
Cyrill Gorcunov
f737cb441f sockets: Move packet queue handling into sk-queue.h
Easier to read.

[ xemul: There's a silent change in how sk buffer is read in -- before
  the patch there was a static buffer for data, now this thing is
  xrealloc-ed ]

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-23 14:23:40 +04:00
Cyrill Gorcunov
94657b6be1 sockets: Add support for IPv6 sockets
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-23 14:10:44 +04:00
Cyrill Gorcunov
cd29ec489b sockets: Use socket family in show_inetsk
Needed for IPv6.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-23 14:07:58 +04:00
Cyrill Gorcunov
702ab17e16 sockets: Show uncollected socket ino in hex
To be in same form as collected sockets.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-23 14:07:28 +04:00
Cyrill Gorcunov
9634153dfc sockets: Align output in collected unix/inet sockets debug printing
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-23 14:06:55 +04:00
Cyrill Gorcunov
84cc188b24 sockets: Use socket family for inet_ntop
Will need it for IPv6

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-23 14:06:11 +04:00
Cyrill Gorcunov
19c1de828b sockets: Restore unconnected dgram sockets v7
In case if dgram socket peer is not connected back
we can try to resolve peer by name.

For security reason this happens only if '-x' option
is passed at checkpoint and restore time.

In particular this is needed for programs which do
use dgram socket to send messages to /dev/log.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-19 12:04:58 +04:00
Pavel Emelyanov
0e57ce29be files: Put fdinfo entry on fdinfo_list_entry
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-18 16:03:14 +04:00
Pavel Emelyanov
04800b6ed1 files: Rename fdinfo_list_entry's list to desc_list
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-18 15:46:04 +04:00
Kinsbursky Stanislav
231db3f80d output: add "0x" to hex prints manually
Signed-off-by: Stanislav Kinsbursky <skinsbursky@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-16 12:34:01 +04:00
Kinsbursky Stanislav
35eedb5f1f output: add "0x" to hex prints using sed
Command below was executed several times:

sed 's/\(pr_.*[^%,x,X]\)\(\%[0-9,l,L]*x\)/\10x\2/g' -i *.c

Signed-off-by: Stanislav Kinsbursky <skinsbursky@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-16 12:33:35 +04:00
Cyrill Gorcunov
62094fa851 sockets: Drop one-line alignment block
Make sense in multiline cases only.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-16 10:03:03 +04:00
Cyrill Gorcunov
6b391522df sockets: Print sockets ino and peer with %x format
Some ino/peers are printed with %d, some with %x,
get rid of it and print all in %x.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-13 18:01:16 +04:00
Pavel Emelyanov
09d9598074 sock: Add udp-lite sockets support
This is trivial. Just copy-n-paste pieces from the udp dumping
and restoring code. The zdtm test is also a compy of the _udp
test with respecitve changes.

Reuired for httpd, this one uses udplite sockets.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-13 10:42:30 +04:00
Cyrill Gorcunov
b9104ebc97 sockets: Fix potential NULL dereference
In case if unix socket was not found don't call for container_of.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-13 00:03:35 +04:00
Pavel Emelyanov
0e51036d16 show: Move extern print_data declaration from sockets.c to header
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-12 15:33:09 +04:00
Pavel Emelyanov
c96b201700 sockets: Mark open_unix_sk static
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2012-04-12 15:32:16 +04:00