summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/connections/mobile_ppp118
-rw-r--r--src/lib/connections/pppoe90
2 files changed, 79 insertions, 129 deletions
diff --git a/src/lib/connections/mobile_ppp b/src/lib/connections/mobile_ppp
index b966390..5006c6c 100644
--- a/src/lib/connections/mobile_ppp
+++ b/src/lib/connections/mobile_ppp
@@ -11,18 +11,14 @@ quote_word() {
}
mobile_ppp_up() {
- local cfg
- local chat
-
- mkdir -p "$STATE_DIR/mobile_ppp.${Interface}.${Profile}/"
- chmod 700 "$STATE_DIR/mobile_ppp.${Interface}.${Profile}/"
- cfg="$STATE_DIR/mobile_ppp.${Interface}.${Profile}/options"
+ local options chat
+ options="$STATE_DIR/mobile_ppp.${Interface}.${Profile}/options"
chat="$STATE_DIR/mobile_ppp.${Interface}.${Profile}/modem.chat"
- echo "linkname $(quote_word "${Profile}")" > "${cfg}"
- chmod 600 "${cfg}"
- cat >> "${cfg}" << EOF
-${Interface}
+ mkdir -p "$(dirname "$options")"
+ cat >> "$options" << EOF
+linkname $(quote_word "$Profile")
+$(quote_word "$Interface")
921600
lock
crtscts
@@ -30,61 +26,19 @@ modem
passive
novj
holdoff 10
-maxfail ${MaxFail:-5}
-EOF
-
- # Debug pppd output separately from netctl
- if is_yes "${PPPDebug:-yes}"; then
- echo "debug" >> "${cfg}"
- fi
-
- # Sets up route
- if is_yes "${DefaultRoute:-yes}"; then
- echo "defaultroute" >> "${cfg}"
- else
- echo "nodefaultroute" >> "${cfg}"
- fi
- if is_yes "${UsePeerDNS:-yes}"; then
- echo "usepeerdns" >> "${cfg}"
- fi
- # Writes username and password
- echo "noauth" >> "${cfg}"
- echo "hide-password" >> ${cfg}
- [[ -n ${User} ]] && echo "user $(quote_word "${User}")" >> "${cfg}"
- [[ -n ${Password} ]] && echo "password $(quote_word "${Password}")" >> "${cfg}"
-
- #echo "'OK' @/etc/ppp/chatscripts/pin" >> "${chat}"
- if [ -n "${Pin}" ]; then
- PinStr="'OK' 'AT+CPIN=\"${Pin}\"'"
- else
- PinStr="'OK' 'AT'"
- fi
- report_debug echo $PinStr
-
- # Mode can be one of 3Gpref, 3Gonly, GPRSpref, GPRSonly, None
- # Only works for Huawei modems
- #echo "'OK' @/etc/ppp/chatscripts/mode" >> "${chat}"
- case "${Mode}" in
- 3Gonly)
- ModeStr="'OK' 'AT\^SYSCFG=14,2,3fffffff,0,1'"
- ;;
- 3Gpref)
- ModeStr="'OK' 'AT\^SYSCFG=2,2,3fffffff,0,1'"
- ;;
- GPRSonly)
- ModeStr="'OK' 'AT\^SYSCFG=13,1,3fffffff,0,0'"
- ;;
- GPRSpref)
- ModeStr="'OK' 'AT\^SYSCFG=2,1,3fffffff,0,0'"
- ;;
- *)
- ModeStr="'OK' 'AT'"
- ;;
- esac
+noauth
+$(is_yes "${DefaultRoute:-yes}" || printf no)defaultroute
+maxfail $(quote_word "${MaxFail:-5}")
+$(is_yes "${UsePeerDNS:-yes}" && printf usepeerdns)
+hide-password
+${User:+user $(quote_word "$User")}
+${Password:+password $(quote_word "$Password")}
+connect $(quote_word "/usr/sbin/chat -v -t15 -f $(quote_word "$chat")")
+${OptionsFile:+file $(quote_word "$OptionsFile")}
+EOF
- # Now that we’ve got the ppp configuration set up, write the chat script
- cat >> "${chat}" << EOF
+ cat >> "$chat" << EOF
ECHO ON
ABORT 'BUSY'
ABORT 'NO CARRIER'
@@ -100,40 +54,40 @@ TIMEOUT 6
'OK-AT-OK' 'ATZ'
TIMEOUT 3
'OK' 'AT+CFUN=1'
-${PinStr}
+'OK' 'AT${Pin:++CPIN=$(quote_word "$Pin")}'
'OK\d-AT-OK' 'ATI'
'OK' 'ATZ'
'OK' 'ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0'
-${ModeStr}
-'OK-AT-OK' 'AT+CGDCONT=1,"IP","${AccessPointName}"'
+'OK' 'AT$(case $Mode in
+ 3Gonly) printf "\^SYSCFG=14,2,3fffffff,0,1";;
+ 3Gpref) printf "\^SYSCFG=2,2,3fffffff,0,1";;
+ GPRSonly) printf "\^SYSCFG=13,1,3fffffff,0,0";;
+ GPRSpref) printf "\^SYSCFG=2,1,3fffffff,0,0";;
+esac)'
+'OK-AT-OK' 'AT+CGDCONT=1,"IP",$(quote_word "$AccessPointName")'
'OK' 'ATDT*99#'
TIMEOUT 30
CONNECT ''
EOF
- # Add the chat script line to the configuration
- echo "connect \"/usr/sbin/chat -v -t15 -f ${chat}\"" >> "${cfg}"
-
- if ! $PPPD file "${cfg}"; then
- rmdir "$STATE_DIR/mobile_ppp.${Interface}.${Profile}/"
- report_error "Couldn't make pppd connection."
+ if ! $PPPD file "$options"; then
+ rm "$options" "$chat"
+ rmdir "$(dirname "$options")"
+ report_error "Could not establish a ppp connection for profile '$Profile'."
return 1
fi
}
mobile_ppp_down() {
- local cfg chat pidfile pid
- cfg="$STATE_DIR/mobile_ppp.${Interface}.${Profile}/options"
- chat="$STATE_DIR/mobile_ppp.${Interface}.${Profile}/modem.chat"
- pidfile="/var/run/ppp-${Profile}.pid"
+ local options chat pidfile
+ options="$STATE_DIR/mobile_ppp.$Interface.$Profile/options"
+ chat="$STATE_DIR/mobile_ppp.$Interface.$Profile/modem.chat"
+ pidfile="/var/run/ppp-$Profile.pid"
- if [[ -e $pidfile ]]; then
- read pid < "$pidfile"
- [[ "$pid" ]] && kill "$pid"
- fi
+ [[ -r $pidfile ]] && kill "$(< "$pidfile")"
- rm "${cfg}" "${chat}"
- rmdir "$STATE_DIR/mobile_ppp.${Interface}.${Profile}/"
+ rm "$options" "$chat"
+ rmdir "$(dirname "$options")"
}
diff --git a/src/lib/connections/pppoe b/src/lib/connections/pppoe
index 65fee79..78cc35f 100644
--- a/src/lib/connections/pppoe
+++ b/src/lib/connections/pppoe
@@ -8,7 +8,9 @@ quote_word() {
}
pppoe_up() {
- local cfg
+ local options pidfile pppn
+ options="$STATE_DIR/pppoe.$Interface.$Profile/options"
+ pidfile="/var/run/ppp-$Profile.pid"
if ! is_interface "$Interface"; then
report_error "Interface '$Interface' does not exist"
@@ -19,61 +21,55 @@ pppoe_up() {
return 1
fi
- mkdir -p "$STATE_DIR/pppoe.${Interface}.${Profile}/"
- chmod 700 "$STATE_DIR/pppoe.${Interface}.${Profile}/"
- cfg="$STATE_DIR/pppoe.${Interface}.${Profile}/options"
- echo "linkname $(quote_word "${Profile}")" > "${cfg}"
- chmod 600 "${cfg}"
+ mkdir -p "$(dirname "$options")"
+ cat >> "$options" << EOF
+linkname $(quote_word "$Profile")
+${PPPUnit:+unit $(quote_word "$PPPUnit")}
+updetach
+plugin rp-pppoe.so
+nic-$Interface
- echo "plugin rp-pppoe.so" >> "${cfg}"
- echo "nic-${Interface}" >> "${cfg}"
- echo "noauth" >> "${cfg}"
- if is_yes "${DefaultRoute:-yes}"; then
- echo "defaultroute" >> "${cfg}"
- else
- echo "nodefaultroute" >> "${cfg}"
- fi
- if is_yes "${UsePeerDNS:-yes}"; then
- echo "usepeerdns" >> "${cfg}"
- fi
- echo "maxfail ${MaxFail:-5}" >> "${cfg}"
- echo "updetach" >> "${cfg}"
- if [[ ${ConnectionMode} == demand ]]; then
- echo "demand" >> "${cfg}"
- echo "idle ${IdleTimeout}" >> "${cfg}"
- else
- echo "persist" >> "${cfg}"
- fi
- echo "user $(quote_word "${User}")" >> "${cfg}"
- echo "password $(quote_word "${Password}")" >> "${cfg}"
- [[ -n ${LCPEchoInterval} ]] && echo "lcp-echo-interval ${LCPEchoInterval}" >> "${cfg}"
- [[ -n ${LCPEchoFailure} ]] && echo "lcp-echo-failure ${LCPEchoFailure}" >> "${cfg}"
- [[ -n ${PPPoEService} ]] && echo "rp_pppoe_service $(quote_word "${PPPoEService}")" >> "${cfg}"
- [[ -n ${PPPoEAC} ]] && echo "rp_pppoe_ac $(quote_word "${PPPoEAC}")" >> "${cfg}"
- [[ -n ${PPPoESession} ]] && echo "rp_pppoe_sess $(quote_word "${PPPoESession}")" >> "${cfg}"
- [[ -n ${PPPoEMAC} ]] && echo "pppoe-mac $(quote_word "${PPPoEMAC}")" >> "${cfg}"
- [[ ${PPPoEIP6} == yes ]] && echo "+ipv6" >> "${cfg}"
+noauth
+$(is_yes "${DefaultRoute:-yes}" || printf no)defaultroute
+maxfail $(quote_word "${MaxFail:-5}")
+$(is_yes "${UsePeerDNS:-yes}" && printf usepeerdns)
+$(quote_word "${ConnectionMode:-persist}")
+$([[ $ConnectionMode == demand ]] && printf "idle %s" "$(quote_word "$IdleTimeout")")
+${LCPEchoInterval:+lcp-echo-interval $(quote_word "$LCPEchoInterval")}
+${LCPEchoFailure:+lcp-echo-failure $(quote_word "$LCPEchoFailure")}
+${PPPoEService:+rp_pppoe_service $(quote_word "$PPPoEService")}
+${PPPoEAC:+rp_pppoe_ac $(quote_word "$PPPoEAC")}
+${PPPoESession:+rp_pppoe_sess $(quote_word "$PPPoESession")}
+${PPPoEMAC:+pppoe-mac $(quote_word "$PPPoEMAC")}
+$(is_yes "${PPPoEIP6:-no}" && printf +ipv6)
+$(is_yes "${PPPoEIP6:-yes}" || printf noipv6)
- if ! $PPPD file "${cfg}"; then
- rm "${cfg}"
- rmdir "$STATE_DIR/pppoe.${Interface}.${Profile}/"
- report_error "Couldn't make pppd connection."
+user $(quote_word "$User")
+password $(quote_word "$Password")
+${OptionsFile:+file $(quote_word "$OptionsFile")}
+EOF
+
+ if ! $PPPD file "$options"; then
+ rm "$options"
+ rmdir "$(dirname "$options")"
+ report_error "Could not establish a ppp connection for profile '$Profile'."
return 1
fi
+
+ [[ -r $pidfile ]] || return 0
+ pppn=$(grep -l "$(< "$pidfile")" /var/run/ppp[[:digit:]]*.pid)
+ report_notice "PPP unit for profile '$Profile': ${pppn:9:-4}"
}
pppoe_down() {
- local cfg pidfile pid
- cfg="$STATE_DIR/pppoe.${Interface}.${Profile}/options"
- pidfile="/var/run/ppp-${Profile}.pid"
+ local options pidfile
+ options="$STATE_DIR/pppoe.$Interface.$Profile/options"
+ pidfile="/var/run/ppp-$Profile.pid"
- if [[ -e $pidfile ]]; then
- read pid < "$pidfile"
- [[ "$pid" ]] && kill "$pid"
- fi
+ [[ -r $pidfile ]] && kill "$(< "$pidfile")"
- rm "${cfg}"
- rmdir "$STATE_DIR/pppoe.${Interface}.${Profile}/"
+ rm "$options"
+ rmdir "$(dirname "$options")"
bring_interface_down "$Interface"
}