starter: No special handling for left|rightsubnet, just pass it on as string.
[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 "cmp.h"
25
26 #define VARCMP(obj) if (c1->obj != c2->obj) return FALSE
27 #define ADDCMP(obj) if (!sameaddr(&c1->obj,&c2->obj)) return FALSE
28 #define SUBCMP(obj) if (!samesubnet(&c1->obj,&c2->obj)) return FALSE
29 #define STRCMP(obj) if (strcmp(c1->obj,c2->obj)) return FALSE
30
31 static bool
32 starter_cmp_end(starter_end_t *c1, starter_end_t *c2)
33 {
34 if ((c1 == NULL) || (c2 == NULL))
35 return FALSE;
36
37 VARCMP(ikeport);
38 VARCMP(has_port_wildcard);
39 VARCMP(has_natip);
40 VARCMP(modecfg);
41 VARCMP(port);
42 VARCMP(protocol);
43
44 return cmp_args(KW_END_FIRST, KW_END_LAST, (char *)c1, (char *)c2);
45 }
46
47 bool
48 starter_cmp_conn(starter_conn_t *c1, starter_conn_t *c2)
49 {
50 if ((c1 == NULL) || (c2 == NULL))
51 return FALSE;
52
53 VARCMP(policy);
54 VARCMP(mark_in.value);
55 VARCMP(mark_in.mask);
56 VARCMP(mark_out.value);
57 VARCMP(mark_in.mask);
58
59 if (!starter_cmp_end(&c1->left, &c2->left))
60 return FALSE;
61 if (!starter_cmp_end(&c1->right, &c2->right))
62 return FALSE;
63
64 return cmp_args(KW_CONN_NAME, KW_CONN_LAST, (char *)c1, (char *)c2);
65 }
66
67 bool
68 starter_cmp_ca(starter_ca_t *c1, starter_ca_t *c2)
69 {
70 if (c1 == NULL || c2 == NULL)
71 return FALSE;
72
73 return cmp_args(KW_CA_NAME, KW_CA_LAST, (char *)c1, (char *)c2);
74 }
75
76 bool
77 starter_cmp_klips(starter_config_t *c1, starter_config_t *c2)
78 {
79 if ((c1 == NULL) || (c2 == NULL))
80 return FALSE;
81
82 return cmp_args(KW_KLIPS_FIRST, KW_KLIPS_LAST, (char *)c1, (char *)c2);
83 }
84
85 bool
86 starter_cmp_pluto(starter_config_t *c1, starter_config_t *c2)
87 {
88 if ((c1 == NULL) || (c2 == NULL))
89 return FALSE;
90
91 return cmp_args(KW_PLUTO_FIRST, KW_PLUTO_LAST, (char *)c1, (char *)c2);
92 }