SHARE
TWEET

diff for Freifunk dnsmasq startup script

jcomeau_ictx Jul 17th, 2013 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. jcomeau@aspire:~/rentacoder/jcomeau/freifunk$ bzr diff -r669 S50dnsmasq
  2. === modified file 'freifunk/S50dnsmasq'
  3. --- freifunk/S50dnsmasq 2013-07-16 22:48:48 +0000
  4. +++ freifunk/S50dnsmasq 2013-07-17 03:17:26 +0000
  5. @@ -1,5 +1,38 @@
  6.  #!/bin/sh
  7. -
  8. +inet_ntoa() {
  9. + # convert numeric address to dotted octet representation
  10. + # remember ash uses signed integers so trim sign bit!
  11. + a=$(((($1 >> 1) & 0x7fffffff) >> 23))
  12. + b=$((($1 & 0x00ff0000) >> 16))
  13. + c=$((($1 & 0x0000ff00) >> 8))
  14. + d=$(($1 & 0x000000ff))
  15. + echo $a.$b.$c.$d
  16. +}
  17. +inet_aton() {
  18. + # convert dotted octet notation to integer
  19. + n=0
  20. + shift=24
  21. + for octet in 1 2 3 4; do
  22. +  m=$(echo $1 | cut -d. -f$octet)
  23. +  n=$(($n | ($m << $shift)))
  24. +  shift=$((shift - 8))
  25. + done
  26. + printf 0x%x $n
  27. +}
  28. +inet_test_functions() {
  29. + exit_status=0
  30. + for address in 0.0.0.0 1.2.3.4 255.254.253.252 255.255.255.255; do
  31. +  number=$(inet_aton $address)
  32. +  check=$(inet_ntoa $number)
  33. +  if [ "$check" != "$address" ]; then
  34. +   echo "Failed: $check != $address ($number)" >&2
  35. +   exit_status=1
  36. +  fi
  37. + done
  38. +}
  39. +calc_ip() {  # ipcalc without the preassigned variable names
  40. +       ipcalc $* | cut -s -d= -f2-  # trailing - means "any remaining fields"
  41. +}
  42.  write_config()
  43.  {
  44.         cat>/var/etc/dnsmasq.conf<<EOF
  45. @@ -39,20 +72,18 @@
  46.                 echo "dhcp-range=wired,$DHCPNET.$DHCPBEG,$DHCPNET.$DHCPEND,$LANMSK,$DHCPLEASE">>/var/etc/dnsmasq.conf
  47.         ;;esac
  48.  
  49. -       WLDHCP=$(nvram get ff_wldhcp)
  50. +       WLDHCP=$(nvram get ff_wldhcp | sed 's/,/:/g')
  51.         IFS=\;
  52.         for ENT in $WLDHCP; do
  53. -               NET=${ENT%[:,]*}
  54. -               MSK=${ENT#*[:,]}
  55. -               case $NET in "");;*)case $MSK in "");;*)
  56. -                       DHCPLEASE=2h
  57. -                       DHCPBEG=$(ipcalc -n $NET|cut -d'.' -f4)
  58. -                       DHCPBEG=$(( $DHCPBEG + 2 ))
  59. -                       DHCPEND=$(ipcalc -b $NET|cut -d'.' -f4)
  60. -                       DHCPEND=$(( $DHCPEND - 1 ))
  61. -                       DHCPNET=$(ipcalc -n $NET|cut -d'=' -f2|cut -d'.' -f1-3)
  62. -                       echo "dhcp-range=wlnat,$DHCPNET.$DHCPBEG,$DHCPNET.$DHCPEND,$MSK,$DHCPLEASE">>/var/etc/dnsmasq.conf
  63. -               ;;esac;;esac
  64. +               DHCPBEG=${ENT%%[/:]*}
  65. +               [ -z "$DHCPBEG" ] && continue
  66. +               SUBNET=$(echo $ENT | cut -s -d/ -f2 | cut -d: -f1)
  67. +               [ -z "$SUBNET" ] && SUBNET=32
  68. +               MSK=$(echo $ENT | cut -s -d: -f2)
  69. +               [ -z "$MSK" ] && MSK=$(calc_ip -n 255.255.255.255/$SUBNET)
  70. +               DHCPLEASE=2h
  71. +               DHCPEND=$(inet_ntoa $(($(inet_aton $(calc_ip -b $DHCPBEG/$SUBNET)) - 1)))
  72. +               echo "dhcp-range=wlnat,$DHCPBEG,$DHCPEND,$MSK,$DHCPLEASE">>/var/etc/dnsmasq.conf
  73.         done
  74.  
  75.         WAN_HOSTNAME=$(nvram get wan_hostname)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top