Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jcomeau@aspire:~/rentacoder/jcomeau/freifunk$ bzr diff -r669 S50dnsmasq
- === modified file 'freifunk/S50dnsmasq'
- --- freifunk/S50dnsmasq 2013-07-16 22:48:48 +0000
- +++ freifunk/S50dnsmasq 2013-07-17 03:17:26 +0000
- @@ -1,5 +1,38 @@
- #!/bin/sh
- -
- +inet_ntoa() {
- + # convert numeric address to dotted octet representation
- + # remember ash uses signed integers so trim sign bit!
- + a=$(((($1 >> 1) & 0x7fffffff) >> 23))
- + b=$((($1 & 0x00ff0000) >> 16))
- + c=$((($1 & 0x0000ff00) >> 8))
- + d=$(($1 & 0x000000ff))
- + echo $a.$b.$c.$d
- +}
- +inet_aton() {
- + # convert dotted octet notation to integer
- + n=0
- + shift=24
- + for octet in 1 2 3 4; do
- + m=$(echo $1 | cut -d. -f$octet)
- + n=$(($n | ($m << $shift)))
- + shift=$((shift - 8))
- + done
- + printf 0x%x $n
- +}
- +inet_test_functions() {
- + exit_status=0
- + for address in 0.0.0.0 1.2.3.4 255.254.253.252 255.255.255.255; do
- + number=$(inet_aton $address)
- + check=$(inet_ntoa $number)
- + if [ "$check" != "$address" ]; then
- + echo "Failed: $check != $address ($number)" >&2
- + exit_status=1
- + fi
- + done
- +}
- +calc_ip() { # ipcalc without the preassigned variable names
- + ipcalc $* | cut -s -d= -f2- # trailing - means "any remaining fields"
- +}
- write_config()
- {
- cat>/var/etc/dnsmasq.conf<<EOF
- @@ -39,20 +72,18 @@
- echo "dhcp-range=wired,$DHCPNET.$DHCPBEG,$DHCPNET.$DHCPEND,$LANMSK,$DHCPLEASE">>/var/etc/dnsmasq.conf
- ;;esac
- - WLDHCP=$(nvram get ff_wldhcp)
- + WLDHCP=$(nvram get ff_wldhcp | sed 's/,/:/g')
- IFS=\;
- for ENT in $WLDHCP; do
- - NET=${ENT%[:,]*}
- - MSK=${ENT#*[:,]}
- - case $NET in "");;*)case $MSK in "");;*)
- - DHCPLEASE=2h
- - DHCPBEG=$(ipcalc -n $NET|cut -d'.' -f4)
- - DHCPBEG=$(( $DHCPBEG + 2 ))
- - DHCPEND=$(ipcalc -b $NET|cut -d'.' -f4)
- - DHCPEND=$(( $DHCPEND - 1 ))
- - DHCPNET=$(ipcalc -n $NET|cut -d'=' -f2|cut -d'.' -f1-3)
- - echo "dhcp-range=wlnat,$DHCPNET.$DHCPBEG,$DHCPNET.$DHCPEND,$MSK,$DHCPLEASE">>/var/etc/dnsmasq.conf
- - ;;esac;;esac
- + DHCPBEG=${ENT%%[/:]*}
- + [ -z "$DHCPBEG" ] && continue
- + SUBNET=$(echo $ENT | cut -s -d/ -f2 | cut -d: -f1)
- + [ -z "$SUBNET" ] && SUBNET=32
- + MSK=$(echo $ENT | cut -s -d: -f2)
- + [ -z "$MSK" ] && MSK=$(calc_ip -n 255.255.255.255/$SUBNET)
- + DHCPLEASE=2h
- + DHCPEND=$(inet_ntoa $(($(inet_aton $(calc_ip -b $DHCPBEG/$SUBNET)) - 1)))
- + echo "dhcp-range=wlnat,$DHCPBEG,$DHCPEND,$MSK,$DHCPLEASE">>/var/etc/dnsmasq.conf
- done
- WAN_HOSTNAME=$(nvram get wan_hostname)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement