011-freifunk-network 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/sh
  2. . /lib/ar71xx.sh
  3. local lan_ifname="$(uci get network.lan.ifname)"
  4. local board="$(ar71xx_board_name)"
  5. uci -q batch <<EOF
  6. delete network.lan
  7. set network.wan.type='bridge'
  8. set network.wan.proto='dhcp'
  9. set network.wan.accept_ra='0'
  10. set network.wan.auto='1'
  11. set network.freifunk='interface'
  12. set network.freifunk.ifname='$lan_ifname bat0'
  13. set network.freifunk.type='bridge'
  14. set network.freifunk.proto='none'
  15. set network.freifunk.auto='1'
  16. set network.freifunk.accept_ra='1'
  17. set network.mesh='interface'
  18. set network.mesh.proto='batadv'
  19. set network.mesh.mtu='1528'
  20. set network.mesh.mesh='bat0'
  21. set network.mesh_vpn='interface'
  22. set network.mesh_vpn.ifname='mesh-vpn'
  23. set network.mesh_vpn.proto='batadv'
  24. set network.mesh_vpn.mesh='bat0'
  25. EOF
  26. get_main_address() {
  27. case "$board" in
  28. tl-wdr3600|tl-wdr4300)
  29. uci get wireless.radio1.macaddr
  30. ;;
  31. *)
  32. uci get wireless.radio0.macaddr
  33. ;;
  34. esac
  35. }
  36. local mainaddr=$(get_main_address)
  37. local oIFS="$IFS"; IFS=":"; set -- $mainaddr; IFS="$oIFS"
  38. local b2mask=0x02
  39. local vpnaddr=$(printf "%02x:%s:%s:%02x:%s:%s" $(( 0x$1 | $b2mask )) $2 $3 $(( (0x$4 + 1) % 0x100 )) $5 $6)
  40. uci set network.freifunk.macaddr="$mainaddr"
  41. uci set network.mesh_vpn.macaddr="$vpnaddr"
  42. case "$board" in
  43. tl-wr1043nd|\
  44. tl-wdr3600|\
  45. tl-wdr4300) # fix up duplicate mac addresses
  46. local wanaddr=$(printf "%02x:%s:%s:%02x:%s:%02x" $(( 0x$1 | $b2mask )) $2 $3 $(( (0x$4 + 1) % 0x100 )) $5 $(( (0x$6 + 1) % 0x100 )) )
  47. uci set network.wan.macaddr="$wanaddr"
  48. ;;
  49. esac
  50. uci commit network