Project

General

Profile

Download (8.72 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php -f
2
<?php
3
/* $Id$ */
4
/*
5
	rc.bootup
6
	part of pfSense by Scott Ullrich
7
	originally based on m0n0wall (http://m0n0.ch/wall)
8

    
9
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11

    
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14

    
15
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17

    
18
	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

    
22
	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
	echo " done.\n";
35

    
36
	echo "Initializing...";
37
	echo ".";
38
	require_once("/etc/inc/globals.inc");
39
	echo ".";
40
	/* let the other functions know we're booting */
41
	$pkg_interface = 'console';
42
	$g['booting'] = TRUE;
43
	touch("{$g['varrun_path']}/booting");
44
	if($g['platform'] == "cdrom") {
45
		$motd = trim(file_get_contents("/etc/motd"));
46
		if(strlen($motd) > 2) echo "\n{$motd}\n\n";
47
	}
48

    
49
	/* parse the configuration and include all functions used below */
50
	require_once("/etc/inc/config.inc");
51
	echo ".";
52
	require_once("/etc/inc/functions.inc");
53
	/* get system memory amount */
54
	$memory = get_memory();
55
	$avail = $memory[0];
56
	echo " done.\n";
57

    
58
	conf_mount_rw();
59

    
60
	/* remove previous firmware upgrade if present */
61
	if(file_exists("/root/firmware.tgz")) 
62
		unlink("/root/firmware.tgz");
63

    
64
	/* start devd (dhclient now uses it */
65
	echo "Starting device manager (devd)...";
66
	mute_kernel_msgs();
67
	start_devd();
68
	set_device_perms();
69
	unmute_kernel_msgs();
70
	echo "done.\n";
71

    
72
	echo "Loading configuration...";
73
	parse_config_bootup();
74
	echo "done.\n";
75

    
76
	$lan_if = $config['interfaces']['lan']['if'];
77
	$wan_if = get_real_wan_interface();
78

    
79
	/*
80
	 *  Determine if we need to throw a interface exception
81
     *  and ask the user to reassign interfaces.  This will
82
     *  avoid a reboot and thats a good thing.
83
	 */
84
	unmute_kernel_msgs();
85
	/*
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
	/* convert config and clean backups */
96
	echo "Updating configuration...";
97
	convert_config();
98
	echo "done.\n";
99

    
100
	echo "Cleaning backup cache...";
101
	cleanup_backupcache(true);
102
	echo "done.\n";
103

    
104
	/* read in /etc/sysctl.conf and set values if needed */
105
	echo "Setting up extended sysctls...";
106
	system_setup_sysctl();
107
	echo "done.\n";
108

    
109
	/* sync user passwords */
110
	echo "Syncing user passwords...";
111
	sync_webgui_passwords();
112
	echo "done.\n";
113

    
114
	echo "Starting Secure Shell Services...";
115
	mwexec_bg("/etc/sshd");
116
	echo "done.\n";
117

    
118
	/* run any early shell commands specified in config.xml */
119
	system_do_shell_commands(1);
120

    
121
	/* save dmesg output to file */
122
	system_dmesg_save();
123

    
124
	/* set up our timezone */
125
	system_timezone_configure();
126

    
127
	/* set up our hostname */
128
	system_hostname_configure();
129

    
130
	/* make hosts file */
131
	system_hosts_generate();
132

    
133
	/* generate resolv.conf */
134
	system_resolvconf_generate();
135

    
136
	/* configure loopback interface */
137
	interfaces_loopback_configure();
138

    
139
	/* start syslogd */
140
	system_syslogd_start();
141

    
142
	/* set up VLAN virtual interfaces */
143
	interfaces_vlan_configure();
144
	
145
	if($config['interfaces']['lan']) {
146
		/* set up LAN interface */
147
		echo "Configuring LAN interface...";
148
		mute_kernel_msgs();
149
		interfaces_lan_configure();
150
		unmute_kernel_msgs();
151
		echo "done.\n";
152
	}
153

    
154
	/* set up WAN interface */
155
	echo "Configuring WAN interface...";
156
	mute_kernel_msgs();
157
	interfaces_wan_configure();
158
	unmute_kernel_msgs();
159
	echo "done.\n";
160

    
161
	/* set up Optional interfaces */
162
	echo "Configuring OPT interfaces...";
163
	if(!$debugging)
164
		mute_kernel_msgs();
165
	interfaces_optional_configure();
166
	if(!$debugging)
167
		unmute_kernel_msgs();
168
	echo "done.\n";
169

    
170
	/* bring up carp interfaces */
171
	interfaces_carp_configure();
172
	
173
	/* bring ip IP aliases */
174
	interfaces_ipalias_configure();
175

    
176
	/* setup altq + pf */
177
	echo "Configuring firewall...";
178
	//mute_kernel_msgs();
179
	filter_configure_sync();
180
	//unmute_kernel_msgs();
181
	echo "done.\n";
182

    
183
	/* generate resolv.conf */
184
	system_resolvconf_generate();
185

    
186
	/* check if the wan interface is up, this might delay upto 10 seconds */
187
	is_wan_interface_up("wan");
188

    
189
	/* Sync the system time at boot before service startup */
190
	sync_system_time();
191

    
192
	/* start pflog */
193
	filter_pflog_start();
194

    
195
	setup_filter_bridge();
196

    
197
	/* start load balancer daemon */
198
	load_balancer_use_sticky();
199
	slbd_configure();
200
	relayd_configure();
201

    
202
	/* start OpenVPN server & clients */
203
	openvpn_resync_all();
204

    
205
	if($avail > 0 and $avail < 65) {
206
		echo "System has less than 65 megabytes of ram {$avail}.  Delaying webConfigurator startup.\n";
207
		/* start webConfigurator up on final pass */
208
		touch("/tmp/restart_webgui");
209
	} else {
210
		/* start web server */
211
		system_webgui_start();
212
	}
213

    
214
	/* configure cron service */
215
	configure_cron();
216

    
217
	/* set up static routes */
218
	system_routing_configure();
219

    
220
	/* enable routing */
221
	system_routing_enable();
222

    
223
	/* ensure passwords are sync'd */
224
	system_password_configure();
225

    
226
	/* configure console menu */
227
	system_console_configure();
228

    
229
	/* start dyndns service */
230
	services_dyndns_configure();
231

    
232
	/* static IP address? -> attempt DNS update */
233
	if (is_ipaddr($config['interfaces']['wan']['ipaddr']))
234
		services_dnsupdate_process();
235

    
236
	/* start DHCP service */
237
	services_dhcpd_configure();
238

    
239
	/* start dnsmasq service */
240
	services_dnsmasq_configure();
241

    
242
	/* start DHCP relay */
243
	services_dhcrelay_configure();
244

    
245
	/* start proxy ARP service */
246
	services_proxyarp_configure();
247

    
248
	/* setup pppoe and pptp */
249
	vpn_setup();
250

    
251
	/* start the captive portal */
252
	captiveportal_configure();
253

    
254
	/* run any shell commands specified in config.xml */
255
	system_do_shell_commands();
256

    
257
	/* setup polling */
258
	setup_polling();
259

    
260
	/* setup interface microcode which improves tcp/ip speed */
261
	echo "Setting up microcode and tx/rx offloading...";
262
	setup_microcode();
263
	echo "done.\n";
264

    
265
	mwexec("/sbin/pfctl -f /tmp/rules.debug");
266
	
267
	interfaces_carp_bring_up_final();
268

    
269
	/* start IPsec tunnels */
270
	vpn_ipsec_configure();
271

    
272
	/* start ftp proxy helpers if they are enabled */
273
	echo "Starting FTP helpers...";
274
	system_start_ftp_helpers();
275
	echo "done.\n";
276

    
277
	/* start SNMP service */
278
	services_snmpd_configure();
279

    
280
	/* power down hard drive if needed/set */
281
	system_set_harddisk_standby();
282

    
283
	/* lock down console if necessary */
284
	if(isset($config['system']['disableconsolemenu']))
285
		touch("/var/etc/console_lockdown");
286

    
287
	echo "Final filter pass..."
288
	filter_configure_sync();
289
	echo "done.\n"
290

    
291
	/* load graphing functions */
292
	enable_rrd_graphing();
293

    
294
	/*   start DHCP service again now that CARP has settled
295
	 *   incase user is using primary/backup failover dhcp mode
296
         */
297
	services_dhcpd_configure();
298

    
299
	/* startup OLSR if needed */
300
	setup_wireless_olsr();
301

    
302
	/* startup routed if needed */
303
	include_once("/usr/local/pkg/routed/routed.inc");
304
	setup_routed();
305

    
306
	/* enable watchdog if supported */
307
	enable_watchdog();
308

    
309
	/* start the NTP client */
310
	echo "Starting OpenNTP time client...";
311
	system_ntp_configure();
312
	echo "done.\n";
313

    
314
	/* if <system><afterbootupshellcmd> exists, execute the command */
315
	if($config['system']['afterbootupshellcmd'] <> "")
316
		mwexec($config['system']['afterbootupshellcmd']);
317

    
318
	if($avail < 126) {
319
		require_once("/etc/inc/notices.inc");
320
		file_notice("pfSenseMemoryRequirements", "pfSense requires atleast 128 megabytes of RAM.  Expect unusual performance.  This platform is not supported.", "Memory", "", 1);
321
		mwexec("sysctl net.inet.tcp.recvspace=4096");
322
		mwexec("sysctl net.inet.tcp.sendspace=4096");
323
	}
324
	
325
	/* if we are operating at 1000 then increase timeouts.
326
	   this was never accounted for after moving to 1000 hz */
327
	$kern_hz = `sysctl kern.clockrate | awk '{ print $5 }' | cut -d"," -f1`;
328
	$kern_hz = trim($kern_hz, "\r\n");
329
	if($kern_hz == "1000") 
330
		mwexec("sysctl net.inet.tcp.rexmit_min=30");
331

    
332
	upnp_start();
333

    
334
	mwexec_bg("/usr/sbin/update_dns_cache.sh");
335

    
336
	/* done */
337
	unlink("{$g['varrun_path']}/booting");
338
	$g['booting'] = FALSE;
339

    
340
?>
(27-27/79)