]>
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 | ||
13 | # XXX LOAD ZONE CONFIGURATION | |
14 | ||
15 | basename="$(basename $0)" | |
16 | log DEBUG "${basename} called for interface=${interface} reason=${reason}" | |
17 | ||
18 | # Main pitchfork. | |
19 | case "${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}" | |
100 | routing_db_set ${interface} ipv4 remote-ip-address "${new_router}" | |
101 | routing_db_set ${interface} ipv4 active 1 | |
102 | ||
103 | # Update the routing tables. | |
104 | routing_update ${interface} ipv4 | |
105 | fi | |
106 | ;; | |
107 | esac | |
108 | ||
109 | exit 0 | |
110 | ;; | |
111 | ||
112 | EXPIRE|FAIL|RELEASE|STOP) | |
113 | # Remove the currently configured addresses from the device. | |
114 | if [ -n "${old_ip_address}" ]; then | |
115 | ipv4_flush_device ${interface} | |
116 | fi | |
117 | ||
118 | exit 0 | |
119 | ;; | |
120 | esac | |
121 | ||
122 | exit 1 |