2009-05-01 19:41:40 +05:30
|
|
|
# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
|
2011-06-30 05:16:31 +05:30
|
|
|
# Released under the 2-clause BSD license.
|
2007-11-14 20:52:04 +05:30
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
apipa_depend()
|
|
|
|
{
|
2007-04-05 16:48:42 +05:30
|
|
|
program /sbin/arping
|
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
_random()
|
|
|
|
{
|
2012-11-07 07:14:17 +05:30
|
|
|
local r=${RANDOM} # checkbashisms: false positive, we handle it AFTERWARDS
|
2007-11-28 21:15:03 +05:30
|
|
|
if [ -n "${r}" ]; then
|
|
|
|
echo "${r}"
|
2007-04-05 16:48:42 +05:30
|
|
|
else
|
|
|
|
uuidgen | sed -n -e 's/[^[:digit:]]//g' -e 's/\(^.\{1,7\}\).*/\1/p'
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
apipa_start()
|
|
|
|
{
|
2007-04-05 16:48:42 +05:30
|
|
|
local iface="$1" i1= i2= addr= i=0
|
|
|
|
|
|
|
|
_exists true || return 1
|
2011-01-17 15:19:07 +05:30
|
|
|
|
2007-04-05 16:48:42 +05:30
|
|
|
einfo "Searching for free addresses in 169.254.0.0/16"
|
|
|
|
eindent
|
|
|
|
|
|
|
|
while [ ${i} -lt 64516 ]; do
|
2011-11-11 08:16:08 +05:30
|
|
|
: $(( i1 = (_random % 255) + 1 ))
|
|
|
|
: $(( i2 = (_random % 255) + 1 ))
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
addr="169.254.${i1}.${i2}"
|
|
|
|
vebegin "${addr}/16"
|
2007-11-28 21:15:03 +05:30
|
|
|
if ! arping_address "${addr}"; then
|
2007-04-05 16:48:42 +05:30
|
|
|
eval config_${config_index}="\"${addr}/16 broadcast 169.254.255.255\""
|
2011-11-11 08:16:08 +05:30
|
|
|
: $(( config_index -= 1 ))
|
2007-04-05 16:48:42 +05:30
|
|
|
veend 0
|
|
|
|
eoutdent
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2011-11-11 08:16:08 +05:30
|
|
|
: $(( i += 1 ))
|
2007-04-05 16:48:42 +05:30
|
|
|
done
|
|
|
|
|
|
|
|
eerror "No free address found!"
|
|
|
|
eoutdent
|
|
|
|
return 1
|
|
|
|
}
|