Commit Graph

21088 Commits

Author SHA1 Message Date
Thomas Haller
7b91e8b6db device: don't use platform singleton getter in device subclasses
Reduce the use of NM_PLATFORM_GET / nm_platform_get() to get
the platform singleton instance.

For one, this is a step towards supporting namespaces, where we need
to use different NMNetns/NMPlatform instances depending on in which
namespace the device lives.

Also, we should reduce our use of singletons. They are difficult to
coordinate on shutdown. Instead there should be a clear order of
dependencies, expressed by owning a reference to those singelton
instances. We already own a reference to the platform singelton,
so use it and avoid NM_PLATFORM_GET.

(cherry picked from commit 94d9ee129d)
2017-04-18 15:53:11 +02:00
Thomas Haller
8a6eef6aa7 device: keep NMNetns instance per device
This also ensures that we own a reference to the
NMPlatform, NMRouteManager and NMDefaultRouteManager
instances. See bug rh#1440089 where we might access
the singleton getter after destroing the singleton
instance of NMRouteManager. This is prevented by
keeping a reference to those instances -- indirectly
via the netns instance.

Later, we may add support for multiple namespaces. Then it might
make sense to swap the NMNetns instance of a device when moving
the device between namespaces.

Also, drop the use of singelton instances.

https://bugzilla.redhat.com/show_bug.cgi?id=1440089
(cherry picked from commit c48a19b7c6)
2017-04-18 15:53:11 +02:00
Thomas Haller
d37b9d79bc core: add NMNetns to bundle platform and route managers
NMPlatform, NMRouteManager and NMDefaultRouteManager are singletons
instances. Users of those are for example NMDevice, which registers
to GObject signals of both NMPlatform and NMRouteManager.

Hence, as NMDevice:dispose() disconnects the signal handlers, it must
ensure that those singleton instances live longer then the NMDevice
instance. That is usually accomplished by having users of singleton
instances own a reference to those instances.
For NMDevice that effectively means that it shall own a reference to
several singletons.

NMPlatform, NMRouteManager, and NMDefaultRouteManager are all
per-namespace. In general it doesn't make sense to have more then
one instances of these per name space. Nnote that currently we don't
support multiple namespaces yet. If we will ever support multiple
namespaces, then a NMDevice would have a reference to all of these
manager instances. Hence, introduce a new class NMNetns which bundles
them together.

(cherry picked from commit 0af2f5c28b)
2017-04-18 15:53:11 +02:00
Thomas Haller
9e8218f99a device: leave device up when setting it as unmanaged by user
Before, setting a device to unmanaged causes it to go down and clear
the interface state.

It may be useful to instruct NetworkManager not to touch the device
anymore but leave the current state up. Changing behavior for

  nmcli device set "$DEV" managed no

To get the previous behavior, one has to first disconnect the interface
via

  nmcli device disconnect "$DEV"
  nmcli device set "$DEV" managed no

Note that non-permanent addresses like from DHCP will eventually time
out because NetworkManager stops the DHCP client. When instructing
NetworkManager to let go of the device, you have to take it over in
any way you see fit.

https://bugzilla.redhat.com/show_bug.cgi?id=1371433
2017-04-18 15:52:44 +02:00
Thomas Haller
a31ddcfca5 core: merge branch 'th/netns-singleton-rh1440089'
https://bugzilla.redhat.com/show_bug.cgi?id=1440089
2017-04-18 15:52:01 +02:00
Thomas Haller
41148caba8 core: enable "log-with-ptr" by default for platform and route-manager
Arguably, we currently only have one instance of NMPlatform,
NMRouteManager, NMDefaultRouteManager -- the one owned by the
NMNetns singleton.

Hence, all these instances we create with "log-with-ptr" set explicitly
to false.

In the future we want to support namespaces, and it will be be common to
have multiple instances. For that we have "log-with-ptr" so we are able
to disambiguiate the logging.

Change the default to TRUE because it makes more sense. It has currently
no effect as the default is never used.
2017-04-18 15:49:14 +02:00
Thomas Haller
94d9ee129d device: don't use platform singleton getter in device subclasses
Reduce the use of NM_PLATFORM_GET / nm_platform_get() to get
the platform singleton instance.

For one, this is a step towards supporting namespaces, where we need
to use different NMNetns/NMPlatform instances depending on in which
namespace the device lives.

Also, we should reduce our use of singletons. They are difficult to
coordinate on shutdown. Instead there should be a clear order of
dependencies, expressed by owning a reference to those singelton
instances. We already own a reference to the platform singelton,
so use it and avoid NM_PLATFORM_GET.
2017-04-18 15:49:14 +02:00
Thomas Haller
c48a19b7c6 device: keep NMNetns instance per device
This also ensures that we own a reference to the
NMPlatform, NMRouteManager and NMDefaultRouteManager
instances. See bug rh#1440089 where we might access
the singleton getter after destroing the singleton
instance of NMRouteManager. This is prevented by
keeping a reference to those instances -- indirectly
via the netns instance.

Later, we may add support for multiple namespaces. Then it might
make sense to swap the NMNetns instance of a device when moving
the device between namespaces.

Also, drop the use of singelton instances.

https://bugzilla.redhat.com/show_bug.cgi?id=1440089
2017-04-18 15:49:14 +02:00
Thomas Haller
0af2f5c28b core: add NMNetns to bundle platform and route managers
NMPlatform, NMRouteManager and NMDefaultRouteManager are singletons
instances. Users of those are for example NMDevice, which registers
to GObject signals of both NMPlatform and NMRouteManager.

Hence, as NMDevice:dispose() disconnects the signal handlers, it must
ensure that those singleton instances live longer then the NMDevice
instance. That is usually accomplished by having users of singleton
instances own a reference to those instances.
For NMDevice that effectively means that it shall own a reference to
several singletons.

NMPlatform, NMRouteManager, and NMDefaultRouteManager are all
per-namespace. In general it doesn't make sense to have more then
one instances of these per name space. Nnote that currently we don't
support multiple namespaces yet. If we will ever support multiple
namespaces, then a NMDevice would have a reference to all of these
manager instances. Hence, introduce a new class NMNetns which bundles
them together.
2017-04-18 15:49:14 +02:00
Beniamino Galvani
a39fac2248 manager: set interface as removed when the link disappears
Set the device state as removed when the link disappears, so that in
the call to unrealize() when the device is unmanaged we also perform a
cleanup of it and especially, we terminate any DHCP client instances
running on the device.

If we keep DHCP clients running, we can hit assertions later when we
start another instance on the same interface, because we kill the old
dhclient from the pidfile, and the g_child_watch_add() done by the
first client instance is not able to waitpid() it, complaining with:

  GChildWatchSource: Exit status of a child process was requested but
  ECHILD was received by waitpid(). Most likely the process is
  ignoring SIGCHLD, or some other thread is invoking waitpid() with a
  nonpositive first argument; either behavior can break applications
  that use g_child_watch_add()/g_spawn_sync() either directly or
  indirectly.

https://bugzilla.redhat.com/show_bug.cgi?id=1436602
(cherry picked from commit df537d2eac)
2017-04-18 15:10:45 +02:00
Beniamino Galvani
df537d2eac manager: set interface as removed when the link disappears
Set the device state as removed when the link disappears, so that in
the call to unrealize() when the device is unmanaged we also perform a
cleanup of it and especially, we terminate any DHCP client instances
running on the device.

If we keep DHCP clients running, we can hit assertions later when we
start another instance on the same interface, because we kill the old
dhclient from the pidfile, and the g_child_watch_add() done by the
first client instance is not able to waitpid() it, complaining with:

  GChildWatchSource: Exit status of a child process was requested but
  ECHILD was received by waitpid(). Most likely the process is
  ignoring SIGCHLD, or some other thread is invoking waitpid() with a
  nonpositive first argument; either behavior can break applications
  that use g_child_watch_add()/g_spawn_sync() either directly or
  indirectly.

https://bugzilla.redhat.com/show_bug.cgi?id=1436602
2017-04-18 15:09:15 +02:00
Beniamino Galvani
afca8a4c0f clients: fix setting of enum properties
Ensure we call G_IS_ENUM_CLASS() or G_IS_FLAGS_CLASS() only on classed
types.

 $ nmcli connection modify foobar wifi.powersave 1
 Thread 1 "nmcli" received signal SIGSEGV, Segmentation fault.
 0x0000000000440a4d in _set_fcn_gobject_enum at
 clients/common/nm-meta-setting-desc.c:985
 985                 || G_IS_ENUM_CLASS (gtype_prop)) {

Fixes: f53218ed7c
2017-04-18 13:40:02 +02:00
Thomas Haller
297ad945f5 test: fix undefined behavior shifting signed integer in test
(cherry picked from commit d58d8d7518)
2017-04-18 09:45:03 +02:00
Lubomir Rintel
928d68d04a m4: disable -Wmissing-braces for newer clang
src/NetworkManagerUtils.c:347:18: error: suggest braces around initialization of subobject [-Werror,-Wmissing-braces]
          NMIPAddr a1 = { 0 }, a2 = { 0 };
                          ^
                          {}

Should we initialize unions this way? I think it's all right -- the initializer
works well and { { { 0 } } } is probably not what we'd like to see.

(cherry picked from commit 43012156a3)
2017-04-18 09:44:45 +02:00
Lubomir Rintel
fcad4fba16 platform: fix a typo
(cherry picked from commit c76ee5883d)
2017-04-18 09:43:43 +02:00
Dan Williams
589fc0179e ppp: allow disabling IPv4 too
https://bugzilla.redhat.com/show_bug.cgi?id=1439360
(cherry picked from commit a12b3f06cb)
2017-04-18 09:41:44 +02:00
Dan Williams
a12b3f06cb ppp: allow disabling IPv4 too
https://bugzilla.redhat.com/show_bug.cgi?id=1439360
2017-04-18 09:40:31 +02:00
Thomas Haller
d58d8d7518 test: fix undefined behavior shifting signed integer in test 2017-04-17 13:19:47 +02:00
Lubomir Rintel
bacb68f3f6 wifi/test-general: don't do g_message() in test
An unexpected message causes the test to abort after the first line of
output.
2017-04-15 12:30:05 +02:00
Lubomir Rintel
738c2fcefc clients/meta-setting-desc: fix an unintentional fallthrough
Fixes: ddfff04a45
2017-04-15 12:30:02 +02:00
Lubomir Rintel
43012156a3 m4: disable -Wmissing-braces for newer clang
src/NetworkManagerUtils.c:347:18: error: suggest braces around initialization of subobject [-Werror,-Wmissing-braces]
          NMIPAddr a1 = { 0 }, a2 = { 0 };
                          ^
                          {}

Should we initialize unions this way? I think it's all right -- the initializer
works well and { { { 0 } } } is probably not what we'd like to see.
2017-04-15 12:29:59 +02:00
Lubomir Rintel
c76ee5883d platform: fix a typo 2017-04-15 12:29:57 +02:00
Beniamino Galvani
03c2949a2c wifi: merge branch 'bg/wifi-pmf-bgo748367'
Support for 802.11w (Protected Management Frames).

https://bugzilla.gnome.org/show_bug.cgi?id=748367
2017-04-15 10:38:39 +02:00
Beniamino Galvani
72cfa1f458 supplicant: enable stronger AKMs when PMF is enabled 2017-04-15 10:37:33 +02:00
Beniamino Galvani
a72ffe230b supplicant: enable PMF only when wpa_supplicant supports it 2017-04-15 10:37:33 +02:00
Beniamino Galvani
d38eadd990 supplicant: enable PMF based on driver type
Instead of adding a new flag to configuration based on connection
type, use the driver-type field directly in the supplicant-interface.
2017-04-15 10:36:55 +02:00
Michael Cronenworth
8b051bb35e supplicant: Initial pmf support (a.k.a. MFP, a.k.a. 802.11w)
https://bugzilla.gnome.org/show_bug.cgi?id=748367

Signed-off-by: Michael Cronenworth <mike@cchtml.com>
2017-04-15 10:24:53 +02:00
Thomas Haller
acdf3d10cb core: merge branch 'th/route-zero-host-part-rh1439376'
https://bugzilla.redhat.com/show_bug.cgi?id=1439376

(cherry picked from commit fff918ec5a)
2017-04-15 00:37:40 +02:00
Thomas Haller
be19ec0739 core: ignore host part when comparing routes for route-manager
(cherry picked from commit b78562570a)
2017-04-15 00:37:22 +02:00
Thomas Haller
674b224bc1 route-manager: normalize host part of tracked routes in _vx_route_sync()
The input list of routes is allowed to contain non-normalized routes,
that is, routes which host part is non-zero. Such routes are rejected
by kernel, but NM should transparently allow them (by normalizing
the host part).

The ID comparison function route_id_cmp() already properly ignored
the (possibly non-zero) host part. However, in the internal list we
also should make sure not to track such routes. We achive that by
normalizing the host part to zero.

Note that below we check whether the tracked route is idential to
the route configured at platform. If we don't normalize the host part,
the comparison will always indicate that the route is not yet
configured, and thus we will re-sync the route every time.

(cherry picked from commit 5c54b7a31e)
2017-04-15 00:37:22 +02:00
Thomas Haller
b32bb36c61 src: only compare network parts of routes in nm_utils_match_connection()
Kernel requires that routes have a host part of zero. For NetworkManager
configuration we allow non-zero host parts (but ignore them). Fix
route_compare() to ignore the host part.

This has only effect during assuming connections. That means, on
restart NM would fail to match a connection with static routes
if it has a non-zero host part. So, the impact is rather small.

(cherry picked from commit 034b7fb51c)
2017-04-15 00:37:22 +02:00
Thomas Haller
ae8d98391a platform: only consider net part of routes for route cache's ID
Routes with a non-zero host part are not allowed by kernel and
don't really exist. We didn't reject such routes in users configuration,
so various part of NM allow such routes. NM should silently strip
the host part.

Extend the cache's route ID to clear the host part too.

Note that NM's handling of routes is fundamentally flawed, as
for kernels routes don't have an "id" (or rather: all properties
of a route are part of it's ID, not only the family,ifindex,
network/plen and metric tuple (see related bug rh#1337855).

(cherry picked from commit 57b0dce083)
2017-04-15 00:37:22 +02:00
Thomas Haller
514d79fc85 platform: cleanup possibly non-zero host part for route operations
Platform's add/remove operations accept a "network" argument.
Kernel requires that the host part (based on plen) is all zero.
For NetworkManager we are more resilient to user configuration.

Cleanup the input argument already before calling _nl_msg_new_route().
Note that we use the same "network" argument to construct a obj_id
instance and to find the route in the cache (do_add_addrroute()).
Without cleaning the host part, the added object cannot be found
and the add-route command seemingly fails.

(cherry picked from commit 11d8c41898)
2017-04-15 00:37:22 +02:00
Thomas Haller
fff918ec5a core: merge branch 'th/route-zero-host-part-rh1439376'
https://bugzilla.redhat.com/show_bug.cgi?id=1439376
2017-04-15 00:35:46 +02:00
Thomas Haller
b78562570a core: ignore host part when comparing routes for route-manager 2017-04-15 00:35:25 +02:00
Thomas Haller
5c54b7a31e route-manager: normalize host part of tracked routes in _vx_route_sync()
The input list of routes is allowed to contain non-normalized routes,
that is, routes which host part is non-zero. Such routes are rejected
by kernel, but NM should transparently allow them (by normalizing
the host part).

The ID comparison function route_id_cmp() already properly ignored
the (possibly non-zero) host part. However, in the internal list we
also should make sure not to track such routes. We achive that by
normalizing the host part to zero.

Note that below we check whether the tracked route is idential to
the route configured at platform. If we don't normalize the host part,
the comparison will always indicate that the route is not yet
configured, and thus we will re-sync the route every time.
2017-04-15 00:35:25 +02:00
Thomas Haller
034b7fb51c src: only compare network parts of routes in nm_utils_match_connection()
Kernel requires that routes have a host part of zero. For NetworkManager
configuration we allow non-zero host parts (but ignore them). Fix
route_compare() to ignore the host part.

This has only effect during assuming connections. That means, on
restart NM would fail to match a connection with static routes
if it has a non-zero host part. So, the impact is rather small.
2017-04-15 00:35:25 +02:00
Thomas Haller
57b0dce083 platform: only consider net part of routes for route cache's ID
Routes with a non-zero host part are not allowed by kernel and
don't really exist. We didn't reject such routes in users configuration,
so various part of NM allow such routes. NM should silently strip
the host part.

Extend the cache's route ID to clear the host part too.

Note that NM's handling of routes is fundamentally flawed, as
for kernels routes don't have an "id" (or rather: all properties
of a route are part of it's ID, not only the family,ifindex,
network/plen and metric tuple (see related bug rh#1337855).
2017-04-15 00:35:25 +02:00
Thomas Haller
11d8c41898 platform: cleanup possibly non-zero host part for route operations
Platform's add/remove operations accept a "network" argument.
Kernel requires that the host part (based on plen) is all zero.
For NetworkManager we are more resilient to user configuration.

Cleanup the input argument already before calling _nl_msg_new_route().
Note that we use the same "network" argument to construct a obj_id
instance and to find the route in the cache (do_add_addrroute()).
Without cleaning the host part, the added object cannot be found
and the add-route command seemingly fails.
2017-04-15 00:35:25 +02:00
Thomas Haller
0a3fdf6604 vpn: merge branch 'th/vpn-disconnect-rh1442064'
https://bugzilla.redhat.com/show_bug.cgi?id=1442064

(cherry picked from commit 6e67f7f30b)
2017-04-15 00:32:52 +02:00
Thomas Haller
6bfd9b4e85 vpn: inline call_plugin_disconnect()
There is only one caller. Don't bother moving the logic to a separate
function.

(cherry picked from commit b23484be72)
2017-04-15 00:32:23 +02:00
Thomas Haller
e6b1a31106 vpn: avoid calling call_plugin_disconnect() without proxy
Got an assertion due to priv-proxy unset.
  NMDevice:
    - _platform_link_cb_idle()
     - nm_device_unrealize() [NMDeviceTun]
      - nm_device_state_changed()
       - _set_state_full()
         NMVpnConnection:
           - _set_vpn_state()
            - call_plugin_disconnect()

It seam to me, that can only happen if the NMVpnConnection never
completed on_proxy_acquired() and is still in preparing state when
being disconnected.

Avoid that be checking whether we have a proxy.

https://bugzilla.redhat.com/show_bug.cgi?id=1442064
(cherry picked from commit bc1d1c9df4)
2017-04-15 00:32:22 +02:00
Thomas Haller
6e67f7f30b vpn: merge branch 'th/vpn-disconnect-rh1442064'
https://bugzilla.redhat.com/show_bug.cgi?id=1442064
2017-04-15 00:31:34 +02:00
Thomas Haller
b23484be72 vpn: inline call_plugin_disconnect()
There is only one caller. Don't bother moving the logic to a separate
function.
2017-04-15 00:31:23 +02:00
Thomas Haller
bc1d1c9df4 vpn: avoid calling call_plugin_disconnect() without proxy
Got an assertion due to priv-proxy unset.
  NMDevice:
    - _platform_link_cb_idle()
     - nm_device_unrealize() [NMDeviceTun]
      - nm_device_state_changed()
       - _set_state_full()
         NMVpnConnection:
           - _set_vpn_state()
            - call_plugin_disconnect()

It seam to me, that can only happen if the NMVpnConnection never
completed on_proxy_acquired() and is still in preparing state when
being disconnected.

Avoid that be checking whether we have a proxy.

https://bugzilla.redhat.com/show_bug.cgi?id=1442064
2017-04-15 00:31:23 +02:00
Beniamino Galvani
9029dabb87 cli: check for deactivation failures
If the D-Bus call to DeactivateConnection() fails, don't wait for the
connection to change state because this is not going to
happen. Instead, notify the user of the error and, if necessary, wait
for remaining connections to be deactivated.

https://bugzilla.redhat.com/show_bug.cgi?id=1422786
(cherry picked from commit 67d144dd1e)
2017-04-13 17:19:40 +02:00
Beniamino Galvani
67d144dd1e cli: check for deactivation failures
If the D-Bus call to DeactivateConnection() fails, don't wait for the
connection to change state because this is not going to
happen. Instead, notify the user of the error and, if necessary, wait
for remaining connections to be deactivated.

https://bugzilla.redhat.com/show_bug.cgi?id=1422786
2017-04-13 17:18:34 +02:00
Beniamino Galvani
45bef0ad17 cli: fix evaluation of supported settings for *-slave connections
To determine the valid settings we must consider the actual connection
type, not the user-supplied one because, for example, "bridge-slave"
is in fact an ethernet connection.

Fixes: fb8fe1d8cb

https://bugzilla.redhat.com/show_bug.cgi?id=1440957
2017-04-13 15:35:37 +02:00
Lubomir Rintel
55ad538cfb libnm-glib/secret-agent: don't error out on missing out_connection
It's perfectly valid to call the function with out_connection == NULL
when connection_hash == NULL too, as cancel_get_secrets() does.

Fixes: fbb1662269
(cherry picked from commit c4a0002f05)
2017-04-13 14:45:58 +02:00
Lubomir Rintel
c4a0002f05 libnm-glib/secret-agent: don't error out on missing out_connection
It's perfectly valid to call the function with out_connection == NULL
when connection_hash == NULL too, as cancel_get_secrets() does.

Fixes: fbb1662269
2017-04-13 14:43:17 +02:00