/[vps]/baselayout-vserver/trunk/lib/rcscripts/net.modules.d/macchanger
Gentoo

Contents of /baselayout-vserver/trunk/lib/rcscripts/net.modules.d/macchanger

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3 - (show annotations) (download)
Sat Sep 3 16:10:27 2005 UTC (9 years, 3 months ago) by hollow
File size: 3145 byte(s)
import initial baselayout sources (1.12.0_pre8)
1 #!/bin/bash
2 # Copyright (c) 2004-2005 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4
5 # Contributed by Roy Marples (uberlord@gentoo.org)
6
7 # char* macchanger_provides(void)
8 #
9 # Returns a string to change module definition for starting up
10 macchanger_provides() {
11 echo "macchanger"
12 }
13
14 # void macchanger_depend(void)
15 #
16 # Sets up the dependancies for the module
17 macchanger_depend() {
18 before macnet
19 }
20
21 # bool macchanger_check_installed(void)
22 #
23 # macchanger is always installed as an interface can change to a specific
24 # mac address, and an interface is always installed
25 macchanger_check_installed() {
26 return 0
27 }
28
29 # bool macchanger_check_depends(void)
30 #
31 # Checks to see if we have the needed functions
32 macchanger_check_depends() {
33 local f
34
35 for f in interface_get_mac_address interface_set_mac_address; do
36 [[ $( type -t "${f}" ) == "function" ]] && continue
37 eerror "macchanger: missing required function ${f}\n"
38 return 1
39 done
40
41 return 0
42 }
43
44 # bool macchanger_pre_start(char *iface)
45 #
46 # Configures the MAC address for iface
47 macchanger_pre_start() {
48 # We don't change MAC addresses from background
49 ${IN_BACKGROUND} && return 0
50
51 local iface="$1" mac opts ifvar=$( bash_variable "$1" )
52
53 eval mac=\"\$\{mac_${ifvar}\}\"
54 [[ -z ${mac} ]] && return 0
55
56 interface_exists "${iface}" true || return 1
57
58 ebegin "Changing MAC address of ${iface}"
59
60 mac=$( echo "${mac}" | tr '[:upper:]' '[:lower:]' )
61 case "${mac}" in
62 # specific mac-addr, i wish there were a shorter way to specify this
63 [0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f])
64 # We don't need macchanger to change to a specific mac address
65 interface_set_mac_address "${iface}" "${mac}"
66 eend "$?"
67 if [[ $? == "0" ]]; then
68 mac=$( interface_get_mac_address "${iface}" )
69 eindent
70 einfo "changed to ${mac}"
71 eoutdent
72 return 0
73 fi
74 ;;
75
76 # increment MAC address, default macchanger behavior
77 increment) opts="${opts}" ;;
78
79 # randomize just the ending bytes
80 random-ending) opts="${opts} -e" ;;
81
82 # keep the same kind of physical layer (eg fibre, copper)
83 random-samekind) opts="${opts} -a" ;;
84
85 # randomize to any known vendor of any physical layer type
86 random-anykind) opts="${opts} -A" ;;
87
88 # fully random bytes
89 random-full) opts="${opts} -r" ;;
90
91 # default case is just to pass on all the options
92 *) opts="${opts} ${mac}" ;;
93 esac
94
95 if [[ ! -x /sbin/macchanger ]]; then
96 eerror "For changing MAC addresses, emerge net-analyzer/macchanger"
97 return 1
98 fi
99
100 # The interface needs to be up for macchanger to work most of the time
101 interface_down "${iface}"
102
103 mac=$( /sbin/macchanger ${opts} "${iface}" \
104 | sed -n -e 's/^Faked MAC:.*\<\(..:..:..:..:..:..\)\>.*/\U\1/p' )
105
106 # Sometimes the interface needs to be up ....
107 if [[ -z ${mac} ]]; then
108 interface_up "${iface}"
109 mac=$( /sbin/macchanger ${opts} "${iface}" \
110 | sed -n -e 's/^Faked MAC:.*\<\(..:..:..:..:..:..\)\>.*/\U\1/p' )
111 fi
112
113 if [[ -z ${mac} ]]; then
114 eend 1 "Failed to set MAC address"
115 return 1
116 fi
117
118 eend 0
119 eindent
120 einfo "changed to ${mac}"
121 eoutdent
122
123 return 0 #important
124 }
125
126 # vim:ts=4

  ViewVC Help
Powered by ViewVC 1.1.20