]> git.ipfire.org Git - thirdparty/strongswan.git/blob - src/libimcv/seg/seg_contract.h
Update copyright headers after acquisition by secunet
[thirdparty/strongswan.git] / src / libimcv / seg / seg_contract.h
1 /*
2 * Copyright (C) 2014-2022 Andreas Steffen
3 *
4 * Copyright (C) secunet Security Networks AG
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17 /**
18 * @defgroup seg_contract seg_contract
19 * @{ @ingroup libimcv_seg
20 */
21
22 #ifndef SEG_CONTRACT_H_
23 #define SEG_CONTRACT_H_
24
25 typedef struct seg_contract_t seg_contract_t;
26
27 #include "pa_tnc/pa_tnc_attr.h"
28
29 #include <library.h>
30 #include <pen/pen.h>
31
32 #include <tncif.h>
33
34 #define SEG_CONTRACT_NO_MSG_SIZE_LIMIT 0xffffffff
35 #define SEG_CONTRACT_NO_SEGMENTATION 0xffffffff
36
37 /**
38 * Interface for a PA-TNC message segmentation contract
39 *
40 */
41 struct seg_contract_t {
42
43 /**
44 * Get the PA-TNC message type.
45 *
46 * @return PA-TNC Message type
47 */
48 pen_type_t (*get_msg_type)(seg_contract_t *this);
49
50 /**
51 * Set maximum PA-TNC message and segment size in octets
52 *
53 * @param max_msg_size Maximum PA-TNC message size in octets
54 * @param max_seg_size Maximum PA-TNC message segment size in octets
55 */
56 void (*set_max_size)(seg_contract_t *this, uint32_t max_msg_size,
57 uint32_t max_seg_size);
58
59 /**
60 * Get maximum PA-TNC message and segment size in octets
61 *
62 * @param max_msg_size Maximum PA-TNC attribute size in octets
63 * @param max_seg_size Maximum PA-TNC attribute segment size in octets
64 */
65 void (*get_max_size)(seg_contract_t *this, uint32_t *max_msg_size,
66 uint32_t *max_seg_size);
67
68 /**
69 * Check if a PA-TNC attribute must be segmented or is oversized
70 *
71 * @param attr PA-TNC attribute to be checked
72 * @param oversize PA-TNC attribute is larger than maximum size
73 * @return TRUE if PA-TNC attribute must be segmented
74 */
75 bool (*check_size)(seg_contract_t *this, pa_tnc_attr_t *attr,
76 bool *oversize);
77
78 /**
79 * Generate first segment of a PA-TNC attribute according to the contract
80 *
81 * @param attr PA-TNC attribute to be segmented
82 * @param max_attr_len Maximum size of first segment envelope attribute
83 * @return First segment envelope attribute
84 */
85 pa_tnc_attr_t* (*first_segment)(seg_contract_t *this, pa_tnc_attr_t *attr,
86 size_t max_attr_len);
87
88 /**
89 * Generate next segment of a PA-TNC message according to the contract
90 *
91 * @param base_msg_id Base Message ID
92 * @return Next segment envelope attribute
93 */
94 pa_tnc_attr_t* (*next_segment)(seg_contract_t *this, uint32_t base_msg_id);
95
96 /**
97 * Add segments until the PA-TNC attribute is reconstructed
98 *
99 * @param attr Segment envelope attribute
100 * @param error Error attribute if an error occurred or NULL
101 * @param more Need more segments
102 * @return Completed PA-TNC attribute or NULL
103 */
104 pa_tnc_attr_t* (*add_segment)(seg_contract_t *this,
105 pa_tnc_attr_t *attr, pa_tnc_attr_t **error,
106 bool *more);
107
108 /**
109 * Get contract role
110 *
111 * @return TRUE: contracting party (issuer),
112 * FALSE: contracted party
113 */
114 bool (*is_issuer)(seg_contract_t *this);
115
116 /**
117 * Is this a null contract ?
118 *
119 * @return TRUE if null contract
120 */
121 bool (*is_null)(seg_contract_t *this);
122
123 /**
124 * Set the responder ID
125 *
126 * @param responder IMC or IMV ID of responder
127 */
128 void (*set_responder)(seg_contract_t *this, TNC_UInt32 responder);
129
130 /**
131 * Get the responder ID
132 *
133 * @return IMC or IMV ID of responder
134 */
135 TNC_UInt32 (*get_responder)(seg_contract_t *this);
136
137 /**
138 * Get the issuer ID
139 *
140 * @return IMC or IMV ID of issuer
141 */
142 TNC_UInt32 (*get_issuer)(seg_contract_t *this);
143
144 /**
145 * Clone a contract
146 *
147 * @return Cloned contract
148 */
149 seg_contract_t* (*clone)(seg_contract_t *this);
150
151 /**
152 * Get an info string about the contract
153 *
154 * @param buf String buffer of at least size len
155 * @param len Size of string buffer
156 * @param request TRUE if contract request, FALSE if response
157 */
158 void (*get_info_string)(seg_contract_t *this, char *buf, size_t len,
159 bool request);
160
161 /**
162 * Destroys a seg_contract_t object.
163 */
164 void (*destroy)(seg_contract_t *this);
165 };
166
167 /**
168 * Create a PA-TNC attribute segmentation contract
169 *
170 * @param msg_type PA-TNC message type
171 * @param max_msg_size Maximum PA-TNC message size in octets
172 * @param max_seg_size Maximum PA-TNC message segment size in octets
173 * @param is_issuer TRUE if issuer of the contract
174 * @param issuer_id IMC or IMV ID of issuer
175 * @param is_imc TRUE if IMC, FALSE if IMV
176 */
177 seg_contract_t* seg_contract_create(pen_type_t msg_type,
178 uint32_t max_msg_size,
179 uint32_t max_seg_size,
180 bool is_issuer, TNC_UInt32 issuer_id,
181 bool is_imc);
182
183 #endif /** SEG_CONTRACT_H_ @}*/