]> git.ipfire.org Git - people/ms/network.git/blobdiff - header-zone
network: Updated stp framework.
[people/ms/network.git] / header-zone
index 88ed0216e4c013d189ffb36cc57e3480f1f423d1..9407c976f4d03993b5ae5fdf3739f32bc06cfa23 100644 (file)
@@ -60,11 +60,11 @@ function _create() {
        local zone=${1}
        shift
 
-       config_read ${ZONE_DIR}/${zone}/settings
+       config_read $(zone_dir ${zone})/settings
 
        _parse_cmdline $@
 
-       config_write ${ZONE_DIR}/${zone}/settings ${HOOK_SETTINGS}
+       config_write $(zone_dir ${zone})/settings ${HOOK_SETTINGS}
 
        exit ${EXIT_OK}
 }
@@ -113,7 +113,7 @@ function _port() {
        local ret
 
        case "${action}" in
-               create|edit|rem|show)
+               add|create|edit|rem|show)
                        _port_${action} ${zone} $@
                        ret=$?
                        ;;
@@ -126,42 +126,58 @@ function _port() {
        exit ${ret}
 }
 
-# This function is not a public one
-function __portcmd() {
+function _port_add() {
+       _port_cmd add $@
+}
+
+function _port_edit() {
+       _port_cmd edit $@
+}
+
+function _port_rem() {
+       _port_cmd rem $@
+}
+
+function _port_show() {
+       _notimplemented _port_show
+}
+
+function _port_status() {
+       _port_cmd status $@
+}
+
+function _port_cmd() {
        local cmd=${1}
        local zone=${2}
-       local hook_port=${3}
+       local port=${3}
        shift 3
 
+       assert isset cmd
+       assert isset zone
+       assert isset port
+
        local hook_zone=$(zone_get_hook ${zone})
+       local hook_port=$(port_get_hook ${port})
 
-       if ! hook_exists ${hook_zone}; then
-               error "Hook '${hook}' does not exist."
-               exit ${EXIT_ERROR}
-       fi
+       assert isset hook_zone
+       assert isset hook_port
 
-       if ! hook_port_exists ${hook_zone} ${hook_port}; then
-               error "Hook '${hook_port}' is not supported for zone '${zone}'."
+       if ! listmatch ${hook_port} $(zone_get_supported_port_hooks ${zone}); then
+               error_log "Zone '${zone}' does not support port of type '${hook_port}'."
                exit ${EXIT_ERROR}
        fi
 
-       hook_port_exec ${hook_zone} ${hook_port} ${cmd} ${zone} $@
-}
-
-function _port_create() {
-       __portcmd create $@
-}
+       hook_zone_port_exec ${hook_zone} ${hook_port} ${cmd} ${zone} ${port} $@
 
-function _port_edit() {
-       __portcmd edit $@
+       exit $?
 }
 
-function _port_rem() {
-       _notimplemented _port_rem
+function _port_up() {
+       _port_cmd up $@
 }
 
-function _port_show() {
-       _notimplemented _port_show
+function _port_down() {
+       _port_cmd down $@
 }
 
 function _config() {
@@ -194,7 +210,7 @@ function __configcmd() {
 
        local hook_zone=$(zone_get_hook ${zone})
 
-       if ! hook_exists ${hook_zone}; then
+       if ! hook_zone_exists ${hook_zone}; then
                error "Hook '${hook}' does not exist."
                exit ${EXIT_ERROR}
        fi
@@ -204,11 +220,29 @@ function __configcmd() {
                exit ${EXIT_ERROR}
        fi
 
-       hook_config_exec ${hook_zone} ${hook_config} ${cmd} ${zone} $@
+       hook_zone_config_exec ${hook_zone} ${hook_config} ${cmd} ${zone} $@
 }
 
 function _config_create() {
-       __configcmd create $@
+       local zone=${1}
+       local hook_config=${2}
+       shift 2
+
+       assert isset zone
+       assert isset hook_config
+       assert zone_exists ${zone}
+
+       if ! listmatch ${hook_config} $(zone_get_supported_config_hooks ${zone}); then
+               error_log "Zone '${zone}' does not support configuration of type '${hook_config}'."
+               exit ${EXIT_ERROR}
+       fi
+
+       local hook_zone=$(zone_get_hook ${zone})
+       assert isset hook_zone
+
+       hook_zone_config_exec ${hook_zone} ${hook_config} create ${zone} $@
+
+       exit $?
 }
 
 function _config_edit() {
@@ -266,33 +300,33 @@ function _ppp-ip-down() {
 }
 
 function run() {
+       # Replace all dashes by an underscore
+       #action=${action//-/_}
+
        case "${action}" in
+               # Main functions
                create|discover|down|edit|info|rem|status|up)
                        _${action} $@
                        ;;
 
-               port)
-                       if ! hook_has_ports ${HOOK}; then
-                               error "Hook '${HOOK}' does not support ports."
-                               exit ${EXIT_ERROR}
-                       fi
-
-                       _port $@
+               # Port callbacks
+               port_add|port_rem|port_up|port_down|port_status)
+                       _${action} $@
                        ;;
 
-               config)
-                       if ! hook_has_configs ${HOOK}; then
-                               error "Hook '${HOOK}' does not support configurations."
-                               exit ${EXIT_ERROR}
-                       fi
-
-                       _config $@
+               # Configuration callbacks
+               config_create)
+                       _${action} $@
                        ;;
 
+               # ppp daemon callbacks
                ppp-ip-pre-up|ppp-ip-up|ppp-ip-down)
                        _${action} $@
                        ;;
 
+               *)
+                       error "Unknown action: ${action}"
+                       ;;              
        esac
 
        error "Hook did not exit properly."