Commit graph

2077 commits

Author SHA1 Message Date
Antonio Cardace
e04e5a5c2a
ifcfg-rh: add support for ethtool ring settings
Also update unit tests.

https://bugzilla.redhat.com/show_bug.cgi?id=1614700
2020-05-20 10:55:01 +02:00
Antonio Cardace
4fce8b3efb
ifcfg-rh: add support for ethtool coalesce settings
Also update unit tests.

https://bugzilla.redhat.com/show_bug.cgi?id=1614700
2020-05-13 10:15:23 +02:00
Thomas Haller
2929392855
all: use "int/char" instead of "gint/gchar" typedefs
This is also recommended by our checkpatch.pl script.
2020-05-08 12:56:29 +02:00
Thomas Haller
4338cf3800
ifcfg-rh/trivial: rename variable i in write_bridge_*setting() to indicate integer type 2020-05-08 08:02:48 +02:00
Thomas Haller
9996597666
ifcfg: refactor GObject accessors in write_bridge_setting() 2020-05-08 08:02:48 +02:00
Beniamino Galvani
581aa981c2 ifcfg-rh: check return value of fdopen()
Reported by coverity:

>>> CID 210222: Null pointer dereferences (NULL_RETURNS)
>>> Dereferencing a pointer that might be "NULL" "f" when calling
    "fseek".

Fixes: ac5206aa9c ('2007-11-21')
2020-05-07 10:01:57 +02:00
Thomas Haller
ace437338d
ifcfg-rh: minor cleanup of make_match_setting() 2020-05-06 16:01:13 +02:00
Thomas Haller
cf546ee789
ifcfg-rh: refactor write_match_setting()
- write_match_setting() never fails. Don't let it return a boolean
  error result.

- drop "if (!name || !name[0])" checks. It's not possibly to configure
  a name %NULL in NMSettingMatch (without triggering assertions). Also,
  an empty name "" is not valid, so we wouldn't expect it. There is one
  problem with the way how we concatenate the string list: it uses
  spaces as separator, while stripping spaces. That means, in the
  currenty format, an empty token "" cannot be expressed. On the other
  hand, serializing it would lead to duplicate spaces, that get dropped
  during re-read. So the empty name wasn't valid from the start, but it
  also cannot be encoded.

- use nm_gstring_add_space_delimiter() and nm_gstring_prepare().
2020-05-06 15:58:43 +02:00
Adrian Freihofer
369d858525
ifcfg-rh: support new match filters 2020-05-06 15:05:21 +02:00
Adrian Freihofer
d8a7f65ef4
ifcfg-rh-reader: match refactoring 2020-05-06 15:05:21 +02:00
Antonio Cardace
05d9381060
nm-setting-bridge: add 'multicast-startup-query-interval' bridge option
https://bugzilla.redhat.com/show_bug.cgi?id=1755768
2020-05-04 17:33:01 +02:00
Antonio Cardace
abe660f780
nm-setting-bridge: add 'multicast-startup-query-count' bridge option
https://bugzilla.redhat.com/show_bug.cgi?id=1755768
2020-05-04 17:33:00 +02:00
Antonio Cardace
62facc59e8
nm-setting-bridge: add 'multicast-query-response-interval' bridge option
https://bugzilla.redhat.com/show_bug.cgi?id=1755768
2020-05-04 17:33:00 +02:00
Antonio Cardace
9842c55503
nm-setting-bridge: add 'multicast-query-interval' bridge option
https://bugzilla.redhat.com/show_bug.cgi?id=1755768
2020-05-04 17:33:00 +02:00
Antonio Cardace
b9b9a95395
nm-setting-bridge: add 'multicast-querier-interval' bridge option
https://bugzilla.redhat.com/show_bug.cgi?id=1755768
2020-05-04 17:33:00 +02:00
Antonio Cardace
c1bc1570f3
nm-setting-bridge: add 'multicast-membership-interval' bridge option
https://bugzilla.redhat.com/show_bug.cgi?id=1755768
2020-05-04 17:33:00 +02:00
Antonio Cardace
1c437090ff
nm-setting-bridge: add 'multicast-last-member-interval' bridge option
https://bugzilla.redhat.com/show_bug.cgi?id=1755768
2020-05-04 17:33:00 +02:00
Antonio Cardace
c49f20887a
nm-setting-bridge: add 'multicast-last-member-count' bridge option
https://bugzilla.redhat.com/show_bug.cgi?id=1755768
2020-05-04 17:33:00 +02:00
Antonio Cardace
673d51bd5c
nm-setting-bridge: add 'multicast-hash-max' bridge option
https://bugzilla.redhat.com/show_bug.cgi?id=1755768
2020-05-04 17:32:59 +02:00
Thomas Haller
9b295f0df5 dhcp: make connection.mud-url configurable as global connection default
Conceptionally, the MUD URL really depends on the device, and not so
much the connection profile. That is, when you have a specific IoT
device, then this device probably should use the same MUD URL for all
profiles (at least by default).

We already have a mechanism for that: global connection defaults. Use
that. This allows a vendor drop pre-install a file
"/usr/lib/NetworkManager/conf.d/10-mud-url.conf" with

  [connection-10-mud-url]
  connection.mud-url=https://example.com

Note that we introduce the special "connection.mud-url" value "none", to
indicate not to use a MUD URL (but also not to consult the global connection
default).
2020-04-28 13:01:18 +02:00
Thomas Haller
3a2858a2fd ifcfg-rh/trivial: drop comment for nms_ifcfg_well_known_keys
The comment isn't right. The fixed array size is in the header file,
because other parts of the code need to know how many elements are in
the array. The alternative would be a define for the size, but that
is only redundant information. Also, even with a define the user who
adds an entry needs to adjust the code in the header. Explicitly stating
the array size in the header makes it almost impossible to accidentally
choosing the wrong size, because the compiler (and unit tests) ensure
the consistency.
2020-04-24 10:09:50 +02:00
Thomas Haller
db645623ee dhcp: rename mudurl to mud_url 2020-04-24 10:09:50 +02:00
Eliot Lear
295e6678dd dhcp: add support for MUD URL (RFC 8520)
[thaller@redhat.com: rewritten commit message]

https://tools.ietf.org/html/rfc8520
https://blog.apnic.net/2019/05/14/protecting-the-internet-of-things-with-mud/

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/463
2020-04-24 10:07:38 +02:00
Beniamino Galvani
70916a1183 ifcfg-rh: add PKEY_ID to well-known keys
Fixes: 81e6fe963e ('ifcfg-rh: add functions to detect well-known ifcfg-rh keys')
2020-04-17 09:47:16 +02:00
Thomas Haller
b681aec452 dbus: indent by 4 space in "nm-ifcfg-rh.conf" D-Bus configuration file 2020-04-15 18:48:32 +02:00
Antonio Cardace
ad052c3d67
nm-setting-bridge: add 'multicast-querier' bridge option
https://bugzilla.redhat.com/show_bug.cgi?id=1755768
2020-04-06 09:56:11 +02:00
Antonio Cardace
a685cce70a
nm-setting-bridge: add 'multicast-query-use-ifaddr' bridge option
https://bugzilla.redhat.com/show_bug.cgi?id=1755768
2020-04-06 09:56:11 +02:00
Antonio Cardace
e01d3b4c2b
nm-setting-bridge: add 'multicast-router' bridge option
Also add related unit test.

https://bugzilla.redhat.com/show_bug.cgi?id=1755768
2020-04-06 09:56:11 +02:00
Antonio Cardace
bd30491f42
nm-setting-bridge: add 'vlan-stats-enabled' bridge option
https://bugzilla.redhat.com/show_bug.cgi?id=1755768
2020-04-06 09:56:11 +02:00
Antonio Cardace
f5352ff656
nm-setting-bridge: add 'vlan-protocol' bridge option
Also add related unit test.

https://bugzilla.redhat.com/show_bug.cgi?id=1755768
2020-04-06 09:56:11 +02:00
Antonio Cardace
93e38cbe56
nm-setting-bridge: add 'group-address' bridge option
Also add related unit test.

https://bugzilla.redhat.com/show_bug.cgi?id=1755768
2020-04-06 09:56:11 +02:00
Thomas Haller
7e49f4a199 all: use wrappers for g_ascii_strtoll(), g_ascii_strtoull(), g_ascii_strtod()
Sometimes these function may set errno to unexpected values like EAGAIN.
This causes confusion. Avoid that by using our own wrappers that retry
in that case. For example, in rhbz#1797915 we have failures like:

    errno = 0;
    v = g_ascii_strtoll ("10", 0, &end);
    if (errno != 0)
        g_assert_not_reached ();

as g_ascii_strtoll() would return 10, but also set errno to EAGAIN.

Work around that by using wrapper functions that retry. This certainly
should be fixed in glib (or glibc), but the issues are severe enough to
warrant a workaround.

Note that our workarounds are very defensive. We only retry 2 times, if
we get an unexpected errno value. This is in the hope to recover from
a spurious EAGAIN. It won't recover from other errors.

https://bugzilla.redhat.com/show_bug.cgi?id=1797915
2020-04-01 17:18:37 +02:00
Thomas Haller
3930ef194e ifupdown: use _nm_utils_ascii_str_to_int64() for converting netmask to string 2020-04-01 17:12:18 +02:00
Thomas Haller
9cbf4c2825 ifcfg-rh/tests: add unit test for reading DEVTIMEOUT (connection.wait-device-timeout) 2020-04-01 17:12:18 +02:00
Thomas Haller
2e4771be5e ifcfg: strip whitespaces around "DEVTIMEOUT"
Be more graceful and allow whitespaces around the floating point number
for DEVTIMEOUT. Note that _nm_utils_ascii_str_to_int64() is already graceful
against whitespace, so also be it with the g_ascii_strtod() code path.
2020-04-01 17:12:18 +02:00
Thomas Haller
46dd4d0fbf meson: merge branch 'inigomartinez/meson-license'
Add SPDX license headers for meson files.

As far as I can tell, according to RELICENSE.md file, almost everybody
who contributed to the meson files agreed to the LGPL-2.1+ licensing.
This entails the vast majority of code in question.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/397
2020-03-28 12:45:19 +01:00
Thomas Haller
ff814923eb core: prevent multiple attempts to create default wired connection
Scenario:

  - have ethernet connection as unmanaged.
  - create (or have) a suitable profile for the connection.
  - make the device as managed. No default wired connection gets
    created.
  - delete the profile.

Note that NMManager does in manager_device_state_changed():

»···if (NM_IN_SET (new_state,
»···               NM_DEVICE_STATE_UNAVAILABLE,
»···               NM_DEVICE_STATE_DISCONNECTED))
»···»···nm_settings_device_added (priv->settings, device);

that means, when the device the next time goes through
UNAVAILABLE/DISCONNECTED states, we will suddenly create the
default "Wired connection 1" profile.

That doesn't seem right. When a device is suitable to have a
default-wired connection, we should only check once whether to
create it. We should not retry that later. The !no-auto-default
mechanism exists so we can start NetworkManager without a profile for
the device. It doesn't mean that we later one (after previously deciding
not to create a profile), we still create it.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/450
2020-03-28 11:01:05 +01:00
Niklas Goerke
bddba4ca8b Add domain_match mode for wifi certificate domain comparison
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/308
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/437
2020-03-23 20:31:09 +01:00
Thomas Haller
52dbab7d07 all: use nm_clear_pointer() instead of g_clear_pointer()
g_clear_pointer() would always cast the destroy notify function
pointer to GDestroyNotify. That means, it lost some type safety, like

   GPtrArray *ptr_arr = ...

   g_clear_pointer (&ptr_arr, g_array_unref);

Since glib 2.58 ([1]), g_clear_pointer() is also more type safe. But
this is not used by NetworkManager, because we don't set
GLIB_VERSION_MIN_REQUIRED to 2.58.

[1] f9a9902aac

We have nm_clear_pointer() to avoid this issue for a long time (pre
1.12.0). Possibly we should redefine in our source tree g_clear_pointer()
as nm_clear_pointer(). However, I don't like to patch glib functions
with our own variant. Arguably, we do patch g_clear_error() in
such a manner. But there the point is to make the function inlinable.

Also, nm_clear_pointer() returns a boolean that indicates whether
anything was cleared. That is sometimes useful. I think we should
just consistently use nm_clear_pointer() instead, which does always
the preferable thing.

Replace:

   sed 's/\<g_clear_pointer *(\([^;]*\), *\([a-z_A-Z0-9]\+\) *)/nm_clear_pointer (\1, \2)/g' $(git grep -l g_clear_pointer) -i
2020-03-23 11:22:38 +01:00
Thomas Haller
073994ca42 all: use nm_clear_g_free() instead of g_clear_pointer()
I think it's preferable to use nm_clear_g_free() instead of
g_clear_pointer(, g_free). The reasons are not very strong,
but I think it is overall preferable to have a shorthand for this
frequently used functionality.

   sed 's/\<g_clear_pointer *(\([^;]*\), *\(g_free\) *)/nm_clear_g_free (\1)/g' $(git grep -l g_clear_pointer) -i
2020-03-23 11:05:34 +01:00
Antonio Cardace
fcbef9b6d3 ifcfg-rh: add 'timestamp' property before comparing a reread connection
Since ifcfg-rh doesn't write out to file the 'connection.timestamp' property
let's add it before comparing an updated connection with the plugin's reread
one otherwise the comparison operation would always fail.
The fix is not necessary for the keyfile plugin, because the reader/writer
correctly reads/writes the connection timestamp.
2020-03-19 17:26:08 +01:00
Thomas Haller
d482eec6b2 ifcfg-rh: use binary search for converting string to ethtool ID
Don't do a linear search through all names, but use binary search.

Upside: calling nms_ifcfg_rh_utils_get_ethtool_by_name() in a loop
(once over all 60 names) is 75% faster.

Downside: when adding a new feature, we have yet another line that we
need to add. Previously, adding a new feature required adding 7 lines,
not it is 8. But we didn't add a single feature since this was added,
so that happens very seldom.

Possible downside: is this code harder to read? Now we track both how to
convert the ID to name and back. This is redundant (and thus harder to
maintain). But it's really just one extra line per feature, for which there
is a unit test. So, when adding a new NMEthtoolID it would be pretty
hard to mess this up, because of all the tests and assertions.
So, maybe it's slightly harder to read. On the other hand, it unifies
handling for ethtool and kernel names, and the code has less logic
and is more descriptive. I don't think this is actually harder to maintain
and it should be easy to see that it is correct (readability).
2020-03-06 09:52:27 +01:00
Thomas Haller
a78b32a835 ifcfg-rh/tests: add test for consistency of ethtool ifcfg names 2020-03-06 09:49:32 +01:00
Thomas Haller
aa6bc2868d ifcfg-rh: use nm_utils_ifname_valid() for validating interface-name in reader
Maybe the reader should not try to add its own validation. It
could just read the value, set it in the profile, and let
nm_connection_verify() handle it.

However:

 - in this form the code only logs a warning about invalid setting.
   If we let it come to nm_connection_verify(), the connection profile
   will be entirely rejected. I think this makes sense, because ifcfg
   files may be edited by the user and we don't know what is out there.

 - it's nicer to show a warning that specifically mentions the DEVICE=
   variable. There error message we get from nm_connection_verify()
   is no longer aware of ifcfg peculiarities.

Instead: use the appropriate validation function.
2020-02-26 17:51:13 +01:00
Thomas Haller
ae1008b239 libnm: sort "mode" in nm_setting_bond_get_option() first
Internally, the options are tracked in a hash table and of undefined
sort order. However, nm_setting_bond_get_option() always returns a stable
(sorted) order.

Move "mode" as first, because that is usually the most interesting option.

The effect is:

  $ nmcli -o connection show "$BOND_PROFILE"
  ...
  -bond.options:  arp_interval=5,arp_ip_target=192.168.7.7,arp_validate=active,mode=balance-rr,use_carrier=0
  +bond.options:  mode=balance-rr,arp_interval=5,arp_ip_target=192.168.7.7,arp_validate=active,use_carrier=0

This doesn't affect keyfile, which sorts the hash keys themself (and
doesn't treat the "mode" special).

This however does affect ifcfg-rh writer how it writes the BONDING_OPTS
variable. I think this change is fine and preferable.
2020-02-19 17:15:26 +01:00
Antonio Cardace
6e9a36ab9f all: use nm_utils_ifname_valid_kernel() instead of nm_utils_is_valid_iface_name()
nm_utils_is_valid_iface_name() is a public API of libnm-core, let's use
our internal API.

$ sed -i 's/\<nm_utils_is_valid_iface_name\>/nm_utils_ifname_valid_kernel/g' $(git grep -l nm_utils_is_valid_iface_name)
2020-02-17 15:27:35 +01:00
Thomas Haller
de4aeb34e3 libnm,cli,ifcfg-rh: add ipv6.ra-timeout configuration option 2020-02-17 14:43:13 +01:00
Thomas Haller
843c546b84 ifcfg-rh: belatedly add support for "ipv6.dhcp-timeout" setting 2020-02-17 14:43:13 +01:00
Thomas Haller
9b82d29f5f ifcfg-rh: fix potential crash with variadic argument make_ip6_setting()
It is undefined behavior and can lead to crashes or memory corruption.
In practice, this only had an issue on Big Endian systems.

Fixes: fdbf4ae5e6 ('ifcfg-rh: add IPV4_DHCP_TIMEOUT key for ipv4.dhcp-timeout property')
2020-02-17 14:43:13 +01:00
Thomas Haller
d06092acbd ifcfg-rh: inline unnecessary function write_ip6_setting_dhcp_hostname()
If a function is only called once, it may not help to simplify the code
but make it more complicated. It would only simplify the code, if it
had a clear, distinct purpose. That isn't the case here. Also, the
IPv4 writer doesn't have such a function either. Drop and inline it.
2020-02-17 14:43:13 +01:00