When create_htb=0 is specified in ulogd.conf, DRL now ensures that each identity's
[distributedratelimiting.git] / drl / ulogd_DRL.c
index 97f24bc..8d9b20c 100644 (file)
@@ -713,6 +713,25 @@ static identity_t *new_identity(ident_config *config) {
     return ident;
 }
 
+static int validate_htb_exists(int node, int parent) {
+    FILE *pipe = popen("/sbin/tc class show dev eth0", "r");
+    char line[200];
+
+    while (fgets(line, 200, pipe) != NULL) {
+        int n, p;
+        char ignore[200];
+
+        sscanf(line, "class htb 1:%x parent 1:%x prio %s", &n, &p, ignore);
+        if (n == node && p == parent) {
+            pclose(pipe);
+            return 0;
+        }
+    }
+
+    pclose(pipe);
+    return 1;
+}
+
 /* Determines the validity of the parameters of one ident_config.
  *
  * 0 valid
@@ -754,6 +773,11 @@ static int validate_config(ident_config *config) {
             printlog(LOG_CRITICAL, "When create_htb is disabled in ulogd.conf, an identity must specify the htb_node and htb_parent propertities in its configuration.\n");
             return 1;
         }
+
+        if (validate_htb_exists(config->htb_node, config->htb_parent)) {
+            printlog(LOG_CRITICAL, "Identity specified htb node %x with parent %x.  No such node/parent combo seems to exist!\n", config->htb_node, config->htb_parent);
+            return 1;
+        }
     } else {
         if (config->htb_node > -1 || config->htb_parent > -1) {
             printlog(LOG_WARN, "htb_node or htb_parent are configured but ignored because we're configured to create our own htb hierarchy.\n");
@@ -1735,32 +1759,6 @@ static void reconfig() {
     pthread_rwlock_unlock(&limiter.limiter_lock);
 }
 
-static ulog_output_t drl_op = {
-    .name = "drl",
-    .output = &_output_drl,
-    .signal = NULL, /* This appears to be broken. Using my own handler. */
-    .init = NULL,
-    .fini = NULL,
-};
-
-/* Tests the amount of time it takes to call reconfig(). */
-static void time_reconfig(int iterations) {
-    struct timeval start, end;
-    int i;
-
-    gettimeofday(&start, NULL);
-    for (i = 0; i < iterations; ++i) {
-        reconfig();
-    }
-    gettimeofday(&end, NULL);
-
-    printf("%d reconfigs() took %d seconds and %d microseconds.\n",
-           iterations, end.tv_sec - start.tv_sec, end.tv_usec - start.tv_usec);
-    exit(0);
-
-    // Seems to take about 85ms / iteration
-}
-
 static int stop_enforcement(drl_instance_t *instance) {
     char cmd[300];
     int i;
@@ -1839,13 +1837,9 @@ static void *signal_thread_func(void *args) {
                 break;
         }
     }
-
 }
 
-/* register output plugin with ulogd */
-static void _drl_reg_op(void)
-{
-    ulog_output_t *op = &drl_op;
+static int drl_plugin_init() {
     sigset_t signal_mask;
 
     sigemptyset(&signal_mask);
@@ -1868,8 +1862,6 @@ static void _drl_reg_op(void)
         exit(EXIT_FAILURE);
     }
 
-    register_output(op);
-
     /* start up the thread that will periodically estimate the
      * local rate and set the local limits
      * see estimate.c
@@ -1886,6 +1878,43 @@ static void _drl_reg_op(void)
         printlog(LOG_CRITICAL, "--Switching enforcement on.--\n");
         pthread_rwlock_unlock(&limiter.limiter_lock);
     }
+
+    return 0;
+}
+
+static ulog_output_t drl_op = {
+    .name = "drl",
+    .output = &_output_drl,
+    .signal = NULL, /* This appears to be broken. Using my own handler. */
+    .init = &drl_plugin_init,
+    .fini = NULL,
+};
+
+#if 0
+/* Tests the amount of time it takes to call reconfig(). */
+static void time_reconfig(int iterations) {
+    struct timeval start, end;
+    int i;
+
+    gettimeofday(&start, NULL);
+    for (i = 0; i < iterations; ++i) {
+        reconfig();
+    }
+    gettimeofday(&end, NULL);
+
+    printf("%d reconfigs() took %d seconds and %d microseconds.\n",
+           iterations, end.tv_sec - start.tv_sec, end.tv_usec - start.tv_usec);
+    exit(0);
+
+    // Seems to take about 85ms / iteration
+}
+#endif
+
+/* register output plugin with ulogd */
+static void _drl_reg_op(void)
+{
+    ulog_output_t *op = &drl_op;
+    register_output(op);
 }
 
 void _init(void)