[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r23174 - gnunet/src/mesh
From: |
gnunet |
Subject: |
[GNUnet-SVN] r23174 - gnunet/src/mesh |
Date: |
Thu, 9 Aug 2012 14:26:44 +0200 |
Author: bartpolot
Date: 2012-08-09 14:26:44 +0200 (Thu, 09 Aug 2012)
New Revision: 23174
Modified:
gnunet/src/mesh/gnunet-service-mesh.c
Log:
- validate client generated PIDs
Modified: gnunet/src/mesh/gnunet-service-mesh.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh.c 2012-08-09 12:10:03 UTC (rev
23173)
+++ gnunet/src/mesh/gnunet-service-mesh.c 2012-08-09 12:26:44 UTC (rev
23174)
@@ -3482,6 +3482,31 @@
/**
+ * Get the Flow Control info of a client.
+ *
+ * @param t Tunnel on which to look.
+ * @param c Client whose ACK to get.
+ *
+ * @return ACK value.
+ */
+static struct MeshTunnelClientInfo *
+tunnel_get_client_fc (struct MeshTunnel *t,
+ struct MeshClient *c)
+{
+ unsigned int i;
+
+ for (i = 0; i < t->nclients; i++)
+ {
+ if (t->clients[i] != c)
+ continue;
+ return &t->clients_fc[i];
+ }
+ GNUNET_assert (0);
+ return NULL; // avoid compiler / coverity complaints
+}
+
+
+/**
* Iterator to get the appropiate ACK value from all children nodes.
*
* @param cls Closue (tunnel).
@@ -3573,31 +3598,6 @@
/**
- * Get the ACK value of a client in a particular tunnel.
- *
- * @param t Tunnel on which to look.
- * @param c Client whose ACK to get.
- *
- * @return ACK value.
- */
-uint32_t // FIXME fc Is this funcion needed anymore?
-tunnel_get_client_fwd_ack (struct MeshTunnel *t,
- struct MeshClient *c)
-{
- unsigned int i;
-
- for (i = 0; i < t->nclients; i++)
- {
- if (t->clients[i] != c)
- continue;
- return t->clients_fc[i].fwd_ack;
- }
- GNUNET_break (0);
- return UINT32_MAX;
-}
-
-
-/**
* Get the highest ACK value of all clients in a particular tunnel,
* according to the buffering/speed settings.
*
@@ -6858,6 +6858,16 @@
return;
}
+ /* PID should be as expected */
+ if (ntohl (data_msg->pid) != t->fwd_pid + 1)
+ {
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Unicast PID, expected %u, got %u\n",
+ t->fwd_pid + 1, ntohl (data_msg->pid));
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
/* Ok, everything is correct, send the message
* (pretend we got it from a mesh peer)
@@ -6872,13 +6882,6 @@
copy->oid = my_full_id;
copy->tid = htonl (t->id.tid);
copy->ttl = htonl (default_ttl);
- if (ntohl (copy->pid) != t->fwd_pid + 1)
- {
- GNUNET_break (0);
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Unicast PID, expected %u, got %u\n",
- t->fwd_pid + 1, ntohl (copy->pid));
- }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
" calling generic handler...\n");
handle_mesh_data_unicast (NULL, &my_full_id, ©->header, NULL, 0);
@@ -6901,7 +6904,7 @@
const struct GNUNET_MessageHeader *message)
{
struct GNUNET_MESH_ToOrigin *data_msg;
- struct GNUNET_PeerIdentity id;
+ struct MeshTunnelClientInfo *clinfo;
struct MeshClient *c;
struct MeshTunnel *t;
MESH_TunnelNumber tid;
@@ -6950,8 +6953,19 @@
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
- GNUNET_PEER_resolve (t->id.oid, &id);
+ /* PID should be as expected */
+ clinfo = tunnel_get_client_fc (t, c);
+ if (ntohl (data_msg->pid) != clinfo->bck_pid + 1)
+ {
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "To Origin PID, expected %u, got %u\n",
+ clinfo->bck_pid + 1, ntohl (data_msg->pid));
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
+
/* Ok, everything is correct, send the message
* (pretend we got it from a mesh peer)
*/
@@ -6962,7 +6976,7 @@
/* Work around const limitation */
copy = (struct GNUNET_MESH_ToOrigin *) buf;
memcpy (buf, data_msg, size);
- copy->oid = id;
+ GNUNET_PEER_resolve (t->id.oid, ©->oid);
copy->tid = htonl (t->id.tid);
copy->ttl = htonl (default_ttl);
GNUNET_assert (ntohl (copy->pid) == (t->bck_pid + 1));
@@ -7030,7 +7044,18 @@
return;
}
+ /* PID should be as expected */
+ if (ntohl (data_msg->pid) != t->fwd_pid + 1)
{
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Multicast PID, expected %u, got %u\n",
+ t->fwd_pid + 1, ntohl (data_msg->pid));
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
+
+ {
char buf[ntohs (message->size)] GNUNET_ALIGN;
struct GNUNET_MESH_Multicast *copy;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r23174 - gnunet/src/mesh,
gnunet <=