Foomatic-Paket.
Nochmal das DSL Script ueberarbeitet und nen kleinen Daemon geschrieben.


git-svn-id: http://svn.ipfire.org/svn/ipfire/trunk@815 ea5c0bd1-69bd-2848-81d8-4f18e57aeed8
This commit is contained in:
ms
2007-08-23 19:52:52 +00:00
parent d36e62412d
commit 905fbf3e06
15 changed files with 5309 additions and 676 deletions

View File

@@ -0,0 +1,90 @@
#!/bin/bash
#
. /etc/sysconfig/rc
. ${rc_functions}
eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings)
MAX=160
ATTEMPTS=0
COUNT=0
if [ ! $HOLDOFF ]; then
HOLDOFF=30
fi
msg_log () {
logger -t $(basename $0)[$$] $*
}
msg_log "Connectd ($1) started with PID $$"
if [ -s "/var/ipfire/red/keepconnected" ]; then
ATTEMPTS=$(cat /var/ipfire/red/keepconnected)
else
echo "0" > /var/ipfire/red/keepconnected
fi
case "$1" in
start)
boot_mesg "Starting connection daemon..."
echo_ok
while [ "$COUNT" -lt "$MAX" ]; do
if [ ! -e "/var/ipfire/red/keepconnected" ]; then
# User pressed disconnect in gui
msg_log "Stopping by user request. Exiting."
/etc/rc.d/init.d/network stop red
exit 0
fi
if [ -e "/var/ipfire/red/active" ]; then
# Successfully connected in time
echo "0" > /var/ipfire/red/keepconnected
msg_log "System is online. Exiting."; exit 0
fi
if ( ! ps ax | grep -q [p]ppd ); then
msg_log "No pppd is running. Trying reconnect."
break # because pppd died
fi
sleep 5
(( COUNT+=1 ))
done
/etc/rc.d/init.d/network stop red
(( ATTEMPTS+=1 ))
msg_log "Reconnecting: Attempt ${ATTEMPTS} of ${MAXRETRIES}"
if [ "${ATTEMPTS}" -ge "${MAXRETRIES}" ]; then
echo "0" > /var/ipfire/red/keepconnected
if [ "$BACKUPPROFILE" != '' ]; then
rm -f /var/ipfire/ppp/settings
cp "/var/ipfire/ppp/settings-${BACKUPPROFILE}" /var/ipfire/ppp/settings
msg_log "Switched to backup profile ${BACKUPPROFILE}"
else
msg_log "No backup profile given. Exiting."
exit 0
fi
else
echo $ATTEMPTS > /var/ipfire/red/keepconnected
sleep ${HOLDOFF}
fi
/etc/rc.d/init.d/network start red &
;;
reconnect)
while ( ps ax | grep -q [p]ppd ); do
sleep 2
done
/etc/rc.d/init.d/network restart red &
;;
*)
echo "Usage: $0 {start|reconnect}"
exit 1
;;
esac
msg_log "Exiting gracefully connectd with PID $$."

View File

@@ -1,121 +0,0 @@
#!/bin/bash
#
eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings)
# MAXRETRIES is now a count before red clear and if reconnection fail, eventually switching to a backup profil
MAXCONFIGURE=160
if [ ! $HOLDOFF ]; then
HOLDOFF=30
fi
# Debugging. Comment it out to stop logging
DEBUG="yes"
msg() {
if [ "z$DEBUG" != "z" ] ; then
/usr/bin/logger -t red "Connectioncheck: $*"
fi
/bin/echo "$*"
}
if [ -s "/var/ipfire/red/keepconnected" ]; then
ATTEMPTS=$(/bin/cat /var/ipfire/red/keepconnected)
else
echo "0" > /var/ipfire/red/keepconnected
fi
case "$1" in
start)
# waiting pppd start or sync timout set at 90 s when available in driver
# So just wait 5 s after 'red start' end where pppd should have been started
TIMETOSTART=0
while ( ! /bin/ps ax | /bin/grep -q [p]ppd ); do
if [ ! -e "/var/ipfire/red/keepconnected" ]; then
# user pressed disconnect in gui
exit 0
fi
RCREDSTART=`/bin/ps ax | /bin/grep 'red start'`
if [ "$TIMETOSTART" -eq 1 ]; then
msg "fail before pppd start : no sync, trying again"
/etc/rc.d/init.d/network restart red
exit
fi
# give 5 s more at pppd to be visible with ps ax after 'red start' end
if [ "$RCREDSTART" = '' ]; then
TIMETOSTART=1
fi
/bin/sleep 5
done
#watching if an IP is received in $MAXCONFIGURE time to avoid some pppoa waiting forever even after LCP timeout
COUNT=0
while [ "$COUNT" -le "$MAXCONFIGURE" ]; do
if [ ! -e "/var/ipfire/red/keepconnected" ]; then
# user pressed disconnect in gui
exit 0
fi
if [ -e "/var/ipfire/red/active" ]; then
# connected in time so exit
echo "0" > /var/ipfire/red/keepconnected
exit 0
fi
if [ -e "/var/ipfire/red/dial-on-demand" ]; then
# Don't count time when dial-on-demand is not really connected
if ( ! /sbin/ifconfig | /bin/grep -q addr:10.64.64.64 ); then
(( COUNT += 5 ))
fi
else
(( COUNT += 5 ))
fi
if ( ! /bin/ps ax | /bin/grep -q [p]ppd ); then
#pppd exit, so don't need to wait MAXCONFIGURE
break
fi
/bin/sleep 5
done
msg "RED fail to connect"
RCREDSTART=`/bin/ps ax | /bin/grep 'red start' | /usr/bin/cut -f1 -d ' '`
if [ "$RCREDSTART" != '' ]; then
/bin/kill "$RCREDSTART"
fi
# this attempt to connect fail, so retry
#Don't erase keepconnected because it is used to watch user actions
/usr/bin/touch /var/ipfire/red/redial
/etc/rc.d/init.d/network stop red
while ( /bin/ps ax | /bin/grep -q [p]ppd ); do
msg "waiting pppd exit"
/bin/sleep 2
done
/bin/sleep $HOLDOFF
if [ ! -e "/var/ipfire/red/keepconnected" ]; then
# user pressed disconnect in gui
exit 0
fi
(( ATTEMPTS += 1 ))
msg "Restarting $ATTEMPTS/$MAXRETRIES"
if [ "$ATTEMPTS" -ge "$MAXRETRIES" ]; then
echo "0" > /var/ipfire/red/keepconnected
msg "Clearing RED interface"
/etc/rc.d/init.d/network stop red
if [ "$BACKUPPROFILE" != '' ]; then
/bin/rm -f /var/ipfire/ppp/settings
/bin/cp "/var/ipfire/ppp/settings-$BACKUPPROFILE" /var/ipfire/ppp/settings
fi
else
echo $ATTEMPTS > /var/ipfire/red/keepconnected
fi
/etc/rc.d/init.d/network start red
;;
reconnect)
while ( /bin/ps ax | /bin/grep -q [p]ppd ); do
/bin/sleep 2
done
msg "will connect again"
/etc/rc.d/init.d/network start red
;;
*)
/bin/echo "Usage: $0 {start|reconnect}"
exit 1
;;
esac

View File

@@ -149,6 +149,7 @@ case "$1" in
# filtering from GUI
/sbin/iptables -N GUIINPUT
/sbin/iptables -A INPUT -j GUIINPUT
/sbin/iptables -A GUIINPUT -p icmp --icmp-type 8 -j ACCEPT
# Accept everything connected
/sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

View File

@@ -680,8 +680,8 @@ log_warning_msg() {
}
run_subdir() {
$DIR=$1
for i in $( ls -v ${DIR}* 2> /dev/null); do
DIR=$1
for i in $(ls -v ${DIR}* 2> /dev/null); do
check_script_status
OUT=$(echo $(basename ${i}) | awk -F- '{ print $2 }')
case "$OUT" in
@@ -690,7 +690,7 @@ run_subdir() {
RS) ${i} restart ;;
RL) ${i} reload ;;
U) ${i} up ;;
D) ${i] down ;;
D) ${i} down ;;
*) ${i} ;;
esac
done

View File

@@ -143,70 +143,104 @@ case "${1}" in
fi
elif [ "$TYPE" == "PPPOE" ]; then
eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings)
boot_mesg "Bringing up the PPPoE interface on ${DEVICE}..."
ip addr add 1.1.1.1/24 broadcast 1.1.1.255 dev ${DEVICE}
PPPOECONF=/etc/ppp/pppoe.conf
echo > $PPPOECONF #clear
[ -c "/dev/ppp" ] || mknod /dev/ppp c 108 0
if [ "${METHOD}" != "PPPOE_PLUGIN" ]; then
echo "LINUX_PLUGIN=" >> $PPPOECONF
else
echo "LINUX_PLUGIN=/usr/lib/pppd/2.4.4/rp-pppoe.so" >> $PPPOECONF
fi
echo "ETH=${DEVICE}" >> $PPPOECONF
echo "USER=${USERNAME}" >> $PPPOECONF
echo "PPPOE_TIMEOUT=80" >> $PPPOECONF
#echo "PPPD_EXTRA=\"-U\"" >> $PPPOECONF
#echo "PPPOE_EXTRA=\"-m ${MTU}\"" >> $PPPOECONF
### ###
### Configuring the pppd ###
### ###
### Plugin Options
#
[ "${METHOD}" == "PPPOE_PLUGIN" ] && \
PLUGOPTS="plugin /usr/lib/pppd/2.4.4/rp-pppoe.so nic-${DEVICE}"
if [ -n ${SERVICENAME} ]; then
echo "SERVICENAME=${SERVICENAME}" >> $PPPOECONF
### Synchronous Mode
#
#PPPOE_SYNC=-s
#PPPD_SYNC=sync
### Access Concentrator Name
#
if [ -n "${CONCENTRATORNAME}" ]; then
ACNAME="-C ${CONCENTRATORNAME}"
fi
if [ -n ${CONCENTRATORNAME} ]; then
echo "ACNAME=${CONCENTRATORNAME}" >> $PPPOECONF
### Service Name
#
if [ -n "${SERVICENAME}" ]; then
if [ "${METHOD}" == "PPPOE_PLUGIN" ]; then
PLUGOPTS+=" rp_pppoe_service ${SERVICENAME}"
else
SERVICENAME="-S ${SERVICENAME}"
fi
fi
if [ "${DNS}" == "Automatic" ]; then
echo "PEERDNS=yes" >> $PPPOECONF
echo "DNSTYPE=NOCHANGE" >> $PPPOECONF
fi
### Authentication Types
#
if [ "${AUTH}" == "pap" ]; then
PPPD_EXTRA+="-chap "
AUTH="-chap"
elif [ "${AUTH}" == "chap" ]; then
PPPD_EXTRA+="-pap "
AUTH="-pap"
fi
echo "FIREWALL=NONE" >> $PPPOECONF
### Dial On Demand
#
if [ "${RECONNECTION}" != "persistent" ]; then
if [ "${TIMEOUT}" != "0" ] && [ "${TIMEOUT}" != "" ]; then
SECONDS=$[${TIMEOUT} * 60]
else
SECONDS=300
fi
if [ "${RECONNECTION}" == "dialondemand" ]; then
touch /var/ipfire/red/dial-on-demand
echo "DEMAND=${SECONDS}" >> $PPPOECONF
DEMAND="demand persist idle ${SECONDS} 10.112.112.112:10.112.112.113"
DEMAND+=" ipcp-accept-remote ipcp-accept-local connect true noipdefault ktune"
fi
else
echo "DEMAND=no" >> $PPPOECONF
fi
echo "LCP_INTERVAL=20" >> $PPPOECONF
echo "LCP_FAILURE=3" >> $PPPOECONF
echo "PIDFILE=/var/run/ppp-ipfire.pid" >> $PPPOECONF
#ARGS+=" maxfail ${MAXRETRIES}"
### When using plugin the device has to be the last option
#
[ "${METHOD}" == "PPPOE_PLUGIN" ] && PLUGOPTS+=" ${DEVICE}"
### Standard PPP options we always use
#
PPP_STD_OPTIONS="$PLUGOPTS usepeerdns defaultroute noipdefault noauth"
PPP_STD_OPTIONS+=" default-asyncmap hide-password nodetach mtu ${MTU}"
PPP_STD_OPTIONS+=" mru ${MTU} noaccomp nodeflate nopcomp novj novjccomp"
PPP_STD_OPTIONS+=" nobsdcomp user ${USERNAME} lcp-echo-interval 20"
PPP_STD_OPTIONS+=" lcp-echo-failure 3 ${AUTH}"
[ "${METHOD}" != "PPPOE_PLUGIN" ] && [ "${DEBUG}" == "on" ] && export DEBUG=1
/usr/sbin/pppoe-start
evaluate_retval
### Debugging
#
if [ "${DEBUG}" == "on" ]; then
DEBUG="debug"
else
DEBUG=""
fi
### PPPoE invocation
#
PPPOE_CMD="/usr/sbin/pppoe -p /var/run/ppp-ipfire.pid.pppoe -I ${DEVICE}"
PPPOE_CMD+=" -T 80 -U $PPPOE_SYNC $ACNAME $SERVICENAMEOPT"
### Run everything
#
if [ "${METHOD}" == "PPPOE_PLUGIN" ]; then
/usr/sbin/pppd $PPP_STD_OPTIONS $DEBUG $DEMAND >/dev/null 2>&1 &
evaluate_retval
else
/usr/sbin/pppd pty "$PPPOE_CMD" $PPP_STD_OPTIONS $DEBUG $DEMAND $PPPD_SYNC >/dev/null 2>&1 &
evaluate_retval
fi
/etc/rc.d/init.d/connectd start
fi
;;
@@ -254,9 +288,8 @@ case "${1}" in
elif [ "$TYPE" == "PPPOE" ]; then
boot_mesg "Bringing down the PPPoE interface on ${DEVICE}..."
/usr/sbin/pppoe-stop
evaluate_retval
killproc /usr/sbin/pppd
ip addr del 1.1.1.1/24 broadcast 1.1.1.255 dev ${DEVICE}
fi