Skip to contentSkip to conversation

ipset: some small userland improvements

PATCH In review Holger Eitzenberger 2 participants 11 messages Sep 8, 2014 – Sep 14, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover ipset: some small userland improvements

Hi Jozsef,

what follows are some smaller patches I collected while starting to implement sorted ipset list ("ipset -s list") output.

They are not directly related to the sorted output, but are IMO still usefull to have.

I'd like to get them out before sending the initial RFC patches for the sorted output.

Please check.

Cheers,

/Holger

---

Holger Eitzenberger (5):
Remove a duplicate debug print
ipset: avoid duplicate command flags
ipset: coalesce two ifs
ipset: remove extran newline on debug output
ipset: data callback does not need to be part of cb_ctl[]

 lib/mnl.c     |    6 ++----
 lib/session.c |   12 ++++--------
 2 files changed, 6 insertions(+), 12 deletions(-)
Signature · 1 line
A dirty mind is a terrible thing to waste.
#1 lore raw

PATCH 1/5 Remove a duplicate debug print

---
 lib/session.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
lib/session.c +1 -2
index d2957a5..7a719b2 100644
@@ -1038,8 +1038,7 @@ callback_list(struct ipset_session *session, struct nlattr *nla[],
 		ipset_data_flags_unset(data, IPSET_CREATE_FLAGS);
 		D("nla typename %s",
 		  (char *) mnl_attr_get_payload(nla[IPSET_ATTR_TYPENAME]));
-		D("nla typename %s",
-		  (char *) mnl_attr_get_payload(nla[IPSET_ATTR_TYPENAME]));
+
 		ATTR2DATA(session, nla, IPSET_ATTR_FAMILY, cmd_attrs);
 		ATTR2DATA(session, nla, IPSET_ATTR_TYPENAME, cmd_attrs);
 		ATTR2DATA(session, nla, IPSET_ATTR_REVISION, cmd_attrs);
#2 lore raw

Re: [PATCH 1/5] Remove a duplicate debug print

Quoted 11 lines · Holger Eitzenberger
---
 lib/session.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
lib/session.c +0 -0
index d2957a5..7a719b2 100644

lib/session.c callback_list(struct ipset_session *session, struct nlattr *nla[], · line 1044

Quoted 9 lines
lib/session.c +1 -2
@@ -1038,8 +1038,7 @@ callback_list(struct ipset_session *session, struct nlattr *nla[],
 		ipset_data_flags_unset(data, IPSET_CREATE_FLAGS);
 		D("nla typename %s",
 		  (char *) mnl_attr_get_payload(nla[IPSET_ATTR_TYPENAME]));
-		D("nla typename %s",
-		  (char *) mnl_attr_get_payload(nla[IPSET_ATTR_TYPENAME]));
+
 		ATTR2DATA(session, nla, IPSET_ATTR_FAMILY, cmd_attrs);
 		ATTR2DATA(session, nla, IPSET_ATTR_TYPENAME, cmd_attrs);
 		ATTR2DATA(session, nla, IPSET_ATTR_REVISION, cmd_attrs);

Patch is applied, thanks!

Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : Wigner Research Centre for Physics, Hungarian Academy of Sciences

          H-1525 Budapest 114, POB. 49, Hungary
#3 lore raw

PATCH 2/5 ipset: avoid duplicate command flags

In reply to Holger Eitzenberger

NLM_F_DUMP is #defined as (NLM_F_ROOT | NLM_F_ACK), so specifying all of them is redundant.

---
 lib/mnl.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
lib/mnl.c +2 -4
index 786c9e5..a0fa66e 100644
@@ -38,10 +38,8 @@ static const uint16_t cmdflags[] = {
 	[IPSET_CMD_FLUSH-1]	= NLM_F_REQUEST|NLM_F_ACK,
 	[IPSET_CMD_RENAME-1]	= NLM_F_REQUEST|NLM_F_ACK,
 	[IPSET_CMD_SWAP-1]	= NLM_F_REQUEST|NLM_F_ACK,
-	[IPSET_CMD_LIST-1]	= NLM_F_REQUEST|NLM_F_ACK|
-					NLM_F_ROOT|NLM_F_MATCH|NLM_F_DUMP,
-	[IPSET_CMD_SAVE-1]	= NLM_F_REQUEST|NLM_F_ACK|
-					NLM_F_ROOT|NLM_F_MATCH|NLM_F_DUMP,
+	[IPSET_CMD_LIST-1]	= NLM_F_REQUEST|NLM_F_ACK|NLM_F_DUMP,
+	[IPSET_CMD_SAVE-1]	= NLM_F_REQUEST|NLM_F_ACK|NLM_F_DUMP,
 	[IPSET_CMD_ADD-1]	= NLM_F_REQUEST|NLM_F_ACK|NLM_F_EXCL,
 	[IPSET_CMD_DEL-1]	= NLM_F_REQUEST|NLM_F_ACK|NLM_F_EXCL,
 	[IPSET_CMD_TEST-1]	= NLM_F_REQUEST|NLM_F_ACK,
#4 lore raw

Re: [PATCH 2/5] ipset: avoid duplicate command flags

Quoted 16 lines · Holger Eitzenberger

NLM_F_DUMP is #defined as (NLM_F_ROOT | NLM_F_ACK), so specifying all of them is redundant.

---
 lib/mnl.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
lib/mnl.c +0 -0
index 786c9e5..a0fa66e 100644
@@ -38,10 +38,8 @@ static const uint16_t cmdflags[] = {
 	[IPSET_CMD_FLUSH-1]	= NLM_F_REQUEST|NLM_F_ACK,
 	[IPSET_CMD_RENAME-1]	= NLM_F_REQUEST|NLM_F_ACK,

lib/mnl.c static const uint16_t cmdflags[] = { · line 45

Quoted 10 lines
lib/mnl.c +2 -4
 	[IPSET_CMD_SWAP-1]	= NLM_F_REQUEST|NLM_F_ACK,
-	[IPSET_CMD_LIST-1]	= NLM_F_REQUEST|NLM_F_ACK|
-					NLM_F_ROOT|NLM_F_MATCH|NLM_F_DUMP,
-	[IPSET_CMD_SAVE-1]	= NLM_F_REQUEST|NLM_F_ACK|
-					NLM_F_ROOT|NLM_F_MATCH|NLM_F_DUMP,
+	[IPSET_CMD_LIST-1]	= NLM_F_REQUEST|NLM_F_ACK|NLM_F_DUMP,
+	[IPSET_CMD_SAVE-1]	= NLM_F_REQUEST|NLM_F_ACK|NLM_F_DUMP,
 	[IPSET_CMD_ADD-1]	= NLM_F_REQUEST|NLM_F_ACK|NLM_F_EXCL,
 	[IPSET_CMD_DEL-1]	= NLM_F_REQUEST|NLM_F_ACK|NLM_F_EXCL,
 	[IPSET_CMD_TEST-1]	= NLM_F_REQUEST|NLM_F_ACK,

Patch is applied.

Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : Wigner Research Centre for Physics, Hungarian Academy of Sciences

          H-1525 Budapest 114, POB. 49, Hungary
#5 lore raw

PATCH 3/5 ipset: coalesce two ifs

In reply to Holger Eitzenberger

Because they are doing the same for both IPSET_CMD_LIST and IPSET_CMD_SAVE.

---
 lib/session.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
lib/session.c +2 -4
index 7a719b2..d4fe836 100644
@@ -1936,13 +1936,11 @@ ipset_cmd(struct ipset_session *session, enum ipset_cmd cmd, uint32_t lineno)
 	session->lineno = lineno;
 
 	/* Set default output mode */
-	if (cmd == IPSET_CMD_LIST) {
+	if (cmd == IPSET_CMD_LIST || cmd == IPSET_CMD_SAVE) {
 		if (session->mode == IPSET_LIST_NONE)
 			session->mode = IPSET_LIST_PLAIN;
-	} else if (cmd == IPSET_CMD_SAVE) {
-		if (session->mode == IPSET_LIST_NONE)
-			session->mode = IPSET_LIST_SAVE;
 	}
+
 	/* Start the root element in XML mode */
 	if ((cmd == IPSET_CMD_LIST || cmd == IPSET_CMD_SAVE) &&
 	    session->mode == IPSET_LIST_XML)
#6 lore raw

Re: [PATCH 3/5] ipset: coalesce two ifs

Quoted 19 lines · Holger Eitzenberger

Because they are doing the same for both IPSET_CMD_LIST and IPSET_CMD_SAVE.

---
 lib/session.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
lib/session.c +1 -1
index 7a719b2..d4fe836 100644
@@ -1936,13 +1936,11 @@ ipset_cmd(struct ipset_session *session, enum ipset_cmd cmd, uint32_t lineno)
 	session->lineno = lineno;
 
 	/* Set default output mode */
-	if (cmd == IPSET_CMD_LIST) {
+	if (cmd == IPSET_CMD_LIST || cmd == IPSET_CMD_SAVE) {

lib/session.c ipset_cmd(struct ipset_session *session, enum ipset_cmd cmd, uint32_t lineno) · line 1946

Quoted 10 lines
lib/session.c +1 -3
 		if (session->mode == IPSET_LIST_NONE)
 			session->mode = IPSET_LIST_PLAIN;
-	} else if (cmd == IPSET_CMD_SAVE) {
-		if (session->mode == IPSET_LIST_NONE)
-			session->mode = IPSET_LIST_SAVE;
 	}
+
 	/* Start the root element in XML mode */
 	if ((cmd == IPSET_CMD_LIST || cmd == IPSET_CMD_SAVE) &&
 	    session->mode == IPSET_LIST_XML)

The two ifs don't do the same thing: by coalescing them the safe mode would be broken (unless XML mode is specified). So this patch is skipped.

Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : Wigner Research Centre for Physics, Hungarian Academy of Sciences

          H-1525 Budapest 114, POB. 49, Hungary
#7 lore raw

PATCH 4/5 ipset: remove extran newline on debug output

In reply to Holger Eitzenberger
---
 lib/session.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/session.c +1 -1
index d4fe836..8d79a96 100644
@@ -804,7 +804,7 @@ list_adt(struct ipset_session *session, struct nlattr *nla[])
 		safe_snprintf(session, "</elem>");
 
 	for (arg = type->args[IPSET_ADD]; arg != NULL && arg->opt; arg++) {
-		D("print arg opt %u %s\n", arg->opt,
+		D("print arg opt %u %s", arg->opt,
 		   ipset_data_test(data, arg->opt) ? "(yes)" : "(missing)");
 		if (!(arg->print && ipset_data_test(data, arg->opt)))
 			continue;
#8 lore raw

Re: [PATCH 4/5] ipset: remove extran newline on debug output

Quoted 11 lines · Holger Eitzenberger
---
 lib/session.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/session.c +0 -0
index d4fe836..8d79a96 100644

lib/session.c list_adt(struct ipset_session *session, struct nlattr *nla[]) · line 810

Quoted 8 lines
lib/session.c +1 -1
@@ -804,7 +804,7 @@ list_adt(struct ipset_session *session, struct nlattr *nla[])
 		safe_snprintf(session, "</elem>");
 
 	for (arg = type->args[IPSET_ADD]; arg != NULL && arg->opt; arg++) {
-		D("print arg opt %u %s\n", arg->opt,
+		D("print arg opt %u %s", arg->opt,
 		   ipset_data_test(data, arg->opt) ? "(yes)" : "(missing)");
 		if (!(arg->print && ipset_data_test(data, arg->opt)))
 			continue;

This patch is also applied, thanks Holger.

Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : Wigner Research Centre for Physics, Hungarian Academy of Sciences

          H-1525 Budapest 114, POB. 49, Hungary
#9 lore raw

PATCH 5/5 ipset: data callback does not need to be part of cb_ctl[]

In reply to Holger Eitzenberger

Because the data callback is passed explicitely to mnl_cb_run2() there is no need to add it to cb_ctl[]. For nlmsg_types

Quoted 1 line

= NLMSG_MIN_TYPE the data callback is used explicitely.

---
 lib/session.c |    1 -
 1 file changed, 1 deletion(-)
lib/session.c +0 -1
index 8d79a96..807f0d3 100644
@@ -1868,7 +1868,6 @@ static mnl_cb_t cb_ctl[] = {
 	[NLMSG_ERROR] = callback_error,
 	[NLMSG_DONE]  = callback_done,
 	[NLMSG_OVERRUN] = callback_noop,
-	[NLMSG_MIN_TYPE] = callback_data,
 };
 
 static inline struct ipset_handle *
#10 lore raw

Re: [PATCH 5/5] ipset: data callback does not need to be part of cb_ctl[]

Hi Jozsef,

Quoted 3 lines

Because the data callback is passed explicitely to mnl_cb_run2() there is no need to add it to cb_ctl[]. For nlmsg_types

Quoted 1 line

= NLMSG_MIN_TYPE the data callback is used explicitely.

Just noticed that there is a side effect to this one. So please just ignore this patch for now.