mirror of the now-defunct rocklinux.org
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.

120 lines
4.3 KiB

  1. # FIXME: /tmp/.rocknet or such a directory should go to base.sh?
  2. ppp_config_path=/tmp/.rocknet/ppp
  3. [ -d $ppp_config_path ] || mkdir -p $ppp_config_path
  4. # ppp_option <file> ppp-option [...] - add "ppp-option [...]" to the config file
  5. # specified by <file>
  6. ppp_option() {
  7. local optfile=$1
  8. local opt=$2 ; shift 2
  9. case $opt in
  10. hide-password|show-password) optx="hide-password|show-password" ;;
  11. refuse-chap|require-chap) optx="refuse-chap|require-chap" ;;
  12. refuse-mschap|require-mschap) optx="refuse-mschap|require-mschap" ;;
  13. refuse-mschap-v2|require-mschap-v2) optx="refuse-mschap-v2|require-mschap-v2" ;;
  14. refuse-eap|require-eap) optx="refuse-eap|require-eap" ;;
  15. refuse-pap|require-pap) optx="refuse-pap|require-pap" ;;
  16. require-mppe|nomppe) optx="require-mppe|nomppe" ;;
  17. require-mppe-40|nomppe-40) optx="require-mppe-40|nomppe-40" ;;
  18. require-mppe-128|nomppe-128) optx="require-mppe-128|nomppe-128" ;;
  19. noauth|auth) optx="noauth|auth" ;;
  20. nobsdcomp|bsdcomp) optx="nobsdcomp|bsdcomp" ;;
  21. nocrtscts|crtscts) optx="nocrtscts|crtscts" ;;
  22. nocdtrcts|cdtrcts) optx="nocdtrcts|cdtrcts" ;;
  23. nodefaultroute|defaultroute) optx="nodefaultroute|defaultroute" ;;
  24. nodeflate|deflate) optx="nodeflate|deflate" ;;
  25. noendpoint|endpoint) optx="noendpoint|endpoint" ;;
  26. noipv6|ipv6) optx="noipv6|ipv6" ;;
  27. noipx|ipx) optx="noipx|ipx" ;;
  28. noktune|ktune) optx="noktune|ktune" ;;
  29. nomp|mp) optx="nomp|mp" ;;
  30. nomppe-stateful|mppe-stateful) optx="nomppe-stateful|mppe-stateful" ;;
  31. nompshortseq|mpshortseq) optx="nompshortseq|mpshortseq" ;;
  32. nomultilink|multilink) optx="nomultilink|multilink" ;;
  33. nopersist|persist) optx="nopersist|persist" ;;
  34. nopredictor1|predictor1) optx="nopredictor1|predictor1" ;;
  35. noproxyarp|proxyarp) optx="noproxyarp|proxyarp" ;;
  36. novj|vj) optx="novj|vj" ;;
  37. *) optx="$opt" ;;
  38. esac
  39. if egrep "^($optx) .*" $optfile 1>/dev/null 2>/dev/null; then
  40. optx="`echo $optx | sed 's,|,\\\\|,g'`"
  41. sed -i "s,^\($optx\) .*,$opt $*," $optfile
  42. else
  43. echo "$opt $*" >> $optfile
  44. fi
  45. }
  46. # pppoe_config_defaults - create default settings, the respective config file
  47. # is \$ppp_${if}_config
  48. pppoe_config_defaults() {
  49. local each
  50. for each in noipdefault noauth default-asyncmap hide-password noaccomp nobsdcomp \
  51. ipcp-accept-local ipcp-accept-remote \
  52. nodeflate nopcomp novj novjccomp ktune; do
  53. addcode up 4 4 "ppp_option \$ppp_${if}_config $each"
  54. done
  55. addcode up 4 5 "ppp_option \$ppp_${if}_config mru 1492"
  56. addcode up 4 5 "ppp_option \$ppp_${if}_config mtu 1492"
  57. addcode up 4 5 "ppp_option \$ppp_${if}_config lcp-echo-interval 20"
  58. addcode up 4 5 "ppp_option \$ppp_${if}_config lcp-echo-failure 3"
  59. addcode up 4 6 "ppp_option \$ppp_${if}_config ipcp-accept-remote"
  60. addcode up 4 6 "ppp_option \$ppp_${if}_config ipcp-accept-local"
  61. }
  62. # PUBLIC COMMANDS ###########################################################
  63. # pppoe ppp-interface [config file|auto] [ppp-command-line-arg [...]]
  64. public_pppoe() {
  65. # default config file
  66. eval "ppp_${if}_config=$ppp_config_path/option.$if"
  67. addcode up 4 3 "echo -n > \$ppp_${if}_config"
  68. # get unit from $if
  69. ppp_unit=${if#ppp}
  70. # parse args
  71. local ppp_if=$1 ; shift
  72. local ppp_args=
  73. # <config file> or "auto" present?
  74. case $1 in
  75. auto)
  76. pppoe_config_defaults
  77. eval "ppp_args=\"$ppp_args${ppp_args+ }file \$ppp_${if}_config\""
  78. shift
  79. ;;
  80. /*)
  81. eval "ppp_${if}_config=$1"
  82. eval "ppp_args=\"$ppp_args${ppp_args+ }file \$ppp_${if}_config\""
  83. shift
  84. ;;
  85. esac
  86. # user or password info should not be world readable...
  87. addcode up 4 3 "chmod 0600 \$ppp_${if}_config"
  88. ppp_args="$ppp_args${ppp_args+ }`echo $* | sed 's,",\\\\",g'`"
  89. # final config codes
  90. addcode up 5 1 "ip link set $ppp_if down up"
  91. addcode up 5 2 "/usr/sbin/pppd plugin rp-pppoe.so $ppp_if unit $ppp_unit $ppp_args"
  92. addcode down 5 2 "[ -f /var/run/$if.pid ] && kill -TERM \`head -n 1 /var/run/$if.pid\`"
  93. addcode down 5 1 "[ -f /var/run/$if.pid ] && rm -f /var/run/$if.pid"
  94. }
  95. # ppp-option ppp-option [...]
  96. public_ppp_option() {
  97. local param="`echo $* | sed 's,",\\\\",g'`"
  98. addcode up 4 6 "ppp_option \$ppp_${if}_config $param"
  99. }
  100. # ppp-on-demand <idle time in seconds>
  101. public_ppp_on_demand() {
  102. addcode up 4 6 "ppp_option \$ppp_${if}_config demand"
  103. addcode up 4 6 "ppp_option \$ppp_${if}_config idle $1"
  104. addcode up 4 6 "ppp_option \$ppp_${if}_config persist"
  105. }