Commit graph

28273 commits

Author SHA1 Message Date
Fernando Fernandez Mancera
eee4332e8f
ifcfg: fix ACCEPT_ALL_MAC_ADDRESSES for virtual interfaces
The rh-ifcfg plugin was missing the writting code for
ACCEPT_ALL_MAC_ADDRESSES property in virtual interfaces.

https://bugzilla.redhat.com/show_bug.cgi?id=1942331

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>

Fixes: d946aa0c50 ('wired-setting: add support to accept-all-mac-addresses')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/846
2021-05-10 22:54:50 +02:00
Wade Berrier
3839db5191
wifi: fix WPS PBC string typo
Fixes: b83f07916a ('supplicant: large rework of wpa_supplicant handling')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/845
2021-05-09 21:19:42 +02:00
Thomas Haller
661934e48e
firewall: merge branch 'th/firewall'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/841
2021-05-07 11:50:14 +02:00
Thomas Haller
aa859d85d9
firewall: rename NMUtilsShareRules to NMFirewallConfig
It's still not a very good name, but it seems better then
NMUtilsShareRules.

Currently, NMFirewallConfig is mostly about masquerading for shared
mode. But in practice, it's a piece of configuration for something to
configure in the firewall (the NAT and filter rules).
2021-05-07 11:42:51 +02:00
Thomas Haller
b1625697cb
firewall: move firewall code to new "nm-firewall-utils.c" file 2021-05-07 11:42:50 +02:00
Thomas Haller
e9c1d2a9dd
firewall: add new "nm-firewall-utils.[ch]" module 2021-05-07 11:42:50 +02:00
Thomas Haller
ad37120065
firewall: rework iptables rules for shared mode to use custom chain
- add our own rules to a separate custom change. This allows
  to simply flush and delete the chain. This is supposed to
  interfere less with what is already configured on the system.

- also use comments to our rules, so that we can delete them
  more explicitly and don't kill the wrong rule.

- rework the code how we call iptables. We no longer create a list
  of argv arguments that we iterate over. Instead, call functions that
  do the job. The actual arguments move further down the call stack.

- enabling masquerading is now more separate from our other shared
  rules. These two things are mostly independent and the code now
  reflects that.

Before:
  up:   /usr/sbin/iptables --table filter --insert INPUT --in-interface eth0 --protocol tcp --destination-port 53 --jump ACCEPT
  up:   /usr/sbin/iptables --table filter --insert INPUT --in-interface eth0 --protocol udp --destination-port 53 --jump ACCEPT
  up:   /usr/sbin/iptables --table filter --insert INPUT --in-interface eth0 --protocol tcp --destination-port 67 --jump ACCEPT
  up:   /usr/sbin/iptables --table filter --insert INPUT --in-interface eth0 --protocol udp --destination-port 67 --jump ACCEPT
  up:   /usr/sbin/iptables --table filter --insert FORWARD --in-interface eth0 --jump REJECT
  up:   /usr/sbin/iptables --table filter --insert FORWARD --out-interface eth0 --jump REJECT
  up:   /usr/sbin/iptables --table filter --insert FORWARD --in-interface eth0 --out-interface eth0 --jump ACCEPT
  up:   /usr/sbin/iptables --table filter --insert FORWARD --source 192.168.42.0/255.255.255.0 --in-interface eth0 --jump ACCEPT
  up:   /usr/sbin/iptables --table filter --insert FORWARD --destination 192.168.42.0/255.255.255.0 --out-interface eth0 --match state --state ESTABLISHED,RELATED --jump ACCEPT
  up:   /usr/sbin/iptables --table nat --insert POSTROUTING --source 192.168.42.0/255.255.255.0 ! --destination 192.168.42.0/255.255.255.0 --jump MASQUERADE
  down: /usr/sbin/iptables --table nat --delete POSTROUTING --source 192.168.42.0/255.255.255.0 ! --destination 192.168.42.0/255.255.255.0 --jump MASQUERADE
  down: /usr/sbin/iptables --table filter --delete FORWARD --destination 192.168.42.0/255.255.255.0 --out-interface eth0 --match state --state ESTABLISHED,RELATED --jump ACCEPT
  down: /usr/sbin/iptables --table filter --delete FORWARD --source 192.168.42.0/255.255.255.0 --in-interface eth0 --jump ACCEPT
  down: /usr/sbin/iptables --table filter --delete FORWARD --in-interface eth0 --out-interface eth0 --jump ACCEPT
  down: /usr/sbin/iptables --table filter --delete FORWARD --out-interface eth0 --jump REJECT
  down: /usr/sbin/iptables --table filter --delete FORWARD --in-interface eth0 --jump REJECT
  down: /usr/sbin/iptables --table filter --delete INPUT --in-interface eth0 --protocol udp --destination-port 67 --jump ACCEPT
  down: /usr/sbin/iptables --table filter --delete INPUT --in-interface eth0 --protocol tcp --destination-port 67 --jump ACCEPT
  down: /usr/sbin/iptables --table filter --delete INPUT --in-interface eth0 --protocol udp --destination-port 53 --jump ACCEPT
  down: /usr/sbin/iptables --table filter --delete INPUT --in-interface eth0 --protocol tcp --destination-port 53 --jump ACCEPT

Now:

  up:   /usr/sbin/iptables --table nat --insert POSTROUTING --source 192.168.42.0/24 ! --destination 192.168.42.0/24 --jump MASQUERADE -m comment --comment nm-shared-eth0
  up:   /usr/sbin/iptables --table filter --new-chain nm-sh-in-eth0
  up:   /usr/sbin/iptables --table filter --append nm-sh-in-eth0 --protocol tcp --destination-port 67 --jump ACCEPT
  up:   /usr/sbin/iptables --table filter --append nm-sh-in-eth0 --protocol udp --destination-port 67 --jump ACCEPT
  up:   /usr/sbin/iptables --table filter --append nm-sh-in-eth0 --protocol tcp --destination-port 53 --jump ACCEPT
  up:   /usr/sbin/iptables --table filter --append nm-sh-in-eth0 --protocol udp --destination-port 53 --jump ACCEPT
  up:   /usr/sbin/iptables --table filter --new-chain nm-sh-fw-eth0
  up:   /usr/sbin/iptables --table filter --append nm-sh-fw-eth0 --destination 192.168.42.0/24 --out-interface eth0 --match state --state ESTABLISHED,RELATED --jump ACCEPT
  up:   /usr/sbin/iptables --table filter --append nm-sh-fw-eth0 --source 192.168.42.0/24 --in-interface eth0 --jump ACCEPT
  up:   /usr/sbin/iptables --table filter --append nm-sh-fw-eth0 --in-interface eth0 --out-interface eth0 --jump ACCEPT
  up:   /usr/sbin/iptables --table filter --append nm-sh-fw-eth0 --out-interface eth0 --jump REJECT
  up:   /usr/sbin/iptables --table filter --append nm-sh-fw-eth0 --in-interface eth0 --jump REJECT
  up:   /usr/sbin/iptables --table filter --insert INPUT --in-interface eth0 --jump nm-sh-in-eth0 -m comment --comment nm-shared-eth0
  up:   /usr/sbin/iptables --table filter --insert FORWARD --jump nm-sh-fw-eth0 -m comment --comment nm-shared-eth0
  down: /usr/sbin/iptables --table nat --delete POSTROUTING --source 192.168.42.0/24 ! --destination 192.168.42.0/24 --jump MASQUERADE -m comment --comment nm-shared-eth0
  down: /usr/sbin/iptables --table filter --delete INPUT --in-interface eth0 --jump nm-sh-in-eth0 -m comment --comment nm-shared-eth0
  down: /usr/sbin/iptables --table filter --delete FORWARD --jump nm-sh-fw-eth0 -m comment --comment nm-shared-eth0
  down: /usr/sbin/iptables --table filter --flush nm-sh-in-eth0
  down: /usr/sbin/iptables --table filter --delete-chain nm-sh-in-eth0
  down: /usr/sbin/iptables --table filter --flush nm-sh-fw-eth0
  down: /usr/sbin/iptables --table filter --delete-chain nm-sh-fw-eth0
2021-05-07 11:42:49 +02:00
Thomas Haller
c752de2237
firewall: extract _share_iptables_set_masquerade() helper
When we configure iptables rules, we really do two independent
steps: enable masquerading and do some filtering.

As such, introduce a helper method _share_iptables_set_masquerade() for
the masquerading part.

nm_utils_share_rules_apply() is at the moment a bit odd, because
of the order in which we add/remove the rule. This will get better next.
2021-05-07 11:42:37 +02:00
Thomas Haller
f5e12f3915
firewall: use prefix length instead of netmask for iptables arguments
The form "address/netmask" is unnecessarily verbose. iptables
supports prefix length notation just fine.
2021-05-07 11:42:37 +02:00
Thomas Haller
734c82d789
firewall: add _share_iptables_subnet_to_str() helper for creating string 2021-05-07 11:42:37 +02:00
Thomas Haller
27e325c6c2
firewall: extract helper function _shared_iptables_call() to spawn iptables 2021-05-07 11:42:36 +02:00
Thomas Haller
2277c9490a
firewall: rework NMUtilsShareRules to generate argv on demand
Previously, NMUtilsShareRules basically was tracking a list of command
line arguments, and during apply(), it would spawn the (iptables)
processes.

But in practice, this list was always pre-determined by a few
parameters, the interface name and the subnet. Instead of keeping the
list of arguments, only keep those few parameters. And generate the list
of arguments only for the short time when we need them.

The difference is that we will want to support nftables too. Later,
we can just generate a different list of commands, but there is no
need to keep this list around.
2021-05-07 11:42:36 +02:00
Thomas Haller
a9a33f2d12
firewall: downgrade info logging for iptables commands
Sure, it's interesting to see the actual iptables commands in the log.
But not at <info> level!
2021-05-07 11:42:36 +02:00
Thomas Haller
60744889e2
firewall: fix adding duplicate iptables rules for shared mode
nm_act_request_set_shared() already calls nm_utils_share_rules_apply().
Calling it twice, is pretty bad because during deactivate we will only
remove one of each duplicate rule.

Fixes: 701654b930 ('core: refactor tracking of shared-rules to use NMUtilsShareRules')
2021-05-07 11:42:35 +02:00
Thomas Haller
51899c3085
wifi: merge branch 'verdre:better-wifi-auth-selection'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/833
2021-05-06 22:26:54 +02:00
Jonas Dreßler
0e30a5256c
devices/wifi: Use wpa-psk key-mgmt for networks supporting WPA2 and WPA3
Networks offering WPA2 and WPA3/SAE at the same time are in WPA3 hybrid
mode. In this case the PSK passphrase rules that apply need to be the
WPA2 rules, so we shouldn't use "sae" as key-mgmt. Also our wifi card
might not support SAE and we want to make sure WPA2 eventually gets used
in that case.

So use "wpa-psk" as key-mgmt method in case an AP is in WPA3 hybrid
mode.
2021-05-06 22:23:29 +02:00
Jonas Dreßler
e019132033
supplicant/interface: Match more ciphers to determine AP security
There can also be APs which don't do wpa-psk, but do support
wpa-psk-sha256, so we should match all AKM suites the AP offers to
determine the security type we want to assign it.
2021-05-06 22:23:29 +02:00
Jonas Dreßler
60c2f6c596
supplicant/config: Allow using FT ciphers with WPA-EAP-SUITE-B-192
According to [1], the only suitable FT cipher suite for WPA3 Enterprise
192-bit mode is "FT over 802.1X, SHA-384", so enable that in case of
key-mgmt is WPA-EAP-SUITE-B-192 to support FT in that case too.

[1] https://mrncciew.com/2020/08/17/wpa3-enterprise/
2021-05-06 22:23:28 +02:00
Jonas Dreßler
2bc3cf0cb8
supplicant/config: Disallow SHA1 ciphers when using required PMF
As mentioned in the wpa_supplicant reference config, when setting PMF to
required with WPA2 (personal or enterprise) authentication, we want to
only enable SHA256 and upwards as HMAC. So enforce that by not passing
WPA-PSK and WPA-EAP to the config in case pmf is set to REQUIRED.
2021-05-06 22:23:28 +02:00
Jonas Dreßler
a4b95a9fcd
libnm-core: Don't allow disabling PMF when using WPA3 key management
Modern WPA3 authentication methods like SAE and WPA-EAP-SUITE-B-192 need
to have management frame protection set to required according to the
standard. Since the last commit, we enforce this automatically when
key-mgmt is set to 'owe', 'sae' or 'wpa-eap-suite-b-192', so disabling
it manually should not be possible.

Add a check to the pmf property that makes sure it can't be set to
'disabled' or 'optional' when one of those key-mgmt methods is used.
2021-05-06 22:23:28 +02:00
Jonas Dreßler
8816cfe736
supplicant/config: Require pmf for owe, sae and wpa-eap-suite-b-192
When using modern WPA3 encryption like owe, sae or wpa-eap-suite-b-192
without fallbacks (so not WPA3+WPA2), protected management frames are
required to be enabled by the specification.

For wpa-eap-suite-b-192 we already do this and force PMF to REQUIRED, we
should also do it for OWE and SAE.
2021-05-06 22:23:28 +02:00
Jonas Dreßler
e06f9508d1
libnm-core: Rewrite comment of key-mgmt property
The key-mgmt property of NMSettingWirelessSecurity is slightly confusing
when you know there's also a wpa_supplicant configuration option called
"key_mgmt". Our property is not the same as that supplicant option even
though they do have things in common. NMs key-mgmt is not exactly meant
to configure which AKM suites you want to use, but rather which method
of wifi security is being used (so "wpa2+wpa3 personal", "wpa3 personal
only" or "wpa3 enterprise only").

Try to make this a bit clearer in the documentation of the property by
rewriting it and listing those security methods.
2021-05-06 22:23:28 +02:00
Jonas Dreßler
5f146b40f3
supplicant/config: Refactor key_mgmt config generation
Refactor the generation of the key_mgmt option of the wpa_supplicant
config we generate. The goal of this is to lay out all the cases we
support more obviously and to make it a bit clearer that our key-mgmt
property of NMSettingsWirelessSecurity is not the same as the "key_mgmt"
config we set in wpa_supplicant.
2021-05-06 22:23:28 +02:00
Thomas Haller
a6cf94cfc4
strbuf: drop nm_str_buf_append_c[24]() for nm_str_buf_append_c() 2021-05-06 13:18:56 +02:00
Thomas Haller
94ce36f816
strbuf: make nm_str_buf_append_c() a variadic macro
We already have nm_str_buf_append_c2() and nm_str_buf_append_c4()
to support 2 or 4 characters.

I'd like to also have one for 3 characters.

At this point, just make it a variadic macro. This now supports 1 up to
4 characters, and it will be easy to extend further.
2021-05-06 13:18:19 +02:00
Thomas Haller
cc40eba9aa
firewall: merge branch 'th/firewalld-manager-rename'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/839
2021-05-06 12:24:40 +02:00
Thomas Haller
b86545e7c0
firewall: rename NMFirewallManager to NMFirewalldManager
The file was already renamed. Now also rename the type and API.
2021-05-06 12:22:37 +02:00
Thomas Haller
8483c47d70
firewall: rename "nm-firewall-manager.[ch]" to "nm-firewalld-manager.[ch]"
We will add a general "firewall-manager", so rename the firewalld related
file. This commit only renames the file. The next commit will change the
symbol naming.
2021-05-06 12:22:37 +02:00
Thomas Haller
0bc5a2c76f
core: add "nm-device-utils.[ch]" with simple helper functions
"nm-device.c" is huge, and it does complicated things like handling the
state of the device and IP configuration.

It also contains simpler, individual functions, like converting enums to
strings. Let's move those trivial functions to a new module, so that the
remaining part is smaller.

"nm-device-utils.[ch]" should only contain simpler functions that have
no complex behavior or state.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/840
2021-05-06 12:19:44 +02:00
Thomas Haller
037a94e837
ppp: cleanup nm-ppp-manager-call to use const pointer and atomic operations
- Mark NMPPPOps variable as const. It really must not be modified.

- We cache the loaded symbols in a global variable. While this code
  is not used in a multi threaded situation, I think we should not
  add code that uses global variables that is not thread safe.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/837
2021-05-06 11:34:28 +02:00
Beniamino Galvani
f3821b27dd release: bump version to 1.31.4 (development) 2021-05-05 21:17:53 +02:00
Wen Liang
86dcb31ab3
build: replace ./tools/generate-docs-nm-property-infos.pl with python script
In order to have more structured settings in man page and make it more
manageable to generate the docbook, it is recommended to use python
script to replace `./tools/generate-docs-nm-property-infos.pl` (this
tool is used to parse the comment section starting with `---nmcli---`,
`---dbus---`, `---keyfile---`, `---ifcfg-rh---`).

Signed-off-by: Wen Liang <liangwen12year@gmail.com>

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/824
2021-05-05 15:28:17 +02:00
Thomas Haller
8232c3473f
all: merge branch 'th/uuid'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/835
2021-05-04 15:53:08 +02:00
Thomas Haller
207cf3d5d4
libnm: normalize "connection.uuid"
For NetworkManager profiles, "connection.uuid" is the identifier of the
profile. It is supposed to be a UUID, however:

- the UUID was not ensured to be all-lower case. We should make sure
  that our UUIDs are in a consistent manner, so that users can rely
  on the format of the string.

- the UUID was never actually interpreted as a UUID. It only was some
  opaque string, that we use as identifier. We had nm_utils_is_uuid()
  which checks that the format is valid, however that did not fully
  validate the format, like it would accept "----7daf444dd78741a59e1ef1b3c8b1c0e8"
  and "549fac10a25f4bcc912d1ae688c2b4987daf444d" (40 hex characters).

Both invalid UUIDs and non-normalized UUID should be normalized. We
don't want to break existing profiles that use such UUIDs, thus we don't
outright reject them. Let's instead mangle them during
nm_connection_normalize().
2021-05-04 15:51:59 +02:00
Thomas Haller
5bd03fd9a3
libnm: use nm_uuid_is_valid_nmlegacy() to implement nm_utils_is_uuid() 2021-05-04 15:51:57 +02:00
Thomas Haller
ce65fc52a8
glib-aux: add nm_uuid_is_valid() helper 2021-05-04 15:51:55 +02:00
Thomas Haller
b12f116a02
glib-aux: add nm_uuid_is_valid_nmlegacy() helper 2021-05-04 15:51:53 +02:00
Thomas Haller
2fcabf5699
all: only include "libnm-glib-aux/nm-uuid.h" where needed
Don't let "nm-core-internal.h" (which is a very popular header itself)
drag in "nm-uuid.h".
2021-05-04 15:51:51 +02:00
Thomas Haller
414ce2236e
glib-aux: add NMUuidType enum for nm_uuid_generate_from_string()
Let's have an enum instead of plain "int" and #define.
2021-05-04 15:51:50 +02:00
Thomas Haller
995c78245e
glib-aux/trivial: rename NMUuid API 2021-05-04 15:51:49 +02:00
Thomas Haller
78297db721
libnm,glib-aux: move nm_utils_uuid_*() API to libnm-glib-aux 2021-05-04 15:51:47 +02:00
Thomas Haller
c5985db7cf
libnm,glib-aux: move nm_crypto_md5_hash() to "libnm-glib-aux"
This only uses glib's md5 code and has no dependency on our
crypto libraries (gnutls, nss).

Move it to "libnm-glib-aux" so it can be freely used.

Maybe it deserves a better name, but "nm-shared-utils.h" is a heap of
various utility functions, it's hard to name them well.
2021-05-04 15:51:46 +02:00
Thomas Haller
73cfc4097a
libnm,glib-aux: add and use nm_uuid_generate_random_str*() helpers 2021-05-04 15:51:45 +02:00
Thomas Haller
dd1a618745
libnm,glib-aux: move nm_utils_uuid_is_null() to "nm-uuid.h" 2021-05-04 15:51:45 +02:00
Thomas Haller
73b9883c6f
build: don't link libnm/libnm-core against libuuid
We use util-linux's libuuid for handling UUIDs. But UUIDs are
really a trivial thing, at least the portion that we use.

Reimplement the parse/unparse/generate_random() methods and drop
the dependency. Note that no other libraries from our dependency chain
was dragging in libuuid, so thereby we really get rid of the dependency.

We still require libuuid for building, because it is used by an example
program. Maybe that should be changed, to avoid the build dependency.
But that can be done at a later time.
2021-05-04 15:51:44 +02:00
Thomas Haller
7a15144f75
glib-aux: use nm_uuid_generate_random() helper 2021-05-04 15:51:43 +02:00
Thomas Haller
b4608b3ff7
glib-aux: add nm_uuid_generate_random() helper 2021-05-04 15:51:43 +02:00
Thomas Haller
42d67415b4
glib-aux: use nm_uuid_parse() helper 2021-05-04 15:51:42 +02:00
Thomas Haller
e7568e29b2
glib-aux: add nm_uuid_parse() helper 2021-05-04 15:51:42 +02:00
Thomas Haller
596bf4b91b
glib-aux: use nm_uuid_unparse() 2021-05-04 15:51:42 +02:00