Return to openwrt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / dhcp / client / scripts |
1.1 ! misho 1: #!/bin/sh ! 2: ! 3: make_resolv_conf() { ! 4: if [ x"$new_domain_name_servers" != x ]; then ! 5: cat /dev/null > /etc/resolv.conf.dhclient ! 6: chmod 644 /etc/resolv.conf.dhclient ! 7: if [ x"$new_domain_search" != x ]; then ! 8: echo search $new_domain_search >> /etc/resolv.conf.dhclient ! 9: elif [ x"$new_domain_name" != x ]; then ! 10: # Note that the DHCP 'Domain Name Option' is really just a domain ! 11: # name, and that this practice of using the domain name option as ! 12: # a search path is both nonstandard and deprecated. ! 13: echo search $new_domain_name >> /etc/resolv.conf.dhclient ! 14: fi ! 15: for nameserver in $new_domain_name_servers; do ! 16: echo nameserver $nameserver >>/etc/resolv.conf.dhclient ! 17: done ! 18: ! 19: mv /etc/resolv.conf.dhclient /etc/resolv.conf ! 20: elif [ "x${new_dhcp6_name_servers}" != x ] ; then ! 21: cat /dev/null > /etc/resolv.conf.dhclient6 ! 22: chmod 644 /etc/resolv.conf.dhclient6 ! 23: ! 24: if [ "x${new_dhcp6_domain_search}" != x ] ; then ! 25: echo search ${new_dhcp6_domain_search} >> /etc/resolv.conf.dhclient6 ! 26: fi ! 27: for nameserver in ${new_dhcp6_name_servers} ; do ! 28: # If the nameserver has a link-local address ! 29: # add a <zone_id> (interface name) to it. ! 30: case $nameserver in ! 31: fe80:*) zone_id="%$interface";; ! 32: FE80:*) zone_id="%$interface";; ! 33: *) zone_id='';; ! 34: esac ! 35: echo nameserver ${nameserver}$zone_id >> /etc/resolv.conf.dhclient6 ! 36: done ! 37: ! 38: mv /etc/resolv.conf.dhclient6 /etc/resolv.conf ! 39: fi ! 40: } ! 41: ! 42: # Must be used on exit. Invokes the local dhcp client exit hooks, if any. ! 43: exit_with_hooks() { ! 44: exit_status=$1 ! 45: if [ -f /etc/dhclient-exit-hooks ]; then ! 46: . /etc/dhclient-exit-hooks ! 47: fi ! 48: # probably should do something with exit status of the local script ! 49: exit $exit_status ! 50: } ! 51: ! 52: # Invoke the local dhcp client enter hooks, if they exist. ! 53: if [ -f /etc/dhclient-enter-hooks ]; then ! 54: exit_status=0 ! 55: . /etc/dhclient-enter-hooks ! 56: # allow the local script to abort processing of this state ! 57: # local script must set exit_status variable to nonzero. ! 58: if [ $exit_status -ne 0 ]; then ! 59: exit $exit_status ! 60: fi ! 61: fi ! 62: ! 63: ### ! 64: ### DHCPv4 Handlers ! 65: ### ! 66: ! 67: if [ x$new_broadcast_address != x ]; then ! 68: new_broadcast_arg="broadcast $new_broadcast_address" ! 69: fi ! 70: if [ x$new_subnet_mask != x ]; then ! 71: new_subnet_arg="netmask $new_subnet_mask" ! 72: fi ! 73: if [ x$alias_subnet_mask != x ]; then ! 74: alias_subnet_arg="netmask $alias_subnet_mask" ! 75: fi ! 76: if [ x$new_interface_mtu != x ]; then ! 77: mtu_arg="mtu $new_interface_mtu" ! 78: fi ! 79: if [ x$IF_METRIC != x ]; then ! 80: metric_arg="metric $IF_METRIC" ! 81: fi ! 82: ! 83: if [ x$reason = xMEDIUM ]; then ! 84: # Linux doesn't do mediums (ok, ok, media). ! 85: exit_with_hooks 0 ! 86: fi ! 87: ! 88: if [ x$reason = xPREINIT ]; then ! 89: if [ x$alias_ip_address != x ]; then ! 90: # Bring down alias interface. Its routes will disappear too. ! 91: ifconfig $interface:0- 0.0.0.0 ! 92: fi ! 93: ifconfig $interface 0.0.0.0 up ! 94: ! 95: # We need to give the kernel some time to get the interface up. ! 96: sleep 1 ! 97: ! 98: exit_with_hooks 0 ! 99: fi ! 100: ! 101: if [ x$reason = xARPCHECK ] || [ x$reason = xARPSEND ]; then ! 102: exit_with_hooks 0 ! 103: fi ! 104: ! 105: if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \ ! 106: [ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then ! 107: current_hostname=`hostname` ! 108: if [ x$current_hostname = x ] || \ ! 109: [ x$current_hostname = x$old_host_name ]; then ! 110: if [ x$current_hostname = x ] || \ ! 111: [ x$new_host_name != x$old_host_name ]; then ! 112: hostname $new_host_name ! 113: fi ! 114: fi ! 115: ! 116: if [ x$old_ip_address != x ] && [ x$alias_ip_address != x ] && \ ! 117: [ x$alias_ip_address != x$old_ip_address ]; then ! 118: # Possible new alias. Remove old alias. ! 119: ifconfig $interface:0- 0.0.0.0 ! 120: fi ! 121: if [ x$old_ip_address != x ] && [ x$old_ip_address != x$new_ip_address ]; then ! 122: # IP address changed. Bringing down the interface will delete all routes, ! 123: # and clear the ARP cache. ! 124: ifconfig $interface 0.0.0.0 down ! 125: ! 126: fi ! 127: if [ x$old_ip_address = x ] || [ x$old_ip_address != x$new_ip_address ] || \ ! 128: [ x$reason = xBOUND ] || [ x$reason = xREBOOT ]; then ! 129: ! 130: ifconfig $interface $new_ip_address $new_subnet_arg \ ! 131: $new_broadcast_arg $mtu_arg $metric_arg ! 132: for router in $new_routers; do ! 133: if [ "x$new_subnet_mask" = "x255.255.255.255" ] ; then ! 134: route add -host $router dev $interface ! 135: fi ! 136: route add default gw $router ! 137: done ! 138: else ! 139: # we haven't changed the address, have we changed other options ! 140: # that we wish to update? ! 141: if [ x$new_routers != x ] && [ x$new_routers != x$old_routers ] ; then ! 142: # if we've changed routers delete the old and add the new. ! 143: $LOGGER "New Routers: $new_routers" ! 144: for router in $old_routers; do ! 145: route delete default $router ! 146: done ! 147: for router in $new_routers; do ! 148: if [ "x$new_subnet_mask" = "x255.255.255.255" ] ; then ! 149: route add -host $router dev $interface ! 150: fi ! 151: route add default gw $router ! 152: done ! 153: fi ! 154: fi ! 155: if [ x$new_ip_address != x$alias_ip_address ] && [ x$alias_ip_address != x ]; ! 156: then ! 157: ifconfig $interface:0- 0.0.0.0 ! 158: ifconfig $interface:0 $alias_ip_address $alias_subnet_arg ! 159: route add -host $alias_ip_address $interface:0 ! 160: fi ! 161: make_resolv_conf ! 162: exit_with_hooks 0 ! 163: fi ! 164: ! 165: if [ x$reason = xEXPIRE ] || [ x$reason = xFAIL ] || [ x$reason = xRELEASE ] \ ! 166: || [ x$reason = xSTOP ]; then ! 167: if [ x$alias_ip_address != x ]; then ! 168: # Turn off alias interface. ! 169: ifconfig $interface:0- 0.0.0.0 ! 170: fi ! 171: if [ x$old_ip_address != x ]; then ! 172: # Shut down interface, which will delete routes and clear arp cache. ! 173: ifconfig $interface 0.0.0.0 down ! 174: fi ! 175: if [ x$alias_ip_address != x ]; then ! 176: ifconfig $interface:0 $alias_ip_address $alias_subnet_arg ! 177: route add -host $alias_ip_address $interface:0 ! 178: fi ! 179: exit_with_hooks 0 ! 180: fi ! 181: ! 182: if [ x$reason = xTIMEOUT ]; then ! 183: if [ x$alias_ip_address != x ]; then ! 184: ifconfig $interface:0- 0.0.0.0 ! 185: fi ! 186: ifconfig $interface $new_ip_address $new_subnet_arg \ ! 187: $new_broadcast_arg $mtu_arg $metric_arg ! 188: set $new_routers ! 189: if ping -q -c 1 $1; then ! 190: if [ x$new_ip_address != x$alias_ip_address ] && \ ! 191: [ x$alias_ip_address != x ]; then ! 192: ifconfig $interface:0 $alias_ip_address $alias_subnet_arg ! 193: route add -host $alias_ip_address dev $interface:0 ! 194: fi ! 195: for router in $new_routers; do ! 196: if [ "x$new_subnet_mask" = "x255.255.255.255" ] ; then ! 197: route add -host $router dev $interface ! 198: fi ! 199: route add default gw $router ! 200: done ! 201: make_resolv_conf ! 202: exit_with_hooks 0 ! 203: fi ! 204: ifconfig $interface 0.0.0.0 down ! 205: exit_with_hooks 1 ! 206: fi ! 207: ! 208: ### ! 209: ### DHCPv6 Handlers ! 210: ### ! 211: ! 212: if [ x$reason = xPREINIT6 ]; then ! 213: # Ensure interface is up. ! 214: ifconfig ${interface} up ! 215: ! 216: # Remove any stale addresses from aborted clients. ! 217: ip -f inet6 addr flush dev ${interface} scope global ! 218: ! 219: exit_with_hooks 0 ! 220: fi ! 221: ! 222: if [ x${old_ip6_prefix} != x ] || [ x${new_ip6_prefix} != x ] ; then ! 223: echo Prefix ${reason} old=${old_ip6_prefix} new=${new_ip6_prefix} ! 224: ! 225: exit_with_hooks 0 ! 226: fi ! 227: ! 228: if [ x$reason = xBOUND6 ]; then ! 229: if [ x${new_ip6_address} = x ] || [ x${new_ip6_prefixlen} = x ] ; then ! 230: exit_with_hooks 2; ! 231: fi ! 232: ! 233: ifconfig ${interface} inet6 ${new_ip6_address}/${new_ip6_prefixlen} alias ! 234: ! 235: # Check for nameserver options. ! 236: make_resolv_conf ! 237: ! 238: exit_with_hooks 0 ! 239: fi ! 240: ! 241: if [ x$reason = xRENEW6 ] || [ x$reason = xREBIND6 ]; then ! 242: if [ x${new_ip6_address} = x ] || [ x${new_ip6_prefixlen} = x ] ; then ! 243: exit_with_hooks 2; ! 244: fi ! 245: ! 246: ifconfig ${interface} inet6 ${new_ip6_address}/${new_ip6_prefixlen} alias ! 247: ! 248: # Make sure nothing has moved around on us. ! 249: ! 250: # Nameservers/domains/etc. ! 251: if [ "x${new_dhcp6_name_servers}" != "x${old_dhcp6_name_servers}" ] || ! 252: [ "x${new_dhcp6_domain_search}" != "x${old_dhcp6_domain_search}" ] ; then ! 253: make_resolv_conf ! 254: fi ! 255: ! 256: exit_with_hooks 0 ! 257: fi ! 258: ! 259: if [ x$reason = xDEPREF6 ]; then ! 260: if [ x${new_ip6_address} = x ] ; then ! 261: exit_with_hooks 2; ! 262: fi ! 263: ! 264: ifconfig ${interface} inet6 ${new_ip6_address} deprecated ! 265: ! 266: exit_with_hooks 0 ! 267: fi ! 268: ! 269: if [ x$reason = xEXPIRE6 -o x$reason = xRELEASE6 -o x$reason = xSTOP6 ]; then ! 270: if [ x${old_ip6_address} = x ] || [ x${old_ip6_prefixlen} = x ] ; then ! 271: exit_with_hooks 2; ! 272: fi ! 273: ! 274: ifconfig ${interface} inet6 ${old_ip6_address}/${old_ip6_prefixlen} -alias ! 275: ! 276: exit_with_hooks 0 ! 277: fi ! 278: ! 279: exit_with_hooks 0