2 # SPDX-License-Identifier: LGPL-2.1-or-later
4 # disable shellcheck warning about '"aaa"' type quotation
5 # shellcheck disable=SC2016
10 # shellcheck source=test/units/assert.sh
11 .
"$(dirname "$0")"/assert.sh
13 mkdir
-p /run
/udev
/rules.d
/
15 # test for ID_RENAMING= udev property and device unit state
17 cat >/run
/udev
/rules.d
/50-testsuite.rules
<<EOF
18 ACTION=="remove", GOTO="hoge_end"
19 SUBSYSTEM!="net", GOTO="hoge_end"
20 KERNEL!="hoge", GOTO="hoge_end"
22 OPTIONS="log_level=debug"
25 ACTION=="online", ENV{ID_RENAMING}="1"
30 udevadm control
--log-priority=debug
--reload --timeout=30
32 ip link add hoge
type dummy
33 udevadm
wait --timeout=30 --settle /sys
/devices
/virtual
/net
/hoge
34 assert_not_in
"ID_RENAMING=" "$(udevadm info /sys/devices/virtual/net/hoge)"
35 timeout
30 bash
-c 'while [[ "$(systemctl show --property=ActiveState --value /sys/devices/virtual/net/hoge)" != "active" ]]; do sleep .5; done'
36 timeout
30 bash
-c 'while [[ "$(systemctl show --property=ActiveState --value /sys/subsystem/net/devices/hoge)" != "active" ]]; do sleep .5; done'
38 udevadm trigger
--action=online
--settle /sys
/devices
/virtual
/net
/hoge
39 assert_in
"ID_RENAMING=" "$(udevadm info /sys/devices/virtual/net/hoge)"
40 timeout
30 bash
-c 'while [[ "$(systemctl show --property=ActiveState --value /sys/devices/virtual/net/hoge)" != "inactive" ]]; do sleep .5; done'
41 timeout
30 bash
-c 'while [[ "$(systemctl show --property=ActiveState --value /sys/subsystem/net/devices/hoge)" != "inactive" ]]; do sleep .5; done'
43 udevadm trigger
--action=move
--settle /sys
/devices
/virtual
/net
/hoge
44 assert_not_in
"ID_RENAMING=" "$(udevadm info /sys/devices/virtual/net/hoge)"
45 timeout
30 bash
-c 'while [[ "$(systemctl show --property=ActiveState --value /sys/devices/virtual/net/hoge)" != "active" ]]; do sleep .5; done'
46 timeout
30 bash
-c 'while [[ "$(systemctl show --property=ActiveState --value /sys/subsystem/net/devices/hoge)" != "active" ]]; do sleep .5; done'
48 # test for renaming interface with NAME= (issue #25106)
50 cat >/run
/udev
/rules.d
/50-testsuite.rules
<<EOF
51 ACTION!="add", GOTO="hoge_end"
52 SUBSYSTEM!="net", GOTO="hoge_end"
54 OPTIONS="log_level=debug"
56 KERNEL=="hoge", NAME="foobar"
57 KERNEL=="foobar", NAME="hoge"
62 udevadm control
--log-priority=debug
--reload --timeout=30
64 udevadm trigger
--action=add
--settle /sys
/devices
/virtual
/net
/hoge
65 udevadm
wait --timeout=30 --settle /sys
/devices
/virtual
/net
/foobar
66 assert_not_in
"ID_RENAMING=" "$(udevadm info /sys/devices/virtual/net/foobar)"
67 timeout
30 bash
-c 'while [[ "$(systemctl show --property=ActiveState --value /sys/devices/virtual/net/hoge)" != "inactive" ]]; do sleep .5; done'
68 timeout
30 bash
-c 'while [[ "$(systemctl show --property=ActiveState --value /sys/subsystem/net/devices/hoge)" != "inactive" ]]; do sleep .5; done'
69 timeout
30 bash
-c 'while [[ "$(systemctl show --property=ActiveState --value /sys/devices/virtual/net/foobar)" != "active" ]]; do sleep .5; done'
70 timeout
30 bash
-c 'while [[ "$(systemctl show --property=ActiveState --value /sys/subsystem/net/devices/foobar)" != "active" ]]; do sleep .5; done'
72 udevadm trigger
--action=add
--settle /sys
/devices
/virtual
/net
/foobar
73 udevadm
wait --timeout=30 --settle /sys
/devices
/virtual
/net
/hoge
74 assert_not_in
"ID_RENAMING=" "$(udevadm info /sys/devices/virtual/net/hoge)"
75 timeout
30 bash
-c 'while [[ "$(systemctl show --property=ActiveState --value /sys/devices/virtual/net/hoge)" != "active" ]]; do sleep .5; done'
76 timeout
30 bash
-c 'while [[ "$(systemctl show --property=ActiveState --value /sys/subsystem/net/devices/hoge)" != "active" ]]; do sleep .5; done'
77 timeout
30 bash
-c 'while [[ "$(systemctl show --property=ActiveState --value /sys/devices/virtual/net/foobar)" != "inactive" ]]; do sleep .5; done'
78 timeout
30 bash
-c 'while [[ "$(systemctl show --property=ActiveState --value /sys/subsystem/net/devices/foobar)" != "inactive" ]]; do sleep .5; done'
81 rm -f /run
/udev
/rules.d
/50-testsuite.rules
82 udevadm control
--reload --timeout=30
84 # test for renaming interface with an external tool (issue #16967)
86 ip link
set hoge name foobar
87 udevadm
wait --timeout=30 --settle /sys
/devices
/virtual
/net
/foobar
88 timeout
30 bash
-c 'while [[ "$(systemctl show --property=ActiveState --value /sys/devices/virtual/net/hoge)" != "inactive" ]]; do sleep .5; done'
89 timeout
30 bash
-c 'while [[ "$(systemctl show --property=ActiveState --value /sys/subsystem/net/devices/hoge)" != "inactive" ]]; do sleep .5; done'
90 timeout
30 bash
-c 'while [[ "$(systemctl show --property=ActiveState --value /sys/devices/virtual/net/foobar)" != "active" ]]; do sleep .5; done'
91 timeout
30 bash
-c 'while [[ "$(systemctl show --property=ActiveState --value /sys/subsystem/net/devices/foobar)" != "active" ]]; do sleep .5; done'
93 ip link
set foobar name hoge
94 udevadm
wait --timeout=30 --settle /sys
/devices
/virtual
/net
/hoge
95 timeout
30 bash
-c 'while [[ "$(systemctl show --property=ActiveState --value /sys/devices/virtual/net/hoge)" != "active" ]]; do sleep .5; done'
96 timeout
30 bash
-c 'while [[ "$(systemctl show --property=ActiveState --value /sys/subsystem/net/devices/hoge)" != "active" ]]; do sleep .5; done'
97 timeout
30 bash
-c 'while [[ "$(systemctl show --property=ActiveState --value /sys/devices/virtual/net/foobar)" != "inactive" ]]; do sleep .5; done'
98 timeout
30 bash
-c 'while [[ "$(systemctl show --property=ActiveState --value /sys/subsystem/net/devices/foobar)" != "inactive" ]]; do sleep .5; done'
103 teardown_netif_renaming_conflict
() {
106 if [[ -n "$KILL_PID" ]]; then
112 rm -f /run
/udev
/rules.d
/50-testsuite.rules
113 udevadm control
--reload --timeout=30
119 test_netif_renaming_conflict
() {
122 trap teardown_netif_renaming_conflict RETURN
124 cat >/run
/udev
/rules.d
/50-testsuite.rules
<<EOF
125 ACTION!="add", GOTO="hoge_end"
126 SUBSYSTEM!="net", GOTO="hoge_end"
128 OPTIONS="log_level=debug"
130 KERNEL=="foobar", NAME="hoge"
135 udevadm control
--log-priority=debug
--reload --timeout=30
137 ip link add hoge
type dummy
138 udevadm
wait --timeout=30 --settle /sys
/devices
/virtual
/net
/hoge
140 TMPDIR
=$
(mktemp
-d -p /tmp udev-tests.XXXXXX
)
141 udevadm monitor
--udev --property --subsystem-match=net
>"$TMPDIR"/monitor.txt
&
144 # make sure that 'udevadm monitor' actually monitor uevents
147 since
="$(date '+%H:%M:%S')"
149 # add another interface which will conflict with an existing interface
150 ip link add foobar
type dummy
154 grep -q 'ACTION=add' "$TMPDIR"/monitor.txt
155 grep -q 'DEVPATH=/devices/virtual/net/foobar' "$TMPDIR"/monitor.txt
156 grep -q 'SUBSYSTEM=net' "$TMPDIR"/monitor.txt
157 grep -q 'INTERFACE=foobar' "$TMPDIR"/monitor.txt
158 grep -q 'ID_NET_DRIVER=dummy' "$TMPDIR"/monitor.txt
159 grep -q 'ID_NET_NAME=foobar' "$TMPDIR"/monitor.txt
160 # Even when network interface renaming is failed, SYSTEMD_ALIAS with the conflicting name will be broadcast.
161 grep -q 'SYSTEMD_ALIAS=/sys/subsystem/net/devices/hoge' "$TMPDIR"/monitor.txt
162 grep -q 'UDEV_WORKER_FAILED=1' "$TMPDIR"/monitor.txt
163 grep -q 'UDEV_WORKER_ERRNO=17' "$TMPDIR"/monitor.txt
164 grep -q 'UDEV_WORKER_ERRNO_NAME=EEXIST' "$TMPDIR"/monitor.txt
166 cat "$TMPDIR"/monitor.txt
174 timeout
30 bash
-c "while ! journalctl _PID=1 _COMM=systemd --since $since | grep -q 'foobar: systemd-udevd failed to process the device, ignoring: File exists'; do sleep 1; done"
175 # check if the invalid SYSTEMD_ALIAS property for the interface foobar is ignored by PID1
176 assert_eq
"$(systemctl show --property=SysFSPath --value /sys/subsystem/net/devices/hoge)" "/sys/devices/virtual/net/hoge"
179 test_netif_renaming_conflict