Fixed allocated interface inconsistency bug.

The bug caused the interface allocation subroutine to generate an error when attemping to allocate an interface that had already been allocated rather than gracefully returning, signifying the interface already exists in the allocation table.
The interface selector subroutine wasn't masking already allocated interfaces, causing an issue when attemping to reallocate in series (back-to-back).
This commit is contained in:
Matias Barcenas 2018-01-08 23:50:10 -06:00
parent 2aefa3bb22
commit 98f3d2b7ea
1 changed files with 35 additions and 21 deletions

52
fluxion
View File

@ -623,17 +623,25 @@ function fluxion_deallocate_interface() { # Release interfaces
unset FluxionInterfaces[$newIdentifier] unset FluxionInterfaces[$newIdentifier]
} }
# Parameters: <interface_identifier>
# ------------------------------------------------------------ #
# Return 1: No interface identifier was passed.
# Return 2: Interface identifier given points to no interface.
# Return 3: Unable to determine interface's driver.
# Return 4: Fluxion failed to reidentify interface.
# Return 5: Interface allocation failed (identifier missing).
function fluxion_allocate_interface() { # Reserve interfaces function fluxion_allocate_interface() { # Reserve interfaces
if [ ! "$1" ] || ! interface_is_real $1; then return 1; fi if [ ! "$1" ]; then return 1; fi
local -r identifier=$1 local -r identifier=$1
# If the interface is already in allocation table, return it. # If the interface is already in allocation table, we're done.
if [ "${FluxionInterfaces[$identifier]+x}" ]; then if [ "${FluxionInterfaces[$identifier]+x}" ]; then
FluxionInterface=${FluxionInterfaces[$identifier]}
return 0 return 0
fi fi
if ! interface_is_real $identifier; then return 2; fi
echo -e "$FLUXIONVLine $FLUXIONAllocatingInterfaceNotice" echo -e "$FLUXIONVLine $FLUXIONAllocatingInterfaceNotice"
if interface_is_wireless $identifier; then if interface_is_wireless $identifier; then
@ -648,7 +656,7 @@ function fluxion_allocate_interface() { # Reserve interfaces
if ! interface_driver "$identifier"; then if ! interface_driver "$identifier"; then
echo -e "$FLUXIONVLine$CRed $FLUXIONUnknownWIDriverError" echo -e "$FLUXIONVLine$CRed $FLUXIONUnknownWIDriverError"
sleep 3 sleep 3
return 2 return 3
fi fi
# Notice: This local is function-scoped, not block-scoped. # Notice: This local is function-scoped, not block-scoped.
@ -706,7 +714,7 @@ function fluxion_allocate_interface() { # Reserve interfaces
fi fi
if [ $? -ne 0 ] # If reidentifying failed, abort immediately. if [ $? -ne 0 ] # If reidentifying failed, abort immediately.
then return 3 then return 4
fi fi
fi fi
@ -740,7 +748,7 @@ function fluxion_allocate_interface() { # Reserve interfaces
if [ ! "$newIdentifier" -o "$newIdentifier" = "$oldIdentifier" ]; then if [ ! "$newIdentifier" -o "$newIdentifier" = "$oldIdentifier" ]; then
echo -e "$FLUXIONVLine $FLUXIONInterfaceAllocationFailedError" echo -e "$FLUXIONVLine $FLUXIONInterfaceAllocationFailedError"
sleep 3 sleep 3
return 4 return 5
fi fi
# Register identifiers to allocation hash table. # Register identifiers to allocation hash table.
@ -770,13 +778,19 @@ function fluxion_get_interface() {
local interfacesAvailableState=() local interfacesAvailableState=()
# Gather information from all available interfaces. # Gather information from all available interfaces.
local interfaceCandidate local -r interfacesAvailableCount=${#interfacesAvailable[@]}
for interfaceCandidate in "${interfacesAvailable[@]}"; do
local i
for (( i = 0; i < interfacesAvailableCount; i++ )); do
local interfaceCandidate=${interfacesAvailable[i]}
interface_chipset "$interfaceCandidate" interface_chipset "$interfaceCandidate"
interfacesAvailableInfo+=("$InterfaceChipset") interfacesAvailableInfo+=("$InterfaceChipset")
# If it has already been allocated, we can use it at will. # If it has already been allocated, we can use it at will.
if [ ${FluxionInterfaces["$interfaceCandidate"]} ]; then local interfaceCandidateAlt=${FluxionInterfaces["$interfaceCandidate"]}
if [ "$interfaceCandidateAlt" ]; then
interfacesAvailable[$i]=$interfaceCandidateAlt
interfacesAvailableColor+=("$CGrn") interfacesAvailableColor+=("$CGrn")
interfacesAvailableState+=("[*]") interfacesAvailableState+=("[*]")
else else
@ -1337,19 +1351,22 @@ while [ "$1" != "--" ]; do
-t|--target) echo "Not yet implemented!"; sleep 3; fluxion_shutdown;; -t|--target) echo "Not yet implemented!"; sleep 3; fluxion_shutdown;;
--test) --test)
while true; do while true; do
if ! fluxion_get_interface subtest1; then fluxion_get_interface subtest1
echo Failed to get interface with code $? result=$?
if [ $result -ne 0 ]; then
echo Failed to get interface with code $result
exit exit
fi fi
if ! fluxion_allocate_interface "$FluxionInterfaceSelected"; then fluxion_allocate_interface "$FluxionInterfaceSelected"
echo Failed to allocate "$FluxionInterfaceSelected" with code $? result=$?
if [ $result -ne 0 ]; then
echo Failed to allocate "$FluxionInterfaceSelected" with code $result
exit exit
else fi
interfaceA=${FluxionInterfaces["$FluxionInterfaceSelected"]} interfaceA=${FluxionInterfaces["$FluxionInterfaceSelected"]}
echo "Allocated $FluxionInterfaceSelected -> $interfaceA" echo "Allocated $FluxionInterfaceSelected -> $interfaceA"
fi
fluxion_get_target $interfaceA fluxion_get_target $interfaceA
result=$? result=$?
@ -1358,10 +1375,7 @@ while [ "$1" != "--" ]; do
exit exit
fi fi
if ! fluxion_target_show; then fluxion_target_show
echo Failed to show target with code $?
exit
fi
done done
exit exit
;; ;;