[Nice] [nice/master] Use stun_demux to demux stun so that zero-filled buffers are passed out

Olivier Crete olivier.crete at collabora.co.uk
Wed Nov 5 14:01:09 PST 2008


darcs-hash:20080426042635-3e2dc-7f782b585b7a2c3df49ec8ef34a38062bc1a7a52.gz
---
 agent/agent.c   |    7 +++++--
 stun/bind.h     |   17 +++++++++++++++++
 stun/stun-msg.h |    3 ++-
 3 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/agent/agent.c b/agent/agent.c
index bb87bfa..8166da5 100644
--- a/agent/agent.c
+++ b/agent/agent.c
@@ -1229,9 +1229,12 @@ _nice_agent_recv (
     }
   /* step: validate using the new STUN API */
   /*    - 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 
     {
diff --git a/stun/bind.h b/stun/bind.h
index f6c24b1..8c37332 100644
--- a/stun/bind.h
+++ b/stun/bind.h
@@ -178,7 +178,24 @@ int stun_nested_process (stun_nested_t *restrict ctx,
 
 # ifndef STUN_VALIDATE_DECLARATION
 #  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);
+
+/**
+ * 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
 
 # ifdef __cplusplus
diff --git a/stun/stun-msg.h b/stun/stun-msg.h
index 0961b42..0449f4d 100644
--- a/stun/stun-msg.h
+++ b/stun/stun-msg.h
@@ -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.
  */
 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
@@ -343,6 +342,8 @@ ssize_t stun_validate (const uint8_t *msg, size_t len);
  */
 bool stun_demux (const uint8_t *msg);
 
+#endif
+
 /**
  * Matches a response (or error response) to a request.
  *
-- 
1.5.6.5




More information about the Nice mailing list