Skip to contentSkip to conversation

ebtables: Use the shared commandline parser

PATCH In review Phil Sutter 1 participant 15 messages Nov 29, 2023 – Dec 5, 2023 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

cover ebtables: Use the shared commandline parser

This series converts do_commandeb() and do_commandeb_xlate() to call do_parse() from xshared.c instead of iterating over argv themselves.

Patches 1-6 prepare the shared (parser) code for use by ebtables. Patches 7-11 prepare ebtables code for the following integration in patch 13. Patch 12 is a minor refactoring in xshared but fits fine right before the merge as the introduced helper function is called two more times by it.

Phil Sutter (13):
xshared: do_parse: Skip option checking for CMD_DELETE_NUM
xshared: Perform protocol value parsing in callback
xshared: Turn command_default() into a callback
xshared: Introduce print_help callback (again)
xshared: Support rule range deletion in do_parse()
xshared: Support for ebtables' --change-counters command ebtables{,-translate}: Convert if-clause to switch()
ebtables: Change option values to avoid clashes
ebtables: Pass struct iptables_command_state to print_help()
ebtables: Make 'h' case just a call to print_help()
ebtables: Use struct xt_cmd_parse
xshared: Introduce option_test_and_reject()
ebtables: Use do_parse() from xshared

 iptables/ip6tables.c            |   2 +
 iptables/iptables.c             |   2 +
 iptables/nft-arp.c              |   2 +
 iptables/nft-bridge.c           | 121 +++++
 iptables/nft-bridge.h           |  13 +-
 iptables/nft-cmd.h              |   7 -
 iptables/nft-ipv4.c             |   2 +
 iptables/nft-ipv6.c             |   2 +
 iptables/nft.h                  |   1 -
 iptables/xshared.c              | 218 +++++++--
 iptables/xshared.h              |  36 +-
 iptables/xtables-eb-translate.c | 491 +++----------------
 iptables/xtables-eb.c           | 839 ++++++--------------------------
 13 files changed, 567 insertions(+), 1169 deletions(-)
Signature · 1 line
2.41.0
author reviewer
#1 lore raw

PATCH 1/13 xshared: do_parse: Skip option checking for CMD_DELETE_NUM

This command will delete a rule by its number, not rule spec. No -i/-o options are expected on commandline.

---
 iptables/xshared.c | 1 -
 1 file changed, 1 deletion(-)
iptables/xshared.c +0 -1
index dca744773d773..53e6720169950 100644
@@ -1837,7 +1837,6 @@ void do_parse(int argc, char *argv[],
 
 	if (p->command == CMD_APPEND ||
 	    p->command == CMD_DELETE ||
-	    p->command == CMD_DELETE_NUM ||
 	    p->command == CMD_CHECK ||
 	    p->command == CMD_INSERT ||
 	    p->command == CMD_REPLACE) {
Signature · 1 line
2.41.0
author reviewer
#2 lore raw

PATCH 2/13 xshared: Perform protocol value parsing in callback

In reply to Phil Sutter

The code is same in iptables and ip6tables, but different in ebtables. Therefore move it into the callback to keep that part of do_parse() generic.

---
 iptables/xshared.c | 22 ++++++++++++++--------
 iptables/xshared.h |  1 -
 2 files changed, 14 insertions(+), 9 deletions(-)
iptables/xshared.c +14 -8
index 53e6720169950..ff809f2be3438 100644
@@ -1547,12 +1547,6 @@ void do_parse(int argc, char *argv[],
 				*cs->protocol = tolower(*cs->protocol);
 
 			cs->protocol = optarg;
-			args->proto = xtables_parse_protocol(cs->protocol);
-
-			if (args->proto == 0 &&
-			    (args->invflags & XT_INV_PROTO))
-				xtables_error(PARAMETER_PROBLEM,
-					   "rule would never match protocol");
 
 			/* This needs to happen here to parse extensions */
 			if (p->ops->proto_parse)
@@ -1865,7 +1859,13 @@ void do_parse(int argc, char *argv[],
 void ipv4_proto_parse(struct iptables_command_state *cs,
 		      struct xtables_args *args)
 {
-	cs->fw.ip.proto = args->proto;
+	cs->fw.ip.proto = xtables_parse_protocol(cs->protocol);
+
+	if (cs->fw.ip.proto == 0 &&
+	    (args->invflags & XT_INV_PROTO))
+		xtables_error(PARAMETER_PROBLEM,
+			      "rule would never match protocol");
+
 	cs->fw.ip.invflags = args->invflags;
 }
 
@@ -1881,7 +1881,13 @@ static int is_exthdr(uint16_t proto)
 void ipv6_proto_parse(struct iptables_command_state *cs,
 		      struct xtables_args *args)
 {
-	cs->fw6.ipv6.proto = args->proto;
+	cs->fw6.ipv6.proto = xtables_parse_protocol(cs->protocol);
+
+	if (cs->fw6.ipv6.proto == 0 &&
+	    (args->invflags & XT_INV_PROTO))
+		xtables_error(PARAMETER_PROBLEM,
+			      "rule would never match protocol");
+
 	cs->fw6.ipv6.invflags = args->invflags;
 
 	/* this is needed for ip6tables-legacy only */
iptables/xshared.h +0 -1
index d2ce72e90824a..3df2153fd6a10 100644
@@ -249,7 +249,6 @@ struct addr_mask {
 
 struct xtables_args {
 	int		family;
-	uint16_t	proto;
 	uint8_t		flags;
 	uint16_t	invflags;
 	char		iniface[IFNAMSIZ], outiface[IFNAMSIZ];
Signature · 1 line
2.41.0
author reviewer
#3 lore raw

PATCH 3/13 xshared: Turn command_default() into a callback

In reply to Phil Sutter

Ebtables' variant is pretty different since all extensions are loaded up front and some targets serve as "watcher" extensions, so let variants specify the function to call for extension parameters.

---
 iptables/ip6tables.c | 1 +
 iptables/iptables.c  | 1 +
 iptables/nft-arp.c   | 1 +
 iptables/nft-ipv4.c  | 1 +
 iptables/nft-ipv6.c  | 1 +
 iptables/xshared.c   | 6 +++---
 iptables/xshared.h   | 4 ++++
 7 files changed, 12 insertions(+), 3 deletions(-)
iptables/ip6tables.c +1 -0
index 53eeb6e90bbb7..96603756324a5 100644
@@ -670,6 +670,7 @@ int do_command6(int argc, char *argv[], char **table,
 		.post_parse	= ipv6_post_parse,
 		.option_name	= ip46t_option_name,
 		.option_invert	= ip46t_option_invert,
+		.command_default = command_default,
 	};
 	struct xt_cmd_parse p = {
 		.table		= *table,
iptables/iptables.c +1 -0
index 69dd289060528..b57483ef44514 100644
@@ -664,6 +664,7 @@ int do_command4(int argc, char *argv[], char **table,
 		.post_parse	= ipv4_post_parse,
 		.option_name	= ip46t_option_name,
 		.option_invert	= ip46t_option_invert,
+		.command_default = command_default,
 	};
 	struct xt_cmd_parse p = {
 		.table		= *table,
iptables/nft-arp.c +1 -0
index c009dd83e26cf..f3e2920ac6d15 100644
@@ -858,6 +858,7 @@ struct nft_family_ops nft_family_ops_arp = {
 		.post_parse	= nft_arp_post_parse,
 		.option_name	= nft_arp_option_name,
 		.option_invert	= nft_arp_option_invert,
+		.command_default = command_default,
 	},
 	.rule_to_cs		= nft_rule_to_iptables_command_state,
 	.init_cs		= nft_arp_init_cs,
iptables/nft-ipv4.c +1 -0
index c140ffde34b62..754c776473143 100644
@@ -354,6 +354,7 @@ struct nft_family_ops nft_family_ops_ipv4 = {
 		.post_parse	= ipv4_post_parse,
 		.option_name	= ip46t_option_name,
 		.option_invert	= ip46t_option_invert,
+		.command_default = command_default,
 	},
 	.rule_to_cs		= nft_rule_to_iptables_command_state,
 	.clear_cs		= xtables_clear_iptables_command_state,
iptables/nft-ipv6.c +1 -0
index 4bf4f54f18a00..b1b5891013577 100644
@@ -345,6 +345,7 @@ struct nft_family_ops nft_family_ops_ipv6 = {
 		.post_parse	= ipv6_post_parse,
 		.option_name	= ip46t_option_name,
 		.option_invert	= ip46t_option_invert,
+		.command_default = command_default,
 	},
 	.rule_to_cs		= nft_rule_to_iptables_command_state,
 	.clear_cs		= xtables_clear_iptables_command_state,
iptables/xshared.c +3 -3
index ff809f2be3438..29b3992904e68 100644
@@ -122,8 +122,8 @@ static struct xtables_match *load_proto(struct iptables_command_state *cs)
 			  cs->options & OPT_NUMERIC, &cs->matches);
 }
 
-static int command_default(struct iptables_command_state *cs,
-			   struct xtables_globals *gl, bool invert)
+int command_default(struct iptables_command_state *cs,
+		    struct xtables_globals *gl, bool invert)
 {
 	struct xtables_rule_match *matchp;
 	struct xtables_match *m;
@@ -1784,7 +1784,7 @@ void do_parse(int argc, char *argv[],
 			exit_tryhelp(2, p->line);
 
 		default:
-			if (command_default(cs, xt_params, invert))
+			if (p->ops->command_default(cs, xt_params, invert))
 				/* cf. ip6tables.c */
 				continue;
 			break;
iptables/xshared.h +4 -0
index 3df2153fd6a10..bf24fd568a6f5 100644
@@ -272,6 +272,8 @@ struct xt_cmd_parse_ops {
 			      struct xtables_args *args);
 	const char *(*option_name)(int option);
 	int	(*option_invert)(int option);
+	int	(*command_default)(struct iptables_command_state *cs,
+				   struct xtables_globals *gl, bool invert);
 };
 
 struct xt_cmd_parse {
@@ -289,6 +291,8 @@ struct xt_cmd_parse {
 
 const char *ip46t_option_name(int option);
 int ip46t_option_invert(int option);
+int command_default(struct iptables_command_state *cs,
+		    struct xtables_globals *gl, bool invert);
 
 void do_parse(int argc, char *argv[],
 	      struct xt_cmd_parse *p, struct iptables_command_state *cs,
Signature · 1 line
2.41.0
author reviewer
#4 lore raw

PATCH 4/13 xshared: Introduce print_help callback (again)

In reply to Phil Sutter

Prep work for ebtables parser to use do_parse(). Adding more special casing to xtables_printhelp() causes a mess, so work with a callback again.

---
 iptables/ip6tables.c | 1 +
 iptables/iptables.c  | 1 +
 iptables/nft-arp.c   | 1 +
 iptables/nft-ipv4.c  | 1 +
 iptables/nft-ipv6.c  | 1 +
 iptables/xshared.c   | 6 +++---
 iptables/xshared.h   | 2 ++
 7 files changed, 10 insertions(+), 3 deletions(-)
iptables/ip6tables.c +1 -0
index 96603756324a5..4b5d4ac6878b7 100644
@@ -671,6 +671,7 @@ int do_command6(int argc, char *argv[], char **table,
 		.option_name	= ip46t_option_name,
 		.option_invert	= ip46t_option_invert,
 		.command_default = command_default,
+		.print_help	= xtables_printhelp,
 	};
 	struct xt_cmd_parse p = {
 		.table		= *table,
iptables/iptables.c +1 -0
index b57483ef44514..5ae28fe04a5f5 100644
@@ -665,6 +665,7 @@ int do_command4(int argc, char *argv[], char **table,
 		.option_name	= ip46t_option_name,
 		.option_invert	= ip46t_option_invert,
 		.command_default = command_default,
+		.print_help	= xtables_printhelp,
 	};
 	struct xt_cmd_parse p = {
 		.table		= *table,
iptables/nft-arp.c +1 -0
index f3e2920ac6d15..6011620cf52a7 100644
@@ -859,6 +859,7 @@ struct nft_family_ops nft_family_ops_arp = {
 		.option_name	= nft_arp_option_name,
 		.option_invert	= nft_arp_option_invert,
 		.command_default = command_default,
+		.print_help	= xtables_printhelp,
 	},
 	.rule_to_cs		= nft_rule_to_iptables_command_state,
 	.init_cs		= nft_arp_init_cs,
iptables/nft-ipv4.c +1 -0
index 754c776473143..979880a3e7702 100644
@@ -355,6 +355,7 @@ struct nft_family_ops nft_family_ops_ipv4 = {
 		.option_name	= ip46t_option_name,
 		.option_invert	= ip46t_option_invert,
 		.command_default = command_default,
+		.print_help	= xtables_printhelp,
 	},
 	.rule_to_cs		= nft_rule_to_iptables_command_state,
 	.clear_cs		= xtables_clear_iptables_command_state,
iptables/nft-ipv6.c +1 -0
index b1b5891013577..e4b1714d00c2f 100644
@@ -346,6 +346,7 @@ struct nft_family_ops nft_family_ops_ipv6 = {
 		.option_name	= ip46t_option_name,
 		.option_invert	= ip46t_option_invert,
 		.command_default = command_default,
+		.print_help	= xtables_printhelp,
 	},
 	.rule_to_cs		= nft_rule_to_iptables_command_state,
 	.clear_cs		= xtables_clear_iptables_command_state,
iptables/xshared.c +3 -3
index 29b3992904e68..177f3ddd1c19e 100644
@@ -1108,9 +1108,9 @@ int print_match_save(const struct xt_entry_match *e, const void *ip)
 	return 0;
 }
 
-static void
-xtables_printhelp(const struct xtables_rule_match *matches)
+void xtables_printhelp(struct iptables_command_state *cs)
 {
+	const struct xtables_rule_match *matches = cs->matches;
 	const char *prog_name = xt_params->program_name;
 	const char *prog_vers = xt_params->program_version;
 
@@ -1527,7 +1527,7 @@ void do_parse(int argc, char *argv[],
 				xtables_find_match(cs->protocol,
 					XTF_TRY_LOAD, &cs->matches);
 
-			xtables_printhelp(cs->matches);
+			p->ops->print_help(cs);
 			xtables_clear_iptables_command_state(cs);
 			xtables_free_opts(1);
 			xtables_fini();
iptables/xshared.h +2 -0
index bf24fd568a6f5..69f50e505cb9b 100644
@@ -274,6 +274,7 @@ struct xt_cmd_parse_ops {
 	int	(*option_invert)(int option);
 	int	(*command_default)(struct iptables_command_state *cs,
 				   struct xtables_globals *gl, bool invert);
+	void	(*print_help)(struct iptables_command_state *cs);
 };
 
 struct xt_cmd_parse {
@@ -289,6 +290,7 @@ struct xt_cmd_parse {
 	struct xt_cmd_parse_ops		*ops;
 };
 
+void xtables_printhelp(struct iptables_command_state *cs);
 const char *ip46t_option_name(int option);
 int ip46t_option_invert(int option);
 int command_default(struct iptables_command_state *cs,
Signature · 1 line
2.41.0
author reviewer
#5 lore raw

PATCH 5/13 xshared: Support rule range deletion in do_parse()

In reply to Phil Sutter

This is a distinct ebtables feature. Introduce struct xt_cmd_parse::rule_ranges boolean indicating support for it and bail otherwise if a range was specified by the user.

---
 iptables/xshared.c | 34 +++++++++++++++++++++++++++++++++-
 iptables/xshared.h |  2 ++
 2 files changed, 35 insertions(+), 1 deletion(-)
iptables/xshared.c +33 -1
index 177f3ddd1c19e..62ae4141325ed 100644
@@ -903,6 +903,38 @@ static int parse_rulenumber(const char *rule)
 	return rulenum;
 }
 
+static void parse_rule_range(struct xt_cmd_parse *p, const char *argv)
+{
+	char *colon = strchr(argv, ':'), *buffer;
+
+	if (colon) {
+		if (!p->rule_ranges)
+			xtables_error(PARAMETER_PROBLEM,
+				      "Rule ranges are not supported");
+
+		*colon = '\0';
+		if (*(colon + 1) == '\0')
+			p->rulenum_end = -1; /* Until the last rule */
+		else {
+			p->rulenum_end = strtol(colon + 1, &buffer, 10);
+			if (*buffer != '\0' || p->rulenum_end == 0)
+				xtables_error(PARAMETER_PROBLEM,
+					      "Invalid rule range end`%s'",
+					      colon + 1);
+		}
+	}
+	if (colon == argv)
+		p->rulenum = 1; /* Beginning with the first rule */
+	else {
+		p->rulenum = strtol(argv, &buffer, 10);
+		if (*buffer != '\0' || p->rulenum == 0)
+			xtables_error(PARAMETER_PROBLEM,
+				      "Invalid rule number `%s'", argv);
+	}
+	if (!colon)
+		p->rulenum_end = p->rulenum;
+}
+
 /* list the commands an option is allowed with */
 #define CMD_IDRAC	CMD_INSERT | CMD_DELETE | CMD_REPLACE | \
 			CMD_APPEND | CMD_CHECK
@@ -1411,7 +1443,7 @@ void do_parse(int argc, char *argv[],
 			add_command(&p->command, CMD_DELETE, CMD_NONE, invert);
 			p->chain = optarg;
 			if (xs_has_arg(argc, argv)) {
-				p->rulenum = parse_rulenumber(argv[optind++]);
+				parse_rule_range(p, argv[optind++]);
 				p->command = CMD_DELETE_NUM;
 			}
 			break;
iptables/xshared.h +2 -0
index 69f50e505cb9b..2fd15c725faaf 100644
@@ -280,6 +280,7 @@ struct xt_cmd_parse_ops {
 struct xt_cmd_parse {
 	unsigned int			command;
 	unsigned int			rulenum;
+	unsigned int			rulenum_end;
 	char				*table;
 	const char			*chain;
 	const char			*newname;
@@ -287,6 +288,7 @@ struct xt_cmd_parse {
 	bool				restore;
 	int				line;
 	int				verbose;
+	bool				rule_ranges;
 	struct xt_cmd_parse_ops		*ops;
 };
 
Signature · 1 line
2.41.0
author reviewer
#6 lore raw

PATCH 6/13 xshared: Support for ebtables' --change-counters command

In reply to Phil Sutter

This is tricky because the short-option clashes with the --check command. OTOH, ebtables supports --check as well (though without short-option), so making do_parse() detect ebtables based on struct xtables_args::family is probably still the least messy option.

---
 iptables/nft-cmd.h |  7 ------
 iptables/xshared.c | 57 +++++++++++++++++++++++++++++++++++++++++++++-
 iptables/xshared.h | 11 ++++++++-
 3 files changed, 66 insertions(+), 9 deletions(-)
iptables/nft-cmd.h +0 -7
index 8163b82c3511f..00ecc80249f0d 100644
@@ -7,13 +7,6 @@
 
 struct nftnl_rule;
 
-enum {
-	CTR_OP_INC_PKTS = 1 << 0,
-	CTR_OP_DEC_PKTS = 1 << 1,
-	CTR_OP_INC_BYTES = 1 << 2,
-	CTR_OP_DEC_BYTES = 1 << 3,
-};
-
 struct nft_cmd {
 	struct list_head		head;
 	int				command;
iptables/xshared.c +56 -1

79 lines not on this page · raw message

iptables/xshared.h +10 -1
index 2fd15c725faaf..68acfb4b406fb 100644
@@ -69,8 +69,9 @@ enum {
 	CMD_LIST_RULES		= 1 << 12,
 	CMD_ZERO_NUM		= 1 << 13,
 	CMD_CHECK		= 1 << 14,
+	CMD_CHANGE_COUNTERS	= 1 << 15, /* ebtables only */
 };
-#define NUMBER_OF_CMD		16
+#define NUMBER_OF_CMD		17
 
 struct xtables_globals;
 struct xtables_rule_match;
@@ -247,6 +248,13 @@ struct addr_mask {
 	} mask;
 };
 
+enum {
+	CTR_OP_INC_PKTS = 1 << 0,
+	CTR_OP_DEC_PKTS = 1 << 1,
+	CTR_OP_INC_BYTES = 1 << 2,
+	CTR_OP_DEC_BYTES = 1 << 3,
+};
+
 struct xtables_args {
 	int		family;
 	uint8_t		flags;
@@ -261,6 +269,7 @@ struct xtables_args {
 	const char	*arp_hlen, *arp_opcode;
 	const char	*arp_htype, *arp_ptype;
 	unsigned long long pcnt_cnt, bcnt_cnt;
+	uint8_t		counter_op;
 	int		wait;
 };
 
Signature · 1 line
2.41.0
author reviewer
#7 lore raw

PATCH 7/13 ebtables{,-translate}: Convert if-clause to switch()

In reply to Phil Sutter

Parser merge prep work, align final do_commandeb*() parts with do_commandx().

---
 iptables/xtables-eb-translate.c | 24 +++++++++--------
 iptables/xtables-eb.c           | 46 ++++++++++++++++++++-------------
 2 files changed, 41 insertions(+), 29 deletions(-)
iptables/xtables-eb-translate.c +13 -11
index da7e5e3dda1f3..d0fec9c6d5ae3 100644
@@ -497,23 +497,25 @@ static int do_commandeb_xlate(struct nft_handle *h, int argc, char *argv[], char
 
 	cs.eb.ethproto = htons(cs.eb.ethproto);
 
-	if (command == 'P') {
-		return 0;
-	} else if (command == 'F') {
-			if (p.chain) {
-				printf("flush chain bridge %s %s\n", p.table, p.chain);
-			} else {
-				printf("flush table bridge %s\n", p.table);
-			}
-			ret = 1;
-	} else if (command == 'A') {
+	switch (command) {
+	case 'F':
+		if (p.chain) {
+			printf("flush chain bridge %s %s\n", p.table, p.chain);
+		} else {
+			printf("flush table bridge %s\n", p.table);
+		}
+		ret = 1;
+		break;
+	case 'A':
 		ret = nft_rule_eb_xlate_add(h, &p, &cs, true);
 		if (!ret)
 			print_ebt_cmd(argc, argv);
-	} else if (command == 'I') {
+		break;
+	case 'I':
 		ret = nft_rule_eb_xlate_add(h, &p, &cs, false);
 		if (!ret)
 			print_ebt_cmd(argc, argv);
+		break;
 	}
 
 	ebt_cs_clean(&cs);
iptables/xtables-eb.c +28 -18

75 lines not on this page · raw message

Signature · 1 line
2.41.0
author reviewer
#8 lore raw

PATCH 8/13 ebtables: Change option values to avoid clashes

In reply to Phil Sutter

In order to parse input using do_parse(), distinct ebtables option's values have to be distinct from others. Since arptables uses values 2-8 already, resort to values >10.

---
 iptables/xtables-eb-translate.c | 14 +++++++-------
 iptables/xtables-eb.c           | 24 ++++++++++++------------
 2 files changed, 19 insertions(+), 19 deletions(-)
iptables/xtables-eb-translate.c +7 -7
index d0fec9c6d5ae3..a2ab318cff251 100644
@@ -292,9 +292,9 @@ static int do_commandeb_xlate(struct nft_handle *h, int argc, char *argv[], char
 			table_set = true;
 			break;
 		case 'i': /* Input interface */
-		case 2  : /* Logical input interface */
+		case 15 : /* Logical input interface */
 		case 'o': /* Output interface */
-		case 3  : /* Logical output interface */
+		case 16 : /* Logical output interface */
 		case 'j': /* Target */
 		case 'p': /* Net family protocol */
 		case 's': /* Source mac */
@@ -316,7 +316,7 @@ static int do_commandeb_xlate(struct nft_handle *h, int argc, char *argv[], char
 
 				ebtables_parse_interface(optarg, cs.eb.in);
 				break;
-			} else if (c == 2) {
+			} else if (c == 15) {
 				ebt_check_option2(&flags, OPT_LOGICALIN);
 				if (selected_chain > 2 && selected_chain < NF_BR_BROUTING)
 					xtables_error(PARAMETER_PROBLEM,
@@ -336,7 +336,7 @@ static int do_commandeb_xlate(struct nft_handle *h, int argc, char *argv[], char
 
 				ebtables_parse_interface(optarg, cs.eb.out);
 				break;
-			} else if (c == 3) {
+			} else if (c == 16) {
 				ebt_check_option2(&flags, OPT_LOGICALOUT);
 				if (selected_chain < 2 || selected_chain == NF_BR_BROUTING)
 					xtables_error(PARAMETER_PROBLEM,
@@ -424,14 +424,14 @@ static int do_commandeb_xlate(struct nft_handle *h, int argc, char *argv[], char
 				xtables_error(PARAMETER_PROBLEM,
 					      "Sorry, protocols have values above or equal to 0x0600");
 			break;
-		case 4  : /* Lc */
+		case 17 : /* Lc */
 			ebt_check_option2(&flags, LIST_C);
 			if (command != 'L')
 				xtables_error(PARAMETER_PROBLEM,
 					      "Use --Lc with -L");
 			flags |= LIST_C;
 			break;
-		case 5  : /* Ln */
+		case 18 : /* Ln */
 			ebt_check_option2(&flags, LIST_N);
 			if (command != 'L')
 				xtables_error(PARAMETER_PROBLEM,
@@ -441,7 +441,7 @@ static int do_commandeb_xlate(struct nft_handle *h, int argc, char *argv[], char
 					      "--Lx is not compatible with --Ln");
 			flags |= LIST_N;
 			break;
-		case 6  : /* Lx */
+		case 19 : /* Lx */
 			ebt_check_option2(&flags, LIST_X);
 			if (command != 'L')
 				xtables_error(PARAMETER_PROBLEM,
iptables/xtables-eb.c +12 -12
index db75e65caa02a..9afaa614bac5b 100644
@@ -196,17 +196,17 @@ struct option ebt_original_options[] =
 	{ "insert"         , required_argument, 0, 'I' },
 	{ "delete"         , required_argument, 0, 'D' },
 	{ "list"           , optional_argument, 0, 'L' },
-	{ "Lc"             , no_argument      , 0, 4   },
-	{ "Ln"             , no_argument      , 0, 5   },
-	{ "Lx"             , no_argument      , 0, 6   },
+	{ "Lc"             , no_argument      , 0, 17  },
+	{ "Ln"             , no_argument      , 0, 18  },
+	{ "Lx"             , no_argument      , 0, 19  },
 	{ "Lmac2"          , no_argument      , 0, 12  },
 	{ "zero"           , optional_argument, 0, 'Z' },
 	{ "flush"          , optional_argument, 0, 'F' },
 	{ "policy"         , required_argument, 0, 'P' },
 	{ "in-interface"   , required_argument, 0, 'i' },
 	{ "in-if"          , required_argument, 0, 'i' },
-	{ "logical-in"     , required_argument, 0, 2   },
-	{ "logical-out"    , required_argument, 0, 3   },
+	{ "logical-in"     , required_argument, 0, 15  },
+	{ "logical-out"    , required_argument, 0, 16  },
 	{ "out-interface"  , required_argument, 0, 'o' },
 	{ "out-if"         , required_argument, 0, 'o' },
 	{ "version"        , no_argument      , 0, 'V' },
@@ -940,9 +940,9 @@ int do_commandeb(struct nft_handle *h, int argc, char *argv[], char **table,
 			table_set = true;
 			break;
 		case 'i': /* Input interface */
-		case 2  : /* Logical input interface */
+		case 15 : /* Logical input interface */
 		case 'o': /* Output interface */
-		case 3  : /* Logical output interface */
+		case 16 : /* Logical output interface */
 		case 'j': /* Target */
 		case 'p': /* Net family protocol */
 		case 's': /* Source mac */
@@ -965,7 +965,7 @@ int do_commandeb(struct nft_handle *h, int argc, char *argv[], char **table,
 
 				ebtables_parse_interface(optarg, cs.eb.in);
 				break;
-			} else if (c == 2) {
+			} else if (c == 15) {
 				ebt_check_option2(&flags, OPT_LOGICALIN);
 				if (selected_chain > 2 && selected_chain < NF_BR_BROUTING)
 					xtables_error(PARAMETER_PROBLEM,
@@ -985,7 +985,7 @@ int do_commandeb(struct nft_handle *h, int argc, char *argv[], char **table,
 
 				ebtables_parse_interface(optarg, cs.eb.out);
 				break;
-			} else if (c == 3) {
+			} else if (c == 16) {
 				ebt_check_option2(&flags, OPT_LOGICALOUT);
 				if (selected_chain < 2 || selected_chain == NF_BR_BROUTING)
 					xtables_error(PARAMETER_PROBLEM,
@@ -1073,14 +1073,14 @@ int do_commandeb(struct nft_handle *h, int argc, char *argv[], char **table,
 				xtables_error(PARAMETER_PROBLEM,
 					      "Sorry, protocols have values above or equal to 0x0600");
 			break;
-		case 4  : /* Lc */
+		case 17 : /* Lc */
 			ebt_check_option2(&flags, LIST_C);
 			if (command != 'L')
 				xtables_error(PARAMETER_PROBLEM,
 					      "Use --Lc with -L");
 			flags |= LIST_C;
 			break;
-		case 5  : /* Ln */
+		case 18 : /* Ln */
 			ebt_check_option2(&flags, LIST_N);
 			if (command != 'L')
 				xtables_error(PARAMETER_PROBLEM,
@@ -1090,7 +1090,7 @@ int do_commandeb(struct nft_handle *h, int argc, char *argv[], char **table,
 					      "--Lx is not compatible with --Ln");
 			flags |= LIST_N;
 			break;
-		case 6  : /* Lx */
+		case 19 : /* Lx */
 			ebt_check_option2(&flags, LIST_X);
 			if (command != 'L')
 				xtables_error(PARAMETER_PROBLEM,
Signature · 1 line
2.41.0
author reviewer
#9 lore raw

PATCH 9/13 ebtables: Pass struct iptables_command_state to print_help()

In reply to Phil Sutter

Parameters passed by the sole caller came from there already, apart from 'table' which is not used (ebtables-nft does not have per-table help texts).

---
 iptables/xtables-eb.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
iptables/xtables-eb.c +5 -6
index 9afaa614bac5b..017e1ad364840 100644
@@ -303,9 +303,11 @@ static struct option *merge_options(struct option *oldopts,
 	return merge;
 }
 
-static void print_help(const struct xtables_target *t,
-		       const struct xtables_rule_match *m, const char *table)
+static void print_help(struct iptables_command_state *cs)
 {
+	const struct xtables_rule_match *m = cs->matches;
+	struct xtables_target *t = cs->target;
+
 	printf("%s %s\n", prog_name, prog_vers);
 	printf(
 "Usage:\n"
@@ -354,9 +356,6 @@ static void print_help(const struct xtables_target *t,
 		printf("\n");
 		t->help();
 	}
-
-//	if (table->help)
-//		table->help(ebt_hooknames);
 }
 
 /* Execute command L */
@@ -1144,7 +1143,7 @@ int do_commandeb(struct nft_handle *h, int argc, char *argv[], char **table,
 		ebt_print_error2("Bad table name");*/
 
 	if (command == 'h' && !(flags & OPT_ZERO)) {
-		print_help(cs.target, cs.matches, *table);
+		print_help(&cs);
 		ret = 1;
 	}
 
Signature · 1 line
2.41.0
author reviewer
#10 lore raw

PATCH 10/13 ebtables: Make 'h' case just a call to print_help()

In reply to Phil Sutter

Move the special ebtables help parameter handling into its print_help() function to prepare for it turning into a callback. Add new field 'argc' to struct iptables_command_state to make this possible. It is actually kind of consistent as it holds 'argv' already.

---
 iptables/xshared.h    |  1 +
 iptables/xtables-eb.c | 61 +++++++++++++++++++++----------------------
 2 files changed, 31 insertions(+), 31 deletions(-)
iptables/xshared.h +1 -0
index 68acfb4b406fb..de32198fa0b67 100644
@@ -137,6 +137,7 @@ struct iptables_command_state {
 	char *protocol;
 	int proto_used;
 	const char *jumpto;
+	int argc;
 	char **argv;
 	bool restore;
 };
iptables/xtables-eb.c +30 -31

85 lines not on this page · raw message

Signature · 1 line
2.41.0
author reviewer
#11 lore raw

PATCH 11/13 ebtables: Use struct xt_cmd_parse

In reply to Phil Sutter

This is merely to reduce size of the parser merge patch, no functional change intended.

---
 iptables/xtables-eb.c | 59 ++++++++++++++++++++++++++-----------------
 1 file changed, 36 insertions(+), 23 deletions(-)
iptables/xtables-eb.c +36 -23
index 8ab479237faa8..e03b2b2510eda 100644
@@ -767,6 +767,8 @@ int do_commandeb(struct nft_handle *h, int argc, char *argv[], char **table,
 		.jumpto	= "",
 		.eb.bitmask = EBT_NOPROTO,
 	};
+	struct xt_cmd_parse p = {
+	};
 	char command = 'h';
 	const char *chain = NULL;
 	const char *policy = NULL;
@@ -1166,56 +1168,67 @@ int do_commandeb(struct nft_handle *h, int argc, char *argv[], char **table,
 	 * The kernel does not have to do this of course */
 	cs.eb.ethproto = htons(cs.eb.ethproto);
 
+	p.table		= *table;
+	p.chain		= chain;
+	p.policy	= policy;
+	p.rulenum	= rule_nr;
+	p.rulenum_end	= rule_nr_end;
+	cs.options	= flags;
+
 	switch (command) {
 	case 'P':
 		if (selected_chain >= NF_BR_NUMHOOKS) {
-			ret = ebt_cmd_user_chain_policy(h, *table, chain, policy);
+			ret = ebt_cmd_user_chain_policy(h, p.table, p.chain,
+							p.policy);
 			break;
 		}
-		if (strcmp(policy, "RETURN") == 0) {
+		if (strcmp(p.policy, "RETURN") == 0) {
 			xtables_error(PARAMETER_PROBLEM,
 				      "Policy RETURN only allowed for user defined chains");
 		}
-		ret = nft_cmd_chain_set(h, *table, chain, policy, NULL);
+		ret = nft_cmd_chain_set(h, p.table, p.chain, p.policy, NULL);
 		if (ret < 0)
 			xtables_error(PARAMETER_PROBLEM, "Wrong policy");
 		break;
 	case 'L':
-		ret = list_rules(h, chain, *table, rule_nr,
-				 flags & OPT_VERBOSE,
+		ret = list_rules(h, p.chain, p.table, p.rulenum,
+				 cs.options & OPT_VERBOSE,
 				 0,
-				 /*flags&OPT_EXPANDED*/0,
-				 flags&LIST_N,
-				 flags&LIST_C);
-		if (!(flags & OPT_ZERO))
+				 /*cs.options&OPT_EXPANDED*/0,
+				 cs.options&LIST_N,
+				 cs.options&LIST_C);
+		if (!(cs.options & OPT_ZERO))
 			break;
 	case 'Z':
-		ret = nft_cmd_chain_zero_counters(h, chain, *table,
-						  flags & OPT_VERBOSE);
+		ret = nft_cmd_chain_zero_counters(h, p.chain, p.table,
+						  cs.options & OPT_VERBOSE);
 		break;
 	case 'F':
-		ret = nft_cmd_rule_flush(h, chain, *table, flags & OPT_VERBOSE);
+		ret = nft_cmd_rule_flush(h, p.chain, p.table,
+					 cs.options & OPT_VERBOSE);
 		break;
 	case 'A':
-		ret = nft_cmd_rule_append(h, chain, *table, &cs,
-					  flags & OPT_VERBOSE);
+		ret = nft_cmd_rule_append(h, p.chain, p.table, &cs,
+					  cs.options & OPT_VERBOSE);
 		break;
 	case 'I':
-		ret = nft_cmd_rule_insert(h, chain, *table, &cs,
-					  rule_nr - 1, flags & OPT_VERBOSE);
+		ret = nft_cmd_rule_insert(h, p.chain, p.table, &cs,
+					  p.rulenum - 1,
+					  cs.options & OPT_VERBOSE);
 		break;
 	case 'D':
-		ret = delete_entry(h, chain, *table, &cs, rule_nr - 1,
-				   rule_nr_end, flags & OPT_VERBOSE);
+		ret = delete_entry(h, p.chain, p.table, &cs, p.rulenum - 1,
+				   p.rulenum_end, cs.options & OPT_VERBOSE);
 		break;
 	case 14:
-		ret = nft_cmd_rule_check(h, chain, *table,
-					 &cs, flags & OPT_VERBOSE);
+		ret = nft_cmd_rule_check(h, p.chain, p.table,
+					 &cs, cs.options & OPT_VERBOSE);
 		break;
 	case 'C':
-		ret = change_entry_counters(h, chain, *table, &cs,
-					    rule_nr - 1, rule_nr_end, chcounter,
-					    flags & OPT_VERBOSE);
+		ret = change_entry_counters(h, p.chain, p.table, &cs,
+					    p.rulenum - 1, p.rulenum_end,
+					    chcounter,
+					    cs.options & OPT_VERBOSE);
 		break;
 	}
 
Signature · 1 line
2.41.0
author reviewer
#12 lore raw

PATCH 12/13 xshared: Introduce option_test_and_reject()

In reply to Phil Sutter

Just a small helper eliminating the repetitive code there.

---
 iptables/xshared.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
iptables/xshared.c +11 -10
index 50f23757d4aff..ebe172223486e 100644
@@ -1439,6 +1439,15 @@ static void parse_change_counters_rule(int argc, char **argv,
 			      "Packet counter '%s' invalid", argv[optind - 1]);
 }
 
+static void option_test_and_reject(struct xt_cmd_parse *p,
+				   struct iptables_command_state *cs,
+				   unsigned int option)
+{
+	if (cs->options & option)
+		xtables_error(PARAMETER_PROBLEM, "Can't use %s with %s",
+			      p->ops->option_name(option), p->chain);
+}
+
 void do_parse(int argc, char *argv[],
 	      struct xt_cmd_parse *p, struct iptables_command_state *cs,
 	      struct xtables_args *args)
@@ -1924,21 +1933,13 @@ void do_parse(int argc, char *argv[],
 		if (strcmp(p->chain, "PREROUTING") == 0
 		    || strcmp(p->chain, "INPUT") == 0) {
 			/* -o not valid with incoming packets. */
-			if (cs->options & OPT_VIANAMEOUT)
-				xtables_error(PARAMETER_PROBLEM,
-					      "Can't use %s with %s\n",
-					      p->ops->option_name(OPT_VIANAMEOUT),
-					      p->chain);
+			option_test_and_reject(p, cs, OPT_VIANAMEOUT);
 		}
 
 		if (strcmp(p->chain, "POSTROUTING") == 0
 		    || strcmp(p->chain, "OUTPUT") == 0) {
 			/* -i not valid with outgoing packets */
-			if (cs->options & OPT_VIANAMEIN)
-				xtables_error(PARAMETER_PROBLEM,
-					      "Can't use %s with %s\n",
-					      p->ops->option_name(OPT_VIANAMEIN),
-					      p->chain);
+			option_test_and_reject(p, cs, OPT_VIANAMEIN);
 		}
 	}
 }
Signature · 1 line
2.41.0
author reviewer
#13 lore raw

PATCH 13/13 ebtables: Use do_parse() from xshared

In reply to Phil Sutter

Drop the custom commandline parsers from ebtables and ebtables-translate, extend and use the shared one instead.

ebtables gains a few new features from doing this:

- Rule counters may be specified in the '-c N,M' syntax
- Support for --replace command
- Support for --list-rules command
- Zero individual rules

There is one known regression in this patch, namely maximum chain name length shrinks to 28 characters (from 32). Since this limit changed for iptables in the past as well (e.g. with commit 5429b41c2bb4a), assume nobody really relies upon it anyway.

---
 iptables/nft-bridge.c           | 121 ++++++
 iptables/nft-bridge.h           |  13 +-
 iptables/nft.h                  |   1 -
 iptables/xshared.c              |  71 +++-
 iptables/xshared.h              |  17 +-
 iptables/xtables-eb-translate.c | 477 +++------------------
 iptables/xtables-eb.c           | 720 ++++----------------------------
 7 files changed, 341 insertions(+), 1079 deletions(-)
iptables/nft-bridge.c +121 -0
index 1fcdeaf2cad68..60d5f4d0ba1b1 100644
@@ -571,11 +571,132 @@ static int nft_bridge_xlate(const struct iptables_command_state *cs,
 	return ret;
 }
 
+static const char *nft_bridge_option_name(int option)
+{
+	switch (option) {
+	/* ebtables specific ones */
+	case OPT_LOGICALIN:	return "--logical-in";
+	case OPT_LOGICALOUT:	return "--logical-out";
+	case OPT_LINENUMBERS:	return "--Ln";
+	case OPT_LIST_C:	return "--Lc";
+	case OPT_LIST_X:	return "--Lx";
+	case OPT_LIST_MAC2:	return "--Lmac2";
+	default:		return ip46t_option_name(option);
+	}
+}
+
+static int nft_bridge_option_invert(int option)
+{
+	switch (option) {
+	case OPT_SOURCE:	return EBT_ISOURCE;
+	case OPT_DESTINATION:	return EBT_IDEST;
+	case OPT_PROTOCOL:	return EBT_IPROTO;
+	case OPT_VIANAMEIN:	return EBT_IIN;
+	case OPT_VIANAMEOUT:	return EBT_IOUT;
+	case OPT_LOGICALIN:	return EBT_ILOGICALIN;
+	case OPT_LOGICALOUT:	return EBT_ILOGICALOUT;
+	default:		return -1;
+	}
+}
+
+static void nft_bridge_proto_parse(struct iptables_command_state *cs,
+				   struct xtables_args *args)
+{
+	char *buffer;
+	int i;
+
+	cs->eb.bitmask &= ~((unsigned int)EBT_NOPROTO);
+
+	i = strtol(cs->protocol, &buffer, 16);
+	if (*buffer == '\0' && (i < 0 || i > 0xFFFF))
+		xtables_error(PARAMETER_PROBLEM,
+			      "Problem with the specified protocol");
+	if (*buffer != '\0') {
+		struct xt_ethertypeent *ent;
+
+		if (!strcmp(cs->protocol, "length")) {
+			cs->eb.bitmask |= EBT_802_3;
+			return;
+		}
+		ent = xtables_getethertypebyname(cs->protocol);
+		if (!ent)
+			xtables_error(PARAMETER_PROBLEM,
+				      "Problem with the specified Ethernet protocol '%s', perhaps "XT_PATH_ETHERTYPES " is missing",
+				      cs->protocol);
+		cs->eb.ethproto = ent->e_ethertype;
+	} else
+		cs->eb.ethproto = i;
+
+	if (cs->eb.ethproto < 0x0600)
+		xtables_error(PARAMETER_PROBLEM,
+			      "Sorry, protocols have values above or equal to 0x0600");
+}
+
+static void nft_bridge_post_parse(int command,
+				  struct iptables_command_state *cs,
+				  struct xtables_args *args)
+{
+	struct ebt_match *match;
+
+	cs->eb.invflags = args->invflags;
+
+	memcpy(cs->eb.in, args->iniface, IFNAMSIZ);
+	memcpy(cs->eb.out, args->outiface, IFNAMSIZ);
+	memcpy(cs->eb.logical_in, args->bri_iniface, IFNAMSIZ);
+	memcpy(cs->eb.logical_out, args->bri_outiface, IFNAMSIZ);
+
+	cs->counters.pcnt = args->pcnt_cnt;
+	cs->counters.bcnt = args->bcnt_cnt;
+
+	if (args->shostnetworkmask) {
+		if (xtables_parse_mac_and_mask(args->shostnetworkmask,
+					       cs->eb.sourcemac,
+					       cs->eb.sourcemsk))
+			xtables_error(PARAMETER_PROBLEM,
+				      "Problem with specified source mac '%s'",
+				      args->shostnetworkmask);
+		cs->eb.bitmask |= EBT_SOURCEMAC;
+	}
+	if (args->dhostnetworkmask) {
+		if (xtables_parse_mac_and_mask(args->dhostnetworkmask,
+					       cs->eb.destmac,
+					       cs->eb.destmsk))
+			xtables_error(PARAMETER_PROBLEM,
+				      "Problem with specified destination mac '%s'",
+				      args->dhostnetworkmask);
+		cs->eb.bitmask |= EBT_DESTMAC;
+	}
+
+	if ((cs->options & (OPT_LIST_X | OPT_LINENUMBERS)) ==
+			(OPT_LIST_X | OPT_LINENUMBERS))
+		xtables_error(PARAMETER_PROBLEM,
+			      "--Lx is not compatible with --Ln");
+
+	/* So, the extensions can work with the host endian.
+	 * The kernel does not have to do this of course */
+	cs->eb.ethproto = htons(cs->eb.ethproto);
+
+	for (match = cs->match_list; match; match = match->next) {
+		if (match->ismatch)
+			continue;
+
+		xtables_option_tfcall(match->u.watcher);
+	}
+}
+
 struct nft_family_ops nft_family_ops_bridge = {
 	.add			= nft_bridge_add,
 	.is_same		= nft_bridge_is_same,
 	.print_payload		= NULL,
 	.rule_parse		= &nft_ruleparse_ops_bridge,
+	.cmd_parse		= {
+		.proto_parse	= nft_bridge_proto_parse,
+		.post_parse	= nft_bridge_post_parse,
+		.option_name	= nft_bridge_option_name,
+		.option_invert	= nft_bridge_option_invert,
+		.command_default = ebt_command_default,
+		.print_help	= nft_bridge_print_help,
+	},
 	.print_table_header	= nft_bridge_print_table_header,
 	.print_header		= nft_bridge_print_header,
 	.print_rule		= nft_bridge_print_rule,
iptables/nft-bridge.h +5 -8
index 0e6a29650acca..13b077fc4fbf3 100644
@@ -8,13 +8,6 @@
 #include <net/ethernet.h>
 #include <libiptc/libxtc.h>
 
-/* We use replace->flags, so we can't use the following values:
- * 0x01 == OPT_COMMAND, 0x02 == OPT_TABLE, 0x100 == OPT_ZERO */
-#define LIST_N	  0x04
-#define LIST_C	  0x08
-#define LIST_X	  0x10
-#define LIST_MAC2 0x20
-
 extern unsigned char eb_mac_type_unicast[ETH_ALEN];
 extern unsigned char eb_msk_type_unicast[ETH_ALEN];
 extern unsigned char eb_mac_type_multicast[ETH_ALEN];
@@ -119,7 +112,8 @@ void ebt_add_match(struct xtables_match *m,
 			  struct iptables_command_state *cs);
 void ebt_add_watcher(struct xtables_target *watcher,
                      struct iptables_command_state *cs);
-int ebt_command_default(struct iptables_command_state *cs);
+int ebt_command_default(struct iptables_command_state *cs,
+			struct xtables_globals *unused, bool ebt_invert);
 
 struct nft_among_pair {
 	struct ether_addr ether;
@@ -177,4 +171,7 @@ nft_among_insert_pair(struct nft_among_pair *pairs,
 	(*pcount)++;
 }
 
+/* from xtables-eb.c */
+void nft_bridge_print_help(struct iptables_command_state *cs);
+
 #endif
iptables/nft.h +0 -1
index 79f1e037cd6d3..57533b6529f5b 100644
@@ -234,7 +234,6 @@ int do_commandarp(struct nft_handle *h, int argc, char *argv[], char **table, bo
 /* For xtables-eb.c */
 int nft_init_eb(struct nft_handle *h, const char *pname);
 void nft_fini_eb(struct nft_handle *h);
-int ebt_get_current_chain(const char *chain);
 int do_commandeb(struct nft_handle *h, int argc, char *argv[], char **table, bool restore);
 
 /*
iptables/xshared.c +65 -6

140 lines not on this page · raw message

iptables/xshared.h +10 -7
index de32198fa0b67..2a9cdf45f581a 100644
@@ -47,10 +47,11 @@ enum {
 	/* below are for ebtables only */
 	OPT_LOGICALIN	= 1 << 18,
 	OPT_LOGICALOUT	= 1 << 19,
-	OPT_COMMAND	= 1 << 20,
-	OPT_ZERO	= 1 << 21,
+	OPT_LIST_C	= 1 << 20,
+	OPT_LIST_X	= 1 << 21,
+	OPT_LIST_MAC2	= 1 << 22,
 };
-#define NUMBER_OF_OPT	23
+#define NUMBER_OF_OPT	24
 
 enum {
 	CMD_NONE		= 0,
@@ -70,16 +71,17 @@ enum {
 	CMD_ZERO_NUM		= 1 << 13,
 	CMD_CHECK		= 1 << 14,
 	CMD_CHANGE_COUNTERS	= 1 << 15, /* ebtables only */
+	CMD_INIT_TABLE		= 1 << 16, /* ebtables only */
 };
-#define NUMBER_OF_CMD		17
+#define NUMBER_OF_CMD		18
 
 struct xtables_globals;
 struct xtables_rule_match;
 struct xtables_target;
 
-#define OPTSTRING_COMMON "-:A:C:D:E:F::I:L::M:N:P:VX::Z::" "c:d:i:j:o:p:s:t:v"
-#define IPT_OPTSTRING	OPTSTRING_COMMON "R:S::W::" "46bfg:h::m:nw::x"
-#define ARPT_OPTSTRING	OPTSTRING_COMMON "R:S::" "h::l:nx" /* "m:" */
+#define OPTSTRING_COMMON "-:A:C:D:E:F::I:L::M:N:P:R:S::VX::Z::" "c:d:i:j:o:p:s:t:v"
+#define IPT_OPTSTRING	OPTSTRING_COMMON "W::" "46bfg:h::m:nw::x"
+#define ARPT_OPTSTRING	OPTSTRING_COMMON "h::l:nx" /* "m:" */
 #define EBT_OPTSTRING	OPTSTRING_COMMON "h"
 
 /* define invflags which won't collide with IPT ones.
@@ -262,6 +264,7 @@ struct xtables_args {
 	uint16_t	invflags;
 	char		iniface[IFNAMSIZ], outiface[IFNAMSIZ];
 	unsigned char	iniface_mask[IFNAMSIZ], outiface_mask[IFNAMSIZ];
+	char		bri_iniface[IFNAMSIZ], bri_outiface[IFNAMSIZ];
 	bool		goto_set;
 	const char	*shostnetworkmask, *dhostnetworkmask;
 	const char	*pcnt, *bcnt;
iptables/xtables-eb-translate.c +55 -422

525 lines not on this page · raw message

iptables/xtables-eb.c +85 -635

810 lines not on this page · raw message

Signature · 1 line
2.41.0
author reviewer
#14 lore raw
In reply to Phil Sutter
Quoted 9 lines · Phil Sutter

This series converts do_commandeb() and do_commandeb_xlate() to call do_parse() from xshared.c instead of iterating over argv themselves.

Patches 1-6 prepare the shared (parser) code for use by ebtables. Patches 7-11 prepare ebtables code for the following integration in patch 13. Patch 12 is a minor refactoring in xshared but fits fine right before the merge as the introduced helper function is called two more times by it.

Quoted 14 lines

Phil Sutter (13):
xshared: do_parse: Skip option checking for CMD_DELETE_NUM
xshared: Perform protocol value parsing in callback
xshared: Turn command_default() into a callback
xshared: Introduce print_help callback (again)
xshared: Support rule range deletion in do_parse()
xshared: Support for ebtables' --change-counters command ebtables{,-translate}: Convert if-clause to switch()
ebtables: Change option values to avoid clashes
ebtables: Pass struct iptables_command_state to print_help()
ebtables: Make 'h' case just a call to print_help()
ebtables: Use struct xt_cmd_parse
xshared: Introduce option_test_and_reject()
ebtables: Use do_parse() from xshared

Series applied.