X-Git-Url: http://git.harvie.cz/?a=blobdiff_plain;f=prometheus.c;h=474d5cd76a711ac3842f893fa8cf7ea243d1aadb;hb=84245208015652c96cd65021f394fb69f5e2d37b;hp=1b510293460791b215ac569c658910a9fc85840e;hpb=3430e838dc632523c571a995d75ace44de1b06b6;p=svn%2FPrometheus-QoS%2F.git
diff --git a/prometheus.c b/prometheus.c
index 1b51029..474d5cd 100644
--- a/prometheus.c
+++ b/prometheus.c
@@ -7,7 +7,7 @@
/* Credit: CZFree.Net,Martin Devera,Netdave,Aquarius,Gandalf */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
-/* Modified by: xChaos, 20190127
+/* Modified by: xChaos, 20190912
ludva, 20080415
Prometheus QoS is free software; you can redistribute it and/or
@@ -29,7 +29,7 @@
#include "cll1-0.6.2.h"
#include "ipstruct.h"
-const char *version = "0.9.1";
+const char *version = "0.9.0-c";
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Versions: 0.9.0 is development release, 1.0 will be "stable" */
@@ -40,7 +40,7 @@ const char *version = "0.9.1";
/* Warning: unofficial Github mirror is not supported by author! */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
-const char *stats_html_signature = "Statistics generated by Prometheus QoS version %s
GPL+Copyright(C)2005-2017 Michael Polak, Arachne Labs\n";
+const char *stats_html_signature = "Statistics generated by Prometheus QoS version %s
GPL+Copyright(C)2005-2019 Michael Polak, Arachne Labs\n";
#define STRLEN 512
#undef DEBUG
@@ -87,7 +87,6 @@ char *final_chain = "DROP"; /* REJECT would be better, but it is impossible
char *mark = "MARK";
char *mark_iptables = "MARK --set-mark ";
int dry_run = FALSE; /* preview - use puts() instead of system() */
-int mix_new_hosts = FALSE; /* execute only commands not already in log of iptables */
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]";
char *ip6preamble = "-A FORWARD -p ipv6-icmp -j ACCEPT\n-A POSTROUTING -p ipv6-icmp -j ACCEPT\n-A FORWARD -s fe80::/10 -j ACCEPT\n-A FORWARD -d ff00::/8 -j ACCEPT\n-A POSTROUTING -s fe80::/10 -j ACCEPT\n-A POSTROUTING -d ff00::/8 -j ACCEPT";
FILE *iptables_file = NULL;
@@ -102,6 +101,8 @@ char *medium = "1000Mbit"; /* 10Mbit/100Mbit ethernet */
char *ip6prefix = NULL; /* Prefix for global /48 IPv6 subnet */
char *qos_leaf = "sfq perturb 5"; /* leaf discipline */
char *qos_free_zone = NULL; /* QoS free zone */
+char *qos_free_dst_ipset = NULL; /* QoS free zone - dst match ipset name, must be prepared outside prometheus */
+char *qos_free_src_ipset = NULL; /* QoS free zone - src match ipset name, must be prepared outside prometheus */
/* int qos_proxy = TRUE; include proxy port to QoS */
int found_lmsid = FALSE; /* show links to users in LMS information system */
int include_upload = TRUE; /* upload+download=total traffic */
@@ -127,12 +128,12 @@ int ip_count = 0;
FILE *log_file = NULL;
char *kwd = "via-prometheus"; /* /etc/hosts comment, eg. #qos-64-128 */
-const int highest_priority = 0; /* highest HTB priority (HTB built-in value is 0) */
-const int lowest_priority = 7; /* lowest HTB priority /include/uapi/linux/pkt_sched.h: #define TC_HTB_NUMPRIO 8 */
-const int idxtable_treshold1 = 24; /* this is no longer configurable */
-const int idxtable_treshold2 = 12; /* this is no longer configurable */
-const int idxtable_bitmask1 = 3; /* this is no longer configurable */
-const int idxtable_bitmask2 = 3; /* this is no longer configurable */
+const int highest_priority = 0; /* highest HTB priority (HTB built-in value is 0) */
+const int lowest_priority = 7; /* lowest HTB priority /include/uapi/linux/pkt_sched.h: #define TC_HTB_NUMPRIO 8 */
+const int idxtable_treshold1 = 24; /* this is no longer configurable */
+const int idxtable_treshold2 = 12; /* this is no longer configurable */
+const int idxtable_bitmask1 = 3; /* this is no longer configurable */
+const int idxtable_bitmask2 = 3; /* this is no longer configurable */
struct IP *ips = NULL, *networks = NULL, *ip, *sharedip;
struct Group *groups = NULL, *group;
@@ -141,7 +142,6 @@ struct Macro *macro, *macros = NULL;
struct Index *idxs = NULL, *idx, *metaindex;
struct Interface *interfaces = NULL, *interface;
struct QosFreeInterface *qosfreeinterfaces = NULL, *qosfreeinterface;
-struct Textfile *previous_commands = NULL, *previous_iptables = NULL, *previous_ip6tables = NULL, *textline;
#define FREE_CLASS 3
#define OVERLIMIT_CLASS 4
@@ -186,6 +186,7 @@ const char *tr_odd_even(void)
}
}
+
/* ====== iptables indexes are used to reduce complexity to log8(N) ===== */
char *index_id(char *ip, int bitmask);
@@ -315,6 +316,8 @@ void get_config(char *config_filename)
option("lms-url",lms_url);
ioption("use-jquery-popups",use_jquery_popups);
option("qos-free-zone",qos_free_zone);
+ option("qos-free-dst-ipset",qos_free_dst_ipset);
+ option("qos-free-src-ipset",qos_free_src_ipset);
ioption("qos-free-delay",qos_free_delay);
/* ioption("qos-proxy-enable",qos_proxy); */
/* option("qos-proxy-ip",proxy_ip);*/
@@ -379,23 +382,7 @@ void safe_run(char *cmd)
}
else
{
- int skip_cmd = FALSE;
- if(mix_new_hosts)
- for_each(textline, previous_commands)
- if(eq(textline->str, cmd))
- {
- skip_cmd = TRUE;
- break;
- }
-
- if(!skip_cmd)
- {
- if(mix_new_hosts)
- {
- printf("Executing command: %s\n", cmd);
- }
- system(cmd);
- }
+ system(cmd);
}
if(log_file)
{
@@ -404,29 +391,15 @@ void safe_run(char *cmd)
}
void iptables_save_line(char *line, int ipv6)
-{
+{
if(ipv6)
{
- if(mix_new_hosts)
- for_each(textline, previous_ip6tables)
- if(eq(textline->str, line))
- return;
-
fprintf(ip6tables_file,"%s\n",line);
}
else
{
- if(mix_new_hosts)
- for_each(textline, previous_iptables)
- if(eq(textline->str, line))
- return;
-
fprintf(iptables_file,"%s\n",line);
}
- if(mix_new_hosts)
- {
- printf("Adding iptables/ip6tables rule: %s\n", line);
- }
}
#define IPv4 FALSE
@@ -500,7 +473,7 @@ program
int just_preview = FALSE; /* preview - generate just stats */
int start_shaping = FALSE; /* apply FUP - requires classmap file */
int stop_shaping = FALSE; /* lift FUP - requires classmap file */
- int reduce_ceil = 0; /* allow only rate+(ceil-rate)/2, /4, etc. */
+ int reduce_ceil = 0; /* allow only rate+(ceil-rate)/2, /4, etc. */
int just_logs = FALSE; /* just parse logs */
int run = FALSE;
int total = 0;
@@ -509,7 +482,7 @@ program
printf("\n\
Prometheus QoS - \"fair-per-IP\" Quality of Service setup utility.\n\
-Version %s - Copyright (C)2005-2019 Michael Polak, Arachne Labs\n\
+Version %s - Copyright (C)2005-2017 Michael Polak, Arachne Labs\n\
iptables-restore & burst tunning & classify modification by Ludva\n\
Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
@@ -518,21 +491,20 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
{
argument("-c") { nextargument(config); }
argument("-h") { nextargument(althosts);}
- argument("-d") { run = TRUE; dry_run = TRUE; }
- argument("-f") { run = TRUE; just_flush = TRUE; }
- argument("-9") { run = TRUE; just_flush = 9; }
- argument("-p") { run = TRUE; just_preview = TRUE; }
- argument("-q") { run = TRUE; just_preview = TRUE; stop_shaping = TRUE; }
- argument("-2") { run = TRUE; just_preview = TRUE; reduce_ceil = 2; }
- argument("-4") { run = TRUE; just_preview = TRUE; reduce_ceil = 4; }
- argument("-s") { run = TRUE; just_preview = TRUE; start_shaping = TRUE; }
- argument("-x") { run = TRUE; just_preview = TRUE; mix_new_hosts = TRUE; }
- argument("-r") { run = TRUE; }
- argument("-n") { run = TRUE; nodelay = TRUE; }
- argument("-a") { run = TRUE; just_networks = TRUE; }
- argument("-l") { just_logs = TRUE; }
- argument("-m") { just_logs = TRUE; }
- argument("-y") { just_logs = TRUE; }
+ argument("-d") { run=TRUE; dry_run=TRUE; }
+ argument("-f") { run=TRUE; just_flush=TRUE; }
+ argument("-9") { run=TRUE; just_flush=9; }
+ argument("-p") { run=TRUE; just_preview=TRUE; }
+ argument("-q") { run=TRUE; just_preview=TRUE; stop_shaping=TRUE; }
+ argument("-2") { run=TRUE; just_preview=TRUE; reduce_ceil=2; }
+ argument("-4") { run=TRUE; just_preview=TRUE; reduce_ceil=4; }
+ argument("-s") { run=TRUE; just_preview=TRUE; start_shaping=TRUE; }
+ argument("-r") { run=TRUE; }
+ argument("-n") { run=TRUE; nodelay=TRUE; }
+ argument("-a") { run=TRUE; just_networks=TRUE; }
+ argument("-l") { just_logs=TRUE; }
+ argument("-m") { just_logs=TRUE; }
+ argument("-y") { just_logs=TRUE; }
argument("-?") { help(); exit(0); }
argument("--help") { help(); exit(0); }
argument("-v") { exit(0); }
@@ -618,7 +590,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
hosts = althosts;
}
- if(!mix_new_hosts && just_flush<9)
+ if(just_flush<9)
{
/*-----------------------------------------------------------------*/
puts("Parsing iptables verbose output ...");
@@ -662,6 +634,8 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
}
done; /* ugly macro end */
+
+
/*-----------------------------------------------------------------*/
printf("Parsing class defintion file %s ...\n", hosts);
/*-----------------------------------------------------------------*/
@@ -675,33 +649,6 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
}
*/
- if(mix_new_hosts)
- {
- char *new_filename;
- /*-----------------------------------------------------------------*/
- printf("Loading log of previously executed commands %s ...\n", cmdlog);
- /*-----------------------------------------------------------------*/
- load(textline, previous_commands, cmdlog, Textfile, str);
- /*-----------------------------------------------------------------*/
- printf("Loading log of iptables-restore commands %s ...\n", iptablesfile);
- /*-----------------------------------------------------------------*/
- load(textline, previous_iptables, iptablesfile, Textfile, str);
- /*-----------------------------------------------------------------*/
- printf("Loading log of ip6tables-restore commands %s ...\n", ip6tablesfile);
- /*-----------------------------------------------------------------*/
- load(textline, previous_ip6tables, ip6tablesfile, Textfile, str);
-
- string(new_filename, strlen(iptablesfile)+2);
- strcpy(new_filename, iptablesfile);
- strcat(new_filename, "-x");
- iptablesfile = new_filename;
-
- string(new_filename, strlen(ip6tablesfile)+2);
- strcpy(new_filename, ip6tablesfile);
- strcat(new_filename, "-x");
- ip6tablesfile = new_filename;
- }
-
/*-----------------------------------------------------------------*/
puts("Resolving shared connections ...");
/*-----------------------------------------------------------------*/
@@ -742,7 +689,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
}
}
- if(!mix_new_hosts && enable_credit && just_flush<9)
+ if(enable_credit && just_flush<9)
{
/*-----------------------------------------------------------------*/
printf("Parsing credit file %s ...\n", credit);
@@ -762,7 +709,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
}
- if(!mix_new_hosts && !just_preview)
+ if(!just_preview)
{
/*-----------------------------------------------------------------*/
puts("Initializing iptables and tc classes ...");
@@ -812,7 +759,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
iptables_save_line(ip6preamble, IPv6);
}
- if(qos_free_zone && *qos_free_zone!='0') /* this is currently supported only for IPv4 */
+ if(qos_free_zone && *qos_free_zone != '0') /* this is currently supported only for IPv4 */
{
for_each(interface, interfaces)
{
@@ -820,6 +767,24 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
iptables_save_line(str, IPv4);
}
}
+
+ if(qos_free_dst_ipset && *qos_free_dst_ipset != '0') /* this is currently supported only for IPv4 */
+ {
+ for_each(interface, interfaces)
+ {
+ sprintf(str,"-A %s -m set --match-set %s %s -o %s -j ACCEPT", interface->chain, qos_free_dst_ipset, (interface->is_upstream?"dst":"src"), interface->name);
+ iptables_save_line(str, IPv4);
+ }
+ }
+
+ if(qos_free_src_ipset && *qos_free_src_ipset != '0') /* this is currently supported only for IPv4 */
+ {
+ for_each(interface, interfaces)
+ {
+ sprintf(str,"-A %s -m set --match-set %s %s -o %s -j ACCEPT", interface->chain, qos_free_src_ipset, (interface->is_upstream?"src":"dst"), interface->name);
+ iptables_save_line(str, IPv4);
+ }
+ }
for_each(qosfreeinterface, qosfreeinterfaces)
{
@@ -982,7 +947,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
exit(0);
}
- if(!mix_new_hosts && !just_preview)
+ if(!just_preview)
{
if(!dry_run && !nodelay && qos_free_delay)
{
@@ -1006,13 +971,10 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
}
}
- if(mix_new_hosts)
- {
- /*-----------------------------------------------------------------*/
- puts("Locating heavy downloaders and generating root classes ...");
- /*-----------------------------------------------------------------*/
- sort(ip,ips,desc_order_by,traffic);
- }
+ /*-----------------------------------------------------------------*/
+ puts("Locating heavy downloaders and generating root classes ...");
+ /*-----------------------------------------------------------------*/
+ sort(ip,ips,desc_order_by,traffic);
/*-----------------------------------------------------------------*/
for_each(interface, interfaces)
@@ -1247,7 +1209,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
json_traffic=json_preview;
}
- if(!mix_new_hosts && !dry_run && !just_flush)
+ if(!dry_run && !just_flush)
{
/*-----------------------------------------------------------------*/
printf("Writing json traffic overview %s ... ", json_traffic);
@@ -1278,8 +1240,8 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
printf("Statistics preview generated (-%c switch) - now exiting ...\n", swchar);
exit(0);
- }
-
+ }
+
i=0;
#ifdef DEBUG
printf("%-22s %-15s mark\n","name","ip");