summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenzo Colitti <lorenzo@google.com>2015-05-13 10:57:43 +0900
committerLorenzo Colitti <lorenzo@google.com>2015-05-13 17:43:43 +0900
commitf4483a3fe9caa9d849232803ec28b2a34aacbb7a (patch)
treef45943965a876ea161be5ba6927be9f9e7d638cb
parent3524cd080b113ee3735ff1d49022c71d990a1568 (diff)
downloadextras-f4483a3fe9caa9d849232803ec28b2a34aacbb7a.tar.gz
Improve netlink message debugging.
1. Add a method to convert a message to a string. The code didn't have anything that did just that; all string conversions were part of the debugging code. This method can be used by external callers that just want to parse raw messages obtained by other means (e.g., strace). 2. Teach the code about FRA_FWMASK. 3. Fix a bug in the parsing error handling due to attempting to catch the wrong exception. Also fix a couple of lint errors. Change-Id: I1915ab984934810ddbef7040c78d58e8657bb028
-rw-r--r--tests/net_test/iproute.py30
1 files changed, 20 insertions, 10 deletions
diff --git a/tests/net_test/iproute.py b/tests/net_test/iproute.py
index df1c1210..cf1f282a 100644
--- a/tests/net_test/iproute.py
+++ b/tests/net_test/iproute.py
@@ -160,6 +160,7 @@ FRA_PRIORITY = 6
FRA_FWMARK = 10
FRA_SUPPRESS_PREFIXLEN = 14
FRA_TABLE = 15
+FRA_FWMASK = 16
FRA_OIFNAME = 17
FRA_UID_START = 18
FRA_UID_END = 19
@@ -185,6 +186,7 @@ IFLA_NUM_TX_QUEUES = 31
IFLA_NUM_RX_QUEUES = 32
IFLA_CARRIER = 33
+
def CommandVerb(command):
return ["NEW", "DEL", "GET", "SET"][command % 4]
@@ -196,7 +198,7 @@ def CommandSubject(command):
def CommandName(command):
try:
return "RTM_%s%s" % (CommandVerb(command), CommandSubject(command))
- except KeyError:
+ except IndexError:
return "RTM_%d" % command
@@ -293,7 +295,7 @@ class IPRoute(object):
# Don't know what this is. Leave it as an integer.
name = nla_type
- if name in ["FRA_PRIORITY", "FRA_FWMARK", "FRA_TABLE",
+ if name in ["FRA_PRIORITY", "FRA_FWMARK", "FRA_TABLE", "FRA_FWMASK",
"FRA_UID_START", "FRA_UID_END",
"RTA_OIF", "RTA_PRIORITY", "RTA_TABLE", "RTA_MARK",
"IFLA_MTU", "IFLA_TXQLEN", "IFLA_GROUP", "IFLA_EXT_MASK",
@@ -518,12 +520,10 @@ class IPRoute(object):
self._ExpectDone()
return out
- def MaybeDebugCommand(self, command, data):
- subject = CommandSubject(command)
- if "ALL" not in self.NL_DEBUG and subject not in self.NL_DEBUG:
- return
- name = CommandName(command)
+ def CommandToString(self, command, data):
try:
+ name = CommandName(command)
+ subject = CommandSubject(command)
struct_type = {
"ADDR": IfAddrMsg,
"LINK": IfinfoMsg,
@@ -532,14 +532,24 @@ class IPRoute(object):
"RULE": RTMsg,
}[subject]
parsed = self._ParseNLMsg(data, struct_type)
- print "%s %s" % (name, str(parsed))
- except KeyError:
+ return "%s %s" % (name, str(parsed))
+ except IndexError:
raise ValueError("Don't know how to print command type %s" % name)
+ def MaybeDebugCommand(self, command, data):
+ subject = CommandSubject(command)
+ if "ALL" not in self.NL_DEBUG and subject not in self.NL_DEBUG:
+ return
+ print self.CommandToString(command, data)
+
def MaybeDebugMessage(self, message):
hdr = NLMsgHdr(message)
self.MaybeDebugCommand(hdr.type, message)
+ def PrintMessage(self, message):
+ hdr = NLMsgHdr(message)
+ print self.CommandToString(hdr.type, message)
+
def _Dump(self, command, msg, msgtype):
"""Sends a dump request and returns a list of decoded messages."""
# Create a netlink dump request containing the msg.
@@ -672,7 +682,7 @@ class IPRoute(object):
self._Neighbour(version, False, addr, lladdr, dev, 0)
def DumpNeighbours(self, version):
- ndmsg = NdMsg((0, 0, 0, 0, 0))
+ ndmsg = NdMsg((self._AddressFamily(version), 0, 0, 0, 0))
return self._Dump(RTM_GETNEIGH, ndmsg, NdMsg)