Commit Graph

13873 Commits

Author SHA1 Message Date
Dan Winship
d80e100179 libnm-core: simplify _nm_setting_new_from_dbus()
libnm-util's nm_setting_new_from_hash() needed to call
g_type_class_ref(setting_type) to ensure that the class had been
initialized by the time we fetched its properties. But in libnm-core's
version, we create the setting object before fetching the list of
properties, so we know the class will already have been initialized by
that point.
2015-01-15 14:46:30 -05:00
Dan Winship
bbbbca2778 libnm-core: fix a leak in _nm_setting_new_from_dbus() 2015-01-15 14:46:30 -05:00
Aleksander Morgado
bf7865e859 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.

(fixup by dcbw to use cached passed to cache_remove_unknown())

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 11:13:50 -06:00
Dan Williams
dd20407c4e Revert "platform: avoid storing unknown netlink object types (bgo #742928)"
This reverts commit 6c1a6d2d5f.

Mistaken push; it'll get committed, just needs a slight fixup.
2015-01-15 11:13:20 -06:00
Dan Williams
d2871089a8 platform: don't read past end of address array (bgo #742937)
The address might be zero-size, and therefore nl_addr_get_binary_addr()
returns a pointer to a zero-size array.  We don't want to read past the
end of that array.  Since zero-size addresses really mean an address
of all zeros, just make that happen.

As an additional optimization, if the prefix length is zero, the whole
address is host bits and should be cleared.

==30286== Invalid read of size 4
==30286==    at 0x478090: clear_host_address (nm-linux-platform.c:3786)
==30286==    by 0x4784D4: route_search_cache (nm-linux-platform.c:3883)
==30286==    by 0x4785A1: refresh_route (nm-linux-platform.c:3901)
==30286==    by 0x4787B6: ip4_route_delete (nm-linux-platform.c:3978)
==30286==    by 0x47F674: nm_platform_ip4_route_delete (nm-platform.c:1980)
==30286==    by 0x4B279D: _v4_platform_route_delete_default (nm-default-route-manager.c:1122)
==30286==    by 0x4AEF03: _platform_route_sync_flush (nm-default-route-manager.c:320)
==30286==    by 0x4B043E: _resync_all (nm-default-route-manager.c:574)
==30286==    by 0x4B0CA7: _entry_at_idx_remove (nm-default-route-manager.c:631)
==30286==    by 0x4B1A66: _ipx_update_default_route (nm-default-route-manager.c:806)
==30286==    by 0x4B1A9C: nm_default_route_manager_ip4_update_default_route (nm-default-route-manager.c:813)
==30286==    by 0x45C3BC: _cleanup_generic_post (nm-device.c:7143)
==30286==  Address 0xee33514 is 0 bytes after a block of size 20 alloc'd
==30286==    at 0x4C2C080: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==30286==    by 0x6B2B0B1: nl_addr_alloc (in /usr/lib/libnl-3.so.200.20.0)
==30286==    by 0x6B2B0E3: nl_addr_build (in /usr/lib/libnl-3.so.200.20.0)
==30286==    by 0x6B2B181: nl_addr_clone (in /usr/lib/libnl-3.so.200.20.0)
==30286==    by 0x66DB0D7: ??? (in /usr/lib/libnl-route-3.so.200.20.0)
==30286==    by 0x6B33CE6: nl_object_clone (in /usr/lib/libnl-3.so.200.20.0)
==30286==    by 0x6B2D303: nl_cache_add (in /usr/lib/libnl-3.so.200.20.0)
==30286==    by 0x472E55: refresh_object (nm-linux-platform.c:1735)
==30286==    by 0x473137: add_object (nm-linux-platform.c:1795)
==30286==    by 0x478373: ip4_route_add (nm-linux-platform.c:3846)
==30286==    by 0x47F375: nm_platform_ip4_route_add (nm-platform.c:1939)
==30286==    by 0x4AEC06: _platform_route_sync_add (nm-default-route-manager.c:254)

https://bugzilla.gnome.org/show_bug.cgi?id=742937
2015-01-15 11:08:20 -06:00
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
Dan Winship
5828a4b0b4 connectivity: merge branch 'danw/connectivity-bgo742823'
https://bugzilla.gnome.org/show_bug.cgi?id=742823
2015-01-15 10:22:13 -05:00
Dan Winship
66b8f2b7a0 connectivity: avoid redundant connectivity checks
Don't start an automatic connectivity check right when NMManager tells
us we're online; only do it if the manager doesn't request an explicit
connectivity check immediately afterward.
2015-01-15 10:22:13 -05:00
Dan Winship
0997c4b245 connectivity: simplify redundant code
Merge the two nm_connectivity_set_online() calls into one, after
tweaking NMConnectivity to always update its internal state before
alerting callers to the new state.
2015-01-15 10:22:13 -05:00
Dan Winship
5e182d5577 connectivity: fix manager state during connectivity check (bgo #742823)
When a connection has finished activating, but we don't know yet that
we have full connectivity, then find_best_device_state() should return
CONNECTED_SITE, not CONNECTING. Fixes a bug where the manager state
would repeatedly switch between those two states.
2015-01-15 10:22:13 -05:00
Dan Winship
53f2642c73 connectivity: improve debug logging
nm-connectivity was logging both "started" and "finished" for periodic
connectivity checks, but was only logging "finished" for manual ones,
which made the logs look weird. Fix it to log both periodic and manual
starts, and differentiate them.

Also add some additional logging to indicate when set_online() is
called, and when :state changes.
2015-01-15 10:22:13 -05:00
Jiří Klimeš
233498e0a4 ifcfg-rh: update test files not to use obsolete GATEWAY<n> variables
But add a dedicated test reading GATEWAY1 to ensure we are still backwards
compatible.
2015-01-15 13:03:13 +01:00
Jiří Klimeš
a3c52d7a33 man: add description of BOOTPROTO to nm-settings-ifcfg-rh manpage 2015-01-15 13:03:13 +01:00
Jiří Klimeš
c8fe3bbabc ifcfg-rh: read custom IP address for shared connections (rh #1174632)
Custom IP ranges for shared connection were implemeted in bgo #6759732
(commit 32a001f526). The first IP address
is used and a range is calculated.
However, the commit missed to update ifcfg-rh plugin to read the address.

Test case:
* use ifcfg-rh plugin for NetworkManager
$ nmcli con add type eth con-name shared-ip ifname eth0
$ nmcli con mod shared-ip ipv4.addresses 9.8.7.6/24 ipv4.method shared
$ nmcli con show shared-ip
$ nmcli con show shared-ip  <--- ip address 9.8.7.6 was missing

https://bugzilla.redhat.com/show_bug.cgi?id=1174632
2015-01-15 13:03:13 +01:00
Lubomir Rintel
a169a79a7d bond: allow overriding the MTU
Set the MTU if 802-3-ethernet.mtu is present and non-zero. The ifcfg-rh writer
sets it if there's a MTU key.

https://bugzilla.redhat.com/show_bug.cgi?id=1177582
2015-01-14 18:44:20 +01:00
Thomas Haller
29eb46b126 settings: merge branch 'th/uuid-duplicate-rh1171751'
https://bugzilla.redhat.com/show_bug.cgi?id=1171751
2015-01-13 16:58:24 +01:00
Thomas Haller
4475f59bce settings: update year in copyright text of plugin-info for keyfile and ifcfg-rh 2015-01-13 16:41:31 +01:00
Thomas Haller
236226a590 ifcfg-rh: don't reload connection in connection_ifcfg_changed() if monitoring is not enabled
This was not really an error, because NMIfcfgConnection would not
watch the files if monitoring is not enabled. Still do it, because
it feels more correct.
2015-01-13 16:41:31 +01:00
Thomas Haller
0c6349c627 ifcfg-rh: refactor update_connection()
Make update_connection() analogous to keyfiles implementation.
Effectively merge _internal_new_connection() and update_connection()
-- previously connection_new_or_changed().

https://bugzilla.redhat.com/show_bug.cgi?id=1171751
2015-01-13 16:41:31 +01:00
Thomas Haller
0cf00ff3aa ifcfg-rh: sort paths in read_connections()
Presort the files in read_connections() as we do it
for keyfile.

This alone has not much consequences. Do this patch first, to
keep the next patches more self-contained.
2015-01-13 16:41:30 +01:00
Thomas Haller
a609dd12d3 ifcfg-rh/trivial: rename connection_new_or_changed() and variable
The ifcfg-rh implementation should be similar to the one from keyfile.
Rename the variables and function that have the same meaning.
Do this trivial commit first, before starting refactoring.
2015-01-13 16:41:30 +01:00
Thomas Haller
bbaa243e31 ifcfg-rh: add logging macros _LOGX() to plugin.c 2015-01-13 16:41:30 +01:00
Thomas Haller
7b807b11cc settings: avoid duplicate UUID in settings
When adding a connection to NMSettings we did not check for
duplicate connection UUIDs (which could for example happen
if two different plugins report a conflicting UUID).
Also, we would not check that an already added connection
changes it's UUID.

Both could lead to have duplicate connections (by UUID).

Avoid that two ways:
- when adding a connection to NMSettings, ensure that we don't add
  a conflicting UUID. Otherwise just bail out and do nothing.
- when modifying a connection that is already added to NMSettings,
  enforce that the UUID cannot change. Otherwise fail with error.

For ifcfg-rh plugin this situation still can happen during reload.
In this case error out and refuse to update the connection. After
all, the user configured invalid UUIDs.

https://bugzilla.redhat.com/show_bug.cgi?id=1171751
2015-01-13 16:41:30 +01:00
Thomas Haller
8ba8a55cfa keyfile: ignore GFileMonitor change flags in dir_changed()
When writing a file (for example with `sed -i`) a temporary file
might be created and removed quickly. This causes spurious events
in dir_changed().
2015-01-13 16:41:30 +01:00
Thomas Haller
db5c4ce64f keyfile: reuse duplicate check from update_connection() in add_connection()
Also during add_connection() we must take special care of not "adding" a
connection with a conflicting UUID. In that case we want to fallback to
"update".

update_connection() already does all the checks, so call
update_connection() from add_connection().
2015-01-13 16:41:30 +01:00
Thomas Haller
5c2fa92099 keyfile: cleanup logging
Log lines with a "keyfile:" prefix and show more information about
the loaded connection. Especially printing the UUID is interesting.
2015-01-13 16:41:30 +01:00
Thomas Haller
8a4e64c6aa keyfile: read_connections() must skip duplicate connections
If there are keyfiles with duplicate UUIDs, read_connections()
would iterate over the files, loading them as they appear and
overwriting duplicate connections that were just loaded.

For example, have keyfiles 'A' and 'B' with the same UUID.
On start, NM might first load 'A', then 'B'. 'B' would replace the
content of 'A' which was just loaded.
On reload, NM would first overwrite 'B' with 'A', and then again
overwriting 'A' with 'B'.

Fix that by accept the first found connection and don't overwrite
it during the same read_connections() run.

Also sort the files by file modification timestamp so that we
get a reproducible and sensible behavior.
2015-01-13 16:41:30 +01:00
Thomas Haller
c2fcb680f8 keyfile: merge update_connection() and new_connection()
new_connection() and update_connection() are very similar as both
must anticipate collisions of UUIDs.

When reloading a connection (update_connection(), previously), the loaded
connection for a certain path might actually replace another existing
connection. In this case, the old connection must be removed, and
the existing one updated instead.
If reloading a connection changes the UUID to a new value, the old
connection must be removed likewise and a new connection added.

Merge both functions into update_connection().
2015-01-13 12:14:37 +01:00
Thomas Haller
f41586f00c keyfile/trival: move code 2015-01-13 11:46:06 +01:00
Thomas Haller
fbd30c7dd2 keyfile: simplify g_return() checks for _internal_write_connection() 2015-01-13 11:44:05 +01:00
Thomas Haller
e14ea6818a settings: log connection diffs in replace_settings only where appropriate
Only log connection diffs when we update a connection that we actually
care about.

Note that most plugin specific connections use
nm_settings_connection_replace_settings() in their constructor
to initialize themselves. These occurrences are not interesting
and spam the logfile.
2015-01-13 11:44:05 +01:00
Thomas Haller
750f01dfcb settings: no need to check nm_connection_compare() before nm_settings_connection_replace_settings()
nm_settings_connection_replace_settings() does nothing, if there are no changes.
2015-01-13 11:23:22 +01:00
Thomas Haller
c2dc5d3b0f settings: fix wrong assertions for calling nm_settings_connection_replace_settings() 2015-01-13 11:23:22 +01:00
Thomas Haller
73703c4d19 core: log object type in nm_utils_log_connection_diff() 2015-01-13 11:23:22 +01:00
Thomas Haller
45094c71d8 core: log ignored property notification with level TRACE
Avoids for example:
  notify(): ignoring notification for prop visible on type NMKeyfileConnection
2015-01-13 11:23:22 +01:00
Jiří Klimeš
91fd36e166 ifnet: fix a crash in ifnet settings plugin (bgo #737645)
conn_name can be NULL now as the connections are tracked by UUID
(see commit 689dadaffb)

Sep 29 21:20:34 Jdeapad NetworkManager[1339]: <info> getting unmanaged specs...
Sep 29 21:20:34 Jdeapad NetworkManager[1339]: <info> Checking unmanaged: (null)
Sep 29 21:20:38 Jdeapad kernel: NetworkManager[1339]: segfault at 0 ip
00007f1bfffbedd0 sp 00007fff98daa628 error 4 in
libglib-2.0.so.0.4002.0[7f1bfff86000+130000]

https://bugzilla.gnome.org/show_bug.cgi?id=737645
2015-01-13 10:27:52 +01:00
Jiří Klimeš
5cf985e158 merge: accept numeric bonding modes (bgo #704666) (rh #1133544) (rh #1171009)
Bonding mode can be provided either as descriptive name of a numeric value
(on D-Bus and ifcfg-rh too).

https://bugzilla.gnome.org/show_bug.cgi?id=704666
https://bugzilla.redhat.com/show_bug.cgi?id=1133544
https://bugzilla.redhat.com/show_bug.cgi?id=1171009
2015-01-13 09:58:57 +01:00
Jiří Klimeš
c743670251 ifcfg-rh: add a testcase for numeric bonding mode values in BONDING_OPTS 2015-01-13 09:35:49 +01:00
Jiří Klimeš
3d1b6bd4d8 bond: normalize bond mode to string notation (rh #1171009)
Use descriptive string value as preferred bond mode representation.
Numeric modes still verify but with NM_SETTING_VERIFY_NORMALIZABLE,
suggesting a normalization action.

https://bugzilla.redhat.com/show_bug.cgi?id=1171009
2015-01-13 09:35:49 +01:00
Jiří Klimeš
93438dd092 libnm-core: accept numeric bond modes (bgo #704666) (rh #1133544)
https://bugzilla.gnome.org/show_bug.cgi?id=704666
https://bugzilla.redhat.com/show_bug.cgi?id=1133544
2015-01-13 09:35:49 +01:00
Jiří Klimeš
d787f0391b utils: add functions for converting string <-> numeric bonding modes 2015-01-13 09:35:49 +01:00
Thomas Haller
d9f143df8b platform: merge branch 'th/route-fixes-bgo741871-v2'
https://bugzilla.gnome.org/show_bug.cgi?id=741871
2015-01-12 20:08:10 +01: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
Thomas Haller
4f390e7e4d platform/tests: add test for deleting IPv4 route with metric 0 2015-01-12 20:02:06 +01:00
Thomas Haller
a6cd0e7a29 platform/tests: use assert_ip4_route_exists() function 2015-01-12 20:02:06 +01:00
Thomas Haller
b421af3730 platform/tests: add ip4_route_exists() test function 2015-01-12 20:02:06 +01:00
Thomas Haller
0f1fca29db platform/tests: fix errors in fake platform handling route metrics 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
Dan Williams
a687d1f9e0 core: ensure manager state is updated on resume with connectivity checking enabled (rh #1162636) (bgo #742675)
On resume configured interfaces are unmanaged to clear their pre-resume
state and then re-managed.  Eventually the interface should end up moving
to the DISCONNECTED state, which should trigger an auto-activate check in
the Policy.  If connectivity checking was enabled, that auto-activate check
would fail because the Manager's state was still NM_STATE_ASLEEP.

This caused bridge slaves not to auto-activate on resume, which left bridges
without connectivity.

The manager never left NM_STATE_ASLEEP when connectivity checking was
enabled due to nm_manager_update_state() returning early when kicking
off a connectivity check.  Instead, the manager's state should always
be updated to accurately reflect the current state.

https://bugzilla.redhat.com/show_bug.cgi?id=1162636
https://bugzilla.gnome.org/show_bug.cgi?id=742675
2015-01-12 09:57:13 -06:00
Lubomir Rintel
c9002c041d settings: fix up bad merge
Fixes: 24a464a7da
2015-01-12 16:44:17 +01:00