Commit Graph

17390 Commits

Author SHA1 Message Date
Thomas Haller
c429951c46 libnm: track invalid user data separately and reject during verify()
nm_setting_user_set_data() rejects invalid keys and values, and
can fail. This API is correct never to fail, like the get_data()
only returns valid user-data.

However, the g_object_set() API allows to set the hash directly but
it cannot report errors for invalid values. This API is used to
initialize the value from D-Bus or keyfile, hence it is wrong
to emit g_critial() assertions for untrusted data.
It would also be wrong to silently drop all invalid date, because
then the user cannot get an error message to understand what happend.

The correct but cumbersome solution is to remember the invalid values
separately, so that verify() can report the setting as invalid.

(cherry picked from commit 1dbbf6fb03)
2017-05-06 14:53:05 +02:00
Thomas Haller
f38878c997 keyfile: fix handling unsupported characters in keys
vpn.data, bond.options, and user.data encode their values directly as
keys in keyfile. However, keys for GKeyFile may not contain characters
like '='.

We need to escape such special characters, otherwise an assertion
is hit on the server:

  $ nmcli connection modify "$VPN_NAME" +vpn.data 'aa[=value'

Another example of encountering the assertion is when setting user-data key
with an invalid character "my.this=key=is=causes=a=crash".

(cherry picked from commit 8ef57d0f7e)
2017-05-06 14:52:29 +02:00
Thomas Haller
2ab5537b20 keyfile: minor refactoring dropping temporary variable in mac_address_parser()
(cherry picked from commit 095c6f5d53)
2017-05-06 14:52:29 +02:00
Thomas Haller
e7b32fb2b8 keyfile: fix memleak in read_hash_of_string()
Fixes: 10661abe17
(cherry picked from commit cb33e3f3c2)
2017-05-06 14:52:29 +02:00
Beniamino Galvani
1d08391ed1 all: fix typo 'entires' -> 'entries'
(cherry picked from commit a4cbfe6f0a)
2017-05-05 19:16:39 +02:00
Beniamino Galvani
8f4caab601 device: synchronize IPv6 configuration in stage3
Most of the IPv6 methods require a non-tentative link local address
configured on the interface; we look at priv->ip6_config to determine
if such address exist. If the configuration is out-of-sync, we may
proceed with configuration when the link-local address does not exist
or is still tentative, especially because we toggle the "disable_ipv6"
sysctl parameter just before, which clears all IPv6 addresses on the
interface.

Ensure that priv->ip6_config is up-to-date before continuing with the
IPv6 configuration.

Fixes test: @ipv6_set_ra_announced_mtu

(cherry picked from commit 78b43f7ea1)
2017-05-05 19:00:22 +02:00
Thomas Haller
1530cb457d device/firewall: merge branch 'th/firewall-apply-early-rh1445242'
https://bugzilla.redhat.com/show_bug.cgi?id=1445242

(cherry picked from commit 4c0a377a7a)
2017-05-05 14:50:33 +02:00
Thomas Haller
4f2aeb7c82 device: track firewall state and reset zone during activation
nm_device_update_firewall_zone() would only reconfigure the firewall
zone when the device is fully activated. That means, while the device
is activating, changing the firewall zone is not working. Activation
might take a long time with DHCP, or with master devices waiting
for their slaves.

For example:

  nmcli connection add type team con-name t-team ifname i-team autoconnect no
  nmcli connection up t-team

Note how t-team/i-team is waiting for a slave device. During stage3,
we already set firewall.zone to default.

  nmcli connection modify t-team connection.zone external

Note how changing the firewall zone does not immidiately take
effect. Only later, during IP_CHECK state the firewall zone
is reset -- but only for devices with differing ip_ifindex.

https://bugzilla.redhat.com/show_bug.cgi?id=1445242
(cherry picked from commit 20ccbb97d5)
2017-05-05 14:50:06 +02:00
Thomas Haller
054f9d8c33 device: fix changing firewall zone during _set_state_full()
For regular devices that don't have a separate ip_iface/ip_ifindex,
the ip_ifindex is left at zero. Hence, the condition is always
true and does not work as intended, resulting in setting the
firewall zone twice.

Fixes: 7cf5c326bc
(cherry picked from commit baa8b4029c)
2017-05-05 14:50:05 +02:00
Francesco Giudici
74dac5f516 nm-manager: try assuming connections on managed devices
Commit 850c97795 ("device: track system interface state in NMDevice")
introduced interface states for devices and prevented checking if a
connection should be assumed on already managed devices.
This prevented to properly manage the event of an ip configuration added
externally to NM to a managed but not (yet) activated device.

Fixes: 850c977953
(cherry picked from commit acf1067a45)
2017-05-04 17:12:03 +02:00
Beniamino Galvani
40dadc7ac4 device: fix behavior for assumed DHCP connections
When a DHCP connection is active and the DHCP server is temporarily
unreachable, we restart DHCP for some times before failing the
connection. From the user point of view, restarting NM (and thus
assuming the existing connection) should not change this behavior.

However, if NM is restarted while the server is temporarily down, at
the moment we immediately fail because we consider the DHCP
transaction our first try. Fix this by restoring the multiple tries
when we detect that DHCP was active before because the connection is
assumed.

(cherry picked from commit e3113fdc4b)
2017-05-04 11:26:19 +02:00
Francesco Giudici
5651f0cef6 device: add default route penalty only if concheck is enabled
If we don't have connection checking functionality just avoid adding
a penalty to the defaut route of newly activated connections.

(cherry picked from commit 2524a6f852)
2017-05-04 11:18:28 +02:00
Beniamino Galvani
aaaa35a89e device: let slaves wait in IP_CONFIG until master is ready
We call nm_device_activate_stage3_ipX_start() in various places,
e.g. after a carrier change or when a master enslaves a new device to
configure IP for the device. If the device is a slave in state
IP_CONFIG, this makes it transition to IP_CHECK, while it should stay
in IP_CONFIG until the master becomes ready. When the master is ready,
it will move slaves directly to SECONDARIES, skipping IP configuration
entirely.

(cherry picked from commit 41f6540afd)
2017-05-04 10:29:48 +02:00
Thomas Haller
9573d60023 device: avoid integer overflow with route-metric penalty
(cherry picked from commit bd805b7e49)
2017-05-02 18:39:45 +02:00
Thomas Haller
f1469558c0 policy: fix memleak in lookup_callback() and cancelling
When the operation is cancelled, we must not touch user_data. Note that
NM_POLICY_GET_PRIVATE() theoretically doesn't dereference the pointer
(does it?) but doing pointer arithmetic on a dangling pointer is a very
ugly thing to do.

And of course, the memleak.

Fixes: 5c716c8af8
Fixes: a2cdf63204
(cherry picked from commit 3215508293)
2017-05-02 18:24:53 +02:00
Beniamino Galvani
c030bd3049 dhcp: dhclient: fix timeout greater than 60 seconds
The default timeout in dhclient is 60 seconds; if a lease can't be
obtained during such interval, dhclient sends to NM a FAIL event and
then the IP method fails.

Thus, even if user specified a greater dhcp-timeout, NM terminated
DHCP after 60 seconds. Fix this by passing an explicit timeout to
dhclient.

(cherry picked from commit 82ef497cc9)
2017-05-02 15:31:48 +02:00
Thomas Haller
20ef91879c ifcfg-rh/tests: fix test_write_unknown() after change svGetValue() for invalid values
Fixes: daaa741a3d
(cherry picked from commit 43c3501f97)
2017-04-27 17:56:07 +02:00
Lubomir Rintel
d21b21eba1 ifcfg-rh: preserve the archaic NETMASK key
py-kickstart writes this out and there apparently are users using this.
Let them have one less problem.

Co-Authored-By: Thomas Haller <thaller@redhat.com>

https://bugzilla.redhat.com/show_bug.cgi?id=1445414
(cherry picked from commit dbe0659ba419a77ad5ff2340bfc93c71a1bec61a)
2017-04-27 17:26:26 +02:00
Lubomir Rintel
40b39844fa ifcfg-rh: preserve the archaic BOOTPROTO=static form
py-kickstart writes this out. Okay -- we don't care on read and it makes
sense when there actually are addresses.

https://bugzilla.redhat.com/show_bug.cgi?id=1445414
(cherry picked from commit aa50dfc236b3806c6d7161cdea450655a1268f0d)
2017-04-27 17:26:26 +02:00
Thomas Haller
8d2ceac897 ifcfg-rh: treat a wrongly quoted value like empty string
For example, if you want to test whether a value is present and
reset it to a different value (only if it is present), it would
be reasonable to do

    if (svGetValue (s, key, &tmp)) {
        svSetValue (s, key, "new-value");
        g_free (tmp);
    }

Without this patch, you could not be sure that key is not
set to some inparsable value, which svWriteFile() would then
write out as empty string.

Have invalid values returned by svGetValue() as empty string.
That is how svWriteFile() treats them.

(cherry picked from commit 6470bed5f1ad25e20df14b333f1b083c9b390ece)
2017-04-27 17:26:26 +02:00
Thomas Haller
cfd8cf54df core: make dad_counter argument guint32 type
The dad_counter is hashed into the resulting address. Since we
want the hashing to be independent of the architecture, we always
hash 32 bit of dad_counter. Make the dad_counter argument of
type guint32 for consistency.

In practice this has no effect because:
  - for all our (current!) architectues, guint is the same as
    guint32.
  - all callers of nm_utils_ipv6_addr_set_stable_privacy() keep
    their dad-counter argument as guint8, so they never even pass
    numbers larger then 255.
  - nm_utils_ipv6_addr_set_stable_privacy() limits dad_counter
    further against RFC7217_IDGEN_RETRIES.

(cherry picked from commit 951e5f5bf8)
2017-04-27 17:21:36 +02:00
Thomas Haller
9f7433f869 core: avoid generating reserved IPv6 interface identifiers
https://tools.ietf.org/html/rfc7217 says:

  The resulting Interface Identifier SHOULD be compared against the
  reserved IPv6 Interface Identifiers [RFC5453] [IANA-RESERVED-IID]
  and against those Interface Identifiers already employed in an
  address of the same network interface and the same network
  prefix.  In the event that an unacceptable identifier has been
  generated, this situation SHOULD be handled in the same way as
  the case of duplicate addresses (see Section 6).

In case of conflict, this suggests to create a new address incrementing
the DAD counter, etc. Don't do that. If we generate an address of the
reserved region, just rehash it right away. Note that the actual address
anyway appears random, so this re-hashing is just as good as incrementing
the DAD counter and going through the entire process again.

Note that now we no longer generate certain addresses like we did
previously. But realize that we now merely reject (1 + 16777216 + 128)
addresses out of 2^64. So, the likelyhood of of a user accidentally
generating an address that is suddenly rejected is in the order of
10e-13 (1 / 1,099,503,173,697). Which is not astronomically, but still
extreeeemely unlikely.

Also, the whole process is anyway build on the idea that somebody else
might generate conflicting addresses (DAD). It means, there was always
the extremely tiny chance that the address you generated last time is
suddenly taken by somebody else. So, this change appears to a user
like these reserved addresses are now claimed by another (non existing)
host and a different address gets generated -- business as usual, as
far as SLAAC is concerned.

(cherry picked from commit f15c4961ad)
2017-04-27 17:21:35 +02:00
Thomas Haller
8ac1bf76bd core: move NMIPAddr to nm-core-utils.h
(cherry picked from commit 67da0a28db)
2017-04-27 17:21:33 +02:00
Thomas Haller
9c37b4ae21 ifcfg-rh/tests: fix out-of-tree build for cexpected file
Fixes: f04bf45e84
(cherry picked from commit 5fc4bfc0e3)
2017-04-27 16:25:51 +02:00
Lubomir Rintel
af87569a9b device: disable delegating prefixes to the device when the IPv6 config is removed
Fixes a crash where the default DNS domain to be announced together with the
prefixes to be delegated is updated at the same time the device is being
unrealized.

https://bugzilla.redhat.com/show_bug.cgi?id=1425818
(cherry picked from commit 3e076cf8b1)
2017-04-27 15:43:00 +02:00
Beniamino Galvani
43182c6e79 libnm-core,shared: fix typo in '(allow-none)' annotation
(cherry picked from commit d19553392b)
2017-04-27 09:03:34 +02:00
Thomas Haller
753a2cc4d9 device: fix restricting Generic connection by interface-name
NMDeviceGeneric:check_connection_compatible() doesn't check for a
matching interface name. It relies on the parent implementation to
do that.

The parent implementation calls nm_manager_get_connection_iface().
That fails for NM_SETTING_GENERIC_SETTING_NAME, because that one has
no factory. Maybe this imbalance of having no factory for the Generic device
is wrong, but usually factories only match a distinct set of device
types, while the generic factory would handle them all (as last resort).

Without this, activating a generic connection might activate the
wrong interface.

(cherry picked from commit 3876b10a47)
2017-04-26 21:09:19 +02:00
Thomas Haller
d19a11e137 ifcfg-rh/tests: compare the written files to a expected result
We have unit tests for writing and re-reading ifcfg file. Those
tests compare whether a file can be successfully read and is
semantically identical.

However, there were no tests that a certain output is written in
a stable format. We aim not to change the output of what we write.
For that, add tests to not only check the semantic of the written
ifcfg file, but their bits and bytes.

Some future changes may well intentionally change the current
output. That will require to update the expected result files
and can be done via

  NMTST_IFCFG_RH_UPDATE_EXPECTED=yes src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh

Note that alias, route, and key files are not checked.

Related: https://bugzilla.redhat.com/show_bug.cgi?id=1445414
(cherry picked from commit f04bf45e84)
2017-04-26 12:31:37 +02:00
Thomas Haller
27025f08c3 ifcfg-rh/tests: remove unused macro _writer_update_connection_FIXME()
Fixes: 670e088efe
(cherry picked from commit e1e5d0d867)
2017-04-26 12:31:36 +02:00
Thomas Haller
424e6c8538 proxy: merge branch 'th/proxy-rh1444374'
https://bugzilla.redhat.com/show_bug.cgi?id=1444374

(cherry picked from commit b495d0bf94)
2017-04-23 18:16:48 +02:00
Thomas Haller
6ce0044c4d proxy: send proxy config after creating D-Bus proxy
As NMDevice now creates the NMPacrunnerManager instance
as needed, it is even more likely that the initial call
to nm_pacrunner_manager_send() will only queue (but not yet
send) the new config.

Later, when the D-Bus proxy is created, we will not get a
name-owner changed signal. We instead have to push the configuration
right away.

(cherry picked from commit 019b9fbfc0)
2017-04-23 18:16:25 +02:00
Thomas Haller
48388f1038 proxy: unify logging in nm-pacrunner-manager
Give logging lines that are concerned with a certain "config"
the same prefix: their call-id.

(cherry picked from commit 8c81a4b58b)
2017-04-23 18:16:25 +02:00
Thomas Haller
b7a30dbf1f proxy: introduce call-id for clearing pacmanager configuration
nm_pacrunner_manager_remove() required a "tag" argument. It was a
bug for callers trying to remove a configuration for a non-existing
tag.

That effectively means, the caller must keep track of whether a certain
"tag" is pending. The caller also must remember the tag -- a tag that he
must choose uniquely in the first place.

Turn that around and have nm_pacrunner_manager_send() return a (non
NULL) call-id. This call-id may later be used to remove the
configuration.

Apparently, previously the tracking of the "tag" was not always correct
and we hit the assertion in nm_pacrunner_manager_remove().

https://bugzilla.redhat.com/show_bug.cgi?id=1444374
(cherry picked from commit b04a9c90eb)
2017-04-23 18:16:25 +02:00
Thomas Haller
ddd6f94ab7 firewall: merge branch 'th/firewall-dbus-policy-rh1436770'
https://bugzilla.redhat.com/show_bug.cgi?id=1436770

(cherry picked from commit 7d1f725743)
2017-04-21 13:41:34 +02:00
Thomas Haller
ff5b7275a7 dbus: allow firewalld to communicate with NetworkManager
Usually, this "<allow send_destination="..."/>" part is shipped
by firewalld's D-Bus policy. However, if firewalld is initially
not installed with NetworkManager already running, dbus-daemon
seems to cache the missing permission for the D-Bus connection.
As a result, when installing and starting firewalld, NetworkManager
requests fail until restart:

  firewall: [0x7f4b83643890,change:"eth1"]: complete: request failed (Rejected send message, 1 matched rules; type="method_call", sender=":1.3" (uid=0 pid=715 comm="/usr/sbin/NetworkManager --no-daemon ") interface="org.fedoraproject.FirewallD1.zone" member="changeZone" error name="(unset)" requested_reply="0" destination=":1.25" (uid=0 pid=1243 comm="/usr/bin/python -Es /usr/sbin/firewalld --nofork -"))

https://bugzilla.redhat.com/show_bug.cgi?id=1436770
(cherry picked from commit cc1d409ba8)
2017-04-21 13:41:21 +02:00
Thomas Haller
ebb3830e57 org.freedesktop.NetworkManager.conf: don't use tabs
(cherry picked from commit 8583e62276)
2017-04-21 13:41:21 +02:00
Thomas Haller
5eb1ef41ac firewall: fix supressing errors from D-Bus calls
We want to ignore certain errors from firewalld. In the past,
the error message contained only the error code.
Since recently ([1], [2]), the error message contains a longer text:

  NetworkManager[647]: <debug> [1492768494.7475] device[0x7f7f21e78f50] (eth0): Activation: setting firewall zone 'default'
  NetworkManager[647]: <debug> [1492768494.7475] firewall: [0x7f7f21ed8900,change:"eth0"]: firewall zone change eth0:default
  ...
  firewalld[2342]: ERROR: UNKNOWN_INTERFACE: 'eth0' is not in any zone
  NetworkManager[647]: <warn>  [1492768494.7832] firewall: [0x7f7f0400c780,remove:"eth0"]: complete: request failed (UNKNOWN_INTERFACE: 'eth0' is not in any zone)

[1] c77156d7f6
[2] 7c6ab456c5

(cherry picked from commit 2ad8bb0ce3)
2017-04-21 13:41:21 +02:00
Thomas Haller
2e612f9bf0 firewall: merge branch 'th/firewall-async'
(cherry picked from commit ec3a9c0607)
2017-04-21 13:40:59 +02:00
Thomas Haller
b504c6de24 firewall: queue operations while NMFirewallManager instance is initializing
We now initialize the NMFirewallManager asynchronously. That means, at
first firewalld appears as "not running", for which we usually would
fake-success right away.

It would be complex for callers to wait for firewall-manager to be
ready. So instead, have the asynchronous requests be queued and
complete them once the D-Bus proxy is initialized.

(cherry picked from commit fb7815df6e)
2017-04-21 13:40:31 +02:00
Thomas Haller
3489b07e59 firewall: drop _cb_info_is_idle()
Next we will get another mode, so an is-idle doesn't cut it.
It can be confusing where the mode is set and where it is only
accessed read-only. For that, add mode_mutable.

(cherry picked from commit 04f4e327a9)
2017-04-21 13:40:31 +02:00
Thomas Haller
2d8b6118ce firewall: factor out D-Bus call from _start_request()
Will be used in the next commit.

(cherry picked from commit d8bf05d3e6)
2017-04-21 13:40:31 +02:00
Thomas Haller
0a668deb78 firewall: merge "started" signal and "available" property
The GObject property NM_FIREWALL_MANAGER_AVAILABLE is basically unused.
Drop it.

(cherry picked from commit db576b848a)
2017-04-21 13:40:31 +02:00
Thomas Haller
da38fa32f0 firewall: create firewall D-Bus proxy asynchronously
Creating it asynchronously changes that on the first call to
nm_firewall_manager_get() the instance is not yet running.

Note that NMPolicy already connects to the "STARTED" signal and
reapplies the zones when firewalld appears. So, this delayed
change of the running state is handled mostly fine already.

One part is still missing, it's to queue add_or_change/remove calls
while the firewall manager is initializing. That follows next.

(cherry picked from commit 753f39fa82)
2017-04-21 13:40:31 +02:00
Lubomir Rintel
258b863130 release: bump version to 1.7.91 (1.8-rc2) 2017-04-20 17:02:31 +02:00
Lubomir Rintel
b5d63b8005 release: update NEWS 2017-04-20 17:02:31 +02:00
Francesco Giudici
347016b584 nmcli: fix access to memeber nmc->show_secret
Cherry-picked commit from master which used the new
nmc->nmc_config member not available in nm-1-8.
We should use the nmc->show_secret member here.

Fixes: d4c8a3fbf2
2017-04-20 14:41:08 +02:00
Thomas Haller
030d77d3e1 device: merge branch 'th/device-assume-guess-rh1443878'
https://bugzilla.redhat.com/show_bug.cgi?id=1443878

(cherry picked from commit c828277872)
2017-04-20 14:29:18 +02:00
Thomas Haller
e3f4c492e8 device: assume matching connections during first start
Since commit 2d1b85f (th/assume-vs-unmanaged-bgo746440), we clearly
distinguish between two modes when encountering devices with external
IP configuration:
 a) external devices. For those devices we generate a volatile in-memory
   connection and pretend it's active. However, the device must not be
   touched by NetworkManager in any way.
 b) assume, seamless take over. Mostly for restart of NetworkManager,
   we activate a connection gracefully without going through an down-up
   cycle. After the device reaches activated state, the device is
   considered fully managed. For this only an existing, non volatile
   connection can be used.

Before 'th/assume-vs-unmanaged-bgo746440', the behaviors were not
clearly separated.

Since then, we only choose to assume a connection (b) when the state
file indicates a matching connection. Now, extend this to also assume
connections when:

  - during first-start (not after a restart) when there is no
    state file yet.
  - and, if we have an existing, non volatile, connection which
    matches the device's configuration.

This patch lets NetworkManager assume connection also on first start.
That is for example useful when handing over network configuration from
initrd.

This only applies to existing, permanent, matching(!) connections, so it is a
good guess that the user wants NM to take over this interface. This brings us
closer to the previous behavior before 'th/assume-vs-unmanaged-bgo746440'.

https://bugzilla.redhat.com/show_bug.cgi?id=1439220
(cherry picked from commit 27b2477cb7)
2017-04-20 14:29:00 +02:00
Thomas Haller
7fa7d57a83 config: add first_start paramter to NMConfig to detect restart
(cherry picked from commit 2131954a19)
2017-04-20 14:29:00 +02:00
Thomas Haller
cd92ee58a6 config: remove unused NMConfig self argument from nm_config_device_state_*() API
nm_config_device_state_*() always access the file system directly,
they don't cache data in NMConfig. Hence, they don't use the
@self argument.

Maybe those functions don't belong to nm-config.h, anyway. For lack
of a better place they are there.

(cherry picked from commit 1940be410c)
2017-04-20 14:29:00 +02:00