[CRIU] [PATCH] crit: Encode back pretty IP addresses

Pavel Emelyanov xemul at parallels.com
Fri Dec 4 07:06:29 PST 2015


Currently decoded with --pretty image cannot be encoded back if there's
an IP address inside. "Just decoded" can.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 pycriu/images/pb2dict.py | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/pycriu/images/pb2dict.py b/pycriu/images/pb2dict.py
index 4e717f1..7252d7a 100644
--- a/pycriu/images/pb2dict.py
+++ b/pycriu/images/pb2dict.py
@@ -192,6 +192,20 @@ def dict2pb(d, pb):
 		value = d[field.name]
 		if field.label == FD.LABEL_REPEATED:
 			pb_val = getattr(pb, field.name, None)
+			if isinstance(value[0], unicode) and _marked_as_ip(field):
+				val = ipaddr.IPAddress(value[0])
+				if val.version == 4:
+					pb_val.append(socket.htonl(int(val)))
+				elif val.version == 6:
+					ival = int(val)
+					pb_val.append(socket.htonl((ival >> (32 * 3)) & 0xFFFFFFFF))
+					pb_val.append(socket.htonl((ival >> (32 * 2)) & 0xFFFFFFFF))
+					pb_val.append(socket.htonl((ival >> (32 * 1)) & 0xFFFFFFFF))
+					pb_val.append(socket.htonl((ival >> (32 * 0)) & 0xFFFFFFFF))
+				else:
+					raise Exception("Unknown IP address version %d" % val.version)
+				continue
+
 			for v in value:
 				if field.type == FD.TYPE_MESSAGE:
 					dict2pb(v, pb_val.add())
-- 
1.9.3



More information about the CRIU mailing list