mpls: don't dump RTA_VIA attribute if not specified
authorRobert Shearman <rshearma@brocade.com>
Thu, 10 Dec 2015 19:30:49 +0000 (19:30 +0000)
committerDavid S. Miller <davem@davemloft.net>
Sat, 12 Dec 2015 05:43:44 +0000 (00:43 -0500)
commit72dcac96c7f8320caf80dfaa559331174060a1ce
tree6ebf1a477b7f842038fb96ade44df2a500d10653
parenta3e948e83a302c63f196512e253067ded6bbc832
mpls: don't dump RTA_VIA attribute if not specified

The problem seen is that when adding a route with a nexthop with no
via address specified, iproute2 generates bogus output:

  # ip -f mpls route add 100 dev lo
  # ip -f mpls route list
  100 via inet 0.0.8.0 dev lo

The reason for this is that the kernel generates an RTA_VIA attribute
with the family set to AF_INET, but the via address data having zero
length. The cause of family being AF_INET is that on route insert
cfg->rc_via_table is left set to 0, which just happens to be
NEIGH_ARP_TABLE which is then translated into AF_INET.

iproute2 doesn't validate the length prior to printing and so prints
garbage. Although it could be fixed to do the validation, I would
argue that AF_INET addresses should always be exactly 4 bytes so the
kernel is really giving userspace bogus data.

Therefore, avoid generating the RTA_VIA attribute when dumping the
route if the via address wasn't specified on add/modify. This is
indicated by NEIGH_ARP_TABLE and a zero via address length - if the
user specified a via address the address length would have been
validated such that it was 4 bytes. Although this is a change in
behaviour that is visible to userspace, I believe that what was
generated before was invalid and as such userspace wouldn't be
expecting it.

Signed-off-by: Robert Shearman <rshearma@brocade.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/mpls/af_mpls.c