Project

General

Profile

Download (8.42 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
	echo "Starting Secure Shell Services...";
110
	mwexec_bg("/etc/sshd");
111
	echo "done.\n";
112

    
113
	/* run any early shell commands specified in config.xml */
114
	system_do_shell_commands(1);
115

    
116
	/* save dmesg output to file */
117
	system_dmesg_save();
118

    
119
	/* generate resolv.conf */
120
	system_resolvconf_generate();
121

    
122
	/* set up our timezone */
123
	system_timezone_configure();
124

    
125
	/* set up our hostname */
126
	system_hostname_configure();
127

    
128
	/* make hosts file */
129
	system_hosts_generate();
130

    
131
	/* configure loopback interface */
132
	interfaces_loopback_configure();
133

    
134
	/* start syslogd */
135
	system_syslogd_start();
136

    
137
	/* set up VLAN virtual interfaces */
138
	interfaces_vlan_configure();
139
	
140
	/* set up interfaces */
141
	if(!$debugging)
142
		mute_kernel_msgs();
143
	interfaces_configure();
144
	if(!$debugging)
145
		unmute_kernel_msgs();
146

    
147
        /* set up GRE virtual interfaces */
148
        interfaces_gre_configure();
149

    
150
        /* set up GIF virtual interfaces */
151
        interfaces_gif_configure();
152
	
153
	/* set up LAGG virtual interfaces */
154
	interfaces_lagg_configure();
155

    
156
	/* set up BRIDGe virtual interfaces */
157
        interfaces_bridge_configure();
158

    
159
	/* bring up carp interfaces */
160
	interfaces_carp_configure();
161
	
162
	/* bring ip IP aliases */
163
	interfaces_ipalias_configure();
164

    
165
	/* 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
	/* generate resolv.conf */
173
	system_resolvconf_generate();
174

    
175
	/* start pflog */
176
	filter_pflog_start();
177

    
178
	/* start load balancer daemon */
179
	relayd_configure();
180

    
181
 	/* reconfigure our gateway monitor */
182
 	setup_gateways_monitor();
183

    
184
	/* start OpenVPN server & clients */
185
	openvpn_resync_all();
186

    
187
	if($avail > 0 and $avail < 65) {
188
		echo "System has less than 65 megabytes of ram {$avail}.  Delaying webConfigurator startup.\n";
189
		/* start webConfigurator up on final pass */
190
		touch("/tmp/restart_webgui");
191
	} else {
192
		/* start web server */
193
		system_webgui_start();
194
	}
195

    
196
	/* configure cron service */
197
	configure_cron();
198

    
199
	/* set up static routes */
200
	system_routing_configure();
201

    
202
	/* enable routing */
203
	system_routing_enable();
204

    
205
	/* ensure passwords are sync'd */
206
//	system_password_configure();
207

    
208
	/* configure console menu */
209
	system_console_configure();
210

    
211
	/* check if the wan interface is up, this might delay upto 10 seconds */
212
	is_wan_interface_up("wan");
213

    
214
	/* Sync the system time at boot before service startup */
215
	sync_system_time();
216

    
217
	/* start dyndns service */
218
	services_dyndns_configure();
219

    
220
	/* static IP address? -> attempt DNS update */
221
	if (is_ipaddr($config['interfaces']['wan']['ipaddr']))
222
		services_dnsupdate_process();
223

    
224
	/* start DHCP service */
225
	services_dhcpd_configure();
226

    
227
	/* start dnsmasq service */
228
	services_dnsmasq_configure();
229

    
230
	/* start DHCP relay */
231
	services_dhcrelay_configure();
232

    
233
	/* start proxy ARP service */
234
	services_proxyarp_configure();
235

    
236
	/* setup pppoe and pptp */
237
	vpn_setup();
238

    
239
	/* start the captive portal */
240
	captiveportal_configure();
241

    
242
	/* run any shell commands specified in config.xml */
243
	system_do_shell_commands();
244

    
245
	/* setup polling */
246
	setup_polling();
247

    
248
	/* setup interface microcode which improves tcp/ip speed */
249
	echo "Setting up microcode and tx/rx offloading...";
250
	setup_microcode();
251
	echo "done.\n";
252

    
253
	mwexec("/sbin/pfctl -f /tmp/rules.debug");
254
	
255
	/* start IPsec tunnels */
256
	vpn_ipsec_configure();
257

    
258
	/* start ftp proxy helpers if they are enabled */
259
	echo "Starting FTP helpers...";
260
	system_start_ftp_helpers();
261
	echo "done.\n";
262

    
263
	/* start SNMP service */
264
	services_snmpd_configure();
265

    
266
	/* power down hard drive if needed/set */
267
	system_set_harddisk_standby();
268

    
269
	/* lock down console if necessary */
270
	if(isset($config['system']['disableconsolemenu']))
271
		touch("/var/etc/console_lockdown");
272

    
273
	filter_configure_sync();
274

    
275
	/* load graphing functions */
276
	enable_rrd_graphing();
277

    
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

    
283
	/* startup OLSR if needed */
284
	setup_wireless_olsr();
285

    
286
	/* startup routed if needed */
287
	include_once("/usr/local/pkg/routed/routed.inc");
288
	setup_routed();
289

    
290
	/* enable watchdog if supported */
291
	enable_watchdog();
292

    
293
	/* start the NTP client */
294
	echo "Starting OpenNTP time client...";
295
	system_ntp_configure();
296
	echo "done.\n";
297

    
298
	/* if <system><afterbootupshellcmd> exists, execute the command */
299
	if($config['system']['afterbootupshellcmd'] <> "")
300
		mwexec($config['system']['afterbootupshellcmd']);
301

    
302
	if($avail < 126) {
303
		require_once("/etc/inc/notices.inc");
304
		file_notice("pfSenseMemoryRequirements", "pfSense requires atleast 128 megabytes of RAM.  Expect unusual performance.  This platform is not supported.", "Memory", "", 1);
305
		mwexec("sysctl net.inet.tcp.recvspace=4096");
306
		mwexec("sysctl net.inet.tcp.sendspace=4096");
307
	}
308
	
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
	if($kern_hz == "1000") 
314
		mwexec("sysctl net.inet.tcp.rexmit_min=30");
315

    
316
	upnp_start();
317

    
318
	mwexec_bg("/usr/sbin/update_dns_cache.sh");
319

    
320
	/* done */
321
	unlink("{$g['varrun_path']}/booting");
322
	$g['booting'] = FALSE;
323

    
324
?>
(28-28/79)