Commit graph

1430 commits

Author SHA1 Message Date
Lennart Poettering bbd8598f8b
Merge pull request #11589 from yuwata/udevd-is-device-busy
udevd: refactoring is_device_busy()
2019-02-15 12:16:37 +01:00
Michael Olbrich 646876105f v4l_id: use device_caps if available
According to the specification[1] the 'capabilities' describe the physical
device as a whole and the 'device_caps' describe the current device node.
The existence of 'device_caps' is indicated by the V4L2_CAP_DEVICE_CAPS
capability flag.
Use the 'device_caps' if available to generate the correct
ID_V4L_CAPABILITIES for the current device node.

This is relevant for UVC devices with current kernels: Two /dev/videoX
devices exist for those. One for video and one for metadata. The
 V4L2_CAP_VIDEO_CAPTURE flag is present in the 'capabilities' for both
device nodes but only in the 'device_caps' of the video device node.

Without this, the ID_V4L_CAPABILITIES of the metadata device node
incorrectly contains 'capture'.

[1] https://www.linuxtv.org/downloads/v4l-dvb-apis-new/uapi/v4l/vidioc-querycap.html
2019-02-15 12:14:05 +01:00
Lennart Poettering 683a1e7fd9
Merge pull request #11594 from yuwata/udev-rule-cleanups
udev-rule, ethtool: several coding style cleanups
2019-02-15 11:37:11 +01:00
Lennart Poettering e5d21c24a0
Merge pull request #11382 from keszybz/udev-predictable-macs
Allow MACAddressPolicy=persistent for all virtual devices
2019-02-15 11:31:25 +01:00
Zbigniew Jędrzejewski-Szmek dc9cced4ac
Merge pull request #11704 from yuwata/fix-oss-fuzz-12980
udev-rule: make rule_add_key() return negative errno when too much tokens
2019-02-13 23:27:12 +01:00
Yu Watanabe 31cbd20253 udev: check whether systemd is running, and do not use cg_kill() if not
Fixes #11645.
2019-02-13 17:07:56 +01:00
Yu Watanabe 6e2efb6c73 udev-rule: make rule_add_key() return negative errno when too much tokens
As OPTIONS= rule introduce multiple tokens.

Fixes oss-fuzz#12980.
2019-02-13 04:14:21 +09:00
Yu Watanabe 76b9bdd96f udev-rule: check function retun value is negative or not, instead of non-zero
One exception is udev_event_spawn(), which returns negative or positive
value on failure.
2019-02-12 11:03:40 +09:00
Yu Watanabe 605aa52f83 udev-rule: make match_key() and match_attr() return boolean value 2019-02-12 11:03:40 +09:00
Yu Watanabe bb175a0338 udev-rule: drop unnecessary parentheses 2019-02-12 11:03:40 +09:00
Yu Watanabe ee60be466b ethtool: make find_feature_index() return negative errno 2019-02-12 11:03:40 +09:00
Yu Watanabe 704dbfb279 udev-rule: make get_key() return negative errno 2019-02-12 11:03:40 +09:00
Yu Watanabe 1f362ff185 udev-rule: drop unnecessary assignments 2019-02-12 11:03:39 +09:00
Yu Watanabe ef660d072f udev-rule: propagate error cause in add_token() 2019-02-12 11:03:39 +09:00
Mantas Mikulėnas 6d6308f677 udevadm info: "-a" should enumerate sysfs attributes, not envs (#11642)
This fixes a bug introduced by 13aca84769.
2019-02-05 06:30:49 +02:00
Yu Watanabe 8671411668 udevd: save the result of devnum or ifindex blocker 2019-01-29 14:07:21 +01:00
Yu Watanabe baa461fc05 udevd: always block follwoing events with same devpath
Originally commented as "devices names might have changed/swapped in the meantime",
but may not. For safety, let's block the following events with same
devpath.

This may fix #6514.
2019-01-29 14:04:43 +01:00
Yu Watanabe 0bd0407efc udevd: trivial refactoring of is_device_busy() 2019-01-29 13:53:19 +01:00
Yu Watanabe 2277e84560 udevadm info: make --export-prefix imply --export
Setting --export without --export-prefix is meaningless.
2019-01-22 15:07:27 +09:00
Zbigniew Jędrzejewski-Szmek 015b097cce udev: add debug logging about the choice of MAC 2019-01-21 17:33:53 +01:00
Zbigniew Jędrzejewski-Szmek 6d36464065 udev,networkd: use the interface name as fallback basis for MAC and IPv4LL seed
Fixes #3374. The problem is that we set MACPolicy=persistent (i.e. we would
like to generate persistent MAC addresses for interfaces which don't have a
fixed MAC address), but various virtual interfaces including bridges, tun/tap,
bonds, etc., do not not have the necessary ID_NET_NAME_* attributes and udev
would not assing the address and warn:
  Could not generate persistent MAC address for $name: No such file or directory

Basic requirements which I think a solution for this needs to satisfy:

1. No changes to MAC address generation for those cases which are currently
  handled successfully. This means that net_get_unique_predictable_data() must
  keep returning the same answer, which in turn means net_get_name() must keep
  returning the same answer. We can only add more things we look at with lower
  priority so that we start to cover cases which were not covered before.

2. Like 1, but for IPvLL seed and DHCP IAD. This is less important, but "nice
  to have".

3. Keep MACPolicy=persistent. If people don't want it, they can always apply
  local configuration, but in general stable MACs are a good thing. I have never
  seen anyone complain about that.

== Various approaches that have been proposed

=== https://github.com/systemd/systemd/issues/3374#issuecomment-223753264 (tomty89)
if !ID_BUS and INTERFACE, use INTERFACE

I think this almost does the good thing, but I don't see the reason to reject ID_BUS
(i.e. physical hardware). Stable MACs are very useful for physical hardware that has
no physical MAC.

=== https://github.com/systemd/systemd/issues/3374#issuecomment-224733069 (teg)
if (should_rename(device, true))

This means looking at name_assign_type. In particular for
NET_NAME_USER should_rename(..., true) returns true. It only returns false
for NET_NAME_PREDICTABLE. So this would cover stuff like br0, bond0, etc,
but would not cover lo and other devices with predictable names. That doesn't
make much sense.

But did teg mean should_rename() or !should_rename()?

=== https://github.com/systemd/systemd/issues/3374#issuecomment-234628502 (tomty89):
+ if (!should_rename(device, true))
+        return udev_device_get_sysname(device)

This covers only devices with NET_NAME_PREDICTABLE. Since the problem applies as
much to bridges and such, this isn't neough.

=== https://github.com/systemd/systemd/issues/3374#issuecomment-281745967  (grafi-tt)
+        /* if the machine doesn't provide data about the device, use the ifname specified by userspace
+        * (this is the case when the device is virtual, e.g., bridge or bond) */
+        s = udev_device_get_sysattr_value(device, "name_assign_type");
+        if (s && safe_atou(s, &type) >= 0 && type == NET_NAME_USER)
+                return udev_device_get_sysname(device);

This does not cover bond0, vnet0, tun/tap and similar.
grafi-tt also proposes patching the kernel, but *not* setting name_assign_type
seems intentional in those cases, because the device name is a result of
enumeration, not set by the userspace.

=== https://github.com/systemd/systemd/issues/3374#issuecomment-288882355 (tomty89)
(also PR #11372)
- MACAddressPolicy=persistent

This break requirement 3. above. It would solve the immediate problem, but I
think the disruption is too big.

=== This patch

This patch means that we will set a "stable" MAC for pretty much any virtual
device by default, where "stable" means keyed off the machine-id and interface
name.

It seems like a big change, but we already did this for most physical devices.
Doing it also for virtual devices doesn't seem like a big issue. It will make
the setup and monitoring of virtualized networks slightly nicer. I don't think
anyone is depending on having the MAC address changed when those devices are
destoryed and recreated. If they do, they'd have to change MACAddressPolicy=.

== Implementation
net_get_name() is called from dhcp_ident_set_iaid() so I didn't change
net_get_name() like in grafi-tt's patch, but net_get_unique_predictable_data().

net_get_unique_predictable_data() is called from get_mac() in link-config.c
and sd_ipv4ll_set_address_seed(), so both of those code paths are affected
and will now get data in some cases where they errored out previously.

The return code is changed to -ENODATA since that gives a nicer error string.
2019-01-21 17:33:09 +01:00
Zbigniew Jędrzejewski-Szmek b0a28c2956
Merge pull request #11349 from yuwata/udevadm-control-ping
Add 'udevadm control --ping'
2019-01-18 17:41:00 +01:00
Yu Watanabe d30f43eec5 udevd: rename control command SYNC -> PING in log message 2019-01-18 16:10:01 +01:00
Yu Watanabe 2001622c58 udevadm: add --wait-daemon option to 'trigger' command 2019-01-18 16:10:01 +01:00
Yu Watanabe a82340cc03 udevadm: add --ping option to 'control' command
This exposes `udev_ctrl_send_ping()`.
2019-01-18 16:10:01 +01:00
Lennart Poettering 8274a4132c
Merge pull request #11449 from keszybz/udev-link-naming-again
Make udev link re-renaming conditional
2019-01-17 20:06:55 +01:00
Zbigniew Jędrzejewski-Szmek 73d2bb0881 link-config: default to "keep" policy if naming-scheme<=239 is used
This makes the new (>=240) behaviour conditional, restoring backwards compat, as least
as long as an old naming scheme is used.
2019-01-17 13:56:02 +01: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 3907446f02 link-config: add "keep" policy and use it by default
If "keep" policy is specified, and the interface has a name that is
NET_NAME_USER or NET_NAME_RENAMED, we stop processing rules. "keep" should
probably be specified either first or last depending on the preference.

This partially reimplements 55b6530baa, in the
sense that if the "keep" policy is not specified, and if the interface has
a NamingPolicy, it will be renamed, even if it had a name previously.
So this breaks backwards compatibility in this case, but that's more in line
with what users expect.

Closes #9006.
2019-01-17 13:56:02 +01:00
Jan Janssen a0e1ad10ea ethtool: Make sure advertise is actually set when autonegotiation is used 2019-01-17 09:15:09 +01:00
Zbigniew Jędrzejewski-Szmek 0b189e8fa7 link-config: unentangle the renaming logic and add logging
What policy we dicide to use it rather important, but this bit of information
wasn't logged. Let's always do that.

The code was also written in a confusing way, which probably contributed to the
unintended effects of 55b6530baa and other commits.
We would loop over all policies, and note if "kernel" was specified, and then
possibly unset the result at the end. Let's immediately log the result and cut
to the end if we can figure out the answer.

No functional change intended, except for the new log lines.
Using goto is not very elegant, but we can't use break because of the switch,
and there are multiple conditions to break the loop, so using goto is cleanest.
2019-01-16 22:20:04 +01:00
Yu Watanabe 7e8bd58eb1 udev: 'val' may be NULL, use strempty() 2019-01-16 13:34:04 +01:00
Zbigniew Jędrzejewski-Szmek ed30802324 Revert "Always rename an interface to its name specified in config if no NamePolicy= is specified"
This reverts commit 55b6530baa.

This commit description says "Always rename an interface to its name specified
in config if no NamePolicy= is specified", but it does much more:
1. It completely changes the meaning of NamePolicy=kernel. Before, it meant that an interface
   with type==NAMEPOLICY_KERNEL would not be renamed. After, the kernel name only works as
   a fallback, if no policy matches.
2. The "if no NamePolicy= is specified" part is not true at all, the interface will be renamed
   according to the specified NamePolicy=.

After 55b6530baa, the should_rename() function is named very misleadingly: it is only used
to mean "respect kernel predictable name if no naming policy matches".

Let's revert, and start with a clean slate. This fixes #11436.
2019-01-16 13:28:41 +01:00
Zbigniew Jędrzejewski-Szmek a6ca3c1921 udev: do logging before setting variables to NULL
gcc-9 diagnoses this as an error.
Reported by Jeff Law.
2019-01-15 13:58:45 +01:00
Topi Miettinen a1e92eee3e Remove 'inline' attributes from static functions in .c files (#11426)
Let the compiler perform inlining (see #11397).
2019-01-15 08:12:28 +01:00
Yu Watanabe 0eba88dc9f udevadm: fix segfault
Fixes #11416.
2019-01-14 06:34:19 +09:00
Yu Watanabe 8d6c4b310d udev: use ENODATA when 'No entry found from hwdb'
Before:
IMPORT builtin 'hwdb' fails: No such file or directory

After:
IMPORT builtin 'hwdb' fails: No data available

Previous log is confusing and may be understood as hwdb file not exist.
2019-01-13 18:04:10 +09:00
Yu Watanabe a119328608 udev: use SYNTHETIC_ERRNO() macro in log_device_*_errno() 2019-01-13 17:50:47 +09:00
Yu Watanabe 3797776e11 udev: use usec_t for timeout in udev_ctrl_send_*() 2019-01-13 07:37:49 +09:00
Yu Watanabe b1d1cb5b47 udevadm: also set LOG_DEBUG to LOG_REAL_SYSTEMD when --debug is passed 2019-01-13 07:37:49 +09:00
Yu Watanabe c809f33719 udev: also update log level for LOG_REALM_SYSTEMD
Now, not a few udevd debug logs come from sd-device or sd-hwdb.
Only setting LOG_REALM_UDEV may not sufficient to debug.
We have already similar code in main() and udevadm.
2019-01-13 07:37:49 +09:00
Yu Watanabe 47c8fcbeb7 udevadm: use SYNTHETIC_ERRNO() macro 2019-01-13 07:37:49 +09:00
Yu Watanabe cf7f501353 udevadm: improve error message when no option specified for 'control' command
Also drop redundant block, use SYNTHETIC_ERRNO(), and add log_oom().
2019-01-13 07:37:49 +09:00
Topi Miettinen 7ae3561a5a Delete duplicate lines
Found by inspecting results of running this small program:

int main(int argc, const char **argv) {
	for (int i = 1; i < argc; i++) {
		FILE *f;
		char line[1024], prev[1024], *r;
		int lineno;

		prev[0] = '\0';
		lineno = 1;
		f = fopen(argv[i], "r");
		if (!f)
			exit(1);
		do {
			r = fgets(line, sizeof(line), f);
			if (!r)
				break;
			if (strcmp(line, prev) == 0)
				printf("%s:%d: error: dup %s", argv[i], lineno, line);
			lineno++;
			strcpy(prev, line);
		} while (!feof(f));
		fclose(f);
	}
}
2019-01-12 16:02:26 +01:00
Yu Watanabe e0b7a5d151 udevd: refuse devices which do not have ACTION property 2019-01-12 09:32:20 +09:00
Yu Watanabe 33ad742a84 udevd: drop unnecessary brackets 2019-01-12 09:32:20 +09:00
Yu Watanabe c0ff3d6cbc udevd: make worker also log ACTION property 2019-01-12 09:32:20 +09:00
Yu Watanabe 25d4f5b071 udevd: reject devices which do not have SEQNUM 2019-01-12 09:32:20 +09:00
Yu Watanabe 956833b417 udevd: provide worker_hash_ops and drop manager_workers_free() 2019-01-12 09:32:20 +09:00
Yu Watanabe d40534643b udevd: use structured initializer at one more place 2019-01-12 09:32:20 +09:00