Advertisement
zefie

zefie openwrt wan2 + traffic marking

Aug 27th, 2018
521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.52 KB | None | 0 0
  1. #!/bin/ash
  2. Z_WAN_IF="eth0"
  3. Z_WAN2_IF="eth2"
  4. Z_WAN2_MAC="A0:63:91:B8:86:BC"
  5. Z_TABLE="200"
  6. Z_WAIT=5
  7. Z_COUNT=0
  8.  
  9. # Create interface if it doesn't exist
  10. if [ $(ip link | grep "${Z_WAN_IF}" | grep UP | wc -l) -gt 0 ]; then
  11.         if [ $(ip link | grep "${Z_WAN2_IF}" | wc -l) -lt 1 ]; then
  12.                 ip link add link ${Z_WAN_IF} ${Z_WAN2_IF} type macvlan
  13.                 if [ $? -ne 0 ]; then exit; fi
  14.                 ifconfig ${Z_WAN2_IF} hw ether "${Z_WAN2_MAC}"
  15.                 if [ $? -ne 0 ]; then exit; fi
  16.  
  17.                 # Wait for interface
  18.                 Z_COUNT=0
  19.                 while [ ${Z_COUNT} -lt ${Z_WAIT} ]; do
  20.                         if [ $(ip link | grep "${Z_WAN2_IF}" | wc -l) -eq 1 ]; then
  21.                                 break;
  22.                         fi
  23.                         sleep 1
  24.                         Z_COUNT=$(expr ${Z_COUNT} + 1)
  25.                 done
  26.         fi
  27. fi
  28.  
  29. if [ $(ip link | grep "${Z_WAN2_IF}" | grep UP | wc -l) -eq 1 ] && [ -z "${1}" ]; then
  30.         Z_WAN_IP="$(ip addr | grep "${Z_WAN_IF}" -A2 | grep inet | grep "/24" | cut -d' ' -f6 | cut -d'/' -f1)"
  31.         if [ "${Z_WAN_IP}" == "" ]; then exit; fi
  32.         if [ $(ip route show table ${Z_TABLE} | grep "${Z_WAN2_IF}" | wc -l) -eq 0 ]; then
  33.                 Z_COUNT=0
  34.                 while [ ${Z_COUNT} -lt ${Z_WAIT} ]; do
  35.                         Z_WAN2_IP="$(ip addr | grep "${Z_WAN2_IF}" -A2 | grep inet | grep "/24" | cut -d' ' -f6 | cut -d'/' -f1)"
  36.                         if [ "${Z_WAN2_IP}" != "" ]; then break; fi
  37.                         Z_COUNT=$(expr ${Z_COUNT} + 1)
  38.                         sleep 1
  39.                 done
  40.                 if [ "${Z_WAN2_IP}" == "" ]; then exit; fi
  41.                 Z_WAN2_GATEWAY="$(echo ${Z_WAN2_IP} | cut -d'.' -f1,2,3).254"
  42.                 ip route flush table ${Z_TABLE}
  43.                 ip route show table main | grep -Ev ^default | while read ROUTE ; do ip route add table ${Z_TABLE} ${ROUTE} ; done
  44.                 ip route add default via ${Z_WAN2_GATEWAY} dev ${Z_WAN2_IF} src ${Z_WAN2_IP} table ${Z_TABLE}
  45.                 ip rule add fwmark ${Z_TABLE} table ${Z_TABLE}
  46.                 ip route flush cache
  47.         fi
  48.         iptables -A OUTPUT -o eth2 -j MARK --set-mark ${Z_TABLE}
  49.  
  50.         # Set WAN2 Flag for Free Wifi
  51.         iptables -t mangle -A PREROUTING -i wlan1-1 -j MARK --set-mark ${Z_TABLE}
  52.  
  53.         # Set WAN2 Flag for Zefie Server
  54.         iptables -t mangle -A PREROUTING -m mac --mac-source 1C:75:08:11:83:96 -j MARK --set-mark ${Z_TABLE}
  55.  
  56.         exit 0;
  57. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement