netfilter: correct error in construction of NAT tuple
link cache: remove AF_UNSPEC check in rtnl_get_link and rtnl_get_link_by_name

This patch reverts back the AF_UNSPEC check introduced by AF_BRIDGE
changes at http://lists.infradead.org/pipermail/libnl/2012-November/000796.html

After the addition of AF_BRIDGE support, link cache can now contain objects of
type AF_BRIDGE. To make sure existing api's did not return AF_BRIDGE objects
and surprise existing callers, I introduced the check for AF_UNSPEC.

But from what Andy Wang reported, rtnl_link_get_by_name returns the first
link object with matching ifindex and that could have not only been AF_UNSPEC
but also of family AF_INET6. And his app always got an AF_INET6 object prior
to the patch that introduced the AF_UNSPEC check.

I could just add AF_INET6 family check along with AF_UNSPEC in the apis and that
should work well.

But thinking about it some more, removing the AF_UNSPEC change seems to be safer at
this point. That way this api will retain its semantics and return the first object
with matching ifindex. It could be of any supported family. The user will know if the
cache contains bridge objects, because they are available only with the cache flag
NL_CACHE_AF_ITER. Besides, if new users want to search for a specific object,
nl_cache_find is a better option.

Reported-by: Andy Wang <Andy.Wang@watchguard.com>
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
Merge branch 'nattuple' of https://github.com/rmfought/libnl
Fix mask calculation in nl_addr_cmp_prefix()

Signed-off-by: Malte Langermann <mlangermann@radiodata.biz>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
cache: Make NL_ACT_* and nl_cache_ops_(get|put)() available

Move NL_ACT_* definition and the functions nl_cache_ops_get()
and nl_cache_ops_put() into the public facing API. They can
be considered stable.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
neigh: Remove check for AF_UNSPEC in rtnl_neigh_get()

This check was introduces to not accidently return AF_BRIDGE objects
to unaware API users as they do differ in structure. However, such
objects are only available if explicitely requests using the
NL_CACHE_AF_ITER flag or by using arg1 == AF_BRIDGE for the cache.

Therefore remove this check and allow rtnl_neigh_get() to be used to
fetch any neighbor object of a cache.

Reported-by: Maxime Bizon <mbizon@freebox.fr>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
can: Include "linux/can/netlink.h" in the distribution

Needed to compile if local kernel headers are outdated.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
can: Fix nested message creation in can_put_attrs()

Signed-off-by: Benedikt Spranger <b.spranger@linutronix.de>
Signed-off-by: Holger Dengler <dengler@linutronix.de>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
link: Fix af_ops leak on ENOMEM

Signed-off-by: Thomas Graf <tgraf@suug.ch>
link: Keep reference to af_ops during lifetime of link object

Signed-off-by: Thomas Graf <tgraf@suug.ch>
link: Modify link policy on the stack

Signed-off-by: Thomas Graf <tgraf@suug.ch>
link: Hold af_ops reference for each AF_SPEC block during lifetime of link object

Signed-off-by: Thomas Graf <tgraf@suug.ch>
link: Free and realloc af specific data upon rtnl_link_set_family()

Signed-off-by: Thomas Graf <tgraf@suug.ch>
attr: Provide nla_is_nested() function

Signed-off-by: Thomas Graf <tgraf@suug.ch>
bridge: Support the new bridging attributes

This provides support for the new bridging attributes provided
in IFLA_PROTINFO while maintaining backwards compatibility
with older kernels.

A set of new API functions are exported to access the bridging
information. rtnl_link_bridge_has_ext_info() can be used to
check whether a bridge object has been constructed based on
the newly available attributes or the old message format.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
bridge: Provide rtnl_link_bridge_alloc()

Signed-off-by: Thomas Graf <tgraf@suug.ch>
netlink: Forward declare frequent libnl types to ease inclusion deps

Signed-off-by: Thomas Graf <tgraf@suug.ch>
vlan: Provide rtnl_link_vlan_alloc()

Signed-off-by: Thomas Graf <tgraf@suug.ch>
bond: Provide rtnl_link_bond_alloc()

Signed-off-by: Thomas Graf <tgraf@suug.ch>
link: move af_data_compare to the end

In the current code if rtnl_link_af_data_compare returns value > 0
we mark PROTINFO attribute in the diff mask and return without
comparing flags.

This patch makes af_data to be the last thing we compare.

Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
Reviewed-by: Nolan Leake <nolan@cumulusnetworks.com>
Reviewed-by: Shrijeet Mukherjee <shm@cumulusnetworks.com>
Reviewed-by: Wilson Kok <wkok@cumulusnetworks.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>