Commit graph

70 commits

Author SHA1 Message Date
Thomas Haller
9f95b797f1 initrd/cmdline: minor style cleanups 2020-01-14 16:43:26 +01:00
Lubomir Rintel
39e1e723de initrd/cmdline: obey rd.iscsi.ibft
Do process the connections from the iBFT block if the rd.iscsi.ibft or
rd.iscsi.ibft=1 argument is present.

This is supposed to fix what was originally reported by Kairui Song
<kasong@redhat.com> here: https://github.com/dracutdevs/dracut/pull/697
2020-01-14 16:43:26 +01:00
Lubomir Rintel
59ead70952 initrd/ibft-reader: don't set con.interface-name in iBFT connections
If an argument in form ip=eth0:ibft is specified, we'd first create a
wired connection with con.interface-name and then proceed completing it
from the iBFT block. At that point we also add the MAC address, so the
interface-name is no longer necessary..

Worse even, for VLAN connections, it results in an attempt to create
a VLAN with the same name as the parent wired device. Ooops.

Let's just drop it. MAC address is guarranteed to be there and does the
right thing for both plain wired devices as well as VLANs.
2020-01-14 16:43:26 +01:00
Thomas Haller
d964decbbd libnm/keyfile: build keyfile code as separate GPL licensed internal library
Keyfile support was initially added under GPL-2.0+ license as part of
core. It was moved to "libnm-core" in commit 59eb5312a5 ('keyfile: merge
branch 'th/libnm-keyfile-bgo744699'').

"libnm-core" is statically linked with by core and "libnm". In
the former case under terms of GPL-2.0+ (good) and in the latter case
under terms of LGPL-2.1+ (bad).

In fact, to this day, "libnm" doesn't actually use the code. The linker
will probably remove all the GPL-2.0+ symbols when compiled with
gc-sections or LTO. Still, linking them together in the first place
makes "libnm" only available under GPL code (despite the code
not actually being used).

Instead, move the GPL code to a separate static library
"shared/nm-keyfile/libnm-keyfile.la" and only link it to the part
that actually uses the code (and which is GPL licensed too).

This fixes the license violation.

Eventually, it would be very useful to be able to expose keyfile
handling via "libnm". However that is not straight forward due to the
licensing conflict.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/381
2020-01-07 13:17:47 +01:00
Thomas Haller
9f76f5eb81 initrd: don't use inet_aton() to parse IPv4 address
inet_aton() is very accepting when parsing the address. For example,
it accepts addresses with fewer octets (interpreting the last octet
as a number in network byte order for multiple bytes). It also ignores
any trailing garbage after the first delimiting whitespace (at least,
the glibc implementation). It also accepts octets in hex and octal
notation.

For the initrd reader we want to be more forgiving than inet_pton()
and also accept addresses like 255.000.000.000 (octal notation). For
that we would want to use inet_aton(). But we should not accept all the
craziness that inet_aton() otherwise accepts.

Use nm_utils_parse_inaddr_bin_full() instead. This function implements
our way how we want to interpret IP addresses in string representation.
Under the hood, of course it also uses inet_pton() and even inet_aton(),
but it is stricter than inet_aton() and only accepts certain formats.

(cherry picked from commit d68373c305)
2019-12-05 13:12:04 +01:00
Thomas Haller
4f3e31f7c5 initrd: fix out-of-bounds read when detecting address family in dt_get_ipaddr_property()
The @family argument is an input and output argument.

Initially, the family is set to AF_UNSPEC, in which case the family
gets detected based on the IP address. However, we call
dt_get_ipaddr_property() multiple times to parse the netmask, the
gateway and the IP address.

That means, after the first successfull call, the @family is set to
AF_INET or AF_INET6.

Note that the previous code (in the switch block) would only check that
the family is set to AF_UNSPEC, but it would not check that the @family
matches the expected binary address length @len. Later, we then might call
nm_ip_address_new_binary() with a family and a binary address of
unexpected length.

Also drop the error checking for nm_ip_address_new_binary().
nm_ip_address_new_binary() can only fail if the prefix length is larger
than 32/128. The function has no way to validate the input arguments
beyond that and can thus not fail (short of undefined behavior).

(cherry picked from commit 9618f1bb4b)
2019-12-05 13:12:04 +01:00
Thomas Haller
90c33b798e initrd: use cleanup attribute in nmi_dt_reader_parse()
(cherry picked from commit e7cf22be3e)
2019-12-05 13:12:04 +01:00
Thomas Haller
f970039122 initrd: fix use-after-free for variable "s_gateway" in nmi_dt_reader_parse()
(cherry picked from commit 321a323df4)
2019-12-05 13:12:04 +01:00
Thomas Haller
1367e8a1b8 initrd: generate IPv6 profiles with ipv6.addr-gen-mode=eui64
https://bugzilla.redhat.com/show_bug.cgi?id=1779389
(cherry picked from commit ea4e95ec33)
2019-12-04 18:28:47 +01:00
Lubomir Rintel
cdfa3d3428 initrd/tests: put the bootif=no next to the other bootif tests
A cosmetical improvement.
2019-11-18 13:40:48 +01:00
Lubomir Rintel
45548bc670 dracut/cmdline: don't combine BOOTIF with on with a name or a MAC address
This fixes the dracut test suite.
2019-11-18 13:40:48 +01:00
Lubomir Rintel
e1a068e93c initrd/cmdline: split add_conn() from get_conn()
No change in behavior. Will be useful when we'll want to unconditionally
add new connection without the matching behavior.
2019-11-18 13:40:48 +01:00
Lubomir Rintel
30f8154319 initrd: don't overwrite just any connection's name with bootdev= argument
It is really not clear what the user could have meant by specifying a
bootdev= argument, and we deal with it just by ensuring a device with
that name whould come up.

We therefore pick a default connection if there's one (that is a
conneciton that we create if the device name is unspecified, as in
"ip=auto"), otherwise we create a new one.
2019-11-18 13:40:48 +01:00
Lubomir Rintel
f581756af6 initrd: default bridge name to br0 as opposed to bridge0
For compatibility. The dracut.cmdline(7) manual says:

  Bridge without parameters assumes bridge=br0:eth0
2019-11-18 13:40:48 +01:00
Lubomir Rintel
927ae6d927 initrd/tests: test that we generate the s390 interface names correctly 2019-11-04 16:22:14 +01:00
Dan Horák
22e388d90e initrd: handle rd.znet with legacy interface names
Handle rd.znet with legacy interface names too, the index for eth or ctc
corresponds to the position on the command line.
2019-11-04 16:22:14 +01:00
Dan Horák
c7423dca89 initrd: prepare interface in rd.znet only if persistent interface names are enabled
When processing the rd.znet option set the interface name only in case when
the persistent interface names feature isn't disabled via net.ifnames=0

[lkundrak@v3.sk: minor tweaks to the net.ifnames=0 parsing]
2019-11-04 16:21:58 +01:00
Dan Horák
c27f5030e9 initrd/tests: use a valid combination of device and interface name for testing 2019-11-04 16:21:16 +01:00
Dan Horák
adcc52c3da initrd: use proper interface when adding s390 specific details
The current solution for s390 specific details relies on an interface to
exist before adding the s390 details. It means the ip= option must precede
the rd.znet= option. Also only a single interface can be configured. With
this change the s390 details are put to the right interface and properly
named interface is created if it hasn't existed yet.
2019-11-04 15:44:58 +01:00
Thomas Haller
3b69f02164 all: unify format of our Copyright source code comments
```bash

readarray -d '' FILES < <(
  git ls-files -z \
    ':(exclude)po' \
    ':(exclude)shared/c-rbtree' \
    ':(exclude)shared/c-list' \
    ':(exclude)shared/c-siphash' \
    ':(exclude)shared/c-stdaux' \
    ':(exclude)shared/n-acd' \
    ':(exclude)shared/n-dhcp4' \
    ':(exclude)src/systemd/src' \
    ':(exclude)shared/systemd/src' \
    ':(exclude)m4' \
    ':(exclude)COPYING*'
  )

sed \
  -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) *[-–] *\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C1pyright#\5 - \7#\9/' \
  -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) *[,] *\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C2pyright#\5, \7#\9/' \
  -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C3pyright#\5#\7/' \
  -e 's/^Copyright \(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/C4pyright#\1#\3/' \
  -i \
  "${FILES[@]}"

echo ">>> untouched Copyright lines"
git grep Copyright "${FILES[@]}"

echo ">>> Copyright lines with unusual extra"
git grep '\<C[0-9]pyright#' "${FILES[@]}" | grep -i reserved

sed \
  -e 's/\<C[0-9]pyright#\([^#]*\)#\(.*\)$/Copyright (C) \1 \2/' \
  -i \
  "${FILES[@]}"

```

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/298
2019-10-02 17:03:52 +02:00
Iñigo Martínez
4e5b1e257e meson: Improve nm-initrd-generator target
The set of link targets used when building `nm-initrd-generator`
target has been grouped together.
2019-10-01 09:49:33 +02:00
Iñigo Martínez
31f1516760 meson: Improve the src build file
The targets that involve the use of the `NetworkManager` library,
built in the `src` build file have been improved by applying a set
of changes:

- Indentation has been fixed.
- Set of objects used in targets have been grouped together.
- Aritificial dependencies used to group dependencies and custom
  compiler flags have been removed and their use replaced with
  proper dependencies and compiler flags to avoid any confussion.
2019-10-01 09:49:33 +02:00
Iñigo Martínez
f427f4771e meson: Improve the libnm-core build file
The `libnm-core` build file has been improved by applying a set of
changes:

- Indentation has been fixed to be consistent.
- Library variable names have been changed to `lib{name}` pattern
  following their filename pattern.
- `shared` prefix has been removed from all variables using it.
- Dependencies have been reviewed to store the necessary data.
- The use of the libraries and dependencies created in this file
  has been reviewed through the entire source code. This has
  required the addition or the removal of different libraries and
  dependencies in different targets.
- Some files used directly with the `files` function have been moved
  to their nearest path build file because meson stores their full
  path seamessly and they can be used anywhere later.
2019-10-01 09:49:33 +02:00
Iñigo Martínez
70a34c54fe meson: Use dependency for nm-default header
The `nm-default.h` header is used widely in the code by many
targets. This header includes different headers and needs different
libraries depending the compilation flags.

A new set of `*nm_default_dep` dependencies have been created to
ease the inclusion of different directorires and libraries.

This allows cleaner build files and avoiding linking unnecessary
libraries so this has been applied allowing the removal of some
dependencies involving the linking of unnecessary libraries.
2019-10-01 09:49:33 +02:00
Thomas Haller
abff46cacf all: manually drop code comments with file description 2019-10-01 07:50:52 +02:00
Thomas Haller
eea783d129 initrd: make "argv" argument of nmi_cmdline_reader_parse() a const strv 2019-09-27 09:20:06 +02:00
Thomas Haller
eea8ee2321 initrd/tests: check for the parsed values in detail for rd.znet test 2019-09-27 09:20:06 +02:00
Thomas Haller
19604cb126 initrd: avoid modifying the argv argument in nmi_cmdline_reader_parse()
While nmi_cmdline_reader_parse() only has one caller, which indeed has the
argv parameter at hand and doesn't care it to be modified, I think it
is ugly.

Arguments preferably are strictly either input or output arguments,
with input arguments not being modified by the call.
2019-09-27 09:20:06 +02:00
Thomas Haller
783fe28465 initrd: avoid assertion inparse_rd_znet() and cleanup
- nm_setting_wired_add_s390_option() asserts that a "value" argument
  is given. Check that the string contains a '=' where we can split.

- pass the requested NM_SETTING_WIRED_SETTING_NAME type to get_conn().
  Otherwise, @s_wired might be %NULL, resulting in an assertion.
  I do wonder whether this always retrieves a connection of the
  appropriate type for modification, or whether a profile could
  be returned that was created for a different purpose. But that
  isn't changed.

- avoid "g_strcmp0 (nettype, "ctc") != 0". I find it unexpected, that we add the
  3rd subchannel component, if the nettype is "ctc" (intuitively, I'd expect it
  to be the opposite). The reasons for this are not documented, but I
  presume it is correct.
  Anyway, using streq() makes this slightly more clear to me, as with
  strcmp() I would wonder whether this was just a typo while with
  streq() I'd be more confident that this is indeed intended.

- don't initialize local variables unnecessarily. The compiler would
  warn if we would forget about this. Also, don'\''t use { } for a
  one-line block.
2019-09-27 09:18:43 +02:00
Dan Horák
df07539105 nm-initrd-generator - add test for rd.znet 2019-09-27 09:17:57 +02:00
Dan Horák
11d4412ee1 process s390 specific device info from rd.znet parameter in nm-initrd-generator
syntax: rd.znet=<nettype>,<subchannels>,<options>

The s390 specific options used to create the network interface in the kernel
are currently not processed by nm-initrd-generator causing incomplete ifcfg file.

fixes https://bugzilla.redhat.com/show_bug.cgi?id=1753975
2019-09-27 09:17:57 +02:00
Lubomir Rintel
24028a2246 all: SPDX header conversion
$ find * -type f |xargs perl contrib/scripts/spdx.pl
  $ git rm contrib/scripts/spdx.pl
2019-09-10 11:19:56 +02:00
Lubomir Rintel
7a72c705ac initrd: add devicetree support
This adds capability to hand over the network configuration from
OpenFirmware (and potentially other boot loaders with openfirmware
support such as U-Boot) to NetworkManager.

It's done analogously to ACPI/iBFT. In fact, the same ip=ibft command
line option is used, adding a more general ip=fw alias. This probably
deserves some documentation, but I'm not adding any at this time.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/257
2019-09-10 11:04:51 +02:00
Thomas Haller
b216abb012 shared,all: return boolean success from nm_utils_file_get_contents()
... and nm_utils_fd_get_contents() and nm_utils_file_set_contents().

Don't mix negative errno return value with a GError output. Instead,
return a boolean result indicating success or failure.

Also, optionally

  - output GError

  - set out_errsv to the positive errno (or 0 on success)

Obviously, the return value and the output arguments (contents, length,
out_errsv, error) must all agree in their success/failure result.
That means, you may check any of the return value, out_errsv, error, and
contents to reliably detect failure or success.

Also note that out_errsv gives the positive(!) errno. But you probably
shouldn't care about the distinction and use nm_errno_native() either
way to normalize the value.
2019-08-08 11:59:59 +02:00
Thomas Haller
1bad35061f shared: let nm_utils_file_set_contents() return a errno error code
nm_utils_file_set_contents() is a re-implementation of g_file_set_contents(),
as such it returned merely a boolean success value.

It's sometimes interesting to get the native error code. Let the function
deviate from glib's original g_file_set_contents() and return the error code
(as negative value) instead.

This requires all callers to change. Also, it's potentially a dangerous
change, as this is easy to miss.

Note that nm_utils_file_get_contents() also returns an errno, and
already deviates from g_file_get_contents() in the same way. This patch
resolves at least the inconsistency with nm_utils_file_get_contents().
2019-08-08 10:53:03 +02:00
Thomas Haller
2ecc7e8cb5 initrd: avoid coverity warning in parse_ip() about "Dereference before null check"
get_word() only moves the "argument" pointer forward. It never sets it
to %NULL. Also, above we already dereference argument, so Coverity thinks
that this NULL check indicates a bug.

Drop it to silence Coverity.

(cherry picked from commit 4596d7793c)
2019-08-02 11:10:51 +02:00
Lubomir Rintel
93859d8ffd initrd/tests: add some more variations of possible BOOTIF= variables
Test the form with a hwtype and color-separated as well as
hyphen-separated.
2019-07-03 09:16:52 +02:00
Lubomir Rintel
2952953a48 initrd: skip ethernet hwtype in BOOTIF
Dracut documents the BOOTIF argument to be a MAC address and so we
accept one in any of the conventions we recognize. However, the PXE boot
loaders like to prepend a "01-" to denote an ethernet hardware type.
Accept that too.

https://bugzilla.redhat.com/show_bug.cgi?id=1726240
2019-07-03 09:16:52 +02:00
Lubomir Rintel
39d5c8c12f initrd/tests: ensure that nameserver= setting affects the correct connection 2019-07-02 13:43:06 +02:00
Lubomir Rintel
6da2058237 initrd: don't create a default connection if there's already one
Certain arguments (such as "nameserver") don't specify a connection they
apply to and using them would generate a default ethernet connection.
This is probably not the right thing to do.
2019-07-02 13:43:06 +02:00
Lubomir Rintel
77540b2a7c initrd/tests: ensure we accept a prefix in place of an IPv4 mask 2019-07-02 13:42:19 +02:00
Lubomir Rintel
390d79079e initrd: allow specifying the net mask in form of a prefix
This is not documented in dracut.cmdline(7), however it seems to have
worked and has users and Red Hat even seems to recommend this (thanks to
Dan Horak for the pointers):

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/installation_guide/chap-installer-booting-ipl-s390
https://bugzilla.redhat.com/show_bug.cgi?id=1725872
2019-07-02 13:42:19 +02:00
Lubomir Rintel
920e59016f initrd: remove an accidental backspace 2019-07-02 13:42:09 +02:00
Lubomir Rintel
4b097e314e initrd: fix error reporting on bad netmask
It says the address is bad, but what is wrong is the mask.
2019-07-02 10:29:23 +02:00
Beniamino Galvani
e6628fa27c ipv6: add 'disabled' method
Add a new ipv6.method value 'disabled' that completely disables IPv6
for the interface.

https://bugzilla.redhat.com/show_bug.cgi?id=1643841
2019-06-11 16:22:04 +02:00
Thomas Haller
c5e0e33b52 initrd/tests: increase test timeout for "initrd/test-cmdline-reader" with meson
The default timeout of 30 seconds may not be sufficient when running under valgrind
on a busy system.
2019-06-11 08:54:40 +02:00
Lubomir Rintel
04621c6c0f initrd/cmdline: add support for rd.neednet option
This is used to indicate the network dracut module should fall back to
configure network automatically (as with ip=dhcp was specified) if
there's no other network configuration present on the command line.

The option is documented in dracut.cmdline(7).

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/167
2019-05-28 11:26:17 +02:00
Thomas Haller
e7836cd151 build/meson: rename "nm_core_dep" to "libnm_core_dep"
The library is called "libnm_core". So the dependency should be called
"libnm_core_dep", like in all other cases.

(cherry picked from commit c27ad37c27)
2019-04-18 20:13:49 +02:00
Thomas Haller
d984b2ce4a shared: move most of "shared/nm-utils" to "shared/nm-glib-aux"
From the files under "shared/nm-utils" we build an internal library
that provides glib-based helper utilities.

Move the files of that basic library to a new subdirectory
"shared/nm-glib-aux" and rename the helper library "libnm-core-base.la"
to "libnm-glib-aux.la".

Reasons:

 - the name "utils" is overused in our code-base. Everything's an
   "utils". Give this thing a more distinct name.

 - there were additional files under "shared/nm-utils", which are not
   part of this internal library "libnm-utils-base.la". All the files
   that are part of this library should be together in the same
   directory, but files that are not, should not be there.

 - the new name should better convey what this library is and what is isn't:
   it's a set of utilities and helper functions that extend glib with
   funcitonality that we commonly need.

There are still some files left under "shared/nm-utils". They have less
a unifying propose to be in their own directory, so I leave them there
for now. But at least they are separate from "shared/nm-glib-aux",
which has a very clear purpose.

(cherry picked from commit 80db06f768)
2019-04-18 19:57:27 +02:00
Thomas Haller
8f62c76c0a license: re-license initrd-generator and ibft reader as LGPL
New code we want to add LGPL licensed to make it easier to share code
between libnm and the daemon.

The code in question was only recently added in commit b544f7243d
("initrd: add iBFT reader") and mostly written from scratch by Lubomir.

Some parts were adapted from earlier ibft code.

  $ git shortlog -s -e -- src/settings/plugins/ibft/  ':(exclude)*/meson.build'
       3    Beniamino Galvani <bgalvani@redhat.com>
       1    Colin Walters <walters@verbum.org>
       2    Dan Williams <dcbw@redhat.com>
      17    Dan Winship <danw@redhat.com>
       7    Lubomir Rintel <lkundrak@v3.sk>
      46    Thomas Haller <thaller@redhat.com>

  $ git log --no-merges -L '/^fill_ip4_setting_from_ibft/,/^}/:src/settings/plugins/ifcfg-rh/reader.c' fc9c1f1557b517e799d15802e8f3d0ea43b0daea~ | grep '^Author: ' | sort | uniq
  Author: Dan Williams <dcbw@redhat.com>
  Author: Dan Winship <danw@redhat.org>
  Author: Jiří Klimeš <jklimes@redhat.com>
  Author: Pavel Šimerda <psimerda@redhat.com>

Hence, all non-trival contributions were provided by Red Hat employees
and the copy-right is with Red Hat.

Acked-by: Dan Williams <dcbw@redhat.com>
Acked-by: Dan Winship <danw@redhat.com>
Acked-by: Lubomir Rintel <lkundrak@v3.sk>
2019-02-22 21:06:00 +01:00