Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Side by Side Diff: src/scripts/mod_for_test_scripts/100setupTestingInterface

Issue 1431003: Set up for a backchannel Ethernet interface to be used in testing (Closed)
Patch Set: Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 eth1 backchannel"
8
9 # Prevent connman from taking control of the backchannel network device.
10 ORIG_CONF=${ROOT_FS_DIR}/etc/init/connman.conf
11 TEMP_CONF=${ORIG_CONF}.tmp
12 sed 's/connmand -W/connmand -I eth1 -W/' ${ORIG_CONF} > ${TEMP_CONF}
13 mv -f ${TEMP_CONF} ${ORIG_CONF}
14
15 # Arrange to run dhclient on the backchannel device but without
16 # installing the default route, and stashing said route away for later
17 # installation as a host route.
18 cat > ${ROOT_FS_DIR}/etc/udev/rules.d/50-backchannel-eth1.rules <<EOF
19 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)"
21 EOF
22
23 cat > ${ROOT_FS_DIR}/sbin/backchannel-setup <<EOF
24 #!/bin/sh
25
26 if [ -f /var/run/dhclient-eth1.pid ]; then
27 # Something else is already going on - perhaps a second
28 # USB Ethernet device has been inserted. Let's not mess with it.
29 exit
30 fi
31
32 if [ "\$1" != "eth1" ]; then
33 initctl stop connman
34 # \$1 is the current name of the backchannel device. Swap it with eth1.
35 if ifconfig eth1 > /dev/null 2>&1; then
36 orig_eth1_mac=\$(ifconfig eth1 | awk '/HWaddr/ {print \$5}')
37 ifconfig eth1 down # must be down for nameif to work
38 nameif eth_tmp \${orig_eth1_mac}
39 fi
40 bdev_mac=\$(ifconfig \$1 | awk '/HWaddr/ {print \$5}')
41 ifconfig \$1 down # must be down for nameif to work
42 nameif eth1 \${bdev_mac}
43 if [ -n "\${orig_eth1_mac}" ]; then
44 nameif \$1 \${orig_eth1_mac}
45 fi
46 initctl start connman
47 fi
48
49 # Bring up the backchannel interface
50 dhclient -q -pf /var/run/dhclient-eth1.pid \\
51 -lf /var/run/dhclient-eth1.leases \\
52 -cf /etc/dhclient-backchannel.conf \\
53 -sf /sbin/dhclient-backchannel-script \\
54 eth1
55 EOF
56
57 chmod +x ${ROOT_FS_DIR}/sbin/backchannel-setup
58
59 cat > ${ROOT_FS_DIR}/etc/dhclient-backchannel.conf <<EOF
60 request subnet-mask, broadcast-address, routers;
61 EOF
62
63 cat > ${ROOT_FS_DIR}/sbin/dhclient-backchannel-script <<EOF
64 #!/bin/sh
65
66 if [ -n "\$new_broadcast_address" ]; then
67 new_broadcast_arg="broadcast \$new_broadcast_address"
68 fi
69 if [ -n "\$new_subnet_mask" ]; then
70 new_subnet_arg="netmask \$new_subnet_mask"
71 fi
72
73
74 case "\$reason" in
75 MEDIUM|ARPCHECK|ARPSEND)
76 # Do nothing
77 ;;
78 PREINIT)
79 # The DHCP client is requesting that an interface be
80 # configured as required in order to send packets prior to
81 # receiving an actual address. - dhclient-script(8)
82
83 ifconfig \$interface inet 0 up
84
85 # We need to give the kernel some time to get the interface up.
86 sleep 1
87 ;;
88
89 BOUND|RENEW|REBIND|REBOOT|TIMEOUT)
90 if [ -n "\$old_ip_address" -a \
91 "\$old_ip_address" != "\$new_ip_address" ]; then
92 # IP address changed. Bringing down the interface will delete all ro utes,
93 # and clear the ARP cache.
94 ifconfig \$interface inet 0
95
96 fi
97
98 if [ -z "\$old_ip_address" -o "\$old_ip_address" != "\$new_ip_address" - o \
99 "\$reason" = "BOUND" -o "\$reason" = "REBOOT" ]; then
100
101 ifconfig \$interface inet \$new_ip_address \$new_subnet_arg \
102 \$new_broadcast_arg \$mtu_arg
103
104 # Since this script is for the backchannel testing interface,
105 # we don't set the default route from here, but we do stash
106 # it for possible later use in setting up a host route.
107 cp /dev/null /var/run/dhclient-\${interface}.routers
108 for router in \$new_routers; do
109 echo \$router >> /var/run/dhclient-\${interface}.routers
110 done
111 fi
112 ;;
113
114 EXPIRE|FAIL|RELEASE|STOP)
115 if [ -n "\$old_ip_address" ]; then
116 # Shut down interface, which will delete routes and clear arp cache.
117 ifconfig \$interface inet 0
118 fi
119 ;;
120 esac
121 EOF
122
123 chmod +x ${ROOT_FS_DIR}/sbin/dhclient-backchannel-script
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698