Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
9766a61a
Commit
9766a61a
authored
Jan 10, 2016
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(legacy) code style ipsec.inc
parent
4b4e32b7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
326 additions
and
320 deletions
+326
-320
ipsec.inc
src/etc/inc/ipsec.inc
+326
-320
No files found.
src/etc/inc/ipsec.inc
View file @
9766a61a
<?php
<?php
/*
/*
Copyright (C) 2007 Scott Ullrich
Copyright (C) 2007 Scott Ullrich
Copyright (C) 2008 Shrew Soft Inc
Copyright (C) 2008 Shrew Soft Inc
Copyright (C) 2003-2004 Manuel Kasper
Copyright (C) 2003-2004 Manuel Kasper
All rights reserved.
All rights reserved.
Redistribution and use in source and binary forms, with or without
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
POSSIBILITY OF SUCH DAMAGE.
*/
*/
/* IPsec defines */
/* IPsec defines */
$ipsec_loglevels
=
array
(
"dmn"
=>
"Daemon"
,
"mgr"
=>
"SA Manager"
,
"ike"
=>
"IKE SA"
,
"chd"
=>
"IKE Child SA"
,
$ipsec_loglevels
=
array
(
"dmn"
=>
"Daemon"
,
"mgr"
=>
"SA Manager"
,
"ike"
=>
"IKE SA"
,
"chd"
=>
"IKE Child SA"
,
"job"
=>
"Job Processing"
,
"cfg"
=>
"Configuration backend"
,
"knl"
=>
"Kernel Interface"
,
"job"
=>
"Job Processing"
,
"cfg"
=>
"Configuration backend"
,
"knl"
=>
"Kernel Interface"
,
"net"
=>
"Networking"
,
"asn"
=>
"ASN encoding"
,
"enc"
=>
"Message encoding"
,
"net"
=>
"Networking"
,
"asn"
=>
"ASN encoding"
,
"enc"
=>
"Message encoding"
,
"imc"
=>
"Integrity checker"
,
"imv"
=>
"Integrity Verifier"
,
"pts"
=>
"Platform Trust Service"
,
"imc"
=>
"Integrity checker"
,
"imv"
=>
"Integrity Verifier"
,
"pts"
=>
"Platform Trust Service"
,
"tls"
=>
"TLS handler"
,
"esp"
=>
"IPsec traffic"
,
"lib"
=>
"StrongSWAN Lib"
);
"tls"
=>
"TLS handler"
,
"esp"
=>
"IPsec traffic"
,
"lib"
=>
"StrongSWAN Lib"
);
$p1_ealgos
=
array
(
$p1_ealgos
=
array
(
'aes'
=>
array
(
'name'
=>
'AES'
,
'keysel'
=>
array
(
'lo'
=>
128
,
'hi'
=>
256
,
'step'
=>
64
)
),
'aes'
=>
array
(
'name'
=>
'AES'
,
'keysel'
=>
array
(
'lo'
=>
128
,
'hi'
=>
256
,
'step'
=>
64
)
),
'aes128gcm'
=>
array
(
'name'
=>
'AES128-GCM'
,
'keysel'
=>
array
(
'lo'
=>
64
,
'hi'
=>
128
,
'step'
=>
32
)
),
'aes128gcm'
=>
array
(
'name'
=>
'AES128-GCM'
,
'keysel'
=>
array
(
'lo'
=>
64
,
'hi'
=>
128
,
'step'
=>
32
)
),
'aes192gcm'
=>
array
(
'name'
=>
'AES192-GCM'
,
'keysel'
=>
array
(
'lo'
=>
64
,
'hi'
=>
128
,
'step'
=>
32
)
),
'aes192gcm'
=>
array
(
'name'
=>
'AES192-GCM'
,
'keysel'
=>
array
(
'lo'
=>
64
,
'hi'
=>
128
,
'step'
=>
32
)
),
'aes256gcm'
=>
array
(
'name'
=>
'AES256-GCM'
,
'keysel'
=>
array
(
'lo'
=>
64
,
'hi'
=>
128
,
'step'
=>
32
)
),
'aes256gcm'
=>
array
(
'name'
=>
'AES256-GCM'
,
'keysel'
=>
array
(
'lo'
=>
64
,
'hi'
=>
128
,
'step'
=>
32
)
),
'blowfish'
=>
array
(
'name'
=>
'Blowfish'
,
'keysel'
=>
array
(
'lo'
=>
128
,
'hi'
=>
256
,
'step'
=>
64
)
),
'blowfish'
=>
array
(
'name'
=>
'Blowfish'
,
'keysel'
=>
array
(
'lo'
=>
128
,
'hi'
=>
256
,
'step'
=>
64
)
),
'3des'
=>
array
(
'name'
=>
'3DES'
),
'3des'
=>
array
(
'name'
=>
'3DES'
),
'cast128'
=>
array
(
'name'
=>
'CAST128'
),
'cast128'
=>
array
(
'name'
=>
'CAST128'
),
'des'
=>
array
(
'name'
=>
'DES'
));
'des'
=>
array
(
'name'
=>
'DES'
)
);
$p2_ealgos
=
array
(
$p2_ealgos
=
array
(
'aes'
=>
array
(
'name'
=>
'AES'
,
'keysel'
=>
array
(
'lo'
=>
128
,
'hi'
=>
256
,
'step'
=>
64
)
),
'aes'
=>
array
(
'name'
=>
'AES'
,
'keysel'
=>
array
(
'lo'
=>
128
,
'hi'
=>
256
,
'step'
=>
64
)
),
'aes128gcm'
=>
array
(
'name'
=>
'AES128-GCM'
,
'keysel'
=>
array
(
'lo'
=>
64
,
'hi'
=>
128
,
'step'
=>
32
)
),
'aes128gcm'
=>
array
(
'name'
=>
'AES128-GCM'
,
'keysel'
=>
array
(
'lo'
=>
64
,
'hi'
=>
128
,
'step'
=>
32
)
),
'aes192gcm'
=>
array
(
'name'
=>
'AES192-GCM'
,
'keysel'
=>
array
(
'lo'
=>
64
,
'hi'
=>
128
,
'step'
=>
32
)
),
'aes192gcm'
=>
array
(
'name'
=>
'AES192-GCM'
,
'keysel'
=>
array
(
'lo'
=>
64
,
'hi'
=>
128
,
'step'
=>
32
)
),
'aes256gcm'
=>
array
(
'name'
=>
'AES256-GCM'
,
'keysel'
=>
array
(
'lo'
=>
64
,
'hi'
=>
128
,
'step'
=>
32
)
),
'aes256gcm'
=>
array
(
'name'
=>
'AES256-GCM'
,
'keysel'
=>
array
(
'lo'
=>
64
,
'hi'
=>
128
,
'step'
=>
32
)
),
'blowfish'
=>
array
(
'name'
=>
'Blowfish'
,
'keysel'
=>
array
(
'lo'
=>
128
,
'hi'
=>
256
,
'step'
=>
64
)
),
'blowfish'
=>
array
(
'name'
=>
'Blowfish'
,
'keysel'
=>
array
(
'lo'
=>
128
,
'hi'
=>
256
,
'step'
=>
64
)
),
'3des'
=>
array
(
'name'
=>
'3DES'
),
'3des'
=>
array
(
'name'
=>
'3DES'
),
'cast128'
=>
array
(
'name'
=>
'CAST128'
),
'cast128'
=>
array
(
'name'
=>
'CAST128'
),
'des'
=>
array
(
'name'
=>
'DES'
));
'des'
=>
array
(
'name'
=>
'DES'
)
);
$p2_halgos
=
array
(
$p2_halgos
=
array
(
'hmac_md5'
=>
'MD5'
,
'hmac_md5'
=>
'MD5'
,
'hmac_sha1'
=>
'SHA1'
,
'hmac_sha1'
=>
'SHA1'
,
'hmac_sha256'
=>
'SHA256'
,
'hmac_sha256'
=>
'SHA256'
,
'hmac_sha384'
=>
'SHA384'
,
'hmac_sha384'
=>
'SHA384'
,
'hmac_sha512'
=>
'SHA512'
,
'hmac_sha512'
=>
'SHA512'
,
'aesxcbc'
=>
'AES-XCBC'
'aesxcbc'
=>
'AES-XCBC'
);
);
$p2_protos
=
array
(
$p2_protos
=
array
(
'esp'
=>
'ESP'
,
'esp'
=>
'ESP'
,
'ah'
=>
'AH'
);
'ah'
=>
'AH'
);
$p2_pfskeygroups
=
array
(
$p2_pfskeygroups
=
array
(
0
=>
'off'
,
0
=>
'off'
,
1
=>
'1 (768 bit)'
,
1
=>
'1 (768 bit)'
,
2
=>
'2 (1024 bit)'
,
2
=>
'2 (1024 bit)'
,
5
=>
'5 (1536 bit)'
,
5
=>
'5 (1536 bit)'
,
14
=>
'14 (2048 bit)'
,
14
=>
'14 (2048 bit)'
,
15
=>
'15 (3072 bit)'
,
15
=>
'15 (3072 bit)'
,
16
=>
'16 (4096 bit)'
,
16
=>
'16 (4096 bit)'
,
17
=>
'17 (6144 bit)'
,
17
=>
'17 (6144 bit)'
,
18
=>
'18 (8192 bit)'
18
=>
'18 (8192 bit)'
);
);
/*
/*
* Return phase1 local address
* Return phase1 local address
*/
*/
function
ipsec_get_phase1_src
(
&
$ph1ent
)
{
function
ipsec_get_phase1_src
(
&
$ph1ent
)
{
if
(
!
empty
(
$ph1ent
[
'interface'
]))
{
if
(
!
empty
(
$ph1ent
[
'interface'
]))
{
if
(
!
is_ipaddr
(
$ph1ent
[
'interface'
]))
{
if
(
!
is_ipaddr
(
$ph1ent
[
'interface'
]))
{
if
(
strpos
(
$ph1ent
[
'interface'
],
'_vip'
)
!==
false
)
{
if
(
strpos
(
$ph1ent
[
'interface'
],
'_vip'
)
!==
false
)
{
// if this is a vip, set the interface to $ph1ent['interface']
// if this is a vip, set the interface to $ph1ent['interface']
$if
=
$ph1ent
[
'interface'
];
$if
=
$ph1ent
[
'interface'
];
}
else
{
}
else
{
// not a vip, check failover interface
// not a vip, check failover interface
if
(
$ph1ent
[
'protocol'
]
==
"inet6"
)
{
if
(
$ph1ent
[
'protocol'
]
==
"inet6"
)
{
$if
=
get_failover_interface
(
$ph1ent
[
'interface'
],
"inet6"
);
$if
=
get_failover_interface
(
$ph1ent
[
'interface'
],
"inet6"
);
}
else
{
}
else
{
$if
=
get_failover_interface
(
$ph1ent
[
'interface'
]);
$if
=
get_failover_interface
(
$ph1ent
[
'interface'
]);
}
}
}
}
}
else
{
}
else
{
// interface is an ip address, return
// interface is an ip address, return
return
$ph1ent
[
'interface'
];
return
$ph1ent
[
'interface'
];
}
}
}
else
{
}
else
{
$if
=
"wan"
;
$if
=
"wan"
;
}
}
if
(
$ph1ent
[
'protocol'
]
==
"inet6"
)
{
if
(
$ph1ent
[
'protocol'
]
==
"inet6"
)
{
return
get_interface_ipv6
(
$if
);
return
get_interface_ipv6
(
$if
);
}
else
{
}
else
{
return
get_interface_ip
(
$if
);
return
get_interface_ip
(
$if
);
}
}
}
}
...
@@ -117,42 +121,45 @@ function ipsec_get_phase1_src(& $ph1ent) {
...
@@ -117,42 +121,45 @@ function ipsec_get_phase1_src(& $ph1ent) {
* Return phase2 idinfo in cidr format
* Return phase2 idinfo in cidr format
*/
*/
function
ipsec_idinfo_to_cidr
(
&
$idinfo
,
$addrbits
=
false
,
$mode
=
""
)
{
function
ipsec_idinfo_to_cidr
(
&
$idinfo
,
$addrbits
=
false
,
$mode
=
""
)
{
global
$config
;
global
$config
;
switch
(
$idinfo
[
'type'
])
{
switch
(
$idinfo
[
'type'
])
{
case
"address"
:
case
"address"
:
if
(
$addrbits
)
{
if
(
$addrbits
)
{
if
(
$mode
==
"tunnel6"
)
if
(
$mode
==
"tunnel6"
)
{
return
$idinfo
[
'address'
]
.
"/128"
;
return
$idinfo
[
'address'
]
.
"/128"
;
else
}
else
{
return
$idinfo
[
'address'
]
.
"/32"
;
return
$idinfo
[
'address'
]
.
"/32"
;
}
else
}
return
$idinfo
[
'address'
];
}
else
{
break
;
/* NOTREACHED */
return
$idinfo
[
'address'
];
case
"network"
:
}
return
"
{
$idinfo
[
'address'
]
}
/
{
$idinfo
[
'netbits'
]
}
"
;
break
;
/* NOTREACHED */
break
;
/* NOTREACHED */
case
"network"
:
case
"none"
:
return
"
{
$idinfo
[
'address'
]
}
/
{
$idinfo
[
'netbits'
]
}
"
;
case
"mobile"
:
break
;
/* NOTREACHED */
return
"0.0.0.0/0"
;
case
"none"
:
break
;
/* NOTREACHED */
case
"mobile"
:
default
:
return
"0.0.0.0/0"
;
if
(
empty
(
$mode
)
&&
!
empty
(
$idinfo
[
'mode'
]))
break
;
/* NOTREACHED */
$mode
=
$idinfo
[
'mode'
];
default
:
if
(
empty
(
$mode
)
&&
!
empty
(
$idinfo
[
'mode'
]))
{
if
(
$mode
==
"tunnel6"
)
{
$mode
=
$idinfo
[
'mode'
];
$address
=
get_interface_ipv6
(
$idinfo
[
'type'
]);
}
$netbits
=
get_interface_subnetv6
(
$idinfo
[
'type'
]);
$address
=
gen_subnetv6
(
$address
,
$netbits
);
if
(
$mode
==
"tunnel6"
)
{
return
"
{
$address
}
/
{
$netbits
}
"
;
$address
=
get_interface_ipv6
(
$idinfo
[
'type'
]);
}
else
{
$netbits
=
get_interface_subnetv6
(
$idinfo
[
'type'
]);
$address
=
get_interface_ip
(
$idinfo
[
'type'
]);
$address
=
gen_subnetv6
(
$address
,
$netbits
);
$netbits
=
get_interface_subnet
(
$idinfo
[
'type'
]);
return
"
{
$address
}
/
{
$netbits
}
"
;
$address
=
gen_subnet
(
$address
,
$netbits
);
}
else
{
return
"
{
$address
}
/
{
$netbits
}
"
;
$address
=
get_interface_ip
(
$idinfo
[
'type'
]);
}
$netbits
=
get_interface_subnet
(
$idinfo
[
'type'
]);
break
;
/* NOTREACHED */
$address
=
gen_subnet
(
$address
,
$netbits
);
}
return
"
{
$address
}
/
{
$netbits
}
"
;
}
break
;
/* NOTREACHED */
}
}
}
...
@@ -161,42 +168,43 @@ function ipsec_idinfo_to_cidr(& $idinfo, $addrbits = false, $mode = "") {
...
@@ -161,42 +168,43 @@ function ipsec_idinfo_to_cidr(& $idinfo, $addrbits = false, $mode = "") {
*/
*/
function
ipsec_lookup_phase1
(
&
$ph2ent
,
&
$ph1ent
)
function
ipsec_lookup_phase1
(
&
$ph2ent
,
&
$ph1ent
)
{
{
global
$config
;
global
$config
;
if
(
!
isset
(
$config
[
'ipsec'
])
||
!
is_array
(
$config
[
'ipsec'
]))
{
if
(
!
isset
(
$config
[
'ipsec'
])
||
!
is_array
(
$config
[
'ipsec'
]))
{
return
false
;
return
false
;
}
}
if
(
!
is_array
(
$config
[
'ipsec'
][
'phase1'
]))
{
if
(
!
is_array
(
$config
[
'ipsec'
][
'phase1'
]))
{
return
false
;
return
false
;
}
}
if
(
empty
(
$config
[
'ipsec'
][
'phase1'
]))
{
if
(
empty
(
$config
[
'ipsec'
][
'phase1'
]))
{
return
false
;
return
false
;
}
}
foreach
(
$config
[
'ipsec'
][
'phase1'
]
as
$ph1tmp
)
{
foreach
(
$config
[
'ipsec'
][
'phase1'
]
as
$ph1tmp
)
{
if
(
$ph1tmp
[
'ikeid'
]
==
$ph2ent
[
'ikeid'
])
{
if
(
$ph1tmp
[
'ikeid'
]
==
$ph2ent
[
'ikeid'
])
{
$ph1ent
=
$ph1tmp
;
$ph1ent
=
$ph1tmp
;
return
$ph1ent
;
return
$ph1ent
;
}
}
}
}
return
false
;
return
false
;
}
}
/*
/*
* Check phase1 communications status
* Check phase1 communications status
*/
*/
function
ipsec_phase1_status
(
$ipsec_status
,
$ikeid
)
{
function
ipsec_phase1_status
(
$ipsec_status
,
$ikeid
)
{
foreach
(
$ipsec_status
as
$ike
)
{
foreach
(
$ipsec_status
as
$ike
)
{
if
(
$ike
[
'id'
]
!=
$ikeid
)
{
if
(
$ike
[
'id'
]
!=
$ikeid
)
continue
;
continue
;
}
if
(
$ike
[
'status'
]
==
'established'
)
if
(
$ike
[
'status'
]
==
'established'
)
{
return
true
;
return
true
;
break
;
}
}
break
;
}
return
false
;
return
false
;
}
}
/*
/*
...
@@ -204,49 +212,53 @@ function ipsec_phase1_status($ipsec_status, $ikeid) {
...
@@ -204,49 +212,53 @@ function ipsec_phase1_status($ipsec_status, $ikeid) {
*/
*/
function
ipsec_dump_spd
()
function
ipsec_dump_spd
()
{
{
$fd
=
@
popen
(
"/sbin/setkey -DP"
,
"r"
);
$fd
=
@
popen
(
"/sbin/setkey -DP"
,
"r"
);
$spd
=
array
();
$spd
=
array
();
if
(
$fd
)
{
if
(
$fd
)
{
while
(
!
feof
(
$fd
))
{
while
(
!
feof
(
$fd
))
{
$line
=
chop
(
fgets
(
$fd
));
$line
=
chop
(
fgets
(
$fd
));
if
(
!
$line
)
if
(
!
$line
)
{
continue
;
continue
;
if
(
$line
==
"No SPD entries."
)
}
break
;
if
(
$line
==
"No SPD entries."
)
{
if
(
$line
[
0
]
!=
"
\t
"
)
{
break
;
if
(
isset
(
$cursp
))
}
$spd
[]
=
$cursp
;
if
(
$line
[
0
]
!=
"
\t
"
)
{
$cursp
=
array
();
if
(
isset
(
$cursp
))
{
$linea
=
explode
(
" "
,
$line
);
$spd
[]
=
$cursp
;
$cursp
[
'srcid'
]
=
substr
(
$linea
[
0
],
0
,
strpos
(
$linea
[
0
],
"["
));
}
$cursp
[
'dstid'
]
=
substr
(
$linea
[
1
],
0
,
strpos
(
$linea
[
1
],
"["
));
$cursp
=
array
();
$i
=
0
;
$linea
=
explode
(
" "
,
$line
);
}
else
if
(
isset
(
$cursp
))
{
$cursp
[
'srcid'
]
=
substr
(
$linea
[
0
],
0
,
strpos
(
$linea
[
0
],
"["
));
$linea
=
explode
(
" "
,
trim
(
$line
));
$cursp
[
'dstid'
]
=
substr
(
$linea
[
1
],
0
,
strpos
(
$linea
[
1
],
"["
));
switch
(
$i
)
$i
=
0
;
{
}
elseif
(
isset
(
$cursp
))
{
case
1
:
$linea
=
explode
(
" "
,
trim
(
$line
));
if
(
$linea
[
1
]
==
"none"
)
/* don't show default anti-lockout rule */
switch
(
$i
)
{
unset
(
$cursp
);
case
1
:
else
if
(
$linea
[
1
]
==
"none"
)
{
/* don't show default anti-lockout rule */
$cursp
[
'dir'
]
=
$linea
[
0
];
unset
(
$cursp
);
break
;
}
else
{
case
2
:
$cursp
[
'dir'
]
=
$linea
[
0
];
$upperspec
=
explode
(
"/"
,
$linea
[
0
]);
}
$cursp
[
'proto'
]
=
$upperspec
[
0
];
break
;
list
(
$cursp
[
'src'
],
$cursp
[
'dst'
])
=
explode
(
"-"
,
$upperspec
[
2
]);
case
2
:
$cursp
[
'reqid'
]
=
substr
(
$upperspec
[
3
],
strpos
(
$upperspec
[
3
],
"#"
)
+
1
);
$upperspec
=
explode
(
"/"
,
$linea
[
0
]);
break
;
$cursp
[
'proto'
]
=
$upperspec
[
0
];
}
list
(
$cursp
[
'src'
],
$cursp
[
'dst'
])
=
explode
(
"-"
,
$upperspec
[
2
]);
}
$cursp
[
'reqid'
]
=
substr
(
$upperspec
[
3
],
strpos
(
$upperspec
[
3
],
"#"
)
+
1
);
$i
++
;
break
;
}
}
if
(
isset
(
$cursp
)
&&
count
(
$cursp
))
}
$spd
[]
=
$cursp
;
$i
++
;
pclose
(
$fd
);
}
}
if
(
isset
(
$cursp
)
&&
count
(
$cursp
))
{
$spd
[]
=
$cursp
;
return
$spd
;
}
pclose
(
$fd
);
}
return
$spd
;
}
}
/*
/*
...
@@ -254,141 +266,135 @@ function ipsec_dump_spd()
...
@@ -254,141 +266,135 @@ function ipsec_dump_spd()
*/
*/
function
ipsec_dump_sad
()
function
ipsec_dump_sad
()
{
{
$fd
=
@
popen
(
"/sbin/setkey -D"
,
"r"
);
$fd
=
@
popen
(
"/sbin/setkey -D"
,
"r"
);
$sad
=
array
();
$sad
=
array
();
if
(
$fd
)
{
if
(
$fd
)
{
while
(
!
feof
(
$fd
))
{
while
(
!
feof
(
$fd
))
{
$line
=
chop
(
fgets
(
$fd
));
$line
=
chop
(
fgets
(
$fd
));
if
(
!
$line
||
$line
[
0
]
==
" "
)
if
(
!
$line
||
$line
[
0
]
==
" "
)
{
continue
;
continue
;
if
(
$line
==
"No SAD entries."
)
}
break
;
if
(
$line
==
"No SAD entries."
)
{
if
(
$line
[
0
]
!=
"
\t
"
)
break
;
{
}
if
(
is_array
(
$cursa
))
if
(
$line
[
0
]
!=
"
\t
"
)
{
$sad
[]
=
$cursa
;
if
(
is_array
(
$cursa
))
{
$cursa
=
array
();
$sad
[]
=
$cursa
;
list
(
$cursa
[
'src'
],
$cursa
[
'dst'
])
=
explode
(
" "
,
$line
);
}
$i
=
0
;
$cursa
=
array
();
}
list
(
$cursa
[
'src'
],
$cursa
[
'dst'
])
=
explode
(
" "
,
$line
);
else
$i
=
0
;
{
}
else
{
$linea
=
explode
(
" "
,
trim
(
$line
));
$linea
=
explode
(
" "
,
trim
(
$line
));
switch
(
$i
)
{
switch
(
$i
)
{
case
1
:
case
1
:
$cursa
[
'proto'
]
=
$linea
[
0
];
$cursa
[
'proto'
]
=
$linea
[
0
];
$cursa
[
'spi'
]
=
substr
(
$linea
[
2
],
strpos
(
$linea
[
2
],
"x"
)
+
1
,
-
1
);
$cursa
[
'spi'
]
=
substr
(
$linea
[
2
],
strpos
(
$linea
[
2
],
"x"
)
+
1
,
-
1
);
$reqid
=
substr
(
$linea
[
3
],
strpos
(
$linea
[
3
],
"="
)
+
1
);
$reqid
=
substr
(
$linea
[
3
],
strpos
(
$linea
[
3
],
"="
)
+
1
);
$cursa
[
'reqid'
]
=
substr
(
$reqid
,
0
,
strcspn
(
$reqid
,
"("
));
$cursa
[
'reqid'
]
=
substr
(
$reqid
,
0
,
strcspn
(
$reqid
,
"("
));
break
;
break
;
case
2
:
case
2
:
$cursa
[
'ealgo'
]
=
$linea
[
1
];
$cursa
[
'ealgo'
]
=
$linea
[
1
];
break
;
break
;
case
3
:
case
3
:
$cursa
[
'aalgo'
]
=
$linea
[
1
];
$cursa
[
'aalgo'
]
=
$linea
[
1
];
break
;
break
;
case
8
:
case
8
:
$sadata
=
explode
(
"("
,
$linea
[
1
]);
$sadata
=
explode
(
"("
,
$linea
[
1
]);
$cursa
[
'data'
]
=
$sadata
[
0
]
.
" B"
;
$cursa
[
'data'
]
=
$sadata
[
0
]
.
" B"
;
break
;
break
;
}
}
}
}
$i
++
;
$i
++
;
}
}
if
(
is_array
(
$cursa
)
&&
count
(
$cursa
))
if
(
is_array
(
$cursa
)
&&
count
(
$cursa
))
{
$sad
[]
=
$cursa
;
$sad
[]
=
$cursa
;
pclose
(
$fd
);
}
}
pclose
(
$fd
);
}
return
$sad
;
return
$sad
;
}
}
function
ipsec_mobilekey_sort
()
{
function
ipsec_mobilekey_sort
()
{
global
$config
;
global
$config
;
function
mobilekeycmp
(
$a
,
$b
)
{
function
mobilekeycmp
(
$a
,
$b
)
{
return
strcmp
(
$a
[
'ident'
][
0
],
$b
[
'ident'
][
0
]);
return
strcmp
(
$a
[
'ident'
][
0
],
$b
[
'ident'
][
0
]);
}
}
usort
(
$config
[
'ipsec'
][
'mobilekey'
],
"mobilekeycmp"
);
usort
(
$config
[
'ipsec'
][
'mobilekey'
],
"mobilekeycmp"
);
}
}
function
ipsec_get_number_of_phase2
(
$ikeid
)
{
function
ipsec_get_number_of_phase2
(
$ikeid
)
{
global
$config
;
global
$config
;
$a_phase2
=
$config
[
'ipsec'
][
'phase2'
];
$a_phase2
=
$config
[
'ipsec'
][
'phase2'
];
$nbph2
=
0
;
$nbph2
=
0
;
if
(
is_array
(
$a_phase2
)
&&
count
(
$a_phase2
))
{
foreach
(
$a_phase2
as
$ph2tmp
)
{
if
(
is_array
(
$a_phase2
)
&&
count
(
$a_phase2
))
{
if
(
$ph2tmp
[
'ikeid'
]
==
$ikeid
)
{
foreach
(
$a_phase2
as
$ph2tmp
)
{
$nbph2
++
;
if
(
$ph2tmp
[
'ikeid'
]
==
$ikeid
)
{
}
$nbph2
++
;
}
}
}
}
return
$nbph2
;
}
return
$nbph2
;
}
}
function
ipsec_find_id
(
&
$ph1ent
,
$side
=
"local"
,
$rgmap
=
array
())
{
function
ipsec_find_id
(
&
$ph1ent
,
$side
=
"local"
,
$rgmap
=
array
())
{
$id_data
=
null
;
$id_data
=
null
;
if
(
$side
==
"local"
)
{
if
(
$side
==
"local"
)
{
$id_type
=
$ph1ent
[
'myid_type'
];
$id_type
=
$ph1ent
[
'myid_type'
];
if
(
isset
(
$ph1ent
[
'myid_data'
]))
{
if
(
isset
(
$ph1ent
[
'myid_data'
]))
{
$id_data
=
$ph1ent
[
'myid_data'
];
$id_data
=
$ph1ent
[
'myid_data'
];
}
}
$addr
=
ipsec_get_phase1_src
(
$ph1ent
);
$addr
=
ipsec_get_phase1_src
(
$ph1ent
);
if
(
!
$addr
)
if
(
!
$addr
)
{
return
array
();
return
array
();
}
elseif
(
$side
==
"peer"
)
{
}
$id_type
=
$ph1ent
[
'peerid_type'
];
}
elseif
(
$side
==
"peer"
)
{
if
(
isset
(
$ph1ent
[
'peerid_data'
]))
{
$id_type
=
$ph1ent
[
'peerid_type'
];
$id_data
=
$ph1ent
[
'peerid_data'
];
if
(
isset
(
$ph1ent
[
'peerid_data'
]))
{
}
$id_data
=
$ph1ent
[
'peerid_data'
];
}
if
(
isset
(
$ph1ent
[
'mobile'
]))
$addr
=
"%any"
;
if
(
isset
(
$ph1ent
[
'mobile'
]))
{
else
$addr
=
"%any"
;
$addr
=
$ph1ent
[
'remote-gateway'
];
}
else
{
}
else
{
$addr
=
$ph1ent
[
'remote-gateway'
];
return
array
();
}
}
}
else
{
return
array
();
}
$thisid_type
=
$id_type
;
switch
(
$thisid_type
)
{
$thisid_type
=
$id_type
;
case
"myaddress"
:
switch
(
$thisid_type
)
{
$thisid_type
=
"address"
;
case
"myaddress"
:
$thisid_data
=
$addr
;
$thisid_type
=
"address"
;
break
;
$thisid_data
=
$addr
;
break
;
case
"dyn_dns"
:
case
"dyn_dns"
:
$thisid_type
=
"address"
;
$thisid_type
=
"address"
;
$thisid_data
=
resolve_retry
(
$id_data
);
$thisid_data
=
resolve_retry
(
$id_data
);
break
;
break
;
case
"peeraddress"
:
case
"peeraddress"
:
$thisid_type
=
"address"
;
$thisid_type
=
"address"
;
$thisid_data
=
$rgmap
[
$ph1ent
[
'remote-gateway'
]];
$thisid_data
=
$rgmap
[
$ph1ent
[
'remote-gateway'
]];
break
;
break
;
case
"address"
;
$thisid_data
=
$id_data
;
case
"address"
;
break
;
$thisid_data
=
$id_data
;
case
"fqdn"
;
break
;
case
"keyid tag"
;
case
"user_fqdn"
;
case
"fqdn"
;
case
"asn1dn"
;
case
"keyid tag"
;
$thisid_data
=
$id_data
;
case
"user_fqdn"
;
if
(
$thisid_data
)
{
case
"asn1dn"
;
$thisid_data
=
"
{
$thisid_data
}
"
;
$thisid_data
=
$id_data
;
}
if
(
$thisid_data
)
break
;
$thisid_data
=
"
{
$thisid_data
}
"
;
}
break
;
return
array
(
$thisid_type
,
$thisid_data
);
}
return
array
(
$thisid_type
,
$thisid_data
);
}
}
?>
?>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment