/[baselayout]/branches/rc-scripts-1_6/net-scripts/net.modules.d/apipa
Gentoo

Contents of /branches/rc-scripts-1_6/net-scripts/net.modules.d/apipa

Parent Directory Parent Directory | Revision Log Revision Log


Revision 757 - (show annotations) (download)
Mon Dec 6 15:46:18 2004 UTC (13 years, 10 months ago) by agriffis
File size: 2452 byte(s)
Merge updates from HEAD

1 # Automatic Private IP Addressing (APIPA) module for net-scripts
2 # Version 1.0.1
3 # Copyright (c) 2004 Gentoo Foundation
4 # Distributed under the terms of the GNU General Public License V2
5 # Contributed by Roy Marples (uberlord@gentoo.org)
6
7 # char* apipa_provides(void)
8 #
9 # Returns a string to change module definition for starting up
10 apipa_provides() {
11 echo "apipa"
12 }
13
14 # void apipa_depend(void)
15 #
16 # Sets up the dependancies for the module
17 apipa_depend() {
18 after dhcp
19 }
20
21 # bool apipa_check_installed(void)
22 #
23 # Returns 1 if ifenslave is installed, otherwise 0
24 apipa_check_installed() {
25 [[ -x /sbin/arping || -x /usr/sbin/arping2 ]] && return 0
26 if ${1:-false}; then
27 eerror "For Automatic Private IP Addressing (APIPA) support"
28 eerror "emerge net-misc/iputils or net-analyzer/arping"
29 fi
30 return 1
31 }
32
33 # bool apipa_check_depends(void)
34 #
35 # Checks to see if we have the needed functions
36 apipa_check_depends() {
37 local f
38
39 for f in interface_exists interface_up; do
40 [[ $( type -t ${f} ) == function ]] && continue
41 eerror "apipa: missing required function ${f}\n"
42 return 1
43 done
44
45 return 0
46 }
47
48 # bool address_exists(char *interface, char *address)
49 #
50 # Returns 0 if the address on the interface responds to an arping
51 # 1 if not - packets defaults to 1
52 # If neither arping (net-misc/iputils) or arping2 (net-analyzer/arping)
53 # is installed then we return 1
54 address_exists() {
55 local iface=${1} address=${2%%/*} i
56
57 # We only handle IPv4 addresses
58 [[ ${address} != *.*.*.* ]] && return 1
59
60 # We need to bring the interface up to test
61 interface_up ${iface}
62
63 if [[ -x /sbin/arping ]]; then
64 /sbin/arping -q -c 2 -w 3 -D -f -I ${iface} ${address} &>/dev/null || return 0
65 elif [[ -x /usr/sbin/arping2 ]]; then
66 for (( i=0; i<3; i++ )); do
67 /usr/sbin/arping2 -0 -c 1 -i ${iface} ${address} &>/dev/null && return 0
68 done
69 fi
70 return 1
71 }
72
73 # bool apipa_start(char *iface)
74 #
75 # Tries to locate an address in the 169.254.0.0 netmask 169.254.255.255 range
76 apipa_start() {
77 local iface=${1} i1 i2 addr i=0
78
79 interface_exists ${iface} true || return 1
80
81 ebegin "Searching for free addresses"
82 interface_up ${iface}
83
84 while [[ ${i} -lt 64516 ]]; do
85 (( i1=${RANDOM}%255 ))
86 (( i2=${RANDOM}%255 ))
87
88 addr="169.254.${i1}.${i2}"
89 if ! address_exists ${iface} ${addr} ; then
90 config[config_counter]="${addr}/16 broadcast 169.254.255.255"
91 (( config_counter-- ))
92 eend 0
93 return 0
94 fi
95
96 (( i++ ))
97 done
98
99 eend 1 "No free address found!"
100 return 1
101 }

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.20