]> git.ipfire.org Git - people/ms/network.git/commitdiff
ports: Make a generic hook_new function
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 15 Aug 2017 21:02:44 +0000 (21:02 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 15 Aug 2017 21:02:44 +0000 (21:02 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/header-port
src/hooks/ports/wireless-ap

index 238749e61442be68138be3e0d8ca7512737be363..9fd2503abdc932c9ae9e935318271e95b2cc5319 100644 (file)
@@ -40,8 +40,23 @@ hook_hotplug_rename() {
        exit ${EXIT_FALSE}
 }
 
-hook_add() {
-       cmd_not_implemented
+hook_default_new() {
+       if ! hook_parse_cmdline "$@"; then
+               return ${EXIT_ERROR}
+       fi
+
+       assert isset HOOK_PORT_PATTERN
+
+       local port=$(port_find_free ${HOOK_PORT_PATTERN})
+       assert isset port
+
+       port_settings_write "${port}" ${HOOK_SETTINGS}
+
+       exit ${EXIT_OK}
+}
+
+hook_new() {
+       hook_default_new "$@"
 }
 
 hook_default_edit() {
@@ -115,6 +130,7 @@ hook_default_up() {
        done
 }
 
+# Depends on the port existing
 hook_up() {
        hook_default_up $@
 }
index 9c77bb13f3779a204451721bce2c6dceb95140f0..9c0375cc80bf32f266ad5f85ababc0f0dab45728 100644 (file)
@@ -21,6 +21,8 @@
 
 . /usr/lib/network/header-port
 
+HOOK_PORT_PATTERN="${PORT_PATTERN_ACCESSPOINT}"
+
 HOOK_SETTINGS="HOOK ADDRESS BROADCAST_SSID CHANNEL MODE PHY SSID"
 HOOK_SETTINGS="${HOOK_SETTINGS} ENCRYPTION KEY"
 
@@ -92,19 +94,6 @@ hook_parse_cmdline() {
        PHY=$(phy_get_address ${PHY})
 }
 
-hook_new() {
-       if ! hook_parse_cmdline $@; then
-               return ${EXIT_ERROR}
-       fi
-
-       local port=$(port_find_free ${PORT_PATTERN_ACCESSPOINT})
-       assert isset port
-
-       port_settings_write "${port}" ${HOOK_SETTINGS}
-
-       exit ${EXIT_OK}
-}
-
 hook_edit() {
        local port=${1}
        assert isset port