]>
git.ipfire.org Git - thirdparty/dhcp.git/blob - client/scripts/macos
a896b1e9a288e4145379c3b60449e45fc6c2def9
3 # $Id: macos,v 1.4 2011/09/20 16:59:54 sar Exp $
5 # automous run of this script will commit the DNS setting
8 if [ -x /usr
/bin
/logger
]; then
9 LOGGER
="/usr/bin/logger -s -p user.notice -t dhclient"
18 if [ "x${new_dhcp6_name_servers}" != x
]; then
19 ( cat /dev
/null
> /var
/run
/resolv.conf.dhclient6
)
21 if [ $exit_status -ne 0 ]; then
22 $LOGGER "Unable to create /var/run/resolv.conf.dhclient6: Error $exit_status"
24 if [ "x${new_dhcp6_domain_search}" != x
]; then
25 ( echo search
${new_dhcp6_domain_search} >> /var
/run
/resolv.conf.dhclient6
)
28 for nameserver
in ${new_dhcp6_name_servers} ; do
29 if [ $exit_status -ne 0 ]; then
32 # If the nameserver has a link-local address
33 # add a <zone_id> (interface name) to it.
35 fe80
:*) zone_id
="%$interface";;
36 FE80
:*) zone_id
="%$interface";;
39 ( echo nameserver
${nameserver}$zone_id >> /etc
/resolv.conf.dhclient6
)
43 if [ $exit_status -eq 0 ]; then
51 # Try to commit /var/run/resolv.conf.dhclient6 contents to
52 # System Configuration framework's Dynamic Store.
53 # Note this will be cleared by the next location change
54 # or preempted by IPv4.
56 # The System Configuration agent "IPMonitor" gets the DNS configuration
57 # from the IPv4 or IPv6 primary service in the Dynamic Store
58 # (managed by configd).
59 commit_resolv_conf
() {
60 if [ -f /var
/run
/resolv.conf.dhclient6
]; then
61 if [ -x /usr
/sbin
/scutil
]; then
62 serviceID
=`echo show State:/Network/Global/IPv6 | \
64 awk '/PrimaryService/ { print $3 }'`
66 if [ x
$serviceID = x
]; then
67 $LOGGER "Can't find the primary IPv6 service"
69 tmp
=`mktemp SC_dhclient6.XXXXXXXXXX`
70 echo list |
/usr
/sbin
/scutil
> /tmp
/$tmp
71 grep -q State
:/Network
/Service
/$serviceID/DNS
/tmp
/$tmp
73 if [ $grep_status -eq 0 ]; then
74 $LOGGER "DNS service already set in primary IPv6 service"
77 res
=/var
/run
/resolv.conf.dhclient6
78 cp /dev
/null
/tmp
/$tmp
79 grep -q '^nameserver' $res
81 if [ $grep_status -eq 0 ]; then
82 echo d.add ServerAddresses
'*' \
83 `awk 'BEGIN { n="" } \
84 /^nameserver/ { n=n " " $2 } \
85 END { print n}' < $res` >> /tmp
/$tmp
87 grep -q '^search' $res
89 if [ $grep_status -eq 0 ]; then
90 echo d.add SearchDomains
'*' \
91 `sed 's/^search//' < $res` >> /tmp
/$tmp
93 echo set State
:/Network
/Service
/$serviceID/DNS
>> /tmp
/$tmp
94 echo quit
>> /tmp
/$tmp
96 /usr
/sbin
/scutil
< /tmp
/$tmp
101 $LOGGER "Can't find SystemConfiguration tools."
104 if [ $to_commit = force
]; then
105 $LOGGER "Can't find /var/run/resolv.conf.dhclient6"
111 # Must be used on exit. Invokes the local dhcp client exit hooks, if any.
114 if [ -f /etc
/dhclient-exit-hooks
]; then
115 .
/etc
/dhclient-exit-hooks
117 # probably should do something with exit status of the local script
121 # Invoke the local dhcp client enter hooks, if they exist.
122 if [ -f /etc
/dhclient-enter-hooks
]; then
124 .
/etc
/dhclient-enter-hooks
125 # allow the local script to abort processing of this state
126 # local script must set exit_status variable to nonzero.
127 if [ $exit_status -ne 0 ]; then
132 if [ x
$reason = xMEDIUM
]; then
133 eval "ifconfig $interface $medium"
134 eval "ifconfig $interface inet -alias 0.0.0.0 $medium" >/dev
/null
2>&1
143 if [ x
$reason = xPREINIT6
]; then
144 # Ensure interface is up.
145 ifconfig
${interface} up
147 # We need to give the kernel some time to active interface
148 interface_up_wait_time
=5
149 for i
in $
(seq 0 ${interface_up_wait_time})
151 ifconfig
${interface} |
grep inactive
&> /dev
/null
152 if [ $?
-ne 0 ]; then
158 # XXX: Remove any stale addresses from aborted clients.
160 # Wait for duplicate address detection for this interface if the
161 # --dad-wait-time parameter has been specified and is greater than
163 if [ ${dad_wait_time} -gt 0 ]; then
164 # Check if any IPv6 address on this interface is marked as
166 ifconfig
${interface} |
grep inet6 |
grep tentative \
168 if [ $?
-eq 0 ]; then
169 # Wait for duplicate address detection to complete or for
170 # the timeout specified as --dad-wait-time.
171 for i
in $
(seq 0 $dad_wait_time)
173 # We're going to poll for the tentative flag every second.
175 ifconfig
${interface} |
grep inet6 |
grep tentative \
177 if [ $?
-ne 0 ]; then
187 if [ x
${old_ip6_prefix} != x
] ||
[ x
${new_ip6_prefix} != x
]; then
188 echo Prefix
$reason old
=${old_ip6_prefix} new
=${new_ip6_prefix}
193 if [ x
$reason = xBOUND6
]; then
194 if [ x
${new_ip6_address} = x
] ||
[ x
${new_ip6_prefixlen} = x
]; then
198 ifconfig
${interface} inet6 ${new_ip6_address}/${new_ip6_prefixlen} alias
200 # Check for nameserver options.
206 if [ x
$reason = xRENEW6
] ||
[ x
$reason = xREBIND6
]; then
207 # Make sure nothing has moved around on us.
209 # Nameservers/domains/etc.
210 if [ "x${new_dhcp6_name_servers}" != "x${old_dhcp6_name_servers}" ] ||
211 [ "x${new_dhcp6_domain_search}" != "x${old_dhcp6_domain_search}" ]; then
218 if [ x
$reason = xDEPREF6
]; then
219 if [ x
${new_ip6_address} = x
]; then
223 ifconfig
${interface} inet6
${new_ip6_address} deprecated
228 if [ x
$reason = xEXPIRE6
-o x
$reason = xRELEASE6
-o x
$reason = xSTOP6
]; then
229 if [ x
${old_ip6_address} = x
] ||
[ x
${old_ip6_prefixlen} = x
]; then
233 ifconfig
${interface} inet6 ${old_ip6_address}/${old_ip6_prefixlen} -alias
238 if [ $to_commit = yes ]; then