Fixed two bugs related to interface allocation.

Allocated interfaces were being identified with indexes in intervals of two.
Reidentification failures were potentially not being detected.
This commit is contained in:
Matias Barcenas 2018-05-03 18:30:56 -05:00
parent 53087e6907
commit c288943f66
1 changed files with 22 additions and 5 deletions

View File

@ -871,11 +871,15 @@ fluxion_allocate_interface() { # Reserve interfaces
# Prevent interface-snatching by renaming the interface. # Prevent interface-snatching by renaming the interface.
if [ $allocatingWirelessInterface ]; then if [ $allocatingWirelessInterface ]; then
interface_reidentify $identifier fluxwl${#FluxionInterfaces[@]} # Get next wireless interface to add to FluxionInterfaces global.
fluxion_next_assignable_interface fluxwl
else else
interface_reidentify $identifier fluxet${#FluxionInterfaces[@]} # Get next ethernet interface to add to FluxionInterfaces global.
fluxion_next_assignable_interface fluxet
fi fi
interface_reidentify $identifier $FluxionNextAssignableInterface
if [ $? -ne 0 ]; then # If reidentifying failed, abort immediately. if [ $? -ne 0 ]; then # If reidentifying failed, abort immediately.
return 4 return 4
fi fi
@ -900,12 +904,12 @@ fluxion_allocate_interface() { # Reserve interfaces
) )
else else
# Attempt activating monitor mode on the interface. # Attempt activating monitor mode on the interface.
if interface_set_mode fluxwl${#FluxionInterfaces[@]} monitor; then if interface_set_mode $FluxionNextAssignableInterface monitor; then
# Register the new identifier upon consecutive successes. # Register the new identifier upon consecutive successes.
local -r newIdentifier=fluxwl${#FluxionInterfaces[@]} local -r newIdentifier=$FluxionNextAssignableInterface
else else
# If monitor-mode switch fails, undo rename and abort. # If monitor-mode switch fails, undo rename and abort.
interface_reidentify fluxwl${#FluxionInterfaces[@]} $identifier interface_reidentify $FluxionNextAssignableInterface $identifier
fi fi
fi fi
fi fi
@ -930,6 +934,19 @@ fluxion_allocate_interface() { # Reserve interfaces
# as the key for the global FluxionInterfaces hash/map/dictionary. # as the key for the global FluxionInterfaces hash/map/dictionary.
} }
# Parameters: <interface_prefix>
# Description: Prints next available assignable interface name.
# ------------------------------------------------------------ #
fluxion_next_assignable_interface() {
# Find next available interface by checking global.
readonly prefix=$1
local index=0
while [ "${FluxionInterfaces[$prefix$index]}" ]; do
let index++
done
FluxionNextAssignableInterface="$prefix$index"
}
# Parameters: <interfaces:lambda> [<query>] # Parameters: <interfaces:lambda> [<query>]
# Note: The interfaces lambda must print an interface per line. # Note: The interfaces lambda must print an interface per line.
# ------------------------------------------------------------ # # ------------------------------------------------------------ #