OpenSDE Packages Database (without history before r20070)
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.

166 lines
5.3 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: package/.../ppp/rocknet_ppp.sh
  5. # Copyright (C) 2004 - 2006 The T2 SDE Project
  6. #
  7. # More information can be found in the files COPYING and README.
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; version 2 of the License. A copy of the
  12. # GNU General Public License can be found in the file COPYING.
  13. # --- SDE-COPYRIGHT-NOTE-END ---
  14. ppp_option() {
  15. local optfile=$1
  16. local opt=$2 ; shift 2
  17. case $opt in
  18. hide-password|show-password) optx="hide-password|show-password" ;;
  19. refuse-chap|require-chap) optx="refuse-chap|require-chap" ;;
  20. refuse-mschap|require-mschap) optx="refuse-mschap|require-mschap" ;;
  21. refuse-mschap-v2|require-mschap-v2) optx="refuse-mschap-v2|require-mschap-v2" ;;
  22. refuse-eap|require-eap) optx="refuse-eap|require-eap" ;;
  23. refuse-pap|require-pap) optx="refuse-pap|require-pap" ;;
  24. require-mppe|nomppe) optx="require-mppe|nomppe" ;;
  25. require-mppe-40|nomppe-40) optx="require-mppe-40|nomppe-40" ;;
  26. require-mppe-128|nomppe-128) optx="require-mppe-128|nomppe-128" ;;
  27. noauth|auth) optx="noauth|auth" ;;
  28. nobsdcomp|bsdcomp) optx="nobsdcomp|bsdcomp" ;;
  29. nocrtscts|crtscts) optx="nocrtscts|crtscts" ;;
  30. nocdtrcts|cdtrcts) optx="nocdtrcts|cdtrcts" ;;
  31. nodefaultroute|defaultroute) optx="nodefaultroute|defaultroute" ;;
  32. nodeflate|deflate) optx="nodeflate|deflate" ;;
  33. noendpoint|endpoint) optx="noendpoint|endpoint" ;;
  34. noipv6|ipv6) optx="noipv6|ipv6" ;;
  35. noipx|ipx) optx="noipx|ipx" ;;
  36. noktune|ktune) optx="noktune|ktune" ;;
  37. nomp|mp) optx="nomp|mp" ;;
  38. nomppe-stateful|mppe-stateful) optx="nomppe-stateful|mppe-stateful" ;;
  39. nompshortseq|mpshortseq) optx="nompshortseq|mpshortseq" ;;
  40. nomultilink|multilink) optx="nomultilink|multilink" ;;
  41. nopersist|persist) optx="nopersist|persist" ;;
  42. nopredictor1|predictor1) optx="nopredictor1|predictor1" ;;
  43. noproxyarp|proxyarp) optx="noproxyarp|proxyarp" ;;
  44. novj|vj) optx="novj|vj" ;;
  45. *) optx="$opt" ;;
  46. esac
  47. if egrep "^($optx) .*" $optfile 1>/dev/null 2>/dev/null; then
  48. optx="`echo $optx | sed 's,|,\\\\|,g'`"
  49. sed -i "s,^\($optx\) .*,$opt $*," $optfile
  50. else
  51. echo "$opt $*" >> $optfile
  52. fi
  53. }
  54. chat_init_if() {
  55. if isfirst "chat_$if" ; then
  56. addcode up 4 1 "echo -n > \$ppp_${if}_chat"
  57. addcode up 4 6 "ppp_option \$ppp_${if}_config \
  58. connect \'chat -v -s -f \$ppp_${if}_chat\'"
  59. fi
  60. }
  61. # PUBLIC COMMANDS ###########################################################
  62. # pppoe ppp-interface [config file|auto] [ppp-command-line-arg [...]]
  63. public_ppp() {
  64. # config file
  65. eval "ppp_${if}_config=$rocknet_tmp_base/ppp_${if}_options"
  66. eval "ppp_${if}_chat=$rocknet_tmp_base/ppp_${if}_chat"
  67. # get unit from $if
  68. ppp_unit=${if#ppp}
  69. # parse args
  70. ppp_if=$1 ; shift
  71. local ppp_args="`echo $* | sed 's,",\\\\",g'`"
  72. addcode up 4 1 "echo -n > \$ppp_${if}_config"
  73. addcode up 4 2 "chmod 0600 \$ppp_${if}_config"
  74. ppp_command="/usr/sbin/pppd file \$ppp_${if}_config $ppp_if"
  75. ppp_command="$ppp_command unit $ppp_unit"
  76. ppp_command="$ppp_command $ppp_args"
  77. if [ "$CANUSESERVICE" == "1" ]; then
  78. addcode up 5 1 "service_create $if 'ip link set $ppp_if down up
  79. exec `eval echo $ppp_command` nodetach' \
  80. '[ -f /var/run/$if.pid ] && rm -f /var/run/$if.pid'"
  81. addcode down 5 1 "service_destroy $if"
  82. else
  83. addcode up 6 2 "$ppp_command"
  84. addcode down 5 5 "[ -f /var/run/$if.pid ] && kill -TERM \`head -n 1 /var/run/$if.pid\`"
  85. addcode down 5 4 "[ -f /var/run/$if.pid ] && rm -f /var/run/$if.pid"
  86. fi
  87. }
  88. public_pppoe() {
  89. addcode up 4 5 "ppp_option \$ppp_${if}_config plugin rp-pppoe.so"
  90. addcode up 4 5 "ppp_option \$ppp_${if}_config mru 1492"
  91. addcode up 4 5 "ppp_option \$ppp_${if}_config mtu 1492"
  92. if [ "$CANUSESERVICE" != "1" ]; then
  93. addcode up 5 1 "ip link set $ppp_if up"
  94. fi
  95. }
  96. public_ppp_defaults() {
  97. local each
  98. for each in noipdefault noauth hide-password \
  99. ipcp-accept-local ipcp-accept-remote \
  100. defaultroute usepeerdns ; do
  101. addcode up 4 4 "ppp_option \$ppp_${if}_config $each"
  102. done
  103. }
  104. public_ppp_speed_defaults() {
  105. local each
  106. for each in default-asyncmap noaccomp nobsdcomp nodeflate nopcomp \
  107. novj novjccomp ktune ; do
  108. addcode up 4 4 "ppp_option \$ppp_${if}_config $each"
  109. done
  110. addcode up 4 5 "ppp_option \$ppp_${if}_config lcp-echo-interval 20"
  111. addcode up 4 5 "ppp_option \$ppp_${if}_config lcp-echo-failure 3"
  112. }
  113. public_ppp_option() {
  114. local param="`echo $* | sed 's,",\\\\",g'`"
  115. addcode up 4 6 "ppp_option \$ppp_${if}_config $param"
  116. }
  117. public_ppp_on_demand() {
  118. addcode up 4 6 "ppp_option \$ppp_${if}_config demand"
  119. addcode up 4 6 "ppp_option \$ppp_${if}_config idle $1"
  120. addcode up 4 6 "ppp_option \$ppp_${if}_config persist"
  121. }
  122. public_chat_defaults() {
  123. chat_init_if
  124. addcode up 4 1 "echo 'ABORT \"NO CARRIER\"
  125. ABORT \"NO DIALTONE\"
  126. ABORT \"ERROR\"
  127. ABORT \"NO ANSWER\"
  128. ABORT \"BUSY\"
  129. \"\" \"at\"' >> \$ppp_${if}_chat"
  130. }
  131. public_chat_init() {
  132. chat_init_if
  133. # don't ask and count ...
  134. opts="`echo "$@" | sed -e 's/"/\\\\\\\\\\\\\"/g' \
  135. -e 's/&/\\\\\\&/g'`"
  136. addcode up 4 3 "echo '\"OK\" \"$opts\"' >> \$ppp_${if}_chat"
  137. }
  138. public_chat_dial() {
  139. chat_init_if
  140. # don't ask and count ...
  141. opts="`echo "$@" | sed 's/"/\\\\\\\\\\\\\"/g'`"
  142. addcode up 4 5 "echo -e '\"OK\" \"$opts\"\n\"CONNECT\" \"\"' >> \$ppp_${if}_chat"
  143. }