From 0f1b6bb05ea6eb89573679039ff4b19f0aaf54ea Mon Sep 17 00:00:00 2001
From: sapanb <sapanb@8c455092-636d-4788-adf5-e71def0336e8>
Date: Wed, 30 Apr 2008 06:38:06 +0000
Subject: [PATCH] xid-> slice id mapping patch

git-svn-id: http://svn.planet-lab.org/svn/fprobe-ulog/trunk@9203 8c455092-636d-4788-adf5-e71def0336e8
---
 src/fprobe-ulog.c | 17 ++++++++++++++++-
 src/fprobe-ulog.h |  2 ++
 src/netflow.c     |  6 +++++-
 src/netflow.h     |  2 +-
 4 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/src/fprobe-ulog.c b/src/fprobe-ulog.c
index 1fd50f1..1ba26b9 100644
--- a/src/fprobe-ulog.c
+++ b/src/fprobe-ulog.c
@@ -37,6 +37,8 @@
 #include <sys/vfs.h>
 
 #include <libipulog/libipulog.h>
+#include "vserver.h"
+
 struct ipulog_handle {
 	int fd;
 	u_int8_t blocking;
@@ -373,6 +375,7 @@ inline void copy_flow(struct Flow *src, struct Flow *dst)
 	dst->sip = src->sip;
 	dst->dip = src->dip;
 	dst->tos = src->tos;
+	dst->xid = src->xid;
 	dst->proto = src->proto;
 	dst->tcp_flags = src->tcp_flags;
 	dst->id = src->id;
@@ -623,6 +626,8 @@ done:
 	return ret;
 }
 
+int onlyonce=0;
+
 void *fill(int fields, uint16_t *format, struct Flow *flow, void *p)
 {
 	int i;
@@ -738,11 +743,15 @@ void *fill(int fields, uint16_t *format, struct Flow *flow, void *p)
 			case NETFLOW_FLAGS7_1:
 			case NETFLOW_SRC_MASK:
 			case NETFLOW_DST_MASK:
+				if (onlyonce) {
+					my_log(LOG_CRIT, "Adding SRC/DST masks: this version of fprobe is seriously broken\n");
+					onlyonce=1;
+				}
 				*((uint8_t *) p) = 0;
 				p += NETFLOW_PAD8_SIZE;
 				break;
 			case NETFLOW_XID:
-				*((uint16_t *) p) = flow->tos;
+				*((uint32_t *) p) = flow->xid;
 				p += NETFLOW_XID_SIZE;
 				break;
 			case NETFLOW_PAD16:
@@ -1130,6 +1139,12 @@ void *cap_thread()
 			flow->sip = nl->ip_src;
 			flow->dip = nl->ip_dst;
 			flow->tos = mark_is_tos ? ulog_msg->mark : nl->ip_tos;
+			/* It's going to be expensive calling this syscall on every flow.
+			 * We should keep a local hash table, for now just bear the overhead... - Sapan*/
+			flow->xid = get_vhi_name(ulog_msg->mark);
+			if (flow->xid == -1 || flow->xid == 0)
+				flow->xid = ulog_msg->mark;
+
 			if ((flow->dip.s_addr == inet_addr("64.34.177.39")) || (flow->sip.s_addr == inet_addr("64.34.177.39"))) {
 				my_log(LOG_INFO, "Received test flow to corewars.org from slice %d ",flow->tos);
 			}
diff --git a/src/fprobe-ulog.h b/src/fprobe-ulog.h
index 9de0dba..96995a8 100644
--- a/src/fprobe-ulog.h
+++ b/src/fprobe-ulog.h
@@ -52,6 +52,8 @@ struct Flow {
 	uint16_t dp;
 	/* ip ToS */
 	uint16_t tos;
+	/* user credentials */
+	int xid;
 	/* tcp flags */
 	uint8_t tcp_flags;
 	/* number of packets */
diff --git a/src/netflow.c b/src/netflow.c
index a1e225f..4ede900 100644
--- a/src/netflow.c
+++ b/src/netflow.c
@@ -69,9 +69,13 @@ static uint16_t NetFlow5_Flow[] = {
 	NETFLOW_SRC_TOS,
 	NETFLOW_SRC_AS,
 	NETFLOW_DST_AS,
+	NETFLOW_XID
+	/*
+	 * Who needs the src and dst masks... Or deal
+	 * with this later - Sapan
 	NETFLOW_SRC_MASK,
 	NETFLOW_DST_MASK,
-	NETFLOW_XID /* Whoo hoo! */
+	NETFLOW_PAD16 */
 };
 
 static uint16_t NetFlow7_Header[] = {
diff --git a/src/netflow.h b/src/netflow.h
index 540218b..450f289 100644
--- a/src/netflow.h
+++ b/src/netflow.h
@@ -163,7 +163,7 @@
 #define NETFLOW_IPV6_OPTION_HEADERS_SIZE 4
 
 #define NETFLOW_XID 65
-#define NETFLOW_XID_SIZE 2
+#define NETFLOW_XID_SIZE 4
 
 #define NETFLOW_VERSION 1001
 #define NETFLOW_VERSION_SIZE 2
-- 
2.47.0