igmpproxy.init 3.3 KB

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