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