Commit Graph

45 Commits

Author SHA1 Message Date
Thomas Haller
4c79b605bc platform: implement nmp_object_is_visible() based on nmp_object_is_alive()
An object should only be visible if it is also alive.
Hence, refactor nmp_object_is_visible() to be reject
object that fail nmp_object_is_alive().
2016-01-16 13:43:23 +01:00
Thomas Haller
ad1d74d142 platform: add index for links by ifname
Downsides:

  - Add some additional overhead to manage the index

  - The NMPCacheId struct grows to 16 bytes, affecting
    hashing performance for all object types.

Still do it, based on the assumption that it doesn't matter
for a low number of interfaces. But the O(1) access time matters
when having lots of interfaces.
2015-12-17 18:42:53 +01:00
Beniamino Galvani
3871056019 platform: add macvtap link creation support 2015-12-09 14:30:08 +01:00
Beniamino Galvani
32f6e1ef2e platform: add IP6TNL links support 2015-12-01 17:39:41 +01:00
Beniamino Galvani
30e648f981 platform: add IPIP links support 2015-12-01 17:39:41 +01:00
Beniamino Galvani
0754280b9f platform: add SIT links support 2015-12-01 17:39:41 +01:00
Thomas Haller
832539a511 platform: emit signals by signal-id instead of string
We potentially emit a lot of signals. Don't look up the
signal by name because that adds quite some additional
overhead, like peeking for a GQuark.

Instead pass the numeric signal-id directly.
2015-11-27 15:17:44 +01:00
Thomas Haller
9587867349 logging: swap names of logging macros _LOGT() and _LOGt()
Previsously, _LOGT() could be disabled at compile time. Thus it
was different then the other macros _LOGD(), _LOGI(), etc.

OTOH, _LOGt() was the macro that always was compiled in.

Swap the name of the macros. Now the upper-case macros are always
enabled, while the lower-case macro _LOGt() is enabled depending
on compile configuration.
2015-11-06 14:16:41 +01:00
Thomas Haller
a5ea141956 platform/vlan: add support for ingress/egress-qos-mappings and changing flags
Previously, we could only set the ingress-qos-mappings/egress-qos-mappings.
Now also cache the mappings and expose them from the platform cache.

Also, support changing the vlan flags not only when creating the vlan
interface.
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
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
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
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
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
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
fd7d57be03 platform/trivial: rename "auto_nmp_obj" macro to "nm_auto_nmpobj"
A define in a header file should have an "NM" prefix. Also,
let's have "nm_auto_" as a prefix for cleanup macros beside
libgsystem's "gs_".
2015-10-20 14:43:54 +02:00
Thomas Haller
6a5dab5c7c platform: fix id-equality for IPv6 address to ignore prefix-length
For IPv6 addresses, the prefix-length is not part of the id.
E.g. you cannot add two IPv6 addresses that only differ by
plen.
2015-10-14 12:52:07 +02:00
Thomas Haller
8968e15eb7 platform: properly handle peer-address for IPv4 addresses
Kernel allows to add the same IPv4 address that only differs by
peer-address (IFL_ADDRESS):

    $ ip link add dummy type dummy
    $ ip address add 1.1.1.1 peer 1.1.1.3/24 dev dummy
    $ ip address add 1.1.1.1 peer 1.1.1.4/24 dev dummy
    RTNETLINK answers: File exists
    $ ip address add 1.1.1.1 peer 1.1.2.3/24 dev dummy
    $ ip address show dev dummy
    2: dummy@NONE: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default
        link/ether 52:58:a7:1e:e8:93 brd ff:ff:ff:ff:ff:ff
        inet 1.1.1.1 peer 1.1.1.3/24 scope global dummy
           valid_lft forever preferred_lft forever
        inet 1.1.1.1 peer 1.1.2.3/24 scope global dummy
           valid_lft forever preferred_lft forever

We must also consider peer-address, otherwise platform will treat
two different addresses as one and the same.

https://bugzilla.gnome.org/show_bug.cgi?id=756356
2015-10-14 12:52:07 +02:00
Thomas Haller
1ef431ab38 platform: use nm_g_hash_table_add() compat wrapper in _nmp_cache_update_add() 2015-10-10 19:41:42 +02:00
Thomas Haller
6395c829bb build: make NM_MORE_ASSERTS define numeric for different levels of more-asserts
Allows to enable more-asserts more granularly.

Unfortunately, the old check was "${enable_more_asserts} == "yes", thus
we cannot extend "--enable-more-assert=level" because that would mean
that the same build script cannot set the option on both old and new
NetworkManager.
Thus, add a new option --with-more-asserts=level. If you put the
following in your build script, it will work as expected whether
you build a new or an old version of NetworkManager.
  ./configure --enable-more-asserts --with-more-asserts=5
2015-10-05 15:25:54 +02:00
Thomas Haller
ad7cdfc766 logging: declare default logging macros in "nm-logging.h"
The logging macros _LOGD(), etc. are specific to each
file as they format the message according to their context.

Still, they were cumbersome to define and their implementation
was repeated over and over (slightly different at times).

Move the declaration of these macros to "nm-logging.h".
The source file now only needs to define _NMLOG(), and either
_NMLOG_ENABLED() or _NMLOG_DOMAIN.

This reduces code duplication and encourages a common implementation
and usage of these macros.
2015-08-20 11:15:13 +02:00
Thomas Haller
19c3ea948a all: make use of new header file "nm-default.h" 2015-08-05 15:32:40 +02:00
Thomas Haller
42664e8752 platform: expose routes with "proto kernel" too
Also expose routes with "proto kernel". But add a flag
to nm_platform_ipx_route_get_all() to hide them by default.
2015-07-01 16:00:21 +02:00
Thomas Haller
85bf9ded2e platform/trivial: rename enum value NM_IP_CONFIG_SOURCE_RTPROT_KERNEL
This source type was platform internal up to now. Next we will expose it.
2015-07-01 16:00:21 +02:00
Thomas Haller
7bd3b0b304 platform/trivial: fix name of enum value OBJECT_TYPE_UNKNOWN
Fixes: 518cf76de7
2015-06-24 16:09:57 +02:00
Lubomir Rintel
14bfd55361 platform: g_hash_table_add doesn't return a value before 2.40 2015-06-22 17:04:22 +02:00
Lubomir Rintel
a1868dcfc3 platform: fix build on 32-bit systems
The decimal literals are signed by default and these are too large to fit in a
signed 32-bit int.
2015-06-22 13:13:05 +02:00
Thomas Haller
ae824f582b nmp-object: check for non-empty ifname in _vt_cmd_obj_is_visible_link() 2015-06-20 18:50:27 +02:00
Thomas Haller
518cf76de7 platform/trivial: rename ObjectType to NMPObjectType
After doing all the refactoring, rename the ObjectType enum to NMPObjectType.
I didn't do this earlier to avoid problems with rebasing. But since I will
backport the platform changes to nm-1-0, this is the right time to get
the name right.
2015-06-19 16:24:20 +02:00
Thomas Haller
8f9dac01ac platform: fix lookup addresses and routes for any ifindex and refactor NMPCacheIdType
After refactoring platform, nm_platform_ipx_route_get_all() and
nm_platform_ipx_address_get_all() was broken for calling with a
non-posititive ifindex (which has the meaning: ignore ifindex).

While fixing that, also refactor the NMPCacheIdType so that it matches
better the supported id-types.

Fixes: 470bcefa5f
2015-06-18 17:19:00 +02:00
Thomas Haller
1b2b988ea9 platform: no longer expose udi field in NMPlatformLink
The @udi field is not a static string, so any user of a NMPlatformLink
instance must make sure not to use the field beyond the lifetime of the
NMPlatformLink instance.
As we pass on the platform link instance during platform changed events,
this is hard to ensure for the subscriber of the signal -- because a
call back into platform could invalidate/modify the object.

Just not expose this field as part of the link instance. The few callers
who actually needed it should instead call nm_platform_get_uid(). With
that, the lifetime of the returned 'const char *' pointer is clearly
defined.
2015-06-17 11:41:43 +02:00
Thomas Haller
53f98e7f9e platform: implement NMPObject and NMPCache
NMPObject is a simple "object" implemenation around NMPlatformObject.
They are ref-counted and have a class-pointer. Several basic functions
like equality, hash, to-string are implemented.

NMPCache is can be used to store the NMPObject. Objects are indexed
via their primary id, but there is also multi-lookup via NMCacheId
and NMMultiIndex.

Part of the implementation is inside "nm-linux-platform.c",
because it depends on utility functions from there.
2015-06-17 11:23:51 +02:00
Thomas Haller
359fe9f8c1 platform: add nmp-object.h file 2015-06-17 11:23:51 +02:00