Blame SOURCES/0002-lib-split-parser-from-command-execution.patch

e0f94f
From c371154c65f7b09aa0582b7ae2f68aaf13113ee1 Mon Sep 17 00:00:00 2001
e0f94f
From: Pablo Neira Ayuso <pablo@netfilter.org>
e0f94f
Date: Fri, 25 Jun 2021 22:30:40 +0200
e0f94f
Subject: [PATCH] lib: split parser from command execution
e0f94f
e0f94f
ipset_parse_argv() parses, builds and send the netlink messages to the
e0f94f
kernel. This patch extracts the parser and wrap it around the new
e0f94f
ipset_parser() function.
e0f94f
e0f94f
This patch comes is preparation for the ipset to nftables translation
e0f94f
infrastructure.
e0f94f
e0f94f
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
e0f94f
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
e0f94f
(cherry picked from commit 4dd0a5e5755ec058b78e3bd6da39fe2bb7bbb4f3)
e0f94f
---
e0f94f
 lib/ipset.c | 44 ++++++++++++++++++++++++++++++--------------
e0f94f
 1 file changed, 30 insertions(+), 14 deletions(-)
e0f94f
e0f94f
diff --git a/lib/ipset.c b/lib/ipset.c
e0f94f
index 6729919657707..3077f9793f841 100644
e0f94f
--- a/lib/ipset.c
e0f94f
+++ b/lib/ipset.c
e0f94f
@@ -923,20 +923,8 @@ static const char *cmd_prefix[] = {
e0f94f
 	[IPSET_TEST]   = "test   SETNAME",
e0f94f
 };
e0f94f
 
e0f94f
-/* Workhorses */
e0f94f
-
e0f94f
-/**
e0f94f
- * ipset_parse_argv - parse and argv array and execute the command
e0f94f
- * @ipset: ipset structure
e0f94f
- * @argc: length of the array
e0f94f
- * @argv: array of strings
e0f94f
- *
e0f94f
- * Parse an array of strings and execute the ipset command.
e0f94f
- *
e0f94f
- * Returns 0 on success or a negative error code.
e0f94f
- */
e0f94f
-int
e0f94f
-ipset_parse_argv(struct ipset *ipset, int oargc, char *oargv[])
e0f94f
+static int
e0f94f
+ipset_parser(struct ipset *ipset, int oargc, char *oargv[])
e0f94f
 {
e0f94f
 	int ret = 0;
e0f94f
 	enum ipset_cmd cmd = IPSET_CMD_NONE;
e0f94f
@@ -1280,6 +1268,34 @@ ipset_parse_argv(struct ipset *ipset, int oargc, char *oargv[])
e0f94f
 	if (argc > 1)
e0f94f
 		return ipset->custom_error(ipset, p, IPSET_PARAMETER_PROBLEM,
e0f94f
 			"Unknown argument %s", argv[1]);
e0f94f
+
e0f94f
+	return cmd;
e0f94f
+}
e0f94f
+
e0f94f
+/* Workhorses */
e0f94f
+
e0f94f
+/**
e0f94f
+ * ipset_parse_argv - parse and argv array and execute the command
e0f94f
+ * @ipset: ipset structure
e0f94f
+ * @argc: length of the array
e0f94f
+ * @argv: array of strings
e0f94f
+ *
e0f94f
+ * Parse an array of strings and execute the ipset command.
e0f94f
+ *
e0f94f
+ * Returns 0 on success or a negative error code.
e0f94f
+ */
e0f94f
+int
e0f94f
+ipset_parse_argv(struct ipset *ipset, int oargc, char *oargv[])
e0f94f
+{
e0f94f
+	struct ipset_session *session = ipset->session;
e0f94f
+	void *p = ipset_session_printf_private(session);
e0f94f
+	enum ipset_cmd cmd;
e0f94f
+	int ret;
e0f94f
+
e0f94f
+	cmd = ipset_parser(ipset, oargc, oargv);
e0f94f
+	if (cmd < 0)
e0f94f
+		return cmd;
e0f94f
+
e0f94f
 	ret = ipset_cmd(session, cmd, ipset->restore_line);
e0f94f
 	D("ret %d", ret);
e0f94f
 	/* In the case of warning, the return code is success */
e0f94f
-- 
e0f94f
2.38.0
e0f94f