OLD | NEW |
| (Empty) |
1 #!/bin/bash | |
2 | |
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 | |
5 # found in the LICENSE file. | |
6 | |
7 echo "Configuring for backchannel network device" | |
8 | |
9 testif=eth_test | |
10 | |
11 # Prevent flimflam from taking control of the backchannel network device. | |
12 ORIG_CONF=${ROOT_FS_DIR}/etc/init/flimflam.conf | |
13 TEMP_CONF=${ORIG_CONF}.tmp | |
14 sed "s,/usr/sbin/flimflamd,/usr/sbin/flimflamd -I ${testif}," ${ORIG_CONF} > ${T
EMP_CONF} | |
15 mv -f ${TEMP_CONF} ${ORIG_CONF} | |
16 | |
17 # Arrange to run dhclient on the backchannel device but without | |
18 # installing the default route, and stashing said route away for later | |
19 # installation as a host route. | |
20 cat > ${ROOT_FS_DIR}/etc/udev/rules.d/50-backchannel-network.rules <<EOF | |
21 KERNEL=="eth*", SUBSYSTEMS=="usb", ACTION=="add", RUN+="/sbin/backchannel-setup
%k" | |
22 KERNEL=="${testif}", SUBSYSTEMS=="usb", ACTION=="remove", RUN+="kill \$(cat /var
/run/dhclient-%k.pid)" | |
23 EOF | |
24 | |
25 cat > ${ROOT_FS_DIR}/sbin/backchannel-setup <<EOF | |
26 #!/bin/sh | |
27 | |
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 | |
36 # Something else is already going on - perhaps a second | |
37 # USB Ethernet device has been inserted. Let's not mess with it. | |
38 exit | |
39 fi | |
40 | |
41 if [ "\$1" != "\${testif}" ]; then | |
42 initctl stop flimflam | |
43 # \$1 is the current name of the backchannel device. Swap it with testif. | |
44 if ifconfig \${testif} > /dev/null 2>&1; then | |
45 orig_mac=\$(ifconfig \${testif} | awk '/HWaddr/ {print \$5}') | |
46 ifconfig \${testif} down # must be down for nameif to work | |
47 nameif eth_tmp \${orig_mac} | |
48 fi | |
49 bdev_mac=\$(ifconfig \$1 | awk '/HWaddr/ {print \$5}') | |
50 ifconfig \$1 down # must be down for nameif to work | |
51 nameif \${testif} \${bdev_mac} | |
52 if [ -n "\${orig_mac}" ]; then | |
53 nameif \$1 \${orig_mac} | |
54 fi | |
55 initctl start flimflam | |
56 fi | |
57 | |
58 # Bring up the backchannel interface | |
59 dhclient -q -pf /var/run/dhclient-\${testif}.pid \\ | |
60 -lf /var/run/dhclient-\${testif}.leases \\ | |
61 -cf /etc/dhclient-backchannel.conf \\ | |
62 -sf /sbin/dhclient-backchannel-script \\ | |
63 \${testif} | |
64 EOF | |
65 | |
66 chmod +x ${ROOT_FS_DIR}/sbin/backchannel-setup | |
67 | |
68 cat > ${ROOT_FS_DIR}/etc/dhclient-backchannel.conf <<EOF | |
69 request subnet-mask, broadcast-address, routers; | |
70 EOF | |
71 | |
72 cat > ${ROOT_FS_DIR}/sbin/dhclient-backchannel-script <<EOF | |
73 #!/bin/sh | |
74 | |
75 if [ -n "\$new_broadcast_address" ]; then | |
76 new_broadcast_arg="broadcast \$new_broadcast_address" | |
77 fi | |
78 if [ -n "\$new_subnet_mask" ]; then | |
79 new_subnet_arg="netmask \$new_subnet_mask" | |
80 fi | |
81 | |
82 | |
83 case "\$reason" in | |
84 MEDIUM|ARPCHECK|ARPSEND) | |
85 # Do nothing | |
86 ;; | |
87 PREINIT) | |
88 # The DHCP client is requesting that an interface be | |
89 # configured as required in order to send packets prior to | |
90 # receiving an actual address. - dhclient-script(8) | |
91 | |
92 ifconfig \$interface inet 0 up | |
93 | |
94 # We need to give the kernel some time to get the interface up. | |
95 sleep 1 | |
96 ;; | |
97 | |
98 BOUND|RENEW|REBIND|REBOOT|TIMEOUT) | |
99 if [ -n "\$old_ip_address" -a \ | |
100 "\$old_ip_address" != "\$new_ip_address" ]; then | |
101 # IP address changed. Bringing down the interface will delete all ro
utes, | |
102 # and clear the ARP cache. | |
103 ifconfig \$interface inet 0 | |
104 | |
105 fi | |
106 | |
107 if [ -z "\$old_ip_address" -o "\$old_ip_address" != "\$new_ip_address" -
o \ | |
108 "\$reason" = "BOUND" -o "\$reason" = "REBOOT" ]; then | |
109 | |
110 ifconfig \$interface inet \$new_ip_address \$new_subnet_arg \ | |
111 \$new_broadcast_arg \$mtu_arg | |
112 | |
113 # Since this script is for the backchannel testing interface, | |
114 # we don't set the default route from here, but we do stash | |
115 # it for possible later use in setting up a host route. | |
116 cp /dev/null /var/run/dhclient-\${interface}.routers | |
117 for router in \$new_routers; do | |
118 echo \$router >> /var/run/dhclient-\${interface}.routers | |
119 done | |
120 fi | |
121 ;; | |
122 | |
123 EXPIRE|FAIL|RELEASE|STOP) | |
124 if [ -n "\$old_ip_address" ]; then | |
125 # Shut down interface, which will delete routes and clear arp cache. | |
126 ifconfig \$interface inet 0 | |
127 fi | |
128 ;; | |
129 esac | |
130 EOF | |
131 | |
132 chmod +x ${ROOT_FS_DIR}/sbin/dhclient-backchannel-script | |
OLD | NEW |