summaryrefslogtreecommitdiffstats
path: root/src/lib/connections/pppoe
blob: 2578af7335298819a427177ff8a7312bd6b99cca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Contributed by: Thomas Bächler <thomas@archlinux.org>

: ${PPPD:=pppd}

_quotestring() {
    echo "\"${1/\"/\\\"}\""
}

pppoe_up() {
    local cfg

    mkdir -p "$STATE_DIR/pppoe.${Interface}.$1/"
    chmod 700 "$STATE_DIR/pppoe.${Interface}.${Profile}/"
    cfg="$STATE_DIR/pppoe.${Interface}.${Profile}/options"
    : > "${cfg}"
    chmod 600 "${cfg}"

    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 "linkname $(_quotestring "${Profile}")" >> "${cfg}"
    echo "maxfail 5" >> "${cfg}"
    echo "updetach" >> "${cfg}"
    if [[ ${ConnectionMode} == demand ]]; then
        echo "demand" >> "${cfg}"
        echo "idle ${IdleTimeout}" >> "${cfg}"
    else
        echo "persist" >> "${cfg}"
    fi
    echo "user $(_quotestring "${User}")" >> "${cfg}"
    echo "password $(_quotestring "${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}"
    [[ ${PPPoEIP6} == yes ]] && echo "+ipv6" >> "${cfg}"

    ip link set dev "${Interface}" up
    $PPPD file "${cfg}"

    if [[ $? -ne 0 ]]; then
        rm "${cfg}"
        rmdir "$STATE_DIR/pppoe.${Interface}.${Profile}/"
        report_error "Couldn't make pppd connection."
        return 1
    fi
}

pppoe_down() {
    local cfg
    cfg="$STATE_DIR/pppoe.${Interface}.${Profile}/options"
    PIDFILE="/var/run/ppp-${Profile}.pid"

    if [[ -e $PIDFILE ]]; then
        read PID < "$PIDFILE"
        [[ "$PID" ]] && kill "$PID"
    fi

    rm "${cfg}"
    rmdir "$STATE_DIR/pppoe.${Interface}.${Profile}/"
}


# vim: ft=sh ts=4 et sw=4: