]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
libxt_AUDIT: use guided option parser
authorJan Engelhardt <jengelh@medozas.de>
Tue, 1 Mar 2011 19:11:01 +0000 (20:11 +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_AUDIT.c

index a6ab37f91ac5d90788348931f6a26cbc69452ca3..86a61cbe72022b1b07644a89ab0b76e99a683aba 100644 (file)
@@ -5,16 +5,15 @@
  *
  * This program is distributed under the terms of GNU GPL v2, 1991
  */
-
-#include <stdbool.h>
 #include <stdio.h>
 #include <string.h>
-#include <stdlib.h>
-#include <getopt.h>
-
 #include <xtables.h>
 #include <linux/netfilter/xt_AUDIT.h>
 
+enum {
+       O_AUDIT_TYPE = 0,
+};
+
 static void audit_help(void)
 {
        printf(
@@ -22,46 +21,26 @@ static void audit_help(void)
 "  --type TYPE         Action type to be recorded.\n");
 }
 
-static const struct option audit_opts[] = {
-       {.name = "type", .has_arg = true, .val = 't'},
-       XT_GETOPT_TABLEEND,
+static const struct xt_option_entry audit_opts[] = {
+       {.name = "type", .id = O_AUDIT_TYPE, .type = XTTYPE_STRING,
+        .flags = XTOPT_MAND},
+       XTOPT_TABLEEND,
 };
 
-static int audit_parse(int c, char **argv, int invert, unsigned int *flags,
-                     const void *entry, struct xt_entry_target **target)
-{
-       struct xt_audit_info *einfo
-               = (struct xt_audit_info *)(*target)->data;
-
-       switch (c) {
-       case 't':
-               if (!strcasecmp(optarg, "accept"))
-                       einfo->type = XT_AUDIT_TYPE_ACCEPT;
-               else if (!strcasecmp(optarg, "drop"))
-                       einfo->type = XT_AUDIT_TYPE_DROP;
-               else if (!strcasecmp(optarg, "reject"))
-                       einfo->type = XT_AUDIT_TYPE_REJECT;
-               else
-                       xtables_error(PARAMETER_PROBLEM,
-                                  "Bad action type value `%s'", optarg);
-
-               if (*flags)
-                       xtables_error(PARAMETER_PROBLEM,
-                                  "AUDIT: Can't specify --type twice");
-               *flags = 1;
-               break;
-       default:
-               return 0;
-       }
-
-       return 1;
-}
-
-static void audit_final_check(unsigned int flags)
+static void audit_parse(struct xt_option_call *cb)
 {
-       if (!flags)
+       struct xt_audit_info *einfo = cb->data;
+
+       xtables_option_parse(cb);
+       if (strcasecmp(cb->arg, "accept") == 0)
+               einfo->type = XT_AUDIT_TYPE_ACCEPT;
+       else if (strcasecmp(cb->arg, "drop") == 0)
+               einfo->type = XT_AUDIT_TYPE_DROP;
+       else if (strcasecmp(cb->arg, "reject") == 0)
+               einfo->type = XT_AUDIT_TYPE_REJECT;
+       else
                xtables_error(PARAMETER_PROBLEM,
-                          "AUDIT target: Parameter --type is required");
+                          "Bad action type value \"%s\"", cb->arg);
 }
 
 static void audit_print(const void *ip, const struct xt_entry_target *target,
@@ -110,11 +89,10 @@ static struct xtables_target audit_tg_reg = {
        .size           = XT_ALIGN(sizeof(struct xt_audit_info)),
        .userspacesize  = XT_ALIGN(sizeof(struct xt_audit_info)),
        .help           = audit_help,
-       .parse          = audit_parse,
-       .final_check    = audit_final_check,
        .print          = audit_print,
        .save           = audit_save,
-       .extra_opts     = audit_opts,
+       .x6_parse       = audit_parse,
+       .x6_options     = audit_opts,
 };
 
 void _init(void)