8dd2c7e8994e2514a43ee89651bb43abd038b377
[people/teissler/ipfire-2.x.git] / src / initscripts / init.d / network
1 #!/bin/sh
2 ########################################################################
3 # Begin $rc_base/init.d/network
4 #
5 # Description : Network Control Script
6 #
7 # Authors : Michael Tremer - mitch@ipfire.org
8 #
9 # Version : 01.00
10 #
11 # Notes : Written for IPFire by its team
12 #
13 ########################################################################
14
15 . /etc/sysconfig/rc
16 . ${rc_functions}
17 eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
18
19 init_networking() {
20 boot_mesg "Loading firewall modules into the kernel"
21 modprobe iptable_nat || failed=1
22 for i in $(find /lib/modules/$(uname -r) -name nf_conntrack*); do
23 modprobe $(basename $i | cut -d. -f1) || failed=1
24 done
25 for i in $(find /lib/modules/$(uname -r) -name nf_nat*); do
26 modprobe $(basename $i | cut -d. -f1) || failed=1
27 done
28 (exit ${failed})
29 evaluate_retval
30
31 # Enable netfilter accounting
32 sysctl net.netfilter.nf_conntrack_acct=1 > /dev/null
33
34 if [ -e /var/ipfire/main/disable_nf_sip ]; then
35 rmmod nf_nat_sip
36 rmmod nf_conntrack_sip
37 rmmod nf_nat_h323
38 rmmod nf_conntrack_h323
39 fi
40
41 boot_mesg "Setting up firewall"
42 /etc/rc.d/init.d/firewall start; evaluate_retval
43
44 if [ "$CONFIG_TYPE" = "3" -o "$CONFIG_TYPE" = "4" ]; then
45 boot_mesg "Setting up wireless firewall rules"
46 /usr/local/bin/wirelessctrl; evaluate_retval
47 fi
48
49 /etc/rc.d/init.d/dnsmasq start
50 /etc/rc.d/init.d/static-routes start
51 }
52
53 DO="${1}"
54 shift
55
56 if [ -n "${1}" ]; then
57 ALL=0
58 for i in green red blue orange; do
59 eval "${i}=0"
60 done
61 else
62 ALL=1
63 for i in green red blue orange; do
64 eval "${i}=1"
65 done
66 fi
67
68 while [ ! $# = 0 ]; do
69 for i in green red blue orange; do
70 if [ "${i}" == "${1}" ]; then
71 eval "${i}=1"
72 shift
73 fi
74 done
75 done
76
77 case "${DO}" in
78 start)
79 [ "${ALL}" == "1" ] && init_networking
80
81 # Starting interfaces...
82 # GREEN
83 [ "$green" == "1" ] && /etc/rc.d/init.d/networking/green start
84
85 # BLUE
86 [ "$blue" == "1" ] && [ "$CONFIG_TYPE" = "3" -o "$CONFIG_TYPE" = "4" ] && \
87 /etc/rc.d/init.d/networking/blue start
88
89 # ORANGE
90 [ "$orange" == "1" ] && [ "$CONFIG_TYPE" = "2" -o "$CONFIG_TYPE" = "4" ] && \
91 /etc/rc.d/init.d/networking/orange start
92
93 # RED
94 if [ "$red" == "1" ]; then
95 if [ "$CONFIG_TYPE" = "1" -o "$CONFIG_TYPE" = "2" -o "$CONFIG_TYPE" = "3" -o "$CONFIG_TYPE" = "4" ]; then
96 # Remove possible leftover files
97 rm -f /var/ipfire/red/{active,device,dial-on-demand,dns1,dns2,local-ipaddress,remote-ipaddress,resolv.conf}
98 [ "$AUTOCONNECT" == "off" ] || /etc/rc.d/init.d/networking/red start
99 fi
100 fi
101 ;;
102
103 stop)
104 # Stopping interfaces...
105 # GREEN
106 [ "$green" == "1" ] && /etc/rc.d/init.d/networking/green stop
107
108 # BLUE
109 [ "$blue" == "1" ] && [ "$CONFIG_TYPE" = "3" -o "$CONFIG_TYPE" = "4" ] && \
110 /etc/rc.d/init.d/networking/blue stop
111
112 # ORANGE
113 [ "$orange" == "1" ] && [ "$CONFIG_TYPE" = "2" -o "$CONFIG_TYPE" = "4" ] && \
114 /etc/rc.d/init.d/networking/orange stop
115
116 # RED
117 if [ "$red" == "1" ]; then
118 if [ "$CONFIG_TYPE" = "1" -o "$CONFIG_TYPE" = "2" -o "$CONFIG_TYPE" = "3" -o "$CONFIG_TYPE" = "4" ]; then
119 /etc/rc.d/init.d/networking/red stop
120 fi
121 fi
122
123 # Stopping dnsmasq if network all networks shutdown
124 [ "${ALL}" == "1" ] && /etc/rc.d/init.d/dnsmasq stop
125
126 exit 0
127 ;;
128
129 restart)
130 for i in green red blue orange; do
131 if [ "${!i}" == "1" ]; then
132 ARGS+=" ${i}"
133 fi
134 done
135 ${0} stop ${ARGS}
136 sleep 1
137 ${0} start ${ARGS}
138 ;;
139
140 *)
141 echo "Usage: ${0} {start|stop|restart} [device(s)]"
142 exit 1
143 ;;
144 esac
145
146 # End /etc/rc.d/init.d/network