blob: 133ffae9aba4793d4988d34bb4620456bdfdc15a (
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
|
#!/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)
action="$1"
service="net.${interface}"
. /lib/rcscripts/net.modules.d/helpers.d/module-loader
# Bring the interface up
interface_is_up "${interface}" || interface_up "${interface}"
case "${action}" in
bound|renew)
# We handle these actions below
;;
deconfig)
# Just remove IPv4 / inet addresses
interface_del_addresses "${interface}" true
if service_starting "${service}" || service_started "${service}" ; then
mark_service_inactive "net.${interface}"
fi
remove_state "${interface}"
if [[ ${RC_AUTO_INTERFACE} == "yes" ]]; then
best_interface=$( select_best_interface )
apply_state "${best_interface}"
fi
echo "${action}"
exit 0
;;
nak)
echo "${action}"
exit 0
;;
leasefail)
if service_starting "${service}" || service_started "${service}" ; then
mark_service_inactive "net.${interface}"
fi
echo "${action}"
exit 0
;;
*)
echo "${action}"
echo "We don't handle that action" >&2
exit 1
;;
esac
# Map MAC address variables to interface variables
macnet_pre_start "${interface}" 1>/dev/null
# Map wireless ESSID variables to interface variables
if [[ -n ${wireless_module} ]]; then
if wireless_check_extensions "${interface}" ; then
essidnet_pre_start "${interface}" 1>/dev/null
fi
fi
# Calculate the metric for our routes
ifvar=$( bash_variable "${interface}" )
eval metric=\"\$\{metric_${ifvar}\}\"
if [[ -z ${metric} ]]; then
if [[ ${RC_AUTO_INTERFACE} == "yes" ]]; then
metric=$( calculate_metric "${interface}" )
else
metric="0"
fi
eval metric_${ifvar}="${metric}"
fi
eval d=\" \$\{dhcp_${ifvar}\} \"
[[ ${d} == " " ]] && d=" ${dhcp} "
# Configure our IP address
ip="${ip// }"
subnet="${subnet// }"
cidr=$( netmask2cidr "${subnet}" )
broadcast="${broadcast// }"
[[ -n ${broadcast} ]] && broadcast="broadcast ${broadcast}"
# If we don't have our address then we flush it and then add our new one
curip=$( interface_get_address "${interface}" )
if [[ ${curip} != "${ip}/${cidr}" ]] ; then
# Just remove IPv4 / inet addresses
interface_del_addresses "${interface}" true
interface_add_address "${interface}" "${ip}/${cidr}" "${broadcast}"
fi
# Store the address in a cache for future usage
echo "${ip}" > "/var/cache/dhcp-${interface}.lease"
chmod 600 "/var/cache/dhcp-${interface}.lease"
# Configure our default route - we only have 1 default route
if [[ ${d} != *" nogateway "* ]]; then
for r in ${routers}; do
interface_default_route "${interface}" "${r}" "${metric:-0}" && break
done
fi
# Configure our hostname - but only if we need it
if [[ -n ${hostname} ]]; then
x=$( hostname )
[[ ${x} == "(none)" || ${x} == "localhost" ]] && hostname "${hostname}"
fi
[[ ! -d "${statedir}/${interface}" ]] \
&& mkdir -m 0755 -p "${statedir}/${interface}"
# Only setup the information we're told to
# By default that's everything
[[ ${d} != *" nodns "* ]] && system_dns "${interface}"
[[ ${d} != *" nontp "* ]] && system_ntp "${interface}"
[[ ${d} != *" nonis "* ]] && system_nis "${interface}"
if [[ ${RC_AUTO_INTERFACE} == "yes" ]]; then
best_interface=$( select_best_interface )
apply_state "${best_interface}"
else
apply_state "${interface}"
fi
! service_stopping "${service}" && mark_service_started "${service}"
echo "${action}"
exit 0
# vim:ts=4
|