igmpproxy.init 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. local status="$(ubus -S call "network.interface.$network" status)"
  34. [ -n "$status" ] || return
  35. json_load "$status"
  36. json_get_var device l3_device
  37. json_get_var up up
  38. [ -n "$device" -a "$up" = "1" ] || {
  39. procd_append_param error "$network is not up"
  40. return;
  41. }
  42. [[ "$direction" = "upstream" ]] && has_upstream=1
  43. echo -e "\nphyint $device $direction ratelimit 0 threshold 1" >> /var/etc/igmpproxy.conf
  44. if [ -n "$altnets" ]; then
  45. local altnet
  46. for altnet in $altnets; do
  47. echo -e "\taltnet $altnet" >> /var/etc/igmpproxy.conf
  48. done
  49. fi
  50. }
  51. igmp_add_network() {
  52. local network
  53. config_get network $1 network
  54. procd_add_interface_trigger "interface.*" $network /etc/init.d/igmpproxy restart
  55. }
  56. igmp_add_firewall_routing() {
  57. config_get network $1 network
  58. config_get direction $1 direction
  59. [[ "$direction" = "downstream" ]] || return 0
  60. json_add_object ""
  61. json_add_string type rule
  62. json_add_string src "$upstream"
  63. json_add_string dest "$network"
  64. json_add_string family ipv4
  65. json_add_string proto udp
  66. json_add_string dest_ip "224.0.0.0/4"
  67. json_add_string target ACCEPT
  68. json_close_object
  69. }
  70. igmp_add_firewall_network() {
  71. config_get network $1 network
  72. config_get direction $1 direction
  73. json_add_object ""
  74. json_add_string type rule
  75. json_add_string src "$network"
  76. json_add_string proto igmp
  77. json_add_string target ACCEPT
  78. json_close_object
  79. [[ "$direction" = "upstream" ]] && {
  80. upstream="$network"
  81. config_foreach igmp_add_firewall_routing phyint
  82. }
  83. }
  84. service_triggers() {
  85. procd_add_reload_trigger "igmpproxy"
  86. }
  87. start_service() {
  88. has_upstream=
  89. config_load igmpproxy
  90. config_foreach igmp_header igmpproxy
  91. config_foreach igmp_add_phyint phyint
  92. [ -n "$has_upstream" ] || return
  93. procd_open_instance
  94. procd_set_param command $PROG
  95. [ -n "$OPTIONS" ] && procd_append_param $OPTIONS
  96. procd_append_param command $CONFIGFILE
  97. procd_set_param file $CONFIGFILE
  98. procd_set_param respawn
  99. procd_open_trigger
  100. config_foreach igmp_add_network phyint
  101. procd_close_trigger
  102. procd_open_data
  103. json_add_array firewall
  104. config_foreach igmp_add_firewall_network phyint
  105. json_close_array
  106. procd_close_data
  107. procd_close_instance
  108. }
  109. service_started() {
  110. procd_set_config_changed firewall
  111. }