mirror of
https://github.com/checkpoint-restore/criu
synced 2025-09-01 14:55:39 +00:00
protobuf: use pretty output for inet sockets
v4: 1) Only address specificator ('A') left New custom specificators: 'A': output as socket address Signed-off-by: Stanislav Kinsbursky <skinsbursky@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
committed by
Pavel Emelyanov
parent
694576723c
commit
96b62808ff
22
protobuf.c
22
protobuf.c
@@ -3,6 +3,7 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
#include <google/protobuf-c/protobuf-c.h>
|
#include <google/protobuf-c/protobuf-c.h>
|
||||||
|
|
||||||
@@ -12,6 +13,7 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
#include "sockets.h"
|
||||||
|
|
||||||
#include "protobuf.h"
|
#include "protobuf.h"
|
||||||
#include "protobuf/inventory.pb-c.h"
|
#include "protobuf/inventory.pb-c.h"
|
||||||
@@ -128,6 +130,8 @@ void cr_pb_init(void)
|
|||||||
*/
|
*/
|
||||||
#define PB_PKOBJ_LOCAL_SIZE 1024
|
#define PB_PKOBJ_LOCAL_SIZE 1024
|
||||||
|
|
||||||
|
#define INET_ADDR_LEN 40
|
||||||
|
|
||||||
struct pb_pr_field_s {
|
struct pb_pr_field_s {
|
||||||
void *data;
|
void *data;
|
||||||
int number;
|
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)
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
40
sk-inet.c
40
sk-inet.c
@@ -496,43 +496,5 @@ int inet_connect(int sk, struct inet_sk_info *ii)
|
|||||||
|
|
||||||
void show_inetsk(int fd, struct cr_options *o)
|
void show_inetsk(int fd, struct cr_options *o)
|
||||||
{
|
{
|
||||||
InetSkEntry *ie;
|
pb_show_plain_pretty(fd, PB_INETSK, "1:%#x 2:%#x 3:%d 4:%d 5:%d 6:%d 7:%d 8:%d 9:%2x 11:A 12:A");
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user