ss: create a function to print info about netlink sockets

It will be reused for printing info about netlink sockets, when
socket diag is used for retrieving information.

Cc: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Andrey Vagin <avagin@openvz.org>
This commit is contained in:
Andrey Vagin 2013-06-05 12:41:59 +04:00 committed by Stephen Hemminger
parent d8402b9641
commit 129709aea1
1 changed files with 72 additions and 58 deletions

View File

@ -2672,27 +2672,11 @@ static int packet_show(struct filter *f)
return 0; return 0;
} }
static int netlink_show(struct filter *f) static void netlink_show_one(struct filter *f,
int prot, int pid, unsigned groups,
int rq, int wq,
unsigned long long sk, unsigned long long cb)
{ {
FILE *fp;
char buf[256];
int prot, pid;
unsigned groups;
int rq, wq, rc;
unsigned long long sk, cb;
if (!(f->states & (1<<SS_CLOSE)))
return 0;
if ((fp = net_netlink_open()) == NULL)
return -1;
fgets(buf, sizeof(buf)-1, fp);
while (fgets(buf, sizeof(buf)-1, fp)) {
sscanf(buf, "%llx %d %d %x %d %d %llx %d",
&sk,
&prot, &pid, &groups, &rq, &wq, &cb, &rc);
if (f->f) { if (f->f) {
struct tcpstat tst; struct tcpstat tst;
tst.local.family = AF_NETLINK; tst.local.family = AF_NETLINK;
@ -2702,7 +2686,7 @@ static int netlink_show(struct filter *f)
tst.local.data[0] = prot; tst.local.data[0] = prot;
tst.remote.data[0] = 0; tst.remote.data[0] = 0;
if (run_ssfilter(f->f, &tst) == 0) if (run_ssfilter(f->f, &tst) == 0)
continue; return;
} }
if (netid_width) if (netid_width)
@ -2751,6 +2735,36 @@ static int netlink_show(struct filter *f)
printf(" sk=%llx cb=%llx groups=0x%08x", sk, cb, groups); printf(" sk=%llx cb=%llx groups=0x%08x", sk, cb, groups);
} }
printf("\n"); printf("\n");
return;
}
static int netlink_show(struct filter *f)
{
FILE *fp;
char buf[256];
int prot, pid;
unsigned groups;
int rq, wq, rc;
unsigned long long sk, cb;
if (!(f->states & (1<<SS_CLOSE)))
return 0;
if (!getenv("PROC_NET_NETLINK") && !getenv("PROC_ROOT") &&
netlink_show_netlink(f, NULL) == 0)
return 0;
if ((fp = net_netlink_open()) == NULL)
return -1;
fgets(buf, sizeof(buf)-1, fp);
while (fgets(buf, sizeof(buf)-1, fp)) {
sscanf(buf, "%llx %d %d %x %d %d %llx %d",
&sk,
&prot, &pid, &groups, &rq, &wq, &cb, &rc);
netlink_show_one(f, prot, pid, groups, rq, wq, sk, cb);
} }
return 0; return 0;