/[baselayout]/trunk/net-scripts/net.modules.d/helpers.d/dhcp
Gentoo

Contents of /trunk/net-scripts/net.modules.d/helpers.d/dhcp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1103 - (show annotations) (download)
Fri Apr 22 14:42:57 2005 UTC (14 years, 1 month ago) by uberlord
File size: 3773 byte(s)
Address network routes now get metrics applied as well
(ie a route automatically added when an address is added)

net.lo no longer errors when exlcuding modules who are installed

1 #!/bin/bash
2 # Copyright (c) 2004-2005 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4 # $Header$
5
6 # Contributed by Roy Marples (uberlord@gentoo.org)
7
8 action="$1"
9
10 . /etc/conf.d/net
11 [[ -z ${MODULES_DIR} ]] && MODULES_DIR="/lib/rcscripts/net.modules.d"
12 . "${MODULES_DIR}/system"
13 . "${MODULES_DIR}/helpers.d/functions"
14
15 # Guess which interface module to load - we prefer iproute2
16 if [[ -x /sbin/ip ]]; then
17 interface_module="iproute2"
18 elif [[ -x /sbin/ifconfig ]]; then
19 interface_module="ifconfig"
20 else
21 echo "Can't find a known interface module" >&2
22 exit 1
23 fi
24
25 # iwconfig is the best bet for wireless - we use wpa_supplicant
26 # only if we need to
27 if [[ -x /usr/sbin/iwconfig ]]; then
28 wireless_module="iwconfig"
29 elif [[ -x /usr/sbin/wpa_supplicant && -S "/var/run/wpa_supplicant/${interface}" ]]; then
30 wireless_module="wpa_supplicant"
31 fi
32
33 # Load our modules
34 . "${MODULES_DIR}/${interface_module}"
35 function_wrap "${interface_module}" interface
36 if [[ -n ${wireless_module} ]]; then
37 . "${MODULES_DIR}/${wireless_module}"
38 function_wrap "${wireless_module}" wireless
39 fi
40
41 auto_interface=${auto_interface:-"yes"}
42
43 # Bring the interface up
44 interface_is_up "${interface}" || interface_up "${interface}"
45
46 case "${action}" in
47 "bound"|"renew")
48 # We handle these actions below
49 ;;
50 "deconfig")
51 interface_del_addresses "${interface}"
52 mark_service_inactive "net.${interface}"
53 if [[ ${auto_interface} == "yes" ]]; then
54 remove_state "${interface}"
55 best_interface=$( select_best_interface )
56 apply_state "${interface}"
57 fi
58 echo "${action}"
59 exit 0
60 ;;
61 "nak")
62 echo "${action}"
63 exit 0
64 ;;
65 "leasefail")
66 mark_service_inactive "net.${interface}"
67 echo "${action}"
68 exit 0
69 ;;
70 *)
71 echo "${action}"
72 echo "We don't handle that action" >&2
73 exit 1
74 ;;
75 esac
76
77 # Map wireless ESSID variables to interface variables
78 if wireless_check_extensions "${interface}" ; then
79 MODULES=( "${interface_module}" "essidnet" "system" )
80 source ${MODULES_DIR}/essidnet
81 essidnet_pre_start ${interface}
82 fi
83
84 # Calculate the metric for our routes
85 ifvar=$( bash_variable ${interface} )
86 eval metric=\"\$\{metric_${ifvar}\}\"
87 if [[ -z ${metric} ]]; then
88 if [[ ${auto_interface} == "yes" ]]; then
89 metric=$( calculate_metric ${interface} )
90 else
91 metric=0
92 fi
93 eval metric_${ifvar}="${metric}"
94 fi
95
96 # Configure our IP address
97 ip=${ip// }
98 subnet=${subnet// }
99 cidr=$( netmask2cidr ${subnet} )
100 broadcast=${broadcast// }
101 [[ -n ${broadcast} ]] && broadcast="broadcast ${broadcast}"
102
103 # If we don't have our address then we flush it and then add our new one
104 curip=$( interface_get_address ${interface} )
105 if [[ ${curip} != "${ip}/${cidr}" ]] ; then
106 interface_del_addresses ${interface}
107 interface_add_address ${interface} "${ip}/${cidr}" ${broadcast}
108 fi
109
110 # Store the address in a cache for future usage
111 echo ${ip} > /var/cache/dhcp-${interface}.lease
112 chmod 600 /var/cache/dhcp-${interface}.lease
113
114 # Configure our default route - we only have 1 default route
115 for r in ${router}; do
116 interface_default_route ${interface} ${r} ${metric:-0} && break
117 done
118
119 # Configure our hostname - but only if we need it
120 if [[ -n ${hostname} ]]; then
121 x=$( /bin/hostname )
122 [[ ${x} == "(none)" || ${x} == "localhost" ]] && /bin/hostname "${hostname}"
123 fi
124
125 # Only setup the information we're told to
126 # By default that's everything
127 eval dhcp=\" \$\{dhcp_${ifvar}\} \"
128 [[ ${dhcp} != *' nodns '* ]] && system_dns "${interface}"
129 [[ ${dhcp} != *' nontp '* ]] && system_ntp "${interface}"
130 [[ ${dhcp} != *' nonis '* ]] && system_nis "${interface}"
131
132 if [[ ${auto_interface} == "yes" ]]; then
133 save_state ${interface}
134 best_interface=$( select_best_interface )
135 apply_state ${best_interface}
136 fi
137
138 mark_service_started net.${interface}
139
140 echo "${action}"
141 exit 0

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.20