Commit graph

13336 commits

Author SHA1 Message Date
Thomas Haller 17aa8c0fc8 libnm: internally expose NMVlanQosMapping struct in "nm-core-internal.h" 2015-11-02 13:57:02 +01:00
Thomas Haller d61875c960 libnm: add internal header file "nm-core-types-internal.h"
This shall contain type definitions, with similar use
to "nm-core-internal.h".

However, it should contain a minimal set, so that we can include this
header in other headers under "src/", without including the whole
"nm-core-internal.h" in headers.
2015-11-02 13:57:02 +01:00
Thomas Haller 4b1e1f8aab platform: promise that the link lnk is an immutable NMPObject and expose it
Expose internal lnk object and promise in the API that the object will
not be modified (which allows the user to ref it).
2015-11-02 13:57:02 +01:00
Thomas Haller f8fa4a0970 nmp-object: add virtual function for implementing nmp_object_to_string() 2015-11-02 13:57:02 +01:00
Thomas Haller b4cf41f9e7 build: no longer link against libnl-route-3 library 2015-11-02 13:57:02 +01:00
Thomas Haller 9ecdba316c platform: create netlink messages directly without libnl-route-3
Instead of using libnl-route-3 library to serialize netlink messages,
construct the netlink messages ourselves.

This has several advantages:

- Creating the netlink message ourself is actually more straight
  forward then having an intermediate layer between NM and the kernel.
  Now it is immediately clear, how a platform request translates to
  a netlink/kernel request.
  You can look at the kernel sources how a certain netlink attribute
  behaves, and then it's immediately clear how to set that (and vice
  versa).

- Older libnl versions might have bugs or missing features for which
  we needed to workaround (often by offering a reduced/broken/untested
  functionality). Now we can get rid or workaround like _nl_has_capability(),
  check_support_libnl_extended_ifa_flags(), HAVE_LIBNL_INET6_TOKEN.
  Another example is a libnl bug when setting vlan ingress map which
  isn't even yet fixed in libnl upstream.

- We no longer need libnl-route-3 at all and can drop that runtime
  requirement, saving some 400k.
  Constructing the messages ourselves also gives better performance
  because we don't have to create the intermediate libnl object.

- In the future we will add more link-type support which is easier
  to support by basing directly on the plain kernel/netlink API,
  instead of requiring also libnl3 to expose this functionality.
  E.g. adding macvtap support: we already parsed macvtap properties
  ourselves because of missing libnl support. To *add* macvtap
  support, we also would have to do it ourself (or extend libnl).
2015-11-02 13:57:01 +01:00
Thomas Haller b296325cca platform: reimplement netlink flags/enum to string conversions 2015-11-02 13:57:01 +01:00
Thomas Haller dae0dbd533 utils: add flags2str utility functions 2015-11-02 13:57:01 +01:00
Thomas Haller 9369fac8ca core: add nm_utils_to_string_buffer global buffer
Having a static string buffer for convenience is useful not only
for platform. Define the string buffer in NetworkManagerUtils.h,
so that all to-string functions can reuse *one* buffer.

Of course, this has the potential danger, that different
to-string method might reuse the same buffer. Hence, low-level
library functions are adviced to use their own buffer, because
an upper level might already use the global buffer for another
string.
2015-11-02 13:57:01 +01:00
Thomas Haller 99f9785345 platform/tests: test setting bridge address 2015-11-02 13:57:01 +01:00
Thomas Haller 64b2924051 platform/trivial: rename variable "obj_needle" to "obj_id"
Both names were used for the same thing.
2015-11-02 13:57:01 +01:00
Thomas Haller 6c8aa669a4 platform: properly handle IPv4 peer-addresses
The peer-address (IFA_ADDRESS) can also be all-zero (0.0.0.0).
That is distinct from an usual address without explicit peer-address,
which implicitly has the same peer and local address.

Previously, we treated an all-zero peer_address as having peer and
local address equal. This is especially grave, because the peer is part
of the primary key for an IPv4 address. So we not only get a property of
the address wrong, but we wrongly consider two different addresses as
one and the same.

To properly handle these addresses, we always must explicitly set the peer.
2015-11-02 13:57:01 +01:00
Thomas Haller aa5b89a2ec ip4-config: let the IPv4 device route depend on the peer-address
Usually, the peer-address is the same as the local address.
In case where it is not, it is the peer-address that determines
the IPv4 device-route. So we must use the peer-address.

Also, don't consider device-routes with the first octet of zero,
just like kernel does.

Also, nm_ip4_config_get_subnet_for_host() is effectively the same
as nm_ip4_config_destination_is_direct(). So drop it.
2015-11-02 13:57:01 +01:00
Thomas Haller 59eb21f4a9 platform/tests: add test setting vlan ingress/egress mappings 2015-11-02 13:57:01 +01:00
Thomas Haller fe246d1659 platform/trivial: reorder declaration of structures in "nm-platform.h"
Just group the NMPlatformLnk* types together and sort them by name.
2015-11-02 13:57:01 +01:00
Thomas Haller 9a3cdecdec platform/trivial: rename nm_platform_infiniband_get_info() to get_properties()
We already have nm_platform_tun_get_properties(). Rename the function
as they both sidestep the platform cache to lookup some link-specific
properties.
2015-11-02 13:57:01 +01:00
Thomas Haller 7cdbc393a0 platform: refactor nm_platform_veth_get_properties()
For recent kernels, the peer-ifindex of veths is reported as
parent (IFA_LINK). Prefer that over the ethtool lookup.

For one, this avoids the extra ethtool call which has the
downside of sidestepping the platform cache. Also, looking
up the peer-ifindex in ethtool does not report whether the
peer lifes in another netns (NM_PLATFORM_LINK_OTHER_NETNS).

Only use ethtool as fallback for older kernels.
2015-11-02 13:57:01 +01:00
Thomas Haller dd1f4d8947 platform/tests: add test cases for detecting lnk data 2015-11-02 13:57:01 +01:00
Thomas Haller d13d17f84a platform/tests: remove "dump" test-program
The program ran over the platform links and printed them.
Our to-string methods of platform objects are already supposed
to print all fields. So this only duplicates code to print a link.

If you want to see what links were picked up by platfrom run:

  NMTST_DEBUG=log-level=TRACE ./src/platform/tests/monitor

or just

  ./src/platform/tests/monitor

Yes, this has less the iproute2 feeling, but it gives you a more
native access to the platform objects -- which is what you want
for debugging platform.
2015-11-01 17:28:09 +01:00
Thomas Haller ca8e40e1dc platform/tests: use "nm-test-utils.h" in "monitor.c"
This gives us a way to externally configure the logging level like:

  NMTST_DEBUG=log-level=TRACE ./src/platform/tests/monitor
2015-11-01 17:28:09 +01:00
Thomas Haller d55f19e4c4 platform: always complete link-type from cache
Previously, while detecting the link type we would lookup the
@kind in case it was missing.

Now, go one step further, and also prefer the link-type from the
cache.
2015-11-01 17:28:09 +01:00
Thomas Haller 90ff0c466d platform: implement infiniband properties as lnk data
But keep the fallback to reading sysfs to support pre-3.7 kernels.
2015-11-01 17:28:09 +01:00
Thomas Haller 07550f8dae platform: implement macvlan properties as lnk data 2015-11-01 17:28:09 +01:00
Thomas Haller 3d3762cee3 platform: implement vxlan properties as lnk data 2015-11-01 17:28:09 +01:00
Thomas Haller 4ab3d71d70 platform: implement gre properties as lnk data 2015-11-01 17:28:09 +01:00
Thomas Haller db5d00d396 platform: implement vlan properties as lnk data 2015-11-01 17:28:08 +01:00
Thomas Haller 0506d54d55 platform: add link_data member to NMPObjectLink
https://bugzilla.gnome.org/show_bug.cgi?id=754570
2015-11-01 17:28:08 +01:00
Thomas Haller 4a20956400 platform: parse netlink messages ourselves without libnl-route-3
Constructing the libnl3 object only to parse the message
is wasteful. It involves several memory allocations, thread
synchronization and parsing fields that we don't care about.

But moreover, older libnl version might not support all the
fields we are interested in, hence we have workarounds like
_nl_link_parse_info_data(). Certain features might not fully
work unless libnl supports it too (although kernel would).

As we already parse the data ourselves sometimes, just go
all they way and don't construct the intermediate libnl object.

This will allow us to drop the _nl_link_parse_info_data() workarounds
in next commits. That is important, because _nl_link_parse_info_data()
sidesteps our platform cache and is not in sync with the cache (not to
mention the extra work to explicitly refetch the data on every lookup).

Also, it gets us 60% on the way to no longer needing 'libnl-route-3.so'
at all and eventually drop requiring the library.
2015-11-01 17:28:08 +01:00
Thomas Haller 25751f9c57 platform: add NMIPAddr struct 2015-11-01 17:28:08 +01:00
Thomas Haller f5171089af platform/trivial: move code 2015-11-01 17:28:08 +01:00
Thomas Haller a0229badd8 platform: only convert link-type to string once in nm_platform_link_to_string() 2015-11-01 17:28:08 +01:00
Thomas Haller b931b09601 platform: move nm_platform_tun_get_properties() to NMPlatform base class
This function only accesses sysctl function to retrieve the tun-properties.
sysctl is already defined in the base class and equally inherited by linux
and fake platform. Move the implementation there.
2015-11-01 17:28:08 +01:00
Thomas Haller c91a4617a1 nmp-object: allow missing implementations for certain virtual functions
We will add classes that don't implement all virtual functions.
E.g. a non-hashable class.

Be more resilient and allow for missing implementation.
2015-11-01 17:28:08 +01:00
Thomas Haller 3ae7692d31 nmp-object: remove unused nl_type field from NMPClass 2015-11-01 17:28:08 +01:00
Thomas Haller 0fd3c4e24c nmp-object/trivial: move code 2015-11-01 17:28:08 +01:00
Thomas Haller 250b1293f3 nmp-object: refactor nmp_object_copy() not to call virtual cmd_obj_copy() function for plain data 2015-11-01 17:28:08 +01:00
Thomas Haller c40e9d764d nmp-object: implement nmp_object_equal() based on cmp()
For link objects, nmp_object_cmp() did not consider the private fields and
thus behaved different then nmp_object_equal(). This is wrong.

Implement nmp_object_equal() based on compare.
2015-11-01 17:28:08 +01:00
Thomas Haller a2d59f5f10 platform: add buffer argument to platform to-string functions
Arguably, it is more convenient to use the static buffer as
it saves typing.

But having such a low-level function use a static buffer also
limits the way how to use it. As it was, you could not avoid
using the static buffer.

E.g. you cannot do:

  char buf[100];

  _LOGD ("nmp-object: %s; platform-link: %s",
         nmp_object_to_string (nmpobj, buf, sizeof(buf)),
         nm_platform_link_to_string (link));

This will fail for non-obvious reasons because both
to-string functions end up using the same static buffer.

Also change the to-string implementations to accept NULL
as valid and return it as "(null)".

https://bugzilla.gnome.org/show_bug.cgi?id=756427
2015-11-01 17:28:08 +01:00
Thomas Haller 7e2710fcd0 build: no longer link against libnl-genl-3 library 2015-11-01 17:28:07 +01:00
Thomas Haller 98c37fed43 wifi: reimplement use of libnl-genl-3 library 2015-11-01 17:28:07 +01:00
Thomas Haller a2e58e6e91 wifi/trivial: fix whitespace and indention in "wifi-utils-nl80211.c" 2015-11-01 17:28:07 +01:00
Thomas Haller 59af27ddb9 dnsmasq/tests: minor refactoring in test 2015-11-01 17:28:07 +01:00
Thomas Haller abd607257b macros: add nm_sprintf_buf() helper macro 2015-11-01 17:28:07 +01:00
Thomas Haller 204fcd33d8 macros: add nm_clear_g_cancellable() utility 2015-11-01 17:28:07 +01:00
Thomas Haller 88a2f1c93b tests: handle no_expect_message also for tests without assert-logging 2015-11-01 17:28:07 +01:00
Thomas Haller d5ef08e01e tests: add nmtst_rand_perm() utility 2015-11-01 17:28:07 +01:00
Thomas Haller 09983442bd tests: add nmtst_assert_ip4_address() and nmtst_assert_ip6_address() utility method 2015-11-01 17:28:07 +01:00
Thomas Haller 59ae981b22 platform: fix reading dst-port and src-port-range for vxlan
This was broken since introducing vxlan support.
2015-11-01 17:28:07 +01:00
Thomas Haller 1a6f4d08ba vpn-connection: fix parsing IPv4 routes
Fixes: 3b145a33b7
2015-11-01 17:23:24 +01:00
Lubomir Rintel 6a5595fc1a merge: branch 'lr/tunnelled-route'
https://bugzilla.gnome.org/show_bug.cgi?id=757287
2015-11-01 11:31:23 +01:00