[CRIU] [PATCH v2 13/13] protobuf: use pretty output for inet sockets
Kinsbursky Stanislav
skinsbursky at openvz.org
Mon Aug 6 12:12:02 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 | 34 +++++++++++++++++++++++++++++++++-
sk-inet.c | 40 +---------------------------------------
2 files changed, 34 insertions(+), 40 deletions(-)
-------------- next part --------------
diff --git a/protobuf.c b/protobuf.c
index 647786f..a5c692c 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>
@@ -11,6 +12,7 @@
#include "log.h"
#include "util.h"
#include "string.h"
+#include "sockets.h"
#include "protobuf.h"
@@ -21,11 +23,14 @@
*/
#define PB_PKOBJ_LOCAL_SIZE 1024
+#define INET_ADDR_LEN 40
+
struct pb_pr_field_s {
void *data;
int number;
int depth;
char fmt[32];
+ u32 cookie;
};
typedef struct pb_pr_field_s pb_pr_field_t;
@@ -156,7 +161,34 @@ static size_t pb_show_prepare_field_context(const ProtobufCFieldDescriptor *fd,
static void 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 'F':
+ pr_msg("%s", skfamily2s(*(long *)field->data));
+ field->cookie = *(long *)field->data;
+ break;
+ case 'T':
+ pr_msg("%s", sktype2s(*(long *)field->data));
+ break;
+ case 'P':
+ pr_msg("%s", skproto2s(*(long *)field->data));
+ break;
+ case 'S':
+ pr_msg("%s", skstate2s(*(long *)field->data));
+ break;
+ case 'A':
+ {
+ char addr[INET_ADDR_LEN] = "<unknown>";
+ if (inet_ntop(field->cookie, (void *)field->data, addr,
+ INET_ADDR_LEN) == NULL)
+ pr_msg("failed to translate");
+ else
+ pr_msg("%s", addr);
+ }
+ break;
+ }
}
static int pb_field_show_pretty(pb_pr_ctl_t *ctl)
diff --git a/sk-inet.c b/sk-inet.c
index 9cc97d2..8765c5c 100644
--- a/sk-inet.c
+++ b/sk-inet.c
@@ -473,43 +473,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_eof(fd, &ie, inet_sk_entry);
- 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, inet_sk_entry, "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