summaryrefslogtreecommitdiffstats
path: root/src/lib/connections/pppoe
blob: 981665817645b6a773383b2370491e88afb59694 (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
# Contributed by: Thomas Bächler <thomas@archlinux.org>

: ${PPPD:=pppd}

quote_word() {
    set -- "${@//\\/\\\\}"
    printf '"%s"\n' "${@//\"/\\\"}"
}

pppoe_up() {
    local options="$STATE_DIR/pppoe.$Interface.$Profile/options"

    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 "$(dirname "$options")"
    cat >> "$options" << EOF
linkname $(quote_word "$Profile")
${PPPUnit:+unit $(quote_word "$PPPUnit")}
updetach
plugin rp-pppoe.so
nic-$Interface

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)

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
}

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

    if [[ -r $pidfile ]]; then
        read pid < "$pidfile"
        (( pid )) && kill "$pid"
    fi

    rm "$options"
    rmdir "$(dirname "$options")"

    bring_interface_down "$Interface"
}


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