]> git.ipfire.org Git - people/ms/network.git/commitdiff
hotplug: Return port name for a device.
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 May 2011 15:11:22 +0000 (15:11 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 May 2011 15:11:22 +0000 (15:11 +0000)
functions.cli
functions.device
functions.ports
header-port
hooks/ports/ethernet
network

index 82a9c6f4a0edf7077df726d6bc5192bb396669ec..411188da899269e18917c9cbf42fe7f4434a7e74 100644 (file)
@@ -151,6 +151,27 @@ function cli_hostname() {
        exit ${EXIT_OK}
 }
 
+function cli_hotplug() {
+       if cli_help_requested $@; then
+               cli_usage root-hotplug
+               exit ${EXIT_OK}
+       fi
+
+       local command=${1}
+       shift
+
+       case "${command}" in
+               device)
+                       device_hotplug $@
+                       exit $?
+                       ;;
+               *)
+                       cli_usage root-hotplug
+                       exit ${EXIT_OK}
+                       ;;
+       esac
+}
+
 function cli_port() {
        if cli_help_requested $@; then
                cli_usage root-port
index 1ddc7d2c9d9b34349dbb29fd1e3d87fdd93ec69a..7367f642b7de3dbcafcc9ce8ec6b711fa660da6f 100644 (file)
@@ -549,3 +549,27 @@ function device_get_tx_errors() {
 
        __device_get_file ${device} statistics/tx_errors
 }
+
+function device_hotplug() {
+       local device=${1}
+       shift
+
+       assert isset device
+       #assert device_exists ${device}
+
+       if ! device_is_free ${device}; then
+               log ERROR "The device '${device}' does not look to be unused."
+               log ERROR "Don't proceed."
+       #       return ${EXIT_ERROR}
+       fi
+
+       for port in $(ports_get_all); do
+               port_cmd hotplug ${port} ${device}
+               if [ $? -eq ${EXIT_OK} ]; then
+                       echo "${port}"
+                       exit ${EXIT_OK}
+               fi
+       done
+
+       exit ${EXIT_ERROR}
+}
index 9cda5641e4fd618f0a11d918c1848c62b7684d36..8aa4cac19eb6f27af17707035bf865e85b4ddb03 100644 (file)
@@ -23,6 +23,16 @@ function port_dir() {
        echo "${CONFIG_DIR}/ports"
 }
 
+function ports_get_all() {
+       local port
+
+       for port in $(port_dir)/*; do
+               [ -f "${port}" ] || continue
+
+               basename ${port}
+       done
+}
+
 function port_file() {
        local port=${1}
 
index 95b39d0e62007d17f22e2347d8709d27b6a2792f..bb319a4fec4f13141ba94cb038c8f25781d8fe2a 100644 (file)
@@ -40,7 +40,7 @@ done
 
 function run() {
        case "${action}" in
-               edit|add|create|rem|up|down|status|info)
+               edit|add|create|rem|up|down|status|info|hotplug)
                        _${action} $@
                        ;;
        esac
@@ -49,6 +49,10 @@ function run() {
        exit ${EXIT_ERROR}
 }
 
+function _hotplug() {
+       exit ${EXIT_ERROR}
+}
+
 function _info() {
        local port=${1}
        shift
index 2d49f49aee17d553dc11ac4c69260b92128da319..cf37aa05cf78d25ee9970172f5b38efc69d464c2 100755 (executable)
@@ -60,6 +60,22 @@ function _down() {
        exit ${EXIT_OK}
 }
 
+function _hotplug() {
+       local port=${1}
+       local device=${2}
+
+       assert isset port
+       assert isset device
+
+       config_read $(port_file ${port})
+
+       if [ "${DEVICE_MAC}" = "$(device_get_address ${device})" ]; then
+               exit ${EXIT_OK}
+       fi
+
+       exit ${EXIT_ERROR}
+}
+
 function _status() {
        local port=${1}
        shift
diff --git a/network b/network
index e84adff9e953eefbb9675a7681995f0031af6bc7..54ad808657b0ced0813894489ddcc3d10ea39043 100755 (executable)
--- a/network
+++ b/network
@@ -42,7 +42,7 @@ case "${action}" in
                init_run
                ;;
 
-       config|hostname|port|device|zone|start|stop|restart|status|reset)
+       config|hostname|hotplug|port|device|zone|start|stop|restart|status|reset)
                cli_${action} $@
                ;;