Commit graph

10140 commits

Author SHA1 Message Date
Thomas Haller
33d33be6af core/trivial: add FIXME comment about uncancellable async action
(cherry picked from commit 80b95f8b5f)
2018-02-07 12:54:52 +01:00
Thomas Haller
9c137d7e42 manager: use cleanup functions for impl_manager_activate_connection()
Also, drop two redundant g_assert(). If we proceed, we will very soon afterwards
hit a SEGFAULT or a g_return_val_if_fail(), which is just as good.

(cherry picked from commit 0df3837656)
2018-02-07 12:54:52 +01:00
Thomas Haller
5159c34ea8 ovs: fix compiler error for passing NMDevice pointer to NM_DEVICE_OVS_INTERFACE_GET_PRIVATE()
NM_DEVICE_OVS_INTERFACE_GET_PRIVATE() is implemented via the _NM_GET_PRIVATE()
macro. This macro uses C11's _Generic() to provide additional compiler checks
when casting from an incompatible pointer type.

As such,

  NMDevice *device = ...;
  NMDeviceOvsInterfacePrivate *priv;

  priv = NM_DEVICE_OVS_INTERFACE_GET_PRIVATE (device);

causes a compilation error:

    error: ‘_Generic’ selector of type ‘NMDevice * {aka struct _NMDevice *}’ is not compatible with any association

One workaround would be to cast the pointer first:

  priv = NM_DEVICE_OVS_INTERFACE_GET_PRIVATE ((NMDeviceOvsInterface *) device);

A better fix is to mark NMDevice as a compatible pointer in _NM_GET_PRIVATE(),
which this patch does.

Previously, this went unnoticed, because due to bug "a43bf3388 build: fix configure
check for CC support of _Generic() and __auto_type", we failed to detect support
for _Generic() when compiling with -Werror. That essentially disables this check,
and NM_DEVICE_OVS_INTERFACE_GET_PRIVATE() would do a direct cast.

A workaround for this build failure might be to build with -Werror, which accidentally
results in not using _Generic().

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

Fixes: 8ad310f8e3
(cherry picked from commit 782578122c)
2018-02-05 14:04:06 +01:00
Lubomir Rintel
60eb596b0d ovs-interface: avoid starting ip[46] configuration more than once
OvsInterface can postpone the stage3_ip[46]_config until the link
actually appears. It ought to restart the stage only when the link
appears, not upon further changes to it (which would trip an assertion
when starting the DHCP client while one already exists).

https://bugzilla.redhat.com/show_bug.cgi?id=1540063
(cherry picked from commit 8ad310f8e3)
2018-02-05 10:58:33 +01:00
Beniamino Galvani
a169247b7d device: skip IP configuration phase for external devices
We already avoid committing the IP configuration for external devices
(see commit 60334a2893). However, we still start DHCP/IPv6-autoconf
and, especially, we change sysctl values of the device.

To be sure that no action is taken on the device, return early from
the IP configuration phase, as in the method=disabled/ignore case.

https://bugzilla.redhat.com/show_bug.cgi?id=1530288
(cherry picked from commit 22f32a16f5)
2018-01-19 14:14:30 +01:00
Beniamino Galvani
3c60d63540 device: increase carrier wait time to 6 seconds
Some NICs need longer to establish the link, increase the timeout from
5 to 6 seconds.

https://bugzilla.redhat.com/show_bug.cgi?id=1520826
(cherry picked from commit 156344b8be)
2018-01-18 15:29:24 +01:00
Lubomir Rintel
c778d9a252 ifcfg: don't forget master of ovs interfaces
https://bugzilla.redhat.com/show_bug.cgi?id=1519179
(cherry picked from commit 1440fe6a88)
2018-01-18 13:31:30 +01:00
Thomas Haller
c17315d555 platform: fix wrong cleanup function in ip_route_get()
Fixes: 33a2a7c3e3
(cherry picked from commit 3de3f59ffd)
2018-01-15 20:33:47 +01:00
Thomas Haller
8998ce629d dhcp: fix check for client-id in _set_client_id()
Fixes: 686afe531a
(cherry picked from commit 0e1fb1dbd2)
2018-01-09 15:56:20 +01:00
Lubomir Rintel
ccd98ba214 platform-linux: reload qdiscs and tfilters after removing them
Kernel (as of 4.14) merely ACKs our RTM_DELQDISC and RTM_DELTFILTER, not
bothering to signal the full RTM_DEL* message unless the removal is
external to NetworkManager.

https://bugzilla.redhat.com/show_bug.cgi?id=1527197
(cherry picked from commit f3b4053a91)
2018-01-08 17:51:54 +01:00
Thomas Haller
41a89aeeba dhcp: cleanup handling of ipv4.dhcp-client-id and avoid assertion failure
The internal client asserts that the length of the client ID is not more
than MAX_CLIENT_ID_LEN. Avoid that assert by truncating the string.

Also add new nm_dhcp_client_set_client_id_*() setters, that either
set the ID based on a string (in our common dhclient specific
format), or based on the binary data (as obtained from systemd client).

Also, add checks and assertions that the client ID which is
set via nm_dhcp_client_set_client_id() is always of length
of at least 2 (as required by rfc2132, section-9.14).

(cherry picked from commit 686afe531a)
2018-01-04 18:53:34 +01:00
Beniamino Galvani
207eb3266f all: add more meaningful error code for unsupported IP method
Add a new device state reason code for unsupported IP method. It is
returned, for example, when users select manual IP configuration for
WWAN connections:

 # nmcli connection mod Gsm ipv4.method manual ipv4.address 1.2.3.4/32
 # nmcli connection up Gsm
 Error: Connection activation failed: The selected IP method is not
 supported

compared to the old:

 Error: Connection activation failed: IP configuration could not be
 reserved (no available address, timeout, etc.)

Note that we could instead fail the connection validation if the
method is not supported by the connection type, but adding such
limitation now could make existing connections invalid.

https://bugzilla.redhat.com/show_bug.cgi?id=1459529
(cherry picked from commit aa820e9386)
2017-12-21 10:07:12 +01:00
Beniamino Galvani
8a570a41cf device: add a new state-reason for DAD failures
(cherry picked from commit 12a49cbdc7)
2017-12-21 10:07:07 +01:00
Beniamino Galvani
4ca7e3d0cf wwan: clear idle source id when the callback runs
Fixes: f0996d0eb8
(cherry picked from commit 5d372fd30e)
2017-12-21 09:45:01 +01:00
Beniamino Galvani
d9512bc807 wwan: add default route even if modem didn't return a gateway
If the modem didn't return a gateway, add a device route.

Fixes: 5c299454b4
(cherry picked from commit ec32edb21f)
2017-12-21 09:45:00 +01:00
Beniamino Galvani
f4dc5bd782 wwan: fix checks on IP configuration
Don't call nm_utils_parse_inaddr_bin() if the string returned by
mm_bearer_ip_config_get_address() and mm_bearer_ip_config_get_gateway()
is NULL, as the function requires a valid pointer. Throw an error if the
address is NULL, but allow an empty gateway.

Fixes: 7837afe87f
(cherry picked from commit 8ddc6caf98)
2017-12-21 09:44:59 +01:00
Beniamino Galvani
b1b463d0dc settings: clear unsaved flag on new settings-connection
When a new settings-connection is populated with the actual settings
read from disk by the plugin, calling nm_settings_connection_update()
with KEEP mode also marks it as unsaved, which should not happen on a
new connection just written to (or read from) disk.

Introduce a new KEEP_SAVED persist mode that is similar to KEEP but
clears the UNSAVED flag.

Fixes: 023ce50d21

https://bugzilla.redhat.com/show_bug.cgi?id=1525078
(cherry picked from commit 5fff928a6b)
2017-12-20 15:40:05 +01:00
Thomas Haller
fa53c715d1 core: persist aspired default route-metric in device's state file
NMManager tries to assign unique route-metrics in an increasing manner
so that the device which activates first keeps to have the best routes.

This information is also persisted in the device's state file, however
we not only need to persist the effective route-metric which was
eventually chosen by NMManager, but also the aspired metric.

The reason is that when a metric is chosen for a device, the entire
range between aspired and effective route-metric is reserved for that
device. We must remember the entire range so that after restart the
entire range is still considered to be in use.

Fixes: 6a32c64d8f
(cherry picked from commit 4277bc0ee0)
2017-12-20 14:26:30 +01:00
Thomas Haller
782b85bf13 settings: drop unused define for HOSTNAME_FILE
Fixes: 5bfb7c3c89
(cherry picked from commit 7deb3b4fb5)
2017-12-20 14:26:30 +01:00
Beniamino Galvani
39e1c65494 settings: avoid assertion when deleting connections
If a volatile connection is deleted by user when it was already being
deleted internally because the device vanished, we may hit the
following failed assertion:

 file src/settings/nm-settings-connection.c: line 2196
 (nm_settings_connection_signal_remove): should not be reached

The @removed flag keeps track of whether we already signaled the
connection removal. Instead of throwing an assertion if we try to emit
the signal again, just return without action because this can happen
in the situation described above.

While at it, remove the @allow_reuse argument from
nm_settings_connection_signal_remove(): we should never emit the
signal twice. Instead, we should reset the @removed flag when the
connection is added.

Fixes: a9384452ed

https://bugzilla.redhat.com/show_bug.cgi?id=1506552
(cherry picked from commit 98ac0f404e)
2017-12-20 10:46:36 +01:00
Thomas Haller
5fd91fb67d core: ensure that the default route-metric bumps at most 50 points
First check that the limit of 50 metric points is not surpassed.
Otherwise, if you have an ethernet device (aspired 100, effective
130) and a MACSec devic (aspired 125, effective 155), activating a
new ethernet device would bump it's metric to 155 -- more then
the 50 points limit.

It doesn't matter too much, because the cases where the limit of
50 could have been surpassed were very specific. Still, change
it to ensure that the limit is always honored as one would expect.

Fixes: 6a32c64d8f
(cherry picked from commit 2499d3bdc6)
2017-12-19 10:37:33 +01:00
Lubomir Rintel
c96ab5277e ifcfg-rh: remove the watch on finalize
(cherry picked from commit 0ae44fe7e2)
2017-12-19 10:04:46 +01:00
Lubomir Rintel
643d80ec91 manager: fix connectivity-check-enabled property
(cherry picked from commit 99fea5f380)
2017-12-19 10:04:46 +01:00
Thomas Haller
bd2d71754b device: generate unique default route-metrics per interface
In the past we had NMDefaultRouteManager which would coordinate adding
the default-route with identical metrics. That especially happened, when
activating two devices of the same type, without explicitly specifying
ipv4.route-metric. For example, with ethernet devices, the routes on
both interfaces would get a metric of 100.

Coordinating routes was especially necessary, because we added
routes with NLM_F_EXCL flag, akin to `ip route replace`. We not
only had to avoid that activating two devices in NetworkManager would
result in a fight over the default-route, but more importently
to preserve externally added default-routes on unmanaged interfaces.

NMDefaultRouteManager would ensure that in case of duplicate
metrics, that the device that activated first would keep the
best default-route. It would do so by bumping the metric
of the second device to find a unused metric. The bumping itself
was not very important -- MDefaultRouteManager could also just not
configure any default-routes that show up as second, the result
would be quite similar. More important was to keep the best
default-route on the first activating device until the device
deactivates or a device activates that really has a better
default-route..

Likewise, NMRouteManager would globally manage non-default-routes.
It would not do any bumping of metrics, but it would also ensure that the routes
of the device that activates first are not overwritten by a device activating
later.

However, the `ip route replace` approach has downsides, especially
that it messes with routes on other interfaces, interfaces that are
possibly not managed by NetworkManager. Another downside is, that
binding a socket to an interface might not result in correct
routes, because the route might just not be there (in case of
NMRouteManager, which wouldn't configure duplicate routes by bumping
their metric).

Since commit 77ec302714 we would no longer
use NLM_F_EXCL, but add routes akin to `ip route append`. When
activating for example two ethernet devices with no explict route
metric configuration, there are two routes like

   default via 10.16.122.254 dev eth0 proto dhcp metric 100
   default via 192.168.100.1 dev eth1 proto dhcp metric 100

This does not only affect default routes. In case of a multi-homing
setup you'd get

  192.168.100.0/24 dev eth0 proto kernel scope link src 192.168.100.1 metric 100
  192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.1 metric 100

but it's visible the most for default-routes.

Note that we would append the routes that are activated later, as the order
of `ip route show` confirms. One might hence expect, that kernel selects
a route based on the order in the routing tables. However, that isn't
the case, and activating the second interface will non-deterministically
re-route traffic via the new interface. That will interfere badly with
with NAT, stateful firewalls, and existing connections (like TCP).

The solution is to have NMManager keep a global index of the default route-metrics
currently in use. So, instead of determining the default-route metric based solely
on the device-type, we now in addition generate default metrics that do not
overlap. For example, if you activate eth0 first, it gets route-metric 100,
and if you then activate eth1, it gets 101. Note that if you deactivate
and re-activate eth0, then it will get route-metric 102, because the
best route should stick on eth1 (which reserves the range 100 to 101).

Note that when a connection explititly selects a particular metric, then that
choice is honored (contrary to NMDefaultRouteManager which was more concerned
with avoiding conflicts, then keeping the exact metric).

https://bugzilla.redhat.com/show_bug.cgi?id=1505893
(cherry picked from commit 6a32c64d8f)
2017-12-15 11:44:52 +01:00
Thomas Haller
282ed0d175 core: add read/write support for route-metric to NMConfig's device state
(cherry picked from commit a90b523a3e)
2017-12-15 11:44:52 +01:00
Thomas Haller
7b89933406 core: cache device state in NMConfig and load all at once
NMManager will need to know the state of all device at once.
Hence, load it once and cache it in NMConfig.

Note that this wastes a bit of memory in the order of
O(number-of-interfaces). But each device state entry is
rather small, and we always consume memory in the order
of O(number-of-interfaces).

(cherry picked from commit ea08df925f)
2017-12-15 11:44:52 +01:00
Thomas Haller
42fbc9410b core: add nm_config_keyfile_get_int64() util
(cherry picked from commit 3f38b76515)
2017-12-15 11:44:52 +01:00
Thomas Haller
ea78f156f2 device: expose nm_device_get_route_metric_default()
(cherry picked from commit 989b5fabaa)
2017-12-15 11:44:52 +01:00
Francesco Giudici
2638d53ca8 devices/test: give more time to dad checking in test-arping
# random seed: R02Sc708af827453d4ace33cd27ffd3d7f0b
  1..2
  # Start of arping tests
  **
  NetworkManager:ERROR:src/devices/tests/test-arping.c:95:test_arping_common: assertion failed (nm_arping_manager_check_address (manager, info->addresses[i]) == info->expected_result[i]): (1 == 0)
  ok 1 /arping/1
  PASS: src/devices/tests/test-arping 1 /arping/1
  ./tools/run-nm-test.sh: line 193:  2836 Aborted                 "${NMTST_DBUS_RUN_SESSION[@]}" "$TEST" "$@"
  # NetworkManager:ERROR:src/devices/tests/test-arping.c:95:test_arping_common: assertion failed (nm_arping_manager_check_address (manager, info->addresses[i]) == info->expected_result[i]): (1 == 0)
  ERROR: src/devices/tests/test-arping - too few tests run (expected 2, got 1)
  ERROR: src/devices/tests/test-arping - exited with status 134 (terminated by signal 6?)

(cherry picked from commit 5c6a382d4d)
2017-12-13 10:27:43 +01:00
Thomas Haller
490911c6fa platform: assert() for valid item in nm_platform_link_get_all()
Coverity thinks that item might be NULL, but actually it
cannot. Unclear how to avoid the false positive.

(cherry picked from commit 62d4dba74b)
2017-12-12 11:21:05 +01:00
Thomas Haller
99eef7a2ea platform: fix crash hashing NMPlatformTfilter and NMPlatformQdisc
@kind might be NULL. There are 3 forms of the hash-update functions for
string: str(), str0(), and strarr().

- str0() is when the string might be NULL.
- str() does not allow the string to be NULL
- strarr() is like str(), except it adds a G_STATIC_ASSERT()
  that the argument is a C array.

The reason why a difference between str() and str0() exists, is
because str0() hashes NULL different from a "" or any other string.
This has an overhead, because it effectively must hash another bit
of information that tells whether a string was passed or not.

The reason is, that hashing a tupple of two strings should always
yield a different hash value, even for "aa",""; "a","a"; "","aa",
where naive concatentation would yield identical hash values in all
three cases.

Fixes: e75fc8279b
(cherry picked from commit 27e8fffdb8)
2017-12-12 11:21:05 +01:00
Thomas Haller
1bb6b3a79f core: avoid dereferencing NULL in nm_utils_resolve_conf_parse()
Found by coverity.

Fixes: 8f1ef161f4
(cherry picked from commit a7087b1f05)
2017-12-12 11:21:05 +01:00
Thomas Haller
387377d8fc core: fix uninialized boolean variable in reset_autoconnect_all()
It's not critical, because at worst we get a false-positive that
something changed.

Found by coverity.

Fixes: 4e7b05de79
(cherry picked from commit fbc6008260)
2017-12-12 11:21:05 +01:00
Thomas Haller
d6e7857389 platform/tests: fix memleaks in tests
Fixes: 0b0fb045bc
(cherry picked from commit 5201121a1b)
2017-12-11 21:04:58 +01:00
Lubomir Rintel
35e86a0cef device: ensure simple action sdata is a NUL-terminated bytestring
(cherry picked from commit 9639a176ff)
2017-12-11 19:53:09 +01:00
Lubomir Rintel
775893fc00 ifcfg-rh: add tc support
Format:

  QDISC1=ingress
  QDISC2="root handle 1234: fq_codel"
  FILTER1="parent ffff: matchall action simple sdata Input"
  FILTER2="parent 1234: matchall action simple sdata Output"

(cherry picked from commit 902bbfdb18)
2017-12-11 19:53:09 +01:00
Lubomir Rintel
626bf76972 device: set traffic filters when device comes up
(cherry picked from commit 8bffb2c750)
2017-12-11 19:53:09 +01:00
Thomas Haller
014b50fcbe platform: fix TC to-string/hash/cmp functions to include the action
Also add a define NM_PLATFORM_ACTION_KIND_SIMPLE. It makes the
uses of "simple" grepable.

(cherry picked from commit fe3d7209e7)
2017-12-11 19:53:09 +01:00
Lubomir Rintel
97eeadb990 platform: add support for traffic filters
(cherry picked from commit b0fd3ecbaf)
2017-12-11 19:53:09 +01:00
Lubomir Rintel
e881d0ab33 keyfile/tests: test tc traffic filter reading and writing
(cherry picked from commit bc471c8e7a)
2017-12-11 19:43:37 +01:00
Lubomir Rintel
f8da7febbc device: set qdiscs when device comes up
(cherry picked from commit e4bdb21909)
2017-12-11 19:34:31 +01:00
Lubomir Rintel
bb50e73626 keyfile/tests: test tc qdisc reading and writing
(cherry picked from commit 8547387942)
2017-12-11 19:06:28 +01:00
Lubomir Rintel
ea532fd527 platform/tests: tests qdisc caching behavior
Just the most rudimentary tests.

(cherry picked from commit 0b0fb045bc)
2017-12-11 19:00:51 +01:00
Lubomir Rintel
f29db02aac platform: add support for queueing disciplines
(cherry picked from commit ff9f27eb12)
2017-12-11 19:00:46 +01:00
Thomas Haller
0dbcbbcd86 platform: add <linux/tc_act/tc_defact.h> header
We're going to need that one for TC filter & action support.

<linux/tc_act/tc_defact.h> was moved to user-space API only in 2013
by commit 5bc3db5c9ca8407f52918b6504d3b27230defedc. Our travis CI currently
fails to build due to that.

Re-implement the header.

(cherry picked from commit 82befe3c40)
2017-12-11 19:00:44 +01:00
Thomas Haller
c38ed3afa5 platform: merge nm_platform_*_delete() delete functions
It only makes sense to call delete() with NMPObjects that
we obtained from the platform cache. Otherwise, if we didn't
get it from the cache in the first place, we wouldn't know
what to delete.

Hence, the input argument is (almost) always an NMPObject
in the first place. That is different from add(), where
we might create a new specific NMPlatform* instance on the
stack. For add() it makes slightly more sense to have different
functions depending on the type. For delete(), it doesn't.

(cherry picked from commit 7573594a21)
2017-12-11 19:00:41 +01:00
Lubomir Rintel
3db46feb16 platform/nmp-object: (trivial) keep enum ordered by a numeric value
(cherry picked from commit 44be0dfca7)
2017-12-11 18:56:48 +01:00
Lubomir Rintel
cb4c51f014 platform/linux: stringify also NLMSG_* in logs
(cherry picked from commit ffe89f86e0)
2017-12-11 18:56:47 +01:00
Lubomir Rintel
f7df4f0cde platform/trivial: s/ADDRROUTE/OBJECT/ for the cache lookup
It's going to be useful for other objects that have a type (of course)
and an ifindex.

(cherry picked from commit 93ac0e455b)
2017-12-11 18:56:41 +01:00
Lubomir Rintel
d3abc7aed1 ifcfg-rh: drop unused functions
Perhaps a cargo cult leftover.

(cherry picked from commit b49c7e026f)
2017-12-11 18:56:20 +01:00