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

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