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,
*plen = 0;
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)
return val;
......@@ -111,7 +111,7 @@ stun_conncheck_reply (uint8_t *restrict buf, size_t *restrict plen,
if (stun_has_unknown (msg))
{
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)
val = stun_finish_short (buf, &len, NULL, pass, NULL, compat);
if (val)
......@@ -186,7 +186,7 @@ stun_conncheck_reply (uint8_t *restrict buf, size_t *restrict plen,
DBG ("STUN Role not specified by peer!\n");
#endif
stun_init_response (buf, len, msg);
stun_init_response (buf, len, msg, compat);
if (compat == 1) {
val = stun_append_addr (buf, len, STUN_MAPPED_ADDRESS, src, srclen);
} else {
......
......@@ -546,7 +546,7 @@ void stun_init_indication (uint8_t *msg, stun_method_t m);
*
* 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
......@@ -564,7 +564,7 @@ void stun_init_response (uint8_t *ans, size_t msize, const uint8_t *req);
* ans == req is allowed.
*/
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
......@@ -578,7 +578,8 @@ int stun_init_error (uint8_t *ans, size_t msize, const uint8_t *req,
*
* 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
stun_finish_long (uint8_t *msg, size_t *restrict plen,
......
......@@ -213,14 +213,14 @@ static int dgram_process (int sock)
/* Unknown attributes */
if (stun_has_unknown (buf))
{
stun_init_error_unknown (buf, sizeof (buf), buf);
stun_init_error_unknown (buf, sizeof (buf), buf, 0);
goto finish;
}
switch (stun_get_method (buf))
{
case STUN_BINDING:
stun_init_response (buf, sizeof (buf), buf);
stun_init_response (buf, sizeof (buf), buf, 0);
if (stun_has_cookie (buf))
stun_append_xor_addr (buf, sizeof (buf),
STUN_XOR_MAPPED_ADDRESS,
......@@ -231,7 +231,7 @@ static int dgram_process (int sock)
break;
default:
stun_init_error (buf, sizeof (buf), buf, STUN_BAD_REQUEST);
stun_init_error (buf, sizeof (buf), buf, STUN_BAD_REQUEST, 0);
}
finish:
......
......@@ -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;
assert (strlen (server) < 128);
// return stun_append_string (msg, msize, STUN_SERVER, server);
return 0;
if (compat == 1)
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_get_class (req) == STUN_REQUEST);
......@@ -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));
/* For RFC3489 compatibility, we cannot assume the cookie */
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)
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 (msize >= 20u);
......@@ -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));
/* For RFC3489 compatibility, we cannot assume the cookie */
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);
}
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;
#ifdef HAVE_C_VARARRAYS
......@@ -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]));
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;
for (i = 0; i < counter; i++)
......
......@@ -266,7 +266,7 @@ static void responses (void)
val = recv (servfd, buf, 1000, MSG_DONTWAIT);
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);
val = stun_finish (buf, &len, 0);
assert (val == 0);
......@@ -284,7 +284,7 @@ static void responses (void)
val = recv (servfd, buf, 1000, MSG_DONTWAIT);
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,
"This is an unknown attribute!");
assert (val == 0);
......@@ -306,7 +306,7 @@ static void responses (void)
val = recv (servfd, buf, 1000, MSG_DONTWAIT);
assert (val >= 0);
stun_init_response (buf, sizeof (buf), buf);
stun_init_response (buf, sizeof (buf), buf, 0);
len = sizeof (buf);
val = stun_finish (buf, &len, 0);
assert (val == 0);
......@@ -325,7 +325,7 @@ static void responses (void)
val = recv (servfd, buf, 1000, MSG_DONTWAIT);
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,
(struct sockaddr *)&addr, addrlen);
assert (val == 0);
......
......@@ -75,7 +75,7 @@ int main (void)
/* Incorrect message class */
stun_init_request (req, STUN_BINDING);
stun_init_response (req, sizeof (req), req);
stun_init_response (req, sizeof (req), req, 0);
len = sizeof (req);
val = stun_finish (req, &len, 0);
assert (val == 0);
......
......@@ -149,14 +149,14 @@ int main (void)
fatal ("Request formatting test failed");
/* Response formatting test */
stun_init_response (msg, sizeof (msg), msg);
stun_init_response (msg, sizeof (msg), msg, 0);
finish_check (msg);
if (memcmp (msg, "\x01\x01", 2))
fatal ("Response formatting test failed");
/* Error formatting test */
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");
finish_check (msg);
if (memcmp (msg, "\x01\x11", 2))
......@@ -164,7 +164,7 @@ int main (void)
/* Unknown error formatting test */
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");
finish_check (msg);
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