]> git.ipfire.org Git - people/stevee/network.git/blob - src/dhclient-script
hostapd: Enable WMM by default.
[people/stevee/network.git] / src / dhclient-script
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 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}"
98 routing_db_set ${interface} ipv4 remote-ip-address "${new_routers}"
99 routing_db_set ${interface} ipv4 active 1
100 routing_db_set ${interface} ipv4 domain-name "${new_domain_name}"
101 routing_db_set ${interface} ipv4 domain-name-servers "${new_domain_name_servers}"
102 routing_db_set ${interface} ipv4 domain-name-servers-priority "${DNS_SERVER_DYNAMIC_PRIORITY}"
103
104 # Update the routing tables.
105 routing_update ${interface} ipv4
106 routing_default_update
107
108 # Update resolv.conf
109 dns_generate_resolvconf
110 fi
111 ;;
112 esac
113
114 exit 0
115 ;;
116
117 EXPIRE|FAIL|RELEASE|STOP)
118 # Remove the currently configured addresses from the device.
119 if [ -n "${old_ip_address}" ]; then
120 ipv4_flush_device ${interface}
121 fi
122
123 routing_db_remove ${interface} ipv4
124 routing_default_update
125
126 exit 0
127 ;;
128 esac
129
130 exit 1