summaryrefslogtreecommitdiff
path: root/src/libcharon/encoding/payloads/traffic_selector_substructure.h
blob: 0109fd7f5bf0ba7270b16d6dd35dee74f4b8c44d (plain)
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
141
142
143
144
145
146
147
148
149
150
151
/*
 * Copyright (C) 2005-2006 Martin Willi
 * Copyright (C) 2005 Jan Hutter
 * 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 traffic_selector_substructure traffic_selector_substructure
 * @{ @ingroup payloads
 */

#ifndef TRAFFIC_SELECTOR_SUBSTRUCTURE_H_
#define TRAFFIC_SELECTOR_SUBSTRUCTURE_H_

typedef struct traffic_selector_substructure_t traffic_selector_substructure_t;

#include <library.h>
#include <utils/host.h>
#include <selectors/traffic_selector.h>
#include <encoding/payloads/payload.h>

/**
 * Length of a TRAFFIC SELECTOR SUBSTRUCTURE without start and end address.
 */
#define TRAFFIC_SELECTOR_HEADER_LENGTH 8

/**
 * Class representing an IKEv2 TRAFFIC SELECTOR.
 *
 * The TRAFFIC SELECTOR format is described in RFC section 3.13.1.
 */
struct traffic_selector_substructure_t {
	/**
	 * The payload_t interface.
	 */
	payload_t payload_interface;

	/**
	 * Get the type of Traffic selector.
	 *
	 * @return			type of traffic selector
	 *
	 */
	ts_type_t (*get_ts_type) (traffic_selector_substructure_t *this);

	/**
	 * Set the type of Traffic selector.
	 *
	 * @param ts_type	type of traffic selector
	 */
	void (*set_ts_type) (traffic_selector_substructure_t *this,
						 ts_type_t ts_type);

	/**
	 * Get the IP protocol ID of Traffic selector.
	 *
	 * @return			type of traffic selector
	 *
	 */
	u_int8_t (*get_protocol_id) (traffic_selector_substructure_t *this);

	/**
	 * Set the IP protocol ID of Traffic selector
	 *
	 * @param protocol_id	protocol ID of traffic selector
	 */
	void (*set_protocol_id) (traffic_selector_substructure_t *this,
							  u_int8_t protocol_id);

	/**
	 * Get the start port and address as host_t object.
	 *
	 * Returned host_t object has to get destroyed by the caller.
	 *
	 * @return			start host as host_t object
	 *
	 */
	host_t *(*get_start_host) (traffic_selector_substructure_t *this);

	/**
	 * Set the start port and address as host_t object.
	 *
	 * @param start_host	start host as host_t object
	 */
	void (*set_start_host) (traffic_selector_substructure_t *this,
							host_t *start_host);

	/**
	 * Get the end port and address as host_t object.
	 *
	 * Returned host_t object has to get destroyed by the caller.
	 *
	 * @return			end host as host_t object
	 *
	 */
	host_t *(*get_end_host) (traffic_selector_substructure_t *this);

	/**
	 * Set the end port and address as host_t object.
	 *
	 * @param end_host	end host as host_t object
	 */
	void (*set_end_host) (traffic_selector_substructure_t *this,
						  host_t *end_host);

	/**
	 * Get a traffic_selector_t from this substructure.
	 *
	 * @warning traffic_selector_t must be destroyed after usage.
	 *
	 * @return			contained traffic_selector_t
	 */
	traffic_selector_t *(*get_traffic_selector) (
										traffic_selector_substructure_t *this);

	/**
	 * Destroys an traffic_selector_substructure_t object.
	 */
	void (*destroy) (traffic_selector_substructure_t *this);
};

/**
 * Creates an empty traffic_selector_substructure_t object.
 *
 * TS type is set to default TS_IPV4_ADDR_RANGE!
 *
 * @return 					traffic_selector_substructure_t object
 */
traffic_selector_substructure_t *traffic_selector_substructure_create(void);

/**
 * Creates an initialized traffif selector substructure using
 * the values from a traffic_selector_t.
 *
 * @param traffic_selector	traffic_selector_t to use for initialization
 * @return					traffic_selector_substructure_t object
 */
traffic_selector_substructure_t *traffic_selector_substructure_create_from_traffic_selector(
										traffic_selector_t *traffic_selector);

#endif /** TRAFFIC_SELECTOR_SUBSTRUCTURE_H_ @}*/