23-restricted-wan 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/bin/sh
  2. clear_restricted_gw()
  3. {
  4. local state="$1"
  5. local iface
  6. local ifname
  7. local subnet
  8. config_get iface "$state" iface
  9. if [ "$iface" = "$INTERFACE" ]; then
  10. config_get ifname "$state" ifname
  11. config_get subnet "$state" subnet
  12. logger -t firewall.freifunk "removing local restriction to the network connected to $ifname ($iface)"
  13. iptables -D forwarding_freifunk_rule -o $ifname -d $subnet -j REJECT --reject-with icmp-host-prohibited
  14. uci_revert_state firewall "$state"
  15. fi
  16. }
  17. get_enabled()
  18. {
  19. local name
  20. config_get name "$1" name
  21. if [ "$name" = "$ZONE" ]; then
  22. config_get_bool local_restrict "$1" local_restrict
  23. fi
  24. }
  25. if [ "$ACTION" = add ]; then
  26. local enabled
  27. local subnet
  28. . /lib/functions/network.sh
  29. network_find_wan wan
  30. [ "$INTERFACE" = "$wan" ] || return 0
  31. network_get_subnet subnet $INTERFACE
  32. if [ -n "$subnet" ]; then
  33. config_load firewall
  34. local_restrict=0
  35. config_foreach get_enabled zone
  36. if [ "$local_restrict" = 1 ]; then
  37. logger -t firewall.freifunk "restricting local access to the network connected to $INTERFACE ($DEVICE)"
  38. iptables -I forwarding_freifunk_rule -o $DEVICE -d $subnet -j REJECT --reject-with icmp-host-prohibited
  39. local state="restricted_gw_${INTERFACE}"
  40. uci_set_state firewall "$state" "" restricted_gw_state
  41. uci_set_state firewall "$state" iface "$INTERFACE"
  42. uci_set_state firewall "$state" ifname "$DEVICE"
  43. uci_set_state firewall "$state" subnet "$subnet"
  44. fi
  45. fi
  46. elif [ "$ACTION" = remove ]; then
  47. config_load firewall
  48. config_foreach clear_restricted_gw restricted_gw_state
  49. fi