summaryrefslogtreecommitdiff
path: root/pcr/openrc-net/slpd-init
diff options
context:
space:
mode:
authorfreaj <freaj@riseup.net>2015-03-30 10:36:00 +0200
committerfreaj <freaj@riseup.net>2015-03-30 10:36:00 +0200
commit7385c6143c1b587bca68deade6e5989d11879767 (patch)
tree6ccef2617293e9afd03c80d5de22fd8f9c260c70 /pcr/openrc-net/slpd-init
parent41c9dc8729840f45f174a14a08703e04d1f5717e (diff)
downloadabslibre-7385c6143c1b587bca68deade6e5989d11879767.tar.gz
abslibre-7385c6143c1b587bca68deade6e5989d11879767.tar.bz2
abslibre-7385c6143c1b587bca68deade6e5989d11879767.zip
openrc-net-20150330-1: updating version
Diffstat (limited to 'pcr/openrc-net/slpd-init')
-rw-r--r--pcr/openrc-net/slpd-init89
1 files changed, 89 insertions, 0 deletions
diff --git a/pcr/openrc-net/slpd-init b/pcr/openrc-net/slpd-init
new file mode 100644
index 000000000..bbc0eac1a
--- /dev/null
+++ b/pcr/openrc-net/slpd-init
@@ -0,0 +1,89 @@
+#!/sbin/runscript
+# Copyright 1999-2012 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/net-libs/openslp/files/slpd-init,v 1.5 2012/02/09 08:19:35 robbat2 Exp $
+
+depend() {
+ need net
+}
+
+#
+# Does nothing if a route exists that supports multicast traffic.
+# If no routes supporting multicast traffic exists, the function
+# tries to add one. A 0 is returned on success and a 1 on failure.
+# One parameter must be passed in. This variable determins verbosity.
+# If parameter is non-zero debugging will appear.
+#
+multicast_route_set() {
+ PING_OPTIONS_1='-c1 -w1'
+ PING_OPTIONS_2='-c1 -i1'
+ MULTICAST_ADDRESS='239.255.255.253'
+ TMP_FILE=/tmp/route.check
+ PING_ERROR_NO_ROUTE='unreachable'
+
+ MSG_FAILED_TO_FIND='Failed to Detect Multicast Route'
+ MSG_SUCCESS_ON_FIND='Multicast Route Enabled'
+ MSG_ADDING_ROUTE='Attempting to Add Multicast Route ...'
+ MSG_FAILED_TO_ADD=' FAILED - Route NOT Added.'
+ MSG_SUCCES_ON_ADD=' SUCCESS - Route Added.'
+
+ CMD_GET_INTERFACE="netstat -i | awk 'BEGIN{}(NR>2)&&(!/^lo*/){print \$1;exit}'"
+ CMD_ADD_ROUTE="route add -net 224.0.0.0 netmask 240.0.0.0"
+
+ ping $PING_OPTIONS_1 $MULTICAST_ADDRESS 2> $TMP_FILE 1> /dev/null
+ if [ $? = 2 ]; then
+ ping $PING_OPTIONS_2 $MULTICAST_ADDRESS 2> $TMP_FILE 1> /dev/null
+ fi
+
+ grep $PING_ERROR_NO_ROUTE $TMP_FILE > /dev/null 2>&1
+ err_unreachable_found=$?
+
+ #If errors, add route. Otherwise, do nothing
+ if [ -s $TMP_FILE ] && [ $err_unreachable_found = 0 ]; then
+
+ if [ $1 != 0 ]; then
+ echo $MSG_FAILED_TO_FIND
+ echo $MSG_ADDING_ROUTE
+ fi
+
+ $CMD_ADD_ROUTE `eval $CMD_GET_INTERFACE` > /dev/null 2>&1
+ retval=$?
+ if [ $1 != 0 ]; then
+
+ if [ $retval = 0 ]; then
+ echo $MSG_SUCCES_ON_ADD
+ else
+ echo $MSG_FAILED_TO_ADD
+ fi
+ fi
+ else
+ if [ $1 != 0 ]; then
+ echo -n $MSG_SUCCESS_ON_FIND
+ fi
+ retval=0
+ fi
+
+ rm -f $TMP_FILE # Clean up
+ return $retval
+}
+
+checkconfig() {
+ multicast_route_set 0
+ if [ $? -ne 0 ]; then
+ eerror "No route available for multicast traffic!"
+ return 1
+ fi
+}
+
+start() {
+ checkconfig || return 1
+ ebegin "Starting slpd"
+ start-stop-daemon --start --quiet --exec /usr/sbin/slpd --pidfile /var/run/slpd.pid
+ eend $?
+}
+
+stop() {
+ ebegin "Stopping slpd"
+ start-stop-daemon --stop --quiet --pidfile /var/run/slpd.pid
+ eend $?
+}