pre-release cleanup
[svn/Prometheus-QoS/.git] / prometheus.c
index 19f06e822ea1782c56d54c0082d6e7e365c7a9c9..fcba898971e8a84d57445551ffea62ae1d236344 100644 (file)
@@ -7,7 +7,7 @@
 /* == Credit: CZFree.Net,Martin Devera,Netdave,Aquarius,Gandalf == */\r
 /* =============================================================== */\r
 \r
-/* Modified: xChaos, 20080201\r
+/* Modified: xChaos, 20080202\r
              ludva, 20071227\r
 \r
    Prometheus QoS is free software; you can redistribute it and/or\r
 \r
 const char *version="0.7.8"; /*0.7.9 will be last development, 0.8.0 first stable */\r
 \r
+/* ======= All path names are defined hear (for RPM patch) =======  */\r
+\r
+char *tc              = "/sbin/tc"; /* requires tc with HTB support */\r
+char *iptables        = "/sbin/iptables"; /* requires iptables utility */\r
+char *iptablessave    = "/sbin/iptables-save"; /* not yet required */\r
+char *iptablesrestore = "/sbin/iptables-restore";  /* requires iptables-restore */\r
+\r
+char *config          = "/etc/prometheus/prometheus.conf"; /* main configuration file */\r
+char *hosts           = "/etc/prometheus/hosts"; /* per-IP bandwidth definition file */\r
+\r
+char *iptablesfile    = "/var/spool/prometheus.iptables"; /* temporary file for iptables-restore*/\r
+char *credit          = "/var/lib/misc/prometheus.credit"; /* credit log file */\r
+char *html            = "/var/www/traffic.html"; /* hall of fame filename */\r
+char *preview         = "/var/www/preview.html"; /* hall of fame preview */\r
+char *cmdlog          = "/var/log/prometheuslog"; /* command log filename */\r
+char *log_dir         = "/var/www/logs/"; /* log directory pathname, ended with slash */\r
+char *log_url         = "logs/"; /* log directory relative URI prefix (partial URL) */\r
+\r
 /* ======= Help screen is hopefuly self-documenting part of code :-) ======= */\r
 \r
 void help(void)\r
@@ -59,23 +77,10 @@ int filter_type=1;                      /*1 mark, 2 classify*/
 char *mark="MARK";\r
 char *mark_iptables="MARK --set-mark ";\r
 int dry_run=0;                         /* preview - use puts() instead of system() */\r
-char *config="/etc/prometheus/prometheus.conf";   /* main configuration file */\r
-char *hosts="/etc/prometheus/hosts";              /* line bandwidth definition file */\r
-char *tc="/sbin/tc";                   /* requires tc with HTB support */\r
-char *iptables="/sbin/iptables";       /* requires iptables utility */\r
-char *iptablessave="/sbin/iptables-save"; /* new */\r
-char *iptablesrestore="/sbin/iptables-restore";  /* new */\r
-char *iptablesfile="/var/spool/prometheus.iptables";  /* new; file for iptables-restore*/\r
 char *iptablespreamble="*mangle\n:PREROUTING ACCEPT [0:0]\n:POSTROUTING ACCEPT [0:0]\n:INPUT ACCEPT [0:0]\n:OUTPUT ACCEPT [0:0]\n:FORWARD ACCEPT [0:0]";\r
 FILE *iptables_file=NULL;\r
-char *html="/var/www/traffic.html";    /* hall of fame filename */\r
-char *preview="/var/www/preview.html"; /* hall of fame preview */\r
-char *cmdlog="/var/log/prometheus";    /* command log filename */\r
-char *credit="/var/run/prometheus.credit";  /* credit log file */\r
 int enable_credit=1;                   /* enable credit file */\r
 int use_credit=0;                      /* use credit file (if enabled)*/\r
-char *log_dir="/var/www/logs/";        /* log directory pathname */\r
-char *log_url="logs/";                 /* log directory URL prefix */\r
 char *title="Hall of Fame - Greatest Suckers"; /* hall of fame title */\r
 int hall_of_fame=1;                           /* enable hall of fame */\r
 char *lan="eth0";                /* LAN interface */\r
@@ -563,20 +568,24 @@ void run_restore(void)
 {\r
  char *restor, *str;\r
  string(restor,STRLEN);\r
+\r
+ /*-----------------------------------------------------------------*/\r
+ printf("Running %s <%s ...\n",iptablesrestore,iptablesfile);\r
+ /*-----------------------------------------------------------------*/\r
  \r
  save_line("COMMIT");\r
  fclose(iptables_file);\r
- if(dry_run) {\r
+ if(dry_run) \r
+ {\r
     parse(iptablesfile)\r
     {\r
         str=_;\r
         printf("%s\n", str);\r
     }done;\r
- }else{\r
-    //sprintf(restor,"cat %s",iptablesfile); else \r
-    sprintf(restor,"%s <%s",iptablesrestore, iptablesfile);\r
-    system(restor);\r
- };\r
+ }\r
+\r
+ sprintf(restor,"%s <%s",iptablesrestore, iptablesfile);\r
+ safe_run(restor);\r
  \r
  free(restor);\r
 }\r
@@ -1075,7 +1084,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
      }\r
      else\r
      {\r
-      if( keyword->data_prio && !ip->fixedprio &&\r
+      if( ip->keyword->data_prio && !ip->fixedprio &&\r
           ip->traffic>ip->credit+\r
            (ip->min*ip->keyword->data_prio+(ip->keyword->fixed_prio<<20)) )\r
       {\r
@@ -1459,6 +1468,10 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
 \r
  printf("Total IP count: %d\n", i);\r
 \r
+ /*-----------------------------------------------------------------*/\r
+ puts("Generating free bandwith classes ...");\r
+ /*-----------------------------------------------------------------*/\r
+\r
  /* ---------------------------------------- tc - free bandwith shared class */\r
  sprintf(str,"%s class add dev %s parent 1:%d classid 1:3 htb rate %dkbit ceil %dkbit burst %dk prio 2",tc,lan,parent,free_min,free_max,burst);\r
  safe_run(str);\r
@@ -1481,7 +1494,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
 \r
  sprintf(str,"%s filter add dev %s parent 1:0 protocol ip handle 3 fw flowid 1:3",tc,wan);\r
  safe_run(str);\r
\r
+\r
  run_restore();\r
  \r
  if (log_file) fclose(log_file);\r
This page took 0.122227 seconds and 4 git commands to generate.