Advertisement
teknoraver

multiwan bonding

Dec 10th, 2015
216
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2.  
  3. remote=1.2.3.4 # MIX server
  4. dev=eth0.1036
  5. modules='ip_gre macvlan bonding'
  6. sn=D-W1234567890123
  7. snh=57313233343536373839303930313
  8.  
  9. loadmodules() {
  10.     for i in $modules; do
  11.         grep -q $i /proc/modules || modprobe $i
  12.     done
  13. }
  14.  
  15. unloadmodules() {
  16.     for i in $modules; do
  17.         grep -q $i /proc/modules && modprobe -r $i
  18.     done
  19. }
  20.  
  21. localinit() {
  22.     loadmodules
  23.  
  24.     ip addr add 10.0.0.2/24 dev bond0
  25.     ip link set dev grezz$i up
  26.     iptables -t mangle -A FORWARD -o bond0 -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
  27.     iptables -t nat -A POSTROUTING -o bond0 -j MASQUERADE
  28.     ip route add default via 10.0.0.1
  29. }
  30.  
  31. localadd() {
  32.     i=$(awk -F'grezz|:' '/^grezz/{m=$2 > m ? $2 : m}END{print m}' /proc/net/dev)
  33.     i=$((i + 1))
  34.     mac=$(ip link show dev $dev |awk '/ether/{print$2}')
  35.     macx=$(echo $mac |awk -F: '{printf $1":"$2":"$3":"$4":"$5":%02x", xor(strtonum("0x"$6),'"$i)}")
  36.  
  37.     ip link add link $dev veth$i address $macx type macvlan
  38.     ip link set dev veth$i up
  39.     pppd debug updetach call data ifname pppoe$i user $sn$i password 'VJ|5.4.8.1.160.8.24|RA|CGN=1|pw=Vodafone' veth$i host-uniq $snh$i nodefaultroute
  40.     ip=$(ip addr show dev pppoe$i |awk '/inet/{print$2}')
  41.  
  42.     ip rule add from $ip table 100$i
  43.     ip route add default dev pppoe$i table 100$i
  44.  
  45.     ip link add grezz$i type gretap local $ip remote $remote
  46.     ip link set dev grezz$i up
  47.     ssh -b $ip $remote 'multiwan remoteadd'
  48.     ifenslave bond0 grezz$i
  49. }
  50.  
  51. localcleanup() {
  52.     killall -w pppd
  53.     unloadmodules
  54.     i=1001
  55.     while ip rule del lookup $i; do i=$((i + 1)); done
  56.     iptables -t mangle -D FORWARD -o bond0 -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
  57.     iptables -t nat -D POSTROUTING -o bond0 -j MASQUERADE
  58. }
  59.  
  60. remoteinit() {
  61.     loadmodules
  62.  
  63.     ip addr add 10.0.0.1/24 dev bond0
  64.     ip link set dev bond0 up mtu 1454
  65. }
  66.  
  67. remoteadd() {
  68.     i=$(awk -F'grezz|:' '/^grezz/{print $2}' /proc/net/dev)
  69.     i=$((i + 1))
  70.     ip link add grezz$i type gretap remote ${SSH_CLIENT%% *}
  71.     ip link set dev grezz$i up
  72.     ifenslave bond0 grezz$i
  73. }
  74.  
  75. remotecleanup() {
  76.     unloadmodules
  77.     i=1001
  78.     while ip rule del lookup $i; do i=$((i + 1)); done
  79. }
  80.  
  81. $1
Advertisement
RAW Paste Data Copied
Advertisement