Packetseer wrapper to let slices see all traffic on a PL node
Sapan Bhatia [Fri, 17 Sep 2010 15:35:16 +0000 (11:35 -0400)]
packetseer/Makefile [new file with mode: 0644]
packetseer/packetseer.c [new file with mode: 0644]
packetseer/packetseer.h [new file with mode: 0644]
packetseer/pcap [new file with mode: 0755]

diff --git a/packetseer/Makefile b/packetseer/Makefile
new file mode 100644 (file)
index 0000000..01147d4
--- /dev/null
@@ -0,0 +1,7 @@
+all: packetseer.so
+
+LIBDIR=../lib/
+INCLUDEDIR=../lib/
+
+packetseer.so: packetseer.c $(LIBDIR)/fdpass.c
+       gcc -I$(INCLUDEDIR) -shared -ldl packetseer.c $(LIBDIR)/fdpass.c -o packetseer.so
diff --git a/packetseer/packetseer.c b/packetseer/packetseer.c
new file mode 100644 (file)
index 0000000..8ab785d
--- /dev/null
@@ -0,0 +1,63 @@
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "fdpass.h"
+#include <dlfcn.h>
+
+#define VSYS_PACKETSEER "/vsys/fd_packetseer.control"
+
+int (*socket_orig)(int f, int p, int s);
+
+int _init_pslib() {
+    socket_orig = &socket;
+    printf("Stored value of socket");
+}
+
+int socket(int f, int p, int s)
+{
+    if (!socket_orig) {
+        void *handle = dlopen("/lib/libc.so.6",RTLD_LAZY);
+        if (!handle) {
+            fprintf(stderr,"Error loading libc.so.6\n");
+            return -1;
+        }
+        socket_orig = dlsym(handle, "socket");
+        if (!socket_orig) {
+            fprintf(stderr,"Error loading socket symbol");
+            return -1;
+        }
+        fprintf(stderr,"Socket call: %x",socket_orig);
+    }
+
+    if (f == PF_PACKET) {
+        int sfd;
+        struct sockaddr_un addr;
+        int remotefd;
+
+        sfd = socket(AF_UNIX, SOCK_STREAM, 0);
+        if (sfd == -1) {
+            perror("Could not create UNIX socket\n");
+            exit(-1);
+        }
+
+        memset(&addr, 0, sizeof(struct sockaddr_un));
+        /* Clear structure */
+        addr.sun_family = AF_UNIX;
+        strncpy(addr.sun_path, VSYS_PACKETSEER,
+                sizeof(addr.sun_path) - 1);
+
+        if (connect(sfd, (struct sockaddr *) &addr,
+                    sizeof(struct sockaddr_un)) == -1) {
+            perror("Could not connect to Vsys control socket");
+            exit(-1);
+        }
+
+        remotefd = receive_fd(sfd);
+        return remotefd;
+    }
+    else
+        return (*socket_orig)(f, p, s);
+}
+
diff --git a/packetseer/packetseer.h b/packetseer/packetseer.h
new file mode 100644 (file)
index 0000000..930f6f2
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef _BM_SOCKET_H_
+#define _BM_SOCKET_H_
+
+extern int CreateLargeBufSocket(int recvbuf, int sndbuf);
+
+#endif
diff --git a/packetseer/pcap b/packetseer/pcap
new file mode 100755 (executable)
index 0000000..942c42a
Binary files /dev/null and b/packetseer/pcap differ