adec18f626952334eee1ab7de6cdcf587184c4f2
[ipfw.git] / planetlab / ipfw
1 #!/bin/sh
2 #
3 # ipfw  init the emulation service
4 #
5 # chkconfig: 2345 09 91
6 # description: ipfw init and shutdown
7 #
8
9 # Source function library.
10 . /etc/init.d/functions
11
12 IPFW=ipfw
13 IPFW_BACKEND=/vsys/ipfw-be
14 IPFW_MOD=ipfw_mod
15
16 if [ ! -x /sbin/$IPFW ] || [ ! -x ${IPFW_BACKEND} ]; then
17     echo -n "/sbin/$IPFW does not exist."; warning; echo
18     exit 0
19 fi
20
21 # Load the ipfw module, and initialize netconfig
22 start() {
23         # load the module
24         modprobe $IPFW_MOD > /dev/null 2> /dev/null
25         let ret=$?;
26         [ $ret -eq 0 ] && success || failure
27
28         # init netconfig
29         echo "super dbcleanup" | ${IPFW_BACKEND} root > /dev/null 2> /dev/null
30         echo "super init" | ${IPFW_BACKEND} root > /dev/null 2> /dev/null
31
32         return $ret
33 }
34
35 stop() {
36         # clean netconfig stuff
37         echo "super dbcleanup" | ${IPFW_BACKEND} root > /dev/null 2> /dev/null
38         echo "Unloading $IPFW_MOD module: "
39
40         # unload the ipfw module
41         rmmod ${IPFW_MOD}
42         let ret=$?;
43         [ $ret -eq 0 ] && success || failure
44
45         return $ret
46 }
47
48 # echo the ipfw status
49 status() {
50         # check for module presence
51         LOADED=`cat /proc/modules | grep ^ipfw_mod`
52         [ ! -n "$LOADED" ] && echo "ipfw not loaded" && return 0
53
54         # Show active users
55         USERS=`cat /tmp/ff | grep BLOCK | wc -l`
56         echo "ipfw is loaded and there are currently ${USERS} with active emulation."
57         return 0
58 }
59
60 # main
61 case "$1" in
62     start)
63         start
64         RETVAL=$?
65         ;;
66     stop)
67         stop
68         RETVAL=$?
69         ;;
70     restart)
71         stop
72         start
73         RETVAL=$?
74         ;;
75     status)
76         status
77         RETVAL=$?
78         ;;
79     *)
80         echo $"Usage: $0 {start|stop|restart|status}"
81         exit 1
82         ;;
83 esac
84
85 exit $RETVAL