blob: 95eb61a807b4dab4557a11eb6bfd52062ed25a00 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
#!/bin/bash
# Copyright (c) 2004-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# Contributed by Roy Marples (uberlord@gentoo.org)
# Fix any potential localisation problems
# Note that LC_ALL trumps LC_anything_else according to locale(7)
pump() {
LC_ALL=C /sbin/pump "$@"
}
# char* pump_provides(void)
#
# Returns a string to change module definition for starting up
pump_provides() {
echo "dhcp"
}
# void pump_depend(void)
#
# Sets up the dependancies for the module
pump_depend() {
after interface
}
# bool pump_check_installed(void)
#
# Returns 1 if pump is installed, otherwise 0
pump_check_installed() {
[[ -x /sbin/pump ]] && return 0
${1:-false} && eerror "For DHCP (pump) support, emerge net-misc/pump"
return 1
}
# bool pump_check_depends(void)
#
# Checks to see if we have the needed functions
pump_check_depends() {
local f
for f in interface_exists interface_get_address; do
[[ $( type -t "${f}" ) == "function" ]] && continue
eerror "pump: missing required function ${f}\n"
return 1
done
return 0
}
# char* pump_get_vars(char *interface)
#
# Returns a string spaced with possible user set
# configuration variables
pump_get_vars() {
echo "pump_$1 dhcp_$1"
}
# bool pump_stop(char *iface)
#
# Stop pump on an interface
# Return 0 if pump is not running or we stop it successfully
# Otherwise 1
pump_stop() {
local iface="$1" count e
pump_check_installed || return 0
# We check for a pump process first as querying for status
# causes pump to spawn a process
pidof /sbin/pump &>/dev/null || return 0
# Check that pump is running on the interface
pump --status --interface "${iface}" 2>/dev/null \
| grep -q "^Device ${iface}" || return 0
# Pump always releases the lease
ebegin "Stopping pump on ${iface}"
pump --release --interface "${iface}"
eend "$?" "Failed to stop pump"
return "$?"
}
# bool pump_start(char *iface)
#
# Start pump on an interface by calling pumpcd $iface $options
#
# Returns 0 (true) when a dhcp address is obtained, otherwise
# the return value from pump
pump_start() {
local iface="$1" opts d ifvar=$( bash_variable "$1" ) search
interface_exists "${iface}" true || return 1
eval opts=\" \$\{pump_${ifvar}\} \"
# Map some generic options to pump
eval d=\" \$\{dhcp_${ifvar}\} \"
[[ ${d} == " " ]] && d=" ${dhcp} "
[[ ${d} == *" nodns "* ]] && opts="${opts} --no-dns"
[[ ${d} == *" nogateway "* ]] && opts="${opts} --no-gateway"
[[ ${d} == *" nontp "* ]] && opts="${opts} --no-ntp"
eval search=\"\$\{dns_search_${ifvar}\}\"
[[ -n ${search} ]] && opts="${opts} --search-path='"${search}"'"
# Add our route metric
eval metric=\"\$\{metric_${ifvar}\}\"
[[ -n ${metric} ]] && opts="${opts} --route-metric ${metric}"
[[ ! -d "${statedir}/${iface}" ]] && mkdir -m 0755 -p "${statedir}/${iface}"
opts="${opts} --win-client-ident --etc-dir=${statedir}/${iface}"
opts="${opts} --script /lib/rcscripts/net.modules.d/helpers.d/pump-wrapper"
opts="${opts} --keep-up --interface ${iface}"
# Bring up DHCP for this interface (or alias)
ebegin "Running pump"
if [[ ${background} == "yes" ]]; then
eval pump ${opts} &
eend 0
go_background
fi
eval pump ${opts}
eend "$?" || return "$?"
# pump succeeded, show address retrieved
local addr=$( interface_get_address "${iface}" )
einfo "${iface} received address ${addr}"
return 0
}
# vim:ts=4
|