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
1 file changed
tree: 6a8ade52576bb3a06d6a7f27ef0e013940689af2
  1. net/