]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
libxt_CLASSIFY: use guided option parser
authorJan Engelhardt <jengelh@medozas.de>
Tue, 1 Mar 2011 19:14:16 +0000 (20:14 +0100)
committerJan Engelhardt <jengelh@medozas.de>
Wed, 6 Apr 2011 11:12:58 +0000 (13:12 +0200)
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
extensions/libxt_CLASSIFY.c

index e9a036505c07f4a088279a7ff55ff05b4ec272c0..ee0f9e1c4a509a10693fc35d2e5fee2af0329923 100644 (file)
@@ -1,16 +1,12 @@
-/* Shared library add-on to iptables to add CLASSIFY target support. */
-#include <stdbool.h>
 #include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <getopt.h>
-
 #include <xtables.h>
-#include <linux/netfilter/x_tables.h>
 #include <linux/netfilter/xt_CLASSIFY.h>
-#include <linux/types.h>
 #include <linux/pkt_sched.h>
 
+enum {
+       O_SET_CLASS = 0,
+};
+
 static void
 CLASSIFY_help(void)
 {
@@ -19,9 +15,10 @@ CLASSIFY_help(void)
 "--set-class MAJOR:MINOR    Set skb->priority value (always hexadecimal!)\n");
 }
 
-static const struct option CLASSIFY_opts[] = {
-       {.name = "set-class", .has_arg = true, .val = '1'},
-       XT_GETOPT_TABLEEND,
+static const struct xt_option_entry CLASSIFY_opts[] = {
+       {.name = "set-class", .id = O_SET_CLASS, .type = XTTYPE_STRING,
+        .flags = XTOPT_MAND},
+       XTOPT_TABLEEND,
 };
 
 static int CLASSIFY_string_to_priority(const char *s, unsigned int *p)
@@ -35,35 +32,14 @@ static int CLASSIFY_string_to_priority(const char *s, unsigned int *p)
        return 0;
 }
 
-static int
-CLASSIFY_parse(int c, char **argv, int invert, unsigned int *flags,
-      const void *entry,
-      struct xt_entry_target **target)
+static void CLASSIFY_parse(struct xt_option_call *cb)
 {
-       struct xt_classify_target_info *clinfo
-               = (struct xt_classify_target_info *)(*target)->data;
-
-       switch (c) {
-       case '1':
-               if (CLASSIFY_string_to_priority(optarg, &clinfo->priority))
-                       xtables_error(PARAMETER_PROBLEM,
-                                  "Bad class value `%s'", optarg);
-               if (*flags)
-                       xtables_error(PARAMETER_PROBLEM,
-                                  "CLASSIFY: Can't specify --set-class twice");
-               *flags = 1;
-               break;
-       }
+       struct xt_classify_target_info *clinfo = cb->data;
 
-       return 1;
-}
-
-static void
-CLASSIFY_final_check(unsigned int flags)
-{
-       if (!flags)
+       xtables_option_parse(cb);
+       if (CLASSIFY_string_to_priority(cb->arg, &clinfo->priority))
                xtables_error(PARAMETER_PROBLEM,
-                          "CLASSIFY: Parameter --set-class is required");
+                          "Bad class value \"%s\"", cb->arg);
 }
 
 static void
@@ -100,11 +76,10 @@ static struct xtables_target classify_target = {
        .size           = XT_ALIGN(sizeof(struct xt_classify_target_info)),
        .userspacesize  = XT_ALIGN(sizeof(struct xt_classify_target_info)),
        .help           = CLASSIFY_help,
-       .parse          = CLASSIFY_parse,
-       .final_check    = CLASSIFY_final_check,
        .print          = CLASSIFY_print,
        .save           = CLASSIFY_save,
-       .extra_opts     = CLASSIFY_opts,
+       .x6_parse       = CLASSIFY_parse,
+       .x6_options     = CLASSIFY_opts,
 };
 
 void _init(void)