[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: New/Update: bandwidthd 1.2.0b



>>>>> "TTF" == "Todd T Fries" <todd@openbsd.org>:
TTF> I had someone suggest a diff that didn't quite work on sparc64 for the
TTF> last time I submitted this (1.1.7 at that time).  Comments/feedback/etc
TTF> appreciated.

and just so this gets the benifit of testing by more people here is a patch
for bandwidthd to allow it to work on not just i386 machines.  enjoy.

sent to todd and tested on sparc64 and i386.

-dan

##====================================================================

diff -Nurp bandwidthd.orig/patches/patch-bandwidthd_c bandwidthd/patches/patch-bandwidthd_c
--- bandwidthd.orig/patches/patch-bandwidthd_c	2004-01-27 09:23:07.000000000 -0800
+++ bandwidthd/patches/patch-bandwidthd_c	2004-01-29 15:50:15.000000000 -0800
@@ -1,7 +1,64 @@
 $OpenBSD$
---- bandwidthd.c.orig	2004-01-14 10:20:53.000000000 -0600
-+++ bandwidthd.c	2004-01-27 11:14:52.000000000 -0600
-@@ -625,7 +625,7 @@ int RCDF_Test(char *filename)
+--- bandwidthd.c.orig	2004-01-14 08:20:53.000000000 -0800
++++ bandwidthd.c	2004-01-29 15:50:13.000000000 -0800
+@@ -80,7 +80,7 @@ void bd_CollectingData(char *filename)
+ 		}
+ 	}
+ 
+-void WriteOutWebpages(long int timestamp)
++void WriteOutWebpages(time_t timestamp)
+ 	{
+     struct IPDataStore *DataStore;
+ 	int NumGraphs = 0;
+@@ -186,7 +186,7 @@ int main(int argc, char **argv)
+ 		{
+ 		if ((shmid = shmget(IPCKey, sizeof(struct IPCData)*IP_NUM, 0)) == -1)
+ 			{
+-			printf("Error allocating %d bytes of IPC Shared memory, or attaching to existing segment. Do you have System V IPC turned on in your kernel? Do you have enough? Has a memory segment already been created with my ID that I don't have permisions to?\n", sizeof(struct IPCData)*IP_NUM);
++			printf("Error allocating %d bytes of IPC Shared memory, or attaching to existing segment. Do you have System V IPC turned on in your kernel? Do you have enough? Has a memory segment already been created with my ID that I don't have permisions to?\n", (int)sizeof(struct IPCData)*IP_NUM);
+ 			exit(0);
+ 			}
+ 
+@@ -287,9 +287,8 @@ void PacketCallback(u_char *user, const 
+     u_int caplen = h->caplen;
+     const struct ip *ip;
+ 
+-    uint32_t srcip;
+-    uint32_t dstip;
+-
++    in_addr_t srcip;
++    in_addr_t dstip;
+ 
+     struct IPData *ptrIPData;
+ 
+@@ -399,7 +398,7 @@ inline void Credit(struct Statistics *St
+     }
+ 
+ // TODO:  Throw away old data!
+-void DropOldData(long int timestamp) 	// Go through the ram datastore and dump old data
++void DropOldData(time_t timestamp) 	// Go through the ram datastore and dump old data
+ 	{
+ 	struct IPDataStore *DataStore;
+ 	struct IPDataStore *PrevDataStore;	
+@@ -467,7 +466,7 @@ void StoreIPDataInCDF(struct IPData IncD
+ 		{
+ 		IPData = &IncData[counter];
+ 		HostIp2CharIp(IPData->ip, IPBuffer);
+-		fprintf(cdf, "%s,%lu,", IPBuffer, IPData->timestamp);
++		fprintf(cdf, "%s,%ld,", IPBuffer, IPData->timestamp);
+ 		Stats = &(IPData->Send);
+ 		fprintf(cdf, "%llu,%llu,%llu,%llu,%llu,%llu,%llu,", Stats->total, Stats->icmp, Stats->udp, Stats->tcp, Stats->ftp, Stats->http, Stats->p2p); 
+ 		Stats = &(IPData->Receive);
+@@ -571,7 +570,7 @@ void StoreIPDataInRam(struct IPData IncD
+ 	}
+ 
+ 
+-void CommitData(long int timestamp)
++void CommitData(time_t timestamp)
+     {
+     unsigned int counter;
+ 
+@@ -625,7 +624,7 @@ int RCDF_Test(char *filename)
  	time_t timestamp;
  
  	if (!(cdf = fopen(filename, "r"))) return FALSE;
@@ -10,7 +67,7 @@ $OpenBSD$
  	if (timestamp > time(NULL) - config.range)
  		return FALSE; // Keep looking
  	else
-@@ -656,7 +656,7 @@ void RCDF_PositionStream(FILE *cdf)
+@@ -656,7 +655,7 @@ void RCDF_PositionStream(FILE *cdf)
  			}
  		while (fgetc(cdf) != '\n' && !feof(cdf)); // Read to next line
  		ungetc('\n', cdf);  // Just so the fscanf mask stays identical
@@ -19,7 +76,7 @@ $OpenBSD$
  			{
  			printf("Unknown error while scanning for beginning of data...\n");
  			return;	
-@@ -678,7 +678,7 @@ void RCDF_Load(FILE *cdf)
+@@ -678,7 +677,7 @@ void RCDF_Load(FILE *cdf)
  
      for(Counter = 0; !feof(cdf) && !ferror(cdf); Counter++)
  	    {
@@ -28,3 +85,21 @@ $OpenBSD$
  			goto End_RecoverDataFromCdf;
  
  		if (!timestamp) // First run through loop
+@@ -836,7 +835,7 @@ void RecoverDataFromCDF(void)
+ // ****** FindIp **********
+ // ****** Returns or allocates an Ip's data structure
+ 
+-inline struct IPData *FindIp(uint32_t ipaddr)
++inline struct IPData *FindIp(in_addr_t ipaddr)
+     {
+     unsigned int counter;
+     
+@@ -862,7 +861,7 @@ inline struct IPData *FindIp(uint32_t ip
+ 
+ size_t ICGrandTotalDataPoints = 0;
+ 
+-char inline *HostIp2CharIp(unsigned long ipaddr, char *buffer)
++char inline *HostIp2CharIp(in_addr_t ipaddr, char *buffer)
+     {
+ 	struct in_addr in_addr;
+ 	char *s;
diff -Nurp bandwidthd.orig/patches/patch-bandwidthd_h bandwidthd/patches/patch-bandwidthd_h
--- bandwidthd.orig/patches/patch-bandwidthd_h	1969-12-31 16:00:00.000000000 -0800
+++ bandwidthd/patches/patch-bandwidthd_h	2004-01-29 15:36:08.000000000 -0800
@@ -0,0 +1,86 @@
+$OpenBSD$
+--- bandwidthd.h.orig	2004-01-13 12:03:33.000000000 -0800
++++ bandwidthd.h	2004-01-29 15:35:34.000000000 -0800
+@@ -71,8 +71,8 @@ struct config
+ 
+ struct SubnetData
+     {
+-    uint32_t ip;
+-    uint32_t mask;
++    in_addr_t ip;
++    in_addr_t mask;
+     } SubnetTable[SUBNET_NUM];
+ 
+ struct Statistics
+@@ -91,15 +91,15 @@ struct Statistics
+ struct IPData
+     {
+     char Magick[4];
+-    long int timestamp;
+-    uint32_t ip;	// Host byte order
++    time_t timestamp;
++    in_addr_t ip;	// needs to be stored in network byte order
+     struct Statistics Send;
+     struct Statistics Receive;
+     } IpTable[IP_NUM];
+ 
+ struct IPCData
+ 	{
+-	uint32_t IP;
++	in_addr_t IP;
+ 	int Graph;  // TRUE or FALSE, Did we write out a graph for this ip
+ 	unsigned long long Total;
+ 	unsigned long long TotalSent;
+@@ -114,7 +114,7 @@ struct IPCData
+ 
+ struct IPDataStore
+ 	{
+-	uint32_t ip;	
++	in_addr_t ip;	
+ 	struct DataStoreBlock *FirstBlock;  // This is structure is allocated at the same time, so it always exists.
+ 		
+     struct IPDataStore *Next;
+@@ -123,7 +123,7 @@ struct IPDataStore
+ #define IPDATAALLOCCHUNKS 100
+ struct DataStoreBlock
+ 	{
+-	long int LatestTimestamp;
++	time_t LatestTimestamp;
+ 	int NumEntries;  // Is the index of the first unused entry in IPData
+ 	struct IPData *Data;  // These are allocated at creation, and thus always exist
+ 
+@@ -144,7 +144,7 @@ void            PacketCallback(u_char *u
+ void RecoverDataFromCDF(void);
+ 
+ // ************ This function converts and IP to a char string
+-char inline 	*HostIp2CharIp(unsigned long ipaddr, char *buffer);
++char inline 	*HostIp2CharIp(in_addr_t ipaddr, char *buffer);
+ 
+ // ************ This function converts the numbers for each quad into an IP
+ inline uint32_t IpAddr(unsigned char q1, unsigned char q2, unsigned char q3, unsigned char q4);
+@@ -153,18 +153,18 @@ inline uint32_t IpAddr(unsigned char q1,
+ inline void     Credit(struct Statistics *Stats, const struct ip *ip);
+ 
+ // ************ Finds an IP in our IPTable
+-inline struct IPData *FindIp(uint32_t ipaddr);
++inline struct IPData *FindIp(in_addr_t ipaddr);
+ 
+ // ************ Writes our IPTable to Disk or to the Ram cache
+-void            CommitData(long int timestamp);
++void            CommitData(time_t timestamp);
+ 
+ // ************ Creates our Graphs
+-void            GraphIp(struct IPDataStore *DataStore, struct IPCData *IPCData, long int timestamp);
+-void            PrepareXAxis(gdImagePtr im, long int timestamp);
+-void            PrepareYAxis(gdImagePtr im, long int YMax);
+-long int        GraphData(gdImagePtr im, gdImagePtr im2, struct IPDataStore *DataStore, long int timestamp,  struct IPCData *IPCData);
++void            GraphIp(struct IPDataStore *DataStore, struct IPCData *IPCData, time_t timestamp);
++void            PrepareXAxis(gdImagePtr im, time_t timestamp);
++void            PrepareYAxis(gdImagePtr im, time_t YMax);
++time_t          GraphData(gdImagePtr im, gdImagePtr im2, struct IPDataStore *DataStore, time_t timestamp,  struct IPCData *IPCData);
+ 
+ 
+ // ************ Misc
+-inline void     DstCredit(uint32_t ipaddr, unsigned int psize);
++inline void     DstCredit(in_addr_t ipaddr, unsigned int psize);
+ void			MakeIndexPages(int NumGraphs);
diff -Nurp bandwidthd.orig/patches/patch-graph_c bandwidthd/patches/patch-graph_c
--- bandwidthd.orig/patches/patch-graph_c	1969-12-31 16:00:00.000000000 -0800
+++ bandwidthd/patches/patch-graph_c	2004-01-29 15:30:17.000000000 -0800
@@ -0,0 +1,98 @@
+$OpenBSD$
+--- graph.c.orig	2004-01-14 08:51:16.000000000 -0800
++++ graph.c	2004-01-29 15:27:15.000000000 -0800
+@@ -21,7 +21,7 @@ jmp_buf dnsjump;
+ 
+ static void rdnslngjmp(int signal);
+ 
+-void rdns(char *Buffer, unsigned long IP)  // This takes over sigalarm!
++void rdns(char *Buffer, in_addr_t IP)  // This takes over sigalarm!
+ 	{
+ 	char DNSError[] = "DNS Timeout: Correct to speed up graphing";
+ 	char None[] = "Configure DNS to reverse this IP";
+@@ -30,7 +30,6 @@ void rdns(char *Buffer, unsigned long IP
+ 	char chrIP[50];
+ 	static int Init = TRUE;
+ 	static int DNSTimeouts = 0;  // This is reset for each run because we're forked
+-	unsigned long addr = htonl(IP);
+ 
+     _res.retrans = 1;
+     _res.retry = 2;
+@@ -52,7 +51,7 @@ void rdns(char *Buffer, unsigned long IP
+ 	if (setjmp(dnsjump) == 0)
+ 		{
+ 		alarm(10);  // Don't let gethostbyaddr hold us up too long
+-		hostent = gethostbyaddr((char *) &addr, 4, AF_INET); // (char *)&Data->IP				
++		hostent = gethostbyaddr((char *) &IP, sizeof(in_addr_t), AF_INET); // (char *)&Data->IP				
+ 		alarm(0);
+ 		
+ 		if (hostent)
+@@ -245,7 +244,7 @@ void MakeIndexPages(int NumIps)
+ 		default: PeriodDesc = ""; break;
+ 		}
+ 	
+-	fprintf(file, "<HTML><HEAD>\n<META HTTP-EQUIV=\"REFRESH\" content=\"150\">\n<META HTTP-EQUIV=\"EXPIRES\" content=\"-1\">\n");
++	fprintf(file, "<HTML><HEAD>\n<META HTTP-EQUIV=\"REFRESH\" content=\"%ld\">\n<META HTTP-EQUIV=\"EXPIRES\" content=\"-1\">\n", (config.skip_intervals * INTERVAL1));
+ 	fprintf(file, "<META HTTP-EQUIV=\"PRAGMA\" content=\"no-cache\">\n");
+ 	fprintf(file, "</HEAD><BODY vlink=blue>\n%s<br>\n<center><img src=\"logo.gif\"><BR>\n", ctime(&WriteTime));
+ 	fprintf(file, "<BR>\n - <a href=index.html>Daily</a> -- <a href=index2.html>Weekly</a> -- ");
+@@ -359,16 +358,16 @@ void MakeIndexPages(int NumIps)
+ 	free(IPCData);
+ 	}
+ 
+-void GraphIp(struct IPDataStore *DataStore, struct IPCData *IPCData, long int timestamp)
++void GraphIp(struct IPDataStore *DataStore, struct IPCData *IPCData, time_t timestamp)
+     {
+     FILE *OutputFile;
+     char outputfilename[50];
+     gdImagePtr im, im2;
+     int white;
+-    long int YMax;
++    time_t YMax;
+ 	char CharIp[20];
+ 
+-    long int GraphBeginTime;
++    time_t GraphBeginTime;
+ 
+ 	// TODO: First determine if graph will be printed before creating image and drawing backround, etc
+ 
+@@ -421,9 +420,9 @@ void GraphIp(struct IPDataStore *DataSto
+     }
+ 
+ // Returns YMax
+-long int GraphData(gdImagePtr im, gdImagePtr im2, struct IPDataStore *DataStore, long int timestamp, struct IPCData *IPCData)
++time_t GraphData(gdImagePtr im, gdImagePtr im2, struct IPDataStore *DataStore, time_t timestamp, struct IPCData *IPCData)
+     {
+-    long int YMax=0;
++    time_t YMax=0;
+ 	
+ 	struct DataStoreBlock *CurrentBlock;
+     struct IPData *Data;
+@@ -705,7 +704,7 @@ long int GraphData(gdImagePtr im, gdImag
+     return(YMax);
+     }
+ 
+-void PrepareYAxis(gdImagePtr im, long int YMax)
++void PrepareYAxis(gdImagePtr im, time_t YMax)
+     {
+     char buffer[20];
+ 
+@@ -753,14 +752,14 @@ void PrepareYAxis(gdImagePtr im, long in
+         }
+     } 
+ 
+-void PrepareXAxis(gdImagePtr im, long int timestamp)
++void PrepareXAxis(gdImagePtr im, time_t timestamp)
+     {
+     char buffer[100];
+     int black, red;
+-    long int sample_begin, sample_end;    
++    time_t sample_begin, sample_end;    
+     struct tm *timestruct;
+-    long int MarkTime;
+-	long int MarkTimeStep;
++    time_t MarkTime;
++    time_t MarkTimeStep;
+     double x;
+     
+     sample_begin=timestamp-config.range;