192
void knetfilter::delshaperRules() {
193
QString shapermark, shaperglobalband, shaperrateband, shaperqdischandle, shaperrootclassid, shaperrootclassweight, shaperrootclassprio, shapersubclassid, shapersubclassweight, shapersubclassprio, shaperinterface, shaperrootclassparent;
195
char shaperinterfaceChoice2[5];
196
strcpy (shaperinterfaceChoice2, shaperinterfaceChoice );
197
shaperinterfaceChoicedmp = strcat ( shaperinterfaceChoice2, shaperinterfacenrChoicedmp);
198
shaperinterface.sprintf(shaperinterfaceChoicedmp);
200
shapermark.sprintf((const char *)(shaperMark->text()));
201
shaperglobalband.sprintf((const char *)(shaperglobalBand->text()));
202
shaperrateband.sprintf((const char *)(shaperrateBand->text()));
203
shaperqdischandle.sprintf((const char *)(shaperqdiscHandle->text()));
204
shaperrootclassid.sprintf((const char *)(shaperrootclassId->text()));
205
shaperrootclassweight.sprintf((const char *)(shaperrootclassWeight->text()));
206
shaperrootclassprio.sprintf((const char *)(shaperrootclassPrio->text()));
207
shapersubclassid.sprintf((const char *)(shapersubclassId->text()));
208
shapersubclassweight.sprintf((const char *)(shapersubclassWeight->text()));
209
shapersubclassprio.sprintf((const char *)(shapersubclassPrio->text()));
211
delshaperqdisc.clearArguments();
212
delshaperrootclass.clearArguments();
213
delshapersubclass.clearArguments();
214
delshaperfilter.clearArguments();
216
if ( qdisc_exec == 0 && class_exec == 0 && subclass_exec == 0)
218
QMessageBox::critical(0, "Error",
219
"You have to say which action you want to perform! \n Remember to remove subclasses at first, then the root class \n and at the end the qdisc!\n");
221
else if(shaperglobalband.length()==0)
223
QMessageBox::critical(0, "Error",
224
"You have to supply global bandwidht on net device \n e.g. 100Mbit! \n");
228
char *shaperrootclassParent;
229
char shaperrootclassParent2[5];
231
strcpy (shaperrootclassParent2, (const char *)(shaperqdiscHandle->text()) );
232
shaperrootclassParent = strcat ( shaperrootclassParent2, "0");
233
shaperrootclassparent.sprintf(shaperrootclassParent);
237
if ( subclass_exec == 1 )
239
if(shaperrateband.length()==0)
241
QMessageBox::critical(0, "Error",
242
"You have to supply the amount on bandwidth on net device \n you want to reser for XX marked packets \n e.g. 600Kbit! \n");
244
else if (shaperqdischandle.length()==0)
246
QMessageBox::critical(0, "Error",
247
"You have to supply the qdisc handle! \n e.g. 1! \n So knetfilter can establish the filter parent. \n");
249
else if(shapermark.length()==0)
251
QMessageBox::critical(0, "Error",
252
"You have to supply the mark that the traffic shaper \n should use to count the packet for a reserved rate. \n e.g. 0x03! \n");
254
else if (shaperrootclassid.length()==0)
256
QMessageBox::critical(0, "Error",
257
"You have to supply the root class ID! \n so knetfilter can establish to which parent the rule \n has to be conencted\n e.g. 1:10! \n");
259
else if (shapersubclassid.length()==0)
261
QMessageBox::critical(0, "Error",
262
"You have to supply the subclass ID!\n e.g 1:11! \n");
265
else if (shapersubclassweight.length()==0)
267
QMessageBox::critical(0, "Error",
268
"You have to supply the subclass data flow weight! :)\n e.g. 600Kbit! \n");
270
else if (shapersubclassprio.length()==0)
272
QMessageBox::critical(0, "Error",
273
"you have to supply the sub class priority!\n e.g. 5! \n");
277
delshapersubclass << "tc" << "class" << "del" << "dev" << shaperinterface << "parent" << shaperrootclassid << "classid" << shapersubclassid << "cbq" << "bandwidth" << shaperglobalband << "rate" << shaperrateband << "allot" << "1514" << "weight" << shapersubclassweight << "prio" << shapersubclassprio << "maxburst" << "20" << "avpkt" << "1000";
278
delshaperfilter << "tc" << "filter" << "del" << "dev" << shaperinterface << "protocol" << "ip" << "parent" << shaperrootclassparent << "prio" << "1" << "handle" << shapermark << "fw" << "classid" << shapersubclassid;
280
bool successfilter=delshaperfilter.start();
281
bool successsubclass=delshapersubclass.start();
282
if (successfilter && successsubclass) {
283
statusbar->message(i18n("shaper filter deleted"), 2000);
285
msg.sprintf("sub class created for device %s\n", shaperinterfaceChoicedmp);
286
messageLog->insertItem(msg);
287
msg.sprintf("shaper filter deleted for device %s\n", shaperinterfaceChoicedmp);
288
messageLog->insertItem(msg);
290
statusbar->message(i18n("tc died"), 2000);
291
QMessageBox::critical(0, "Error",
292
"sub class or filter has not been deleted, please check your parameters! \n");
299
if ( class_exec == 1 )
302
if (shaperqdischandle.length()==0)
304
QMessageBox::critical(0, "Error",
305
"You have to supply the qdisc handle! \n e.g. 1! \n So knetfilter can establish the root class parent. \n");
307
else if (shaperrootclassid.length()==0)
309
QMessageBox::critical(0, "Error",
310
"You have to supply the root classID! \n e.g. 1:10! \n");
312
else if (shaperrootclassweight.length()==0)
314
QMessageBox::critical(0, "Error",
315
"You have to supply the root class data flow weight! :)\n e.g. 1Mbit! \n");
317
else if (shaperrootclassprio.length()==0)
319
QMessageBox::critical(0, "Error",
320
"you have to supply the root class priority!\n e.g. 8! \n");
324
delshaperrootclass << "tc" << "class" << "del" << "dev" << shaperinterface << "parent" << shaperrootclassparent << "classid" << shaperrootclassid << "cbq" << "bandwidth" << shaperglobalband << "rate" << shaperglobalband << "allot" << "1514"<< "weight" << shaperrootclassweight << "prio" << shaperrootclassprio << "maxburst" << "20" << "avpkt" << "1000";
326
bool successrootclass=delshaperrootclass.start();
327
if (successrootclass) {
328
statusbar->message(i18n("New root class deleted"), 2000);
330
msg.sprintf("root class deleted for device %s\n", shaperinterfaceChoicedmp);
331
messageLog->insertItem(msg);
333
statusbar->message(i18n("tc died"), 2000);
334
QMessageBox::critical(0, "Error",
335
"root class has not been deleted, please check your parameters! \n");
343
if ( qdisc_exec == 1 )
345
if (shaperqdischandle.length()==0)
347
QMessageBox::critical(0, "Error",
348
"You have to supply the qdisc handle! \n e.g. 1! \n");
352
delshaperqdisc << "tc" << "qdisc" << "del" << "dev" << shaperinterface << "root" << "handle" << shaperqdischandle << "cbq" << "bandwidth" << shaperglobalband << "avpkt" << "1000";
354
bool successqdisc=delshaperqdisc.start();
356
statusbar->message(i18n("qdisc deleted"), 2000);
358
msg.sprintf("qdisc deleted for device %s\n", shaperinterfaceChoicedmp);
359
messageLog->insertItem(msg);
361
statusbar->message(i18n("tc died"), 2000);
362
QMessageBox::critical(0, "Error",
363
"qdisc has not been deleted, please check your parameters! \n");
193
371
// set up interface
195
373
void knetfilter::trafficShaper() {
196
374
if ( shaperList == NULL )
200
378
shaperList = new KNFWidget();
201
379
shaperList->resize(640,480);
777
// Traffic Shaper's Rules Monitor
780
void knetfilter::startqdiscMonitor() {
782
showip.clearArguments();
783
showqdisc.clearArguments();
784
char shapermonitorinterfaceChoice2[5];
785
strcpy ( shapermonitorinterfaceChoice2, shapermonitorinterfaceChoice );
787
shapermonitorinterfaceChoicedmp = strcat ( shapermonitorinterfaceChoice2, shapermonitorinterfacenrChoicedmp );
789
showip << "ip" << "addr" << "show" << "dev" << shapermonitorinterfaceChoicedmp ;
790
showqdisc << "tc" << "qdisc" << "show" << "dev" << shapermonitorinterfaceChoicedmp ;
793
bool showaddr=showip.start(KProcess::NotifyOnExit,
794
KProcess::AllOutput);
795
bool success=showqdisc.start(KProcess::NotifyOnExit,
796
KProcess::AllOutput);
797
if (showaddr && success)
798
statusbar->message(i18n("Running..."), 2000);
800
statusbar->message(i18n("Couldn't start tc"), 2000);
805
void knetfilter::startclassMonitor() {
807
showip.clearArguments();
808
showclass.clearArguments();
809
char shapermonitorinterfaceChoice2[5];
810
strcpy ( shapermonitorinterfaceChoice2, shapermonitorinterfaceChoice );
812
shapermonitorinterfaceChoicedmp = strcat ( shapermonitorinterfaceChoice2, shapermonitorinterfacenrChoicedmp );
814
showip << "ip" << "addr" << "show" << "dev" << shapermonitorinterfaceChoicedmp ;
815
showclass << "tc" << "class" << "show" << "dev" << shapermonitorinterfaceChoicedmp ;
817
bool showaddr=showip.start(KProcess::NotifyOnExit,
818
KProcess::AllOutput);
819
bool success=showclass.start(KProcess::NotifyOnExit,
820
KProcess::AllOutput);
821
if (showaddr && success)
822
statusbar->message(i18n("Running..."), 2000);
824
statusbar->message(i18n("Couldn't start tc"), 2000);
829
void knetfilter::startfilterMonitor() {
831
showip.clearArguments();
832
showfilter.clearArguments();
833
char shapermonitorinterfaceChoice2[5];
834
strcpy ( shapermonitorinterfaceChoice2, shapermonitorinterfaceChoice );
836
shapermonitorinterfaceChoicedmp = strcat ( shapermonitorinterfaceChoice2, shapermonitorinterfacenrChoicedmp );
838
showip << "ip" << "addr" << "show" << "dev" << shapermonitorinterfaceChoicedmp ;
839
showfilter << "tc" << "filter" << "show" << "dev" << shapermonitorinterfaceChoicedmp ;
841
bool showaddr=showip.start(KProcess::NotifyOnExit,
842
KProcess::AllOutput);
843
bool success=showfilter.start(KProcess::NotifyOnExit,
844
KProcess::AllOutput);
845
if (showaddr && success)
846
statusbar->message(i18n("Running..."), 2000);
848
statusbar->message(i18n("Couldn't start tc"), 2000);
853
void knetfilter::trafficShaperMonitor() {
854
if ( shapermonList == NULL )
858
shapermonList = new KNFWidget();
859
shapermonList->resize(680,420);
860
shapermonList->setCaption("current traffic shaper rules, qdisc, class and filter entries");
862
QBoxLayout *top = new QBoxLayout(shapermonList, QBoxLayout::LeftToRight, 7);
863
QGridLayout *grid = new QGridLayout(7,5);
864
top->addLayout(grid,5);
866
shapermonBox = new QListBox(shapermonList);
867
grid->addMultiCellWidget(shapermonBox,0,5,0,5);
869
QLabel *labelshapermonInterface = new QLabel(shapermonList);
870
labelshapermonInterface->setText("Interface:");
871
grid->addMultiCellWidget(labelshapermonInterface,6,6,1,1);
873
shapermoninterface = new QComboBox( FALSE, shapermonList, "interface");
874
shapermoninterface->insertItem("eth");
875
shapermoninterface->insertItem("tr");
876
shapermoninterface->insertItem("lec");
877
shapermoninterface->insertItem("atm");
878
shapermoninterface->insertItem("bond");
879
shapermoninterface->insertItem("lo");
880
shapermoninterface->insertItem("slip");
881
shapermoninterface->insertItem("plip");
882
shapermoninterface->insertItem("ppp");
883
shapermoninterface->insertItem("ippp");
884
shapermoninterface->insertItem("tap");
885
shapermoninterface->insertItem("tun");
886
shapermoninterface->setFixedHeight(shapermoninterface->sizeHint().height());
887
connect(shapermoninterface,SIGNAL(activated(int)), SLOT(shapermonitorinterfaceActivated(int)));
888
grid->addMultiCellWidget(shapermoninterface,6,6,2,2);
891
QLabel *labelshapermonInterfacenr = new QLabel(shapermonList);
892
labelshapermonInterfacenr->setText("Interface nr:");
893
grid->addMultiCellWidget(labelshapermonInterfacenr,6,6,3,3);
895
shapermoninterfacenr = new QComboBox( FALSE, shapermonList, "interface nr");
896
shapermoninterfacenr->insertItem("0");
897
shapermoninterfacenr->insertItem("1");
898
shapermoninterfacenr->insertItem("2");
899
shapermoninterfacenr->insertItem("3");
900
shapermoninterfacenr->insertItem("4");
901
shapermoninterfacenr->insertItem("5");
902
shapermoninterfacenr->setFixedHeight(shapermoninterfacenr->sizeHint().height());
903
connect(shapermoninterfacenr,SIGNAL(activated(int)), SLOT(shapermonitorinterfacenrActivated(int)));
904
grid->addMultiCellWidget(shapermoninterfacenr,6,6,4,4);
906
QPushButton *btnQdisc = new QPushButton(shapermonList);
907
btnQdisc->setText("Qdisc");
908
btnQdisc->setFixedHeight(btnQdisc->sizeHint().height());
909
connect(btnQdisc,SIGNAL(clicked()), this, SLOT(startqdiscMonitor()));
910
grid->addWidget(btnQdisc,7,0);
912
QPushButton *btnClass = new QPushButton(shapermonList);
913
btnClass->setText("Class");
914
btnClass->setFixedHeight(btnClass->sizeHint().height());
915
connect(btnClass,SIGNAL(clicked()), this, SLOT(startclassMonitor()));
916
grid->addWidget(btnClass,7,1);
918
QPushButton *btnFilter = new QPushButton(shapermonList);
919
btnFilter->setText("Filter");
920
btnFilter->setFixedHeight(btnFilter->sizeHint().height());
921
connect(btnFilter,SIGNAL(clicked()), this, SLOT(startfilterMonitor()));
922
grid->addWidget(btnFilter,7,2);
924
QPushButton *btnClose = new QPushButton(shapermonList);
925
btnClose->setText("Close");
926
btnClose->setFixedHeight(btnClose->sizeHint().height());
927
connect(btnClose,SIGNAL(clicked()), this, SLOT(closeshaperMonitor()));
928
grid->addWidget(btnClose,7,5);
930
shapermonList->show();
931
setCentralWidget(shapermonList);
935
if (!shapermonList->isVisible() )
937
shapermonList->show();
941
QMessageBox::critical(0,"Warning", "Already Running\n");
947
void knetfilter::closeshaperMonitor() {
949
shapermonList->close();
954
void knetfilter::shaperMonitor(KProcess *, char *data, int len) {
958
static QString remainder;
962
memmove(dst,data,len);
972
newindex=list.find('\n',index);
974
remainder=list.right(list.length()-index);
977
lines.append(list.mid(index,newindex-index));
983
shapermonBox->insertStrList(&lines);
986
shapermonBox->insertItem(remainder.data());
987
shapermonBox->setTopItem(shapermonBox->count()-shapermonBox->numItemsVisible());
991
// menu widget choice interface
992
void knetfilter::shapermonitorinterfaceActivated(int index) {
996
shapermonitorinterfaceChoice = "eth";
998
shapermonitorinterfaceChoice = "eth";
1001
shapermonitorinterfaceChoice = "tr";
1004
shapermonitorinterfaceChoice = "lec";
1007
shapermonitorinterfaceChoice = "atm";
1010
shapermonitorinterfaceChoice = "bond";
1013
shapermonitorinterfaceChoice = "lo";
1016
shapermonitorinterfaceChoice = "slip";
1019
shapermonitorinterfaceChoice = "plip";
1022
shapermonitorinterfaceChoice = "ppp";
1025
shapermonitorinterfaceChoice = "ippp";
1028
shapermonitorinterfaceChoice = "tap";
1031
shapermonitorinterfaceChoice = "tun";
1038
void knetfilter::shapermonitorinterfacenrActivated(int index) {
1042
shapermonitorinterfacenrChoice = 0;
1044
shapermonitorinterfacenrChoice = 0;
1045
shapermonitorinterfacenrChoicedmp = "0";
1048
shapermonitorinterfacenrChoice = 1;
1049
shapermonitorinterfacenrChoicedmp = "1";
1052
shapermonitorinterfacenrChoice = 2;
1053
shapermonitorinterfacenrChoicedmp = "2";
1056
shapermonitorinterfacenrChoice = 3;
1057
shapermonitorinterfacenrChoicedmp = "3";
1060
shapermonitorinterfacenrChoice = 4;
1061
shapermonitorinterfacenrChoicedmp = "4";
1064
shapermonitorinterfacenrChoice = 5;
1065
shapermonitorinterfacenrChoicedmp = "5";