1

I want to understand the netlink messages exchanged with the kernel when I run the following commmand to create a pair of veth devices (I am using Ubuntu 16.04):

$ sudo ip link add veth1 type veth peer name veth2

I tried to follow the tutorial at this link. I used strace and got the following trace related to netlink:

$ sudo strace -e trace=network -x -s 16384 -f -o out ip link add veth1 type veth peer name veth2
$ cat out 
socket(PF_NETLINK, SOCK_RAW|SOCK_CLOEXEC, NETLINK_ROUTE) = 3
setsockopt(3, SOL_SOCKET, SO_SNDBUF, [32768], 4) = 0
setsockopt(3, SOL_SOCKET, SO_RCVBUF, [1048576], 4) = 0
bind(3, {sa_family=AF_NETLINK, pid=0, groups=00000000}, 12) = 0
getsockname(3, {sa_family=AF_NETLINK, pid=6001, groups=00000000}, [12]) = 0
send(3, "\x20\x00\x00\x00\x10\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 32, 0) = 32
recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"\x34\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x71\x17\x00\x00\xed\xff\xff\xff\x20\x00\x00\x00\x10\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16384}], msg_controllen=0, msg_flags=0}, 0) = 52
socket(PF_LOCAL, SOCK_DGRAM|SOCK_CLOEXEC, 0) = 4
sendmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"\x5c\x00\x00\x00\x10\x00\x05\x06\x38\xa2\x16\x5d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0a\x00\x03\x00\x76\x65\x74\x68\x31\x00\x00\x00\x30\x00\x12\x00\x08\x00\x01\x00\x76\x65\x74\x68\x24\x00\x02\x00\x20\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0a\x00\x03\x00\x76\x65\x74\x68\x32\x00\x00\x00", 92}], msg_controllen=0, msg_flags=0}, 0) = 92
recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"\x24\x00\x00\x00\x02\x00\x00\x00\x38\xa2\x16\x5d\x71\x17\x00\x00\x00\x00\x00\x00\x5c\x00\x00\x00\x10\x00\x05\x06\x38\xa2\x16\x5d\x00\x00\x00\x00", 32768}], msg_controllen=0, msg_flags=0}, 0) = 36

For example, I try decoding the messages related to sending.

// my test did not have any line breaks
$ echo'\x20\x00\x00\x00\x10\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00' >> message
$ python tests/decoder/decoder.py pyroute2.netlink.rtnl.rtmsg.rtmsg message
20:00:00:00:10:00:05:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
:00:00:00:00:00:00:00:00:00:00
{'attrs': [('RTA_UNSPEC', None)],
 'dst_len': 0,
 'family': 0,
 'flags': 0,
 'header': {'flags': 5,
            'length': 32,
            'pid': 0,
            'sequence_number': 0,
            'type': 16},
 'proto': 0,
 'scope': 0,
 'src_len': 0,
 'table': 0,
 'tos': 0,
 'type': 0}
........................................ 

$ echo '\x5c\x00\x00\x00\x10\x00\x05\x06\x38\xa2\x16\x5d\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00\x00\x0a\x00\x03\x00\x76\x65\x74\x68\x31\x00\x00\x00\x30\x00
\x12\x00\x08\x00\x01\x00\x76\x65\x74\x68\x24\x00\x02\x00\x20\x00
\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00\x00\x0a\x00\x03\x00\x76\x65\x74\x68\x32\x00\x00\x00' >> 
message

 $ python tests/decoder/decoder.py pyroute2.netlink.rtnl.rtmsg.rtmsg message
 5c:00:00:00:10:00:05:06:38:a2:16:5d:00:00:00:00:00:00:00:00:00:00:
 00:00:00:00:00:00:00:00:00:00:0a:00:03:00:76:65:74:68:31:00:00:00:
 30:00:12:00:08:00:01:00:76:65:74:68:24:00:02:00:20:00:01:00:00:00:
 00:00:00:00:00:00:00:00:00:00:00:00:00:00:0a:00:03:00:76:65:74:68:
 32:00:00:00
 {'attrs': [('RTA_UNSPEC', None),
           ('RTA_IIF', 1752458614),
           ('RTA_VIA', {'addr': 
 '01:00:76:65:74:68:24:00:02:00:20:00:01:00:00:00:00:00:00:00:00:
  00:00:00:00:00:00:00:00:00:0a:00:03:00:76:65:74:68:32:00:00:00', 
 'family': 8})],
 'dst_len': 0,
 'family': 0,
 'flags': 0,
 'header': {'flags': 1541,
        'length': 92,
        'pid': 0,
        'sequence_number': 1561764408,
        'type': 16},
 'proto': 0,
 'scope': 0,
 'src_len': 0,
 'table': 0,
 'tos': 0,
 'type': 0}

I was expecting the decoding to indicate something about veth1 or veth2, but the decoding does not seem to correlate with veth devices. I did repeat the decoding in a related tutorial and could get the same result as in the tutorial. I want to ask if the decoding above is correct, and if so, how can it be interpreted ?

0
1

Note for readers: in pyroute2 decoder.py is available only in git.

The correct module should be ifinfmsg, which will handle interface-related messages (rather than route-related messages):

$ python tests/decoder/decoder.py pyroute2.netlink.rtnl.ifinfmsg.ifinfmsg message
5c:00:00:00:10:00:05:06:38:a2:16:5d:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:0a:00:03:00:76:65:74:68:31:00:00:00:30:00:12:00:08:00:01:00:76:65:74:68:24:00:02:00:20:00:01:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:0a:00:03:00:76:65:74:68:32:00:00:00
{'__align': (),
 'attrs': [('IFLA_IFNAME', 'veth1'),
           ('IFLA_LINKINFO', {'attrs': [('IFLA_INFO_KIND', 'veth'), ('IFLA_INFO_DATA', {'attrs': [('VETH_INFO_PEER', {'index': 0, 'family': 0, '__align': (), 'flags': 0, 'ifi_type': 0, 'change': 0, 'attrs': [('IFLA_IFNAME', 'veth2')]})]})]})],
 'change': 0,
 'family': 0,
 'flags': 0,
 'header': {'flags': 1541,
            'length': 92,
            'pid': 0,
            'sequence_number': 1561764408,
            'type': 16},
 'ifi_type': 0,
 'index': 0}
........................................
1
  • Thank you for taking the time to answer my question. – Jake Jun 29 '19 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.