script.sh 1.0 KB

1234567891011121314151617181920212223242526
  1. #!/bin/sh
  2. # This script adds and removes routes in the Linux kernel whenever a DHCP client
  3. # gets a lease or a lease expires.
  4. # Protocol to use in "ip route"
  5. PROTO=static
  6. case "$1" in
  7. "lease4_select")
  8. # Only add route if FAKE_ALLOCATION is set to 0
  9. [ "${KEA_FAKE_ALLOCATION}" = "0" ] || break
  10. ip route replace "${KEA_LEASE4_ADDRESS}"/32 dev "${KEA_QUERY4_INTERFACE}" proto "${PROTO}"
  11. ;;
  12. "lease4_renew")
  13. ip route replace "${KEA_LEASE4_ADDRESS}"/32 dev "${KEA_QUERY4_INTERFACE}" proto "${PROTO}"
  14. ;;
  15. "lease4_release"|"lease4_expire")
  16. ip route del "${KEA_LEASE4_ADDRESS}"/32 proto "${PROTO}"
  17. ;;
  18. "lease4_decline")
  19. echo "$(date -R): received DHCPDECLINE on ${KEA_QUERY4_INTERFACE} from ${KEA_QUERY4_HWADDR} about ${KEA_LEASE4_ADDRESS}." >&2
  20. echo "Probably a duplicate IP assignment, not removing any route." >&2
  21. echo "Existing route for this IP: $(ip route show ${KEA_LEASE4_ADDRESS})" >&2
  22. echo "Existing ARP entry for this IP: $(ip neigh show ${KEA_LEASE4_ADDRESS})" >&2
  23. ;;
  24. esac