Merge commit 'opendreambox/opendreambox-1.6' into vuplus-1.6
[vuplus_openembedded] / recipes / netbase / netbase / vusolo / init
1 #!/bin/sh
2 #
3 # manage network interfaces and configure some networking options
4
5 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
6
7 if ! [ -x /sbin/ifup ]; then
8     exit 0
9 fi
10
11 spoofprotect_rp_filter () {
12     # This is the best method: turn on Source Address Verification and get
13     # spoof protection on all current and future interfaces.
14     
15     if [ -e /proc/sys/net/ipv4/conf/all/rp_filter ]; then
16         for f in /proc/sys/net/ipv4/conf/*; do
17             [ -e $f/rp_filter ] && echo 1 > $f/rp_filter
18         done
19         return 0
20     else
21         return 1
22     fi
23 }
24
25 spoofprotect () {
26     echo -n "Setting up IP spoofing protection: "
27     if spoofprotect_rp_filter; then
28         echo "rp_filter."
29     else
30         echo "FAILED."
31     fi
32 }
33
34 ip_forward () {
35     if [ -e /proc/sys/net/ipv4/ip_forward ]; then
36         echo -n "Enabling packet forwarding... "
37         echo 1 > /proc/sys/net/ipv4/ip_forward
38         echo "done."
39     fi
40 }
41
42 syncookies () {
43     if [ -e /proc/sys/net/ipv4/tcp_syncookies ]; then
44         echo -n "Enabling TCP/IP SYN cookies... "
45         echo 1 > /proc/sys/net/ipv4/tcp_syncookies
46         echo "done."
47     fi
48 }
49
50 wpa_supplicantcheck () {
51     if [ -e /var/run/wpa_supplicant ]; then
52         echo -n "disabling wpa_supplicant "
53         start-stop-daemon -K -x /usr/sbin/wpa_supplicant
54         # HACK: wpa_supplicant sometimes doesn't quit properly on SIGTERM.
55         if [ -e /var/run/wpa_supplicant ]; then
56                 echo -n "wpa_supplicant still running, force kill now.. "
57                 killall -9 /usr/sbin/wpa_supplicant
58                 rm -rf /var/run/wpa_supplicant
59                 echo "done."
60                 fi
61         echo "done."
62     fi
63 }
64
65 doopt () {
66     optname=$1
67     default=$2
68     opt=`grep "^$optname=" /etc/network/options`
69     if [ -z "$opt" ]; then
70         opt="$optname=$default"
71     fi
72     optval=${opt#$optname=}
73     if [ "$optval" = "yes" ]; then
74         eval $optname
75     fi
76 }
77
78 case "$1" in
79     start)
80         doopt spoofprotect yes
81         doopt syncookies no
82         doopt ip_forward no
83
84         echo -n "Configuring network interfaces... "
85                                 wpa_supplicantcheck
86         ifup -a
87         echo "done."
88         ;;
89     stop)
90         if sed -n 's/^[^ ]* \([^ ]*\) \([^ ]*\) .*$/\1 \2/p' /proc/mounts | 
91           grep -q "^/ nfs$"; then
92             echo "NOT deconfiguring network interfaces: / is an NFS mount"
93         elif sed -n 's/^[^ ]* \([^ ]*\) \([^ ]*\) .*$/\1 \2/p' /proc/mounts |  
94           grep -q "^/ smbfs$"; then
95             echo "NOT deconfiguring network interfaces: / is an SMB mount"
96         elif sed -n 's/^[^ ]* \([^ ]*\) \([^ ]*\) .*$/\2/p' /proc/mounts | 
97           grep -qE '^(nfs|smbfs|ncp|coda)$'; then
98             echo "NOT deconfiguring network interfaces: network shares still mounted."
99         else
100             echo -n "Deconfiguring network interfaces... "
101             ifdown -a
102             wpa_supplicantcheck
103             echo "done."
104         fi
105         ;;
106     force-reload|restart)
107         echo -n "Reconfiguring network interfaces... "
108         ifdown -a
109         wpa_supplicantcheck
110         ifup -a
111         echo "done."
112         ;;
113     *)
114         echo "Usage: /etc/init.d/networking {start|stop|restart|force-reload}"
115         exit 1
116         ;;
117 esac
118
119 exit 0
120