OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 | 2 |
3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 echo "Configuring for eth1 backchannel" | 7 echo "Configuring for backchannel network device" |
| 8 |
| 9 testif=eth_test |
8 | 10 |
9 # Prevent connman from taking control of the backchannel network device. | 11 # Prevent connman from taking control of the backchannel network device. |
10 ORIG_CONF=${ROOT_FS_DIR}/etc/init/connman.conf | 12 ORIG_CONF=${ROOT_FS_DIR}/etc/init/connman.conf |
11 TEMP_CONF=${ORIG_CONF}.tmp | 13 TEMP_CONF=${ORIG_CONF}.tmp |
12 sed 's/connmand -W/connmand -I eth1 -W/' ${ORIG_CONF} > ${TEMP_CONF} | 14 sed "s/connmand -W/connmand -I ${testif} -W/" ${ORIG_CONF} > ${TEMP_CONF} |
13 mv -f ${TEMP_CONF} ${ORIG_CONF} | 15 mv -f ${TEMP_CONF} ${ORIG_CONF} |
14 | 16 |
15 # Arrange to run dhclient on the backchannel device but without | 17 # Arrange to run dhclient on the backchannel device but without |
16 # installing the default route, and stashing said route away for later | 18 # installing the default route, and stashing said route away for later |
17 # installation as a host route. | 19 # installation as a host route. |
18 cat > ${ROOT_FS_DIR}/etc/udev/rules.d/50-backchannel-eth1.rules <<EOF | 20 cat > ${ROOT_FS_DIR}/etc/udev/rules.d/50-backchannel-network.rules <<EOF |
19 KERNEL=="eth*", SUBSYSTEMS=="usb", ACTION=="add", RUN+="/sbin/backchannel-setup
%k" | 21 KERNEL=="eth*", SUBSYSTEMS=="usb", ACTION=="add", RUN+="/sbin/backchannel-setup
%k" |
20 KERNEL=="eth1", SUBSYSTEMS=="usb", ACTION=="remove", RUN+="kill \$(cat /var/run/
dhclient-%k.pid)" | 22 KERNEL=="${testif}", SUBSYSTEMS=="usb", ACTION=="remove", RUN+="kill \$(cat /var
/run/dhclient-%k.pid)" |
21 EOF | 23 EOF |
22 | 24 |
23 cat > ${ROOT_FS_DIR}/sbin/backchannel-setup <<EOF | 25 cat > ${ROOT_FS_DIR}/sbin/backchannel-setup <<EOF |
24 #!/bin/sh | 26 #!/bin/sh |
25 | 27 |
26 if [ -f /var/run/dhclient-eth1.pid ]; then | 28 testif=${testif} |
| 29 |
| 30 if [ ! -f /mnt/stateful_partition/etc/enable_backchannel_network ]; then |
| 31 # This mechanism has to be explicitly enabled on the device. |
| 32 exit |
| 33 fi |
| 34 |
| 35 if [ -f /var/run/dhclient-\${testif}.pid ]; then |
27 # Something else is already going on - perhaps a second | 36 # Something else is already going on - perhaps a second |
28 # USB Ethernet device has been inserted. Let's not mess with it. | 37 # USB Ethernet device has been inserted. Let's not mess with it. |
29 exit | 38 exit |
30 fi | 39 fi |
31 | 40 |
32 if [ "\$1" != "eth1" ]; then | 41 if [ "\$1" != "\${testif}" ]; then |
33 initctl stop connman | 42 initctl stop connman |
34 # \$1 is the current name of the backchannel device. Swap it with eth1. | 43 # \$1 is the current name of the backchannel device. Swap it with testif. |
35 if ifconfig eth1 > /dev/null 2>&1; then | 44 if ifconfig \${testif} > /dev/null 2>&1; then |
36 orig_eth1_mac=\$(ifconfig eth1 | awk '/HWaddr/ {print \$5}') | 45 orig_mac=\$(ifconfig \${testif} | awk '/HWaddr/ {print \$5}') |
37 ifconfig eth1 down # must be down for nameif to work | 46 ifconfig \${testif} down # must be down for nameif to work |
38 nameif eth_tmp \${orig_eth1_mac} | 47 nameif eth_tmp \${orig_mac} |
39 fi | 48 fi |
40 bdev_mac=\$(ifconfig \$1 | awk '/HWaddr/ {print \$5}') | 49 bdev_mac=\$(ifconfig \$1 | awk '/HWaddr/ {print \$5}') |
41 ifconfig \$1 down # must be down for nameif to work | 50 ifconfig \$1 down # must be down for nameif to work |
42 nameif eth1 \${bdev_mac} | 51 nameif \${testif} \${bdev_mac} |
43 if [ -n "\${orig_eth1_mac}" ]; then | 52 if [ -n "\${orig_mac}" ]; then |
44 nameif \$1 \${orig_eth1_mac} | 53 nameif \$1 \${orig_mac} |
45 fi | 54 fi |
46 initctl start connman | 55 initctl start connman |
47 fi | 56 fi |
48 | 57 |
49 # Bring up the backchannel interface | 58 # Bring up the backchannel interface |
50 dhclient -q -pf /var/run/dhclient-eth1.pid \\ | 59 dhclient -q -pf /var/run/dhclient-\${testif}.pid \\ |
51 -lf /var/run/dhclient-eth1.leases \\ | 60 -lf /var/run/dhclient-\${testif}.leases \\ |
52 -cf /etc/dhclient-backchannel.conf \\ | 61 -cf /etc/dhclient-backchannel.conf \\ |
53 -sf /sbin/dhclient-backchannel-script \\ | 62 -sf /sbin/dhclient-backchannel-script \\ |
54 eth1 | 63 \${testif} |
55 EOF | 64 EOF |
56 | 65 |
57 chmod +x ${ROOT_FS_DIR}/sbin/backchannel-setup | 66 chmod +x ${ROOT_FS_DIR}/sbin/backchannel-setup |
58 | 67 |
59 cat > ${ROOT_FS_DIR}/etc/dhclient-backchannel.conf <<EOF | 68 cat > ${ROOT_FS_DIR}/etc/dhclient-backchannel.conf <<EOF |
60 request subnet-mask, broadcast-address, routers; | 69 request subnet-mask, broadcast-address, routers; |
61 EOF | 70 EOF |
62 | 71 |
63 cat > ${ROOT_FS_DIR}/sbin/dhclient-backchannel-script <<EOF | 72 cat > ${ROOT_FS_DIR}/sbin/dhclient-backchannel-script <<EOF |
64 #!/bin/sh | 73 #!/bin/sh |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 EXPIRE|FAIL|RELEASE|STOP) | 123 EXPIRE|FAIL|RELEASE|STOP) |
115 if [ -n "\$old_ip_address" ]; then | 124 if [ -n "\$old_ip_address" ]; then |
116 # Shut down interface, which will delete routes and clear arp cache. | 125 # Shut down interface, which will delete routes and clear arp cache. |
117 ifconfig \$interface inet 0 | 126 ifconfig \$interface inet 0 |
118 fi | 127 fi |
119 ;; | 128 ;; |
120 esac | 129 esac |
121 EOF | 130 EOF |
122 | 131 |
123 chmod +x ${ROOT_FS_DIR}/sbin/dhclient-backchannel-script | 132 chmod +x ${ROOT_FS_DIR}/sbin/dhclient-backchannel-script |
OLD | NEW |