2 * Copyright (C) 2012-2014 Andreas Steffen
3 * HSR Hochschule fuer Technik Rapperswil
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 #include "ietf_attr_fwd_enabled.h"
18 #include <pa_tnc/pa_tnc_msg.h>
19 #include <bio/bio_writer.h>
20 #include <bio/bio_reader.h>
21 #include <utils/debug.h>
23 typedef struct private_ietf_attr_fwd_enabled_t private_ietf_attr_fwd_enabled_t
;
26 * PA-TNC Forwarding Enabled type (see section 4.2.11 of RFC 5792)
29 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
30 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
31 * | Forwarding Enabled |
32 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
35 #define FORWARDING_ENABLED_SIZE 4
38 * Private data of an ietf_attr_fwd_enabled_t object.
40 struct private_ietf_attr_fwd_enabled_t
{
43 * Public members of ietf_attr_fwd_enabled_t
45 ietf_attr_fwd_enabled_t
public;
48 * Vendor-specific attribute type
53 * Length of attribute value
58 * Attribute value or segment
68 * Forwarding Enabled status
70 os_fwd_status_t fwd_status
;
78 METHOD(pa_tnc_attr_t
, get_type
, pen_type_t
,
79 private_ietf_attr_fwd_enabled_t
*this)
84 METHOD(pa_tnc_attr_t
, get_value
, chunk_t
,
85 private_ietf_attr_fwd_enabled_t
*this)
90 METHOD(pa_tnc_attr_t
, get_noskip_flag
, bool,
91 private_ietf_attr_fwd_enabled_t
*this)
93 return this->noskip_flag
;
96 METHOD(pa_tnc_attr_t
, set_noskip_flag
,void,
97 private_ietf_attr_fwd_enabled_t
*this, bool noskip
)
99 this->noskip_flag
= noskip
;
102 METHOD(pa_tnc_attr_t
, build
, void,
103 private_ietf_attr_fwd_enabled_t
*this)
105 bio_writer_t
*writer
;
111 writer
= bio_writer_create(FORWARDING_ENABLED_SIZE
);
112 writer
->write_uint32(writer
, this->fwd_status
);
114 this->value
= writer
->extract_buf(writer
);
115 this->length
= this->value
.len
;
116 writer
->destroy(writer
);
119 METHOD(pa_tnc_attr_t
, process
, status_t
,
120 private_ietf_attr_fwd_enabled_t
*this, u_int32_t
*offset
)
122 bio_reader_t
*reader
;
123 u_int32_t fwd_status
;
127 if (this->value
.len
< this->length
)
131 if (this->value
.len
!= FORWARDING_ENABLED_SIZE
)
133 DBG1(DBG_TNC
, "incorrect size for IETF forwarding enabled attribute");
136 reader
= bio_reader_create(this->value
);
137 reader
->read_uint32(reader
, &fwd_status
);
138 reader
->destroy(reader
);
140 if (fwd_status
> OS_FWD_UNKNOWN
)
142 DBG1(DBG_TNC
, "IETF forwarding enabled field has unknown value %u",
146 this->fwd_status
= fwd_status
;
151 METHOD(pa_tnc_attr_t
, add_segment
, void,
152 private_ietf_attr_fwd_enabled_t
*this, chunk_t segment
)
154 this->value
= chunk_cat("mc", this->value
, segment
);
157 METHOD(pa_tnc_attr_t
, get_ref
, pa_tnc_attr_t
*,
158 private_ietf_attr_fwd_enabled_t
*this)
161 return &this->public.pa_tnc_attribute
;
164 METHOD(pa_tnc_attr_t
, destroy
, void,
165 private_ietf_attr_fwd_enabled_t
*this)
167 if (ref_put(&this->ref
))
169 free(this->value
.ptr
);
174 METHOD(ietf_attr_fwd_enabled_t
, get_status
, os_fwd_status_t
,
175 private_ietf_attr_fwd_enabled_t
*this)
177 return this->fwd_status
;
181 * Described in header.
183 pa_tnc_attr_t
*ietf_attr_fwd_enabled_create(os_fwd_status_t fwd_status
)
185 private_ietf_attr_fwd_enabled_t
*this;
189 .pa_tnc_attribute
= {
190 .get_type
= _get_type
,
191 .get_value
= _get_value
,
192 .get_noskip_flag
= _get_noskip_flag
,
193 .set_noskip_flag
= _set_noskip_flag
,
196 .add_segment
= _add_segment
,
200 .get_status
= _get_status
,
202 .type
= { PEN_IETF
, IETF_ATTR_FORWARDING_ENABLED
},
203 .fwd_status
= fwd_status
,
207 return &this->public.pa_tnc_attribute
;
211 * Described in header.
213 pa_tnc_attr_t
*ietf_attr_fwd_enabled_create_from_data(size_t length
,
216 private_ietf_attr_fwd_enabled_t
*this;
220 .pa_tnc_attribute
= {
221 .get_type
= _get_type
,
222 .get_value
= _get_value
,
223 .get_noskip_flag
= _get_noskip_flag
,
224 .set_noskip_flag
= _set_noskip_flag
,
227 .add_segment
= _add_segment
,
231 .get_status
= _get_status
,
233 .type
= { PEN_IETF
, IETF_ATTR_FORWARDING_ENABLED
},
235 .value
= chunk_clone(data
),
239 return &this->public.pa_tnc_attribute
;