[iptables PATCH 21/23] extensions: libebt_pkttype: Use guided option parser

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Not much to gain here. Maybe implement number parsing with fallback to
get rid of that part from extension parsers?

Signed-off-by: Phil Sutter <phil@xxxxxx>
---
 extensions/libebt_pkttype.c | 45 +++++++++++++++++++------------------
 1 file changed, 23 insertions(+), 22 deletions(-)

diff --git a/extensions/libebt_pkttype.c b/extensions/libebt_pkttype.c
index 4e2d19de7983b..b01b83a1f1f45 100644
--- a/extensions/libebt_pkttype.c
+++ b/extensions/libebt_pkttype.c
@@ -9,7 +9,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <getopt.h>
 #include <netdb.h>
 #include <xtables.h>
 #include <linux/if_packet.h>
@@ -25,10 +24,14 @@ static const char *classes[] = {
 	"fastroute",
 };
 
-static const struct option brpkttype_opts[] =
-{
-	{ "pkttype-type"        , required_argument, 0, '1' },
-	{ 0 }
+enum {
+	O_TYPE,
+};
+
+static const struct xt_option_entry brpkttype_opts[] = {
+	{ .name = "pkttype-type", .id = O_TYPE, .type = XTTYPE_STRING,
+	  .flags = XTOPT_INVERT },
+	XTOPT_TABLEEND,
 };
 
 static void brpkttype_print_help(void)
@@ -40,37 +43,35 @@ static void brpkttype_print_help(void)
 }
 
 
-static int brpkttype_parse(int c, char **argv, int invert, unsigned int *flags,
-			   const void *entry, struct xt_entry_match **match)
+static void brpkttype_parse(struct xt_option_call *cb)
 {
-	struct ebt_pkttype_info *ptinfo = (struct ebt_pkttype_info *)(*match)->data;
-	char *end;
+	struct ebt_pkttype_info *ptinfo = cb->data;
 	long int i;
+	char *end;
+
+	xtables_option_parse(cb);
 
-	switch (c) {
-	case '1':
-		if (invert)
-			ptinfo->invert = 1;
-		i = strtol(optarg, &end, 16);
+	switch (cb->entry->id) {
+	case O_TYPE:
+		ptinfo->invert = cb->invert;
+		i = strtol(cb->arg, &end, 16);
 		if (*end != '\0') {
 			for (i = 0; i < ARRAY_SIZE(classes); i++) {
-				if (!strcasecmp(optarg, classes[i]))
+				if (!strcasecmp(cb->arg, classes[i]))
 					break;
 			}
 			if (i >= ARRAY_SIZE(classes))
-				xtables_error(PARAMETER_PROBLEM, "Could not parse class '%s'", optarg);
+				xtables_error(PARAMETER_PROBLEM,
+					      "Could not parse class '%s'",
+					      cb->arg);
 		}
 		if (i < 0 || i > 255)
 			xtables_error(PARAMETER_PROBLEM, "Problem with specified pkttype class");
 		ptinfo->pkt_type = (uint8_t)i;
 		break;
-	default:
-		return 0;
 	}
-	return 1;
 }
 
-
 static void brpkttype_print(const void *ip, const struct xt_entry_match *match, int numeric)
 {
 	struct ebt_pkttype_info *pt = (struct ebt_pkttype_info *)match->data;
@@ -107,10 +108,10 @@ static struct xtables_match brpkttype_match = {
 	.size		= XT_ALIGN(sizeof(struct ebt_pkttype_info)),
 	.userspacesize	= XT_ALIGN(sizeof(struct ebt_pkttype_info)),
 	.help		= brpkttype_print_help,
-	.parse		= brpkttype_parse,
+	.x6_parse	= brpkttype_parse,
 	.print		= brpkttype_print,
 	.xlate		= brpkttype_xlate,
-	.extra_opts	= brpkttype_opts,
+	.x6_options	= brpkttype_opts,
 };
 
 void _init(void)
-- 
2.43.0





[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux