linux - netlink scatter send causes error response from kernel (NLMSG_ERROR) -


I am writing a program that uses the NetLink protocol to gather the Net data. I am not getting too far because the kernel responds with an error which I believe is a valid packet. I used the stase to compare my program's iotop behavior, which works correctly is.

Relative bit of stress from iotop:

 socket (PF_net, SOCK_RAW, 16) = 3 settop (3, SOL_SOCKET, SO_SNDBUF, [65536], 4) = 0 setocopet (3 , SOL_SOCKET, SO_RCVBUF, [65536], 4) = 0 bind (3, {sa_family = AF_NETLINK, pid = 0, groups = 00000000}, 12) = 0 Vokkam (3, {sa_family = AF_NETLINK, pid = -4286, groups = 00000000}, [12]) = 0 Send (3, "\ x24 \ x00 \ x00 \ x00 \ x10 \ x00 \ x01 \ x00 \ x01 \ x00 \ x00 \ x00 \ x42 \ xef \ xff \ xff \ x03 \ X00 \ x00 \ x00 \ x0e \ x00 \ x02 \ x00 \ x54 \ x41 \ x53 \ x4b \ x53 \ x54 \ x41 \ x54 \ x53 \ x00 \ x00 \ x00 ", 36, 0, NULL, 0) = 36 records From (3, "\ x70 \ x00 \ x00 \ x00 \ x10 \ x00 \ x00 \ x00 \ x01 \ x00 \ x00 \ x00 \ x42 \ xEF \ xff \ xff \ x01 \ x02 \ x00 \ x00 \ x0e \ x00 \ X02 \ x00 \ x54 \ x41 \ x53 \ x4b \ x53 \ x54 \ x41 \ x54 \ x53 \ x00 \ x00 \ x00 \ x06 \ x00 \ Ks0l \ Ks00 \ Ksl7 \ Ks00 \ Ks00 \ Ks00 \ Ks08 \ Ks00 \ Ks03 \ Ks00 \ Ks0l \ Ks00 \ Ks00 \ Ks00 \ Ks08 \ Ks00 \ Ks04 \ Ks00 \ Ks00 \ Ks00 \ Ks00 \ Ks00 \ Ks08 \ Ks00 \ Ks05 \ Ks00 \ Ks04 \ Ks00 \ Ks00 \ Ks00 \ Ks2c \ Ks00 \ Ks06 \ Ks00 \ Ksl4 \ Ks00 \ Ks0l \ Ks00 \ Ks08 \ Ks00 \ Ks0l \ Ks00 \ Ks0l \ Ks00 \ Ks00 \ Ks00 \ Ks08 \ Ks00 \ Ks02 \ Ks00 \ x0b \ x 00 \ x00 \ x00 \ x14 \ x00 \ x02 \ x00 \ x08 \ x00 \ x01 \ x00 \ x04 \ x00 \ x00 \ x00 \ x08 \ x00 \ x02 \ x00 \ x0a \ x00 \ x00 \ x00 " , 16384, 0 

 bind (8, {0} = 1, {Sa_family = AF_NETLINK, pid = 1 9156, group = 00000000}, 12) = 0 Setokopet (8, SOL_SOCKET, SO_SNDBUF, [65536 ], 4) = 0 setocopet (8, SOL_SOCKET, SO_RCVBUF, [65536], 4) = 0 Sendmsg (8, {msg_name (0) = null, msg_iov (5) = [{"xx \ x00 \ x00 \ x00 \ X10 \ x00 \ x01 \ x00 \ x00 \ x00 \ x00 \ x00 \ xd4 \ x4a \ x00 \ x00 ", 16}, {" \ x03 \ x00 \ x00 \ x00 ", 4}, {" \ x0e \ x00 \ X02 \ x00 ", 4}, {" \ x54 \ x41 \ x53 \ x4b \ x53 \ x54 \ x41 \ x54 \ X53 \ x00 ", 10}, {" \ x00 \ x00 ", 2}], msg_controllen = 0, msg_flags = 0}, MSG_NOSIGNAL) = 36 recvmsg (8, {msg_name (0) = null, msg_iov (1) = [{{Ks38 \ Ks00 \ Ks00 \ Ks00 \ Ks02 \ Ks00 \ Ks00 \ Ks00 \ Ks00 \ Ks00 \ Ks00 \ Ks00 \ Ksd4 \ Ks4a \ Ks00 \ Ks00 ", 16}], Msg_kantrollen = 0, Msg_flags = Msg_trnk} 0 ) = 16 

If I reformat them, then they appear in the form of a hex dump like this: (Note that these are from different runs, so Peed Val UE isolate But the rest of the refrared Strauss output is the same.) 24000000, sent from Iotop 10000100 01000000 42 EFFF 03000000 0e000200 5441534 B53544154 53000000 Received by iotop 70000000 10000000 01000000 42efffff 01020000 0e000200 5441534b 53544154 53000000 06000100 17000000 08000300 01000000 08000400 00000000 08000500 04000000 2c000600 14000100 08000100 01000000 08000200 0 B 000000 14000200 08000100 04000000 sent 08000200 0a000000 program 24000000 10000100 00000000 d44a0000 03000000 0e000200 5441534b 53544154 by 53 million program 38000000 02000000 00000000 d44a0000 < / Pre>

It seems to me that there are two differences.

  1. The iotop seems to be using a negative value for PID. I tried to make changes so that my program sent a negative number for PID. It did not matter.

  2. I use a scatter / collective approach: it is less worthless on memory (which may be constrained in my mind in the targeted PC). However, I suspect that there are some (if not all) netlink components that only support sending and receiving a buffer at each request. Do anyone know whether the network link scatter / collects or if all the communications need to be done in a big buffer at a time? One thing to keep in mind is that you have a specific capability to use NetLink (a CAP_NET_ADMIN,

This Lots Me Trouble Me

I finally did this job by ditching all IoO code and pasting the example code from Linux distribution. I suspect that the netlink does not play well with sendmsg.


Comments