basic ipset support for qos-free-zone
[svn/Prometheus-QoS/.git] / prometheus.c
index 992e6bd6396fca31f3ac9de4e953cb5f6a07f111..a8ec705f0ebbdaf7d0ed33f3af5449b6fba8eee9 100644 (file)
@@ -2,12 +2,12 @@
 /* Prometheus QoS - you can "steal fire" from your ISP         */\r
 /* "fair-per-IP" quality of service (QoS) utility              */\r
 /* requires Linux 2.4.x or 2.6.x with HTB support              */\r
-/* Copyright(C) 2005-2017 Michael Polak, Arachne Aerospace     */\r
+/* Copyright(C) 2005-2019 Michael Polak, Arachne Aerospace     */\r
 /* iptables-restore support Copyright(C) 2007-2008 ludva       */\r
 /* Credit: CZFree.Net,Martin Devera,Netdave,Aquarius,Gandalf  */\r
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */\r
 \r
-/* Modified by: xChaos, 20171012\r
+/* Modified by: xChaos, 20190912\r
                  ludva, 20080415\r
  \r
    Prometheus QoS is free software; you can redistribute it and/or\r
@@ -29,7 +29,7 @@
 #include "cll1-0.6.2.h"\r
 #include "ipstruct.h"\r
 \r
-const char *version = "0.9.0-a";\r
+const char *version = "0.9.0-c";\r
 \r
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */\r
 /* Versions: 0.9.0 is development release, 1.0 will be "stable"    */\r
@@ -61,6 +61,7 @@ char           *hosts = "/etc/prometheus/hosts"; /* per-IP bandwidth definition
 char      *macrosfile = "/etc/prometheus/prometheus.macros"; /* rewrite rules for most common tariffs */\r
 char    *upstreamfile = "/etc/prometheus/upstream.interfaces"; /* list of interfaces to manage */\r
 char  *downstreamfile = "/etc/prometheus/downstream.interfaces"; /* list of interfaces to manage */\r
+char     *qosfreefile = "/etc/prometheus/qosfree.interfaces"; /* list of interfaces to manage */\r
 char    *iptablesfile = "/var/spool/prometheus.iptables"; /* temporary file for iptables-restore*/\r
 char   *ip6tablesfile = "/var/spool/prometheus.ip6tables"; /* temporary file for ip6tables-restore*/\r
 char          *credit = "/var/lib/misc/prometheus.credit"; /* credit log file */\r
@@ -100,6 +101,8 @@ char           *medium = "1000Mbit"; /* 10Mbit/100Mbit ethernet */
 char        *ip6prefix = NULL; /* Prefix for global /48 IPv6 subnet */\r
 char         *qos_leaf = "sfq perturb 5"; /* leaf discipline */\r
 char    *qos_free_zone = NULL; /* QoS free zone */\r
+char *qos_free_dst_ipset = NULL; /* QoS free zone - dst match ipset name, must be prepared outside prometheus */\r
+char *qos_free_src_ipset = NULL; /* QoS free zone - src match ipset name, must be prepared outside prometheus */\r
 /* int          qos_proxy = TRUE; include proxy port to QoS */\r
 int        found_lmsid = FALSE; /* show links to users in LMS information system */\r
 int     include_upload = TRUE; /* upload+download=total traffic */\r
@@ -138,6 +141,7 @@ struct Keyword *keyword, *defaultkeyword=NULL, *keywords = NULL;
 struct Macro *macro, *macros = NULL;\r
 struct Index *idxs = NULL, *idx, *metaindex;\r
 struct Interface *interfaces = NULL, *interface;\r
+struct QosFreeInterface *qosfreeinterfaces = NULL, *qosfreeinterface;\r
 \r
 #define FREE_CLASS      3\r
 #define OVERLIMIT_CLASS 4\r
@@ -290,6 +294,7 @@ void get_config(char *config_filename)
   option("hosts",hosts);\r
   option("downstream-interfaces-list-filename",downstreamfile);\r
   option("upstream-interfaces-list-filename",upstreamfile);\r
+  option("qos-free-interfaces-list-filename",qosfreefile);\r
   option("macros-filename",macrosfile);\r
   option("ip6-prefix",ip6prefix);\r
   option("medium",medium);\r
@@ -311,6 +316,8 @@ void get_config(char *config_filename)
   option("lms-url",lms_url);\r
   ioption("use-jquery-popups",use_jquery_popups);\r
   option("qos-free-zone",qos_free_zone);\r
+  option("qos-free-dst-ipset",qos_free_dst_ipset);\r
+  option("qos-free-src-ipset",qos_free_src_ipset);\r
   ioption("qos-free-delay",qos_free_delay);\r
 /*  ioption("qos-proxy-enable",qos_proxy); */\r
 /*  option("qos-proxy-ip",proxy_ip);*/\r
@@ -566,7 +573,6 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
   }\r
  }\r
  done; /* ugly macro end */\r
-\r
  \r
  if(just_logs)\r
  {\r
@@ -605,6 +611,12 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
  string(str, STRLEN); \r
  string(limit_pkts, STRLEN);\r
 \r
+ /*-----------------------------------------------------------------*/\r
+ printf("Parsing qos free interfaces file %s ...\n", qosfreefile);\r
+ /*-----------------------------------------------------------------*/\r
+ load(qosfreeinterface, qosfreeinterfaces,\r
+      qosfreefile, QosFreeInterface, name);\r
+\r
  /*-----------------------------------------------------------------*/\r
  printf("Parsing macro definition file %s ...\n", macrosfile);\r
  /*-----------------------------------------------------------------*/\r
@@ -747,7 +759,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
    iptables_save_line(ip6preamble, IPv6);\r
   }\r
 \r
-  if(qos_free_zone && *qos_free_zone!='0') /* this is currently supported only for IPv4 */\r
+  if(qos_free_zone && *qos_free_zone != '0') /* this is currently supported only for IPv4 */\r
   {\r
    for_each(interface, interfaces)\r
    {\r
@@ -755,6 +767,34 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
     iptables_save_line(str, IPv4);\r
    }\r
   }\r
+\r
+  if(qos_free_dst_ipset && *qos_free_dst_ipset != '0') /* this is currently supported only for IPv4 */\r
+  {\r
+   for_each(interface, interfaces)\r
+   {\r
+    sprintf(str,"-A %s -m set --match-set %s %s -o %s -j ACCEPT", interface->chain, (interface->is_upstream?"dst":"src"), qos_free_dst_ipset, interface->name);\r
+    iptables_save_line(str, IPv4);\r
+   }\r
+  }\r
+\r
+  if(qos_free_src_ipset && *qos_free_src_ipset != '0') /* this is currently supported only for IPv4 */\r
+  {\r
+   for_each(interface, interfaces)\r
+   {\r
+    sprintf(str,"-A %s -m set --match-set %s %s -o %s -j ACCEPT", interface->chain, (interface->is_upstream?"src":"dst"), qos_free_src_ipset, interface->name);\r
+    iptables_save_line(str, IPv4);\r
+   }\r
+  }\r
+  \r
+  for_each(qosfreeinterface, qosfreeinterfaces)\r
+  {\r
+    sprintf(str,"-A FORWARD -i %s -j ACCEPT", qosfreeinterface->name);\r
+    iptables_save_line(str, IPv4);  \r
+    iptables_save_line(str, IPv6);\r
+    sprintf(str,"-A POSTROUTING -o %s -j ACCEPT", qosfreeinterface->name);\r
+    iptables_save_line(str, IPv4);\r
+    iptables_save_line(str, IPv6);\r
+  }\r
   \r
   if(ip_count > idxtable_treshold1 && !just_flush)\r
   {\r
@@ -1273,7 +1313,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
                 interface->name, limit_pkts);\r
    iptables_save_line(str, ip->v6);\r
 \r
-   if(limit_pkts)\r
+   if(*limit_pkts) /* non-empty string?*/\r
    {\r
     /* classify overlimit packets to separate overlimit class */\r
     sprintf(str, "-A %s -%c %s/%d -o %s -j %s%d",\r
This page took 0.149778 seconds and 4 git commands to generate.