Commit Graph

123 Commits

Author SHA1 Message Date
Yu Watanabe 28423d9a75 tree-wide: fix typo 2020-12-14 12:05:55 +00:00
Yu Watanabe db9ecf0501 license: LGPL-2.1+ -> LGPL-2.1-or-later 2020-11-09 13:23:58 +09:00
Michal Sekletár 2c8ec0095e udev/net_id: don't generate slot based names if multiple devices might claim the same slot 2020-10-19 17:55:44 +02:00
Michal Sekletár 3e545ae5ab udev/net_id: parse _SUN ACPI index as a signed integer
Negative value means there is no match between a PCI device and any of
the slots. In the following commit we will extend this and value of 0
will indicate that there is a match between some slot and PCI device,
but that device is a PCI bridge.
2020-10-19 12:18:03 +02:00
PhoenixDiscord e8607daf7d
Replace gendered pronouns with gender neutral ones. (#16844) 2020-08-27 11:52:48 +09:00
Lennart Poettering 56e577c62f tree-wide: use DISABLE_WARNING_FORMAT_NONLITERAL where appropriate 2020-05-25 18:25:05 +02:00
Lennart Poettering 3ce252d0e0 udev: use dot_or_dot_dot() where appropriate 2020-01-07 18:02:53 +01:00
Lennart Poettering b355d0c9af udev: move naming-scheme.[ch] into src/shared/
That way we can use it from non-udev code too, for example nspawn.
2020-01-02 19:34:00 +01:00
Yu Watanabe 78f8849f84 udev: extend the length of ID_NET_NAME_XXX= to ALTIFNAMSIZ 2019-12-17 11:04:11 +09:00
Lennart Poettering 335498ca57 docs: direct to systemd.io version of naming scheme docs
The document was imported back in
f9e6d49904. Let's make sure we actually
point to that version rather than the old one on freedesktop.
2019-12-11 12:09:02 +01:00
Yu Watanabe 1405cb653a tree-wide: drop stdio.h when stdio-util.h is included 2019-11-04 00:30:32 +09:00
Yu Watanabe 455fa9610c tree-wide: drop string.h when string-util.h or friends are included 2019-11-04 00:30:32 +09:00
Zbigniew Jędrzejewski-Szmek a5648b8094 basic/fs-util: change CHASE_OPEN flag into a separate output parameter
chase_symlinks() would return negative on error, and either a non-negative status
or a non-negative fd when CHASE_OPEN was given. This made the interface quite
complicated, because dependning on the flags used, we would get two different
"types" of return object. Coverity was always confused by this, and flagged
every use of chase_symlinks() without CHASE_OPEN as a resource leak (because it
would this that an fd is returned). This patch uses a saparate output parameter,
so there is no confusion.

(I think it is OK to have functions which return either an error or an fd. It's
only returning *either* an fd or a non-fd that is confusing.)
2019-10-24 22:44:24 +09:00
Yu Watanabe 657ee2d82b tree-wide: replace strjoin() with path_join() 2019-06-21 03:26:16 +09:00
Yu Watanabe 25de7aa7b9 udev: modernize udev-rules.c
This does the following:
- rename enum udev_builtin_cmd -> UdevBuiltinCmd
- rename struct udev_builtin -> UdevBuiltin
- move type definitions to udev-rules.h
- move prototypes of functions defined in udev-rules.c to udev-rules.h
- drop to use strbuf
- propagate critical errors in applying rules,
- drop limitation for number of tokens per line.
2019-06-02 14:15:26 +09:00
Zbigniew Jędrzejewski-Szmek 8c053c83ae udev: drop "en" prefix from ID_NET_NAME_ONBOARD
The comment in udev-builtin-net_id.c (removed in grandparent commit) showed the
property without the prefix. I assume that was always the intent, because it
doesn't make much sense to concatenate anything to an arbitrary user-specified
field.
2019-05-10 10:24:28 +02:00
Zbigniew Jędrzejewski-Szmek 4c27f691a5 udev: fix various comments
In particular: "re-renaming" was just a copy-paste error.
2019-05-10 10:24:28 +02:00
Zbigniew Jędrzejewski-Szmek 0b1e5b6ed8 man: describe naming schemes in a new man page
I decided to make this a separate man page because it is freakin' long.
This content could equally well go in systemd-udevd.service(8), systemd.link(5),
or a new man page for the net_id builtin.

v2:
- rename to systemd.net-naming-scheme
- add udevadm test-builtin net_id example
2019-05-10 10:24:03 +02:00
Jiri Pirko eaa9d507d8 udev: net_id: introduce predictable names for netdevsim
In order to properly and predictably name netdevsim netdevices,
introduce a separate implementation, as the netdevices reside on a
specific netdevsim bus. Note that this applies only to netdevsim devices
created using sysfs, because those expose phys_port_name attribute.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
2019-04-23 14:01:00 +02:00
Zbigniew Jędrzejewski-Szmek 35b351900f udev: move naming-scheme bits into their own file 2019-01-17 13:56:02 +01:00
Zbigniew Jędrzejewski-Szmek 1b2a7d92af Fix a few comments 2019-01-08 23:11:26 +01:00
Zbigniew Jędrzejewski-Szmek 06da5c63dd meson: make net.naming-scheme= default configurable
This is useful for distributions, where the stability of interface names should
be preseved after an upgrade of systemd. So when some specific release of the
distro is made available, systemd defaults to the latest & greatest naming
scheme, and subsequent updates set the same default. This default may still
be overriden through the kernel and env var options.

A special value "latest" is also allowed. Without a specific name, it is harder
to verride from meson. In case of 'combo' options, meson reads the default
during the initial configuration, and "remembers" this choice. When systemd is
updated, old build/ directories could keep the old default, which would be
annoying. Hence, "latest" is introduced to make it explicit, yet follow the
upstream. This is actually useful for the user too, because it may be used
as an override, without having to actually specify a version.
2018-12-12 10:09:36 +01:00
Lennart Poettering f7e81fd96f udev: introduce udev net_id "naming schemes"
With this we can stabilize how naming works for network interfaces. A
user can request through a kernel cmdline option or an env var which
scheme to follow. The idea is that installers use this to set into stone
(a very soft stone though) the scheme used during installation so that
interface naming doesn't change afterwards anymore.

Why use env vars and kernel cmdline options, and not a config file of
its own?

Well, first of all there's no obvious existing one to use. But more
importantly: I have the feeling that this logic is kind of an incomplete
hack, and I simply don't want to do advertise this as a perfectly
working solution. So far we used env vars for the non-so-official
options and proper config files for the official stuff. Given how
incomplete this logic is (i.e. the big variable for naming remains the
kernel, which might expose sysfs attributes in newer versions that we
check for and didn't exist in older versions — and other problems like
this), I am simply not confident in giving this first-class exposure in
a primary configuration file.

Fixes: #10448
2018-12-11 23:29:46 +01:00
Yu Watanabe d354690e7d udev-builtin: propagate negative errno 2018-10-23 18:29:25 +09:00
Yu Watanabe 981b8159e9 udev: drop libudev-private.h from udev-builtin-{hwdb,net_id}.c 2018-10-23 18:28:38 +09:00
Yu Watanabe 3fc2e9a247 udev: replace udev_device by sd_device from prototype of udev builtin commands 2018-10-23 18:28:38 +09:00
Yu Watanabe 09d04a74c1 udev: replace udev_device by sd_device in udev-builtin-net_id.c 2018-10-23 18:28:00 +09:00
Yu Watanabe bfc38d8fff udev: replace udev_device by sd_device in udev-builtin-hwdb.c 2018-10-23 17:51:34 +09:00
Yu Watanabe 0c9c063477 udev: make udev_builtin_add_property() take sd_device instead of udev_device 2018-10-23 17:51:34 +09:00
Yu Watanabe 14cb109d45 tree-wide: replace 'unsigned int' with 'unsigned' 2018-10-19 22:19:12 +02:00
Yu Watanabe 07a26e42da udev-builtin: move definitions related to builtin commands to udev-builtin.h 2018-10-11 04:21:14 +09:00
Joe Hershberger d81186ef4f udev: Allow acpi_index and index to be "0"
0 can be a valid index returned by the BIOS, so allow that by using the
parsing function safe_atolu() to check for errors without excluding the
valid value "0".

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
2018-10-02 22:58:15 +02:00
Zbigniew Jędrzejewski-Szmek 8a76031152 udev-builtin-net_id: do not assume "type" attribute exists
It *should*, but who knows, let's be more defensive here.

CID #1395805.
2018-09-25 11:29:54 +02:00
Lennart Poettering 614a8274f2 udev: fix some type sloppiness
We use strtoul() which returns an "unsigned long", but then assign this
to int or unsigned in, i.e. drop 32bit silently on 64bit systems. Let's
clean this up a bit, and retain the right types.
2018-09-25 09:20:16 +02:00
Arseny Maslennikov b8e8823e63 udev: Fix "strtol" -> "strtoul" for unsigned source values 2018-09-18 20:13:42 +03:00
Arseny Maslennikov cdd63a03ce udev: Provide a fallback for IPoIB device port numbers
In older kernels IPoIB network devices expose the port number via
the sysfs attribute 'dev_id', which is not intended to be used this way.
Let's support both options for a while.
2018-09-18 20:13:42 +03:00
Arseny Maslennikov a0d415da3a udev: Disable HW-address-based naming for IB NICs
An InfiniBand network address is 20 bytes long. Only the least
significant 8 bytes can be interpreted as a persistent hardware unit
identifier; the other 12 are transiently derived at runtime from metadata
specific to the protocol stack.

However, since the network interface name length is hard-capped by
IFNAMSIZ at 16 chars and the 2-byte type prefix with '\0' at the end
leave us only at 13, we cannot squeeze a descriptive representation of a
HW address into an interface name. Thus, it makes the most sense to drop
the scheme for IPoIB interfaces entirely.

Currently udev just gets confused and does what it has been taught
to do: fetches the first six bytes and puts them into a permanent
device attribute.
2018-09-18 20:13:42 +03:00
Arseny Maslennikov 938d30aa98 udev: Introduce predictable naming for InfiniBand NICs
We've long neglected IP-over-InfiniBand network interfaces, let's treat
them the same way we treat anyone else.

IPoIB interfaces will retain the 'ib' prefix; otherwise the naming scheme
is the same one we use for other network interfaces. E.g. a IPoIB network
device provided by a PCI card at bus 21 slot 0 function 6 will be named
'ibp21s0f6'.
2018-09-18 20:13:42 +03:00
Yu Watanabe 2024ed616e udev: drop unused udev struct 2018-09-10 18:27:36 +09:00
Yu Watanabe 152d0efa2b udev: move udev cleanup functions from udev-util.h to udev.h 2018-08-23 04:57:39 +09:00
Evgeni Golov eefe36e64c udev: net_id: document predictable names for SR-IOV virtual devices 2018-07-31 16:41:32 +09:00
Zbigniew Jędrzejewski-Szmek d9b02e1697 tree-wide: drop copyright headers from frequent contributors
Fixes #9320.

for p in Shapovalov Chevalier Rozhkov Sievers Mack Herrmann Schmidt Rudenberg Sahani Landden Andersen Watanabe; do
  git grep -e 'Copyright.*'$p -l|xargs perl -i -0pe 's|/([*][*])?[*]\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\s*[*]([*][*])?/\n*|\n|gms; s|\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\n*|\n|gms'
done
2018-06-20 11:58:53 +02:00
Lennart Poettering 96b2fb93c5 tree-wide: beautify remaining copyright statements
Let's unify an beautify our remaining copyright statements, with a
unicode ©. This means our copyright statements are now always formatted
the same way. Yay.
2018-06-14 10:20:21 +02:00
Lennart Poettering 818bf54632 tree-wide: drop 'This file is part of systemd' blurb
This part of the copyright blurb stems from the GPL use recommendations:

https://www.gnu.org/licenses/gpl-howto.en.html

The concept appears to originate in times where version control was per
file, instead of per tree, and was a way to glue the files together.
Ultimately, we nowadays don't live in that world anymore, and this
information is entirely useless anyway, as people are very welcome to
copy these files into any projects they like, and they shouldn't have to
change bits that are part of our copyright header for that.

hence, let's just get rid of this old cruft, and shorten our codebase a
bit.
2018-06-14 10:20:20 +02:00
Yu Watanabe fb702dd7dd udev: do not mark ari_enabled true when its sysattr value is 0 (#8870)
Fixes #8869.
2018-05-02 16:21:30 +02:00
Lennart Poettering 8e766630f0 tree-wide: drop redundant _cleanup_ macros (#8810)
This drops a good number of type-specific _cleanup_ macros, and patches
all users to just use the generic ones.

In most recent code we abstained from defining type-specific macros, and
this basically removes all those added already, with the exception of
the really low-level ones.

Having explicit macros for this is not too useful, as the expression
without the extra macro is generally just 2ch wider. We should generally
emphesize generic code, unless there are really good reasons for
specific code, hence let's follow this in this case too.

Note that _cleanup_free_ and similar really low-level, libc'ish, Linux
API'ish macros continue to be defined, only the really high-level OO
ones are dropped. From now on this should really be the rule: for really
low-level stuff, such as memory allocation, fd handling and so one, go
ahead and define explicit per-type macros, but for high-level, specific
program code, just use the generic _cleanup_() macro directly, in order
to keep things simple and as readable as possible for the uninitiated.

Note that before this patch some of the APIs (notable libudev ones) were
already used with the high-level macros at some places and with the
generic _cleanup_ macro at others. With this patch we hence unify on the
latter.
2018-04-25 12:31:45 +02:00
Zbigniew Jędrzejewski-Szmek 11a1589223 tree-wide: drop license boilerplate
Files which are installed as-is (any .service and other unit files, .conf
files, .policy files, etc), are left as is. My assumption is that SPDX
identifiers are not yet that well known, so it's better to retain the
extended header to avoid any doubt.

I also kept any copyright lines. We can probably remove them, but it'd nice to
obtain explicit acks from all involved authors before doing that.
2018-04-06 18:58:55 +02:00
Stuart Hayes 6bc04997b6 udev: net_id: Improve predictable names for NPAR devices
NPAR is a technology that allows a single network interface to
be divided into number of partitions. The partitions show up
as functions on the same PCI device... when there are more than
8 functions, ARI (alternative routing-ID interpretation) is
used. With ARI is enabled, the 8 bit field that normally has 5
bits for the PCI device and 3 bits for the PCI function is instead
interpreted as (implicit) device 0, with 8 bits for the function
number.

Because the linux kernel exposes the PCI device/function numbers
to userspace the same regardless of whether ARI is enabled,
systemd predictable device naming can generate unpredictable
names in this case, because network names using the PCI slot use
the function number, but not the device number, causing systemd
to generate the same name for mulitple network devices (so some
will revert to the "ethX" names).

With this patch, device naming code checks if ARI is enabled for
a PCI network device, and uses the full 8-bit function number
for naming to avoid this situation. This should improve
readability and predictability of device names.

Here is an example of how this change would affect naming:

before patch  |  after patch
-----------------------------
ens2f0        |  ens2f0        NPAR partition 0 (in PCI slot 2)
ens2f1        |  ens2f1        NPAR partition 1
...
ens2f7        |  ens2f7        NPAR partition 7
eth1          |  ens2f8        NPAR partition 8
eth2          |  ens2f9        NPAR partition 9
2018-03-26 14:00:43 -04:00
Stuart Hayes 609948c704 udev: net_id: Improve predictable names for SR-IOV virtual devices
With PCI SR-IOV, a number of virtual network devices can be enabled,
all of which share the same physical network device.  Currently,
udev generates names for SR-IOV virtual functions as if they were
independent network devices.

With this change, the predictable network device naming code will
check if a network device is an SR-IOV virtual device, and will
generate a name based on the physical PCI device plus a "v%u"
suffix.  This should improve readability and predictability of
device names.

Here is an example of how this change would affect naming:

before patch  |  after patch
-----------------------------
eno1          |  eno1          onboard NIC, physical function
enp101s0f0    |  eno1v0        onboard NIC, SR-IOV virtual func 0
enp101s0f1    |  eno1v1        onboard NIC, SR-IOV virtual func 1
2018-03-26 14:00:43 -04:00
Stuart Hayes 9009d3b5c3 udev: net_id: search parent devices for PCI slot number
To generate predictable network device names, the code in
udev-builting-net_id.c tries to match the PCI device address
of the network device to the entries in /sys/bus/pci/slots.
However, sometimes the slot number is not associated the
network controller PCI device itself, but rather with one of
its parents.

This change will try to find a match in /sys/bus/pci/slots for
the parents of the PCI network device, if it doesn't find a
match for the device itself.
2018-03-26 13:57:12 -04:00