]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
libxt_CHECKSUM: use guided option parser
authorJan Engelhardt <jengelh@medozas.de>
Sun, 27 Feb 2011 15:54:27 +0000 (16:54 +0100)
committerJan Engelhardt <jengelh@medozas.de>
Wed, 6 Apr 2011 10:54:22 +0000 (12:54 +0200)
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
extensions/libxt_CHECKSUM.c

index 83b3d699e13963f5309954dd8db62f43cd459c3f..df9f9b3c4358d6262293c3a64c460e7027d1526e 100644 (file)
@@ -8,15 +8,14 @@
  *
  * libxt_CHECKSUM.c borrowed some bits from libipt_ECN.c
  */
-#include <stdbool.h>
 #include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <getopt.h>
-
 #include <xtables.h>
 #include <linux/netfilter/xt_CHECKSUM.h>
 
+enum {
+       O_CHECKSUM_FILL = 0,
+};
+
 static void CHECKSUM_help(void)
 {
        printf(
@@ -24,34 +23,18 @@ static void CHECKSUM_help(void)
 "  --checksum-fill                     Fill in packet checksum.\n");
 }
 
-static const struct option CHECKSUM_opts[] = {
-       {.name = "checksum-fill", .has_arg = false, .val = 'F'},
-       XT_GETOPT_TABLEEND,
+static const struct xt_option_entry CHECKSUM_opts[] = {
+       {.name = "checksum-fill", .id = O_CHECKSUM_FILL,
+        .flags = XTOPT_MAND, .type = XTTYPE_NONE},
+       XTOPT_TABLEEND,
 };
 
-static int CHECKSUM_parse(int c, char **argv, int invert, unsigned int *flags,
-                     const void *entry, struct xt_entry_target **target)
+static void CHECKSUM_parse(struct xt_option_call *cb)
 {
-       struct xt_CHECKSUM_info *einfo
-               = (struct xt_CHECKSUM_info *)(*target)->data;
-
-       switch (c) {
-       case 'F':
-               xtables_param_act(XTF_ONLY_ONCE, "CHECKSUM", "--checksum-fill",
-                       *flags & XT_CHECKSUM_OP_FILL);
-               einfo->operation = XT_CHECKSUM_OP_FILL;
-               *flags |= XT_CHECKSUM_OP_FILL;
-               break;
-       }
+       struct xt_CHECKSUM_info *einfo = cb->data;
 
-       return 1;
-}
-
-static void CHECKSUM_check(unsigned int flags)
-{
-       if (!flags)
-               xtables_error(PARAMETER_PROBLEM,
-                          "CHECKSUM target: Parameter --checksum-fill is required");
+       xtables_option_parse(cb);
+       einfo->operation = XT_CHECKSUM_OP_FILL;
 }
 
 static void CHECKSUM_print(const void *ip, const struct xt_entry_target *target,
@@ -82,11 +65,10 @@ static struct xtables_target checksum_tg_reg = {
        .size           = XT_ALIGN(sizeof(struct xt_CHECKSUM_info)),
        .userspacesize  = XT_ALIGN(sizeof(struct xt_CHECKSUM_info)),
        .help           = CHECKSUM_help,
-       .parse          = CHECKSUM_parse,
-       .final_check    = CHECKSUM_check,
        .print          = CHECKSUM_print,
        .save           = CHECKSUM_save,
-       .extra_opts     = CHECKSUM_opts,
+       .x6_parse       = CHECKSUM_parse,
+       .x6_options     = CHECKSUM_opts,
 };
 
 void _init(void)