Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 63 lines (55 sloc) 2.79 kb
d6f48c2 @keithw Initial commit
authored
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 my @script = ( q[iptables -t nat -F],
6 q[iptables -F],
2c374af @keithw Timeout packets for more accurate "outstanding" count
authored
7 q[iptables -t nat -A POSTROUTING -o rmnet0 -j MASQUERADE],
d6f48c2 @keithw Initial commit
authored
8 q[iptables -t nat -A POSTROUTING -o rmnet1 -j MASQUERADE],
2c374af @keithw Timeout packets for more accurate "outstanding" count
authored
9 q[iptables -t nat -A POSTROUTING -o rmnet2 -j MASQUERADE],
10 q[iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT -i rmnet0 -o rndis0],
d6f48c2 @keithw Initial commit
authored
11 q[iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT -i rmnet1 -o rndis0],
2c374af @keithw Timeout packets for more accurate "outstanding" count
authored
12 q[iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT -i rmnet2 -o rndis0],
13 q[iptables -A FORWARD -j ACCEPT -o rmnet0 -i rndis0],
d6f48c2 @keithw Initial commit
authored
14 q[iptables -A FORWARD -j ACCEPT -o rmnet1 -i rndis0],
2c374af @keithw Timeout packets for more accurate "outstanding" count
authored
15 q[iptables -A FORWARD -j ACCEPT -o rmnet2 -i rndis0],
d6f48c2 @keithw Initial commit
authored
16 q[ifconfig rndis0 10.100.DEVICENUM.2 netmask 255.255.255.0 up],
17 q[echo 1 > /proc/sys/net/ipv4/ip_forward] );
18
19 my @devs = ( 'x', 'usb0', 'usb1', 'usb2' );
20
2c374af @keithw Timeout packets for more accurate "outstanding" count
authored
21 system( "echo 0 | sudo tee /proc/sys/net/ipv4/conf/all/rp_filter" );
22 system( "echo 1 | sudo tee /proc/sys/net/ipv4/conf/all/accept_local" );
23 system( "echo 1 | sudo tee /proc/sys/net/ipv4/conf/all/log_martians" );
24 system( "echo 0 | sudo tee /proc/sys/net/ipv4/conf/eth0/rp_filter" );
25 system( "echo 1 | sudo tee /proc/sys/net/ipv4/conf/eth0/accept_local" );
26 system( "echo 1 | sudo tee /proc/sys/net/ipv4/conf/eth0/log_martians" );
27 system( "echo 0 | sudo tee /proc/sys/net/ipv4/conf/default/rp_filter" );
28 system( "echo 1 | sudo tee /proc/sys/net/ipv4/conf/default/accept_local" );
29 system( "echo 1 | sudo tee /proc/sys/net/ipv4/conf/default/log_martians" );
30
d0882cd @keithw Compiles
authored
31 for my $device ( qw[A B] ) {
d6f48c2 @keithw Initial commit
authored
32 my ( $num ) = $device =~ tr{ABC}{123}r;
33 my $dev = $devs[ $num ];
34
446b78a Add rndis to donat, kill network manager
anirudh authored
35 my $linemod = "setprop sys.usb.config rndis,adb";
36 $linemod =~ s{DEVICENUM}{$num}g;
37 my $str = qq{./runon $device shell su -c "$linemod"};
38 print "$str\n";
39 system( $str );
71854cd @anirudhSK give adb time to reboot
anirudhSK authored
40 print "Sleeping 3 seconds for rndis change to take effect and adb to reboot \n";
41 system("sleep 3");
42 print ("Stop network manager to prevent autoconf \n");
446b78a Add rndis to donat, kill network manager
anirudh authored
43 system( "sudo service network-manager stop" );
d6f48c2 @keithw Initial commit
authored
44 for my $line ( @script ) {
45 my $linemod = $line;
46 $linemod =~ s{DEVICENUM}{$num}g;
47 my $str = qq{./runon $device shell su -c "$linemod"};
48 print "$str\n";
49 system( $str );
50 }
51 system( "sudo ifconfig $dev 10.100.$num.1 netmask 255.255.255.0" );
446b78a Add rndis to donat, kill network manager
anirudh authored
52 system( "sudo route del -net default gw 10.100.$num.2 metric 2" );
d6f48c2 @keithw Initial commit
authored
53 system( "sudo route add -net default gw 10.100.$num.2 metric 2" );
54 system( "echo 0 | sudo tee /proc/sys/net/ipv4/conf/$dev/rp_filter" );
55 system( "echo 1 | sudo tee /proc/sys/net/ipv4/conf/$dev/accept_local" );
446b78a Add rndis to donat, kill network manager
anirudh authored
56 system( "ping -c3 10.100.$num.2" );
71854cd @anirudhSK give adb time to reboot
anirudhSK authored
57 system( "ping -c3 -I$dev 8.8.8.8" );
d6f48c2 @keithw Initial commit
authored
58 }
59
60 # A: 8a:71:5f:ef:c7:5e
61 # B: 0a:8d:31:bb:7c:96
62 # C: 6a:f6:8e:83:a7:7e
Something went wrong with that request. Please try again.