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
|
/*-
* Copyright (c) 2009 Internet Initiative Japan Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef L2TP_SUBR_H
#define L2TP_SUBR_H 1
/* $Id: l2tp_subr.h,v 1.1 2010/01/11 04:20:57 yasuoka Exp $ */
/**
* L2TP の Attribute Value Pair (AVP) のパケットヘッダを示す構造体です。
*/
struct l2tp_avp
{
#if BYTE_ORDER == LITTLE_ENDIAN
uint16_t length:10,
rsvd:4,
is_hidden:1,
is_mandatory:1;
#else
uint16_t is_mandatory:1,
is_hidden:1,
rsvd:4,
length:10;
#endif
uint16_t vendor_id;
uint16_t attr_type;
u_char attr_value[0];
} __attribute__((__packed__)) ;
#define avp_attr_length(avp) ((avp)->length - 6)
static inline uint16_t
avp_get_val16(struct l2tp_avp *avp)
{
return (avp->attr_value[0] << 8) | avp->attr_value[1];
}
static inline uint32_t
avp_get_val32(struct l2tp_avp *avp)
{
return (avp->attr_value[0] << 24) | (avp->attr_value[1] << 16) |
(avp->attr_value[2] << 8) | avp->attr_value[3];
}
static inline void
avp_set_val16(struct l2tp_avp *avp, uint16_t val)
{
avp->attr_value[0] = val >> 8;
avp->attr_value[1] = val & 0xff;
}
static inline void
avp_set_val32(struct l2tp_avp *avp, uint32_t val)
{
avp->attr_value[0] = val >> 24;
avp->attr_value[1] = val >> 16;
avp->attr_value[2] = val >> 8;
avp->attr_value[3] = val & 0xff;
}
static inline int
short_cmp(const void *m, const void *n)
{
return (int)((int)m - (int)n);
}
static inline uint32_t
short_hash(const void *v, int sz)
{
return (int)v % sz;
}
/**
* AVPのサイズをチェックするマクロ。
* <p>
* 準備<br>
* <ul>
* <li>エラーメッセージ用の char emes[256] を準備する。
* <li>reigai ラベルを準備する。
* </ul></p>
*/
#define AVP_SIZE_CHECK(avp, op, exp) \
if (!((avp)->length op (exp))) { \
snprintf(emes, sizeof(emes), \
"invalid packet size %s %d" #op "%d)", \
avp_attr_type_string((avp)->attr_type), \
(avp)->length, (exp)); \
goto size_check_failed; \
}
#ifdef __cplusplus
extern "C" {
#endif
int avp_enum (struct l2tp_avp *, const u_char *, int, int);
const char *avp_attr_type_string (int);
struct l2tp_avp *avp_find_message_type_avp(struct l2tp_avp *, const u_char *, int);
struct l2tp_avp *avp_find(struct l2tp_avp *, const u_char *, int, uint16_t, uint16_t, int);
int bytebuf_add_avp (bytebuffer *, struct l2tp_avp *, int);
const char *avp_mes_type_string (int);
const char * l2tp_cdn_rcode_string(int);
const char * l2tp_stopccn_rcode_string(int);
const char * l2tp_ecode_string(int);
#ifdef __cplusplus
}
#endif
#endif
|