Support specifying attributes in dump requests.
Change-Id: Ibe49c87397518eeb35132bc485093cc8d3aae39e
diff --git a/net/test/iproute.py b/net/test/iproute.py
index e0f2837..4f77528 100644
--- a/net/test/iproute.py
+++ b/net/test/iproute.py
@@ -422,11 +422,11 @@
# Create a struct rtmsg specifying the table and the given match attributes.
family = self._AddressFamily(version)
rtmsg = RTMsg((family, 0, 0, 0, 0, 0, 0, 0, 0))
- return self._Dump(RTM_GETRULE, rtmsg, RTMsg)
+ return self._Dump(RTM_GETRULE, rtmsg, RTMsg, "")
def DumpLinks(self):
ifinfomsg = IfinfoMsg((0, 0, 0, 0, 0, 0))
- return self._Dump(RTM_GETLINK, ifinfomsg, IfinfoMsg)
+ return self._Dump(RTM_GETLINK, ifinfomsg, IfinfoMsg, "")
def _Address(self, version, command, addr, prefixlen, flags, scope, ifindex):
"""Adds or deletes an IP address."""
@@ -530,7 +530,7 @@
def DumpNeighbours(self, version):
ndmsg = NdMsg((self._AddressFamily(version), 0, 0, 0, 0))
- return self._Dump(RTM_GETNEIGH, ndmsg, NdMsg)
+ return self._Dump(RTM_GETNEIGH, ndmsg, NdMsg, "")
def ParseNeighbourMessage(self, msg):
msg, _ = self._ParseNLMsg(msg, NdMsg)
diff --git a/net/test/netlink.py b/net/test/netlink.py
index f245901..479d3a4 100644
--- a/net/test/netlink.py
+++ b/net/test/netlink.py
@@ -217,15 +217,26 @@
self._ExpectDone()
return out
- def _Dump(self, command, msg, msgtype):
- """Sends a dump request and returns a list of decoded messages."""
+ def _Dump(self, command, msg, msgtype, attrs):
+ """Sends a dump request and returns a list of decoded messages.
+
+ Args:
+ command: An integer, the command to run (e.g., RTM_NEWADDR).
+ msg: A string, the raw bytes of the request (e.g., a packed RTMsg).
+ msgtype: A cstruct.Struct, the data type to parse the dump results as.
+ attrs: A string, the raw bytes of any request attributes to include.
+
+ Returns:
+ A list of (msg, attrs) tuples where msg is of type msgtype and attrs is
+ a dict of attributes.
+ """
# Create a netlink dump request containing the msg.
flags = NLM_F_DUMP | NLM_F_REQUEST
- length = len(NLMsgHdr) + len(msg)
+ length = len(NLMsgHdr) + len(msg) + len(attrs)
nlmsghdr = NLMsgHdr((length, command, flags, self.seq, self.pid))
# Send the request.
- self._Send(nlmsghdr.Pack() + msg.Pack())
+ self._Send(nlmsghdr.Pack() + msg.Pack() + attrs)
# 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 a9de345..7a703ae 100755
--- a/net/test/sock_diag.py
+++ b/net/test/sock_diag.py
@@ -132,7 +132,7 @@
return InetDiagSockId(("\x00" * len(InetDiagSockId)))
def Dump(self, diag_req):
- out = self._Dump(SOCK_DIAG_BY_FAMILY, diag_req, InetDiagMsg)
+ out = self._Dump(SOCK_DIAG_BY_FAMILY, diag_req, InetDiagMsg, "")
return out
def DumpSockets(self, family, protocol, ext, states, sock_id):
diff --git a/net/test/sock_diag_test.py b/net/test/sock_diag_test.py
index eb5eb63..b89f7e9 100755
--- a/net/test/sock_diag_test.py
+++ b/net/test/sock_diag_test.py
@@ -192,7 +192,7 @@
sock_id = self.sock_diag._EmptyInetDiagSockId()
req = sock_diag.InetDiagReqV2((AF_INET6, IPPROTO_TCP, 0, 0xffffffff,
sock_id))
- self.sock_diag._Dump(code, req, sock_diag.InetDiagMsg)
+ self.sock_diag._Dump(code, req, sock_diag.InetDiagMsg, "")
op = sock_diag.SOCK_DIAG_BY_FAMILY
DiagDump(op) # No errors? Good.