Commit graph

100 commits

Author SHA1 Message Date
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
Filipe Brandenburger 8eebb6a9e5 udev/net-id: Fix check for address to keep interface names stable (#8458)
This was a bug inadvertently added by commit 73fc96c8ac.

The intent of the check is to "match slot address with device by
stripping the function" (as the comment above states it), for example
match network device PCI address 0000:05:00.0 (including a .0 for
function) to PCI slot address 0000:05:00, but changing that to a streq()
call prevented the match.

Change that to startswith(), which should both fix the bug and make the
intent of the check more clear and prevent unintentional bugs from being
introduced by future refactorings.
2018-03-16 02:42:38 +09:00
Zbigniew Jędrzejewski-Szmek 73fc96c8ac udev/net-id: check all snprintf return values
gcc-8 throws an error if it knows snprintf might truncate output and the
return value is ignored:
../src/udev/udev-builtin-net_id.c: In function 'dev_pci_slot':
../src/udev/udev-builtin-net_id.c:297:47: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size between 0 and 4095 [-Werror=format-truncation=]
                 snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
                                               ^~
../src/udev/udev-builtin-net_id.c:297:17: note: 'snprintf' output between 10 and 4360 bytes into a destination of size 4096
                 snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors

Let's check all return values. This actually makes the code better, because there's
no point in trying to open a file when the name has been truncated, etc.
2018-02-23 11:15:42 +01:00
Zbigniew Jędrzejewski-Szmek cc5bbdb274 udev/net-id: use _cleanup_
This fixes a minor memleak of 'address' if the file could not be read.
2018-02-23 11:15:16 +01:00
Zbigniew Jędrzejewski-Szmek f810b631cd Revert "Replace use of snprintf with xsprintf"
This reverts commit a7419dbc59.

_All_ changes in that commit were wrong.

Fixes #8211.
2018-02-23 00:13:52 +01:00
Yu Watanabe 977f65f01d sd-boot, udev: trivial condition simplifications
Reported and proposed by @dcb314.

Fixes #7656 and #7657.
2017-12-25 19:45:40 +01:00
Daniel Lockyer a7419dbc59 Replace use of snprintf with xsprintf 2017-11-24 10:36:04 +00:00
Zbigniew Jędrzejewski-Szmek 53e1b68390 Add SPDX license identifiers to source files under the LGPL
This follows what the kernel is doing, c.f.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
2017-11-19 19:08:15 +01:00
Lennart Poettering 86a48fb6f7 udev: turn off -Wformat-nonliteral for one safe case
c20e6de897 introduced a format string as
variable, but didn't turn off -Wformat-nonliteral warnings on it, thus
breaking the build. Let's fix that, by simply turning off the warning in
this case, as we know it's safe.
2017-05-18 22:26:12 -04:00
Dimitri John Ledkov c20e6de897 udev: net_id add support for platform bus (ACPI, mostly arm64) devices (#5933)
Fixes: #5894
2017-05-17 15:28:35 +02:00
Franck Bui 765a00b98d udev: net_id - support predictable ifnames on vio buses (#5675)
For IBM PowerVM Virtual I/O network devices, we can build predictable names
based on the slot number passed as part of the OF "reg" property.  Valid slot
numbers range between 2-32767, so we only need the bottom half of the unit
address passed.

For example:

  /proc/device-tree/vdevice/l-lan@30000002
  /proc/device-tree/vdevice/vnic@30000005

would initially map to something like:

  /sys/devices/vio/30000002/net/eth0
  /sys/devices/vio/30000005/net/eth1

and would then translate to env2 and env5

This patch ignores the bus number, as there should only ever be one bus, and
then remove leading zeros.
2017-03-31 16:32:09 +02:00
Zbigniew Jędrzejewski-Szmek 3877500c5b udev-builtin-net_id: fix warning about discarded "const" attribute (#5385) 2017-02-19 11:00:42 +03:00
Viktor Mihajlovski ecc11cf70c udev: fix id_net_name_path for virtio-ccw interfaces (#5357)
The CCW id_net_name_path detection didn't account for virtio
interfaces on the CCW bus. As a result the default interface
names for virtio-ccw interfaces would use the old eth<x>
format instead of enc<busid>.

Since virtio-pci interface naming follows the naming rules
of the parent bus, the names_ccw() logic was changed to apply
the CCW interface naming rules to virtio interfaces as well,
e.g. enc2000 for an interface with a CCW bus id 0.0.2000.
As virtio interfaces are apt to get the otherwise unusual
CCW bus id 0.0.0000, the last '0' is now preserved in this
case.

The virtio subsystem skipping loop has been moved from
names_pci() into a function skip_virtio() that can be reused
for all bus types with virtio network devices.

Since virtio-ccw interfaces use single CCW addresses the ccwgroup
requirement was relaxed and the C definitions were changed
accordingly.
2017-02-17 16:18:01 +01:00
Reverend Homer 8fb3f00997 tree-wide: replace all readdir cycles with FOREACH_DIRENT{,_ALL} (#4853) 2016-12-09 10:04:30 +01:00
Zbigniew Jędrzejewski-Szmek e68eedbbdc Revert some uses of xsprintf
This reverts some changes introduced in d054f0a4d4.
xsprintf should be used in cases where we calculated the right buffer
size by hand (using DECIMAL_STRING_MAX and such), and never in cases where
we are printing externally specified strings of arbitrary length.

Fixes #4534.
2016-11-02 22:36:29 -04:00
Jiří Pírko 4887b656c2 udev: net_id: add support for phys_port_name attribute (#4506)
Switch drivers uses phys_port_name attribute to pass front panel port
name to user. Use it to generate netdev names.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
2016-11-01 20:46:01 -06:00
Zbigniew Jędrzejewski-Szmek ccddd104fc tree-wide: use mdash instead of a two minuses 2016-04-21 23:00:13 -04:00
Daniel Mack b26fa1a2fb tree-wide: remove Emacs lines from all files
This should be handled fine now by .dir-locals.el, so need to carry that
stuff in every file.
2016-02-10 13:41:57 +01:00
Dimitri John Ledkov 0037a669ac udev: net_id - for ccw bus, shorten the identifier and stip leading zeros
The commmon case default qeth link is enccw0.0.0600 is rather long.

Thus strip leading zeros (which doesn't make the bus_id unstable),
similar to the PCI domain case.

Also 'ccw' is redundant on S/390, as there aren't really other buses
available which could have qeth driver interfaces. Not sure why this
code is even compiled on non-s390[x] platforms. But to distinguish from
e.g. MAC stable names shorten the suffix to just 'c'.

Thus enccw0.0.0600 becomes enc600.
2016-01-29 17:54:30 +01:00
Lennart Poettering 6c1e69f945 udev: filter out non-sensically high onboard indexes reported by the kernel
Let's not accept onboard interface indexes, that are so high that they are obviously non-sensical.

Fixes: #2407
2016-01-25 17:50:33 +01:00
Daniel Mack d054f0a4d4 tree-wide: use xsprintf() where applicable
Also add a coccinelle receipt to help with such transitions.
2016-01-12 15:36:32 +01:00
Zbigniew Jędrzejewski-Szmek 3f65d73149 udev: add emacs header line
Otherwise emacs wants to use 2-space indentation and other
attrocities.
2015-12-07 00:45:08 -05:00
Jan Engelhardt a8eaaee72a doc: correct orthography, word forms and missing/extraneous words 2015-11-06 13:45:21 +01:00
Lennart Poettering 3ffd4af220 util-lib: split out fd-related operations into fd-util.[ch]
There are more than enough to deserve their own .c file, hence move them
over.
2015-10-25 13:19:18 +01:00