igmpproxy.init 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. # igmpproxy supports both a debug mode and verbosity, which are very useful
  8. # when something isn't working.
  9. #
  10. # Debug mode will print everything to stdout instead of syslog. Generally
  11. # verbosity should NOT be set as it will quickly fill your syslog.
  12. #
  13. # Put any debug or verbosity options into IGMP_OPTS
  14. #
  15. # Examples:
  16. # OPTIONS="-d -v -v" - debug mode and very verbose, this will land in
  17. # stdout and not in syslog
  18. # OPTIONS="-v" - be verbose, this will write aditional information to syslog
  19. OPTIONS=""
  20. igmp_header() {
  21. local quickleave
  22. config_get_bool quickleave "$1" quickleave 0
  23. mkdir -p /var/etc
  24. rm -f /var/etc/igmpproxy.conf
  25. [ $quickleave -gt 0 ] && echo "quickleave" >> /var/etc/igmpproxy.conf
  26. [ -L /etc/igmpproxy.conf ] || ln -nsf /var/etc/igmpproxy.conf /etc/igmpproxy.conf
  27. }
  28. igmp_add_phyint() {
  29. local network direction altnets device up
  30. config_get network $1 network
  31. config_get direction $1 direction
  32. config_get altnets $1 altnet
  33. json_load "$(ifstatus $network)"
  34. json_get_var device l3_device
  35. json_get_var up up
  36. [ -n "$device" -a "$up" = "1" ] || {
  37. procd_append_param error "$network is not up"
  38. return;
  39. }
  40. echo -e "\nphyint $device $direction ratelimit 0 threshold 1" >> /var/etc/igmpproxy.conf
  41. if [ -n "$altnets" ]; then
  42. local altnet
  43. for altnet in $altnets; do
  44. echo -e "\taltnet $altnet" >> /var/etc/igmpproxy.conf
  45. done
  46. fi
  47. }
  48. igmp_add_network() {
  49. local network
  50. config_get network $1 network
  51. procd_add_interface_trigger "interface.*" $network /etc/init.d/igmpproxy restart
  52. }
  53. igmp_add_firewall_routing() {
  54. config_get network $1 network
  55. config_get direction $1 direction
  56. [[ "$direction" = "downstream" ]] || return 0
  57. json_add_object ""
  58. json_add_string type rule
  59. json_add_string src "$upstream"
  60. json_add_string dest "$network"
  61. json_add_string family ipv4
  62. json_add_string proto udp
  63. json_add_string dest_ip "224.0.0.0/4"
  64. json_add_string target ACCEPT
  65. json_close_object
  66. }
  67. igmp_add_firewall_network() {
  68. config_get network $1 network
  69. config_get direction $1 direction
  70. json_add_object ""
  71. json_add_string type rule
  72. json_add_string src "$network"
  73. json_add_string proto igmp
  74. json_add_string target ACCEPT
  75. json_close_object
  76. [[ "$direction" = "upstream" ]] && {
  77. upstream="$network"
  78. config_foreach igmp_add_firewall_routing phyint
  79. }
  80. }
  81. service_triggers() {
  82. procd_add_reload_trigger "igmpproxy"
  83. }
  84. start_service() {
  85. config_load igmpproxy
  86. procd_open_instance
  87. config_foreach igmp_header igmpproxy
  88. config_foreach igmp_add_phyint phyint
  89. procd_set_param command $PROG
  90. [ -n "$OPTIONS" ] && procd_append_param $OPTIONS
  91. procd_append_param command $CONFIGFILE
  92. procd_set_param file $CONFIGFILE
  93. procd_set_param respawn
  94. procd_open_trigger
  95. config_foreach igmp_add_network phyint
  96. procd_close_trigger
  97. procd_open_data
  98. json_add_array firewall
  99. config_foreach igmp_add_firewall_network phyint
  100. json_close_array
  101. procd_close_data
  102. procd_close_instance
  103. }
  104. service_started() {
  105. procd_set_config_changed firewall
  106. }