aboutsummaryrefslogtreecommitdiffstats
path: root/src/libhydra/plugins/kernel_pfkey/kernel_pfkey_ipsec.c
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2010-12-07 11:58:09 +0100
committerTobias Brunner <tobias@strongswan.org>2010-12-07 12:14:50 +0100
commite6f42b0721b3376f04f6bef8287abe0188342619 (patch)
treeae945ad60a821efc1ab807b6dacf5c7dd54fd3ab /src/libhydra/plugins/kernel_pfkey/kernel_pfkey_ipsec.c
parent4332cd7f95ae93fbe4e3f6328c2b819c262ae049 (diff)
downloadstrongswan-e6f42b0721b3376f04f6bef8287abe0188342619.tar.bz2
strongswan-e6f42b0721b3376f04f6bef8287abe0188342619.tar.xz
Include the destination net in the policy priority calculation.
The resulting priorities are as follows: IPv6 IPv4 routed normal routed normal max 4096(+3) 2048(+3) 4096(+3) 2048(+3) min 3072 1024 3840 1792 Where min is for a policy between two single hosts and max is for /0 on both ends (lower priorities are preferred by the kernel). (+3) applies for cases where no protocol and no ports are defined.
Diffstat (limited to 'src/libhydra/plugins/kernel_pfkey/kernel_pfkey_ipsec.c')
-rw-r--r--src/libhydra/plugins/kernel_pfkey/kernel_pfkey_ipsec.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/libhydra/plugins/kernel_pfkey/kernel_pfkey_ipsec.c b/src/libhydra/plugins/kernel_pfkey/kernel_pfkey_ipsec.c
index f5786447b..a2220c48c 100644
--- a/src/libhydra/plugins/kernel_pfkey/kernel_pfkey_ipsec.c
+++ b/src/libhydra/plugins/kernel_pfkey/kernel_pfkey_ipsec.c
@@ -99,8 +99,8 @@
#endif
/** default priority of installed policies */
-#define PRIO_LOW 3000
-#define PRIO_HIGH 2000
+#define PRIO_LOW 1024
+#define PRIO_HIGH 512
#ifdef __APPLE__
/** from xnu/bsd/net/pfkeyv2.h */
@@ -1651,11 +1651,14 @@ METHOD(kernel_ipsec_t, add_policy, status_t,
pol->sadb_x_policy_dir = dir2kernel(direction);
pol->sadb_x_policy_type = IPSEC_POLICY_IPSEC;
#ifdef HAVE_STRUCT_SADB_X_POLICY_SADB_X_POLICY_PRIORITY
- /* calculate priority based on source selector size, small size = high prio */
+ /* calculate priority based on selector size, small size = high prio */
pol->sadb_x_policy_priority = routed ? PRIO_LOW : PRIO_HIGH;
- pol->sadb_x_policy_priority -= policy->src.mask * 10;
- pol->sadb_x_policy_priority -= policy->src.proto != IPSEC_PROTO_ANY ? 2 : 0;
- pol->sadb_x_policy_priority -= policy->src.net->get_port(policy->src.net) ? 1 : 0;
+ pol->sadb_x_policy_priority -= policy->src.mask;
+ pol->sadb_x_policy_priority -= policy->dst.mask;
+ pol->sadb_x_policy_priority <<= 2; /* make some room for the flags */
+ pol->sadb_x_policy_priority += policy->src.net->get_port(policy->src.net) ||
+ policy->dst.net->get_port(policy->dst.net) ? 0 : 2;
+ pol->sadb_x_policy_priority += policy->src.proto != IPSEC_PROTO_ANY ? 0 : 1;
#endif
/* one or more sadb_x_ipsecrequest extensions are added to the sadb_x_policy extension */