[CRIU] [PATCH v3 12/12] protobuf: use pretty output for inet sockets
Kinsbursky Stanislav
skinsbursky at openvz.org
Mon Aug 13 10:00:01 EDT 2012
From: Stanislav Kinsbursky <skinsbursky at openvz.org>
New custom specificators:
'F': output as socket address family
'T': output as socket address type
'P': output as socket address protocol
'S': output as socket address state
'A': output as socket address
Note: added cookie to field descriptor. For sockets it's used to store family
type. BTW, for each message in will be initially set to zero. Hope, we won't
have a message with two sockets with different family in future.
Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>
---
protobuf.c | 22 +++++++++++++++++++++-
sk-inet.c | 40 +---------------------------------------
2 files changed, 22 insertions(+), 40 deletions(-)
-------------- next part --------------
diff --git a/protobuf.c b/protobuf.c
index 0461a8a..8a4d4ad 100644
--- a/protobuf.c
+++ b/protobuf.c
@@ -3,6 +3,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
+#include <arpa/inet.h>
#include <google/protobuf-c/protobuf-c.h>
@@ -12,6 +13,7 @@
#include "log.h"
#include "util.h"
#include "string.h"
+#include "sockets.h"
#include "protobuf.h"
#include "protobuf/inventory.pb-c.h"
@@ -128,6 +130,8 @@ void cr_pb_init(void)
*/
#define PB_PKOBJ_LOCAL_SIZE 1024
+#define INET_ADDR_LEN 40
+
struct pb_pr_field_s {
void *data;
int number;
@@ -281,7 +285,23 @@ static size_t pb_show_prepare_field_context(const ProtobufCFieldDescriptor *fd,
static int pb_show_pretty(pb_pr_field_t *field)
{
- pr_msg(field->fmt, *(long *)field->data);
+ switch (field->fmt[0]) {
+ case '%':
+ pr_msg(field->fmt, *(long *)field->data);
+ break;
+ case 'A':
+ {
+ char addr[INET_ADDR_LEN] = "<unknown>";
+ int family = (field->count == 1) ? AF_INET : AF_INET6;
+
+ if (inet_ntop(family, (void *)field->data, addr,
+ INET_ADDR_LEN) == NULL)
+ pr_msg("failed to translate");
+ else
+ pr_msg("%s", addr);
+ }
+ return 1;
+ }
return 0;
}
diff --git a/sk-inet.c b/sk-inet.c
index d5266ad..cb478d5 100644
--- a/sk-inet.c
+++ b/sk-inet.c
@@ -482,43 +482,5 @@ int inet_connect(int sk, struct inet_sk_info *ii)
void show_inetsk(int fd, struct cr_options *o)
{
- InetSkEntry *ie;
- int ret = 0;
-
- pr_img_head(CR_FD_INETSK);
-
- while (1) {
- char src_addr[INET_ADDR_LEN] = "<unknown>";
- char dst_addr[INET_ADDR_LEN] = "<unknown>";
-
- ret = pb_read_one_eof(fd, &ie, PB_INETSK);
- if (ret <= 0)
- goto out;
-
- if (inet_ntop(ie->family, (void *)ie->src_addr, src_addr,
- INET_ADDR_LEN) == NULL) {
- pr_perror("Failed to translate src address");
- }
-
- if (ie->state == TCP_ESTABLISHED) {
- if (inet_ntop(ie->family, (void *)ie->dst_addr, dst_addr,
- INET_ADDR_LEN) == NULL) {
- pr_perror("Failed to translate dst address");
- }
- }
-
- pr_msg("id %#x ino %#x family %s type %s proto %s state %s %s:%d <-> %s:%d flags 0x%2x\n",
- ie->id, ie->ino, skfamily2s(ie->family), sktype2s(ie->type), skproto2s(ie->proto),
- skstate2s(ie->state), src_addr, ie->src_port, dst_addr, ie->dst_port, ie->flags);
- pr_msg("\t"), show_fown_cont(ie->fown), pr_msg("\n");
- show_socket_opts(ie->opts);
-
- inet_sk_entry__free_unpacked(ie, NULL);
- }
-
-out:
- if (ret)
- pr_info("\n");
- pr_img_tail(CR_FD_INETSK);
+ pb_show_plain_pretty(fd, PB_INETSK, "1:%#x 2:%#x 3:F 4:T 5:P 6:S 7:%d 8:%d 9:%2x 11:A 12:A");
}
-
More information about the CRIU
mailing list