Support for PLC redirection and a single-entry configuration. updated the conf file
authorKyoungSoo Park <kyoungso@cs.princeton.edu>
Thu, 27 Mar 2008 00:01:51 +0000 (00:01 +0000)
committerKyoungSoo Park <kyoungso@cs.princeton.edu>
Thu, 27 Mar 2008 00:01:51 +0000 (00:01 +0000)
codemux.c
codemux.conf
codemux.spec

index 5ba4b01..31a4dfc 100644 (file)
--- a/codemux.c
+++ b/codemux.c
@@ -38,7 +38,7 @@ int defaultTraceSync;
 #define FAIRNESS_CUTOFF (MAX_CONNS * 0.85)
 
 /* codemux version */
 #define FAIRNESS_CUTOFF (MAX_CONNS * 0.85)
 
 /* codemux version */
-#define CODEMUX_VERSION "0.3"
+#define CODEMUX_VERSION "0.4"
 
 typedef struct FlowBuf {
   int fb_refs;                 /* num refs */
 
 typedef struct FlowBuf {
   int fb_refs;                 /* num refs */
@@ -94,6 +94,9 @@ static int numNeedingHeaders; /* how many conns waiting on headers? */
 
 static int numForks;
 
 
 static int numForks;
 
+/* PLC netflow domain name like netflow.planet-lab.org */
+static char* domainNamePLCNetflow = NULL;
+
 #ifndef SO_SETXID
 #define SO_SETXID SO_PEERCRED
 #endif
 #ifndef SO_SETXID
 #define SO_SETXID SO_PEERCRED
 #endif
@@ -297,7 +300,7 @@ ReadConfFile(void)
       break;
 
     memset(&serv, 0, sizeof(serv));
       break;
 
     memset(&serv, 0, sizeof(serv));
-    if (WordCount(line) != 3) {
+    if (WordCount(line) < 3) {
       fprintf(stderr, "bad line: %s\n", line);
       continue;
     }
       fprintf(stderr, "bad line: %s\n", line);
       continue;
     }
@@ -310,11 +313,19 @@ ReadConfFile(void)
     serv.ss_host = GetWord(line, 0);
     serv.ss_slice = GetWord(line, 1);
 
     serv.ss_host = GetWord(line, 0);
     serv.ss_slice = GetWord(line, 1);
 
-    if (num == 0 && /* the first row must be an entry for apache */
-       (strcmp(serv.ss_host, "*") != 0 ||
-        strcmp(serv.ss_slice, "root") != 0)) {
-      fprintf(stderr, "first row has to be for webserver\n");
-      exit(-1);
+    if (num == 0) {
+      /* the first row must be an entry for apache */
+      if (strcmp(serv.ss_host, "*") != 0 ||
+         strcmp(serv.ss_slice, "root") != 0) {
+       fprintf(stderr, "first row has to be for webserver\n");
+       exit(-1);
+      }
+      /* see if there's PLC netflow's domain name */
+      if (domainNamePLCNetflow != NULL) {
+       xfree(domainNamePLCNetflow);
+       domainNamePLCNetflow = NULL;
+      }
+      domainNamePLCNetflow = GetWord(line, 3);
     }
     if (num >= numAlloc) {
       numAlloc = MAX(numAlloc * 2, 8);
     }
     if (num >= numAlloc) {
       numAlloc = MAX(numAlloc * 2, 8);
@@ -330,6 +341,8 @@ ReadConfFile(void)
 
   fclose(f);
 
 
   fclose(f);
 
+#if 0
+  /* Faiyaz asked me to allow a single-entry codemux conf */
   if (num == 1) {
     if (numServices == 0) {
       fprintf(stderr, "nothing found in codemux.conf\n");
   if (num == 1) {
     if (numServices == 0) {
       fprintf(stderr, "nothing found in codemux.conf\n");
@@ -337,6 +350,11 @@ ReadConfFile(void)
     }
     return;
   }
     }
     return;
   }
+#endif
+  if (num < 1) {
+    fprintf(stderr, "no entry found in codemux.conf\n");
+    exit(-1);
+  }
 
   for (i = 0; i < numServices; i++) {
     xfree(serviceSig[i].ss_host);
 
   for (i = 0; i < numServices; i++) {
     xfree(serviceSig[i].ss_host);
@@ -749,6 +767,25 @@ SocketReadyToRead(int fd)
     //    printf("found service %d\n", whichService);
     slice = ServiceToSlice(whichService);
 
     //    printf("found service %d\n", whichService);
     slice = ServiceToSlice(whichService);
 
+    /* if it needs to be redirected to PLC, let it be handled here */
+    if (whichService == 0 && domainNamePLCNetflow != NULL &&
+       strcmp(slice->si_sliceName, "root") == 0) {
+      char msg[1024];
+      int len;
+      static const char* resp302 = 
+       "HTTP/1.0 302 Found\r\n"
+       "Location: http://%s\r\n"
+       "Cache-Control: no-cache, no-store\r\n"
+       "Content-type: text/html\r\n"
+       "Connection: close\r\n"
+       "\r\n"
+       "Your request is being redirected to PLC Netflow http://%s\n";
+      len = snprintf(msg, sizeof(msg), resp302, 
+                    domainNamePLCNetflow, domainNamePLCNetflow);
+      write(fd, msg, len);
+      CloseSock(fd);
+      return;
+    }
     /* no service can have more than some absolute max number of
        connections. Also, when we're too busy, start enforcing
        fairness across the servers */
     /* no service can have more than some absolute max number of
        connections. Also, when we're too busy, start enforcing
        fairness across the servers */
index 7fab6c3..00b35f6 100644 (file)
@@ -5,6 +5,7 @@
 * root 1080   # this is for the Apache webserver
 coblitz.codeen.org princeton_coblitz 3125
 cdn.rd.tp.pl princeton_coblitz 3125
 * root 1080   # this is for the Apache webserver
 coblitz.codeen.org princeton_coblitz 3125
 cdn.rd.tp.pl princeton_coblitz 3125
+fc.codeen.org princeton_coblitztest 5125
 opendht.nyuld.net ucb_bamboo 5851  # this should come before *.nyuld.net
 nyud.net nyu_d 8080
 nyucd.net nyu_d 8080
 opendht.nyuld.net ucb_bamboo 5851  # this should come before *.nyuld.net
 nyud.net nyu_d 8080
 nyucd.net nyu_d 8080
index bd065a6..e0c4c89 100644 (file)
@@ -1,13 +1,6 @@
-#
-# $Id$
-#
-%define url $URL$
-
 %define name codemux 
 %define version 0.1
 %define name codemux 
 %define version 0.1
-%define taglevel 7
-
-%define release %{taglevel}%{?pldistro:.%{pldistro}}%{?date:.%{date}}
+%define release 8%{?pldistro:.%{pldistro}}%{?date:.%{date}}
 
 Summary: CoDemux - HTTP port DeMux
 Name: %{name} 
 
 Summary: CoDemux - HTTP port DeMux
 Name: %{name} 
@@ -18,9 +11,8 @@ Group: System Environment/Base
 Source: %{name}-%{version}.tar.gz
 Vendor: PlanetLab
 Packager: PlanetLab Central <support@planet-lab.org>
 Source: %{name}-%{version}.tar.gz
 Vendor: PlanetLab
 Packager: PlanetLab Central <support@planet-lab.org>
-Distribution: PlanetLab %{plrelease}
-URL: %(echo %{url} | cut -d ' ' -f 2)
-#URL: http://codeen.cs.princeton.edu/
+Distribution: PlanetLab 3.0
+URL: http://codeen.cs.princeton.edu/
 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 #Requires: vnet
 
 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 #Requires: vnet