Project

General

Profile

Download (17.5 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	ipsec.inc
4
	Copyright (C) 2007 Scott Ullrich
5
	Copyright (C) 2008 Shrew Soft Inc
6
	All rights reserved.
7

    
8
	Parts of this code was originally based on vpn_ipsec_sad.php
9
	Copyright (C) 2003-2004 Manuel Kasper
10

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

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

    
17
	2. Redistributions in binary form must reproduce the above copyright
18
	   notice, this list of conditions and the following disclaimer in the
19
	   documentation and/or other materials provided with the distribution.
20

    
21
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
	POSSIBILITY OF SUCH DAMAGE.
31

    
32
	pfSense_BUILDER_BINARIES:	/sbin/setkey
33
	pfSense_MODULE:	ipsec
34

    
35
*/
36

    
37
/* IPsec defines */
38
$ipsec_loglevels = array("dmn" => "Daemon", "mgr" => "SA Manager", "ike" => "IKE SA", "chd" => "IKE Child SA",
39
	"job" => "Job Processing", "cfg" => "Configuration backend", "knl" => "Kernel Interface",
40
	"net" => "Networking", "asn" => "ASN encoding", "enc" => "Message encoding",
41
	"imc" => "Integrity checker", "imv" => "Integrity Verifier", "pts" => "Platform Trust Service",
42
	"tls" => "TLS handler", "esp" => "IPsec traffic", "lib" => "StrongSwan Lib");
43

    
44
$my_identifier_list = array(
45
	'myaddress' => array( 'desc' => gettext('My IP address'), 'mobile' => true ),
46
	'address' => array( 'desc' => gettext('IP address'), 'mobile' => true ),
47
	'fqdn' => array( 'desc' => gettext('Distinguished name'), 'mobile' => true ),
48
	'user_fqdn' => array( 'desc' => gettext('User distinguished name'), 'mobile' => true ),
49
	'asn1dn' => array( 'desc' => gettext('ASN.1 distinguished Name'), 'mobile' => true ),
50
	'keyid tag' => array( 'desc' => gettext('KeyID tag'), 'mobile' => true ),
51
	'dyn_dns' => array( 'desc' => gettext('Dynamic DNS'), 'mobile' => true ));
52

    
53
$peer_identifier_list = array(
54
	'peeraddress' => array( 'desc' => gettext('Peer IP address'), 'mobile' => false ),
55
	'address' => array( 'desc' => gettext('IP address'), 'mobile' => false ),
56
	'fqdn' => array( 'desc' => gettext('Distinguished name'), 'mobile' => true ),
57
	'user_fqdn' => array( 'desc' => gettext('User distinguished name'), 'mobile' => true ),
58
	'asn1dn' => array( 'desc' => gettext('ASN.1 distinguished Name'), 'mobile' => true ),
59
	'keyid tag' => array( 'desc' =>gettext('KeyID tag'), 'mobile' => true ));
60

    
61
$p1_ealgos = array(
62
	'aes' => array( 'name' => 'AES', 'keysel' => array( 'lo' => 128, 'hi' => 256, 'step' => 64 ) ),
63
	'blowfish' => array( 'name' => 'Blowfish', 'keysel' => array( 'lo' => 128, 'hi' => 256, 'step' => 64 ) ),
64
	'3des' => array( 'name' => '3DES' ),
65
	'cast128' => array( 'name' => 'CAST128' ),
66
	'des' => array( 'name' => 'DES' ));
67

    
68
$p2_ealgos = array(
69
	'aes' => array( 'name' => 'AES', 'keysel' => array( 'lo' => 128, 'hi' => 256, 'step' => 64 ) ),
70
	'aes128gcm' => array( 'name' => 'AES128-GCM', 'keysel' => array( 'lo' => 64, 'hi' => 128, 'step' => 32 ) ),
71
	'aes192gcm' => array( 'name' => 'AES192-GCM', 'keysel' => array( 'lo' => 64, 'hi' => 128, 'step' => 32 ) ),
72
	'aes256gcm' => array( 'name' => 'AES256-GCM', 'keysel' => array( 'lo' => 64, 'hi' => 128, 'step' => 32 ) ),
73
	'blowfish' => array( 'name' => 'Blowfish', 'keysel' => array( 'lo' => 128, 'hi' => 256, 'step' => 64 ) ),
74
	'3des' => array( 'name' => '3DES' ),
75
	'cast128' => array( 'name' => 'CAST128' ),
76
	'des' => array( 'name' => 'DES' ));
77

    
78
$p1_halgos = array(
79
	'md5' => 'MD5',
80
	'sha1' => 'SHA1',
81
	'sha256' => 'SHA256',
82
	'sha384' => 'SHA384',
83
	'sha512' => 'SHA512',
84
	'aesxcbc' => 'AES-XCBC'
85
);
86

    
87
$p1_dhgroups = array(
88
	1  => '1 (768 bit)',
89
	2  => '2 (1024 bit)',
90
	5  => '5 (1536 bit)',
91
	14 => '14 (2048 bit)',
92
	15 => '15 (3072 bit)',
93
	16 => '16 (4096 bit)',
94
	17 => '17 (6144 bit)',
95
	18 => '18 (8192 bit)',
96
	22 => '22 (1024(sub 160) bit)',
97
	23 => '23 (2048(sub 224) bit)',
98
	24 => '24 (2048(sub 256) bit)'
99
);
100

    
101
$p2_halgos = array(
102
	'hmac_md5' => 'MD5',
103
	'hmac_sha1' => 'SHA1',
104
	'hmac_sha256' => 'SHA256',
105
	'hmac_sha384' => 'SHA384',
106
	'hmac_sha512' => 'SHA512',
107
	'aesxcbc' => 'AES-XCBC'
108
);
109

    
110
$p1_authentication_methods = array(
111
	'hybrid_rsa_server' => array( 'name' => 'Hybrid RSA + Xauth', 'mobile' => true ),
112
	'xauth_rsa_server' => array( 'name' => 'Mutual RSA + Xauth', 'mobile' => true ),
113
	'xauth_psk_server' => array( 'name' => 'Mutual PSK + Xauth', 'mobile' => true ),
114
	'eap-tls' => array( 'name' => 'EAP-TLS', 'mobile' => true),
115
	'rsasig' => array( 'name' => 'Mutual RSA', 'mobile' => false ),
116
	'pre_shared_key' => array( 'name' => 'Mutual PSK', 'mobile' => false ) );
117

    
118
$p2_modes = array(
119
	'tunnel' => 'Tunnel IPv4',
120
	'tunnel6' => 'Tunnel IPv6',
121
	'transport' => 'Transport');
122

    
123
$p2_protos = array(
124
	'esp' => 'ESP',
125
	'ah' => 'AH');
126

    
127
$p2_pfskeygroups = array(
128
	0 => 'off',
129
	1  => '1 (768 bit)',
130
	2  => '2 (1024 bit)',
131
	5  => '5 (1536 bit)',
132
	14 => '14 (2048 bit)',
133
	15 => '15 (3072 bit)',
134
	16 => '16 (4096 bit)',
135
	17 => '17 (6144 bit)',
136
	18 => '18 (8192 bit)'
137
);
138

    
139
/*
140
 * ikeid management functions
141
 */
142

    
143
function ipsec_ikeid_used($ikeid) {
144
	global $config;
145

    
146
	foreach ($config['ipsec']['phase1'] as $ph1ent)
147
		if( $ikeid == $ph1ent['ikeid'] )
148
			return true;
149

    
150
	return false;
151
}
152

    
153
function ipsec_ikeid_next() {
154

    
155
	$ikeid = 1;
156
	while(ipsec_ikeid_used($ikeid))
157
		$ikeid++;
158

    
159
	return $ikeid;
160
}
161

    
162
/*
163
 * Return phase1 local address
164
 */
165
function ipsec_get_phase1_src(& $ph1ent) {
166

    
167
	if ($ph1ent['interface']) {
168
		if (!is_ipaddr($ph1ent['interface'])) {
169
			if ($ph1ent['protocol'] == "inet6") { 
170
				$interfaceip = get_interface_ipv6($ph1ent['interface']);
171
			} else {
172
				$interfaceip = get_interface_ip($ph1ent['interface']);
173
			}
174
		} else {
175
			$interfaceip=$ph1ent['interface'];
176
		}
177
	} else {
178
		$if = "wan";
179
		if ($ph1ent['protocol'] == "inet6")
180
			$interfaceip = get_interface_ipv6($if);
181
		else
182
			$interfaceip = get_interface_ip($if);
183
	}
184

    
185
	return $interfaceip;
186
}
187

    
188
/*
189
 * Return phase1 local address
190
 */
191
function ipsec_get_phase1_dst(& $ph1ent) {
192
	global $g;
193

    
194
	if (empty($ph1ent['remote-gateway']))
195
		return false;
196
	$rg = $ph1ent['remote-gateway'];
197
	if (!is_ipaddr($rg)) {
198
		if(! platform_booting())
199
			return resolve_retry($rg);
200
	}
201
	if(!is_ipaddr($rg))
202
		return false;
203

    
204
	return $rg;
205
}
206

    
207
/*
208
 * Return phase2 idinfo in cidr format
209
 */
210
function ipsec_idinfo_to_cidr(& $idinfo, $addrbits = false, $mode = "") {
211
	global $config;
212

    
213
	switch ($idinfo['type']) {
214
		case "address":
215
			if ($addrbits) {
216
				if ($mode == "tunnel6")
217
					return $idinfo['address']."/128";
218
				else
219
					return $idinfo['address']."/32";
220
			} else
221
				return $idinfo['address'];
222
			break; /* NOTREACHED */
223
		case "network":
224
			return "{$idinfo['address']}/{$idinfo['netbits']}";
225
			break; /* NOTREACHED */
226
		case "none":
227
		case "mobile":
228
			return '0.0.0.0/0';
229
			break; /* NOTREACHED */
230
		default:
231
			if (empty($mode) && !empty($idinfo['mode']))
232
				$mode = $idinfo['mode'];
233

    
234
			if ($mode == "tunnel6") {
235
				$address = get_interface_ipv6($idinfo['type']);
236
				$netbits = get_interface_subnetv6($idinfo['type']);
237
				$address = gen_subnetv6($address,$netbits);
238
				return "{$address}/{$netbits}";
239
			} else {
240
				$address = get_interface_ip($idinfo['type']);
241
				$netbits = get_interface_subnet($idinfo['type']);
242
				$address = gen_subnet($address,$netbits);
243
				return "{$address}/{$netbits}";
244
			}
245
			break; /* NOTREACHED */
246
	}
247
}
248

    
249
/*
250
 * Return phase2 idinfo in address/netmask format
251
 */
252
function ipsec_idinfo_to_subnet(& $idinfo,$addrbits = false) {
253
	global $config;
254

    
255
	switch ($idinfo['type']) {
256
		case "address":
257
			if ($addrbits) {
258
				if ($idinfo['mode'] == "tunnel6")
259
					return $idinfo['address']."/128";
260
				else
261
					return $idinfo['address']."/255.255.255.255";
262
			} else
263
				return $idinfo['address'];
264
			break; /* NOTREACHED */
265
		case "none":
266
		case "network":
267
			return $idinfo['address']."/".gen_subnet_mask($idinfo['netbits']);
268
			break; /* NOTREACHED */
269
		case "mobile":
270
			return "0.0.0.0/0";
271
			break; /* NOTREACHED */
272
		default:
273
			if ($idinfo['mode'] == "tunnel6") {
274
				$address = get_interface_ipv6($idinfo['type']);
275
				$netbits = get_interface_subnetv6($idinfo['type']);
276
				$address = gen_subnetv6($address,$netbits);
277
				return $address."/".$netbits;
278
			} else {
279
				$address = get_interface_ip($idinfo['type']);
280
				$netbits = get_interface_subnet($idinfo['type']);
281
				$address = gen_subnet($address,$netbits);
282
				return $address."/".$netbits;
283
			}
284
			break; /* NOTREACHED */
285
	}
286
}
287

    
288
/*
289
 *  Return phase2 idinfo in text format
290
 */
291
function ipsec_idinfo_to_text(& $idinfo) {
292
	global $config;
293

    
294
	switch ($idinfo['type']) {
295
        case "address":
296
		return $idinfo['address'];
297
		break; /* NOTREACHED */
298
        case "network":
299
		return $idinfo['address']."/".$idinfo['netbits'];
300
		break; /* NOTREACHED */
301
	case "mobile":
302
		return gettext("Mobile Client");
303
		break; /* NOTREACHED */
304
	case "none":
305
		return gettext("None");
306
		break; /* NOTREACHED */
307
        default:
308
		if (!empty($config['interfaces'][$idinfo['type']]))
309
			return convert_friendly_interface_to_friendly_descr($idinfo['type']);
310
		else
311
			return strtoupper($idinfo['type']);
312
		break; /* NOTREACHED */
313
	}
314
}
315

    
316
/*
317
 * Return phase1 association for phase2
318
 */
319
function ipsec_lookup_phase1(& $ph2ent,& $ph1ent) {
320
	global $config;
321

    
322
	if (!is_array($config['ipsec']))
323
		return false;
324
	if (!is_array($config['ipsec']['phase1']))
325
		return false;
326
	if (empty($config['ipsec']['phase1']))
327
		return false;
328

    
329
	foreach ($config['ipsec']['phase1'] as $ph1tmp) {
330
	    if ($ph1tmp['ikeid'] == $ph2ent['ikeid']) {
331
		$ph1ent = $ph1tmp;
332
		return $ph1ent;
333
	    }
334
	}
335

    
336
	return false;
337
}
338

    
339
/*
340
 * Check phase1 communications status
341
 */
342
function ipsec_phase1_status(&$ipsec_status, $ikeid) {
343

    
344
	foreach ($ipsec_status as $ike) {
345
		if ($ike['id'] == $ikeid) {
346
			if ($ike['status'] == 'established')
347
				return true;
348
		}
349
	}
350

    
351
	return false;
352
}
353

    
354
/*
355
 * Check phase2 communications status
356
 */
357
function ipsec_phase2_status(&$ipsec_status, &$phase2) {
358

    
359
	if (ipsec_lookup_phase1($ph2ent,$ph1ent))
360
		return ipsec_phase1_status($ipsec_status, $ph1ent['ikeid']);
361

    
362
	return false;
363
}
364

    
365
function ipsec_smp_dump_status() {
366
	global $config, $g, $custom_listtags;
367

    
368
	if (!file_exists("{$g['varrun_path']}/charon.xml")) {
369
		log_error("IPsec daemon not running or has a problem!");
370
		return;
371
	}
372

    
373
	$fd = @fsockopen("unix://{$g['varrun_path']}/charon.xml");
374
	if (!$fd) {
375
		log_error("Could not read status from IPsec");
376
		return;
377
	}
378
	$query = '<?xml version="1.0"?><message xmlns="http://www.strongswan.org/smp/1.0" type="request" id="1">';
379
	$query .= '<query><ikesalist/></query></message>';
380

    
381
	@fwrite($fd, $query);
382
	$response = "";
383
	while (!strstr($sread, "</message>")) {
384
		$sread = fgets($fd);
385
		if ($sread === false)
386
			break;
387
		$response .= $sread;
388
	}
389
	fclose($fd);
390

    
391
	if ($sread === false) {
392
		log_error("Error during reading of status from IPsec");
393
		return;
394
	}
395

    
396
	@file_put_contents("{$g['tmp_path']}/smp_status.xml", $response);
397
	unset($response, $sread);
398

    
399
	$custom_listtags = array('ikesa', 'childsa', 'network', 'auth');
400
	$response = parse_xml_config("{$g['tmp_path']}/smp_status.xml", "message");
401
	@unlink("{$g['tmp_path']}/smp_status.xml");
402
	unset($custom_listtags);
403

    
404
	return $response;
405
}
406

    
407
/*
408
 * Return dump of SPD table
409
 */
410
function ipsec_dump_spd()
411
{
412
	$fd = @popen("/sbin/setkey -DP", "r");
413
	$spd = array();
414
	if ($fd) {
415
		while (!feof($fd)) {
416
			$line = chop(fgets($fd));
417
			if (!$line)
418
				continue;
419
			if ($line == "No SPD entries.")
420
				break;
421
			if ($line[0] != "\t") {
422
				if (is_array($cursp))
423
					$spd[] = $cursp;
424
				$cursp = array();
425
				$linea = explode(" ", $line);
426
				$cursp['srcid'] = substr($linea[0], 0, strpos($linea[0], "["));
427
				$cursp['dstid'] = substr($linea[1], 0, strpos($linea[1], "["));
428
				$i = 0;
429
			} else if (is_array($cursp)) {
430
				$line = trim($line, "\t\r\n ");
431
				$linea = explode(" ", $line);
432
				switch($i)
433
				{
434
					case 1:
435
						if ($linea[1] == "none")	/* don't show default anti-lockout rule */
436
							unset($cursp);
437
						else
438
							$cursp['dir'] = $linea[0];
439
						break;
440
					case 2:
441
						$upperspec = explode("/", $linea[0]);
442
						$cursp['proto'] = $upperspec[0];
443
						list($cursp['src'], $cursp['dst']) = explode("-", $upperspec[2]);
444
						$cursp['reqid'] =  substr($upperspec[3], strpos($upperspec[3], "#")+1);
445
						break;
446
				}
447
			}
448
			$i++;
449
		}
450
		if (is_array($cursp) && count($cursp))
451
			$spd[] = $cursp;
452
		pclose($fd);
453
	}
454

    
455
	return $spd;
456
}
457

    
458
/*
459
 * Return dump of SAD table
460
 */
461
function ipsec_dump_sad()
462
{
463
	$fd = @popen("/sbin/setkey -D", "r");
464
	$sad = array();
465
	if ($fd) {
466
		while (!feof($fd)) {
467
			$line = chop(fgets($fd));
468
			if (!$line || $line[0] == " ")
469
				continue;
470
			if ($line == "No SAD entries.")
471
				break;
472
			if ($line[0] != "\t")
473
			{
474
				if (is_array($cursa))
475
					$sad[] = $cursa;
476
				$cursa = array();
477
				list($cursa['src'],$cursa['dst']) = explode(" ", $line);
478
			}
479
			else
480
			{
481
				$line = trim($line, "\t\n\r ");
482
				$linea = explode(" ", $line);
483
				foreach ($linea as $idx => $linee) {
484
					if ($linee == 'esp' || $linee == 'ah' || $linee[0] == '#')
485
						$cursa['proto'] = $linee;
486
					else if (substr($linee, 0, 3) == 'spi')
487
						$cursa['spi'] = substr($linee, strpos($linee, 'x') + 1, -1);
488
					else if (substr($linee, 0, 5) == 'reqid')
489
						$cursa['reqid'] = substr($linee, strpos($linee, 'x') + 1, -1);
490
					else if (substr($linee, 0, 2) == 'E:') {
491
						$cursa['ealgo'] = $linea[$idx + 1];
492
						break;
493
					} else if (substr($linee, 0, 2) == 'A:') {
494
						$cursa['aalgo'] = $linea[$idx + 1];
495
						break;
496
					} else if (substr($linee, 0, 8) == 'current:') {
497
						$cursa['data'] = substr($linea[$idx + 1], 0, strpos($linea[$idx + 1], 'bytes') - 1) . ' B';
498
						break;
499
					}
500
						
501
				}
502
			}
503
		}
504
		if (is_array($cursa) && count($cursa))
505
			$sad[] = $cursa;
506
		pclose($fd);
507
	}
508

    
509
	return $sad;
510
}
511

    
512
/*
513
 * Return dump of mobile user list
514
 */
515
function ipsec_dump_mobile() {
516
	global $g, $custom_listtags;
517

    
518
	$_gb = exec("/usr/local/sbin/ipsec stroke leases > {$g['tmp_path']}/strongswan_leases.xml");
519

    
520
	if (!file_exists("{$g['tmp_path']}/strongswan_leases.xml")) {
521
		log_error(gettext("Unable to find IPsec daemon leases file. Could not display mobile user stats!"));
522
		return array();
523
	}
524

    
525
	/* This is needed for fixing #4130 */
526
	if (filesize("{$g['tmp_path']}/strongswan_leases.xml") < 200)
527
		return array();
528

    
529
	$custom_listtags = array('lease', 'pool');
530
	$response = parse_xml_config("{$g['tmp_path']}/strongswan_leases.xml", "leases");
531
	@unlink("{$g['tmp_path']}/strongswan_leases.xml");
532
	unset($custom_listtags, $_gb);
533

    
534
	return $response;
535
}
536

    
537
function ipsec_mobilekey_sort() {
538
	global $config;
539

    
540
	function mobilekeycmp($a, $b) {
541
		return strcmp($a['ident'][0], $b['ident'][0]);
542
	}
543

    
544
	usort($config['ipsec']['mobilekey'], "mobilekeycmp");
545
}
546

    
547
function ipsec_get_number_of_phase2($ikeid) {
548
	global $config;
549
    	$a_phase2 = $config['ipsec']['phase2'];
550

    
551
	$nbph2=0;
552

    
553
    	if (is_array($a_phase2) && count($a_phase2)) {
554
        	foreach ($a_phase2 as $ph2tmp) {
555
            		if ($ph2tmp['ikeid'] == $ikeid) {
556
				$nbph2++;
557
			}
558
		}
559
	}
560

    
561
	return $nbph2;
562
}
563

    
564
function ipsec_get_descr($ikeid) {
565
	global $config;
566

    
567
	if (!isset($config['ipsec']['phase1']) ||
568
	    !is_array($config['ipsec']['phase1']))
569
		return '';
570

    
571
	foreach ($config['ipsec']['phase1'] as $p1) {
572
		if ($p1['ikeid'] == $ikeid) {
573
			return $p1['descr'];
574
		}
575
	}
576

    
577
	return '';
578
}
579

    
580
function ipsec_get_phase1($ikeid) {
581
        global $config;
582

    
583
        if (!isset($config['ipsec']['phase1']) ||
584
            !is_array($config['ipsec']['phase1']))
585
                return '';
586

    
587
        $a_phase1 = $config['ipsec']['phase1'];
588
        foreach ($a_phase1 as $p1) {
589
                if ($p1['ikeid'] == $ikeid) {
590
                        return $p1;
591
                }
592
        }
593
        unset($a_phase1);
594
}
595

    
596
function ipsec_fixup_ip($ipaddr) {
597
	if (is_ipaddrv6($ipaddr) || is_subnetv6($ipaddr))
598
		return Net_IPv6::compress(Net_IPv6::uncompress($ipaddr));
599
	else
600
		return $ipaddr;
601
}
602

    
603
function ipsec_find_id(& $ph1ent, $side = "local", $rgmap = array()) {
604
	if ($side == "local") {
605
		$id_type = $ph1ent['myid_type'];
606
		$id_data = $ph1ent['myid_data'];
607

    
608
		$addr = ipsec_get_phase1_src($ph1ent);
609
		if (!$addr)
610
			return array();
611
	} elseif ($side = "peer") {
612
		$id_type = $ph1ent['peerid_type'];
613
		$id_data = $ph1ent['peerid_data'];
614

    
615
		if (isset($ph1ent['mobile']))
616
			$addr = "%any";
617
		else
618
			$addr = $ph1ent['remote-gateway'];
619
	} else
620
		return array();
621

    
622

    
623
	$thisid_type = $id_type;
624
	switch ($thisid_type) {
625
	case 'myaddress':
626
		$thisid_type = 'address';
627
		$thisid_data = $addr;
628
		break;
629
	case 'dyn_dns':
630
		$thisid_type = 'dns';
631
		$thisid_data = $id_data;
632
		break;
633
	case 'peeraddress':
634
		$thisid_type = 'address';
635
		$thisid_data = $rgmap[$ph1ent['remote-gateway']];
636
		break;
637
	case 'address';
638
		$thisid_data = $id_data;
639
		break;
640
	case 'fqdn';
641
		$thisid_data = "{$id_data}";
642
		break;
643
	case 'keyid tag';
644
		$thisid_type = 'keyid';
645
		$thisid_data = "{$thisid_data}";
646
		break;
647
	case 'user_fqdn';
648
		$thisid_type = 'userfqdn';
649
		$thisid_data = "{$id_data}";
650
		break;
651
	case 'asn1dn';
652
		$thisid_data = $id_data;
653
		$thisid_data = "{$id_data}";
654
		break;
655
	}
656
	return array($thisid_type, $thisid_data);
657
}
658

    
659
function ipsec_fixup_network($network) {
660
	if (substr($network, -3) == '|/0')
661
		$result = substr($network, 0, -3);
662
	else {
663
		$tmp = explode('|', $network);
664
		if (isset($tmp[1]))
665
			$result = $tmp[1];
666
		else
667
			$result = $tmp[0];
668
		unset($tmp);
669
	}
670

    
671
	return $result;
672
}
673

    
674
?>
(29-29/68)