diff options
Diffstat (limited to 'meta/packages/netbase/netbase/init')
-rw-r--r-- | meta/packages/netbase/netbase/init | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/meta/packages/netbase/netbase/init b/meta/packages/netbase/netbase/init new file mode 100644 index 0000000000..8d6b9aa426 --- /dev/null +++ b/meta/packages/netbase/netbase/init | |||
@@ -0,0 +1,102 @@ | |||
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 | doopt () { | ||
51 | optname=$1 | ||
52 | default=$2 | ||
53 | opt=`grep "^$optname=" /etc/network/options` | ||
54 | if [ -z "$opt" ]; then | ||
55 | opt="$optname=$default" | ||
56 | fi | ||
57 | optval=${opt#$optname=} | ||
58 | if [ "$optval" = "yes" ]; then | ||
59 | eval $optname | ||
60 | fi | ||
61 | } | ||
62 | |||
63 | case "$1" in | ||
64 | start) | ||
65 | doopt spoofprotect yes | ||
66 | doopt syncookies no | ||
67 | doopt ip_forward no | ||
68 | |||
69 | echo -n "Configuring network interfaces... " | ||
70 | ifup -a | ||
71 | echo "done." | ||
72 | ;; | ||
73 | stop) | ||
74 | if sed -n 's/^[^ ]* \([^ ]*\) \([^ ]*\) .*$/\1 \2/p' /proc/mounts | | ||
75 | grep -q "^/ nfs$"; then | ||
76 | echo "NOT deconfiguring network interfaces: / is an NFS mount" | ||
77 | elif sed -n 's/^[^ ]* \([^ ]*\) \([^ ]*\) .*$/\1 \2/p' /proc/mounts | | ||
78 | grep -q "^/ smbfs$"; then | ||
79 | echo "NOT deconfiguring network interfaces: / is an SMB mount" | ||
80 | elif sed -n 's/^[^ ]* \([^ ]*\) \([^ ]*\) .*$/\2/p' /proc/mounts | | ||
81 | grep -qE '^(nfs|smbfs|ncp|coda)$'; then | ||
82 | echo "NOT deconfiguring network interfaces: network shares still mounted." | ||
83 | else | ||
84 | echo -n "Deconfiguring network interfaces... " | ||
85 | ifdown -a | ||
86 | echo "done." | ||
87 | fi | ||
88 | ;; | ||
89 | force-reload|restart) | ||
90 | echo -n "Reconfiguring network interfaces... " | ||
91 | ifdown -a | ||
92 | ifup -a | ||
93 | echo "done." | ||
94 | ;; | ||
95 | *) | ||
96 | echo "Usage: /etc/init.d/networking {start|stop|restart|force-reload}" | ||
97 | exit 1 | ||
98 | ;; | ||
99 | esac | ||
100 | |||
101 | exit 0 | ||
102 | |||