1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
/*
* Copyright (C) 2012 Tobias Brunner
* Copyright (C) 2012 Giuliano Grassi
* Copyright (C) 2012 Ralf Sager
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
/**
* @defgroup ipsec_policy ipsec_policy
* @{ @ingroup libipsec
*/
#ifndef IPSEC_POLICY_H
#define IPSEC_POLICY_H
#include "ip_packet.h"
#include <library.h>
#include <networking/host.h>
#include <ipsec/ipsec_types.h>
#include <selectors/traffic_selector.h>
typedef struct ipsec_policy_t ipsec_policy_t;
/**
* IPsec Policy
*/
struct ipsec_policy_t {
/**
* Get the source traffic selector of this policy
*
* @return the source traffic selector
*/
traffic_selector_t *(*get_source_ts)(ipsec_policy_t *this);
/**
* Get the destination traffic selector of this policy
*
* @return the destination traffic selector
*/
traffic_selector_t *(*get_destination_ts)(ipsec_policy_t *this);
/**
* Get the direction of this policy
*
* @return direction
*/
policy_dir_t (*get_direction)(ipsec_policy_t *this);
/**
* Get the priority of this policy
*
* @return priority
*/
policy_priority_t (*get_priority)(ipsec_policy_t *this);
/**
* Get the type of this policy (e.g. IPsec)
*
* @return the policy type
*/
policy_type_t (*get_type)(ipsec_policy_t *this);
/**
* Get the reqid associated to this policy
*
* @return the reqid
*/
u_int32_t (*get_reqid)(ipsec_policy_t *this);
/**
* Get another reference to this policy
*
* @return additional reference to the policy
*/
ipsec_policy_t *(*get_ref)(ipsec_policy_t *this);
/**
* Check if this policy matches all given parameters
*
* @param src_ts source traffic selector
* @param dst_ts destination traffic selector
* @param direction traffic direction
* @param reqid reqid of the policy
* @param mark mark for this policy
* @param prioirty policy priority
* @return TRUE if policy matches all parameters
*/
bool (*match)(ipsec_policy_t *this, traffic_selector_t *src_ts,
traffic_selector_t *dst_ts, policy_dir_t direction,
u_int32_t reqid, mark_t mark, policy_priority_t priority);
/**
* Check if this policy matches the given IP packet
*
* @param packet IP packet
* @return TRUE if policy matches the packet
*/
bool (*match_packet)(ipsec_policy_t *this, ip_packet_t *packet);
/**
* Destroy an ipsec_policy_t
*/
void (*destroy)(ipsec_policy_t *this);
};
/**
* Create an ipsec_policy_t instance
*
* @param src source address of SA
* @param dst dest address of SA
* @param src_ts traffic selector to match traffic source
* @param dst_ts traffic selector to match traffic dest
* @param direction direction of traffic, POLICY_(IN|OUT|FWD)
* @param type type of policy, POLICY_(IPSEC|PASS|DROP)
* @param sa details about the SA(s) tied to this policy
* @param mark mark for this policy
* @param priority priority of this policy
* @return ipsec policy instance
*/
ipsec_policy_t *ipsec_policy_create(host_t *src, host_t *dst,
traffic_selector_t *src_ts,
traffic_selector_t *dst_ts,
policy_dir_t direction, policy_type_t type,
ipsec_sa_cfg_t *sa, mark_t mark,
policy_priority_t priority);
#endif /** IPSEC_POLICY_H @}*/
|