among them */
#define FAIRNESS_CUTOFF (MAX_CONNS * 0.85)
-/* codemux version */
-#define CODEMUX_VERSION "0.3"
+/* codemux version, from Makefile, or specfile */
+#define CODEMUX_VERSION RPM_VERSION
typedef struct FlowBuf {
int fb_refs; /* num refs */
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
break;
memset(&serv, 0, sizeof(serv));
- if (WordCount(line) != 3) {
+ if (WordCount(line) < 3) {
fprintf(stderr, "bad line: %s\n", line);
continue;
}
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);
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");
}
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);
FindService(FlowBuf *fb, int *whichService, struct in_addr addr)
{
char *end;
- char *lowerBuf;
+ char lowerBuf[FB_ALLOCSIZE];
char *hostVal;
char *buf = fb->fb_buf;
char orig[256];
int i;
int len;
#endif
-
+
if (strstr(buf, "\n\r\n") == NULL && strstr(buf, "\n\n") == NULL)
return(FAILURE);
fb->fb_used += InsertHeader(buf, fb->fb_used + 1, orig);
/* get just the header, so we can work on it */
- LOCAL_STR_DUP_LOWER(lowerBuf, buf);
+ StrcpyLower(lowerBuf, buf);
if ((end = strstr(lowerBuf, "\n\r\n")) == NULL)
end = strstr(lowerBuf, "\n\n");
*end = '\0';
DoesDotlessSuffixMatch(hostVal, 0, serviceSig[i].ss_host)) {
*whichService = i;
free(hostVal);
- /* printf("%s", buf); */
return(SUCCESS);
}
}
// 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 */
OpenLogFile(void)
{
static const char* logfile = "/var/log/codemux.log";
- static const char* oldlogfile = "/var/log/codemux.log.old";
int logfd;
- /* if the previous log file exists,
- rename it to the oldlogfile */
- if (access(logfile, F_OK) == 0) {
- if (rename(logfile, oldlogfile) < 0) {
- fprintf(stderr, "cannot rotate the logfile err=%s\n",
- strerror(errno));
- exit(-1);
- }
- }
-
logfd = open(logfile, O_WRONLY | O_APPEND | O_CREAT, 0600);
if (logfd < 0) {
fprintf(stderr, "cannot open the logfile err=%s\n",