Commit Graph

28348 Commits

Author SHA1 Message Date
Thomas Haller
5aa7e254bd dhcp: refactor DHCP anycast_address to be property of NMDhcpClient
Instead of passing the setting on during ip4_start()/ip6_start(), make
it a property of NMDhcpClient.

This property is currently only set by OLPC devices, and is only
implemented by NMDhcpDhclient. As such, it also does not need to change
or get reset. Hence, and immutable, construct-only property is clearer,
because we don't have to pass parameters to ip[46]_start().

Arguably, the parameter is still there, but being immutable and always
set, make it easier to reason about it.
2021-05-18 09:41:52 +02:00
Thomas Haller
658c6a4146 ethtool: merge branch 'th/ethtool-autoneg-consistency'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/857
2021-05-18 08:41:31 +02:00
Thomas Haller
98a89a05ec core: explicitly disable ethtool.pause-autoneg when setting pause-rx/pause-tx
Kernel will coerce values like

    ethtool -A eth0 autoneg on rx off

to have autonet still on.

Also, if autoneg on the interface is enabled, then `ethtool  -A eth0 tx off`
has no effect.

In NetworkManager, the user cannot configure "autoneg on" together with
any rx/tx settings. That would render the profile invalid. However, we
also need to take care that a profile

  nmcli connection add ... ethtool.pause-autoneg ignore ethtool.pause-tx off

really means off. That means, we must coerce an unspecified autoneg
setting to "off".
2021-05-17 23:31:21 +02:00
Thomas Haller
dfc5667603 libnm: reject setting ethtool.pause-autoneg while setting pause-rx/pause-tx
Setting pause-rx/pause-tx to an explicit value, implies that the user
does not want to enable autoneg. Reject that as invalid value in the
connection profile.
2021-05-17 23:31:21 +02:00
Thomas Haller
0ce59b5dc4 build: merge branch 'liangwen12year:wl/xml'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/842
2021-05-17 23:29:09 +02:00
Wen Liang
a83fb33840 Rewrite ./tools/generate-docs-nm-property-infos.py with XML library
Instead of writing XML text word by word, it is less error prone to
write with XML library.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-05-17 23:28:56 +02:00
Wen Liang
403d776730 Remove unnecessary escaping for single quote
When writing XML text with XML library, single quote will not be
escaped. So remove the escaping for single quote in current tool.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-05-17 23:28:56 +02:00
Wen Liang
f6e52708a2 Add paired property tag to nm-property-infos-*.xml
In order to make the generated XML file format consistent before and
after using XML library, replace self-closing `property` tag with
paired `property` tag.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-05-17 23:28:56 +02:00
Wen Liang
90422ddd1a Remove line breaks in attribute value of nm-property-infos-*.xml
Since line breaks are not needed for XML's attribute tag, remove the
unnecessary line breaks.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-05-17 23:28:56 +02:00
Beniamino Galvani
e67ddd826f device: commit MTU during stage2
Currently we commit the MTU to the device when updating the IP
configuration, or when a port device is added to the controller. This
means that for a connection with DHCP, the MTU is set only after DHCP
has completed. In particular, if DHCP doesn't complete and the
connection has an infinite timeout, the MTU is never set.

_commit_mtu() tracks different sources for the MTU of a device, and
each source has a different priority. Among these sources there are
the parent link (for VLANs), a dynamic IP configuration (DHCP, PPP)
and the connection profile.

A MTU from the connection always has the highest priority and
overrides other sources.

Therefore, if the connection specifies an MTU it can be applied at
stage2, even before configuring IP addressing.

https://bugzilla.redhat.com/show_bug.cgi?id=1890234
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/859
2021-05-17 16:20:36 +02:00
Beniamino Galvani
aeea0203b4 core: merge branch 'bg/assume'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/852
2021-05-14 18:20:31 +02:00
Beniamino Galvani
3c4450aa4d core: don't reset assume state too early
If the device is still unmanaged by platform-init (which means that
udev didn't emit the event for the interface) when the device gets
realized, we currently clear the assume state. Later, when the device
becomes managed, NM is not able to properly assume the device using
the UUID.

This situation arises, for example, when NM already configured the
device in initrd; after NM is restarted in the real root, udev events
can be delayed causing this race condition.

Among all unamanaged flags, platform-init is the only one that can be
delayed externally. We should not clear the assume state if the device
has only platform-init in the unmanaged flags.
2021-05-14 18:19:38 +02:00
Beniamino Galvani
5dc6d73243 managed: remove unneeded call to nm_device_assume_state_reset()
_set_state_full() in NMDevice already calls
nm_device_assume_state_reset() when the device reaches state >
DISCONNECTED.
2021-05-14 18:19:38 +02:00
Beniamino Galvani
f244aa6907 device: add NM_UNMANAGED_ALL 2021-05-14 18:19:38 +02:00
Thomas Haller
0609f1f31c firewall: for now always default firewall-backend to "itables"
ntables backend is not yet well tested. Don't flip the default yet
but for now always use iptables.

Once nftables is shown to work well, revert this patch.
2021-05-14 11:46:56 +02:00
Thomas Haller
6f04f5bc2f firewall: merge branch 'th/firewall-nft'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/847
2021-05-14 11:41:43 +02:00
Thomas Haller
a79d5e2218 firewall: add special firewall-backend "none" 2021-05-14 11:41:33 +02:00
Thomas Haller
9ebdb967de firewall: implement masquerading for shared mode with nftables
Add support for nftables, as a second backend beside iptables (firewalld
still missing).

Like iptables, choose to call the `nft` tool. The alternative would be
to use libnftables or talk netlink.

It's ugly to blocking wait for a process to complete. We already do that
for iptables, but we better should not because we should not treat other
processes as trusted and not allow untrusted code to block NetworkManager.
Fixing that would require a central manager that serializes all requests.
Especially with firewalld support, this will be interesting again,
because we don't want to synchronously talk D-Bus either.
For now, `nft` is still called synchronously. However, the internal
implementation uses an asynchronous function. That currently
serves no purpose except supporting a timeout. Otherwise, the only
reason why this is asynchronous is that I implemented this first, and
I think in the future we want this code to be non-blocking. So, instead
of dropping the asynchronous code, I wrap it in a synchronous function
for now.

The configured nft table is:

    table inet nm-shared-eth0 {
            chain nat_postrouting {
                    type nat hook postrouting priority srcnat; policy accept;
                    ip saddr 192.168.42.0/24 ip daddr != 192.168.42.0/24 masquerade
            }

            chain filter_forward {
                    type filter hook forward priority filter; policy accept;
                    ip daddr 192.168.42.0/24 oifname "eth0" ct state { established, related } accept
                    ip saddr 192.168.42.0/24 iifname "eth0" accept
                    iifname "eth0" oifname "eth0" accept
                    iifname "eth0" reject
                    oifname "eth0" reject
            }
    }
2021-05-14 11:41:33 +02:00
Thomas Haller
1da1ad9c99 firewall: make firewall-backend configurable via "NetworkManager.conf"
"iptables" and "nftables" will be supported. Currently, the code is
unused and only "iptables" is supported.
2021-05-14 11:41:32 +02:00
Thomas Haller
2a1d42e77d firewall: refactor is_comment argument to _share_iptables_get_name()
The new name makes it more generic, because the limitation exists
for iptables chains. Everything else (iptables comments, nftables
tables) has no such length limit.
2021-05-14 11:41:32 +02:00
Thomas Haller
8a11380e80 glib-aux: add nm_auto_pop_and_unref_gmaincontext cleanup macro 2021-05-14 11:41:32 +02:00
Thomas Haller
071ef784cf glib-aux: add nm_g_subprocess_terminate_in_background() helper 2021-05-14 11:41:32 +02:00
Thomas Haller
62027350f7 glib-aux: add NM_STRV_EMPTY() helper
NM_PTRARRAY_EMPTY(char*) gives a "char *const*" pointer,
which is often not useful where a strv array is needed.
Add a helper macro.
2021-05-14 11:41:32 +02:00
Thomas Haller
b5c5b2443d glib-aux: add nm_g_error_free() helper 2021-05-14 11:41:32 +02:00
Thomas Haller
9a95146b70 core/format: drop /*<flags>*/ comment from enums that lead to bad formatting
Our clang-format style doesn't work well with these gtk-doc
tags.

For NetworkManager core, we don't use glib-mkenums. Thus, these
comments serve no purpose. Drop them for better formatting.
2021-05-14 11:41:31 +02:00
Thomas Haller
63bb7580bc core: merge branch 'th/dbus-drop-legacy-properties-changed'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/853
2021-05-14 11:34:33 +02:00
Thomas Haller
b6a195cf81 tools: remove deprecated PropertiesChanged signal in "test-networkmanager-service.py" 2021-05-14 10:57:35 +02:00
Thomas Haller
48dce1b66c core: drop deprecated PropertiesChanged D-Bus signal (API BREAK)
D-Bus 1.3.1 (2010) introduced the standard "PropertiesChanged" signal
on "org.freedesktop.DBus.Properties". NetworkManager is old, and predates
this API. From that time, it still had it's own PropertiesChanged signal
that are emitted together with the standard ones. NetworkManager
supports the standard PropertiesChanged signal since it switched to
gdbus library in version 1.2.0 (2016).

These own signals are deprecated for a long time already ([1], 2016), and
are hopefully not used by anybody anymore. libnm-glib was using them and
relied on them, but that library is gone. libnm does not use them and neither
does plasma-nm.

Hopefully no users are left that are affected by this API break.

[1] 6fb917178a
2021-05-14 10:57:34 +02:00
Thomas Haller
c8900a437a core: use define DBUS_INTERFACE_PROPERTIES instead of string literal 2021-05-14 10:53:09 +02:00
Thomas Haller
86e99fca6b examples: avoid deprecated PropertiesChanged signal in "create-bond.py" example 2021-05-14 10:53:09 +02:00
Thomas Haller
5f939cc1cb dhcpcd: merge branch 'th/dhcpcd-kill-em-all'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/726

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/856
2021-05-14 10:34:33 +02:00
Thomas Haller
80ced3f1fb dhcpcd: fix killing all processes
With kill(), the PID -1 means to send a signal to all processes.
nm_dhcp_client_get_pid() can return -1, if no PID is set. This
must be handled.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/726

Fixes: a2abd15fe0 ('DHCP: Support dhcpcd-9.x')
2021-05-14 10:34:22 +02:00
Thomas Haller
92bfe09724 dhcp: assert that pid_t is signed for NMDhcpClient
Probably pid_t is always signed, because kill() documents that
negative values have a special meaning (technically, C would
automatically cast negative signed values to an unsigned pid_t type
too).

Anyway, NMDhcpClient at several places uses -1 as special value for "no
pid". At the same time, it checks for valid PIDs with "pid > 1". That
only works if pid_t is signed.

Add a static assertion for that.
2021-05-14 10:34:22 +02:00
Beniamino Galvani
e320beb330 dhcp: nettools: support option 249 (Microsoft Classless Static Route)
From [1]:

  The length and the data format for the Microsoft Classless Static
  Route Option are exactly the same as those specified for the
  Classless Static Route Option in [RFC3442]; the only difference is
  that Option Code 249 should be used instead of or in addition to
  Option Code 121.

Use routes from option 249 when option 121 is not present, as already
done by the dhclient backend.

[1] https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-dhcpe/f9c19c79-1c7f-4746-b555-0c0fc523f3f9

https://bugzilla.redhat.com/show_bug.cgi?id=1959461
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/851
2021-05-14 09:26:41 +02:00
Thomas Haller
d7594ae9c9 cli: merge branch 'th/cli-ethtool-ternary'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/849
2021-05-14 09:23:09 +02:00
Thomas Haller
e5b46aa38a cli: use nmc_string_to_ternary() to parse ternary in _set_fcn_ethtool()
nmc_string_to_ternary() is much more flexible, in that it case
insensitive and accepts any unambiguous abbreviation.

Also, nmc_string_to_ternary() accepts "unknown" as alias for "default".

Also, nmc_string_to_ternary() accepts numeric values -1, 0, 1.

By using nmc_string_to_ternary(), we treat ethtool boolean options like
other ternary properties and accept the same keywords.
2021-05-12 22:25:11 +02:00
Thomas Haller
d15eb7dd6e libnmc-base: optionally accept "ignore" in nmc_string_to_ternary() for NMTernary value 2021-05-12 22:25:11 +02:00
Gris Ge
652ddca04c ethtool: Introducing PAUSE support
Introducing ethtool PAUSE support with:

 * ethtool.pause-autoneg on/off
 * ethtool.pause-rx on/off
 * ethtool.pause-tx on/off

Limitations:
 * When `ethtool.pause-autoneg` is set to true, the `ethtool.pause-rx`
   and `ethtool.pause-tx` will be ignored. We don't have warning for
   this yet.

Unit test case included.

Signed-off-by: Gris Ge <fge@redhat.com>

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/829
2021-05-12 18:04:46 +02:00
Thomas Haller
d0e8a7e2ac ifcfg-rh: merge branch 'th/ifcfg-write-wired-setting'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/848
2021-05-12 13:45:20 +02:00
Thomas Haller
0956354bc5 ifcfg-rh: for ethernet profiles write TYPE before other wired settings 2021-05-12 13:43:37 +02:00
Thomas Haller
6f3f25cead ifcfg-rh: write all [ethernet] settings for write_wired_for_virtual()
It's not the task of the writer to mangle/normalize profiles. If a profile
for a virtual device can have an [ethernet] setting, then unsuitable values
like s390 options must be either rejected by nm_connection_verify() or normalized
by nm_connection_normalize(). In no way it's right that the writer simple
pretends they are not set.
2021-05-12 13:43:36 +02:00
Thomas Haller
166c458411 ifcfg-rh: refactor common parts of write_wired_setting()/write_wired_for_virtual() 2021-05-12 13:43:36 +02:00
Thomas Haller
a21714b821 ifcfg-rh: cleanup write_wired_for_virtual() to return-early 2021-05-12 13:43:36 +02:00
Thomas Haller
46eb75d746 ifcfg-rh/trivial: move code 2021-05-12 13:43:36 +02:00
Thomas Haller
18ca3803b5 contrib/rpm: merge branch 'th/contrib-rpm-fixes'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/850
2021-05-12 13:36:50 +02:00
Thomas Haller
af40a14556 contrib/rpm: %ghost "/etc/NetworkManager/VPN"
"/etc/NetworkManager/VPN" was historically the place for .name files for
VPN plugins. In the meantime, those should be under "/usr/lib/NetworkManager/VPN".

Still, NetworkManager honors (and possibly watches) the directory in
/etc. Mark the directory as %ghost.

The exact effect of this is not clear to me. It seems however right to
do, and works for my testing.
2021-05-12 13:36:19 +02:00
Thomas Haller
40c78fe699 contrib/rpm: obsolete "config-routing-rules" package with fixed version
Since commit a447942fc0 ('contrib/rpm: rename package
"NetworkManager-config-routing-rules" to
"NetworkManager-dispatcher-routing-rules"'), the config-routing-rules
subpackage is gone.

This way to specify the version number with a variable parameter, causes
repeated messages in rpmdiff:

    INFO  NetworkManager-dispatcher-routing-rules  changed from Obsoletes: NetworkManager-config-routing-rules < 1:1.32.0-0.2.el8 to Obsoletes: NetworkManager-config-routing-rules < 1:1.32.0-0.3.el8 on noarch

Avoid this by hard coding the obsoleted version.
2021-05-12 13:35:37 +02:00
Thomas Haller
9e3b7b2e99 contrib/rpm: let NetworkManager-libnm package conflict with exact NetworkManager-glib version
This "Conflicts" is since commit b85b8ed6fa ('contrib/rpm: let
NetworkManager-libnm and NetworkManager-glib of differing version
conflict'). This was probably fine back then, but NetworkManager-glib is
long gone.

Also, not hard coding the version number leads to rpmdiff messages like:

  NEEDS INSPECTION  NetworkManager-libnm  changed from Conflicts: NetworkManager-glib < 1:1.32.0-0.2.el8 to Conflicts: NetworkManager-glib < 1:1.32.0-0.3.el8 on all architectures

As NetworkManager-glib is long gone, hard code the version with which
we conflict.
2021-05-12 13:35:28 +02:00
Thomas Haller
d784fdb9d9 glib-aux: use nm_str_buf_append_c() in nm_str_buf_append_c_hex() 2021-05-12 10:06:21 +02:00
Thomas Haller
77fb782060 glib-aux: avoid potential undefined behavior for nm_str_buf_append_printf()
The string buffer may be empty and _priv_str still %NULL. Doing
pointer arithmetic with a %NULL pointer is undefined behavior.
Avoid that.

It's probably not an issue, because it results in computing &(((char *) NULL)[0],
and then g_vsnprintf() would not even inspect the pointer (so it doesn't
matter whether the computed pointer is bogus). But still, there is
undefined behavior involved.
2021-05-12 09:38:15 +02:00