You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

156 lines
3.4 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2010-2014 OpenWrt.org
  3. START=99
  4. USE_PROCD=1
  5. PROG=/usr/sbin/igmpproxy
  6. CONFIGFILE=/var/etc/igmpproxy.conf
  7. igmp_header() {
  8. local quickleave verbose
  9. config_get_bool quickleave "$1" quickleave 0
  10. config_get verbose "$1" verbose 1
  11. [ $verbose = "0" ] && logopts="-d"
  12. [ $verbose = "2" ] && logopts="-v"
  13. [ $verbose = "3" ] && logopts="-v -v"
  14. mkdir -p /var/etc
  15. rm -f /var/etc/igmpproxy.conf
  16. [ $quickleave -gt 0 ] && echo "quickleave" >> /var/etc/igmpproxy.conf
  17. [ -L /etc/igmpproxy.conf ] || ln -nsf /var/etc/igmpproxy.conf /etc/igmpproxy.conf
  18. }
  19. igmp_add_phyint() {
  20. local network direction altnets device up
  21. config_get network $1 network
  22. config_get direction $1 direction
  23. config_get altnets $1 altnet
  24. local status="$(ubus -S call "network.interface.$network" status)"
  25. [ -n "$status" ] || return
  26. json_load "$status"
  27. json_get_var device l3_device
  28. json_get_var up up
  29. [ -n "$device" -a "$up" = "1" ] || {
  30. procd_append_param error "$network is not up"
  31. return;
  32. }
  33. append netdevs "$device"
  34. [ "$direction" = "upstream" ] && has_upstream=1
  35. echo -e "\nphyint $device $direction ratelimit 0 threshold 1" >> /var/etc/igmpproxy.conf
  36. if [ -n "$altnets" ]; then
  37. local altnet
  38. for altnet in $altnets; do
  39. echo -e "\taltnet $altnet" >> /var/etc/igmpproxy.conf
  40. done
  41. fi
  42. }
  43. igmp_add_network() {
  44. local network
  45. config_get network $1 network
  46. procd_add_interface_trigger "interface.*" $network /etc/init.d/igmpproxy reload
  47. }
  48. igmp_add_firewall_routing() {
  49. config_get direction $1 direction
  50. config_get zone $1 zone
  51. if [ "$direction" != "downstream" ] || [ -z "$zone" ]; then
  52. return 0
  53. fi
  54. # First drop SSDP packets then accept all other multicast
  55. json_add_object ""
  56. json_add_string type rule
  57. json_add_string src "$upstream"
  58. json_add_string dest "$zone"
  59. json_add_string family ipv4
  60. json_add_string proto udp
  61. json_add_string dest_ip "239.255.255.250"
  62. json_add_string target DROP
  63. json_close_object
  64. json_add_object ""
  65. json_add_string type rule
  66. json_add_string src "$upstream"
  67. json_add_string dest "$zone"
  68. json_add_string family ipv4
  69. json_add_string proto udp
  70. json_add_string dest_ip "224.0.0.0/4"
  71. json_add_string target ACCEPT
  72. json_close_object
  73. }
  74. igmp_add_firewall_network() {
  75. config_get direction $1 direction
  76. config_get zone $1 zone
  77. [ ! -z "$zone" ] || return
  78. json_add_object ""
  79. json_add_string type rule
  80. json_add_string src "$zone"
  81. json_add_string family ipv4
  82. json_add_string proto igmp
  83. json_add_string target ACCEPT
  84. json_close_object
  85. [ "$direction" = "upstream" ] && {
  86. upstream="$zone"
  87. config_foreach igmp_add_firewall_routing phyint
  88. }
  89. }
  90. service_triggers() {
  91. procd_add_reload_trigger "igmpproxy"
  92. config_foreach igmp_add_network phyint
  93. }
  94. start_service() {
  95. has_upstream=
  96. netdevs=
  97. logopts=
  98. config_load igmpproxy
  99. config_foreach igmp_header igmpproxy
  100. config_foreach igmp_add_phyint phyint
  101. [ -n "$has_upstream" ] || return
  102. procd_open_instance
  103. procd_set_param command $PROG '-n'
  104. [ -n "$logopts" ] && procd_append_param command $logopts
  105. procd_append_param command $CONFIGFILE
  106. procd_set_param file $CONFIGFILE
  107. procd_set_param netdev $netdevs
  108. procd_set_param respawn
  109. procd_open_data
  110. json_add_array firewall
  111. config_foreach igmp_add_firewall_network phyint
  112. json_close_array
  113. procd_close_data
  114. procd_close_instance
  115. }
  116. service_started() {
  117. procd_set_config_changed firewall
  118. }
  119. stop_service() {
  120. procd_set_config_changed firewall
  121. }