Commit Graph

42 Commits

Author SHA1 Message Date
Thomas Haller
ce2d1f062b platform: don't use static temporary cache_id
This only saves some typing at a few places. In general, avoid
static variables, so drop it in favor of a stack-allocated
cache_id.
2016-12-01 10:57:35 +01:00
Thomas Haller
3ceaef90fe core: remove unnecessary includes to netlink/route library
We no longer use libnl-route-3 library in NetworkManager. Remove the
unnecessary includes.
2016-10-07 21:37:17 +02:00
Lubomir Rintel
5f849faa15 platform: fix the typedef-redefinition warnings
The configure script disabled the warning by accident.
2016-05-18 20:53:05 +02:00
Thomas Haller
aaa28d4d40 platform: add nm_linux_platform_lookup()
Give a direct access to the cache to lookup values there. This is only
useful for testing.
2016-04-28 12:53:21 +02:00
Thomas Haller
f8b2cadfc1 platform: ensure cache consistency for routes by workaround missing kernel event
Consider:

  unshare -n
  ip link add d0 type dummy
  ip link add d1 type dummy
  ip link set d0 up
  ip link set d1 up
  ip addr add 192.168.100.5/24 dev d0
  ip addr add 192.168.101.5/24 dev d1

  ip route add 192.168.200.0/24 via 192.168.100.1
  ip monitor &
  ip route change 192.168.200.0/24 via 192.168.101.1
  #prints 192.168.200.0/24 via 192.168.101.1 dev d1
  ip route show
  #192.168.100.0/24 dev d0  proto kernel  scope link  src 192.168.100.5
  #192.168.101.0/24 dev d1  proto kernel  scope link  src 192.168.101.5
  #192.168.200.0/24 via 192.168.101.1 dev d1

Note that `ip route change` replaced the exising route. "Replaced" in this
case means: the previous route on device "d0" got removed and a new route
on "d1" was added. However, kernel only sent one RTM_NEWROUTE event, no
RTM_DELROUTE that notifies about this change.

We need to workaround that by re-synching the routes when we receive a
RTM_NEWROUTE notification.
2016-04-11 11:32:48 +02:00
Thomas Haller
44768f0311 platform: change @plen field of NMPlatformIPxAddress to type guint8
On netlink layer, this field is uint8_t/uchar.

A larger (signed) plen makes no sense. Adjust the signatures
to have only guint8.
2016-04-11 11:26:36 +02:00
Thomas Haller
14ee5dd2f8 platform: change @plen field of NMPlatformIPxRoute to type guint8
On netlink layer, this field is uint8_t/uchar.

A larger (signed) plen makes no sense. Adjust the signatures
to have only guint8.
2016-04-11 11:26:36 +02:00
Thomas Haller
b1e3deaf2f nmp-object: refactor handling of NMPCacheId to consider only relevant part of union
NMPCacheId is a union with fields for all known NMPCacheIdTypes.
Up to now, we always cloned the entire union, computed the hash
over all (possibly unset) fields and used memcmp() unanimously.

That was ok, because NMPCacheId was 16 bytes in total and cache-id
types that consumed less bytes didn't have a large overhead.

Next, we will add a new cache id type which increases the size of
NMPCacheId to 24 bytes. So, while possibly only a fraction of the
instances is that large, they would all have to pay that price.

Change that to consider and clone only those parts of the id
that are actually used.
2016-04-11 11:26:36 +02:00
Thomas Haller
fe78ae0b6a nmp-object: refactor initializing NMPCacheId
As we get more NMPCacheIdType values, it's better to have for
each type a pre-declared list of supported types, instead of
iterating over all types and letting _nmp_object_init_cache_id()
figure out that the cache-id-type is unsupported on that object.
2016-04-11 11:26:36 +02:00
Thomas Haller
1a1c5fb717 platform: don't create udev client if udev isn't used
Inside container, where we don't use udev we don't receive
any events from udev client. Thus the client only returns
devices when iterating it initially, but no events for newly
added devices that appear later.

Thus, inside containers we don't want to create a udev client
at all.
2016-03-07 11:58:01 +01:00
Thomas Haller
2c2d9d2e4c build: cleanup default includes
- "gsystem-local-alloc.h" and <gio/gio.h> are already included via
  "nm-default.h". No need to include them separately.

- include "nm-macros-internal.h" via "nm-default.h" and drop all
  explict includes.

- in the modified files, ensure that we always include "config.h"
  and "nm-default.h" first. As second, include the header file
  for the current source file (if applicable). Then follow external
  includes and finally internal nm includes.

- include nm headers inside source code files with quotes

- internal header files don't need to include default headers.
  They can savely assume that "nm-default.h" is already included
  and with it glib, nm-glib.h, nm-macros-internal.h, etc.
2016-02-12 15:36:01 +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
28c41c1f8c platform: use explict "bool" type instead of "guint8" in NMPObjects 2015-11-20 12:01:46 +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
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
3ae7692d31 nmp-object: remove unused nl_type field from NMPClass 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
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
7bd3b0b304 platform/trivial: fix name of enum value OBJECT_TYPE_UNKNOWN
Fixes: 518cf76de7
2015-06-24 16:09:57 +02:00
Thomas Haller
b6061b3cd5 platform: declare NMPObjectType in nm-types.h
We want to use it outside of NMPlatform, but users should not be required
to include "nmp-object.h".
2015-06-24 16:09:57 +02:00
Thomas Haller
4010d779a7 platform: generate gtype for NMPObjectType enum 2015-06-24 16:09:56 +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
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
d1e7554a90 platform: move ObjectType to nmp-object.h 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