mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-23 06:31:18 +02:00
Adjust backchannel network setup to require explicit enabling
on the device under test and to use a not-normally-generated interface name, so that use of add-on ethernet devices is not affected in normal operation. BUG=2962, 2941 (dup of 1810013, git goofiness) Review URL: http://codereview.chromium.org/1826003
This commit is contained in:
parent
66659791ce
commit
219bbebef2
@ -4,54 +4,63 @@
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
echo "Configuring for eth1 backchannel"
|
||||
echo "Configuring for backchannel network device"
|
||||
|
||||
testif=eth_test
|
||||
|
||||
# Prevent connman from taking control of the backchannel network device.
|
||||
ORIG_CONF=${ROOT_FS_DIR}/etc/init/connman.conf
|
||||
TEMP_CONF=${ORIG_CONF}.tmp
|
||||
sed 's/connmand -W/connmand -I eth1 -W/' ${ORIG_CONF} > ${TEMP_CONF}
|
||||
sed "s/connmand -W/connmand -I ${testif} -W/" ${ORIG_CONF} > ${TEMP_CONF}
|
||||
mv -f ${TEMP_CONF} ${ORIG_CONF}
|
||||
|
||||
# Arrange to run dhclient on the backchannel device but without
|
||||
# installing the default route, and stashing said route away for later
|
||||
# installation as a host route.
|
||||
cat > ${ROOT_FS_DIR}/etc/udev/rules.d/50-backchannel-eth1.rules <<EOF
|
||||
cat > ${ROOT_FS_DIR}/etc/udev/rules.d/50-backchannel-network.rules <<EOF
|
||||
KERNEL=="eth*", SUBSYSTEMS=="usb", ACTION=="add", RUN+="/sbin/backchannel-setup %k"
|
||||
KERNEL=="eth1", SUBSYSTEMS=="usb", ACTION=="remove", RUN+="kill \$(cat /var/run/dhclient-%k.pid)"
|
||||
KERNEL=="${testif}", SUBSYSTEMS=="usb", ACTION=="remove", RUN+="kill \$(cat /var/run/dhclient-%k.pid)"
|
||||
EOF
|
||||
|
||||
cat > ${ROOT_FS_DIR}/sbin/backchannel-setup <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
if [ -f /var/run/dhclient-eth1.pid ]; then
|
||||
testif=${testif}
|
||||
|
||||
if [ ! -f /mnt/stateful_partition/etc/enable_backchannel_network ]; then
|
||||
# This mechanism has to be explicitly enabled on the device.
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ -f /var/run/dhclient-\${testif}.pid ]; then
|
||||
# Something else is already going on - perhaps a second
|
||||
# USB Ethernet device has been inserted. Let's not mess with it.
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ "\$1" != "eth1" ]; then
|
||||
if [ "\$1" != "\${testif}" ]; then
|
||||
initctl stop connman
|
||||
# \$1 is the current name of the backchannel device. Swap it with eth1.
|
||||
if ifconfig eth1 > /dev/null 2>&1; then
|
||||
orig_eth1_mac=\$(ifconfig eth1 | awk '/HWaddr/ {print \$5}')
|
||||
ifconfig eth1 down # must be down for nameif to work
|
||||
nameif eth_tmp \${orig_eth1_mac}
|
||||
# \$1 is the current name of the backchannel device. Swap it with testif.
|
||||
if ifconfig \${testif} > /dev/null 2>&1; then
|
||||
orig_mac=\$(ifconfig \${testif} | awk '/HWaddr/ {print \$5}')
|
||||
ifconfig \${testif} down # must be down for nameif to work
|
||||
nameif eth_tmp \${orig_mac}
|
||||
fi
|
||||
bdev_mac=\$(ifconfig \$1 | awk '/HWaddr/ {print \$5}')
|
||||
ifconfig \$1 down # must be down for nameif to work
|
||||
nameif eth1 \${bdev_mac}
|
||||
if [ -n "\${orig_eth1_mac}" ]; then
|
||||
nameif \$1 \${orig_eth1_mac}
|
||||
nameif \${testif} \${bdev_mac}
|
||||
if [ -n "\${orig_mac}" ]; then
|
||||
nameif \$1 \${orig_mac}
|
||||
fi
|
||||
initctl start connman
|
||||
fi
|
||||
|
||||
# Bring up the backchannel interface
|
||||
dhclient -q -pf /var/run/dhclient-eth1.pid \\
|
||||
-lf /var/run/dhclient-eth1.leases \\
|
||||
dhclient -q -pf /var/run/dhclient-\${testif}.pid \\
|
||||
-lf /var/run/dhclient-\${testif}.leases \\
|
||||
-cf /etc/dhclient-backchannel.conf \\
|
||||
-sf /sbin/dhclient-backchannel-script \\
|
||||
eth1
|
||||
\${testif}
|
||||
EOF
|
||||
|
||||
chmod +x ${ROOT_FS_DIR}/sbin/backchannel-setup
|
||||
|
Loading…
x
Reference in New Issue
Block a user