forked from kamailio/kamailio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hep.h
228 lines (183 loc) · 6.63 KB
/
hep.h
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*
* hep related structure
*
* Copyright (C) 2011-14 Alexandr Dubovikov <alexandr.dubovikov@gmail.com>
*
* This file is part of Kamailio, a free SIP server.
*
* Kamailio 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
*
* Kamailio 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef _hep_h
#define _hep_h
#include "../../core/endianness.h"
#ifdef __IS_BIG_ENDIAN
#define to_le(x) bswap32(x)
#else
#define to_le(x) (x)
#endif
#ifdef __OS_solaris
typedef uint8_t u_int8_t;
typedef uint16_t u_int16_t;
typedef uint32_t u_int32_t;
#define IPPROTO_IPIP IPPROTO_ENCAP /* Solaris IPIP protocol has name ENCAP */
#endif
extern int hep_capture_on;
extern int hep_offset;
extern char *authkey;
extern char *correlation_id;
/* int hep_msg_received(char * buf, unsigned int len, struct receive_info * ri);*/
int hep_msg_received(void *data);
/* new method for events */
int hepv3_message_parse(char *buf, unsigned int len, sip_msg_t* msg);
int hepv2_message_parse(char *buf, unsigned int len, sip_msg_t* msg);
int hepv3_get_chunk(struct sip_msg *msg, char *buf, unsigned int len, int req_chunk, pv_param_t *param, pv_value_t *res);
struct hep_hdr{
u_int8_t hp_v; /* version */
u_int8_t hp_l; /* length */
u_int8_t hp_f; /* family */
u_int8_t hp_p; /* protocol */
u_int16_t hp_sport; /* source port */
u_int16_t hp_dport; /* destination port */
};
struct hep_iphdr{
struct in_addr hp_src;
struct in_addr hp_dst; /* source and dest address */
};
struct hep_timehdr{
u_int32_t tv_sec; /* seconds */
u_int32_t tv_usec; /* useconds */
u_int16_t captid; /* Capture ID node */
};
struct hep_timeinfo{
u_int32_t tv_sec; /* seconds */
u_int32_t tv_usec; /* useconds */
u_int32_t captid; /* Capture ID node */
};
struct hep_ip6hdr {
struct in6_addr hp6_src; /* source address */
struct in6_addr hp6_dst; /* destination address */
};
/* HEPv3 types */
struct hep_chunk {
u_int16_t vendor_id;
u_int16_t type_id;
u_int16_t length;
} __attribute__((packed));
typedef struct hep_chunk hep_chunk_t;
struct hep_chunk_uint8 {
hep_chunk_t chunk;
u_int8_t data;
} __attribute__((packed));
typedef struct hep_chunk_uint8 hep_chunk_uint8_t;
struct hep_chunk_uint16 {
hep_chunk_t chunk;
u_int16_t data;
} __attribute__((packed));
typedef struct hep_chunk_uint16 hep_chunk_uint16_t;
struct hep_chunk_uint32 {
hep_chunk_t chunk;
u_int32_t data;
} __attribute__((packed));
typedef struct hep_chunk_uint32 hep_chunk_uint32_t;
struct hep_chunk_str {
hep_chunk_t chunk;
char *data;
} __attribute__((packed));
typedef struct hep_chunk_str hep_chunk_str_t;
struct hep_chunk_ip4 {
hep_chunk_t chunk;
struct in_addr data;
} __attribute__((packed));
typedef struct hep_chunk_ip4 hep_chunk_ip4_t;
struct hep_chunk_ip6 {
hep_chunk_t chunk;
struct in6_addr data;
} __attribute__((packed));
typedef struct hep_chunk_ip6 hep_chunk_ip6_t;
struct hep_chunk_payload {
hep_chunk_t chunk;
char *data;
} __attribute__((packed));
typedef struct hep_chunk_payload hep_chunk_payload_t;
struct hep_ctrl {
char id[4];
u_int16_t length;
} __attribute__((packed));
typedef struct hep_ctrl hep_ctrl_t;
/* Structure of HEP */
struct hep_generic_recv {
hep_ctrl_t *header;
hep_chunk_uint8_t *ip_family;
hep_chunk_uint8_t *ip_proto;
hep_chunk_uint16_t *src_port;
hep_chunk_uint16_t *dst_port;
hep_chunk_uint32_t *time_sec;
hep_chunk_uint32_t *time_usec;
hep_chunk_ip4_t *hep_src_ip4;
hep_chunk_ip4_t *hep_dst_ip4;
hep_chunk_ip6_t *hep_src_ip6;
hep_chunk_ip6_t *hep_dst_ip6;
hep_chunk_uint8_t *proto_t;
hep_chunk_uint32_t *capt_id;
hep_chunk_uint16_t *keep_tm;
hep_chunk_str_t *auth_key;
hep_chunk_str_t *correlation_id;
hep_chunk_t *payload_chunk;
} __attribute__((packed));
typedef struct hep_generic_recv hep_generic_recv_t;
#define HEP3_PACK_INIT(buf) \
union { \
hep_chunk_uint8_t chunk8; \
hep_chunk_uint16_t chunk16; \
hep_chunk_uint32_t chunk32; \
hep_chunk_t chunkpl; \
uint16_t len; \
} _tmpu; \
char *_tmp_p = (buf); \
memcpy(_tmp_p, "HEP3", 4); \
_tmp_p += 4 + 2/* skip length */;
#define HEP3_PACK_FINALIZE(buf, lenp) \
do { \
_tmpu.len = htons(_tmp_p - (char *)(buf)); \
memcpy((void *)(&(((hep_ctrl_t *)(buf))->length)), (void*)&_tmpu.len, 2); \
*lenp = _tmp_p - (char *)(buf); \
} while (0)
#define _HEP3_PACK_CHUNK_GENERIC(type, tmpvar, vid, tid, val) \
do { \
(tmpvar).chunk.vendor_id = htons(vid); \
(tmpvar).chunk.type_id = htons(tid); \
(tmpvar).chunk.length = htons(sizeof(type)); \
(tmpvar).data = (val); \
memcpy(_tmp_p, (void *) &(tmpvar), sizeof(type)); \
_tmp_p += sizeof(type); \
} while (0)
#define HEP3_PACK_CHUNK_UINT8(vid, tid, val) _HEP3_PACK_CHUNK_GENERIC(hep_chunk_uint8_t, _tmpu.chunk8, vid, tid, val)
#define HEP3_PACK_CHUNK_UINT16(vid, tid, val) _HEP3_PACK_CHUNK_GENERIC(hep_chunk_uint16_t, _tmpu.chunk16, vid, tid, htons(val))
#define HEP3_PACK_CHUNK_UINT16_NBO(vid, tid, val) _HEP3_PACK_CHUNK_GENERIC(hep_chunk_uint16_t, _tmpu.chunk16, vid, tid, (val))
#define HEP3_PACK_CHUNK_UINT32(vid, tid, val) _HEP3_PACK_CHUNK_GENERIC(hep_chunk_uint32_t, _tmpu.chunk32, vid, tid, htonl(val))
#define HEP3_PACK_CHUNK_UINT32_NBO(vid, tid, val) _HEP3_PACK_CHUNK_GENERIC(hep_chunk_uint32_t, _tmpu.chunk32, vid, tid, (val))
#define HEP3_PACK_CHUNK_DATA(vid, tid, val, len) \
do { \
_tmpu.chunkpl.vendor_id = htons(vid); \
_tmpu.chunkpl.type_id = htons(tid); \
_tmpu.chunkpl.length = htons(sizeof(hep_chunk_t) + (len)); \
memcpy(_tmp_p, (void *) &_tmpu.chunkpl, sizeof(hep_chunk_t)); \
_tmp_p += sizeof(hep_chunk_t); \
memcpy(_tmp_p, (void *) (val), len); \
_tmp_p += len; \
} while (0)
#define HEP3_PACK_CHUNK_IP6(vid, tid, paddr) HEP3_PACK_CHUNK_DATA(vid, tid, paddr, sizeof(struct in6_addr))
#endif