Commit graph

40 commits

Author SHA1 Message Date
Lubomir Rintel
68f500f5ce initrd: add support for rd.znet_ifnames
This uses interface names specified rd.znet_ifnames on kernel command line
instead of automatically generated names if possible.

Accompanied by a test.

https://bugzilla.redhat.com/show_bug.cgi?id=1980387
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1070
2022-01-25 14:57:22 +01:00
Lubomir Rintel
79885656d3 initrd: don't add a connection if there's a connection dir with rd.neednet
Only create a default connection with rd.neednet if we're starting with
a totally blank slate. Otherwise it could be that the user already
included configuration in the initrd and merely wants us to activate it.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/999
2021-12-01 15:13:16 +01:00
Thomas Haller
615221a99c format: reformat source tree with clang-format 13.0
We use clang-format for automatic formatting of our source files.
Since clang-format is actively maintained software, the actual
formatting depends on the used version of clang-format. That is
unfortunate and painful, but really unavoidable unless clang-format
would be strictly bug-compatible.

So the version that we must use is from the current Fedora release, which
is also tested by our gitlab-ci. Previously, we were using Fedora 34 with
clang-tools-extra-12.0.1-1.fc34.x86_64.

As Fedora 35 comes along, we need to update our formatting as Fedora 35
comes with version "13.0.0~rc1-1.fc35".
An alternative would be to freeze on version 12, but that has different
problems (like, it's cumbersome to rebuild clang 12 on Fedora 35 and it
would be cumbersome for our developers which are on Fedora 35 to use a
clang that they cannot easily install).

The (differently painful) solution is to reformat from time to time, as we
switch to a new Fedora (and thus clang) version.
Usually we would expect that such a reformatting brings minor changes.
But this time, the changes are huge. That is mentioned in the release
notes [1] as

  Makes PointerAligment: Right working with AlignConsecutiveDeclarations. (Fixes https://llvm.org/PR27353)

[1] https://releases.llvm.org/13.0.0/tools/clang/docs/ReleaseNotes.html#clang-format
2021-11-29 09:31:09 +00:00
Beniamino Galvani
28770eb394 initrd: handle ip=dhcp,dhcp6 specially
With "ip=dhcp,dhcp6" the legacy dracut module does first DHCPv4 and
then IPv6 autoconf (even if DHCPv4 succeeded) [1]. In this way, there
is the guarantee that an address family is always configured if the
network supports it.

Currently "ip=dhcp,dhcp6" is treated a bit differently by NM, which
generates a connection with only ipv4.required-timeout=20s. Therefore
it's possible that NM in initrd quits (or signals startup-complete)
without an IPv6 even if the network is configured for IPv6.

Make NM's behavior similar to the legacy module by also setting an
ipv6.required-timeout for "ip=dhcp,dhcp6".

Note that if the command line contains "rd.neednet=1" without an "ip="
argument, we still generate a default connection with IPv4 preferred
over IPv6 (i.e. only ipv4.required-timeout set). That's similar to
what the legacy module does [2]. See [3] for a description of
different scenarios for "rd.neednet=1".

[1] https://github.com/dracutdevs/dracut/blob/055/modules.d/35network-legacy/ifup.sh#L459-L484
[2] https://github.com/dracutdevs/dracut/blob/055/modules.d/35network-legacy/ifup.sh#L529-L537
[3] https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/729

https://bugzilla.redhat.com/show_bug.cgi?id=1961666
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/994
2021-11-02 11:02:38 +01:00
Thomas Haller
abeedad315
initrd: reword warnings when parsing "rd.ethtool=" option
"Impossible to set rd.ethtool options: invalid format" is not very
clear. Try to explain what is invalid about the format (the interface
name is missing).

"Invalid value for rd.ethtool.autoneg, rd.ethtool.autoneg was not set"
is also confusing. The message gets printed if the autoneg value was
specified on the command line, so "was not set" seems wrong. Maybe the
message meant that the profile value is left at the default (FALSE),
but that isn't very clear.

Reword.
2021-09-21 08:29:47 +02:00
Thomas Haller
2c3f967d1a
initrd: only reset autoneg/speed if specified
The idea of positional arguments is that they might be extended in the
future. That means, there might be an option "rd.ethtool:eth0:::foo".

Also, if multiple "rd.ethtool:eth0" options are specified on the command
line, then the autoneg/speed settings should only be set if present.
That means

  "rd.ethtool:eth0:on:100 rd.ethtool:eth0:::foo"

should work as expected and first set autoneg/speed options, but the
second argument only sets "foo" (without resetting autoneg/speed).
2021-09-21 08:29:47 +02:00
Thomas Haller
b7b275dead
initrd: warn about disabling autoneg without setting speed
To NetworkManager, "autoneg=FALSE && speed=0" has the meaning to
not configure these options and leave whatever is configured previously.
That is also the default.

Explicitly configuring "rd.ethtool=eth0:off:0" is thus likely a misconfiguration,
because it tells NetworkManager to not configure the interface.

Note that the user can configure that, via "rd.ethtool=eth0::", that
is by omitting all parameters. That is a valid configuration and causes
no warning. The reason to support this silently, is so that we can
add in the future more positional arguments that the user can set
without changing autoneg/speed.
2021-09-21 08:29:47 +02:00
Thomas Haller
44e484a6aa
initrd: refactor parsing of "rd.ethtool=" to accept zero positional arguments
The point of positional arguments is that you can omit them, and that
should be treated as the parameter being set to the default.

So, don't treat "rd.ethtool=eth0" (or "rd.ethtool=eth0:") special.
Just continue the parsing and take all following positional arguments
as unset.
2021-09-21 08:29:46 +02:00
Thomas Haller
0e384b0170
initrd: refactor parsing of "rd.ethtool=" to not return after autoneg
Don't return early from parsing "autoneg", if there are not additional
arguments.

The behavior should be exactly the same, whether a positional
argument is missing, empty, or set to the default.

That is,

  - "rd.ethtool=eth0:on"
  - "rd.ethtool=eth0🔛"
  - "rd.ethtool=eth0🔛:"
  - "rd.ethtool=eth0🔛0:"

should all evaluate the same thing.

That was already the case in practice, but that was hard to see.
So don't treat missing positional arguments special and don't return
early. Parse all parameters regardless.

The change is visible when parsing "rd.ethtool=eth0:off:100 rd.ethtool=eth0:on".
Autoneg and speed really belongs together, so when we parse the second
argument, we should reset the speed too -- even if it's not present.
2021-09-21 08:29:46 +02:00
Thomas Haller
44b8c71ed5
initrd/tests: add more tests for "rd.ethtool" (test_rd_ethtool()) 2021-09-21 08:29:46 +02:00
Thomas Haller
f88a608050
initrd/tests: refactor tests for "rd.ethtool" (test_rd_ethtool())
It tests the same input as before (except, dropping the duplicate test
for "rd.ethtool=eth0🔛100:bogus").
2021-09-21 08:29:39 +02:00
Thomas Haller
01fd4b7d2c
initrd: fix crash parsing plain '=' without key
./src/nm-initrd-generator/nm-initrd-generator  -s -- =

Fixes: ecc074b2f8 ('initrd: add command line parser')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/776
2021-08-30 09:15:19 +02:00
Thomas Haller
553721eed7
initrd/tests: add _parse_no_con() macro 2021-08-30 09:14:34 +02:00
Thomas Haller
ea49b50651
all: add some README.md files describing the purpose of our sources 2021-08-19 17:51:11 +02:00
Ana Cabral
750d35a6e3 nm-initrd-generator: remove duplex option 2021-08-17 12:00:37 -03:00
Ana Cabral
f06c89f596 nm-initrd-generator: add kernel command line options ethtool autoneg, speed and duplex to configure NICs
Merge Request !941
2021-08-11 13:55:43 -03:00
Thomas Haller
593cb57eb6
all: rename nm_utils_strdict_*() to nm_strdict_*() 2021-08-02 09:26:48 +02:00
Thomas Haller
3587cbd827
all: rename nm_utils_strsplit_set*() to nm_strsplit_set*() 2021-08-02 09:26:47 +02:00
Thomas Haller
4ac66a4215
all: rename nm_utils_strdup_reset*() to nm_strdup_reset*() 2021-08-02 09:26:47 +02:00
Thomas Haller
4c3aac899e
all: unify and rename strv helper API
Naming is important, because the name of a thing should give you a good
idea what it does. Also, to find a thing, it needs a good name in the
first place. But naming is also hard.

Historically, some strv helper API was named as nm_utils_strv_*(),
and some API had a leading underscore (as it is internal API).

This was all inconsistent. Do some renaming and try to unify things.

We get rid of the leading underscore if this is just a regular
(internal) helper. But not for example from _nm_strv_find_first(),
because that is the implementation of nm_strv_find_first().

  - _nm_utils_strv_cleanup()                 -> nm_strv_cleanup()
  - _nm_utils_strv_cleanup_const()           -> nm_strv_cleanup_const()
  - _nm_utils_strv_cmp_n()                   -> _nm_strv_cmp_n()
  - _nm_utils_strv_dup()                     -> _nm_strv_dup()
  - _nm_utils_strv_dup_packed()              -> _nm_strv_dup_packed()
  - _nm_utils_strv_find_first()              -> _nm_strv_find_first()
  - _nm_utils_strv_sort()                    -> _nm_strv_sort()
  - _nm_utils_strv_to_ptrarray()             -> nm_strv_to_ptrarray()
  - _nm_utils_strv_to_slist()                -> nm_strv_to_gslist()
  - nm_utils_strv_cmp_n()                    -> nm_strv_cmp_n()
  - nm_utils_strv_dup()                      -> nm_strv_dup()
  - nm_utils_strv_dup_packed()               -> nm_strv_dup_packed()
  - nm_utils_strv_dup_shallow_maybe_a()      -> nm_strv_dup_shallow_maybe_a()
  - nm_utils_strv_equal()                    -> nm_strv_equal()
  - nm_utils_strv_find_binary_search()       -> nm_strv_find_binary_search()
  - nm_utils_strv_find_first()               -> nm_strv_find_first()
  - nm_utils_strv_make_deep_copied()         -> nm_strv_make_deep_copied()
  - nm_utils_strv_make_deep_copied_n()       -> nm_strv_make_deep_copied_n()
  - nm_utils_strv_make_deep_copied_nonnull() -> nm_strv_make_deep_copied_nonnull()
  - nm_utils_strv_sort()                     -> nm_strv_sort()

Note that no names are swapped and none of the new names existed
previously. That means, all the new names are really new, which
simplifies to find errors due to this larger refactoring. E.g. if
you backport a patch from after this change to an old branch, you'll
get a compiler error and notice that something is missing.
2021-07-29 10:26:50 +02:00
Thomas Haller
3775f4395a
all: drop unnecessary casts from nm_utils_strv_find_first()
And, where the argument is a GPtrArray, use
nm_strv_ptrarray_find_first() instead.
2021-07-29 09:33:50 +02:00
Thomas Haller
8b25221689
initrd: rework parsing of ip method from "ip="
Dracut supports several options for the "ip=" method.

NetworkManager interprets and handles them in a certain way that aims to
give a similar behavior. But as such it maps different settings ("auth6"
and "dhcp6") to exactly the same behavior.

Add _parse_ip_method() function to normalize these keys, and map their
aliases to the keyword that nm-initrd-generator handles. The advantage
is that you see now in _parse_ip_method() which methods are mapped to
the same behavior, and the later (more complex) code only deals with the
normalized kinds.

Also, use the same validation code at all 3 places where IP methods
can appear, that is

  ip=<method>
  ip=<ifname>:<method>[:...]
  ip=<client-ip>:...:<method>[:...]

Also, dracut supports specifying multiple methods and concatenate them
with comma. nm-initrd-generator only did partly, for example,
`ip=dhcp,dhcp6" would have worked, but only because the code failed
to recognize the string and fell back to the default behavior. It would
not have worked as `ip=<ifname>:dhcp,dhcp6[:...]`. Not all combinations
make sense, but some do. So let _parse_ip_method() detect and handle
them. Currently, they mostly map to "auto", but in the future it might
make sense that `ip=dhcp,local6` is a distinct kind.

Try to tighten up the parsing. It's fine to be forgiving and flexible
about what we parse, but bogus values should not silently be
accepted. However, in order to keep previous behavior, `ip=bogus`
and `ip=<client-ip>:...:<bogus-method>[:...]` explicitly map invalid
method to "auto".
2021-07-29 09:23:22 +02:00
Thomas Haller
6fa7f2e06c
initrd: honor "ip=fw" alias for "ip=ibft" in reader_parse_ip()
This alias was introduced by commit [1], without further explaination
or documentation. As we already have it, implement it fully.

[1] 7a72c705ac
2021-07-28 23:32:47 +02:00
Beniamino Galvani
86f22ce8ba initrd: add a 'origin' user tag to connections
Introduce a user tag key to indicate where the connection comes
from. It would also be possible to have this as a standard property
(as 'connection.origin'), but since this information can be considered
'meta-data' I think the user setting is more appropriate.
2021-07-27 16:36:48 +02:00
Beniamino Galvani
9060c14ccf initrd: support infiniband pkeys
Introduce a new "ib.pkey=<parent>.<pkey>" command line argument to
create a Infiniband partition.

The new connection has IPv4 and IPv6 enabled by default. Unlike for
VLANs, the generator doesn't create a connection for the parent
Infiniband interface.

See also: https://github.com/dracutdevs/dracut/pull/1538

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/884
2021-07-26 14:56:18 +02:00
Thomas Haller
22d6be54f3
initrd: fix handling "ip=single-dhcp:..." in reader_parse_ip()
Fixes: bf7530ccc1 ('initrd: honor "ip=single-dhcp" option as alias for "dhcp"')
2021-07-23 11:36:41 +02:00
Thomas Haller
bf7530ccc1
initrd: honor "ip=single-dhcp" option as alias for "dhcp"
This mode was added to network-legacy in [1]. NetworkManager anyway always
does DHCP in parallel, so this is basically an alias for "dhcp".
Note that network-legacy's "single-dhcp" will stop waiting for DHCP
once the first device gets an address. NetworkManager currently cannot
do that. While it runs DHCP in parallel, all devices need to settle
and there is no concept where completing one device makes the overall
"startup complete" process finish early. That could however be added.

Anyway, while not being exactly the same, it's still more useful to do
something similar instead of not working at all.

See-also: https://github.com/dracutdevs/dracut/pull/853
See-also: https://github.com/dracutdevs/dracut/pull/961
See-also: https://github.com/dracutdevs/dracut/pull/1048

[1] 4026cd3b01
2021-07-23 11:06:06 +02:00
Beniamino Galvani
0a18e97345 initrd: set required-timeout for default IPv4 configuration
If the kernel command-line doesn't contain an explict ip=$method,
currently the generator creates connections with both IPv4 and IPv6
set to 'auto', and both allowed to fail.

Since NM is run in configure-and-quit mode in the initrd, NM can get
an IPv4 address or an IPv6 one (or both) depending on which address
family is quicker to complete. This unpredictable behavior is not
present in the legacy module, which always does IPv4 only by default.

Set a required-timeout of 20 seconds for IPv4, so that NM will
preferably get an IPv4, or will fall back to IPv6.

See also: https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/729
2021-07-05 15:15:45 +02:00
Beniamino Galvani
fa42ba9df2 initrd: rename NMI_WAIT_DEVICE_TIMEOUT_MS to _MSEC 2021-07-05 15:15:44 +02:00
Thomas Haller
09fb7877a9
build: fix linking libnm-log-null into different test programs
We require these, otherwise we can get a linker error about
_nm_utils_monotonic_timestamp_initialized symbol being undefined.
2021-07-05 14:51:27 +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
995c78245e
glib-aux/trivial: rename NMUuid API 2021-05-04 15:51:49 +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
Andrew Zaborowski
38ac64ba62
glib-aux: Set file timestamps in nm_utils_file_set_contents
Extend nm_utils_file_set_contents to be able to optionally set the last
access + last modification times on the file being created, in addition
to the mode.
2021-04-19 18:11:11 +02:00
Beniamino Galvani
c21d4ce125 Revert "initrd: set the bootif MAC in existing connection with ifname"
This reverts commit 389575a6b1.

When the command line contains BOOTIF and there is another ip=
argument specifying an interface name, we can follow 2 approaches:

 a) BOOTIF creates a new distinct connection with DHCP
    (the behaviour before the commit)

 b) the connection generated for ip= will be also be bound to the
    BOOTIF MAC (the behavior introduced by the commit)

Restore a) because we can't be sure that the MAC address refers to the
same interface. In that case it's preferable to generate a different
connection.

https://bugzilla.redhat.com/show_bug.cgi?id=1915493#c35
2021-03-26 07:26:55 +01:00
Beniamino Galvani
0f8fe3c76b initrd: fix crash parsing empty rd.znet argument
Ignore a rd.znet argument without subchannels. When using net.ifnames
(the default), subchannels are used to build the interface name, which
is required to match the right connection.

With net.ifnames=0 the interface name is build using a prefix and a
global counter and therefore in theory it is possible to omit
subchannels. However, without subchannels there won't be a udev rule
that renames the interface and so it can't work.

https://bugzilla.redhat.com/show_bug.cgi?id=1931284
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/783
2021-03-17 10:02:09 +01:00
Thomas Haller
c91dfb850e
initrd: avoid cloning string in reader_parse_rd_znet()
The code did:

   key    = g_strndup(tmp, val - tmp);
   val[0] = '\0';

That is pointless. If we strndup the key, we don't need to truncate
the string at the '='. It might be nicer not to mutate the input string,
however, the entire code with "argument" parsing is about mutating the
input string, so that is something we apparently are fine with.

As such, don't clone the string anymore.
2021-03-16 11:58:09 +01:00
Thomas Haller
bb132cd6de
libnm: verify ethernet.s390-options.bridge_role value
I don't want to fix this for all "ethernet.s390-options" options,
but at least strictly validate the newly introduced option.
2021-03-16 11:56:31 +01:00
Thomas Haller
74a4ee16f5
initrd: silently ignore invalid "ethernet.s390-options" 2021-03-16 09:55:48 +01:00
Thomas Haller
9fc1bf90fa
initrd: move "src/core/initrd/" to "src/nm-initrd-generator/" 2021-03-15 17:10:53 +01:00