1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,186 +0,0 @@ |
1 |
-/* |
|
2 |
- * $Id$ |
|
3 |
- * |
|
4 |
- * Copyright (C) 2001-2003 FhG Fokus |
|
5 |
- * |
|
6 |
- * This file is part of ser, a free SIP server. |
|
7 |
- * |
|
8 |
- * ser is free software; you can redistribute it and/or modify |
|
9 |
- * it under the terms of the GNU General Public License as published by |
|
10 |
- * the Free Software Foundation; either version 2 of the License, or |
|
11 |
- * (at your option) any later version |
|
12 |
- * |
|
13 |
- * For a license to use the ser software under conditions |
|
14 |
- * other than those described here, or to purchase support for this |
|
15 |
- * software, please contact iptel.org by e-mail at the following addresses: |
|
16 |
- * info@iptel.org |
|
17 |
- * |
|
18 |
- * ser is distributed in the hope that it will be useful, |
|
19 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
20 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
21 |
- * GNU General Public License for more details. |
|
22 |
- * |
|
23 |
- * You should have received a copy of the GNU General Public License |
|
24 |
- * along with this program; if not, write to the Free Software |
|
25 |
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
26 |
- * |
|
27 |
- * |
|
28 |
- * History: |
|
29 |
- * -------- |
|
30 |
- * 2006-10-13 created (vlada) |
|
31 |
- */ |
|
32 |
- |
|
33 |
- |
|
34 |
-#ifndef _ser_stun_h |
|
35 |
-#define _ser_stun_h |
|
36 |
- |
|
37 |
-#ifdef USE_STUN |
|
38 |
- |
|
39 |
-#include <openssl/sha.h> |
|
40 |
- |
|
41 |
-#include "str.h" |
|
42 |
-#include "tcp_conn.h" |
|
43 |
-#include "ip_addr.h" |
|
44 |
- |
|
45 |
-/* type redefinition */ |
|
46 |
-typedef unsigned char UCHAR_T; |
|
47 |
-typedef unsigned short USHORT_T; |
|
48 |
-typedef unsigned int UINT_T; |
|
49 |
-typedef unsigned long ULONG_T; |
|
50 |
- |
|
51 |
-/* STUN message types supported by SER */ |
|
52 |
-#define BINDING_REQUEST 0x0001 |
|
53 |
-#define BINDING_RESPONSE 0x0101 |
|
54 |
-#define BINDING_ERROR_RESPONSE 0x0111 |
|
55 |
- |
|
56 |
-/* common STUN attributes */ |
|
57 |
-#define MAPPED_ADDRESS_ATTR 0x0001 |
|
58 |
-#define USERNAME_ATTR 0x0006 |
|
59 |
-#define MESSAGE_INTEGRITY_ATTR 0x0008 |
|
60 |
-#define ERROR_CODE_ATTR 0x0009 |
|
61 |
-#define UNKNOWN_ATTRIBUTES_ATTR 0x000A |
|
62 |
- |
|
63 |
-/* STUN attributes defined by rfc5389 */ |
|
64 |
-#define REALM_ATTR 0x0014 |
|
65 |
-#define NONCE_ATTR 0x0015 |
|
66 |
-#define XOR_MAPPED_ADDRESS_ATTR 0x0020 |
|
67 |
-#define FINGERPRINT_ATTR 0x8028 |
|
68 |
-#define SOFTWARE_ATTR 0x8022 |
|
69 |
-#define ALTERNATE_SERVER_ATTR 0x8023 |
|
70 |
- |
|
71 |
-/* STUN attributes defined by rfc3489 */ |
|
72 |
-#define RESPONSE_ADDRESS_ATTR 0x0002 |
|
73 |
-#define CHANGE_REQUEST_ATTR 0x0003 |
|
74 |
-#define SOURCE_ADDRESS_ATTR 0x0004 |
|
75 |
-#define CHANGED_ADDRESS_ATTR 0x0005 |
|
76 |
-#define REFLECTED_FROM_ATTR 0x000b |
|
77 |
- |
|
78 |
-/* STUN error codes supported by SER */ |
|
79 |
-#define RESPONSE_OK 200 |
|
80 |
-#define TRY_ALTERNATE_ERR 300 |
|
81 |
-#define BAD_REQUEST_ERR 400 |
|
82 |
-#define UNAUTHORIZED_ERR 401 |
|
83 |
-#define UNKNOWN_ATTRIBUTE_ERR 420 |
|
84 |
-#define STALE_CREDENTIALS_ERR 430 |
|
85 |
-#define INTEGRITY_CHECK_ERR 431 |
|
86 |
-#define MISSING_USERNAME_ERR 432 |
|
87 |
-#define USE_TLS_ERR 433 |
|
88 |
-#define MISSING_REALM_ERR 434 |
|
89 |
-#define MISSING_NONCE_ERR 435 |
|
90 |
-#define UNKNOWN_USERNAME_ERR 436 |
|
91 |
-#define STALE_NONCE_ERR 438 |
|
92 |
-#define SERVER_ERROR_ERR 500 |
|
93 |
-#define GLOBAL_FAILURE_ERR 600 |
|
94 |
- |
|
95 |
-#define TRY_ALTERNATE_TXT "Try Alternate" |
|
96 |
-#define BAD_REQUEST_TXT "Bad Request" |
|
97 |
-#define UNAUTHORIZED_TXT "Unauthorized" |
|
98 |
-#define UNKNOWN_ATTRIBUTE_TXT "Unknown Attribute" |
|
99 |
-#define STALE_CREDENTIALS_TXT "Stale Credentials" |
|
100 |
-#define INTEGRITY_CHECK_TXT "Integrity Check Failure" |
|
101 |
-#define MISSING_USERNAME_TXT "Missing Username" |
|
102 |
-#define USE_TLS_TXT "Use TLS" |
|
103 |
-#define MISSING_REALM_TXT "Missing Realm" |
|
104 |
-#define MISSING_NONCE_TXT "Missing Nonce" |
|
105 |
-#define UNKNOWN_USERNAME_TXT "Unknown Username" |
|
106 |
-#define STALE_NONCE_TXT "Stale Nonce" |
|
107 |
-#define SERVER_ERROR_TXT "Server Error" |
|
108 |
-#define GLOBAL_FAILURE_TXT "Global Failure" |
|
109 |
- |
|
110 |
- |
|
111 |
-/* other stuff */ |
|
112 |
-#define MAGIC_COOKIE 0x2112A442 |
|
113 |
-#define MAGIC_COOKIE_2B 0x2112 /* because of XOR for port */ |
|
114 |
-#define MANDATORY_ATTR 0x7fff |
|
115 |
-#define PAD4 4 |
|
116 |
-#define PAD64 64 |
|
117 |
-#define STUN_MSG_LEN 516 |
|
118 |
-#define IPV4_LEN 4 |
|
119 |
-#define IPV6_LEN 16 |
|
120 |
-#define IPV4_FAMILY 0x0001 |
|
121 |
-#define IPV6_FAMILY 0x0002 |
|
122 |
-#define FATAL_ERROR -1 |
|
123 |
-#define IP_ADDR 4 |
|
124 |
-#define XOR 1 |
|
125 |
-#define TRANSACTION_ID 12 |
|
126 |
- |
|
127 |
-/** padd len to a multiple of sz. |
|
128 |
- * sz must be a power of the form 2^k (e.g. 2, 4, 8, 16 ...) |
|
129 |
- */ |
|
130 |
-#define PADD_TO(len, sz) (((len) + (sz)-1) & (~((sz) - 1))) |
|
131 |
- |
|
132 |
-#define PADDED_TO_FOUR(len) PADD_TO(len, 4) |
|
133 |
-#define PADDED_TO_SIXTYFOUR(len) PADD_TO(len, 64) |
|
134 |
- |
|
135 |
-struct transaction_id { |
|
136 |
- UINT_T magic_cookie; |
|
137 |
- UCHAR_T id[TRANSACTION_ID]; |
|
138 |
-}; |
|
139 |
- |
|
140 |
-struct stun_hdr { |
|
141 |
- USHORT_T type; |
|
142 |
- USHORT_T len; |
|
143 |
- struct transaction_id id; |
|
144 |
-}; |
|
145 |
- |
|
146 |
-struct stun_ip_addr { |
|
147 |
- USHORT_T family; /* 0x01: IPv4; 0x02: IPv6 */ |
|
148 |
- USHORT_T port; |
|
149 |
- UINT_T ip[IP_ADDR]; |
|
150 |
-}; |
|
151 |
- |
|
152 |
-struct stun_buffer { |
|
153 |
- str buf; |
|
154 |
- USHORT_T empty; /* number of free bytes in buf before |
|
155 |
- * it'll be necessary to realloc the buf |
|
156 |
- */ |
|
157 |
-}; |
|
158 |
- |
|
159 |
-struct stun_unknown_att { |
|
160 |
- USHORT_T type; |
|
161 |
- struct stun_unknown_att* next; |
|
162 |
-}; |
|
163 |
- |
|
164 |
-struct stun_attr { |
|
165 |
- USHORT_T type; |
|
166 |
- USHORT_T len; |
|
167 |
-}; |
|
168 |
- |
|
169 |
-struct stun_msg { |
|
170 |
- struct stun_hdr hdr; |
|
171 |
- struct stun_ip_addr ip_addr; /* XOR values for rfc3489bis, |
|
172 |
- normal values for rfc3489 */ |
|
173 |
- struct stun_buffer msg; |
|
174 |
- UCHAR_T old; /* true: the format of message is in |
|
175 |
- accordance with rfc3489 */ |
|
176 |
-}; |
|
177 |
- |
|
178 |
- |
|
179 |
-/* |
|
180 |
- * stun functions called from ser |
|
181 |
- */ |
|
182 |
-int stun_process_msg(char* buf, unsigned len, struct receive_info* ri); |
|
183 |
- |
|
184 |
-#endif /* USE_STUN */ |
|
185 |
- |
|
186 |
-#endif /* _ser_stun_h */ |
The PADDED_TO_* macros did not work when the length was a multiple
of the pad value.
(FS#129)
Reported-by: Francesco Castellano
... | ... |
@@ -124,8 +124,13 @@ typedef unsigned long ULONG_T; |
124 | 124 |
#define XOR 1 |
125 | 125 |
#define TRANSACTION_ID 12 |
126 | 126 |
|
127 |
-#define PADDED_TO_FOUR(len) (len == 0) ? 0 : len + (PAD4 - len%PAD4) |
|
128 |
-#define PADDED_TO_SIXTYFOUR(len) (len == 0) ? 0 : len + (PAD64 - len%PAD64) |
|
127 |
+/** padd len to a multiple of sz. |
|
128 |
+ * sz must be a power of the form 2^k (e.g. 2, 4, 8, 16 ...) |
|
129 |
+ */ |
|
130 |
+#define PADD_TO(len, sz) (((len) + (sz)-1) & (~((sz) - 1))) |
|
131 |
+ |
|
132 |
+#define PADDED_TO_FOUR(len) PADD_TO(len, 4) |
|
133 |
+#define PADDED_TO_SIXTYFOUR(len) PADD_TO(len, 64) |
|
129 | 134 |
|
130 | 135 |
struct transaction_id { |
131 | 136 |
UINT_T magic_cookie; |
- Removing checking/adding of FINGERPRINT attibute
- Update some attribute values according to new spec
- Fix endianess of XOR-MAPPED-ADDRESS
... | ... |
@@ -56,19 +56,17 @@ typedef unsigned long ULONG_T; |
56 | 56 |
/* common STUN attributes */ |
57 | 57 |
#define MAPPED_ADDRESS_ATTR 0x0001 |
58 | 58 |
#define USERNAME_ATTR 0x0006 |
59 |
-#define PASSWORD_ATTR 0x0007 |
|
60 | 59 |
#define MESSAGE_INTEGRITY_ATTR 0x0008 |
61 | 60 |
#define ERROR_CODE_ATTR 0x0009 |
62 | 61 |
#define UNKNOWN_ATTRIBUTES_ATTR 0x000A |
63 | 62 |
|
64 |
-/* STUN attributes defined by rfc3489bis */ |
|
63 |
+/* STUN attributes defined by rfc5389 */ |
|
65 | 64 |
#define REALM_ATTR 0x0014 |
66 | 65 |
#define NONCE_ATTR 0x0015 |
67 | 66 |
#define XOR_MAPPED_ADDRESS_ATTR 0x0020 |
68 |
-#define FINGERPRINT_ATTR 0x0023 |
|
69 |
-#define SERVER_ATTR 0x8022 |
|
67 |
+#define FINGERPRINT_ATTR 0x8028 |
|
68 |
+#define SOFTWARE_ATTR 0x8022 |
|
70 | 69 |
#define ALTERNATE_SERVER_ATTR 0x8023 |
71 |
-#define REFRESH_INTERVAL_ATTR 0x8024 |
|
72 | 70 |
|
73 | 71 |
/* STUN attributes defined by rfc3489 */ |
74 | 72 |
#define RESPONSE_ADDRESS_ATTR 0x0002 |
... | ... |
@@ -167,7 +165,6 @@ struct stun_msg { |
167 | 165 |
struct stun_hdr hdr; |
168 | 166 |
struct stun_ip_addr ip_addr; /* XOR values for rfc3489bis, |
169 | 167 |
normal values for rfc3489 */ |
170 |
- char fp[SHA_DIGEST_LENGTH]; /* fingerprint value */ |
|
171 | 168 |
struct stun_buffer msg; |
172 | 169 |
UCHAR_T old; /* true: the format of message is in |
173 | 170 |
accordance with rfc3489 */ |
... | ... |
@@ -94,20 +94,20 @@ typedef unsigned long ULONG_T; |
94 | 94 |
#define SERVER_ERROR_ERR 500 |
95 | 95 |
#define GLOBAL_FAILURE_ERR 600 |
96 | 96 |
|
97 |
-#define TRY_ALTERNATE_TXT "The client should contact an alternate server for this request." |
|
98 |
-#define BAD_REQUEST_TXT "The request was malformed. The client should not retry the request without modification from the previous attempt." |
|
99 |
-#define UNAUTHORIZED_TXT "The request did not contain a MESSAGE-INTEGRITY attribute." |
|
100 |
-#define UNKNOWN_ATTRIBUTE_TXT "The server did not understand a mandatory attribute in the request." |
|
101 |
-#define STALE_CREDENTIALS_TXT "The request did contain a MESSAGE-INTEGRITY attribute, but it used a shared secret that has expired. The client should obtain a new shared secret and try again." |
|
102 |
-#define INTEGRITY_CHECK_TXT "The request contained a MESSAGE-INTEGRITY attribute, but the HMAC failed verification. This could be a sign of a potential attack, or client implementation error." |
|
103 |
-#define MISSING_USERNAME_TXT "The request contained a MESSAGE-INTEGRITY attribute, but not a USERNAME attribute. Both USERNAME and MESSAGE-INTEGRITY must be present for integrity checks." |
|
104 |
-#define USE_TLS_TXT "The Shared Secret request has to be sent over TLS, but was not received over TLS." |
|
105 |
-#define MISSING_REALM_TXT "The REALM attribute was not present in the request." |
|
106 |
-#define MISSING_NONCE_TXT "The NONCE attribute was not present in the request." |
|
107 |
-#define UNKNOWN_USERNAME_TXT "The USERNAME supplied in the request is not known or is not known to the server." |
|
108 |
-#define STALE_NONCE_TXT "The NONCE attribute was present in the request but wasn't valid." |
|
109 |
-#define SERVER_ERROR_TXT "The server has suffered a temporary error. The client should try again." |
|
110 |
-#define GLOBAL_FAILURE_TXT "The server is refusing to fulfill the request. The client should not retry." |
|
97 |
+#define TRY_ALTERNATE_TXT "Try Alternate" |
|
98 |
+#define BAD_REQUEST_TXT "Bad Request" |
|
99 |
+#define UNAUTHORIZED_TXT "Unauthorized" |
|
100 |
+#define UNKNOWN_ATTRIBUTE_TXT "Unknown Attribute" |
|
101 |
+#define STALE_CREDENTIALS_TXT "Stale Credentials" |
|
102 |
+#define INTEGRITY_CHECK_TXT "Integrity Check Failure" |
|
103 |
+#define MISSING_USERNAME_TXT "Missing Username" |
|
104 |
+#define USE_TLS_TXT "Use TLS" |
|
105 |
+#define MISSING_REALM_TXT "Missing Realm" |
|
106 |
+#define MISSING_NONCE_TXT "Missing Nonce" |
|
107 |
+#define UNKNOWN_USERNAME_TXT "Unknown Username" |
|
108 |
+#define STALE_NONCE_TXT "Stale Nonce" |
|
109 |
+#define SERVER_ERROR_TXT "Server Error" |
|
110 |
+#define GLOBAL_FAILURE_TXT "Global Failure" |
|
111 | 111 |
|
112 | 112 |
|
113 | 113 |
/* other stuff */ |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,184 @@ |
1 |
+/* |
|
2 |
+ * $Id$ |
|
3 |
+ * |
|
4 |
+ * Copyright (C) 2001-2003 FhG Fokus |
|
5 |
+ * |
|
6 |
+ * This file is part of ser, a free SIP server. |
|
7 |
+ * |
|
8 |
+ * ser is free software; you can redistribute it and/or modify |
|
9 |
+ * it under the terms of the GNU General Public License as published by |
|
10 |
+ * the Free Software Foundation; either version 2 of the License, or |
|
11 |
+ * (at your option) any later version |
|
12 |
+ * |
|
13 |
+ * For a license to use the ser software under conditions |
|
14 |
+ * other than those described here, or to purchase support for this |
|
15 |
+ * software, please contact iptel.org by e-mail at the following addresses: |
|
16 |
+ * info@iptel.org |
|
17 |
+ * |
|
18 |
+ * ser is distributed in the hope that it will be useful, |
|
19 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
20 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
21 |
+ * GNU General Public License for more details. |
|
22 |
+ * |
|
23 |
+ * You should have received a copy of the GNU General Public License |
|
24 |
+ * along with this program; if not, write to the Free Software |
|
25 |
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
26 |
+ * |
|
27 |
+ * |
|
28 |
+ * History: |
|
29 |
+ * -------- |
|
30 |
+ * 2006-10-13 created (vlada) |
|
31 |
+ */ |
|
32 |
+ |
|
33 |
+ |
|
34 |
+#ifndef _ser_stun_h |
|
35 |
+#define _ser_stun_h |
|
36 |
+ |
|
37 |
+#ifdef USE_STUN |
|
38 |
+ |
|
39 |
+#include <openssl/sha.h> |
|
40 |
+ |
|
41 |
+#include "str.h" |
|
42 |
+#include "tcp_conn.h" |
|
43 |
+#include "ip_addr.h" |
|
44 |
+ |
|
45 |
+/* type redefinition */ |
|
46 |
+typedef unsigned char UCHAR_T; |
|
47 |
+typedef unsigned short USHORT_T; |
|
48 |
+typedef unsigned int UINT_T; |
|
49 |
+typedef unsigned long ULONG_T; |
|
50 |
+ |
|
51 |
+/* STUN message types supported by SER */ |
|
52 |
+#define BINDING_REQUEST 0x0001 |
|
53 |
+#define BINDING_RESPONSE 0x0101 |
|
54 |
+#define BINDING_ERROR_RESPONSE 0x0111 |
|
55 |
+ |
|
56 |
+/* common STUN attributes */ |
|
57 |
+#define MAPPED_ADDRESS_ATTR 0x0001 |
|
58 |
+#define USERNAME_ATTR 0x0006 |
|
59 |
+#define PASSWORD_ATTR 0x0007 |
|
60 |
+#define MESSAGE_INTEGRITY_ATTR 0x0008 |
|
61 |
+#define ERROR_CODE_ATTR 0x0009 |
|
62 |
+#define UNKNOWN_ATTRIBUTES_ATTR 0x000A |
|
63 |
+ |
|
64 |
+/* STUN attributes defined by rfc3489bis */ |
|
65 |
+#define REALM_ATTR 0x0014 |
|
66 |
+#define NONCE_ATTR 0x0015 |
|
67 |
+#define XOR_MAPPED_ADDRESS_ATTR 0x0020 |
|
68 |
+#define FINGERPRINT_ATTR 0x0023 |
|
69 |
+#define SERVER_ATTR 0x8022 |
|
70 |
+#define ALTERNATE_SERVER_ATTR 0x8023 |
|
71 |
+#define REFRESH_INTERVAL_ATTR 0x8024 |
|
72 |
+ |
|
73 |
+/* STUN attributes defined by rfc3489 */ |
|
74 |
+#define RESPONSE_ADDRESS_ATTR 0x0002 |
|
75 |
+#define CHANGE_REQUEST_ATTR 0x0003 |
|
76 |
+#define SOURCE_ADDRESS_ATTR 0x0004 |
|
77 |
+#define CHANGED_ADDRESS_ATTR 0x0005 |
|
78 |
+#define REFLECTED_FROM_ATTR 0x000b |
|
79 |
+ |
|
80 |
+/* STUN error codes supported by SER */ |
|
81 |
+#define RESPONSE_OK 200 |
|
82 |
+#define TRY_ALTERNATE_ERR 300 |
|
83 |
+#define BAD_REQUEST_ERR 400 |
|
84 |
+#define UNAUTHORIZED_ERR 401 |
|
85 |
+#define UNKNOWN_ATTRIBUTE_ERR 420 |
|
86 |
+#define STALE_CREDENTIALS_ERR 430 |
|
87 |
+#define INTEGRITY_CHECK_ERR 431 |
|
88 |
+#define MISSING_USERNAME_ERR 432 |
|
89 |
+#define USE_TLS_ERR 433 |
|
90 |
+#define MISSING_REALM_ERR 434 |
|
91 |
+#define MISSING_NONCE_ERR 435 |
|
92 |
+#define UNKNOWN_USERNAME_ERR 436 |
|
93 |
+#define STALE_NONCE_ERR 438 |
|
94 |
+#define SERVER_ERROR_ERR 500 |
|
95 |
+#define GLOBAL_FAILURE_ERR 600 |
|
96 |
+ |
|
97 |
+#define TRY_ALTERNATE_TXT "The client should contact an alternate server for this request." |
|
98 |
+#define BAD_REQUEST_TXT "The request was malformed. The client should not retry the request without modification from the previous attempt." |
|
99 |
+#define UNAUTHORIZED_TXT "The request did not contain a MESSAGE-INTEGRITY attribute." |
|
100 |
+#define UNKNOWN_ATTRIBUTE_TXT "The server did not understand a mandatory attribute in the request." |
|
101 |
+#define STALE_CREDENTIALS_TXT "The request did contain a MESSAGE-INTEGRITY attribute, but it used a shared secret that has expired. The client should obtain a new shared secret and try again." |
|
102 |
+#define INTEGRITY_CHECK_TXT "The request contained a MESSAGE-INTEGRITY attribute, but the HMAC failed verification. This could be a sign of a potential attack, or client implementation error." |
|
103 |
+#define MISSING_USERNAME_TXT "The request contained a MESSAGE-INTEGRITY attribute, but not a USERNAME attribute. Both USERNAME and MESSAGE-INTEGRITY must be present for integrity checks." |
|
104 |
+#define USE_TLS_TXT "The Shared Secret request has to be sent over TLS, but was not received over TLS." |
|
105 |
+#define MISSING_REALM_TXT "The REALM attribute was not present in the request." |
|
106 |
+#define MISSING_NONCE_TXT "The NONCE attribute was not present in the request." |
|
107 |
+#define UNKNOWN_USERNAME_TXT "The USERNAME supplied in the request is not known or is not known to the server." |
|
108 |
+#define STALE_NONCE_TXT "The NONCE attribute was present in the request but wasn't valid." |
|
109 |
+#define SERVER_ERROR_TXT "The server has suffered a temporary error. The client should try again." |
|
110 |
+#define GLOBAL_FAILURE_TXT "The server is refusing to fulfill the request. The client should not retry." |
|
111 |
+ |
|
112 |
+ |
|
113 |
+/* other stuff */ |
|
114 |
+#define MAGIC_COOKIE 0x2112A442 |
|
115 |
+#define MAGIC_COOKIE_2B 0x2112 /* because of XOR for port */ |
|
116 |
+#define MANDATORY_ATTR 0x7fff |
|
117 |
+#define PAD4 4 |
|
118 |
+#define PAD64 64 |
|
119 |
+#define STUN_MSG_LEN 516 |
|
120 |
+#define IPV4_LEN 4 |
|
121 |
+#define IPV6_LEN 16 |
|
122 |
+#define IPV4_FAMILY 0x0001 |
|
123 |
+#define IPV6_FAMILY 0x0002 |
|
124 |
+#define FATAL_ERROR -1 |
|
125 |
+#define IP_ADDR 4 |
|
126 |
+#define XOR 1 |
|
127 |
+#define TRANSACTION_ID 12 |
|
128 |
+ |
|
129 |
+#define PADDED_TO_FOUR(len) (len == 0) ? 0 : len + (PAD4 - len%PAD4) |
|
130 |
+#define PADDED_TO_SIXTYFOUR(len) (len == 0) ? 0 : len + (PAD64 - len%PAD64) |
|
131 |
+ |
|
132 |
+struct transaction_id { |
|
133 |
+ UINT_T magic_cookie; |
|
134 |
+ UCHAR_T id[TRANSACTION_ID]; |
|
135 |
+}; |
|
136 |
+ |
|
137 |
+struct stun_hdr { |
|
138 |
+ USHORT_T type; |
|
139 |
+ USHORT_T len; |
|
140 |
+ struct transaction_id id; |
|
141 |
+}; |
|
142 |
+ |
|
143 |
+struct stun_ip_addr { |
|
144 |
+ USHORT_T family; /* 0x01: IPv4; 0x02: IPv6 */ |
|
145 |
+ USHORT_T port; |
|
146 |
+ UINT_T ip[IP_ADDR]; |
|
147 |
+}; |
|
148 |
+ |
|
149 |
+struct stun_buffer { |
|
150 |
+ str buf; |
|
151 |
+ USHORT_T empty; /* number of free bytes in buf before |
|
152 |
+ * it'll be necessary to realloc the buf |
|
153 |
+ */ |
|
154 |
+}; |
|
155 |
+ |
|
156 |
+struct stun_unknown_att { |
|
157 |
+ USHORT_T type; |
|
158 |
+ struct stun_unknown_att* next; |
|
159 |
+}; |
|
160 |
+ |
|
161 |
+struct stun_attr { |
|
162 |
+ USHORT_T type; |
|
163 |
+ USHORT_T len; |
|
164 |
+}; |
|
165 |
+ |
|
166 |
+struct stun_msg { |
|
167 |
+ struct stun_hdr hdr; |
|
168 |
+ struct stun_ip_addr ip_addr; /* XOR values for rfc3489bis, |
|
169 |
+ normal values for rfc3489 */ |
|
170 |
+ char fp[SHA_DIGEST_LENGTH]; /* fingerprint value */ |
|
171 |
+ struct stun_buffer msg; |
|
172 |
+ UCHAR_T old; /* true: the format of message is in |
|
173 |
+ accordance with rfc3489 */ |
|
174 |
+}; |
|
175 |
+ |
|
176 |
+ |
|
177 |
+/* |
|
178 |
+ * stun functions called from ser |
|
179 |
+ */ |
|
180 |
+int stun_process_msg(char* buf, unsigned len, struct receive_info* ri); |
|
181 |
+ |
|
182 |
+#endif /* USE_STUN */ |
|
183 |
+ |
|
184 |
+#endif /* _ser_stun_h */ |