Commit da1a1c21 authored by Olivier Crête's avatar Olivier Crête

Pass compat flag everywhere to not put stun-server into packets in gtalk mode

parent 1aeb122c
...@@ -60,7 +60,7 @@ stun_bind_error (uint8_t *buf, size_t *plen, const uint8_t *req, ...@@ -60,7 +60,7 @@ stun_bind_error (uint8_t *buf, size_t *plen, const uint8_t *req,
*plen = 0; *plen = 0;
DBG ("STUN Error Reply (buffer size: %u)...\n", (unsigned)len); DBG ("STUN Error Reply (buffer size: %u)...\n", (unsigned)len);
val = stun_init_error (buf, len, req, code); val = stun_init_error (buf, len, req, code, compat);
if (val) if (val)
return val; return val;
...@@ -111,7 +111,7 @@ stun_conncheck_reply (uint8_t *restrict buf, size_t *restrict plen, ...@@ -111,7 +111,7 @@ stun_conncheck_reply (uint8_t *restrict buf, size_t *restrict plen,
if (stun_has_unknown (msg)) if (stun_has_unknown (msg))
{ {
DBG (" Unknown mandatory attributes in message.\n"); DBG (" Unknown mandatory attributes in message.\n");
val = stun_init_error_unknown (buf, len, msg); val = stun_init_error_unknown (buf, len, msg, compat);
if (!val) if (!val)
val = stun_finish_short (buf, &len, NULL, pass, NULL, compat); val = stun_finish_short (buf, &len, NULL, pass, NULL, compat);
if (val) if (val)
...@@ -186,7 +186,7 @@ stun_conncheck_reply (uint8_t *restrict buf, size_t *restrict plen, ...@@ -186,7 +186,7 @@ stun_conncheck_reply (uint8_t *restrict buf, size_t *restrict plen,
DBG ("STUN Role not specified by peer!\n"); DBG ("STUN Role not specified by peer!\n");
#endif #endif
stun_init_response (buf, len, msg); stun_init_response (buf, len, msg, compat);
if (compat == 1) { if (compat == 1) {
val = stun_append_addr (buf, len, STUN_MAPPED_ADDRESS, src, srclen); val = stun_append_addr (buf, len, STUN_MAPPED_ADDRESS, src, srclen);
} else { } else {
......
...@@ -546,7 +546,7 @@ void stun_init_indication (uint8_t *msg, stun_method_t m); ...@@ -546,7 +546,7 @@ void stun_init_indication (uint8_t *msg, stun_method_t m);
* *
* ans == req is allowed. * ans == req is allowed.
*/ */
void stun_init_response (uint8_t *ans, size_t msize, const uint8_t *req); void stun_init_response (uint8_t *ans, size_t msize, const uint8_t *req, int compat);
/** /**
* Initializes a STUN error response message buffer with an ERROR-CODE * Initializes a STUN error response message buffer with an ERROR-CODE
...@@ -564,7 +564,7 @@ void stun_init_response (uint8_t *ans, size_t msize, const uint8_t *req); ...@@ -564,7 +564,7 @@ void stun_init_response (uint8_t *ans, size_t msize, const uint8_t *req);
* ans == req is allowed. * ans == req is allowed.
*/ */
int stun_init_error (uint8_t *ans, size_t msize, const uint8_t *req, int stun_init_error (uint8_t *ans, size_t msize, const uint8_t *req,
stun_error_t err); stun_error_t err, int compat);
/** /**
* Initializes a STUN error response message buffer, in response to a valid * Initializes a STUN error response message buffer, in response to a valid
...@@ -578,7 +578,8 @@ int stun_init_error (uint8_t *ans, size_t msize, const uint8_t *req, ...@@ -578,7 +578,8 @@ int stun_init_error (uint8_t *ans, size_t msize, const uint8_t *req,
* *
* ans == req is allowed. * ans == req is allowed.
*/ */
int stun_init_error_unknown (uint8_t *ans, size_t msize, const uint8_t *req); int stun_init_error_unknown (uint8_t *ans, size_t msize, const uint8_t *req,
int compat);
size_t size_t
stun_finish_long (uint8_t *msg, size_t *restrict plen, stun_finish_long (uint8_t *msg, size_t *restrict plen,
......
...@@ -213,14 +213,14 @@ static int dgram_process (int sock) ...@@ -213,14 +213,14 @@ static int dgram_process (int sock)
/* Unknown attributes */ /* Unknown attributes */
if (stun_has_unknown (buf)) if (stun_has_unknown (buf))
{ {
stun_init_error_unknown (buf, sizeof (buf), buf); stun_init_error_unknown (buf, sizeof (buf), buf, 0);
goto finish; goto finish;
} }
switch (stun_get_method (buf)) switch (stun_get_method (buf))
{ {
case STUN_BINDING: case STUN_BINDING:
stun_init_response (buf, sizeof (buf), buf); stun_init_response (buf, sizeof (buf), buf, 0);
if (stun_has_cookie (buf)) if (stun_has_cookie (buf))
stun_append_xor_addr (buf, sizeof (buf), stun_append_xor_addr (buf, sizeof (buf),
STUN_XOR_MAPPED_ADDRESS, STUN_XOR_MAPPED_ADDRESS,
...@@ -231,7 +231,7 @@ static int dgram_process (int sock) ...@@ -231,7 +231,7 @@ static int dgram_process (int sock)
break; break;
default: default:
stun_init_error (buf, sizeof (buf), buf, STUN_BAD_REQUEST); stun_init_error (buf, sizeof (buf), buf, STUN_BAD_REQUEST, 0);
} }
finish: finish:
......
...@@ -213,17 +213,19 @@ stun_append_string (uint8_t *restrict msg, size_t msize, ...@@ -213,17 +213,19 @@ stun_append_string (uint8_t *restrict msg, size_t msize,
} }
static int stun_append_server (uint8_t *restrict msg, size_t msize) static int stun_append_server (uint8_t *restrict msg, size_t msize, int compat)
{ {
static const char server[] = PACKAGE_STRING; static const char server[] = PACKAGE_STRING;
assert (strlen (server) < 128); assert (strlen (server) < 128);
// return stun_append_string (msg, msize, STUN_SERVER, server); if (compat == 1)
return 0; return 0;
else
return stun_append_string (msg, msize, STUN_SERVER, server);
} }
void stun_init_response (uint8_t *ans, size_t msize, const uint8_t *req) void stun_init_response (uint8_t *ans, size_t msize, const uint8_t *req, int compat)
{ {
assert (stun_valid (req)); assert (stun_valid (req));
assert (stun_get_class (req) == STUN_REQUEST); assert (stun_get_class (req) == STUN_REQUEST);
...@@ -232,7 +234,7 @@ void stun_init_response (uint8_t *ans, size_t msize, const uint8_t *req) ...@@ -232,7 +234,7 @@ void stun_init_response (uint8_t *ans, size_t msize, const uint8_t *req)
stun_init (ans, STUN_RESPONSE, stun_get_method (req), stun_id (req)); stun_init (ans, STUN_RESPONSE, stun_get_method (req), stun_id (req));
/* For RFC3489 compatibility, we cannot assume the cookie */ /* For RFC3489 compatibility, we cannot assume the cookie */
memcpy (ans + 4, req + 4, 4); memcpy (ans + 4, req + 4, 4);
(void)stun_append_server (ans, msize); (void)stun_append_server (ans, msize, compat);
} }
...@@ -320,7 +322,7 @@ stun_append_error (uint8_t *restrict msg, size_t msize, stun_error_t code) ...@@ -320,7 +322,7 @@ stun_append_error (uint8_t *restrict msg, size_t msize, stun_error_t code)
int stun_init_error (uint8_t *ans, size_t msize, const uint8_t *req, int stun_init_error (uint8_t *ans, size_t msize, const uint8_t *req,
stun_error_t err) stun_error_t err, int compat)
{ {
assert (stun_valid (req)); assert (stun_valid (req));
assert (msize >= 20u); assert (msize >= 20u);
...@@ -329,12 +331,13 @@ int stun_init_error (uint8_t *ans, size_t msize, const uint8_t *req, ...@@ -329,12 +331,13 @@ int stun_init_error (uint8_t *ans, size_t msize, const uint8_t *req,
stun_init (ans, STUN_ERROR, stun_get_method (req), stun_id (req)); stun_init (ans, STUN_ERROR, stun_get_method (req), stun_id (req));
/* For RFC3489 compatibility, we cannot assume the cookie */ /* For RFC3489 compatibility, we cannot assume the cookie */
memcpy (ans + 4, req + 4, 4); memcpy (ans + 4, req + 4, 4);
(void)stun_append_server (ans, msize); (void)stun_append_server (ans, msize, compat);
return stun_append_error (ans, msize, err); return stun_append_error (ans, msize, err);
} }
int stun_init_error_unknown (uint8_t *ans, size_t msize, const uint8_t *req) int stun_init_error_unknown (uint8_t *ans, size_t msize, const uint8_t *req,
int compat)
{ {
unsigned counter, i; unsigned counter, i;
#ifdef HAVE_C_VARARRAYS #ifdef HAVE_C_VARARRAYS
...@@ -346,7 +349,7 @@ int stun_init_error_unknown (uint8_t *ans, size_t msize, const uint8_t *req) ...@@ -346,7 +349,7 @@ int stun_init_error_unknown (uint8_t *ans, size_t msize, const uint8_t *req)
counter = stun_find_unknown (req, ids, sizeof (ids) / sizeof (ids[0])); counter = stun_find_unknown (req, ids, sizeof (ids) / sizeof (ids[0]));
assert (counter > 0); assert (counter > 0);
if (stun_init_error (ans, msize, req, STUN_UNKNOWN_ATTRIBUTE)) if (stun_init_error (ans, msize, req, STUN_UNKNOWN_ATTRIBUTE, compat))
return ENOBUFS; return ENOBUFS;
for (i = 0; i < counter; i++) for (i = 0; i < counter; i++)
......
...@@ -266,7 +266,7 @@ static void responses (void) ...@@ -266,7 +266,7 @@ static void responses (void)
val = recv (servfd, buf, 1000, MSG_DONTWAIT); val = recv (servfd, buf, 1000, MSG_DONTWAIT);
assert (val >= 0); assert (val >= 0);
stun_init_error (buf, sizeof (buf), buf, STUN_SERVER_ERROR); stun_init_error (buf, sizeof (buf), buf, STUN_SERVER_ERROR, 0);
len = sizeof (buf); len = sizeof (buf);
val = stun_finish (buf, &len, 0); val = stun_finish (buf, &len, 0);
assert (val == 0); assert (val == 0);
...@@ -284,7 +284,7 @@ static void responses (void) ...@@ -284,7 +284,7 @@ static void responses (void)
val = recv (servfd, buf, 1000, MSG_DONTWAIT); val = recv (servfd, buf, 1000, MSG_DONTWAIT);
assert (val >= 0); assert (val >= 0);
stun_init_response (buf, sizeof (buf), buf); stun_init_response (buf, sizeof (buf), buf, 0);
val = stun_append_string (buf, sizeof (buf), 0x6000, val = stun_append_string (buf, sizeof (buf), 0x6000,
"This is an unknown attribute!"); "This is an unknown attribute!");
assert (val == 0); assert (val == 0);
...@@ -306,7 +306,7 @@ static void responses (void) ...@@ -306,7 +306,7 @@ static void responses (void)
val = recv (servfd, buf, 1000, MSG_DONTWAIT); val = recv (servfd, buf, 1000, MSG_DONTWAIT);
assert (val >= 0); assert (val >= 0);
stun_init_response (buf, sizeof (buf), buf); stun_init_response (buf, sizeof (buf), buf, 0);
len = sizeof (buf); len = sizeof (buf);
val = stun_finish (buf, &len, 0); val = stun_finish (buf, &len, 0);
assert (val == 0); assert (val == 0);
...@@ -325,7 +325,7 @@ static void responses (void) ...@@ -325,7 +325,7 @@ static void responses (void)
val = recv (servfd, buf, 1000, MSG_DONTWAIT); val = recv (servfd, buf, 1000, MSG_DONTWAIT);
assert (val >= 0); assert (val >= 0);
stun_init_response (buf, sizeof (buf), buf); stun_init_response (buf, sizeof (buf), buf, 0);
val = stun_append_addr (buf, sizeof (buf), STUN_MAPPED_ADDRESS, val = stun_append_addr (buf, sizeof (buf), STUN_MAPPED_ADDRESS,
(struct sockaddr *)&addr, addrlen); (struct sockaddr *)&addr, addrlen);
assert (val == 0); assert (val == 0);
......
...@@ -75,7 +75,7 @@ int main (void) ...@@ -75,7 +75,7 @@ int main (void)
/* Incorrect message class */ /* Incorrect message class */
stun_init_request (req, STUN_BINDING); stun_init_request (req, STUN_BINDING);
stun_init_response (req, sizeof (req), req); stun_init_response (req, sizeof (req), req, 0);
len = sizeof (req); len = sizeof (req);
val = stun_finish (req, &len, 0); val = stun_finish (req, &len, 0);
assert (val == 0); assert (val == 0);
......
...@@ -149,14 +149,14 @@ int main (void) ...@@ -149,14 +149,14 @@ int main (void)
fatal ("Request formatting test failed"); fatal ("Request formatting test failed");
/* Response formatting test */ /* Response formatting test */
stun_init_response (msg, sizeof (msg), msg); stun_init_response (msg, sizeof (msg), msg, 0);
finish_check (msg); finish_check (msg);
if (memcmp (msg, "\x01\x01", 2)) if (memcmp (msg, "\x01\x01", 2))
fatal ("Response formatting test failed"); fatal ("Response formatting test failed");
/* Error formatting test */ /* Error formatting test */
stun_init_request (msg, STUN_BINDING); stun_init_request (msg, STUN_BINDING);
if (stun_init_error (msg, sizeof (msg), msg, 400)) if (stun_init_error (msg, sizeof (msg), msg, 400, 0))
fatal ("Error initialization test failed"); fatal ("Error initialization test failed");
finish_check (msg); finish_check (msg);
if (memcmp (msg, "\x01\x11", 2)) if (memcmp (msg, "\x01\x11", 2))
...@@ -164,7 +164,7 @@ int main (void) ...@@ -164,7 +164,7 @@ int main (void)
/* Unknown error formatting test */ /* Unknown error formatting test */
stun_init_request (msg, STUN_BINDING); stun_init_request (msg, STUN_BINDING);
if (stun_init_error (msg, sizeof (msg), msg, 666)) if (stun_init_error (msg, sizeof (msg), msg, 666, 0))
fatal ("Unknown error initialization test failed"); fatal ("Unknown error initialization test failed");
finish_check (msg); finish_check (msg);
if (memcmp (msg, "\x01\x11", 2)) if (memcmp (msg, "\x01\x11", 2))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment