Improve sock_diag debugging code.
- Unbreak GetConstantName on modules that contain constants whose
names start with "INET_DIAG_BC".
- Honour NL_DEBUG when sending dump requests.
- Decode sock_diag messages differently depending on whether
they are requests or responses.
- Print sock_diag bytecode hex-encoded instead of raw.
(cherry picked from commit c5673f350e1e38b101a4cceb221a7beddc89ba78)
Change-Id: I3cc20ab635d1ff4f137aa0f9ff0ff88b1a37ce72
diff --git a/net/test/netlink.py b/net/test/netlink.py
index 2b8f744..261350b 100644
--- a/net/test/netlink.py
+++ b/net/test/netlink.py
@@ -80,7 +80,7 @@
thismodule = sys.modules[module]
for name in dir(thismodule):
if name.startswith("INET_DIAG_BC"):
- break
+ continue
if (name.startswith(prefix) and
not name.startswith(prefix + "F_") and
name.isupper() and getattr(thismodule, name) == value):
@@ -237,7 +237,9 @@
nlmsghdr = NLMsgHdr((length, command, flags, self.seq, self.pid))
# Send the request.
- self._Send(nlmsghdr.Pack() + msg.Pack() + attrs)
+ request = nlmsghdr.Pack() + msg.Pack() + attrs
+ self.MaybeDebugCommand(command, request)
+ self._Send(request)
# Keep reading netlink messages until we get a NLMSG_DONE.
out = []
diff --git a/net/test/sock_diag.py b/net/test/sock_diag.py
index b4d9cf6..8a84ca2 100755
--- a/net/test/sock_diag.py
+++ b/net/test/sock_diag.py
@@ -106,7 +106,11 @@
def _Decode(self, command, msg, nla_type, nla_data):
"""Decodes netlink attributes to Python types."""
if msg.family == AF_INET or msg.family == AF_INET6:
- name = self._GetConstantName(__name__, nla_type, "INET_DIAG")
+ if isinstance(msg, InetDiagReqV2):
+ prefix = "INET_DIAG_REQ"
+ else:
+ prefix = "INET_DIAG"
+ name = self._GetConstantName(__name__, nla_type, prefix)
else:
# Don't know what this is. Leave it as an integer.
name = nla_type
@@ -122,6 +126,8 @@
data = TcpInfo(nla_data)
elif name == "INET_DIAG_SKMEMINFO":
data = SkMeminfo(nla_data)
+ elif name == "INET_DIAG_REQ_BYTECODE":
+ data = nla_data.encode("hex")
else:
data = nla_data