Add the number of struct tcp_info bytes read from Netlink
This patch adds to the SockDiag TcpInfoReader callback the number of
bytes read from Netlink when parsing a struct tcp_info attribute with
attribute id INET_DIAG_INFO.
On different kernels, struct tcp_info will have different fields and
different sizes when serialized. A generic sock_diag struct tcp_info
handler can use the attribute byte size to distinguish between different
fields and safely read data inside struct tcp_info.
Bug: 64147860
Test: tested manually on sailfish with 3.18 kernel,
using $ adb shell dumpsys netd tcp_socket_info
Change-Id: I45da9ed787dc7f0c4873ce1132b5f8094bcffd0a
diff --git a/server/SockDiag.h b/server/SockDiag.h
index 36b699d..a44c144 100644
--- a/server/SockDiag.h
+++ b/server/SockDiag.h
@@ -49,8 +49,11 @@
typedef std::function<bool(uint8_t proto, const inet_diag_msg *)> DestroyFilter;
// Callback function that is called once for every socket in the sockInfo dump.
- typedef std::function<void(Fwmark mark, const struct inet_diag_msg *, const struct tcp_info *)>
- TcpInfoReader;
+ // 'tcp_info_length' is the length in bytes of the INET_DIAG_INFO attribute read from Netlink.
+ // Knowing this length is necessary for handling struct tcp_info serialized from different
+ // kernel versions.
+ typedef std::function<void(Fwmark mark, const struct inet_diag_msg *, const struct tcp_info *,
+ uint32_t tcp_info_length)> TcpInfoReader;
struct DestroyRequest {
nlmsghdr nlh;