Commit Graph

360 Commits

Author SHA1 Message Date
Aleksander Morgado
6c1a6d2d5f platform: avoid storing unknown netlink object types (bgo #742928)
Testing WWAN connections through a Nokia Series 40 phone, addresses of family
AF_PHONET end up triggering an assert() in object_has_ifindex(), just because
object_type_from_nl_object() only handles AF_INET and AF_INET6 address.

In order to avoid this kind of problems, we'll try to make sure that the object
caches kept by NM only store known object types.

https://bugzilla.gnome.org/show_bug.cgi?id=742928

    Connect: ppp0 <--> /dev/ttyACM0
    nm-pppd-plugin-Message: nm-ppp-plugin: (nm_phasechange): status 5 / phase 'establish'
    NetworkManager[27434]: <info>  (ppp0): new Generic device (driver: 'unknown' ifindex: 12)
    NetworkManager[27434]: <info>  (ppp0): exported as /org/freedesktop/NetworkManager/Devices/4
    [Thread 0x7ffff1ecf700 (LWP 27439) exited]
    NetworkManager[27434]: <info>  (ttyACM0): device state change: ip-config -> deactivating (reason 'user-requested') [70 110 39]
    Terminating on signal 15
    nm-pppd-plugin-Message: nm-ppp-plugin: (nm_phasechange): status 10 / phase 'terminate'
    **
    NetworkManager:ERROR:platform/nm-linux-platform.c:1534:object_has_ifindex: code should not be reached

    Program received signal SIGABRT, Aborted.
    0x00007ffff4692a97 in raise () from /usr/lib/libc.so.6
    (gdb) bt
    #0  0x00007ffff4692a97 in raise () from /usr/lib/libc.so.6
    #1  0x00007ffff4693e6a in abort () from /usr/lib/libc.so.6
    #2  0x00007ffff4c8d7f5 in g_assertion_message () from /usr/lib/libglib-2.0.so.0
    #3  0x00007ffff4c8d88a in g_assertion_message_expr () from /usr/lib/libglib-2.0.so.0
    #4  0x0000000000472b91 in object_has_ifindex (object=0x8a8320, ifindex=12) at platform/nm-linux-platform.c:1534
    #5  0x0000000000472bec in check_cache_items (platform=0x7fe8a0, cache=0x7fda30, ifindex=12) at platform/nm-linux-platform.c:1549
    #6  0x0000000000472de3 in announce_object (platform=0x7fe8a0, object=0x8a8c30, change_type=NM_PLATFORM_SIGNAL_REMOVED, reason=NM_PLATFORM_REASON_EXTERNAL) at platform/nm-linux-platform.c:1617
    #7  0x0000000000473dd2 in event_notification (msg=0x8a7970, user_data=0x7fe8a0) at platform/nm-linux-platform.c:1992
    #8  0x00007ffff5ee14de in nl_recvmsgs_report () from /usr/lib/libnl-3.so.200
    #9  0x00007ffff5ee1849 in nl_recvmsgs () from /usr/lib/libnl-3.so.200
    #10 0x00000000004794df in event_handler (channel=0x7fc930, io_condition=G_IO_IN, user_data=0x7fe8a0) at platform/nm-linux-platform.c:4152
    #11 0x00007ffff4c6791d in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
    #12 0x00007ffff4c67cf8 in ?? () from /usr/lib/libglib-2.0.so.0
    #13 0x00007ffff4c68022 in g_main_loop_run () from /usr/lib/libglib-2.0.so.0
    #14 0x00000000004477ee in main (argc=1, argv=0x7fffffffeaa8) at main.c:447
    (gdb) fr 4
    #4  0x0000000000472b91 in object_has_ifindex (object=0x8a8320, ifindex=12) at platform/nm-linux-platform.c:1534
    1534                    g_assert_not_reached ();
2015-01-15 09:33:35 -06:00
Thomas Haller
96c099de09 platform: suppress change event when deleting IPv4 route with metric 0
refresh_object() raised a spurious change event for the route we
are about to delete. Suppress that by adding an internal reason flag.

Fixes: 41e6c4fac1
2015-01-12 20:02:06 +01:00
Lubomir Rintel
529591d8de platform: fix draining of the event queue with old libnl (rh #1180773)
It fails doesn't propagate EAGAIN properly. Fixed in 3.2.22's 375a629.

https://bugzilla.redhat.com/show_bug.cgi?id=1180773
2015-01-12 17:07:00 +01:00
Thomas Haller
41e6c4fac1 platform: workaround deletion of IPv4 route with metric 0
Deleting routes with metric 0 might end up deleting other
routes with a different metric.

Workaround this in platform to only delete a route with
metric 0 if such a route can be found prior to deletion.

Don't only look into the cache (which might be out of date).
Instead refetch the route we are about to delete to be sure.

There is still a race that we might end up deleting the wrong
route.

https://bugzilla.gnome.org/show_bug.cgi?id=741871
https://bugzilla.redhat.com/show_bug.cgi?id=1172780
2015-01-11 13:08:34 +01:00
Thomas Haller
2cb3c7e8a0 platform: route_search_cache() should not treat a metric 0 as "any" route
This match-any behavior ignoring metric is nowhere used. And even if we
would need such a behavior, using 0 is wrong because IPv4 routes can
have a metric of zero.
2015-01-11 13:08:34 +01:00
Thomas Haller
06e4eee0ce platform: fix IPv6 route methods for metric 0
Handling a route with metric 0 effectively means
a metric of 1024 (user default). Adjust the add(),
delete() and exist() functions to consider routes
with metric 0 as 1024.
2015-01-11 13:08:34 +01:00
Thomas Haller
4ba8df425f platform: fix data type for metric argument of refresh_route() 2015-01-11 13:08:34 +01:00
Lubomir Rintel
53380159dd platform: Fix build with LIBNL_INET6_ADDR_GEN_MODE
platform/nm-linux-platform.c: In function 'setup':
  platform/nm-linux-platform.c:4364:2: error: 'object' undeclared (first use in this function)
    object = nl_cache_get_first (priv->link_cache);
    ^

Fixes 2b8060b9b3
2014-12-11 15:20:08 +01:00
Lubomir Rintel
8b77b93169 Revert "platform: increase NL buffer for systems with lots of interfaces (rh #1141256)"
This reverts commit efd09845c4.

It turns out that the socket space might not be the only buffer that may get
too full. 128K ought to be enough for it and we should resynchronize with the
kernel now if needed.
2014-12-11 11:49:29 +01:00
Lubomir Rintel
2b8060b9b3 platform: resynchronize with kernel when we're out of buffer space
Kernel can return ENOBUFS in variety of reasons. If that happens, we know we've
lost events and should pick up kernel state.

Simple reproducer that triggers an ENOBUFS condition no matter how big our
netlink socket buffer is:

  ip link add bridge0 type bridge
  for i in seq $(0 1023); do ip link add dummy$i type dummy; \
    ip link set dummy$i master bridge0; done
  ip link del bridge0
2014-12-11 11:49:29 +01:00
Lubomir Rintel
85b811cc7c platform: refactor the object comparison logic into a separate function
One from libnl is not good enough (see comment).
2014-12-11 11:49:29 +01:00
Lubomir Rintel
ed78d3b3dc platform: ensure all objects in link cache are of AF_UNSPEC family
We assume that in nm_nl_cache_search() and correctly set that in
get_kernel_object(), but we rtnl_link_alloc_cache() can initialize the cache
with devices of other families.

The consequence is that we don't notify when the bridge changes to IFF_UP as we
fail to match and remove the old downed object from the cache:

  nm_device_bring_up(): [0xf506c0] (bridge0): bringing up device.
  nm_platform_link_set_up(): link: setting up 'bridge0' (12)
  link_change_flags(): link: change 12: flags set 'up' (1)
  get_kernel_object(): get_kernel_object for link: bridge0 (12, family 7)
  log_link(): signal: link   added: 12: bridge0 <UP> mtu 1500 bridge driver 'bridge' udi '/sys/devices/virtual/net/bridge0'
  get_kernel_object(): get_kernel_object for link: bridge0 (12, family 7)
  log_link(): signal: link changed: 12: bridge0 <UP> mtu 1500 bridge driver 'bridge' udi '/sys/devices/virtual/net/bridge0'
  log_link(): signal: link changed: 12: bridge0 <UP> mtu 1500 bridge driver 'bridge' udi '/sys/devices/virtual/net/bridge0'
  (bridge0): device not up after timeout!
  (bridge0): preparing device
2014-12-11 11:49:29 +01:00
Thomas Haller
5849c97c03 platform: avoid conflicts when reinstalling the device-route
Since f32075d2fc, we remove the kernel
added IPv4 device route, and re-add it with appropriate metric.

This could potentially replace existing, conflicting routes. Be more
careful and only take any action when we don't have a conflicting
route and when we add the address for the first time.

The motivation for this was libreswan which might install a VPN route
for a subnet that we also have configured on an interface. But the route
conflict could happen easily for other reasons, for example if you
configure a conflicting route manually.

Don't replace the device route if we have any indication that
a conflict could arise.

https://bugzilla.gnome.org/show_bug.cgi?id=723178
2014-12-11 10:07:00 +01:00
Thomas Haller
0b50940f43 platform: add paramter to ip4_route_add to set src (RTA_PREFSRC)
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-11-25 22:30:38 +01:00
Dan Williams
5de8a0d3a7 platform: stop using private kernel tun device flags (bgo #740380)
The TUN_* flags are going to be deprecated upstream in the kernel
so we might as well stop using them.

https://lkml.org/lkml/2014/11/19/460

https://bugzilla.gnome.org/show_bug.cgi?id=740380
2014-11-19 18:39:08 -06:00
Dan Williams
45bfb653f3 wifi: don't query nl80211 for non-WiFi devices (bgo #740131)
The upstream kernel added module aliases for nl80211 in commit
fb4e156886ce6e8309e912d8b370d192330d19d3, so querying nl80211
now auto-loads the module.  Previously NM was doing this to
determine whether an ethernet-like device was a Wi-Fi device
that supported nl80211, but this leads to the nl80211 loading
on platforms that will never have or use Wi-Fi.

Since every nl80211-capable device will already have
DEVTYPE=wlan set (from /sys/class/net/wlan0/uevent), we can use
that as an indicator that the ethernet-like device is WiFi
instead of asking nl80211.

https://bugzilla.gnome.org/show_bug.cgi?id=740131
2014-11-17 09:45:08 -06:00
Dan Winship
3bfb163a74 all: consistently include config.h
config.h should be included from every .c file, and it should be
included before any other include. Fix that.

(As a side effect of how I did this, this also changes us to
consistently use "config.h" rather than <config.h>. To the extent that
it matters [which is not much], quotes are more correct anyway, since
we're talking about a file in our own build tree, not a system
include.)
2014-11-13 17:18:42 -05:00
Thomas Haller
3ef807c6ae platform: extend nm_platform_ipX_route_get_all() to return default-routes only
Add a new enum NMPlatformGetRouteMode. This extends the existing
functions nm_platform_ip4_route_get_all() and nm_platform_ip6_route_get_all()
to return default routes only.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-11-07 15:23:11 +01:00
Thomas Haller
52ddd72bde core: cleanup type of route metric to ensure guint32
Kernel, netlink an NMPlatformRoute treat route metrics as
uint32. Fix several places to use the exact type.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-11-07 15:19:06 +01:00
Thomas Haller
c262819360 platform: don't include gsystem-local-alloc.h in nm-platform.h
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-11-07 15:19:05 +01:00
Thomas Haller
b77567b225 build: fix -Wstrict-prototypes warnings
We disabled -Wstrict-prototypes in commit
db9b1df0e4 .
Fix compiler warnings.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-10-29 12:30:11 +01:00
Lubomir Rintel
33866e4030 core: Move NMPlatformSource to nm-types.h
...and rename it while at it. It's going to be useful outside nm-platform,
to weight MTU options from various sources.
2014-10-20 12:41:50 +02:00
Thomas Haller
4d675ce0fc platform: fix parsing vxlan netlink message for older kernel
vxlan_info_data_parser() must take care of missing netlink attributes.
Otherwise, older kernels will crash NM.

Also, workaround compilation against old kernel headers which are
missing 'struct ifla_vxlan_port_range'. We do this by defining our
own 'struct nm_ifla_vxlan_port_range' version.

Reported-by: Javier Jardón <jjardon@gnome.org>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-09-25 17:45:53 +02:00
Thomas Haller
388d4d9030 platform: add @peer_address argument to nm_platform_ip4_address_delete()
Deleting an IPv4 address using libnl requires the proper peer address.
Pass the address of the peer on to nm_platform_ip4_address_delete().

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-09-24 16:32:11 +02:00
Lubomir Rintel
efd09845c4 platform: increase NL buffer for systems with lots of interfaces (rh #1141256)
Seems like 128k is not enough for systems with many interfaces. This adds 4k
per device, while keeping the 128k minimum. Therefore this change only
affects systems with more than 32 interfaces.

https://bugzilla.redhat.com/show_bug.cgi?id=1141256
2014-09-22 11:17:12 +02:00
Dan Williams
37f11fbdf8 platform: add support for kernel IPv6LL address generation modes
This patch requires both upstream kernel support for
IFLA_INET6_ADDR_GEN_MODE which was merged in this patch:

ipv6: addrconf: implement address generation modes
bc91b0f07ada5535427373a4e2050877bcc12218

and corresponding libnl support, merged in these patches:

veth: add kernel header linux/veth.h for VETH defines
9dc6e6da90016a33929f262bea0187396e1a061b

link: update copy of kernel header include/linux/if_link.h
b51815a9dbd8e45fd2558bbe337fb360ca2fd861

link/inet6: add link IPv6 address generation mode support
558f966782539f6d975da705fd73cea561c9dc83
2014-09-04 15:10:26 -05:00
Dan Winship
c43f88907b libnm-core: change DBUS_TYPE_G_UCHAR_ARRAY properties to G_TYPE_BYTES
Change all DBUS_TYPE_G_UCHAR_ARRAY properties to G_TYPE_BYTES, and
update corresponding APIs. Notably, this means they are now refcounted
rather than being copied.

Update the rest of NM for the changes. The daemon still converts SSIDs
to GByteArrays internally, because changing it to use GBytes has lots
of trickle-down effects. It can possibly be changed later.
2014-09-04 09:20:11 -04:00
Jiří Klimeš
6999a688b0 platform: (trivial) don't shadow link(3) in NMLinuxPlatform
Reported by Jordan Messina

(cherry picked from commit c54e6a95ff0957fb9d5c51505c8c3dd036600ff5)
2014-08-21 11:16:43 +02:00
Dan Winship
ea456aaa81 all: remove use of struct ether_addr / ether_aton()
Lots of old code used struct ether_addr to store hardware addresses,
and ether_aton() to parse them, but more recent code generally uses
guint8 arrays, and the nm_utils_hwaddr_* methods, to be able to share
code between ETH_ALEN and INFINIBAND_ALEN cases. So update the old
code to match the new. (In many places, this ends up getting rid of
casts between struct ether_addr and guint8* anyway.)

(Also, in some places, variables were switched from struct ether_addr
to guint8[] a while back, but some code still used "&" when referring
to them even though that's unnecessary now. Clean that up.)
2014-08-07 12:11:49 -04:00
Dan Winship
35f36ba4c3 libnm-core, etc: drop type-based hwaddr funcs, port to length-based ones
Drop the arptype-based nm_utils_hwaddr funcs, and rename the
length-based ones to no longer have _len in their names. This also
switches nm_utils_hwaddr_atoba() to using a length rather than an
arptype, and adds a length argument to nm_utils_hwaddr_valid() (making
nm_utils_hwaddr_valid() now a replacement for nm_utils_hwaddr_aton()
in some places, where we were only using aton() to do validity
checking).
2014-08-07 12:08:16 -04:00
Thomas Haller
971dfc773f platform: fix warning warning about unused variable
The variable is not actually unused, because it is used
to free the nl_object instance.

clang warns:

    make[4]: Entering directory `./NetworkManager/src'
      CC       nm-linux-platform.lo
    platform/nm-linux-platform.c:1746:35: error: unused variable 'obj_cleanup' [-Werror,-Wunused-variable]
            auto_nl_object struct nl_object *obj_cleanup = obj;
                                             ^

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-08-01 13:17:00 +02:00
Thomas Haller
06703c1670 core: fix checks for default routes by comparing the prefix length
At some places, we considered a default route to be a route with
destination network 0.0.0.0 (::). This is wrong because a default route
is a route with plen==0.

This is for example relevant for OpenVPN which adds two routes
0.0.0.0/1 and 128.0.0.0/1 to hijack the default route. We should
not treat 0.0.0.0/1 as default route, instead  NM should treat
it as any other subnet route (even if it effectively routes large
parts).

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-07-29 23:40:39 +02:00
Thomas Haller
ac4fafe7a4 platform: assert against the maximum length of link_get_address()
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-07-23 12:42:45 -05:00
Dan Williams
d8d0b37adc platform: fix uninitialized variable usage after fdf78b3d
'address' was not initialized, so using address.ifindex was not
going to work.

==6777== Conditional jump or move depends on uninitialised value(s)
==6777==    at 0x44A6DB: check_cache_items (nm-linux-platform.c:1510)
==6777==    by 0x44AA4F: announce_object (nm-linux-platform.c:1586)
==6777==    by 0x44A59A: refresh_object (nm-linux-platform.c:1666)
==6777==    by 0x44A676: check_cache_items (nm-linux-platform.c:1517)
==6777==    by 0x44A812: announce_object (nm-linux-platform.c:1566)
==6777==    by 0x44D957: handle_udev_event (nm-linux-platform.c:3964)
==6777==    by 0x3BAFC125A7: g_closure_invoke (gclosure.c:777)
==6777==    by 0x3BAFC2465C: signal_emit_unlocked_R (gsignal.c:3586)
==6777==    by 0x3BAFC2C3E1: g_signal_emit_valist (gsignal.c:3330)
==6777==    by 0x3BAFC2C69E: g_signal_emit (gsignal.c:3386)
==6777==    by 0x3D93A03BE3: ??? (in /usr/lib64/libgudev-1.0.so.0.1.3)
==6777==    by 0x3BAF8521D5: g_main_context_dispatch (gmain.c:3066)
2014-07-21 13:09:47 -05:00
Thomas Haller
6cf9724f7d platform: use gs_free (instead of own define auto_g_free)
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-07-15 22:50:36 +02:00
Dan Williams
66d1f2f53c platform: ignore RTM_F_CLONED (eg, cache) routes
The kernel adds these for various operations; they are short-lived,
added often, and not useful to NetworkManager.  Ignore them.  This
prevents NetworkManager from continuously updating the IPv6 config
and emitting state changes to clients via D-Bus for useless changes.
2014-07-11 14:51:12 -05:00
Thomas Haller
2a89258562 platform: fix invalid address lifetimes on startup
When starting, the initally loaded addresses were not fixed to have
absolute lifetimes.

This also leads to a crash due to failed assertion[1], when having
already expired addresses during NetworkManager start.

[1] backtrace:
  #0  0x00007f39db91ec39 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
  #1  0x00007f39db920348 in __GI_abort () at abort.c:89
  #2  0x00007f39dc35a0ed in _g_log_abort () at gmessages.c:255
  #3  0x00007f39dc377c97 in g_assertion_message (domain=domain@entry=0x7f39e0085c67 "NetworkManager", file=file@entry=0x7f39e007f070 "platform/nm-linux-platform.c", line=line@entry=1146,
      func=func@entry=0x7f39e0081430 <__FUNCTION__.23775> "_init_ip_address_lifetime", message=message@entry=0x7f39e13828b0 "assertion failed: (a_preferred <= a_valid && a_valid > 0 && a_preferred > 0)") at gtestutils.c:2278
  #4  0x00007f39dc377cfa in g_assertion_message_expr (domain=domain@entry=0x7f39e0085c67 "NetworkManager", file=file@entry=0x7f39e007f070 "platform/nm-linux-platform.c", line=line@entry=1146,
      func=func@entry=0x7f39e0081430 <__FUNCTION__.23775> "_init_ip_address_lifetime", expr=expr@entry=0x7f39e007f4e8 "a_preferred <= a_valid && a_valid > 0 && a_preferred > 0") at gtestutils.c:2293
  #5  0x00007f39e0004608 in _init_ip_address_lifetime (address=address@entry=0x7fff7f8a2580, rtnladdr=rtnladdr@entry=0x7f39e12cdb20) at platform/nm-linux-platform.c:1144
  #6  0x00007f39e0004ae4 in init_ip6_address (address=address@entry=0x7fff7f8a2580, rtnladdr=rtnladdr@entry=0x7f39e12cdb20) at platform/nm-linux-platform.c:1216
  #7  0x00007f39e000a75e in ip6_address_get_all (platform=<optimized out>, ifindex=3) at platform/nm-linux-platform.c:3342
  #8  0x00007f39e0032729 in nm_ip6_config_capture (ifindex=ifindex@entry=3, capture_resolv_conf=capture_resolv_conf@entry=0, use_temporary=use_temporary@entry=NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN) at nm-ip6-config.c:303
  #9  0x00007f39dffee8fa in update_ip_config (self=0x7f39e1380300, initial=<optimized out>) at devices/nm-device.c:5841
  #10 0x00007f39dffef52a in nm_device_capture_initial_config (dev=<optimized out>) at devices/nm-device.c:5869
  #11 0x00007f39e003e74e in get_existing_connection (manager=manager@entry=0x7f39e132b150, device=device@entry=0x7f39e1380300) at nm-manager.c:1576
  #12 0x00007f39e003edb2 in add_device (self=self@entry=0x7f39e132b150, device=device@entry=0x7f39e1380300, generate_con=<optimized out>) at nm-manager.c:1826
  #13 0x00007f39e003f503 in platform_link_added (reason=<optimized out>, plink=0x7f39e1372340, ifindex=3, self=0x7f39e132b150) at nm-manager.c:2205
  #14 platform_link_cb (platform=<optimized out>, ifindex=3, plink=0x7f39e1372340, change_type=<optimized out>, reason=<optimized out>, user_data=<optimized out>) at nm-manager.c:2220
  #15 0x00007f39da868d8c in ffi_call_unix64 () at ../src/x86/unix64.S:76
  #16 0x00007f39da8686bc in ffi_call (cif=cif@entry=0x7fff7f8a2a40, fn=0x7f39e003f360 <platform_link_cb>, rvalue=0x7fff7f8a29b0, avalue=avalue@entry=0x7fff7f8a2930) at ../src/x86/ffi64.c:522
  #17 0x00007f39dc84aad8 in g_cclosure_marshal_generic (closure=0x7f39e1368080, return_gvalue=0x0, n_param_values=<optimized out>, param_values=<optimized out>, invocation_hint=<optimized out>, marshal_data=0x0) at gclosure.c:1454
  #18 0x00007f39dc84a298 in g_closure_invoke (closure=0x7f39e1368080, return_value=return_value@entry=0x0, n_param_values=5, param_values=param_values@entry=0x7fff7f8a2c40, invocation_hint=invocation_hint@entry=0x7fff7f8a2be0)
      at gclosure.c:777
  #19 0x00007f39dc85c35d in signal_emit_unlocked_R (node=node@entry=0x7f39e12c16c0, detail=detail@entry=0, instance=instance@entry=0x7f39e12c30a0, emission_return=emission_return@entry=0x0,
      instance_and_params=instance_and_params@entry=0x7fff7f8a2c40) at gsignal.c:3586
  #20 0x00007f39dc8640f2 in g_signal_emit_valist (instance=<optimized out>, signal_id=<optimized out>, detail=<optimized out>, var_args=var_args@entry=0x7fff7f8a2e20) at gsignal.c:3330
  #21 0x00007f39dc8643af in g_signal_emit (instance=<optimized out>, signal_id=<optimized out>, detail=detail@entry=0) at gsignal.c:3386
  #22 0x00007f39e000e24c in nm_platform_query_devices () at platform/nm-platform.c:330
  #23 0x00007f39e0040f30 in nm_manager_start (self=0x7f39e132b150) at nm-manager.c:4207
  #24 0x00007f39dffe53ab in main (argc=1, argv=0x7fff7f8a3468) at main.c:657

Regression introduced by commit 8310a039d8.

https://bugzilla.gnome.org/show_bug.cgi?id=732472

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-30 14:19:27 +02:00
Thomas Haller
fdf78b3d54 platform: don't announce routes/addresses that are not returned from get_all()
There is no point in raising events that a route/address was added, if
a subsequent call to ip4_address_get_all() et.al don't show these
objects.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-24 16:07:13 +02:00
Thomas Haller
a2791f54da platform: set timestamp in platform addresses to last_update_time()
Previous patch 8310a039d8 modified
platform to set the timestamp of addresses always to 1.

So, when adding an address platform logging looked like:
  signal: address 4 added: 192.168.232.3/24 lft 2000sec pref 1000sec lifetime 12345-1[13344,14344] dev em1 src kernel

This is confusing in the log file and during debugging. Instead set the
timestamp to the last modification time of the address so that it will
look like:
  signal: address 4 added: 192.168.232.3/24 lft 2000sec pref 1000sec lifetime 12345-12345[1000,2000] dev em1 src kernel

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-19 22:26:10 +02:00
Thomas Haller
31db488396 platform: fix off-by-two error converting lifetimes in _init_ip_address_lifetime()
When setting the timestamp to 1, we have to subtract(!) one second
from a_valid and a_preferred.

Due to this error, NM saw the lifetimes of addresses from system as two
seconds larger then the actual value.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-19 22:13:48 +02:00
Thomas Haller
8366d7cd1b platform: fix setting preferred time off-by-one in _init_ip_address_lifetime()
This error was introduced only recently with commit
8310a039d8.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-07 11:18:51 +02:00
Thomas Haller
26a65f4fe4 platform: fix compiler warning about uninitialized usage
CC       nm-linux-platform.lo
    platform/nm-linux-platform.c: In function '_nm_platform_link_get':
    platform/nm-linux-platform.c:161:17: error: 'rtnllink' may be used uninitialized in this function [-Werror=maybe-uninitialized]
       nl_object_put (*object);
                     ^
    platform/nm-linux-platform.c:1923:35: note: 'rtnllink' was declared here
      auto_nl_object struct rtnl_link *rtnllink;
                                       ^
    cc1: all warnings being treated as errors

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-06 20:11:36 +02:00
Thomas Haller
58b318b53a platform: raise address changed signals for lifetime update
When only the lifetime of an address changes, we did not get a platform signal
as libnl does not consider the time fields in nl_object_diff().
Workaround by comparing the timestamps manually.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-06 20:01:38 +02:00
Thomas Haller
441f337412 platform: refactor setting the source of platform addresses to NM_PLATFORM_SOURCE_KERNEL
Moving setting the source of the address to the init_* functions.

This also has the advantage, that the platform internal to_string functions have the proper
source set.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-06 20:01:38 +02:00
Thomas Haller
8310a039d8 platform: fix preferred and valid lifetimes for addresses from netlink/kernel
The kernel tells the address lifetimes in the 'struct ifa_cacheinfo'
attribute. This contains two timestamps (cstamp and tstamp) and two
relative lifetimes (ifa_prefered and ifa_valid).

The timestamps are equal to clock_gettime(CLOCK_MONOTONIC) scale in
1/100th of a second (wrapping every 497 days).

The preferred/valid times are re-adjusted everytime when sending the
message and count down as the time goes by. In other words, they are
anchored relatively to the moment of when kernel creates the netlink
message.

As platform is caching the rtnl_addr object, the information of *when* the
lifetimes started counting is not available.

This patch fixes reading these values by hacking the libnl object
when it gets received, so that valid and preferred are instead absolute
expiration timestamps in scale nm_utils_get_monotonic_timestamp_s() --
which NM internally is used for address timestamps.

There are two minor downsides to this hack:
- the valid and preferred properties of a cached rtnl_addr object have
  an unexpected meaning, i.e. they are absolute and in a different time
  scale.
- later when converting rtnl_addr to NMPlatformIPAddress, the base
  timestamp is set to "1", i.e. an NMPlatformIPAddress has no knowledge
  of when the address was created or last modified. The timestamp
  property of NMPlatformIPAddress is solely there to anchor the relative
  timestamps lifetime and preferred. Do not use it for anything
  else.
  Another reason the timestamp property is meaningless is that
  its scale nm_utils_get_monotonic_timestamp_s() starts counting at
  process start. So addresses that existed before would have a negative
  or zero timestamp, which we avoid. This in turn could be solved by either
  allowing negative timestamps or by shifting
  nm_utils_get_monotonic_timestamp_*(). Both is viable, but not
  necessary (ATM), because the age of an address has no other apparent
  use then to anchor the relative timestamps.
  Another implication is, that we potentially could get rid of the
  timestamp completely, and insteat make preferred and lifetime be
  absolute expiries.

This will be fixed properly later, by not caching libnl objects but  instead
native NMPlatform objects. For those we have full control over their properties.

https://bugzilla.gnome.org/show_bug.cgi?id=727382

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-06 20:01:37 +02:00
Dan Winship
662ade1e47 platform: improve tracking of route sources
NMIP[46]Route had a "source" field, but it was always set to KERNEL
for routes read from the kernel (even if they were originally added by
NM).

Fix things a bit by translating between our "source" field and the
kernel's "protocol" field.

https://bugzilla.gnome.org/show_bug.cgi?id=729203
2014-06-06 10:24:43 -04:00
Dan Winship
e644745d85 trivial: route-related whitespace/indentation fixes 2014-06-06 10:23:28 -04:00
Pavel Šimerda
fd41c989d5 platform: fix software device handling when announcing links
The handling for announcing links was broken resulting in
duplicate link-added signals from platform.

Co-Authored-By: Thomas Haller <thaller@redhat.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:57 +02:00
Pavel Šimerda
f008c9fbea platform/test: fix fake platform to emit signals synchronously (analog to Linux platform)
When adding a link, the Linux platform implementation raises the
link-changed signal synchronously. Fix the fake platform to behave identically
and also fix all the tests.

This also fixes the Linux platform tests for the most part because now the
test functions (and fake platform) behave like the Linux system
implementation.

https://bugzilla.gnome.org/show_bug.cgi?id=706293

Co-Authored-By: Thomas Haller <thaller@redhat.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:57 +02:00
Thomas Haller
66e2e932b5 platform: add nm_platform_link_get()
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-05 18:12:57 +02:00