debug version
authorxchaos <xchaos@251d49ef-1d17-4917-a970-b30cf55b089b>
Tue, 12 Feb 2019 16:34:51 +0000 (16:34 +0000)
committerxchaos <xchaos@251d49ef-1d17-4917-a970-b30cf55b089b>
Tue, 12 Feb 2019 16:34:51 +0000 (16:34 +0000)
git-svn-id: https://dev.arachne.cz/repos/prometheus/trunk@270 251d49ef-1d17-4917-a970-b30cf55b089b

parsehosts.c
prometheus.c

index 47b06bd5c28925d6495e7ddf20ca6065311a98e4..8c9eca159c6d1b3304f8e45342c1c04d2eeaced9 100644 (file)
@@ -11,7 +11,9 @@ extern struct IP *ips, *ip, *sharedip, *networks;
 extern struct Group *groups, *group;\r
 extern struct Keyword *keyword, *defaultkeyword, *keywords;\r
 extern struct Macro *macro, *macros;\r
+extern struct Textfile *previous_classmap, *textline;\r
 extern int class_count;\r
+extern int mix_new_hosts;\r
 extern int ip_count;\r
 extern int found_lmsid;\r
 extern int free_min;\r
@@ -342,7 +344,23 @@ void parse_hosts(char *hosts)
       }\r
      }\r
 \r
-     ip->mark = FIRSTIPCLASS+1+class_count++;     \r
+     if(mix_new_hosts)\r
+      for_each(textline, previous_classmap)\r
+      {\r
+       ptr = strchr(textline->str, ' ');\r
+       if(ptr)\r
+       {\r
+        if(!strncmp(ip->addr, textline->str, ptr-textline->str))\r
+        {\r
+         ip->mark = atoi(ptr+1);\r
+         printf("Match class: %s %d\n", ip->addr, ip->mark);\r
+        }\r
+       }      \r
+      }\r
+     \r
+     if(!mix_new_hosts || !ip->mark)\r
+      ip->mark = FIRSTIPCLASS+1+class_count++;\r
+          \r
      update_network(ip->addr, ip);\r
 \r
      if_exists(group,groups,(group->min == ip->min)) \r
index 1b510293460791b215ac569c658910a9fc85840e..5a9492e3e7592cc4cf8fac51f5a98e674039016e 100644 (file)
@@ -7,7 +7,7 @@
 /* Credit: CZFree.Net,Martin Devera,Netdave,Aquarius,Gandalf  */\r
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */\r
 \r
-/* Modified by: xChaos, 20190127\r
+/* Modified by: xChaos, 20190212\r
                  ludva, 20080415\r
  \r
    Prometheus QoS is free software; you can redistribute it and/or\r
@@ -40,7 +40,7 @@ const char *version = "0.9.1";
 /* Warning: unofficial Github mirror is not supported by author!  */\r
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */\r
 \r
-const char *stats_html_signature = "<span class=\"small\">Statistics generated by Prometheus QoS version %s<br />GPL+Copyright(C)2005-2017 Michael Polak, <a target=\"_blank\" href=\"http://www.arachne.cz/\">Arachne Labs</a></span>\n";\r
+const char *stats_html_signature = "<span class=\"small\">Statistics generated by Prometheus QoS version %s<br />GPL+Copyright(C)2005-2019 Michael Polak, <a target=\"_blank\" href=\"http://www.arachne.cz/\">Arachne Labs</a></span>\n";\r
 \r
 #define STRLEN 512\r
 #undef DEBUG\r
@@ -88,6 +88,7 @@ char             *mark = "MARK";
 char    *mark_iptables = "MARK --set-mark ";\r
 int            dry_run = FALSE; /* preview - use puts() instead of system() */\r
 int      mix_new_hosts = FALSE; /* execute only commands not already in log of iptables */\r
+char    *log_file_mode = "w";   /* overwrite command and iptables log files, except append in -x mode */\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
 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";\r
 FILE    *iptables_file = NULL;\r
@@ -141,7 +142,7 @@ struct Macro *macro, *macros = NULL;
 struct Index *idxs = NULL, *idx, *metaindex;\r
 struct Interface *interfaces = NULL, *interface;\r
 struct QosFreeInterface *qosfreeinterfaces = NULL, *qosfreeinterface;\r
-struct Textfile *previous_commands = NULL, *previous_iptables = NULL, *previous_ip6tables = NULL, *textline;\r
+struct Textfile *previous_commands = NULL, *previous_iptables = NULL, *previous_ip6tables = NULL, *previous_classmap = NULL, *textline;\r
 \r
 #define FREE_CLASS      3\r
 #define OVERLIMIT_CLASS 4\r
@@ -381,12 +382,17 @@ void safe_run(char *cmd)
  {\r
   int skip_cmd = FALSE;\r
   if(mix_new_hosts)\r
+  {\r
+   skip_cmd = FALSE;\r
    for_each(textline, previous_commands)\r
+   {\r
     if(eq(textline->str, cmd))\r
     {\r
      skip_cmd = TRUE;\r
      break;\r
     }\r
+   }\r
+  }\r
  \r
   if(!skip_cmd)\r
   {\r
@@ -394,38 +400,52 @@ void safe_run(char *cmd)
    {\r
     printf("Executing command: %s\n", cmd);\r
    }\r
-   system(cmd);\r
+   else\r
+    system(cmd);\r
   }\r
  }\r
- if(log_file)\r
+ if(log_file && !mix_new_hosts)//!!debug\r
  {\r
   fprintf(log_file,"%s\n",cmd);\r
  }\r
 }\r
 \r
 void iptables_save_line(char *line, int ipv6)\r
-{   \r
+{\r
+ const char *cmd = NULL;\r
+    \r
  if(ipv6)\r
  {\r
   if(mix_new_hosts)\r
    for_each(textline, previous_ip6tables)\r
     if(eq(textline->str, line))\r
+    {\r
+     printf("Match: %s\n",line);\r
      return;\r
+    }\r
 \r
-  fprintf(ip6tables_file,"%s\n",line);\r
+  if(!mix_new_hosts) //!!debug\r
+   fprintf(ip6tables_file,"%s\n",line);\r
+  cmd = ip6tables;\r
  }\r
  else\r
  {\r
   if(mix_new_hosts)\r
    for_each(textline, previous_iptables)\r
     if(eq(textline->str, line))\r
-     return; \r
+    {\r
+     printf("Match: %s\n",line);\r
+     return;\r
+    }     \r
 \r
-  fprintf(iptables_file,"%s\n",line);\r
+  if(!mix_new_hosts) //!!debug\r
+   fprintf(iptables_file,"%s\n",line);\r
+  cmd = iptables;\r
  }\r
  if(mix_new_hosts)\r
  {\r
-  printf("Adding iptables/ip6tables rule: %s\n", line);\r
\r
+  printf("Executing command: %s %s\n",cmd, line);\r
  } \r
 }\r
 \r
@@ -526,7 +546,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
   argument("-2") { run = TRUE; just_preview = TRUE; reduce_ceil = 2; }\r
   argument("-4") { run = TRUE; just_preview = TRUE; reduce_ceil = 4; }\r
   argument("-s") { run = TRUE; just_preview = TRUE; start_shaping = TRUE; }\r
-  argument("-x") { run = TRUE; just_preview = TRUE; mix_new_hosts = TRUE; }\r
+  argument("-x") { run = TRUE; mix_new_hosts = TRUE; log_file_mode = "a"; }\r
   argument("-r") { run = TRUE; }\r
   argument("-n") { run = TRUE; nodelay = TRUE; }\r
   argument("-a") { run = TRUE; just_networks = TRUE; }\r
@@ -677,7 +697,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
 \r
  if(mix_new_hosts)\r
  {\r
-  char *new_filename;\r
+  char *eoln;\r
   /*-----------------------------------------------------------------*/\r
   printf("Loading log of previously executed commands %s ...\n", cmdlog);\r
   /*-----------------------------------------------------------------*/\r
@@ -690,16 +710,10 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
   printf("Loading log of ip6tables-restore commands %s ...\n", ip6tablesfile);\r
   /*-----------------------------------------------------------------*/\r
   load(textline, previous_ip6tables, ip6tablesfile, Textfile, str);\r
-\r
-  string(new_filename, strlen(iptablesfile)+2);\r
-  strcpy(new_filename, iptablesfile);\r
-  strcat(new_filename, "-x");\r
-  iptablesfile = new_filename;\r
-\r
-  string(new_filename, strlen(ip6tablesfile)+2);\r
-  strcpy(new_filename, ip6tablesfile);\r
-  strcat(new_filename, "-x");\r
-  ip6tablesfile = new_filename;\r
+ /*-----------------------------------------------------------------*/\r
+  printf("Loading map of IP addresses to tc classes  %s ...\n", classmap);\r
+  /*-----------------------------------------------------------------*/\r
+  load(textline, previous_classmap, classmap, Textfile, str);\r
  }\r
 \r
  /*-----------------------------------------------------------------*/\r
@@ -762,35 +776,38 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
  }\r
 \r
 \r
- if(!mix_new_hosts && !just_preview)\r
+ if(!just_preview)\r
  {\r
-  /*-----------------------------------------------------------------*/\r
-  puts("Initializing iptables and tc classes ...");\r
-  /*-----------------------------------------------------------------*/\r
-  \r
-  iptables_file = fopen(iptablesfile, "w");\r
-  if(iptables_file == NULL)\r
+  if(!mix_new_hosts)\r
   {\r
+   /*-----------------------------------------------------------------*/\r
+   puts("Initializing iptables and tc classes ...");\r
+   /*-----------------------------------------------------------------*/\r
+  \r
+   iptables_file = fopen(iptablesfile, "w");\r
+   if(iptables_file == NULL)\r
+   {\r
     perror(iptablesfile);\r
     exit(-1);\r
-  }\r
-  iptables_save_line(iptablespreamble, IPv4);\r
+   }\r
+   iptables_save_line(iptablespreamble, IPv4);\r
 \r
-  if(ip6prefix)\r
-  {\r
-   ip6tables_file = fopen(ip6tablesfile, "w");\r
-   if(ip6tables_file == NULL)\r
+   if(ip6prefix)\r
    {\r
-     perror(ip6tablesfile);\r
-     exit(-1);\r
+    ip6tables_file = fopen(ip6tablesfile, "w");\r
+    if(ip6tables_file == NULL)\r
+    {\r
+      perror(ip6tablesfile);\r
+      exit(-1);\r
+     }\r
+    iptables_save_line(iptablespreamble, IPv6);\r
+    iptables_save_line(ip6preamble, IPv6);\r
    }\r
-   iptables_save_line(iptablespreamble, IPv6);\r
-   iptables_save_line(ip6preamble, IPv6);\r
-  }\r
 \r
-  run_iptables_restore();\r
+   run_iptables_restore();\r
+  }\r
   \r
-  log_file = fopen(cmdlog, "w");\r
+  log_file = fopen(cmdlog, log_file_mode); /* overwrite command and iptables log files, except append in -x mode */\r
   if(log_file == NULL) \r
   {\r
     perror(cmdlog);\r
@@ -802,14 +819,17 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
    sprintf(str,"%s qdisc del dev %s root 2>/dev/null", tc, interface->name);\r
    safe_run(str);\r
   }\r
-  \r
-  iptables_file=fopen(iptablesfile,"w");\r
-  iptables_save_line(iptablespreamble, IPv4);\r
-  if(ip6prefix)\r
-  {\r
-   ip6tables_file=fopen(ip6tablesfile,"w");\r
-   iptables_save_line(iptablespreamble, IPv6);\r
-   iptables_save_line(ip6preamble, IPv6);\r
+\r
+  if(!mix_new_hosts)\r
+  {  \r
+   iptables_file = fopen(iptablesfile, log_file_mode); /* overwrite command and iptables log files, except append in -x mode */\r
+   iptables_save_line(iptablespreamble, IPv4);\r
+   if(ip6prefix)\r
+   {\r
+    ip6tables_file = fopen(ip6tablesfile, log_file_mode); /* overwrite command and iptables log files, except append in -x mode */\r
+    iptables_save_line(iptablespreamble, IPv6);\r
+    iptables_save_line(ip6preamble, IPv6);\r
+   }\r
   }\r
 \r
   if(qos_free_zone && *qos_free_zone!='0') /* this is currently supported only for IPv4 */\r
@@ -1400,6 +1420,7 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
    }\r
    i++;\r
   }\r
+  /* classmap */\r
   if(ip->min && f > 0)\r
   {\r
    fprintf(f, "%s %d\n", ip->addr, ip->mark);\r
@@ -1467,7 +1488,10 @@ Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf\n\n",version);
   safe_run(str);\r
  } \r
  printf("Total IP count: %d\n", i);\r
- run_iptables_restore();\r
+ if(!mix_new_hosts)\r
+ {\r
+  run_iptables_restore();\r
+ }\r
  if(log_file)\r
  {\r
   fclose(log_file);\r
This page took 0.214393 seconds and 4 git commands to generate.