Project

General

Profile

Download (8.42 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php -f
2
<?php
3 1b8df11b Bill Marquette
/* $Id$ */
4 5b237745 Scott Ullrich
/*
5
	rc.bootup
6 e5cd29a0 Scott Ullrich
	part of pfSense by Scott Ullrich
7
	originally based on m0n0wall (http://m0n0.ch/wall)
8
9 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11 e5cd29a0 Scott Ullrich
12 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14 e5cd29a0 Scott Ullrich
15 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17 e5cd29a0 Scott Ullrich
18 5b237745 Scott Ullrich
	2. Redistributions in binary form must reproduce the above copyright
19
	   notice, this list of conditions and the following disclaimer in the
20
	   documentation and/or other materials provided with the distribution.
21 e5cd29a0 Scott Ullrich
22 5b237745 Scott Ullrich
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
	POSSIBILITY OF SUCH DAMAGE.
32
*/
33
34 d0e94aaf Scott Ullrich
	echo " done.\n";
35
36
	echo "Initializing...";
37
	echo ".";
38 4bee8672 Scott Ullrich
	require_once("/etc/inc/globals.inc");
39 d0e94aaf Scott Ullrich
	echo ".";
40 a164b0ca Scott Ullrich
	/* let the other functions know we're booting */
41
	$pkg_interface = 'console';
42
	$g['booting'] = TRUE;
43
	touch("{$g['varrun_path']}/booting");
44 2c35ed91 Scott Ullrich
	if($g['platform'] == "cdrom") {
45 7822d966 Colin Smith
		$motd = trim(file_get_contents("/etc/motd"));
46 2c35ed91 Scott Ullrich
		if(strlen($motd) > 2) echo "\n{$motd}\n\n";
47
	}
48 5f89728d Scott Ullrich
49 5b237745 Scott Ullrich
	/* parse the configuration and include all functions used below */
50 4bee8672 Scott Ullrich
	require_once("/etc/inc/config.inc");
51 d0e94aaf Scott Ullrich
	echo ".";
52 4bee8672 Scott Ullrich
	require_once("/etc/inc/functions.inc");
53 a6abbd66 Scott Ullrich
	/* get system memory amount */
54
	$memory = get_memory();
55
	$avail = $memory[0];
56 d0e94aaf Scott Ullrich
	echo " done.\n";
57 e5cd29a0 Scott Ullrich
58 ef0090a3 Scott Ullrich
	conf_mount_rw();
59
60
	/* remove previous firmware upgrade if present */
61
	if(file_exists("/root/firmware.tgz")) 
62 f8554aed Scott Ullrich
		unlink("/root/firmware.tgz");
63 ef0090a3 Scott Ullrich
64 86ddbb71 Scott Ullrich
	/* start devd (dhclient now uses it */
65 f05740c1 Scott Ullrich
	echo "Starting device manager (devd)...";
66 70b89814 Scott Ullrich
	mute_kernel_msgs();
67 86ddbb71 Scott Ullrich
	start_devd();
68 09b949e1 Scott Ullrich
	set_device_perms();
69 70b89814 Scott Ullrich
	unmute_kernel_msgs();
70 86ddbb71 Scott Ullrich
	echo "done.\n";
71
72 f05740c1 Scott Ullrich
	echo "Loading configuration...";
73 b6f3f5c6 Colin Smith
	parse_config_bootup();
74 74dbce1f Scott Ullrich
	echo "done.\n";
75 b6f3f5c6 Colin Smith
76 afde8c22 Scott Ullrich
	$lan_if = $config['interfaces']['lan']['if'];
77 aa01f2f2 Scott Ullrich
	$wan_if = get_real_wan_interface();
78
79 28d38aa4 Scott Ullrich
	/*
80 22d0b8e5 Bill Marquette
	 *  Determine if we need to throw a interface exception
81 d0e94aaf Scott Ullrich
     *  and ask the user to reassign interfaces.  This will
82
     *  avoid a reboot and thats a good thing.
83 28d38aa4 Scott Ullrich
	 */
84 de16ed63 Scott Ullrich
	unmute_kernel_msgs();
85 8cd7e1fa Scott Ullrich
	/*
86
	 *   Determine if we need to throw a interface exception
87
	 *   and ask the user to reassign interfaces.  This will
88
	 *   avoid a reboot and thats a good thing.
89
	 */
90
	while(is_interface_mismatch() == true) {
91
		echo "\nNetwork interface mismatch -- Running interface assignment option.\n";
92
		set_networking_interfaces_ports();
93
	}
94
	
95 d6f1dbe3 Colin Smith
	/* convert config and clean backups */
96 f05740c1 Scott Ullrich
	echo "Updating configuration...";
97 5b237745 Scott Ullrich
	convert_config();
98 74dbce1f Scott Ullrich
	echo "done.\n";
99 bad59dd6 Colin Smith
100 f05740c1 Scott Ullrich
	echo "Cleaning backup cache...";
101 d6f1dbe3 Colin Smith
	cleanup_backupcache(true);
102 74dbce1f Scott Ullrich
	echo "done.\n";
103 d0e94aaf Scott Ullrich
104 3ff9d424 Scott Ullrich
	/* read in /etc/sysctl.conf and set values if needed */
105 f05740c1 Scott Ullrich
	echo "Setting up extended sysctls...";
106 3ff9d424 Scott Ullrich
	system_setup_sysctl();
107 92e2deb7 Scott Ullrich
	echo "done.\n";
108 3ff9d424 Scott Ullrich
109 f05740c1 Scott Ullrich
	echo "Starting Secure Shell Services...";
110 beaff8b0 Scott Ullrich
	mwexec_bg("/etc/sshd");
111
	echo "done.\n";
112
113 5b237745 Scott Ullrich
	/* run any early shell commands specified in config.xml */
114
	system_do_shell_commands(1);
115 e5cd29a0 Scott Ullrich
116 5b237745 Scott Ullrich
	/* save dmesg output to file */
117
	system_dmesg_save();
118 e5cd29a0 Scott Ullrich
119 5b237745 Scott Ullrich
	/* set up our timezone */
120
	system_timezone_configure();
121 e5cd29a0 Scott Ullrich
122 5b237745 Scott Ullrich
	/* set up our hostname */
123
	system_hostname_configure();
124 e5cd29a0 Scott Ullrich
125 5b237745 Scott Ullrich
	/* make hosts file */
126
	system_hosts_generate();
127 e5cd29a0 Scott Ullrich
128 5b237745 Scott Ullrich
	/* generate resolv.conf */
129
	system_resolvconf_generate();
130 e5cd29a0 Scott Ullrich
131 5b237745 Scott Ullrich
	/* configure loopback interface */
132
	interfaces_loopback_configure();
133 e5cd29a0 Scott Ullrich
134 93629767 Scott Ullrich
	/* start syslogd */
135
	system_syslogd_start();
136
137 5b237745 Scott Ullrich
	/* set up VLAN virtual interfaces */
138
	interfaces_vlan_configure();
139 7a5b7a05 Scott Ullrich
	
140 67ee1ec5 Ermal Luçi
	/* set up interfaces */
141 e556dea7 Scott Ullrich
	if(!$debugging)
142
		mute_kernel_msgs();
143 67ee1ec5 Ermal Luçi
	interfaces_configure();
144 d0e94aaf Scott Ullrich
	if(!$debugging)
145 e556dea7 Scott Ullrich
		unmute_kernel_msgs();
146 dd2ab8f8 Scott Ullrich
147 9c57a161 Ermal Luçi
        /* set up GRE virtual interfaces */
148
        interfaces_gre_configure();
149
150
        /* set up GIF virtual interfaces */
151
        interfaces_gif_configure();
152 f626c320 Ermal Luçi
	
153
	/* set up LAGG virtual interfaces */
154
	interfaces_lagg_configure();
155 9c57a161 Ermal Luçi
156 2995a723 Ermal Luçi
	/* set up BRIDGe virtual interfaces */
157
        interfaces_bridge_configure();
158
159 ae723ece Scott Ullrich
	/* bring up carp interfaces */
160
	interfaces_carp_configure();
161 7e4329ed Chris Buechler
	
162
	/* bring ip IP aliases */
163
	interfaces_ipalias_configure();
164 ae723ece Scott Ullrich
165 499994ff Scott Ullrich
	/* setup altq + pf */
166
	echo "Configuring firewall...";
167
	//mute_kernel_msgs();
168
	filter_configure_sync();
169
	//unmute_kernel_msgs();
170
	echo "done.\n";
171
172 3a89b8d9 Scott Ullrich
	/* generate resolv.conf */
173
	system_resolvconf_generate();
174
175 057ef2f5 Seth Mos
	/* check if the wan interface is up, this might delay upto 10 seconds */
176
	is_wan_interface_up("wan");
177
178 baf9fab2 Seth Mos
	/* Sync the system time at boot before service startup */
179
	sync_system_time();
180
181 24d15c0c Scott Ullrich
	/* start pflog */
182
	filter_pflog_start();
183 3962b070 Scott Ullrich
184 ab34f4ec Scott Ullrich
	/* start load balancer daemon */
185 17623ab5 Bill Marquette
	relayd_configure();
186 67ee1ec5 Ermal Luçi
187
 	/* reconfigure our gateway monitor */
188
 	setup_gateways_monitor();
189 12c09555 Scott Ullrich
190
	/* start OpenVPN server & clients */
191 7e4329ed Chris Buechler
	openvpn_resync_all();
192 d0e94aaf Scott Ullrich
193 a6abbd66 Scott Ullrich
	if($avail > 0 and $avail < 65) {
194 bd042586 Scott Ullrich
		echo "System has less than 65 megabytes of ram {$avail}.  Delaying webConfigurator startup.\n";
195 a6abbd66 Scott Ullrich
		/* start webConfigurator up on final pass */
196
		touch("/tmp/restart_webgui");
197
	} else {
198
		/* start web server */
199
		system_webgui_start();
200
	}
201 d0e94aaf Scott Ullrich
202 1071e028 Scott Ullrich
	/* configure cron service */
203
	configure_cron();
204
205 5b237745 Scott Ullrich
	/* set up static routes */
206
	system_routing_configure();
207 e5cd29a0 Scott Ullrich
208 5b237745 Scott Ullrich
	/* enable routing */
209
	system_routing_enable();
210 d0e94aaf Scott Ullrich
211 fb453a4a Scott Ullrich
	/* ensure passwords are sync'd */
212 659fa7f2 Matthew Grooms
//	system_password_configure();
213 e5cd29a0 Scott Ullrich
214 5b237745 Scott Ullrich
	/* configure console menu */
215
	system_console_configure();
216 e5cd29a0 Scott Ullrich
217 5b237745 Scott Ullrich
	/* start dyndns service */
218
	services_dyndns_configure();
219 d0e94aaf Scott Ullrich
220 5ffb18e0 Scott Ullrich
	/* static IP address? -> attempt DNS update */
221
	if (is_ipaddr($config['interfaces']['wan']['ipaddr']))
222
		services_dnsupdate_process();
223 e5cd29a0 Scott Ullrich
224 5b237745 Scott Ullrich
	/* start DHCP service */
225
	services_dhcpd_configure();
226 e5cd29a0 Scott Ullrich
227 a005424e Scott Ullrich
	/* start dnsmasq service */
228
	services_dnsmasq_configure();
229
230 5ffb18e0 Scott Ullrich
	/* start DHCP relay */
231
	services_dhcrelay_configure();
232
233 5b237745 Scott Ullrich
	/* start proxy ARP service */
234
	services_proxyarp_configure();
235
236 88964924 Scott Ullrich
	/* setup pppoe and pptp */
237
	vpn_setup();
238 3d941d72 Scott Ullrich
239 5b237745 Scott Ullrich
	/* start the captive portal */
240
	captiveportal_configure();
241 e5cd29a0 Scott Ullrich
242 5b237745 Scott Ullrich
	/* run any shell commands specified in config.xml */
243
	system_do_shell_commands();
244 e5cd29a0 Scott Ullrich
245 562fca6d Scott Ullrich
	/* setup polling */
246
	setup_polling();
247
248 28d38aa4 Scott Ullrich
	/* setup interface microcode which improves tcp/ip speed */
249 f05740c1 Scott Ullrich
	echo "Setting up microcode and tx/rx offloading...";
250 11e2c67c Scott Ullrich
	setup_microcode();
251 0192adaf Scott Ullrich
	echo "done.\n";
252 d0e94aaf Scott Ullrich
253 11e2c67c Scott Ullrich
	mwexec("/sbin/pfctl -f /tmp/rules.debug");
254 67ee1ec5 Ermal Luçi
	
255 11c32d4a Scott Ullrich
	/* start IPsec tunnels */
256 11e2c67c Scott Ullrich
	vpn_ipsec_configure();
257 c6e604d8 Scott Ullrich
258 154349f9 Scott Ullrich
	/* start ftp proxy helpers if they are enabled */
259 f05740c1 Scott Ullrich
	echo "Starting FTP helpers...";
260 154349f9 Scott Ullrich
	system_start_ftp_helpers();
261
	echo "done.\n";
262
263 f4959a69 Scott Ullrich
	/* start SNMP service */
264
	services_snmpd_configure();
265
266 9f966bc9 Scott Ullrich
	/* power down hard drive if needed/set */
267 11e2c67c Scott Ullrich
	system_set_harddisk_standby();
268 9f966bc9 Scott Ullrich
269 ce9e67ce Scott Ullrich
	/* lock down console if necessary */
270
	if(isset($config['system']['disableconsolemenu']))
271
		touch("/var/etc/console_lockdown");
272 f4959a69 Scott Ullrich
273 2b263ed6 Chris Buechler
	filter_configure_sync();
274 d0e94aaf Scott Ullrich
275 f0842feb Scott Ullrich
	/* load graphing functions */
276 d0e94aaf Scott Ullrich
	enable_rrd_graphing();
277 1e19b3b4 Scott Ullrich
278
	/*   start DHCP service again now that CARP has settled
279
	 *   incase user is using primary/backup failover dhcp mode
280
         */
281
	services_dhcpd_configure();
282 a199b93e Scott Ullrich
283 11cbd478 Scott Ullrich
	/* startup OLSR if needed */
284
	setup_wireless_olsr();
285
286 011bff69 Bill Marquette
	/* startup routed if needed */
287
	include_once("/usr/local/pkg/routed/routed.inc");
288
	setup_routed();
289
290 a199b93e Scott Ullrich
	/* enable watchdog if supported */
291
	enable_watchdog();
292 d0e94aaf Scott Ullrich
293 5f3e1f12 Scott Ullrich
	/* start the NTP client */
294
	echo "Starting OpenNTP time client...";
295
	system_ntp_configure();
296
	echo "done.\n";
297
298 6d80ad3a Scott Ullrich
	/* if <system><afterbootupshellcmd> exists, execute the command */
299
	if($config['system']['afterbootupshellcmd'] <> "")
300
		mwexec($config['system']['afterbootupshellcmd']);
301
302 3c61530f Scott Ullrich
	if($avail < 126) {
303 4bee8672 Scott Ullrich
		require_once("/etc/inc/notices.inc");
304 232374b7 Scott Ullrich
		file_notice("pfSenseMemoryRequirements", "pfSense requires atleast 128 megabytes of RAM.  Expect unusual performance.  This platform is not supported.", "Memory", "", 1);
305 6f954b49 Scott Ullrich
		mwexec("sysctl net.inet.tcp.recvspace=4096");
306
		mwexec("sysctl net.inet.tcp.sendspace=4096");
307 c108ec01 Scott Ullrich
	}
308 4313e61a Scott Ullrich
	
309
	/* if we are operating at 1000 then increase timeouts.
310
	   this was never accounted for after moving to 1000 hz */
311
	$kern_hz = `sysctl kern.clockrate | awk '{ print $5 }' | cut -d"," -f1`;
312
	$kern_hz = trim($kern_hz, "\r\n");
313 6c038dc6 Scott Ullrich
	if($kern_hz == "1000") 
314 4313e61a Scott Ullrich
		mwexec("sysctl net.inet.tcp.rexmit_min=30");
315 c108ec01 Scott Ullrich
316 6f20377b Scott Ullrich
	upnp_start();
317
318 279ee755 Scott Ullrich
	mwexec_bg("/usr/sbin/update_dns_cache.sh");
319 31381202 Scott Ullrich
320 5b237745 Scott Ullrich
	/* done */
321
	unlink("{$g['varrun_path']}/booting");
322 5c60c947 Scott Ullrich
	$g['booting'] = FALSE;
323
324 c6a22c85 Seth Mos
?>