Commit 9fee68ff authored by Olivier Crete's avatar Olivier Crete

Use stun_demux to demux stun so that zero-filled buffers are passed out

darcs-hash:20080426042635-3e2dc-7f782b585b7a2c3df49ec8ef34a38062bc1a7a52.gz
parent 051cf2f2
...@@ -1229,9 +1229,12 @@ _nice_agent_recv ( ...@@ -1229,9 +1229,12 @@ _nice_agent_recv (
} }
/* step: validate using the new STUN API */ /* step: validate using the new STUN API */
/* - note: old check '((buf[0] & 0xc0) == 0)' */ /* - note: old check '((buf[0] & 0xc0) == 0)' */
else if (stun_validate ((uint8_t*)buf, len) > 0) else if (stun_validate ((uint8_t*)buf, len) > 0 &&
stun_demux ((uint8_t*)buf))
{ {
conn_check_handle_inbound_stun (agent, stream, component, udp_socket, &from, buf, len); /* If the retval is no 0, its not a valid stun packet, probably data */
conn_check_handle_inbound_stun (agent, stream, component, udp_socket,
&from, buf, len);
} }
else else
{ {
......
...@@ -178,7 +178,24 @@ int stun_nested_process (stun_nested_t *restrict ctx, ...@@ -178,7 +178,24 @@ int stun_nested_process (stun_nested_t *restrict ctx,
# ifndef STUN_VALIDATE_DECLARATION # ifndef STUN_VALIDATE_DECLARATION
# define STUN_VALIDATE_DECLARATION 2 # define STUN_VALIDATE_DECLARATION 2
/**
* Verifies that a packet is a valid STUN message.
*
* @return actual byte length of the message if valid (>0),
* 0 if it the packet is incomplete or -1 in case of other error.
*/
ssize_t stun_validate (const uint8_t *msg, size_t len); ssize_t stun_validate (const uint8_t *msg, size_t len);
/**
* Checks whether a packet on a mutiplexed STUN/non-STUN channel looks like a
* STUN message. It is assumed that stun_validate succeeded first (i.e.
* returned a stricly positive value).
*
* @return true if STUN message with cookie and fingerprint, 0 otherwise.
*/
bool stun_demux (const uint8_t *msg);
# endif # endif
# ifdef __cplusplus # ifdef __cplusplus
......
...@@ -332,7 +332,6 @@ int stun_xor_address (const uint8_t *msg, ...@@ -332,7 +332,6 @@ int stun_xor_address (const uint8_t *msg,
* 0 if it the packet is incomplete or -1 in case of other error. * 0 if it the packet is incomplete or -1 in case of other error.
*/ */
ssize_t stun_validate (const uint8_t *msg, size_t len); ssize_t stun_validate (const uint8_t *msg, size_t len);
#endif
/** /**
* Checks whether a packet on a mutiplexed STUN/non-STUN channel looks like a * Checks whether a packet on a mutiplexed STUN/non-STUN channel looks like a
...@@ -343,6 +342,8 @@ ssize_t stun_validate (const uint8_t *msg, size_t len); ...@@ -343,6 +342,8 @@ ssize_t stun_validate (const uint8_t *msg, size_t len);
*/ */
bool stun_demux (const uint8_t *msg); bool stun_demux (const uint8_t *msg);
#endif
/** /**
* Matches a response (or error response) to a request. * Matches a response (or error response) to a request.
* *
......
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