Merge pull request #5933 from alinnastac/rp-pppoe-improved-init-scripts

rp-pppoe: improve init scripts
This commit is contained in:
Hans Dedecker 2018-04-23 09:50:31 +02:00 committed by GitHub
commit caed4b5132
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 93 additions and 81 deletions

View File

@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=rp-pppoe PKG_NAME:=rp-pppoe
PKG_VERSION:=3.12 PKG_VERSION:=3.12
PKG_RELEASE:=3 PKG_RELEASE:=4
PKG_MAINTAINER:=Daniel Dickinson <lede@cshore.thecshore.com> PKG_MAINTAINER:=Daniel Dickinson <lede@cshore.thecshore.com>
PKG_LICENSE:=LGPL-2.0+ PKG_LICENSE:=LGPL-2.0+

View File

@ -2,28 +2,27 @@
# Copyright (C) 2006-2011 OpenWrt.org # Copyright (C) 2006-2011 OpenWrt.org
START=50 START=50
STOP=50
USE_PROCD=1 USE_PROCD=1
pppoe_triggers() { pppoe_triggers() {
local cfg="$1" local cfg="$1"
local interface server_interfaces client_interfaces both_interfaces local enabled interface server_interfaces client_interfaces both_interfaces
config_get_bool enabled "$cfg" enabled 1
[ "$enabled" -gt 0 ] || return 0
config_get server_interfaces "$cfg" server_interface config_get server_interfaces "$cfg" server_interface
config_get client_interfaces "$cfg" client_interface config_get client_interfaces "$cfg" client_interface
config_get both_interfaces "$cfg" both_interfaces config_get both_interfaces "$cfg" both_interfaces
for interface in $server_interfaces; do for interface in $server_interfaces $client_interfaces $both_interfaces; do
append interfaces "$interface" "|" procd_add_reload_interface_trigger $interface
done
for interface in $client_interfaces; do
append interfaces "$interface" "|"
done
for interface in $both_interfaces; do
append interfaces "$interface" "|"
done done
} }
pppoe_relay_instance() { pppoe_relay_instance() {
local cfg="$1" local cfg="$1"
local interface server_interfaces client_interfaces both_interfaces maxsessions timeout OPTIONS local enabled interface device server_interfaces client_interfaces both_interfaces maxsessions timeout OPTIONS
config_get_bool enabled "$cfg" enabled 1
[ "$enabled" -gt 0 ] || return 0
config_get server_interfaces "$cfg" server_interface config_get server_interfaces "$cfg" server_interface
config_get client_interfaces "$cfg" client_interface config_get client_interfaces "$cfg" client_interface
config_get both_interfaces "$cfg" both_interfaces config_get both_interfaces "$cfg" both_interfaces
@ -34,39 +33,47 @@ pppoe_relay_instance() {
if [ "$use_non_uci_config" -gt 0 ]; then if [ "$use_non_uci_config" -gt 0 ]; then
. /etc/default/pppoe-relay . /etc/default/pppoe-relay
else else
[ -z "${server_interfaces}${client_interfaces}${both_interfaces}" ] && return 1 local NEED_INTFS=SC
. /lib/functions/network.sh
for interface in $server_interfaces; do for interface in $server_interfaces; do
append OPTIONS "-S $interface" if network_get_physdev device $interface; then
append OPTIONS "-S $device"
NEED_INTFS=${NEED_INTFS/S/}
fi
done done
for interface in $client_interfaces; do for interface in $client_interfaces; do
append OPTIONS "-C $interface" if network_get_physdev device $interface; then
append OPTIONS "-C $device"
NEED_INTFS=${NEED_INTFS/C/}
fi
done done
for interface in $both_interfaces; do for interface in $both_interfaces; do
append OPTIONS "-B $interface" if network_get_physdev device $interface; then
append OPTIONS "-B $device"
NEED_INTFS=${NEED_INTFS/?/}
fi
done done
[ -z "${NEED_INTFS}" ] || return 1 # need at least 2 interfaces, one for server(s) and one for client(s)
[ -n "$maxsessions" ] && append OPTIONS "-n $maxsessions" [ -n "$maxsessions" ] && append OPTIONS "-n $maxsessions"
[ -n "$timeout" ] && append OPTIONS "-i $timeout" [ -n "$timeout" ] && append OPTIONS "-i $timeout"
fi fi
procd_open_instance procd_open_instance
procd_set_param command /usr/sbin/pppoe-relay -F procd_set_param command /usr/sbin/pppoe-relay -F $OPTIONS
procd_append_param command $OPTIONS procd_set_param respawn
procd_close_instance procd_close_instance
} }
start_service() { start_service() {
local use_non_uci_config local use_non_uci_config
config_load pppoe config_load pppoe
config_foreach pppoe_relay_instance pppoe_relay config_foreach pppoe_relay_instance pppoe_relay
} }
reload_triggers() { service_triggers() {
local interfaces procd_add_reload_trigger "pppoe"
config_load pppoe config_load pppoe
config_foreach pppoe_triggers pppoe_relay config_foreach pppoe_triggers pppoe_relay
procd_add_reload_trigger "pppoe"
procd_add_interface_trigger "$interfaces"
} }

View File

@ -2,73 +2,78 @@
# Copyright (C) 2006-2011 OpenWrt.org # Copyright (C) 2006-2011 OpenWrt.org
START=50 START=50
STOP=50
USE_PROCD=1 USE_PROCD=1
pppoe_triggers() { pppoe_triggers() {
local cfg="$1" local cfg="$1"
local interface local enabled interface
config_get interface "$cfg" interface config_get_bool enabled "$cfg" enabled 1
[ "$enabled" -gt 0 ] || return 0
config_get interface "$cfg" interface
procd_add_reload_interface_trigger $interface
} }
pppoe_instance() { pppoe_instance() {
local cfg="$1" local cfg="$1"
local interface ac_name service_names service_name maxsessionsperpeer localip firstremoteip maxsessions optionsfiles randomsession unit offset timeout mss sync OPTIONS local enabled interface device ac_name service_names service_name maxsessionsperpeer localip firstremoteip maxsessions optionsfiles randomsession unit offset timeout mss sync OPTIONS
config_get interface "$cfg" interface config_get_bool enabled "$cfg" enabled 1
config_get ac_name "$cfg" ac_name [ "$enabled" -gt 0 ] || return 0
config_get service_names "$cfg" service_name config_get interface "$cfg" interface
config_get maxsessionsperpeer "$cfg" maxsessionsperpeer config_get ac_name "$cfg" ac_name
config_get localip "$cfg" localip config_get service_names "$cfg" service_name
config_get firstremoteip "$cfg" firstremoteip config_get maxsessionsperpeer "$cfg" maxsessionsperpeer
config_get maxsessions "$cfg" maxsessions config_get localip "$cfg" localip
config_get optionsfile "$cfg" optionsfile config_get firstremoteip "$cfg" firstremoteip
config_get_bool randomsession "$cfg" randomsession 1 config_get maxsessions "$cfg" maxsessions
config_get_bool unit "$cfg" unit 0 config_get optionsfile "$cfg" optionsfile
config_get offset "$cfg" offset config_get_bool randomsession "$cfg" randomsession 1
config_get timeout "$cfg" timeout config_get_bool unit "$cfg" unit 0
config_get mss "$cfg" mss config_get offset "$cfg" offset
config_get_bool sync "$cfg" sync 0 config_get timeout "$cfg" timeout
config_get use_non_uci_config "$cfg" use_non_uci_config 0 config_get mss "$cfg" mss
config_get_bool sync "$cfg" sync 0
config_get_bool use_non_uci_config "$cfg" use_non_uci_config 0
if [ "$use_non_uci_config" -gt 0 ]; then if [ "$use_non_uci_config" -gt 0 ]; then
. /etc/default/pppoe-server . /etc/default/pppoe-server
else else
[ -z "$interface" ] && return 1 . /lib/functions/network.sh
[ -n "$ac_name" ] && append OPTIONS "-C $ac_name" network_get_physdev device $interface || return 1
for service_name in $service_names; do [ -n "$ac_name" ] && append OPTIONS "-C $ac_name"
append OPTIONS "-S $service_name" for service_name in $service_names; do
done append OPTIONS "-S $service_name"
append OPTIONS "-I $interface" done
[ -n "$maxsessionsperpeer" ] && append OPTIONS "-x $maxsessionsperpeer" append OPTIONS "-I $device"
[ -n "$localip" ] && append OPTIONS "-L $localip" [ -n "$maxsessionsperpeer" ] && append OPTIONS "-x $maxsessionsperpeer"
[ -n "$firstremoteip" ] && append OPTIONS "-R $firstremoteip" [ -n "$localip" ] && append OPTIONS "-L $localip"
[ -n "maxsessions" ] && append OPTIONS "-N $maxsessions" [ -n "$firstremoteip" ] && append OPTIONS "-R $firstremoteip"
[ -n "optionsfile" ] && append OPTIONS "-O $optionsfile" [ -n "maxsessions" ] && append OPTIONS "-N $maxsessions"
[ "$randomsession" = "1" ] && append OPTIONS "-r" [ -n "optionsfile" ] && append OPTIONS "-O $optionsfile"
[ "$unit" = "1" ] && append OPTIONS "-u" [ "$randomsession" = "1" ] && append OPTIONS "-r"
[ -n "$offset" ] && append OPTIONS "-o $offset" [ "$unit" = "1" ] && append OPTIONS "-u"
[ -n "$timeout" ] && append OPTIONS "-T $timeout" [ -n "$offset" ] && append OPTIONS "-o $offset"
[ -n "$mss" ] && append OPTIONS "-m $mss" [ -n "$timeout" ] && append OPTIONS "-T $timeout"
[ "$sync" = "1" ] && append OPTIONS "-s" [ -n "$mss" ] && append OPTIONS "-m $mss"
fi [ "$sync" = "1" ] && append OPTIONS "-s"
fi
procd_open_instance procd_open_instance
procd_set_param command /usr/sbin/pppoe-server -F procd_set_param command /usr/sbin/pppoe-server -F -k $OPTIONS
procd_append_param command -k $OPTIONS procd_set_param respawn
procd_set_param file /etc/ppp/options procd_set_param file /etc/ppp/options
procd_append_param file /etc/ppp/pppoe-server-options procd_append_param file /etc/ppp/pppoe-server-options
procd_close_instance procd_close_instance
} }
start_service() { start_service() {
config_load pppoe config_load pppoe
config_foreach pppoe_instance pppoe_server config_foreach pppoe_instance pppoe_server
} }
service_triggers() { service_triggers() {
local interface procd_add_reload_trigger "pppoe"
config_load pppoe
config_foreach pppoe_triggers pppoe_server
procd_add_reload_trigger "pppoe" config_load pppoe
procd_add_interface_trigger "$interface" config_foreach pppoe_triggers pppoe_server
} }