Commit Graph

123 Commits

Author SHA1 Message Date
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
Lennart Poettering 07630cea1f util-lib: split our string related calls from util.[ch] into its own file string-util.[ch]
There are more than enough calls doing string manipulations to deserve
its own files, hence do something about it.

This patch also sorts the #include blocks of all files that needed to be
updated, according to the sorting suggestions from CODING_STYLE. Since
pretty much every file needs our string manipulation functions this
effectively means that most files have sorted #include blocks now.

Also touches a few unrelated include files.
2015-10-24 23:05:02 +02:00
Tom Gundersen 54683f0f9b udev: net_id - support predictable ifnames on virtio buses
Virtio buses are undeterministically enumerated, so we cannot use them as a basis
for deterministic naming (see bf81e792f3). However, we are guaranteed that there
is only ever one virtio bus for every parent device, so we can simply skip over
the virtio buses when naming the devices.
2015-09-02 14:24:17 +02:00
Tom Gundersen 3b64e4d4f4 udev: add some asserts
Mostly for documentation purposes.
2015-06-02 18:12:47 +02:00
Jason S. McMullan 0454229c10 udev/net_id: Only read the first 64 bytes of PCI config space
The original code used fread(), which on some libc implementions
(ie glibc 2.17) would pre-read a full 4K (PAGE_SIZE) of the
PCI config space, when only 64 bytes were requested.

I have recently come across PCIe hardware which responds with
Completion Timeouts when accesses above 256 bytes are attempted.

This can cause server systems with GHES/AEPI support to cause
and immediate kernel panic due to the failed PCI transaction.

This change replaces the buffered fread() with an explict
unbuffered read() of 64 bytes, which corrects this issue by
only reading the guaranteed first 64 bytes of PCIe config space.
2015-05-22 20:50:01 +02:00
Tom Gundersen 309b578d31 udev: net_id - improve comments
The dev_port concept is a bit confusing, expand on the comment a bit.
2015-04-01 23:34:19 +02:00
Tom Gundersen c0a43734ca udev: net_id - support multi-port enpo* device names
I'd argue that having firmware labels for such devices makes
no sense, but they exist, so make sure we handle them as best
as we can.
2015-04-01 22:56:27 +02:00
Tom Gundersen 16f948cb20 udev: net_id - fix copy-paste error
In case pci_slot overflows we were truncating pci_path instead.
2015-04-01 22:56:26 +02:00
Lennart Poettering 63c372cb9d util: rework strappenda(), and rename it strjoina()
After all it is now much more like strjoin() than strappend(). At the
same time, add support for NULL sentinels, even if they are normally not
necessary.
2015-02-03 02:05:59 +01:00
Zbigniew Jędrzejewski-Szmek 1fa2f38f0f Assorted format fixes
Types used for pids and uids in various interfaces are unpredictable.
Too bad.
2015-01-22 01:14:52 -05:00
Lennart Poettering 5ac0162c3a udevadm,..: make --help output of udev tools more like the output of the various other tools 2015-01-05 13:19:55 +01:00
Torstein Husebø f7340ab269 treewide: correct spacing near eol in code comments 2014-12-11 15:10:03 +01:00
Lennart Poettering 1cb5d1f319 udev: modernize net_id builtin a bit 2014-08-12 01:54:39 +02:00
Thadeu Lima de Souza Cascardo 3058e017fc Use dev_port for the ID of a network device.
For network devices on the same PCI function, dev_id should not be used,
since its purpose is for IPv6 support on interfaces with the same MAC
address.

The new dev_port sysfs attribute should be used instead of dev_id.
2014-07-01 15:19:20 +02:00
Tom Gundersen 19aa72f74e udev: net_id - use constants rather than magic numbers 2014-04-06 18:00:40 +02:00
Tom Gundersen bf81e792f3 udev: persistent naming - we cannot use virtio numbers as they are not stable
This reverts commit 8741f2defaf26aafe5ee0fd29954cfdf84ee519c: 'Add virtio-blk support to path_id' and
commit e3d563346c4237af23335cc6904e0662efdf62ad: 'udev: net_id - handle virtio buses'.

Distros may want to take note of this, as it changes behavior.
2014-03-27 21:47:14 +01:00
Kay Sievers d4b687c96a udev: update net_id comments 2014-03-27 15:30:34 +01:00
Hendrik Brueckner e0d4a0ac06 udev/net_id: Introduce predictable network names for Linux on System z
Use the bus-ID to create predicatable devices names for network interfaces
on Linux on System z instances.  The bus-ID identifies a device in the s390
channel subsystem.

Network interfaces of device type Ethernet are named as:
    enccw0.0.1234    (13 characters)
up to
    enccwff.7.ffff   (14 characters)

CTC network devices of device type SLIP, use a different prefix as follows:
    slccw0.0.1234    (13 characters)

See also Red Hat Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=870859
[tomegun: typical problem of netdevs switching names between reboots.]
2014-01-11 15:03:25 +00:00
Tom Gundersen e3d563346c udev: net_id - handle virtio buses
This was already supported in path_id, so should be uncontroversial.
2014-01-04 15:21:58 +01:00
Zbigniew Jędrzejewski-Szmek b5dd814873 Fix a few signed/unsigned format string issues
Since numbers involved are all small, behaviour was correct already.

https://bugzilla.redhat.com/show_bug.cgi?id=1043304
2013-12-15 17:49:28 -05:00
Thomas Hindoe Paaboel Andersen f168c27313 trivial coding style clean ups
- Add space between if/for and the opening parentheses
- Place the opening brace on same line as the function (not for  udev)

From the CODING_STYLE
Try to use this:
    void foo() {
    }
instead of this:
    void foo()
    {
    }
2013-12-03 22:27:45 +01:00
Kay Sievers a4bbef0992 hwdb: add --lookup-prefix= option 2013-07-08 11:44:17 +02:00
Kay Sievers 67410e9f73 hwdb: add --device=<device-id> and --filter=<key name glob> 2013-07-01 22:34:43 +02:00
Sean McGovern 214daa72cb udev: handle network controllers in nonstandard domains
Onboard network controllers are not always on PCI domain 0.

[Kay: use int instead of long, add [P] to slot naming, remove sysname var]
2013-06-18 13:18:27 +02:00
Zbigniew Jędrzejewski-Szmek b92bea5d2a Use initalization instead of explicit zeroing
Before, we would initialize many fields twice: first
by filling the structure with zeros, and then a second
time with the real values. We can let the compiler do
the job for us, avoiding one copy.

A downside of this patch is that text gets slightly
bigger. This is because all zero() calls are effectively
inlined:

$ size build/.libs/systemd
         text    data     bss     dec     hex filename
before 897737  107300    2560 1007597   f5fed build/.libs/systemd
after  897873  107300    2560 1007733   f6075 build/.libs/systemd

… actually less than 1‰.

A few asserts that the parameter is not null had to be removed. I
don't think this changes much, because first, it is quite unlikely
for the assert to fail, and second, an immediate SEGV is almost as
good as an assert.
2013-04-05 19:50:57 -04:00
Rob Clark bb26309dd0 udev: fix segfault with android rndis
The android gadget driver for network tethering over rndis somehow has a
parent device with a null subsystem.  Probably this is bug in android driver,
but it is easy enough to make systemd/udev behave gracefully and not
segfault.  And this will help for making linux distros with systemd
(like fedora) work on android devices.
2013-03-03 19:02:36 +01:00
Harald Hoyer a5c32cff1f honor SELinux labels, when creating and writing config files
Also split out some fileio functions to fileio.c and provide a SELinux
aware pendant in fileio-label.c

see https://bugzilla.redhat.com/show_bug.cgi?id=881577
2013-02-14 16:19:38 +01:00
Thomas Hindoe Paaboel Andersen 090be86534 use streq instead of strcmp 2013-02-13 18:14:20 +01:00
Thomas Hindoe Paaboel Andersen 641906e936 use strneq instead of strncmp 2013-02-13 00:56:13 +01:00
Kay Sievers 25da63b9da udev: net_id - add link to the wiki page 2013-01-19 16:01:26 +01:00
Kay Sievers f4ddacbd4d udev: net_id - suppress bcma core == 0 2013-01-17 03:30:07 +01:00
Kay Sievers 984c4348ff udev: net_id - handle "bcma" buses 2013-01-17 02:10:58 +01:00
Kay Sievers d5a89d7dc1 udev: move string copy functions to shared/ 2013-01-09 19:06:46 +01:00
Lukas Nykryn 3c123e0899 udev: don't call fclose on NULL in is_pci_multifunction 2013-01-09 17:14:40 +01:00
Kay Sievers 72bc96f078 udev: net_id - skip stacked network devices 2013-01-08 14:54:12 +01:00
Kay Sievers 1328f66ad1 udev: net_id - append "dev_id" value if needed 2013-01-04 19:08:08 +01:00
Kay Sievers decd634e80 udev: net_id: update comments 2012-12-09 14:49:28 +01:00
Kay Sievers 971e7fb625 udev: net_id - fix OUI handling 2012-12-06 21:37:10 +01:00
Kay Sievers 0d6ce9236f udev: net_id - fix typos 2012-12-06 21:27:42 +01:00
Kay Sievers ad37f393fa udev: net_id - update examples 2012-12-06 21:25:39 +01:00
Kay Sievers f610d6de38 udev: net_id - update examples 2012-12-06 21:09:30 +01:00
Kay Sievers 0260944060 udev: net_id - provide path names for USB devices 2012-12-06 20:44:28 +01:00
Tom Gundersen 5fe25affc0 hwdb: add IAB to the OUI database
The individual address block is a poor man's organizationally unique
identifier.

Perhaps we should change the udev key from ID_OUI_FROM_DATABASE to
something like ID_IEEE_VENDOR_FROM_DATABASE?

Suggested-by: Diego Elio Pettenò <flameeyes@flameeyes.eu>
2012-12-04 02:11:37 +01:00
Kay Sievers 137661d875 udev: net_id - clarify comments 2012-12-03 15:47:18 +01:00
Kay Sievers 472780d8b1 udev: hwdb - fix OUI lookup 2012-12-02 02:00:57 +01:00
Kay Sievers de892aea1c udev: net_id - suppress function number for single-function devices 2012-11-30 19:27:42 +01:00
Kay Sievers 5b8180d3f6 udev: net_id - merge properties into the correct device 2012-11-26 15:03:06 +01:00
Kay Sievers 0035597a30 udev: net_id - export PCI hotplug slot names 2012-11-26 14:07:16 +01:00
Kay Sievers 01d183ddae udev: net_id - read ACPI _SUN -- slot user number 2012-11-23 15:02:46 +01:00
Kay Sievers d23965a64e udev: net - add device naming properties 2012-11-20 18:10:45 +01:00
Kay Sievers a660c63c55 udev: net_id - add builtin to retrieve data for network devices 2012-11-09 13:05:19 +01:00