-
Notifications
You must be signed in to change notification settings - Fork 12
/
BD.diff
1887 lines (1887 loc) · 51 KB
/
BD.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Only in .: .svn
Only in .: BD.diff
diff -r /home/perkins/Source/wrk/bandwidthd/CHANGELOG ./CHANGELOG
0a1,24
> 2.0.2.IPv6
>
> Added support for mac addresses in sqlite.
> Renamed sqlight.c to sqlite.c
>
> Added second param to IPTableTransform.main for the name of the sensor in use.
> Included sample IPTableTransform.py that outputs to a mysql DB
> Changed name of python module from LookupMac to IPTableTransform
> Fixed bug in pgsql.c where it was passing the mac address to HostIp2CharIp instead of the IP address (pgsql.c)
> Fixed bug in pgsql.c where it was passing the wrong number of parameters to PQexecParams (pgsql.c)
> Added support for excluding subnets. (conf.l conf.y)
> Added mac record support for pgsql. (pgsql.c)
>
> Cleaned up whitespace (bandwidthd.c)
> Moved global variables from top of bandwidthd.c to bandwidthd.h
> (help avoid namespace collisions if someone only looks in the header file)
> Added struct for vlan headers (bandwidthd.h)
> Added configure option for turning pgsql off (configure.in)
> Added functions for ignoring subnets (bandwidthd.c)
> Added configure option for embedding python for scripting and to optimize ip lookups (bandwidthd.c bandwidthd.h configure.in)
>
>
> 2.0.1
>
diff -r /home/perkins/Source/wrk/bandwidthd/INSTALL.Unix ./INSTALL.Unix
15a16,17
> autoconf && autoheader
>
Only in .: IPTableTransform.py
diff -r /home/perkins/Source/wrk/bandwidthd/Makefile.in ./Makefile.in
10c10
< OBS= bandwidthd.o graph.o conf.tab.o conf.l.o pgsql.o sqlight.o extensions.o
---
> OBS= bandwidthd.o graph.o conf.tab.o conf.l.o pgsql.o sqlite.o extensions.o
diff -r /home/perkins/Source/wrk/bandwidthd/README ./README
0a1,8
> Copyright Logan Perkins 2012 <[email protected]>
>
> Parts copyright David Hinkle.
>
> Based off of bandwidthd, by David Hinkle. Special thanks to the bandwidthd
> team of developers. The original readme file follows below, as the changes
> thus far have been minor. For the complete changes since the fork, see BD.diff
>
diff -r /home/perkins/Source/wrk/bandwidthd/TODO ./TODO
0a1,7
> Add struct for storing IPv6 information
> Make IP information use a linked list
> Add mac record support to sqlite and cdf
> Add support for multiple sensors using the python DBAPI
>
> OLD PROJECT TODO (will still get done)
>
16a24,26
>
>
>
diff -r /home/perkins/Source/wrk/bandwidthd/aclocal.m4 ./aclocal.m4
8a9,11
>
>
>
diff -r /home/perkins/Source/wrk/bandwidthd/bandwidthd.c ./bandwidthd.c
16,21d15
< // ****************************************************************************************
< // ** Global Variables
< // ****************************************************************************************
<
< #define SNAPLEN 100
<
23d16
<
26a20
> unsigned int NotSubnetCount = 0;
33d26
<
34a28
> struct SubnetData NotSubnetTable[SUBNET_NUM];
35a30,34
> size_t ICGrandTotalDataPoints = 0;
>
> #ifdef HAVE_PYTHON
> PyObject *IpTableDict;
> #endif
39d37
<
41a40
> void BroadcastState(int fd);
43d41
<
45c43
<
---
> struct Broadcast *Broadcasts = NULL;
47d44
<
50a48
>
61d58
<
72d68
<
89d84
<
94d88
<
102d95
<
130d122
<
134d125
<
137d127
<
149d138
<
151d139
<
154d141
<
157d143
<
168d153
<
170d154
<
174d157
<
179d161
<
188,189c170,171
<
< switch (level) {
---
> switch (level)
> {
195c177
< break;
---
> break;
203c185
< break;
---
> break;
211c193
< break;
---
> break;
219,220c201
< break;
<
---
> break;
230d210
<
241c221
< fclose(pidfile);
---
> fclose(pidfile);
281d260
<
284d262
<
286d263
<
290d266
<
319d294
<
323c298
< config.filter = "ip";
---
> config.filter = "ip or ether proto 1537";
338d312
<
340d313
<
365d337
<
374d345
<
382c353,358
<
---
> for (Counter = 0; Counter < NotSubnetCount; Counter++)
> {
> addr.s_addr = ntohl(NotSubnetTable[Counter].ip);
> addr2.s_addr = ntohl(NotSubnetTable[Counter].mask);
> syslog(LOG_INFO, "Ignoring subnet %s with netmask %s", inet_ntoa(addr), inet_ntoa(addr2));
> }
402,403c378
< #endif
<
---
> #endif
406d380
<
411d384
<
413d385
<
415d386
<
422d392
<
426d395
<
432d400
<
441d408
<
444d410
<
447d412
<
449,450c414
<
< syslog(LOG_INFO, "Opening %s", config.dev);
---
> syslog(LOG_INFO, "Opening %s", config.dev);
457d420
<
465d427
<
468d429
<
480c441
< break;
---
> break;
502d462
<
504c464
< {
---
> {
509d468
<
515c474,478
<
---
> #ifdef HAVE_PYTHON
> Py_Initialize();
> IpTableDict=PyDict_New();
> Py_Finalize();
> #endif
524c487,491
< if (IntervalFinished) // Then write out this intervals data and possibly kick off the grapher
---
> if (IntervalFinished){ // Then write out this intervals data and possibly kick off the grapher
> #ifdef HAVE_PYTHON
> PyDict_Clear(IpTableDict);
> Py_Finalize();
> #endif
526c493
<
---
> }
534d500
<
536c502
< exit(0);
---
> exit(0);
542d507
<
548d512
<
553c517
< ProgramStart = current_time;
---
> ProgramStart = current_time;
555d518
<
557a521
> BroadcastState(pcap_fileno(pd));
564a529,597
> // Write an ethernet packet describing us out the given socket
> void BroadcastState(int fd)
> {
> char buf[SNAPLEN];
> char enet_broadcast[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
> struct ether_header *eptr;
> if (DataLink != DLT_EN10MB)
> return;
> if ((14+strlen(config.sensor_name)+strlen(config.dev)) > SNAPLEN)
> {
> syslog(LOG_ERR, "Sensor and device name too long for broadcast");
> return;
> }
> bzero(buf, sizeof(buf));
> eptr = (struct ether_header *) buf; /* start of 16-byte Ethernet header */
> // Always broadcast
> memcpy(&buf[0], enet_broadcast, 6);
> memcpy(&buf[6], enet_broadcast, 6); // Would rather use our own mac address
> eptr->ether_type = htons(1537); // Random packet type we'll use for bandwidthd
> memcpy(buf+14, config.sensor_name, strlen(config.sensor_name)+1);
> memcpy(buf+14+strlen(config.sensor_name)+1, config.dev, strlen(config.dev)+1);
> if (write(fd, buf, SNAPLEN) != SNAPLEN)
> syslog(LOG_ERR, "Write error during bandwidthd broadcast");
> }
>
> void ParseBroadcast(const u_char *in)
> {
> char *p = (char *)in+14; // Skip ethernet header
> struct Broadcast *bc;
> struct Broadcast *bc2;
> char *sensor_name;
> char *interface;
> sensor_name = p;
> interface = p+strlen(p)+1;
> // Sanity check
> if (strlen(sensor_name) > SNAPLEN || strlen(interface) > SNAPLEN)
> {
> syslog(LOG_ERR, "Bandwidthd broadcast packet failed sanity check, discarding");
> return;
> }
> if ((!strcmp(sensor_name, config.sensor_name)) && (!strcmp(interface, config.dev)))
> return; // Our own packet
> for (bc = Broadcasts; bc; bc = bc->next)
> {
> if ((!strcmp(sensor_name, bc->sensor_name)) && (!strcmp(interface, bc->interface)))
> {
> // Found this link
> bc->received = time(NULL);
> return;
> }
> }
> bc2 = malloc(sizeof(struct Broadcast));
> bc2->sensor_name = strdup(sensor_name);
> bc2->interface = strdup(interface);
> bc2->received = time(NULL);
> bc2->next = NULL;
> if (Broadcasts == NULL)
> {
> Broadcasts = bc2;
> return;
> }
> else
> {
> for (bc = Broadcasts; bc->next; bc = bc->next);
> bc->next = bc2;
> return;
> }
> }
>
568c601,602
<
---
> unsigned short SkipSrc = 0;
> unsigned short SkipDst = 0;
570a605
> struct VlanHeader *vlanhdr;
572d606
<
575d608
<
577d609
<
580d611
<
582c613,617
<
---
> vlanhdr = (struct vlanhdr *) p;
> if (eptr->ether_type == htons(1537))
> ParseBroadcast(p);
> if (vlanhdr->ether_type[0]==0x81 && vlanhdr->ether_type[1]==0x00) //Two byte-wise checks instead of 1 word-wise check to avoid word boundary issues on some intel processors
> p+=4;
585d619
<
587d620
<
590d622
<
593c625,635
<
---
> for (Counter = 0; Counter < NotSubnetCount; Counter++)
> {
> if (NotSubnetTable[Counter].ip == (srcip & NotSubnetTable[Counter].mask)) //In the list of subnets we're ignoring.
> {
> SkipSrc=1;
> }
> if (NotSubnetTable[Counter].ip == (dstip & NotSubnetTable[Counter].mask)) //In the list of subnets we're ignoring.
> {
> SkipDst=1;
> }
> }
595c637
< {
---
> {
598d639
<
601c642
< if (SubnetTable[Counter].ip == (srcip & SubnetTable[Counter].mask))
---
> if ((SubnetTable[Counter].ip == (srcip & SubnetTable[Counter].mask)) && !SkipSrc)
608d648
<
613,614c653
<
< if (SubnetTable[Counter].ip == (dstip & SubnetTable[Counter].mask))
---
> if ((SubnetTable[Counter].ip == (dstip & SubnetTable[Counter].mask)) && !SkipDst)
621d659
<
625c663
< }
---
> }
630d667
<
638d674
<
641d676
<
650d684
<
659d692
<
675d707
<
680a713,755
> void IgnoreMonitorSubnet(unsigned int ip, unsigned int mask)
> {
> unsigned int subnet = ip & mask;
> int Counter, Counter2;
> struct in_addr addr, addr2;
> addr.s_addr = ntohl(subnet);
> addr2.s_addr = ntohl(mask);
> for (Counter = 0; Counter < NotSubnetCount; Counter++)
> {
> if ((NotSubnetTable[Counter].ip == subnet) && (NotSubnetTable[Counter].mask == mask))
> {
> syslog(LOG_ERR, "Subnet %s/%s already exists, skipping.", inet_ntoa(addr), inet_ntoa(addr2));
> return;
> }
> }
> for (Counter = 0; Counter < NotSubnetCount; Counter++)
> {
> if ((NotSubnetTable[Counter].ip == (ip & NotSubnetTable[Counter].mask)) && (NotSubnetTable[Counter].mask < mask))
> {
> syslog(LOG_ERR, "Subnet %s/%s is already excluded, skipping.", inet_ntoa(addr), inet_ntoa(addr2));
> return;
> }
> }
> for (Counter = 0; Counter < NotSubnetCount; Counter++)
> {
> if (((NotSubnetTable[Counter].ip & mask) == subnet) && (NotSubnetTable[Counter].mask > mask))
> {
> syslog(LOG_ERR, "Subnet %s/%s includes already excluded subnet, removing smaller entry", inet_ntoa(addr), inet_ntoa(addr2));
> // Shift everything down
> for (Counter2 = Counter; Counter2 < NotSubnetCount-1; Counter2++)
> {
> NotSubnetTable[Counter2].ip = NotSubnetTable[Counter2+1].ip;
> NotSubnetTable[Counter2].mask = NotSubnetTable[Counter2+1].mask;
> }
> NotSubnetCount--;
> Counter--; // Retest this entry because we replaced it
> }
> }
> NotSubnetTable[NotSubnetCount].mask = mask;
> NotSubnetTable[NotSubnetCount].ip = subnet;
> NotSubnetCount++;
> }
>
687d761
<
689d762
<
692d764
<
699d770
<
718c789
< return;
---
> return;
737c808
< case 28864: // hotComm
---
> case 28864: // hotComm
740c811
< return;
---
> return;
757c828
< struct IPDataStore *PrevDataStore;
---
> struct IPDataStore *PrevDataStore;
759d829
<
762d831
<
776c845
< free(DataStore);
---
> free(DataStore);
779c848
< }
---
> }
794,795c863
<
< PrevDataStore = DataStore;
---
> PrevDataStore = DataStore;
805c873
< sqliteStoreIPData(IncData, extension_data);
---
> sqliteStoreIPData(IncData, extension_data);
816d883
<
818d884
<
820d885
<
829c894
< fprintf(cdf, "%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu\n", Stats->total, Stats->icmp, Stats->udp, Stats->tcp, Stats->ftp, Stats->http, Stats->mail, Stats->p2p);
---
> fprintf(cdf, "%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu\n", Stats->total, Stats->icmp, Stats->udp, Stats->tcp, Stats->ftp, Stats->http, Stats->mail, Stats->p2p);
838d902
<
843d906
<
846d908
<
850d911
<
853c914
< IPDataStore->FirstBlock->Next = NULL;
---
> IPDataStore->FirstBlock->Next = NULL;
860d920
<
862d921
<
869d927
<
888d945
<
891,892c948
< }
<
---
> }
901d956
<
904d958
<
910c964
< DataStore->Next->FirstBlock->Next = NULL;
---
> DataStore->Next->FirstBlock->Next = NULL;
912,913c966
<
< DataStore = DataStore->Next;
---
> DataStore = DataStore->Next;
921d973
<
935,936d986
<
<
940d989
<
946c995,1001
<
---
> #ifdef HAVE_PYTHON
> //Run python plugin script on IpTable
> Py_Initialize();
> initbandwidthd();
> iptable_Transform(IpCount);
> Py_Finalize();
> #endif
951d1005
<
957d1010
<
962d1014
<
965d1016
<
969c1020
< logname2[offset] = '4';
---
> logname2[offset] = '4';
973c1024
< logname2[offset] = '3';
---
> logname2[offset] = '3';
977c1028
< logname2[offset] = '2';
---
> logname2[offset] = '2';
981c1032
< logname2[offset] = '1';
---
> logname2[offset] = '1';
988d1038
<
992d1041
<
995,996c1044
< MayGraph = TRUE;
<
---
> MayGraph = TRUE;
1001d1048
<
1004d1050
<
1016d1061
<
1043d1087
<
1045d1088
<
1062c1105
< return;
---
> return;
1075a1119,1121
> #ifdef HAVE_PYTHON
> Py_Initialize();
> #endif
1087d1132
<
1092d1136
<
1095d1138
<
1102c1145
< }
---
> }
1106d1148
<
1113c1155
< goto End_RecoverDataFromCdf;
---
> goto End_RecoverDataFromCdf;
1115d1156
<
1134d1174
<
1136d1175
<
1143d1181
<
1168c1206
<
---
> #ifndef HAVE_PYTHON
1172c1210,1224
<
---
> #else
> PyObject *oIP;
> PyObject *oCounter;
> oIP=PyInt_FromLong(ipaddr);
> Counter=PyDict_Contains(IpTableDict, oIP);
> if (Counter==-1){
> printf("PyDict_Contains had an error.\n");
> abort();
> }
> if (Counter){
> Counter=PyInt_AsLong(PyDict_GetItem(IpTableDict, oIP));
> Py_DECREF(oIP);
> return &IpTable[Counter];
> }
> #endif
1183c1235
<
---
> #ifndef HAVE_PYTHON
1185a1238,1245
> #else
> oCounter=PyInt_FromLong(IpCount);
> IpTable[IpCount].ip = ipaddr;
> PyDict_SetItem(IpTableDict, oIP, oCounter);
> Py_DECREF(oCounter);
> Py_DECREF(oIP);
> return (&IpTable[IpCount++]);
> #endif
1188,1189d1247
< size_t ICGrandTotalDataPoints = 0;
<
1194d1251
<
1201d1257
<
1211d1266
<
1225d1279
<
1228d1281
<
1231a1285,1321
> #ifdef HAVE_PYTHON
> void iptable_Transform(uint32_t Counter)
> {
> PyObject *pName, *pModule, *pFunc;
> PyObject *pArgs, *pValue;
> pName = PyString_FromString("IPTableTransform");
> PyRun_SimpleString("import sys\nsys.path.append('.')\n");
> pModule = PyImport_Import(pName);
> Py_DECREF(pName);
> if (pModule != NULL)
> {
> pFunc = PyObject_GetAttrString(pModule, "main");
> if (pFunc && PyCallable_Check(pFunc))
> {
> pArgs= PyTuple_New(2);
> PyTuple_SetItem(pArgs, 0, PyLong_FromUnsignedLong(Counter));
> PyTuple_SetItem(pArgs, 1, PyString_FromString(config.sensor_name));
> pValue = PyObject_CallObject(pFunc, pArgs);
> Py_DECREF(pArgs);
> if (pValue != NULL)
> {
> printf("Result of call: %s\n", PyString_AsString(pValue));
> Py_DECREF(pValue);
> }
> else
> {
> Py_DECREF(pFunc);
> Py_DECREF(pModule);
> PyErr_Print();
> fprintf(stderr,"Call failed\n");
> Py_Finalize();
> return;
> }
> }
> }
> return;
> }
1232a1323,1394
> static PyObject *bandwidthd_get_entry_as_dict(PyObject *self, PyObject* args)
> {
> uint32_t iCounter;
> struct IPData ip_entry;
> if (!PyArg_ParseTuple(args, "k", &iCounter))
> return NULL;
> ip_entry=IpTable[iCounter];
> return Py_BuildValue("{s:k,s:s,s:l,s:{s:K,s:K,s:K,s:K,s:K,s:K,s:K,s:K,s:K},s:{s:K,s:K,s:K,s:K,s:K,s:K,s:K,s:K,s:K}}",
> "ip" , ip_entry.ip,
> "mac" , ip_entry.mac,
> "timestamp" , ip_entry.timestamp,
> "send" ,
> "total" , ip_entry.Send.total,
> "tcp" , ip_entry.Send.tcp,
> "udp" , ip_entry.Send.udp,
> "p2p" , ip_entry.Send.p2p,
> "mail" , ip_entry.Send.mail,
> "icmp" , ip_entry.Send.icmp,
> "http" , ip_entry.Send.http,
> "ftp" , ip_entry.Send.ftp,
> "packets" , ip_entry.Send.packet_count,
> "receive" ,
> "total" , ip_entry.Receive.total,
> "tcp" , ip_entry.Receive.tcp,
> "udp" , ip_entry.Receive.udp,
> "p2p" , ip_entry.Receive.p2p,
> "mail" , ip_entry.Receive.mail,
> "icmp" , ip_entry.Receive.icmp,
> "http" , ip_entry.Receive.http,
> "ftp" , ip_entry.Receive.ftp,
> "packets" , ip_entry.Receive.packet_count
> );
> }
> static PyObject *bandwidthd_set_entry_by_dict(PyObject *self, PyObject* args)
> {
> #if 0
> uint32_t iCounter;
> int *len;
> char *mac;
> struct IPData ip_entry;
> if (!PyArg_ParseTuple(args,
> "k(ks#lKKKKKKKKKKKKKKKKKK)", &iCounter, &ip_entry.ip, &mac,&len, &ip_entry.timestamp, &ip_entry.Send.total, &ip_entry.Send.tcp, &ip_entry.Send.udp, &ip_entry.Send.p2p, &ip_entry.Send.mail, &ip_entry.Send.icmp, &ip_entry.Send.http, &ip_entry.Send.ftp, &ip_entry.Send.packet_count, &ip_entry.Receive.total, &ip_entry.Receive.tcp, &ip_entry.Receive.udp, &ip_entry.Receive.p2p, &ip_entry.Receive.mail, &ip_entry.Receive.icmp, &ip_entry.Receive.http, &ip_entry.Receive.ftp, &ip_entry.Receive.packet_count))
> return NULL;
> strncpy(IpTable[iCounter].mac[0], mac, 17);
> IpTable[iCounter].mac[0][17] = '\0';
> printf("ip: %i\nnew_ip: %i\n", IpTable[iCounter].ip,ip_entry.ip);
> return Py_BuildValue("s",IpTable[iCounter].mac[0]);
> #else
> uint32_t iCounter;
> int *len;
> char *mac;
> if (!PyArg_ParseTuple(args, "ks#", &iCounter, &mac,&len))
> return NULL;
> strncpy(IpTable[iCounter].mac[0], mac, 17);
> IpTable[iCounter].mac[0][17] = '\0';
> return Py_BuildValue("s",IpTable[iCounter].mac[0]);
> #endif
> }
>
>
> static PyMethodDef bandwidthd_methods[] = {
> {"get_entry", bandwidthd_get_entry_as_dict, METH_VARARGS, "Return dictionary of IpTable entry for the given ip and timestamp."},
> {"set_entry", bandwidthd_set_entry_by_dict, METH_VARARGS, "Set dictionary of IpTable entry for the given ip and timestamp."},
> {NULL, NULL} /* sentinel */
> };
>
> void initbandwidthd(void)
> {
> PyImport_AddModule("bandwidthd");
> Py_InitModule("bandwidthd", bandwidthd_methods);
> }
> #endif //HAVE_PYTHON
diff -r /home/perkins/Source/wrk/bandwidthd/bandwidthd.h ./bandwidthd.h
4a5,8
> #ifdef HAVE_PYTHON
> #include <Python.h>
> #endif
>
71c75
< #define IP_NUM 10000 // TODO: Do this dynamicly to save ram and/or scale bigger
---
> #define IP_NUM 256*256 // TODO: Do this dynamicly to save ram and/or scale bigger
156a161
> char *mac[1][20];
174c179
< unsigned long long MAIL;
---
> unsigned long long MAIL;
180c185
< uint32_t ip;
---
> uint32_t ip;
195a201,219
> struct Broadcast
> {
> char *sensor_name;
> char *interface;
> time_t received;
>
> struct Broadcast *next;
> };
>
> // Vlan header
>
> struct VlanHeader
> {
> u_int8_t ether_dhost[6]; /* destination eth addr */
> u_int8_t ether_shost[6]; /* source ether addr */
> u_int8_t ether_type[2]; /* packet type ID field */
> u_int8_t vlan_tag[2]; /* vlan tag information */
> } __attribute__ ((__packed__));
>
217a242
>
253a279,322
> // ************ Python
> #ifdef HAVE_PYTHON
> void iptable_Transform(uint32_t Counter);
> void initbandwidthd(void);
> #endif
>
>
> // ** Global Variables
>
> #define SNAPLEN 100
>
> /*
> static pcap_t *pd;
> unsigned int GraphIntervalCount = 0;
> unsigned int IpCount = 0;
> unsigned int SubnetCount = 0;
> unsigned int NotSubnetCount = 0;
> int IntervalFinished = FALSE;
> time_t IntervalStart;
> time_t ProgramStart;
> int RotateLogs = FALSE;
> int PacketCallbackLock = 0;
> pid_t pidGraphingChild = 0;
> struct SubnetData SubnetTable[SUBNET_NUM];
> struct SubnetData NotSubnetTable[SUBNET_NUM];
> struct IPData IpTable[IP_NUM];
> size_t ICGrandTotalDataPoints = 0;
>
> #ifdef HAVE_PYTHON
> PyObject *IpTableDict;
> #endif
>
> int DataLink;
> int IP_Offset;
> struct IPDataStore *IPDataStore = NULL;
> extern int bdconfig_parse(void);
> void BroadcastState(int fd);
> extern FILE *bdconfig_in;
> struct config config;
> struct Broadcast *Broadcasts = NULL;
> pid_t workerchildpids[NR_WORKER_CHILDS];
> void ResetTrafficCounters(void);
> void CloseInterval(void);
> */
diff -r /home/perkins/Source/wrk/bandwidthd/conf.l ./conf.l
10,12c10,12
< [ \t]+ /* Ignore */;
< \n { return TOKNEWLINE; }
< #.*\n { return TOKNEWLINE; }
---
> [ \t]+ /* Ignore */;
> \n { return TOKNEWLINE; }
> #.*\n { return TOKNEWLINE; }
14,16c14,16
< [-0-9]+ { bdconfig_lval.number=atoi(yytext); return NUMBER; }
< \".*\" { bdconfig_lval.string=strdup(yytext); return STRING; }
< \/ { return TOKSLASH; }
---
> [-0-9]+ { bdconfig_lval.number=atoi(yytext); return NUMBER; }
> \".*\" { bdconfig_lval.string=strdup(yytext); return STRING; }
> \/ { return TOKSLASH; }
18,36c18,37
< subnet { return TOKSUBNET; }
< dev { return TOKDEV; }
< skip_intervals { return TOKSKIPINTERVALS; }
< graph_cutoff { return TOKGRAPHCUTOFF; }
< promiscuous { return TOKPROMISC; }
< output_cdf { return TOKOUTPUTCDF; }
< recover_cdf { return TOKRECOVERCDF; }
< graph { return TOKGRAPH; }
< filter { return TOKFILTER; }
< meta_refresh { return TOKMETAREFRESH; }
< pgsql_connect_string { return TOKPGSQLCONNECTSTRING; }
< sqlite_filename { return TOKSQLITEFILENAME; }
< sensor_id { return TOKSENSORID; }
< htdocs_dir { return TOKHTDOCSDIR; }
< log_dir { return TOKLOGDIR; }
< description { return TOKDESCRIPTION; }
< management_url { return TOKMANAGEMENTURL; }
< extensions { return TOKEXTENSIONS; }
< . { return TOKJUNK; }
---
> subnet { return TOKSUBNET; }
> notsubnet { return TOKNOTSUBNET; }
> dev { return TOKDEV; }
> skip_intervals { return TOKSKIPINTERVALS; }
> graph_cutoff { return TOKGRAPHCUTOFF; }
> promiscuous { return TOKPROMISC; }
> output_cdf { return TOKOUTPUTCDF; }
> recover_cdf { return TOKRECOVERCDF; }
> graph { return TOKGRAPH; }
> filter { return TOKFILTER; }
> meta_refresh { return TOKMETAREFRESH; }
> pgsql_connect_string { return TOKPGSQLCONNECTSTRING; }
> sqlite_filename { return TOKSQLITEFILENAME; }
> sensor_id { return TOKSENSORID; }
> htdocs_dir { return TOKHTDOCSDIR; }
> log_dir { return TOKLOGDIR; }
> description { return TOKDESCRIPTION; }
> management_url { return TOKMANAGEMENTURL; }
> extensions { return TOKEXTENSIONS; }
> . { return TOKJUNK; }
diff -r /home/perkins/Source/wrk/bandwidthd/conf.y ./conf.y
14a15
> extern unsigned int NotSubnetCount;
15a17
> extern struct SubnetData NotSubnetTable[];
23,25c25,27
< fprintf(stderr, "Syntax Error \"%s\" on line %d\n", str, LineNo);
< syslog(LOG_ERR, "Syntax Error \"%s\" on line %d", str, LineNo);
< exit(1);
---
> fprintf(stderr, "Syntax Error \"%s\" on line %d in bandwidthd.conf\n", str, LineNo);
> syslog(LOG_ERR, "Syntax Error \"%s\" on line %d in bandwidthd.conf", str, LineNo);
> exit(1);
29,31c31,33
< {
< return(1);
< }
---
> {
> return(1);
> }
34c36
< %token TOKJUNK TOKSUBNET TOKDEV TOKSLASH TOKSKIPINTERVALS TOKGRAPHCUTOFF TOKDESCRIPTION
---
> %token TOKJUNK TOKSUBNET TOKNOTSUBNET TOKDEV TOKSLASH TOKSKIPINTERVALS TOKGRAPHCUTOFF TOKDESCRIPTION
56,93c58,97
< subnet
< |
< device
< |
< skip_intervals
< |
< graph_cutoff
< |
< promisc
< |
< extensions
< |
< output_cdf