summaryrefslogtreecommitdiffstats
path: root/src/lib/connections/pppoe
blob: 65fee796e2c65dcd97fd17c2c88cfedb481a4f02 (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
75
76
77
78
79
80
81
82
# Contributed by: Thomas Bächler <thomas@archlinux.org>

: ${PPPD:=pppd}

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"
    echo "linkname $(quote_word "${Profile}")" > "${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 "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}"

    if ! $PPPD file "${cfg}"; then
        rm "${cfg}"
        rmdir "$STATE_DIR/pppoe.${Interface}.${Profile}/"
        report_error "Couldn't make pppd connection."
        return 1
    fi
}

pppoe_down() {
    local cfg pidfile pid
    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}/"

    bring_interface_down "$Interface"
}


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