33a057b4478c7575569476e065b058fc28a6c49c
[strongswan.git] / src / starter / cmp.c
1 /* strongSwan IPsec starter comparison functions
2 * Copyright (C) 2001-2002 Mathieu Lafon - Arkoon Network Security
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 */
14
15 #include <string.h>
16
17 #include <freeswan.h>
18
19 #include "../pluto/constants.h"
20 #include "../pluto/defs.h"
21
22 #include "confread.h"
23 #include "args.h"
24 #include "interfaces.h"
25 #include "cmp.h"
26
27 #define VARCMP(obj) if (c1->obj != c2->obj) return FALSE
28 #define ADDCMP(obj) if (!sameaddr(&c1->obj,&c2->obj)) return FALSE
29 #define SUBCMP(obj) if (!samesubnet(&c1->obj,&c2->obj)) return FALSE
30 #define STRCMP(obj) if (strcmp(c1->obj,c2->obj)) return FALSE
31
32 static bool
33 starter_cmp_end(starter_end_t *c1, starter_end_t *c2)
34 {
35 if ((c1 == NULL) || (c2 == NULL))
36 return FALSE;
37
38 if (c2->dns_failed)
39 {
40 c2->addr = c1->addr;
41 }
42 else
43 {
44 ADDCMP(addr);
45 }
46 VARCMP(ikeport);
47 ADDCMP(nexthop);
48 VARCMP(has_client);
49 VARCMP(has_client_wildcard);
50 VARCMP(has_port_wildcard);
51 VARCMP(has_natip);
52 VARCMP(has_virt);
53 VARCMP(modecfg);
54 VARCMP(port);
55 VARCMP(protocol);
56
57 return cmp_args(KW_END_FIRST, KW_END_LAST, (char *)c1, (char *)c2);
58 }
59
60 bool
61 starter_cmp_conn(starter_conn_t *c1, starter_conn_t *c2)
62 {
63 if ((c1 == NULL) || (c2 == NULL))
64 return FALSE;
65
66 VARCMP(policy);
67 VARCMP(addr_family);
68 VARCMP(tunnel_addr_family);
69
70 if (!starter_cmp_end(&c1->left, &c2->left))
71 return FALSE;
72 if (!starter_cmp_end(&c1->right, &c2->right))
73 return FALSE;
74
75 return cmp_args(KW_CONN_NAME, KW_CONN_LAST, (char *)c1, (char *)c2);
76 }
77
78 bool
79 starter_cmp_ca(starter_ca_t *c1, starter_ca_t *c2)
80 {
81 if (c1 == NULL || c2 == NULL)
82 return FALSE;
83
84 return cmp_args(KW_CA_NAME, KW_CA_LAST, (char *)c1, (char *)c2);
85 }
86
87 bool
88 starter_cmp_klips(starter_config_t *c1, starter_config_t *c2)
89 {
90 if ((c1 == NULL) || (c2 == NULL))
91 return FALSE;
92
93 return cmp_args(KW_KLIPS_FIRST, KW_KLIPS_LAST, (char *)c1, (char *)c2);
94 }
95
96 bool
97 starter_cmp_pluto(starter_config_t *c1, starter_config_t *c2)
98 {
99 if ((c1 == NULL) || (c2 == NULL))
100 return FALSE;
101
102 return cmp_args(KW_PLUTO_FIRST, KW_PLUTO_LAST, (char *)c1, (char *)c2);
103 }
104
105 bool
106 starter_cmp_defaultroute(defaultroute_t *d1, defaultroute_t *d2)
107 {
108 if ((d1 == NULL) || (d2 == NULL))
109 return FALSE;
110 return memcmp(d1, d2, sizeof(defaultroute_t)) == 0;
111 }