Commit graph

1696 commits

Author SHA1 Message Date
Thomas Haller
cac0738723 device: change hw_addr_type field to bitfield type
We don't want to waste a full "int" size to store the @hw_addr_type
in NMDevicePrivate. Previously, that was hacked around by using guint8.

Now, instead use a bitfield which has the right type.
2017-02-10 14:40:23 +01:00
Thomas Haller
5151a6071f device: inline device helper structs QueuedState and PingInfo
These two structs are only used at exactly one place: as the type
for a field in NMDevicePrivate.

Having additional structs (that are only used at one place) only
add noise. Also, there are already prior-acts of using unnamed
structs in NMDevicePrivate in case of structs that only serve
to group/namespace a set of fields.
2017-02-10 14:40:23 +01:00
Thomas Haller
e347d96596 device: prepend pending actions list
The order doesn't matter, so prepend instead of append new items
to the pending-actions list.
2017-02-10 14:40:23 +01:00
Thomas Haller
3bc1e02adf device: don't clone pending-action string
All callers either use a static @action argument or keep a clone
of the string that lives as long as the action is pending. So,
save cloning the string.
2017-02-10 14:40:23 +01:00
Thomas Haller
8ac14b5400 device: implement queued_state_to_string() via NM_UTILS_LOOKUP_STR_DEFINE_STATIC() 2017-02-10 14:40:23 +01:00
Thomas Haller
e234673a4a device: refactor pending-action strings as named defines 2017-02-10 14:40:23 +01:00
Thomas Haller
252e95c113 device: queue recheck-available before removing "wait for supplicant" pending action
While we still recheck-available, we want to queue a pending action to block
startup-complete. However, we have to queue that before removing the pending
action for "wait for supplicant".

  <debug> [...] device[0x563abbcca400] (wlp2s0): remove_pending_action (0): 'waiting for supplicant'
  <info>  [...] manager: startup complete
  <debug> [...] device[0x563abbcca400] (wlp2s0): add_pending_action (1): 'queued state change to disconnected'
2017-02-10 14:40:23 +01:00
Thomas Haller
11744b090e device: add pending-action "recheck-available"
Startup-complete means that all devices have settled in a state
and no further activation is pending. When we have a recheck-available
scheduled, we clearly should not yet declare startup-complete.

Add a new pending-action "recheck-available" to avoid:

  <info>  [1485520408.3920] device (wlp2s0): supplicant interface state: starting -> ready
  <debug> [1485520408.3920] device[0x563abbcca400] (wlp2s0): remove_pending_action (0): 'waiting for supplicant'
  <info>  [1485520408.3920] manager: startup complete
  <debug> [1485520408.3924] device[0x563abbcca400] (wlp2s0): add_pending_action (1): 'queued state change to disconnected'
2017-02-10 14:40:23 +01:00
Thomas Haller
95a95b3e48 core: use define for GObject property name NM_SUPPLICANT_INTERFACE_SCANNING
grep-ing for '\<scanning\>' yields 42 hits under src. But only 2 are actual
references to the "scanning" GObject property of NMDeviceWifi.

Use a #define with a unique name where we mean NMDeviceWifi's property.
2017-02-10 14:40:23 +01:00
Thomas Haller
dc40288849 all: use NM_CACHED_QUARK_FCN() to define cached quarks 2017-02-10 14:33:52 +01:00
Thomas Haller
8538b61eb6 core: use cached GQuark and g_object_[gs]et_qdata()
Use g_object_[gs]et_qdata() instead of g_object_[gs]et_data() with a cached
quark. This saves an additional lookup to intern the string.
2017-02-10 14:33:52 +01:00
Beniamino Galvani
0683ad5db2 bond: fix crash in update_connection()
The value read from sysfs can be NULL.

Fixes: 2324410a75
2017-02-07 11:05:01 +01:00
Thomas Haller
7c6c8f0d8b all: cleanup switch fall-through comments for -Wimplicit-fallthrough warning
The -Wimplicit-fallthrough=3 warning is quite flexible of accepting
a fall-through warning.

Some comments were missing or not detected correctly.

Thereby, also change all other comments to follow the exact
same pattern.
2017-02-06 16:45:20 +01:00
Thomas Haller
11bc3f191e all: use nm_utils_strv_find_first() from shared/nm-utils 2017-02-04 17:55:30 +01:00
Thomas Haller
146f2c0bd1 device: track exported-object path for NMActRequest from device
The public property NM_DEVICE_ACTIVATION_REQUEST exposes the exported
D-Bus path. So, it's not sufficient to emit property changed signals
when changing the priv->act_request pointer, we must also react on
exporting/unexporting.

It's not clear whether this fixes an actual bug. Maybe, we never
export/unexport priv->act_request while the device tracks it.
But the code is pretty hard to follow and it's hard to verify
whether this is the case.
By hooking up to "notify::path", we can easily verify that such
a situtation cannot arise.

(cherry picked from commit 9ae5e6a54d)
2017-01-25 17:27:42 +01:00
Thomas Haller
105d8a2447 device: fix setting minimal MTU to 1280 for IPv6
Fixes: 665e398022
(cherry picked from commit ec66135a40)
2017-01-24 16:38:21 +01:00
Thomas Haller
ba1cc6a288 core: refactor evaluation of device's match-spec
Previously, we would have different functions like
  - nm_match_spec_device_type()
  - nm_match_spec_hwaddr()
  - nm_match_spec_s390_subchannels()
  - nm_match_spec_interface_name()
which all would handle one type of match-spec.

So, to get the overall result whether the arguments
match or not, nm_device_spec_match_list() had to stich
them together and iterate the list multiple times.

Refactor the code to have one nm_match_spec_device()
function that gets all relevant paramters.

The upside is:

  - the logic how to evaluate the match-spec is all at one place
    (match_device_eval()) instead of spread over multiple
    functions.

  - It requires iterating the list at most twice. Twice, because
    we do a fast pre-search for "*".

One downside could be, that we have to pass all 4 arguments
for the evaluation, even if the might no be needed. That is,
because "nm-core-utils.c" shall be independend from NMDevice, it
cannot receive a device instance to get the parameters as needed.
As we would add new match-types, the argument list would grow.
However, all arguments are cached and fetching them from the
device's private data is very cheap.

(cherry picked from commit b957403efd)
2017-01-20 21:18:30 +01:00
Beniamino Galvani
2e8af781c5 device: don't call _commit_mtu() when ipv4.method=disabled
After commit 553717bb1c ("device: don't set ip4_state=IP_FAIL for
ipv4.method=disabled"), we commit an empty IPv4 configuration when
IPv4 is disabled. This means that it's not necessary anymore to call
_commit_mtu() because the MTU will be set in
ip4_config_merge_and_apply().

(cherry picked from commit 714b18dcf7)
2017-01-20 18:43:48 +01:00
Beniamino Galvani
303a65b4dd vlan: use parent interface mtu as default
After commit 22e8af6242 ("device: set a per-device default MTU on
activation") we explicitly set the VLAN MTU to 1500 if not overridden
by user settings. This has the advantage that the MTU is set to a
predictable value, while before it could have different values
depending on when the interface was created (for example, the
interface would get a 1500 MTU if created during boot, or would
inherit the parent's MTU if activated manually).

However, a better default value is the MTU of the parent interface
which is in most cases what the user wants. This value was the default
before commit 22e8af6242 for manually activated connections.

https://bugzilla.redhat.com/show_bug.cgi?id=1414186
(cherry picked from commit 7dde8d8106)
2017-01-20 18:43:48 +01:00
Thomas Haller
29a8116fd0 device: mark properties in set_property() as construct-only
(cherry picked from commit ba47744997)
2017-01-20 17:41:09 +01:00
Thomas Haller
3b69a05fa0 device: remove duplicate setting of device's driver property
Fixes: 4dbaac4ba2
(cherry picked from commit 59f37f31d9)
2017-01-20 17:11:56 +01:00
Lubomir Rintel
c2b9bb1844 veth: properly chain up the overridden notify method
Fixes: 992beb4f34
(cherry picked from commit af16cd5a92)
2017-01-20 16:29:53 +01:00
Lubomir Rintel
9d431169c3 device: fix build with old glib & more asserts
src/devices/nm-device.c:8319:4: error: invalid use of void expression

(cherry picked from commit a4d61bf299)
2017-01-19 14:24:29 +01:00
Lubomir Rintel
de0df39646 device: add an initializer
Basically to silence gcc that is not smart enough to understand how does
.initialized and .value relate.

  src/devices/nm-device.c: In function '_commit_mtu':
  src/devices/nm-device.c:6754:15: error: 'ip6_mtu_sysctl.value' may be used uninitialized in this function [-Werror=maybe-uninitialized]
     if (ip6_mtu && ip6_mtu != _IP6_MTU_SYS ()) {
                 ^

(cherry picked from commit 7ce805d49d)
2017-01-17 22:54:17 +01:00
Thomas Haller
be813707f0 device: make the MTU globally configurable via connection-defaults
This allows a user to restore the previous behavior where NetworkManager
would not reconfigure the MTU during device activation, if no MTU is
available (commit "22e8af6 device: set a per-device default MTU on
activation").

Well, not exactly. The previous behavior was to use per-connection
configuration, then DHCP provided value, or finally leave the MTU
unspecified.
Now, we prefer a per-connection configuration, followed by a global
connection default. If "ethernet.mtu=0", the MTU is left unspecified.
In absense of a global connection default, the value from DHCP is used
or finally a per-device-type default. That is effectively 1500 for most
types, except for infiniband where the MTU is still left unspecified.
2017-01-17 13:43:50 +01:00
Lubomir Rintel
5b51a5f260 platform/tun: don't passing around the ifname guess
nm_platform_sysctl_open_netdir() doesn't take it anyways, gets it from
the cache.

CID 160209 (#1 of 1): Unused value (UNUSED_VALUE)
2017-01-16 22:14:47 +01:00
Beniamino Galvani
808b1a0f61 core: support macsec connections
Add code to nm-device-macsec.c to support the creation of macsec
connection. Most of the code for controlling wpa_supplicant is copied
from nm-device-ethernet.c and probably could be consolidated in some
ways.
2017-01-16 17:47:09 +01:00
Beniamino Galvani
0150b644ed supplicant: add an enum to specify the driver
With macsec we now have 3 drivers and a boolean is no longer enough.
2017-01-16 17:37:14 +01:00
Beniamino Galvani
67adbda83e core,libnm: introduce NMDeviceMacsec
At the moment the device only exposes the current link status, but
cannot create new links.
2017-01-16 17:37:14 +01:00
Beniamino Galvani
00463a6e09 ethernet: simplify supplicant error path
Replace the custom supplicant_iface_connection_error_cb_handler() with
nm_device_queue_state().
2017-01-16 17:37:14 +01:00
Thomas Haller
665e398022 device: enforce a link MTU of at least 1280 for connections with IPv6 2017-01-16 17:30:12 +01:00
Thomas Haller
22e8af6242 device: set a per-device default MTU on activation
In absence of an explicit MTU (either via user configuration, PPP or
DHCP), set a default MTU on activation that depends on the device type.

We only want to do that on the very first call to _commit_mtu(). Later
calls (for example in response to new DHCP leases) skip over this step.

This means, on activation the MTU will always be reset to a sensible
value instead of preserving whatever was left from a previous
configuration.

This does not cover setting the MTU from the VPN plugin :(
2017-01-16 17:30:12 +01:00
Thomas Haller
1e67c7ac0b device: reset previous MTU when device disconnects
When you have a connection with "ethernet.mtu=0 (auto)", the MTU is not set
during activation. That means, the effective MTU depends on the previous
MTU configuration of the device. Which in turn, depends on the
previously active connection, as we don't reset the MTU on deactivation.

Restore the previous MTU on deactivation iff NetworkManager changed
the MTU during device activation.
2017-01-16 17:29:44 +01:00
Thomas Haller
b5fcbdf594 device: refactor configuring MTU by dropping mtu_desired
Don't have this mtu_desired variable. All the data is readily available
without redundancy. E.g. the applied-connection contains everything
we need to know. Just get it as needed.

Also drop apply_mtu_from_config(). It didn't take into account
the MTU settings beside NMSettingWired.

Also, no longer merge the NM_IP_CONFIG_SOURCE_USER MTU value into
priv->ip4_config. NMIP4Config now only tracks the MTU from the various
non-user-config sources, but the user config is no longer merged back
into the composite.
2017-01-16 17:29:44 +01:00
Thomas Haller
797ad260e6 device/bridge: support setting bridge MTU via wired setting
The problem is that the bridge's MTU cannot be larger then the slaves'.
Configuring such a setting results in an error being logged and the
activation proceeds (without applying the desired MTU).

Unclear how to fix that best.
2017-01-16 17:29:44 +01:00
Thomas Haller
6e52efe950 device: refactor setting user-configured MTU during config commit
Instead of overwriting ip4_config_pre_commit(), add a new function
get_mtu().

This also adds a default value in case there is no user-configuration.
This will allow us later to reset a default MTU based on the device
type.
2017-01-16 17:29:06 +01:00
Thomas Haller
0210754f18 device: refactor handling of MTU in device
The field priv->mtu should contain what is actually configured
on the device, as that field is also exposed on D-Bus as NM_DEVICE_MTU
property.

That shall be handled distinct from what we want to configure as
MTU on the device.

Refactor the handling of MTU with a new functoin _set_mtu() which looks
at the desired paramters and compares it with what is configured (in
platform and sysctl). Then it makes a decision what to configure.
2017-01-16 17:24:36 +01:00
Thomas Haller
be4442bd0d device: cleanup setting of mtu in NMDevice
Mark priv->mtu/priv->ip_mtu/ priv->ip6_mtu as const to highlight the
places that explicitly set their mutable aliases priv->mtu_/
priv->ip_mtu_/priv->ip6_mtu_.

Also, NM_DEVICE_MTU property is read-only. It cannot be set
via g_object_set().

Also, clear priv->mtu in nm_device_unrealize().
2017-01-16 17:24:36 +01:00
Thomas Haller
5051a04d81 device: drop unused virtual function NMDevice:ip6_config_pre_commit 2017-01-16 17:24:36 +01:00
Thomas Haller
c69ad50b07 device: fix indention and assertion in apply_mtu_from_config()
For the assertion use nm_streq0(). If we bother checking for invalid
values (that are supposed to never happen), avoid a possible crash too.
2017-01-16 17:24:36 +01:00
Thomas Haller
f0cd2403d4 device: fix sysctl getter for MTU using guint32 type
The only caller wants to read the MTU, which is more
type guint32 then gint32.
2017-01-16 17:24:36 +01:00
Thomas Haller
0bb1e9a116 ip[46]-config/trivial: move code around
Move the GObject related functions to the end of the source file.
Similar to how it's done for most other implementations.
2017-01-16 17:24:36 +01:00
Thomas Haller
175ef8f611 ppp: use defines for signal names 2017-01-16 17:24:36 +01:00
Thomas Haller
85c38d18a0 device: cleanup converting mtu to string for sysctl_set()
Use %u for unsigned type and cast the guint32 to (unsigned).
While at it, increase the stack-allocated buffer to 64 bytes
(it doesn't hurt) and use nm_sprintf_buf().
2017-01-13 11:14:12 +01:00
Dan Williams
8de7b8ed31 device/wwan: indicate whether IP iface/ifindex changed and simplify WwAN code
Replace some code in the WWAN device class that checks for a changed
interface name with code that uses the new return value from
nm_device_set_ip_iface(), which now checks whether the ip_ifindex
changed too.

https://mail.gnome.org/archives/networkmanager-list/2017-January/msg00010.html
2017-01-12 13:34:22 +01:00
Thomas Haller
bf3b3d444c device: avoid changing immutable properties during reapply
We allow to reapply a connection with different id, uuid, stable-id, autoconnect value.
This is allowed for convenience, so that a user can reapply a connection that differs
in these fields. But actually, these fields cannot be reapplied. That
is, their new values are not considered and the old values are continued
to be used.

Thus, mangle the reapplied connection to use the original, actually used
values.
2017-01-12 13:02:25 +01:00
Thomas Haller
304e2f56af device: allow reapplying a connection with differing stable-id
The stable-id for one activation cannot actually change. This is also, because we cache it
as priv->current_stable_id. Still, allow reapply with a differing stable-id for convenience.
2017-01-12 12:59:07 +01:00
Thomas Haller
be1f04038d device: fix invalid assertion
Fixes: f0d40525df
2017-01-09 20:24:23 +01:00
Thomas Haller
f0d40525df device: support dynamic "connection.stable-id" in form of text-substitution
Usecase: when connecting to a public Wi-Fi with MAC address randomization
("wifi.cloned-mac-address=random") you get on every re-connect a new
IP address due to the changing MAC address.
"wifi.cloned-mac-address=stable" is the solution for that. But that
means, every time when reconnecting to this network, the same ID will
be reused. We want an ID that is stable for a while, but at a later
point a new ID should e generated when revisiting the Wi-Fi network.

Extend the stable-id to become dynamic and support templates/substitutions.
Currently supported is "${CONNECTION}", "${BOOT}" and "${RANDOM}".
Any unrecognized pattern is treated verbaim/untranslated.

"$$" is treated special to allow escaping the '$' character. This allows
the user to still embed verbatim '$' characters with the guarantee that
future versions of NetworkManager will still generate the same ID.
Of course, a user could just avoid '$' in the stable-id unless using
it for dynamic substitutions.

Later we might want to add more recognized substitutions. For example, it
could be useful to generate new IDs based on the current time. The ${} syntax
is extendable to support arguments like "${PERIODIC:weekly}".

Also allow "connection.stable-id" to be set as global default value.
Previously that made no sense because the stable-id was static
and is anyway strongly tied to the identity of the connection profile.
Now, with dynamic stable-ids it gets much more useful to specify
a global default.

Note that pre-existing stable-ids don't change and still generate
the same addresses -- unless they contain one of the new ${} patterns.
2017-01-09 14:50:33 +01:00
Lubomir Rintel
260563a7d9 all: use nm_utils_is_valid_iface_name() 2017-01-06 15:11:56 +01:00