1 /* $OpenBSD: attribute.c,v 1.11 2004/05/14 08:42:56 hshoexer Exp $ */
2 /* $EOM: attribute.c,v 1.10 2000/02/20 19:58:36 niklas Exp $ */
5 * Copyright (c) 1998, 1999 Niklas Hallqvist. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * This code was written under funding by Ericsson Radio Systems.
32 #include <sys/types.h>
37 #include "attribute.h"
44 attribute_set_basic(u_int8_t
*buf
, u_int16_t type
, u_int16_t value
)
46 SET_ISAKMP_ATTR_TYPE(buf
, ISAKMP_ATTR_MAKE(1, type
));
47 SET_ISAKMP_ATTR_LENGTH_VALUE(buf
, value
);
48 return buf
+ ISAKMP_ATTR_VALUE_OFF
;
52 attribute_set_var(u_int8_t
*buf
, u_int16_t type
, u_int8_t
*value
,
55 SET_ISAKMP_ATTR_TYPE(buf
, ISAKMP_ATTR_MAKE(0, type
));
56 SET_ISAKMP_ATTR_LENGTH_VALUE(buf
, len
);
57 memcpy(buf
+ ISAKMP_ATTR_VALUE_OFF
, value
, len
);
58 return buf
+ ISAKMP_ATTR_VALUE_OFF
+ len
;
62 * Execute a function FUNC taking an attribute type, value, length and ARG
63 * as arguments for each attribute in the area of ISAKMP attributes located
64 * at BUF, sized SZ. If any invocation fails, the processing aborts with a
65 * -1 return value. If all goes well return zero.
68 attribute_map(u_int8_t
*buf
, size_t sz
, int (*func
)(u_int16_t
, u_int8_t
*,
69 u_int16_t
, void *), void *arg
)
77 for (attr
= buf
; attr
< buf
+ sz
; attr
= value
+ len
) {
78 if (attr
+ ISAKMP_ATTR_VALUE_OFF
> buf
+ sz
)
80 type
= GET_ISAKMP_ATTR_TYPE(attr
);
81 fmt
= ISAKMP_ATTR_FORMAT(type
);
82 type
= ISAKMP_ATTR_TYPE(type
);
83 value
= attr
+ (fmt
? ISAKMP_ATTR_LENGTH_VALUE_OFF
84 : ISAKMP_ATTR_VALUE_OFF
);
85 len
= (fmt
? ISAKMP_ATTR_LENGTH_VALUE_LEN
86 : GET_ISAKMP_ATTR_LENGTH_VALUE(attr
));
87 if (value
+ len
> buf
+ sz
)
89 if (func(type
, value
, len
, arg
))
96 attribute_set_constant(char *section
, char *tag
, struct constant_map
*map
,
97 int attr_class
, u_int8_t
**attr
)
102 name
= conf_get_str(section
, tag
);
104 LOG_DBG((LOG_MISC
, 70,
105 "attribute_set_constant: no %s in the %s section", tag
,
109 value
= constant_value(map
, name
);
110 *attr
= attribute_set_basic(*attr
, attr_class
, value
);