summaryrefslogtreecommitdiffstats
path: root/src/lib/connections/pppoe
diff options
context:
space:
mode:
authorJouke Witteveen <j.witteveen@gmail.com>2013-04-18 09:14:08 +0200
committerJouke Witteveen <j.witteveen@gmail.com>2013-04-18 09:14:08 +0200
commite95c9680e0632d835a1786a74c1d2bb2fc5b4a60 (patch)
treef77638a0edf689fd78a42766c049f20fe106d214 /src/lib/connections/pppoe
parente1ae4c56483ee2664a5448a305019b43f1b10ad9 (diff)
downloadnetctl-e95c9680e0632d835a1786a74c1d2bb2fc5b4a60.tar.gz
netctl-e95c9680e0632d835a1786a74c1d2bb2fc5b4a60.tar.xz
Small review of PPP related connections
The most important change is that we now bring the interface down correctly in pppoe_down.
Diffstat (limited to 'src/lib/connections/pppoe')
-rw-r--r--src/lib/connections/pppoe46
1 files changed, 27 insertions, 19 deletions
diff --git a/src/lib/connections/pppoe b/src/lib/connections/pppoe
index d392397..177f575 100644
--- a/src/lib/connections/pppoe
+++ b/src/lib/connections/pppoe
@@ -2,17 +2,27 @@
: ${PPPD:=pppd}
-_quotestring() {
- echo "\"${1/\"/\\\"}\""
+quote_word() {
+ set -- "${@//\\/\\\\}"
+ printf '"%s"\n' "${@/\"/\\\"}"
}
pppoe_up() {
local cfg
+ if ! is_interface "$Interface"; then
+ report_error "Interface '$Interface' does not exist"
+ return 1
+ fi
+ if ! bring_interface_up "$Interface"; then
+ report_error "Failed to bring interface '$Interface' 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"
- : > "${cfg}"
+ echo "linkname $(quote_word "${Profile}")" > "${cfg}"
chmod 600 "${cfg}"
echo "plugin rp-pppoe.so" >> "${cfg}"
@@ -26,7 +36,6 @@ pppoe_up() {
if is_yes "${UsePeerDNS:-yes}"; then
echo "usepeerdns" >> "${cfg}"
fi
- echo "linkname $(_quotestring "${Profile}")" >> "${cfg}"
echo "maxfail 5" >> "${cfg}"
echo "updetach" >> "${cfg}"
if [[ ${ConnectionMode} == demand ]]; then
@@ -35,20 +44,17 @@ pppoe_up() {
else
echo "persist" >> "${cfg}"
fi
- echo "user $(_quotestring "${User}")" >> "${cfg}"
- echo "password $(_quotestring "${Password}")" >> "${cfg}"
+ 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 $(_quotestring "${PPPoEService}")" >> "${cfg}"
- [[ -n ${PPPoEAC} ]] && echo "rp_pppoe_ac $(_quotestring "${PPPoEAC}")" >> "${cfg}"
- [[ -n ${PPPoESession} ]] && echo "rp_pppoe_sess $(_quotestring "${PPPoESession}")" >> "${cfg}"
- [[ -n ${PPPoEMAC} ]] && echo "pppoe-mac $(_quotestring "${PPPoEMAC}")" >> "${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}"
- ip link set dev "${Interface}" up
- $PPPD file "${cfg}"
-
- if [[ $? -ne 0 ]]; then
+ if ! $PPPD file "${cfg}"; then
rm "${cfg}"
rmdir "$STATE_DIR/pppoe.${Interface}.${Profile}/"
report_error "Couldn't make pppd connection."
@@ -57,17 +63,19 @@ pppoe_up() {
}
pppoe_down() {
- local cfg
+ local cfg pidfile pid
cfg="$STATE_DIR/pppoe.${Interface}.${Profile}/options"
- PIDFILE="/var/run/ppp-${Profile}.pid"
+ pidfile="/var/run/ppp-${Profile}.pid"
- if [[ -e $PIDFILE ]]; then
- read PID < "$PIDFILE"
- [[ "$PID" ]] && kill "$PID"
+ if [[ -e $pidfile ]]; then
+ read pid < "$pidfile"
+ [[ "$pid" ]] && kill "$pid"
fi
rm "${cfg}"
rmdir "$STATE_DIR/pppoe.${Interface}.${Profile}/"
+
+ bring_interface_down "$Interface"
}