added RCSID
[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 * RCSID $Id$
15 */
16
17 #include <string.h>
18
19 #include <freeswan.h>
20
21 #include "../pluto/constants.h"
22 #include "../pluto/defs.h"
23
24 #include "confread.h"
25 #include "args.h"
26 #include "interfaces.h"
27 #include "cmp.h"
28
29 #define VARCMP(obj) if (c1->obj != c2->obj) return FALSE
30 #define ADDCMP(obj) if (!sameaddr(&c1->obj,&c2->obj)) return FALSE
31 #define SUBCMP(obj) if (!samesubnet(&c1->obj,&c2->obj)) return FALSE
32
33 static bool
34 starter_cmp_end(starter_end_t *c1, starter_end_t *c2)
35 {
36 if ((c1 == NULL) || (c2 == NULL))
37 return FALSE;
38
39 if (c2->dns_failed)
40 {
41 c2->addr = c1->addr;
42 }
43 else
44 {
45 ADDCMP(addr);
46 }
47 ADDCMP(nexthop);
48 ADDCMP(srcip);
49 SUBCMP(subnet);
50 VARCMP(has_client);
51 VARCMP(has_client_wildcard);
52 VARCMP(has_port_wildcard);
53 VARCMP(has_srcip);
54 VARCMP(modecfg);
55 VARCMP(port);
56 VARCMP(protocol);
57
58 return cmp_args(KW_END_FIRST, KW_END_LAST, (char *)c1, (char *)c2);
59 }
60
61 bool
62 starter_cmp_conn(starter_conn_t *c1, starter_conn_t *c2)
63 {
64 if ((c1 == NULL) || (c2 == NULL))
65 return FALSE;
66
67 VARCMP(policy);
68 VARCMP(addr_family);
69 VARCMP(tunnel_addr_family);
70
71 if (!starter_cmp_end(&c1->left, &c2->left))
72 return FALSE;
73 if (!starter_cmp_end(&c1->right, &c2->right))
74 return FALSE;
75
76 return cmp_args(KW_CONN_NAME, KW_CONN_LAST, (char *)c1, (char *)c2);
77 }
78
79 bool
80 starter_cmp_ca(starter_ca_t *c1, starter_ca_t *c2)
81 {
82 if (c1 == NULL || c2 == NULL)
83 return FALSE;
84
85 return cmp_args(KW_CA_NAME, KW_CA_LAST, (char *)c1, (char *)c2);
86 }
87
88 bool
89 starter_cmp_klips(starter_config_t *c1, starter_config_t *c2)
90 {
91 if ((c1 == NULL) || (c2 == NULL))
92 return FALSE;
93
94 return cmp_args(KW_KLIPS_FIRST, KW_KLIPS_LAST, (char *)c1, (char *)c2);
95 }
96
97 bool
98 starter_cmp_pluto(starter_config_t *c1, starter_config_t *c2)
99 {
100 if ((c1 == NULL) || (c2 == NULL))
101 return FALSE;
102
103 return cmp_args(KW_PLUTO_FIRST, KW_PLUTO_LAST, (char *)c1, (char *)c2);
104 }
105
106 bool
107 starter_cmp_defaultroute(defaultroute_t *d1, defaultroute_t *d2)
108 {
109 if ((d1 == NULL) || (d2 == NULL))
110 return FALSE;
111 return memcmp(d1, d2, sizeof(defaultroute_t)) == 0;
112 }