slpd-init 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/sbin/runscript
  2. # Copyright © 2005 TUBITAK/UEKAE
  3. # Licensed under the GNU General Public License, version 2.
  4. # See the file http://www.gnu.org/copyleft/gpl.txt.
  5. #
  6. # Original work belongs Gentoo Linux
  7. depend() {
  8. need net
  9. }
  10. #
  11. # Does nothing if a route exists that supports multicast traffic.
  12. # If no routes supporting multicast traffic exists, the function
  13. # tries to add one. A 0 is returned on success and a 1 on failure.
  14. # One parameter must be passed in. This variable determins verbosity.
  15. # If parameter is non-zero debugging will appear.
  16. #
  17. multicast_route_set() {
  18. PING_OPTIONS_1='-c1 -w1'
  19. PING_OPTIONS_2='-c1 -i1'
  20. MULTICAST_ADDRESS='239.255.255.253'
  21. TMP_FILE=/tmp/route.check
  22. PING_ERROR_NO_ROUTE='unreachable'
  23. MSG_FAILED_TO_FIND='Failed to Detect Multicast Route'
  24. MSG_SUCCESS_ON_FIND='Multicast Route Enabled'
  25. MSG_ADDING_ROUTE='Attempting to Add Multicast Route ...'
  26. MSG_FAILED_TO_ADD=' FAILED - Route NOT Added.'
  27. MSG_SUCCES_ON_ADD=' SUCCESS - Route Added.'
  28. CMD_GET_INTERFACE="netstat -i | awk 'BEGIN{}(NR>2)&&(!/^lo*/){print \$1}'"
  29. CMD_ADD_ROUTE="route add -net 224.0.0.0 netmask 240.0.0.0"
  30. ping $PING_OPTIONS_1 $MULTICAST_ADDRESS 2> $TMP_FILE 1> /dev/null
  31. if [ $? = 2 ]; then
  32. ping $PING_OPTIONS_2 $MULTICAST_ADDRESS 2> $TMP_FILE 1> /dev/null
  33. fi
  34. grep $PING_ERROR_NO_ROUTE $TMP_FILE > /dev/null 2>&1
  35. err_unreachable_found=$?
  36. #If errors, add route. Otherwise, do nothing
  37. if [ -s $TMP_FILE ] && [ $err_unreachable_found = 0 ]; then
  38. if [ $1 != 0 ]; then
  39. echo $MSG_FAILED_TO_FIND
  40. echo $MSG_ADDING_ROUTE
  41. fi
  42. $CMD_ADD_ROUTE `eval $CMD_GET_INTERFACE` > /dev/null 2>&1
  43. retval=$?
  44. if [ $1 != 0 ]; then
  45. if [ $retval = 0 ]; then
  46. echo $MSG_SUCCES_ON_ADD
  47. else
  48. echo $MSG_FAILED_TO_ADD
  49. fi
  50. fi
  51. else
  52. if [ $1 != 0 ]; then
  53. echo -n $MSG_SUCCESS_ON_FIND
  54. fi
  55. retval=0
  56. fi
  57. rm -f $TMP_FILE # Clean up
  58. return $retval
  59. }
  60. checkconfig() {
  61. multicast_route_set 0
  62. if [ $? -ne 0 ]; then
  63. eerror "No route available for multicast traffic!"
  64. return 1
  65. fi
  66. }
  67. start() {
  68. checkconfig || return 1
  69. ebegin "Starting slpd"
  70. start-stop-daemon --start --quiet --background --exec /usr/sbin/slpd
  71. eend $?
  72. }
  73. stop() {
  74. ebegin "Stopping slpd"
  75. start-stop-daemon --stop --quiet --pidfile /run/slpd.pid
  76. eend $?
  77. }