Advertisement
hellsy

conf.d/net

Nov 11th, 2013
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. # cat /etc/conf.d/net
  2.  
  3. L2TP_BACKEND="xl2tpd"
  4. L2TP_TIMEOUT=20
  5.  
  6. DEPEND="lan"
  7. L2TP="ppp0"
  8. ROUTES="
  9. 195.14.50.0/27
  10. 78.106.0.0/15
  11. 224.0.0.0/4
  12. "
  13.  
  14. config_lan="dhclient"
  15. dhclient_lan="-nw"
  16. config_ppp0="null"
  17. #mtu_lan=1500
  18.  
  19.  
  20. #config_lan="dhcp"
  21.  
  22. modules_wifi="!iwconfig !wpa_supplicant"
  23. config_wifi="192.168.2.1 netmask 255.255.255.0 broadcast 192.168.2.255"
  24.  
  25. depend_ppp0() {
  26. need net.${DEPEND}
  27. }
  28.  
  29. check_module () {
  30. if ! [[ -f /proc/net/pppol2tp ]]; then
  31. ebegin "Loading l2tp module"
  32. # try both new and old module names
  33. modprobe l2tp_ppp 2>/dev/null || modprobe pppol2tp 2>/dev/null
  34. eend $?.
  35. fi
  36. }
  37.  
  38. checkconfig() {
  39. if [ "${L2TP_BACKEND}" = "xl2tpd" ]; then
  40. if [[ ! -f /etc/xl2tpd/xl2tpd.conf ]] ; then
  41. eerror "Missing /etc/xl2tpd/xl2tpd.conf configuration file!"
  42. eerror "Example configuration file could be found in doc directory."
  43. return 1
  44. fi
  45.  
  46. if [ ! -d /var/run/xl2tpd ] ; then
  47. checkpath -d -m 755 /var/run/xl2tpd
  48. fi
  49. fi
  50.  
  51. return 0
  52. }
  53.  
  54. preup() {
  55. if [ -z "${L2TP_BACKEND}" ]; then
  56. L2TP_BACKEND="xl2tpd"
  57. fi
  58.  
  59. checkconfig || return 1
  60.  
  61. if [ x"${IFACE}" = x"${L2TP}" ]; then
  62. if [ "${L2TP_BACKEND}" = "xl2tpd" ]; then
  63. start-stop-daemon --start --quiet --exec /usr/sbin/xl2tpd
  64. else
  65. check_module
  66. start-stop-daemon --start --quiet --exec /usr/sbin/openl2tpd
  67. fi
  68.  
  69. iface_timer=0
  70. while [ $iface_timer -lt $L2TP_TIMEOUT ]; do
  71. if [ -n "$(ifconfig | grep ${IFACE})" ]; then
  72. eend 0
  73. return 0
  74. else
  75. if [ ${iface_timer} -eq 0 ]; then
  76. einfo "Waiting for l2tp..."
  77. fi
  78. sleep 1
  79. ((iface_timer++))
  80. fi
  81. done
  82.  
  83. cleanup_l2tp
  84. eend 1
  85. return 1
  86. fi
  87.  
  88. return 0
  89. }
  90.  
  91. postup() {
  92. if [ x"${IFACE}" = x"${L2TP}" ]; then
  93. gw=`route -n | awk "{ if (\\$1 == \"0.0.0.0\" && \\$8 == \"${DEPEND}\") print \\$2 }" | perl -e 'print split("\n", <>, 1)'`
  94. vpn=`ifconfig | grep -A1 ${IFACE} | grep -i p-t-p | awk '{ print $3 }' | sed 's/p-t-p://gi'`
  95. echo "TRY: route add ${vpn} gw ${gw}"
  96. route add ${vpn} gw ${gw}
  97.  
  98. for i in ${ROUTES}; do
  99. echo "TRY: route add -net ${i} gw ${gw}"
  100. route add -net ${i} gw ${gw}
  101. done
  102. fi
  103. return 0
  104. }
  105.  
  106. predown() {
  107. if [ -z "${L2TP_BACKEND}" ]; then
  108. L2TP_BACKEND="xl2tpd"
  109. fi
  110.  
  111. if [ x"${IFACE}" = x"${L2TP}" ]; then
  112. gw=`route -n | awk "{ if (\\$1 == \"0.0.0.0\" && \\$8 == \"${DEPEND}\") print \\$2 }" | perl -e 'print split("\n", <>, 1)'`
  113. vpn=`ifconfig | grep -A1 ${IFACE} | grep -i p-t-p | awk '{ print $3 }' | sed 's/p-t-p://gi'`
  114. # vpn=`ifconfig | grep -A1 ${IFACE} | grep -i dest | awk '{ print $6 }'`
  115.  
  116. echo "GW: ${gw}" > 1111;
  117.  
  118. cleanup_l2tp
  119. if [ -n ${gw} ]; then
  120. route del ${vpn} gw ${gw}
  121.  
  122. for i in ${ROUTES}; do
  123. route del -net ${i} gw ${gw}
  124. done
  125. fi
  126.  
  127. fi
  128. return 0
  129. }
  130.  
  131. cleanup_l2tp() {
  132. if [ "${L2TP_BACKEND}" = "xl2tpd" ]; then
  133. start-stop-daemon --stop --quiet --pidfile /var/run/xl2tpd.pid
  134.  
  135. if [ -n "$(pidof xl2tpd)" ]; then
  136. killall -9 xl2tpd > /dev/null 2>&1
  137. fi
  138.  
  139. if [ -e /var/run/xl2tpd.pid ]; then
  140. rm -f /var/run/xl2tpd.pid
  141. fi
  142. else
  143. start-stop-daemon --stop --quiet --pidfile /var/run/openl2tpd.pid
  144.  
  145. if [ -n "$(pidof openl2tpd)" ]; then
  146. killall -9 openl2tpd > /dev/null 2>&1
  147. fi
  148.  
  149. if [ -e /var/run/openl2tpd.pid ]; then
  150. rm -f /var/run/openl2tpd.pid
  151. fi
  152. fi
  153.  
  154. killall pppd > /dev/null 2>&1
  155. if [ -n "$(pidof pppd)" ]; then
  156. killall -9 pppd > /dev/null 2>&1
  157. fi
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement