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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3 - (show annotations) (download)
Sat Sep 3 16:10:27 2005 UTC (9 years, 1 month ago) by hollow
File size: 3438 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 action="$1"
8 service="net.${interface}"
9
10 . /lib/rcscripts/net.modules.d/helpers.d/module-loader
11
12 # Bring the interface up
13 interface_is_up "${interface}" || interface_up "${interface}"
14
15 case "${action}" in
16 bound|renew)
17 # We handle these actions below
18 ;;
19 deconfig)
20 # Just remove IPv4 / inet addresses
21 interface_del_addresses "${interface}" true
22 if service_starting "${service}" || service_started "${service}" ; then
23 mark_service_inactive "net.${interface}"
24 fi
25 remove_state "${interface}"
26 if [[ ${RC_AUTO_INTERFACE} == "yes" ]]; then
27 best_interface=$( select_best_interface )
28 apply_state "${best_interface}"
29 fi
30 echo "${action}"
31 exit 0
32 ;;
33 nak)
34 echo "${action}"
35 exit 0
36 ;;
37 leasefail)
38 if service_starting "${service}" || service_started "${service}" ; then
39 mark_service_inactive "net.${interface}"
40 fi
41 echo "${action}"
42 exit 0
43 ;;
44 *)
45 echo "${action}"
46 echo "We don't handle that action" >&2
47 exit 1
48 ;;
49 esac
50
51 # Map MAC address variables to interface variables
52 macnet_pre_start "${interface}" 1>/dev/null
53
54 # Map wireless ESSID variables to interface variables
55 if [[ -n ${wireless_module} ]]; then
56 if wireless_check_extensions "${interface}" ; then
57 essidnet_pre_start "${interface}" 1>/dev/null
58 fi
59 fi
60
61 # Calculate the metric for our routes
62 ifvar=$( bash_variable "${interface}" )
63 eval metric=\"\$\{metric_${ifvar}\}\"
64 if [[ -z ${metric} ]]; then
65 if [[ ${RC_AUTO_INTERFACE} == "yes" ]]; then
66 metric=$( calculate_metric "${interface}" )
67 else
68 metric="0"
69 fi
70 eval metric_${ifvar}="${metric}"
71 fi
72
73
74 eval d=\" \$\{dhcp_${ifvar}\} \"
75 [[ ${d} == " " ]] && d=" ${dhcp} "
76
77 # Configure our IP address
78 ip="${ip// }"
79 subnet="${subnet// }"
80 cidr=$( netmask2cidr "${subnet}" )
81 broadcast="${broadcast// }"
82 [[ -n ${broadcast} ]] && broadcast="broadcast ${broadcast}"
83
84 # If we don't have our address then we flush it and then add our new one
85 curip=$( interface_get_address "${interface}" )
86 if [[ ${curip} != "${ip}/${cidr}" ]] ; then
87 # Just remove IPv4 / inet addresses
88 interface_del_addresses "${interface}" true
89 interface_add_address "${interface}" "${ip}/${cidr}" "${broadcast}"
90 fi
91
92 # Store the address in a cache for future usage
93 echo "${ip}" > "/var/cache/dhcp-${interface}.lease"
94 chmod 600 "/var/cache/dhcp-${interface}.lease"
95
96 # Configure our default route - we only have 1 default route
97 if [[ ${d} != *" nogateway "* ]]; then
98 for r in ${routers}; do
99 interface_default_route "${interface}" "${r}" "${metric:-0}" && break
100 done
101 fi
102
103 # Configure our hostname - but only if we need it
104 if [[ -n ${hostname} ]]; then
105 x=$( /bin/hostname )
106 [[ ${x} == "(none)" || ${x} == "localhost" ]] && /bin/hostname "${hostname}"
107 fi
108
109 [[ ! -d "${statedir}/${interface}" ]] \
110 && mkdir -m 0755 -p "${statedir}/${interface}"
111
112 # Only setup the information we're told to
113 # By default that's everything
114 [[ ${d} != *" nodns "* ]] && system_dns "${interface}"
115 [[ ${d} != *" nontp "* ]] && system_ntp "${interface}"
116 [[ ${d} != *" nonis "* ]] && system_nis "${interface}"
117
118 if [[ ${RC_AUTO_INTERFACE} == "yes" ]]; then
119 best_interface=$( select_best_interface )
120 apply_state "${best_interface}"
121 else
122 apply_state "${interface}"
123 fi
124
125 ! service_stopping "${service}" && mark_service_started "${service}"
126
127 echo "${action}"
128 exit 0
129
130 # vim:ts=4

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.20