OSDN Git Service

Make RTA_METRICS parsing work properly.
authorLorenzo Colitti <lorenzo@google.com>
Thu, 14 Jan 2016 07:15:24 +0000 (16:15 +0900)
committerLorenzo Colitti <lorenzo@google.com>
Thu, 14 Jan 2016 11:20:10 +0000 (20:20 +0900)
commitae33e4e34ae1863e9ab7e3416299c06dc526b902
tree000e0c7ca163c9fe98a0881ee4b2be888d4b8363
parent701a67bfa2a36dee90383ac23484bf2a762081fe
Make RTA_METRICS parsing work properly.

Currently, parsing RTA_METRICS attributes only works if the
attributes only contain a single RTAX_MTU attribute, but not
other attributes.

This is because _ParseAttributes usually operates on netlink data
structures, and thus takes a data structure (such as a RTMsg
instance) as input. In the special case of the RTA_METRICS
attribute, _Decode calls _ParseAttributes on a blob of nested
attributes and not a data structure (which is correct), but
incorrectly passes in a msg of "RTMsg", which is a data structure
class, not an instance.

The result is that _Decode throws an exception when reading
msg.family. This was not never spotted before because _Decode
had a special hack to parse RTAX_MTU and we never happened to
parse a RTA_METRICS that contained anything else.

Fix this by passing None into _ParseAttributes when we know that
there is no message, and fetching msg.family in _ParseAttributes
only when we know that the message is in fact a rtmsg. This
allows us to merge the hack that parses RTAX_MTU with the code
that parses the other arguments. Also, support RTAX_HOPLIMIT,
which is the attribute which caused us to discover this problem.

Change-Id: I1c396ab29850e6cff95d2e7327ef6d702a8046f7
tests/net_test/iproute.py