Packet tunneling over UDP, multiple channels
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

39 lines
1.0 KiB

  1. #!/bin/bash
  2. #
  3. # rrqnet helper script for establishing a rule based route table for a
  4. # given interface with given IP with default route to given gateway IP
  5. # on the interface link.
  6. # $1 = interface
  7. # $2 = interface IP
  8. # $3 = gateway IP
  9. #
  10. # This will retry every second until the setup is successful. Should
  11. # be spawned in a conf file, eg:
  12. # /etc/rrqnet/set-source-route.sh $TAP $IP $GW > /dev/null 2>&1 &
  13. #
  14. TAP=$1
  15. IP=$2
  16. GW=$3
  17. : ${TIX:=200}
  18. function set-source-route() {
  19. grep -q "$TIX $TAP" /etc/iproute2/rt_tables || \
  20. echo "$TIX $TAP" >> /etc/iproute2/rt_tables
  21. if [ -z "$(ip rule list from ${IP%/*})" ] ; then
  22. ip rule add from ${IP%/*} lookup $TAP || return 1
  23. fi
  24. if [ -z "$(ip route show table $TAP | grep ^$GW)" ] ; then
  25. ip route add $GW dev $TAP scope link src ${IP%/*} table $TAP || \
  26. return 1
  27. fi
  28. if [ -z "$(ip route show table $TAP | grep default)" ] ; then
  29. ip route add default via $GW dev $TAP table $TAP || return 1
  30. fi
  31. ip route show table $TAP
  32. }
  33. set-source-route && exit 0
  34. sleep 1
  35. exec $0 $*