]> git.ipfire.org Git - people/stevee/network.git/blobdiff - src/hooks/zones/pppoe
Remove remains of the "real" device type
[people/stevee/network.git] / src / hooks / zones / pppoe
old mode 100755 (executable)
new mode 100644 (file)
index ee89346..b201ebe
@@ -22,7 +22,7 @@
 . /usr/lib/network/header-zone
 
 HOOK_SETTINGS="HOOK ACCESS_CONCENTRATOR AUTH USERNAME PASSWORD"
-HOOK_SETTINGS="${HOOK_SETTINGS} SERVICE_NAME MTU PORT IPV6 PREFIX_DELEGATION"
+HOOK_SETTINGS="${HOOK_SETTINGS} SERVICE_NAME MTU IPV6 PREFIX_DELEGATION"
 
 # User credentials for the dialin.
 USERNAME=""
@@ -31,9 +31,6 @@ PASSWORD=""
 # Set the authentication mechanism.
 AUTH=
 
-# The physical ethernet port the modem is connected to.
-PORT=""
-
 # Access Concentrator.
 ACCESS_CONCENTRATOR=""
 
@@ -60,10 +57,6 @@ function hook_check() {
 
        isset AUTH && assert isoneof AUTH ${PPPOE_SUPPORTED_AUTH_METHODS}
 
-       # Check for a valid port setting.
-       assert isset PORT
-       assert port_exists ${PORT}
-
        assert isset IPV6
        assert isset PREFIX_DELEGATION
 }
@@ -91,9 +84,6 @@ function hook_parse_cmdline() {
                        --password=*)
                                PASSWORD=$(cli_get_val ${1})
                                ;;
-                       --port=*)
-                               PORT=$(cli_get_val ${1})
-                               ;;
                        --prefix-delegation=*)
                                PREFIX_DELEGATION="$(cli_get_bool "${1}")"
                                ;;
@@ -115,11 +105,11 @@ function hook_up() {
        local zone=${1}
        assert isset zone
 
-       zone_config_read ${zone}
+       zone_settings_read "${zone}" ${HOOK_SETTINGS}
 
        # Bring up the port.
-       log DEBUG "Bringing up port '${PORT}'."
-       port_up ${PORT}
+       local port=$(__hook_get_port "${zone}")
+       port_up "${port}"
 
        # Start the ppp daemon.
        pppd_start ${zone}
@@ -131,7 +121,7 @@ function hook_down() {
        local zone=${1}
        assert isset zone
 
-       zone_config_read ${zone}
+       zone_settings_read "${zone}" ${HOOK_SETTINGS}
 
        # Stop the ppp daemon.
        pppd_stop ${zone}
@@ -146,7 +136,8 @@ function hook_down() {
 function hook_discover() {
        local device=${1}
 
-       if [ "$(device_get_type ${device})" != "real" ]; then
+       # This obviously only works on ethernet (or compatible) devices
+       if ! device_is_ethernet_compatible "${device}"; then
                exit ${EXIT_ERROR}
        fi
 
@@ -179,12 +170,16 @@ function hook_status() {
 
        cli_device_headline ${zone}
 
-       zone_config_read ${zone}
+       zone_settings_read "${zone}" ${HOOK_SETTINGS}
 
        cli_headline 2 "Configuration"
        cli_print_fmt1 2 "Username" "${USERNAME}"
        cli_print_fmt1 2 "Password" "<hidden>"
-       cli_print_fmt1 2 "Port" "${PORT}"
+
+       local port=$(__hook_get_port "${zone}")
+       if isset port; then
+               cli_print_fmt1 2 "Port" "${port}"
+       fi
        cli_space
 
        # Exit if zone is down
@@ -233,7 +228,14 @@ function hook_ppp_write_config() {
        assert isset file
 
        # Read in the configuration files.
-       zone_config_read ${zone}
+       zone_settings_read "${zone}" ${HOOK_SETTINGS}
+
+       # A port has to be assigned for this action
+       local port=$(__hook_get_port "${zone}")
+       if ! isset port; then
+               error "No port assigned to pppoe hook of zone '${zone}'"
+               exit ${EXIT_ERROR}
+       fi
 
        # Prepare the command line options for the pppoe plugin.
        local plugin_options
@@ -249,7 +251,7 @@ function hook_ppp_write_config() {
        fi
 
        # The last argument must be the interface.
-       plugin_options="${plugin_options} ${PORT}"
+       plugin_options="${plugin_options} ${port}"
 
        pppd_write_config ${file} \
                --interface="${zone}" \
@@ -264,3 +266,53 @@ function hook_ppp_write_config() {
 
        exit ${EXIT_OK}
 }
+
+function __hook_get_port() {
+       local zone="${1}"
+
+       local port
+       for port in $(zone_get_ports "${zone}"); do
+               echo "${port}"
+               return ${EXIT_OK}
+       done
+
+       return ${EXIT_ERROR}
+}
+
+function hook_port_add() {
+       # Excepting at least two arguments here
+       assert [ $# -ge 2 ]
+
+       local zone="${1}"
+       local port="${2}"
+       shift 2
+
+       # PPPoE can only use one port
+       local ports_num="$(zone_get_ports_num "${zone}")"
+       if [ ${ports_num} -ge 1 ]; then
+               local port=$(__hook_get_port "${zone}")
+               error "The pppoe zone hook only supports assigning one port"
+               error "  port '${port}' has already been assigned to zone '${zone}'"
+               return ${EXIT_ERROR}
+       fi
+
+       zone_port_settings_write "${zone}" "${port}"
+       log INFO "Port '${port}' has been added to zone '${zone}'"
+
+       exit ${EXIT_OK}
+}
+
+function hook_port_remove() {
+       assert [ $# -eq 2 ]
+
+       local zone="${1}"
+       local port="${2}"
+
+       # Shut down the port (if possible)
+       port_down "${port}"
+
+       log INFO "Port '${port}' has been removed from zone '${zone}'"
+       zone_port_settings_remove "${zone}" "${port}"
+
+       exit ${EXIT_OK}
+}