Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/checkpoint-restore/criu.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Emelyanov <xemul@parallels.com>2015-01-28 17:16:00 +0300
committerPavel Emelyanov <xemul@parallels.com>2015-01-29 18:47:30 +0300
commit9ebb3738b2d097b2fdff52c85f67491784e401bc (patch)
tree785e6934e2f0ede4be7e8e62b5e4e1cb87c85735
parent0d2aeb35812f95dabff11c035ec7dfc89077baa6 (diff)
crit: Print IP addresses in pretty mode
There are two places where we store IP addresses (both IPv4 and IPv6). Mark them with custom option and print them in compressed form for --pretty output. Signed-off-by: Pavel Emelyanov <xemul@parallels.com> Acked-by: Ruslan Kuprieiev <kupruser@gmail.com>
-rw-r--r--protobuf/opts.proto1
-rw-r--r--protobuf/sk-inet.proto4
-rw-r--r--pycriu/images/pb2dict.py22
3 files changed, 23 insertions, 4 deletions
diff --git a/protobuf/opts.proto b/protobuf/opts.proto
index a04bfada8..ddfffd55e 100644
--- a/protobuf/opts.proto
+++ b/protobuf/opts.proto
@@ -2,6 +2,7 @@ import "google/protobuf/descriptor.proto";
message CRIU_Opts {
optional bool hex = 1; // Idicate that CRIT should treat this field as hex.
+ optional bool ipadd = 2; // The field is IPv4/v6 address
}
extend google.protobuf.FieldOptions {
diff --git a/protobuf/sk-inet.proto b/protobuf/sk-inet.proto
index fa4d16e57..bd8f0742a 100644
--- a/protobuf/sk-inet.proto
+++ b/protobuf/sk-inet.proto
@@ -22,8 +22,8 @@ message inet_sk_entry {
required uint32 flags = 9 [(criu).hex = true];
required uint32 backlog = 10;
- repeated uint32 src_addr = 11;
- repeated uint32 dst_addr = 12;
+ repeated uint32 src_addr = 11 [(criu).ipadd = true];
+ repeated uint32 dst_addr = 12 [(criu).ipadd = true];
required fown_entry fown = 13;
required sk_opts_entry opts = 14;
diff --git a/pycriu/images/pb2dict.py b/pycriu/images/pb2dict.py
index 954c8fb83..8d06dc94c 100644
--- a/pycriu/images/pb2dict.py
+++ b/pycriu/images/pb2dict.py
@@ -1,5 +1,7 @@
from google.protobuf.descriptor import FieldDescriptor as FD
import opts_pb2
+import ipaddr
+import socket
# pb2dict and dict2pb are methods to convert pb to/from dict.
# Inspired by:
@@ -43,6 +45,9 @@ _basic_cast = {
def _marked_as_hex(field):
return field.GetOptions().Extensions[opts_pb2.criu].hex
+def _marked_as_ip(field):
+ return field.GetOptions().Extensions[opts_pb2.criu].ipadd
+
def _pb2dict_cast(field, value, pretty = False, is_hex = False):
if not is_hex:
is_hex = _marked_as_hex(field)
@@ -73,8 +78,21 @@ def pb2dict(pb, pretty = False, is_hex = False):
for field, value in pb.ListFields():
if field.label == FD.LABEL_REPEATED:
d_val = []
- for v in value:
- d_val.append(_pb2dict_cast(field, v, pretty, is_hex))
+ if pretty and _marked_as_ip(field):
+ if len(value) == 1:
+ v = socket.ntohl(value[0])
+ addr = ipaddr.IPv4Address(v)
+ else:
+ v = 0 + (socket.ntohl(value[0]) << (32 * 3)) + \
+ (socket.ntohl(value[1]) << (32 * 2)) + \
+ (socket.ntohl(value[2]) << (32 * 1)) + \
+ (socket.ntohl(value[3]))
+ addr = ipaddr.IPv6Address(v)
+
+ d_val.append(addr.compressed)
+ else:
+ for v in value:
+ d_val.append(_pb2dict_cast(field, v, pretty, is_hex))
else:
d_val = _pb2dict_cast(field, value, pretty, is_hex)