]> git.ipfire.org Git - people/stevee/network.git/blame - src/dhclient-script
dhclient-script: Read global network configuration
[people/stevee/network.git] / src / dhclient-script
CommitLineData
e9ea243e
MT
1#!/bin/bash
2
3. /usr/lib/network/functions
4
5# Configure logging
6LOG_FACILITY="dhclient-script"
7
9038a844
MT
8network_settings_read
9
e9ea243e
MT
10assert isset interface
11assert isset reason
12
13assert device_exists ${interface}
14
e9ea243e
MT
15basename="$(basename $0)"
16log DEBUG "${basename} called for interface=${interface} reason=${reason}"
17
18# Main pitchfork.
19case "${reason}" in
20 MEDIUM)
21 # Linux does not handle MEDIUM.
22 exit 0
23 ;;
24
25 PREINIT)
26 # Bring up the device if it hasn't been done before.
27 if ! device_is_up ${interface}; then
28 log DEBUG "The interface '${interface}' does not appear to be up."
29
30 zone_up ${interface}
31 fi
32
33 # If the use configured a delay, we will honour that.
34 if [ -n "${DELAY}" ]; then
35 assert isinteger DELAY
36 sleep ${DELAY}
37
38 # If he didn't, we will try to detect is STP has brought the
39 # bridge up.
40 elif device_is_bridge ${interface}; then
41 counter=60
42
43 while [ ${counter} -gt 0 ]; do
44 # We may end this, when the bridge is in forwarding mode.
45 if bridge_is_forwarding ${interface}; then
46 log DEBUG "Bridge '${interface}' is in forwarding mode."
47 break
48 fi
49
50 counter=$(( ${counter} - 1 ))
51 sleep 1
52 done
53
54 # Tell the daemon, that we are not ready to go on.
55 if [ ${counter} -eq 0 ]; then
56 log ERROR "Bridge '${interface}' is not in forwarding mode."
57 log ERROR "Could not go on with getting a DHCP lease. Exiting."
58
59 exit 1
60 fi
61 fi
62
63 exit 0
64 ;;
65
66
67 BOUND|RENEW|REBIND|REBOOT)
68 # Check if the IP address has changed. If so, delete all routes and stuff.
69 if [ -n "${old_ip_address}" -a "${old_ip_address}" != "${new_ip_address}" ]; then
70 ipv4_flush_device ${interface}
71 fi
72
73 case "${reason}" in
74 BOUND|REBOOT)
75 if [ ! "${old_ip_address}" = "${new_ip_address}" ] || \
76 [ ! "${old_subnet_mask}" = "${new_subnet_mask}" ] || \
77 [ ! "${old_network_number}" = "${new_network_number}" ] || \
78 [ ! "${old_broadcast_address}" = "${new_broadcast_address}" ] || \
79 [ ! "${old_routers}" = "${new_routers}" ] || \
80 [ ! "${old_interface_mtu}" = "${new_interface_mtu}" ]; then
81
82
83 # Calc a prefix out of address and subnet mask.
84 new_prefix="$(ipv4_get_prefix ${new_ip_address} ${new_subnet_mask})"
85
86 # Set the new ip address.
87 ip_address_add ${interface} ${new_ip_address}/${new_prefix}
88 device_set_up ${interface}
89
90
91 # A MTU of 576 is used for X.25 and dialup connections. Some broken DHCP
92 # servers send out an MTU of 576 bytes, which will be ignored.
93 if [ -n "${new_interface_mtu}" ] && [ ${new_interface_mtu} -gt 576 ]; then
94 device_set_mtu ${interface} ${new_interface_mtu}
95 fi
96
97 # Save configuration
98 routing_db_set ${interface} ipv4 type "ipv4-dhcp"
99 routing_db_set ${interface} ipv4 local-ip-address "${new_ip_address}/${new_prefix}"
2af98498 100 routing_db_set ${interface} ipv4 remote-ip-address "${new_routers}"
e9ea243e 101 routing_db_set ${interface} ipv4 active 1
a9ebc53b
KB
102 routing_db_set ${interface} ipv4 domain-name "${new_domain_name}"
103 routing_db_set ${interface} ipv4 domain-name-servers "${new_domain_name_servers}"
e5651e17 104 routing_db_set ${interface} ipv4 domain-name-servers-priority "${DNS_SERVER_DYNAMIC_PRIORITY}"
e9ea243e
MT
105
106 # Update the routing tables.
107 routing_update ${interface} ipv4
2af98498 108 routing_default_update
a9ebc53b
KB
109
110 # Update resolv.conf
111 dns_generate_resolvconf
e9ea243e
MT
112 fi
113 ;;
114 esac
115
116 exit 0
117 ;;
118
119 EXPIRE|FAIL|RELEASE|STOP)
120 # Remove the currently configured addresses from the device.
121 if [ -n "${old_ip_address}" ]; then
122 ipv4_flush_device ${interface}
123 fi
124
2af98498
MT
125 routing_db_remove ${interface} ipv4
126 routing_default_update
127
e9ea243e
MT
128 exit 0
129 ;;
130esac
131
132exit 1