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.

79 lines
2.4 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2006-2011 OpenWrt.org
  3. START=50
  4. STOP=50
  5. USE_PROCD=1
  6. pppoe_triggers() {
  7. local cfg="$1"
  8. local enabled interface server_interfaces client_interfaces both_interfaces
  9. config_get_bool enabled "$cfg" enabled 1
  10. [ "$enabled" -gt 0 ] || return 0
  11. config_get server_interfaces "$cfg" server_interface
  12. config_get client_interfaces "$cfg" client_interface
  13. config_get both_interfaces "$cfg" both_interfaces
  14. for interface in $server_interfaces $client_interfaces $both_interfaces; do
  15. procd_add_reload_interface_trigger $interface
  16. done
  17. }
  18. pppoe_relay_instance() {
  19. local cfg="$1"
  20. local enabled interface device server_interfaces client_interfaces both_interfaces maxsessions timeout OPTIONS
  21. config_get_bool enabled "$cfg" enabled 1
  22. [ "$enabled" -gt 0 ] || return 0
  23. config_get server_interfaces "$cfg" server_interface
  24. config_get client_interfaces "$cfg" client_interface
  25. config_get both_interfaces "$cfg" both_interfaces
  26. config_get maxsessions "$cfg" maxsessions
  27. config_get timeout "$cfg" timeout
  28. config_get_bool use_non_uci_config "$cfg" use_non_uci_config 0
  29. if [ "$use_non_uci_config" -gt 0 ]; then
  30. . /etc/default/pppoe-relay
  31. else
  32. local NEED_INTFS=SC
  33. . /lib/functions/network.sh
  34. for interface in $server_interfaces; do
  35. if network_get_physdev device $interface; then
  36. append OPTIONS "-S $device"
  37. NEED_INTFS=${NEED_INTFS/S/}
  38. fi
  39. done
  40. for interface in $client_interfaces; do
  41. if network_get_physdev device $interface; then
  42. append OPTIONS "-C $device"
  43. NEED_INTFS=${NEED_INTFS/C/}
  44. fi
  45. done
  46. for interface in $both_interfaces; do
  47. if network_get_physdev device $interface; then
  48. append OPTIONS "-B $device"
  49. NEED_INTFS=${NEED_INTFS/?/}
  50. fi
  51. done
  52. [ -z "${NEED_INTFS}" ] || return 1 # need at least 2 interfaces, one for server(s) and one for client(s)
  53. [ -n "$maxsessions" ] && append OPTIONS "-n $maxsessions"
  54. [ -n "$timeout" ] && append OPTIONS "-i $timeout"
  55. fi
  56. procd_open_instance
  57. procd_set_param command /usr/sbin/pppoe-relay -F $OPTIONS
  58. procd_set_param respawn
  59. procd_close_instance
  60. }
  61. start_service() {
  62. local use_non_uci_config
  63. config_load pppoe
  64. config_foreach pppoe_relay_instance pppoe_relay
  65. }
  66. service_triggers() {
  67. procd_add_reload_trigger "pppoe"
  68. config_load pppoe
  69. config_foreach pppoe_triggers pppoe_relay
  70. }