Commit Graph

165 Commits

Author SHA1 Message Date
Yu Watanabe 78404d22cc network: support matching based on wifi interfece type 2019-10-25 16:43:18 +09:00
Yu Watanabe 277ba8d1ab network: add support matching based on BSSID= 2019-10-15 01:59:56 +09:00
Yu Watanabe 8d968fdd99 network: support matching based on wifi SSID 2019-10-15 01:59:06 +09:00
Susant Sahani 224ded670f link: Add support to configure NIC ring buffer size 2019-09-24 16:33:35 +02:00
Yu Watanabe 8cec0a5c32 tree-wide: drop duplicated blank lines
```
$ for i in */*.[ch] */*/*.[ch]; do sed -e '/^$/ {N; s/\n$//g}' -i $i; done
$ git checkout HEAD -- basic/linux shared/linux
```
2019-07-15 18:41:27 +02:00
Yu Watanabe 56637e5c20 udev: make Match.OriginalName=* matches all interfaces
Fixes #13035.
2019-07-13 18:29:37 +09:00
Yu Watanabe 44005bfb4e network,udev: add Property= setting in [Match] section
Closes #5665.
2019-07-01 01:24:42 +09:00
Yu Watanabe b38de0e9cc network,udev: make net_match_config() take sd_device 2019-07-01 01:24:42 +09:00
Yu Watanabe 5c2316c605 ethtool-util: move from src/udev/net/ to src/shared/ 2019-06-19 09:03:50 +09:00
Zbigniew Jędrzejewski-Szmek 96848152fa udev: introduce NAMING_STABLE_VIRTUAL_MACS (retroactively)
This is for 6d36464065. It turns out that this is causing more problems than
expected. Let's retroactively introduce naming scheme v241 to conditionalize
this change.

Follow-up for #12792 and 6d36464065. See also
https://bugzilla.suse.com/show_bug.cgi?id=1136600.

$ SYSTEMD_LOG_LEVEL=debug NET_NAMING_SCHEME=v240 build/udevadm test-builtin net_setup_link /sys/class/net/br11
$ SYSTEMD_LOG_LEVEL=debug NET_NAMING_SCHEME=v241 build/udevadm test-builtin net_setup_link /sys/class/net/br11
...
@@ -20,11 +20,13 @@
 link_config: could not set ethtool features for br11
 Could not set offload features of br11: Operation not permitted
 br11: Device has name_assign_type=3
-Using interface naming scheme 'v240'.
+Using interface naming scheme 'v241'.
 br11: Policy *keep*: keeping existing userspace name
 br11: Device has addr_assign_type=1
-br11: No stable identifying information found
-br11: Could not generate persistent MAC: No data available
+br11: Using "br11" as stable identifying information
+br11: Using generated persistent MAC address
+Could not set Alias=, MACAddress= or MTU= on br11: Operation not permitted
+br11: Could not apply link config, ignoring: Operation not permitted
 Unload module index
 Unloaded link configuration context.
 ID_NET_DRIVER=bridge
2019-06-17 13:43:18 +02:00
Yu Watanabe a54510c775 udev: suppress warning when interface matches 99-default.link
This suppress the following warning:
```
systemd-udevd[437]: Config file /usr/lib/systemd/network/99-default.link
applies to device based on potentially unpredictable interface name 'wlan0'
```

Follow-up for 84ea567eb4.
2019-05-28 10:04:12 +02:00
Yu Watanabe 84ea567eb4 udev,network: warn when .link or .network file has no [Match] section
Closes #12098.
2019-04-25 08:41:10 +02:00
Yu Watanabe 01234e1fe7 tree-wide: drop several missing_*.h and import relevant headers from kernel-5.0 2019-04-11 19:00:37 +02:00
Yu Watanabe 4b4a6c9b41 udev: shorten code a bit 2019-04-01 10:30:31 +09:00
Zbigniew Jędrzejewski-Szmek 54ed9f88dc udev/link-config: rename MACPolicy to MACAddressPolicy
Things are clearer if the same name is used everywhere, and we don't gain
much by saving a few bytes.
2019-03-22 17:16:17 +01:00
Yu Watanabe c4f58deab5 network,udev: split static condition tests from net_match_config() 2019-03-21 23:37:39 +09:00
Lennart Poettering 0a9707187b util: split out memcmp()/memset() related calls into memory-util.[ch]
Just some source rearranging.
2019-03-13 12:16:43 +01:00
Yu Watanabe a378400b3f fuzz: add fuzzer for parsing .link files
This also renames load_link() to link_load_one()
2019-02-25 12:35:51 +09:00
Yu Watanabe 391f6bc1db udev: fix memleak in conditions for .link file 2019-02-25 11:57:14 +09:00
Yu Watanabe 176d9c0e11 udev/net: drop .link files earlier when their conditions do not match system environment 2019-02-25 11:54:50 +09:00
Yu Watanabe 6cdab9f17f udev/net: use structured initializer at one more place 2019-02-25 11:53:57 +09:00
Yu Watanabe 79a60834e2 udev/net: use size_t for index at one more place 2019-02-25 11:51:32 +09:00
Yu Watanabe e8a42907ed udev/net: ignore errors in loading .link files but warn about that 2019-02-25 11:50:57 +09:00
Yu Watanabe f2d251cdb8 udev/net: shorten load_link() a little bit 2019-02-25 11:48:39 +09:00
Yu Watanabe c6b3370ab2 udev: drop unused Ethernet section 2019-02-25 11:45:34 +09:00
Lennart Poettering bde06abd4f
Merge pull request #10408 from keszybz/analyze-cat-presets
systemd-analyze cat-presets
2019-02-18 16:02:45 +01:00
Zbigniew Jędrzejewski-Szmek dc0d407851 udev,network: use standard paths for .network and .link files
This centralizes the configuration to one header file.
/usr/local/lib is now included in the search list, and documentation is
updated accordingly.
2019-02-18 10:29:33 +01:00
Yu Watanabe 4f4daf418f udev,network: drop unused parent_driver argument from net_match_config()
The argument has never been used.
2019-02-17 00:47:49 +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 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 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
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
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 1b2a7d92af Fix a few comments 2019-01-08 23:11:26 +01:00
Yu Watanabe 36dd5ffd5d util: drop missing.h from util.h 2018-12-04 10:00:34 +01:00
Yu Watanabe 49c603bd5e udev: drop duplicate whitespaces 2018-11-26 11:53:21 +09:00
Zbigniew Jędrzejewski-Szmek 5dd101186b udev: use an "inline" array instead of allocating for advertise mode
The code is a bit shorter and we don't allocate the uint32_t[127] array.
2018-11-18 16:14:19 +01:00
Yu Watanabe 2d18ac4491 ethtool: drop NetDevAdvertise
Fixes #10807.
2018-11-18 14:33:50 +09:00
Mathieu Trudel-Lapierre 55b6530baa Always rename an interface to its name specified in config if no NamePolicy= is specified
This is for issue #9006
2018-11-12 18:45:57 +01:00
Yu Watanabe 7606377e2c network,udev: drop unnecessary check whether ifindex is positive
As sd_device_get_ifindex() now returns positive ifindex when it
succeeds.
2018-10-27 07:03:39 +09:00
Yu Watanabe b220632c61 link-config: use log_device_*() 2018-10-23 22:44:07 +09:00
Susant Sahani 6cf0a20491 udev/net: add support for the equivalent of "ethtool advertise" to .link files
This work adds support for the equivalent of "ethtool advertise" to .link files?
http://lists.freedesktop.org/archives/systemd-devel/2015-April/030112.html
2018-09-26 22:21:42 +02:00
Yu Watanabe e5eadf53fe udev/net: replace udev_device by sd_device 2018-09-10 18:27:36 +09:00
Yu Watanabe 51517f9e09 network: replace udev_device by sd_device 2018-08-23 04:57:39 +09:00
Thomas Haller cc2ff878fa link: fix type for link-config's "features" array of tristates
The "features" fields is parsed as a tristate value. The values
are thus not of type NetDevFeature enum but int. The NetDevFeature
enum is instead the index for the features array.

Adjust the type. In practice, this had no impact because NetDevFeature
enum commonly has size of int.

Also, don't use memset() 0xFF to initilize the int with -1. While
it works correctly in practice, it feels ugly.
2018-08-07 15:40:39 +02: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 810adae9e9 tree-wide: use proper unicode © instead of (C) where we can
Let's use a proper unicode copyright symbol where we can, it's prettier.

This important patch is very important.
2018-06-14 10:20:20 +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 e90d037411 network,udev: make MACAddress= in [Match] section take multiple MAC addresses 2018-05-09 11:59:18 +09:00