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