]> git.ipfire.org Git - people/stevee/network.git/blobdiff - src/hooks/zones/pppoe
pppoe: Bring up port when zone is coming up
[people/stevee/network.git] / src / hooks / zones / pppoe
index b2d0a950a832ef9a3367d495b977f9e0d646a273..e113c92ea9751198db7d6a9cea58ab488a32da8c 100644 (file)
@@ -38,8 +38,7 @@ ACCESS_CONCENTRATOR=""
 SERVICE_NAME=""
 
 # Maximum Transmission Unit.
-# 1492 is a very common value for that.
-MTU=1492
+MTU=
 
 # This hook can work with all authentication methods supported by pppd.
 PPPOE_SUPPORTED_AUTH_METHODS="${PPP_SUPPORTED_AUTH_METHODS}"
@@ -65,10 +64,10 @@ hook_parse_cmdline() {
        while [ $# -gt 0 ]; do
                case "${1}" in
                        --access-concentrator=*)
-                               ACCESS_CONCENTRATOR=$(cli_get_val ${1})
+                               ACCESS_CONCENTRATOR=$(cli_get_val "${1}")
                                ;;
                        --auth=*)
-                               AUTH=$(cli_get_val ${1})
+                               AUTH=$(cli_get_val "${1}")
                                ;;
                        --ipv6=*)
                                local value="$(cli_get_val "${1}")"
@@ -79,19 +78,19 @@ hook_parse_cmdline() {
                                fi
                                ;;
                        --mtu=*)
-                               MTU=$(cli_get_val ${1})
+                               MTU=$(cli_get_val "${1}")
                                ;;
                        --password=*)
-                               PASSWORD=$(cli_get_val ${1})
+                               PASSWORD=$(cli_get_val "${1}")
                                ;;
                        --prefix-delegation=*)
                                PREFIX_DELEGATION="$(cli_get_bool "${1}")"
                                ;;
                        --service-name=*)
-                               SERVICE_NAME=$(cli_get_val ${1})
+                               SERVICE_NAME=$(cli_get_val "${1}")
                                ;;
                        --username=*)
-                               USERNAME=$(cli_get_val ${1})
+                               USERNAME=$(cli_get_val "${1}")
                                ;;
                        *)
                                warning "Unknown argument: ${1}" >&2
@@ -116,6 +115,9 @@ hook_up() {
 
        zone_settings_read "${zone}"
 
+       # Load the pppoe kernel module
+       module_load "pppoe"
+
        # Bring up the port.
        port_up "${port}"
 
@@ -135,8 +137,11 @@ hook_down() {
        pppd_stop ${zone}
 
        # Bring down the port.
-       log DEBUG "Bringing down port '${PORT}'."
-       port_down ${PORT}
+       local port=$(__hook_get_port "${zone}")
+       if isset port; then
+               log DEBUG "Bringing down port '${port}'"
+               port_down "${port}"
+       fi
 
        exit ${EXIT_OK}
 }
@@ -226,9 +231,12 @@ hook_status() {
        # XXX display time since connection started
 
        cli_headline 2 "Point-to-Point-over-Ethernet protocol"
+       cli_print_fmt1 2 "MAC-Remote"  "$(db_get "${zone}/remote-address")"
+       cli_space
+
        local proto
        for proto in ${IP_SUPPORTED_PROTOCOLS}; do
-               routing_db_exists ${zone} ${proto} || continue
+               db_exists "${zone}/${proto}" || continue
 
                local headline
                case "${proto}" in
@@ -244,11 +252,9 @@ hook_status() {
                esac
                cli_headline 3 "${headline}"
 
-               cli_print_fmt1 3 "IP address"  "$(routing_db_get ${zone} ${proto} local-ip-address)"
-               cli_print_fmt1 3 "Gateway"     "$(routing_db_get ${zone} ${proto} remote-ip-address)"
-               cli_print_fmt1 3 "DNS servers" "$(routing_db_get ${zone} ${proto} dns)"
-               cli_space
-               cli_print_fmt1 3 "MAC-Remote"  "$(routing_db_get ${zone} ${proto} remote-address)"
+               cli_print_fmt1 3 "IP address"  "$(db_get "${zone}/${proto}/local-ip-address")"
+               cli_print_fmt1 3 "Gateway"     "$(db_get "${zone}/${proto}/remote-ip-address")"
+               cli_print_fmt1 3 "DNS servers" "$(db_get "${zone}/${proto}/domain-name-servers")"
                cli_space
        done
 
@@ -357,6 +363,36 @@ hook_port_detach() {
        exit ${EXIT_OK}
 }
 
+hook_port_up() {
+       assert [ $# -eq 2 ]
+
+       local zone="${1}"
+       local port="${2}"
+
+       # Try bringing up the port if it has not been brought up before
+       if ! device_exists "${port}"; then
+               port_create "${port}"
+       fi
+
+       # Make sure that the port is up
+       port_up "${port}"
+
+       exit ${EXIT_OK}
+}
+
+hook_port_down() {
+       assert [ $# -eq 2 ]
+
+       local zone="${1}"
+       local port="${2}"
+
+       if device_exists "${port}"; then
+               port_down "${port}"
+       fi
+
+       exit ${EXIT_OK}
+}
+
 hook_ppp_ipv6_up() {
        local zone="${1}"