All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: netfilter: Remove complexity
@ 2017-03-28 13:00 Arushi Singhal
  2017-03-28 15:26 ` [Outreachy kernel] " Pablo Neira Ayuso
  0 siblings, 1 reply; 3+ messages in thread
From: Arushi Singhal @ 2017-03-28 13:00 UTC (permalink / raw)
  To: pablo
  Cc: Jozsef Kadlecsik, davem, netfilter-devel, coreteam, linux-kernel,
	netdev, outreachy-kernel

To remove complexity of code the function is added in nfnetlink.h
to make code more clear and readable.

Signed-off-by: Arushi Singhal <arushisinghal19971997@gmail.com>
---
 include/linux/netfilter/nfnetlink.h  |  6 ++++++
 net/netfilter/nf_conntrack_netlink.c | 12 +++++++-----
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
index 1b49209dd5c7..9a36a7c3145d 100644
--- a/include/linux/netfilter/nfnetlink.h
+++ b/include/linux/netfilter/nfnetlink.h
@@ -50,6 +50,12 @@ static inline bool lockdep_nfnl_is_held(__u8 subsys_id)
 {
 	return true;
 }
+
+static inline u16 nfnl_msg_type(u8 subsys, u8 msg_type)
+{
+	return subsys << 8 | msg_type;
+}
+
 #endif /* CONFIG_PROVE_LOCKING */
 
 /*
diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
index aa344c5868c5..67f6f88a3e92 100644
--- a/net/netfilter/nf_conntrack_netlink.c
+++ b/net/netfilter/nf_conntrack_netlink.c
@@ -467,7 +467,7 @@ ctnetlink_fill_info(struct sk_buff *skb, u32 portid, u32 seq, u32 type,
 	struct nlattr *nest_parms;
 	unsigned int flags = portid ? NLM_F_MULTI : 0, event;
 
-	event = NFNL_SUBSYS_CTNETLINK << 8 | IPCTNL_MSG_CT_NEW;
+	event = nfnl_msg_type(NFNL_SUBSYS_CTNETLINK, IPCTNL_MSG_CT_NEW);
 	nlh = nlmsg_put(skb, portid, seq, event, sizeof(*nfmsg), flags);
 	if (nlh == NULL)
 		goto nlmsg_failure;
@@ -1983,7 +1983,8 @@ ctnetlink_ct_stat_cpu_fill_info(struct sk_buff *skb, u32 portid, u32 seq,
 	struct nfgenmsg *nfmsg;
 	unsigned int flags = portid ? NLM_F_MULTI : 0, event;
 
-	event = NFNL_SUBSYS_CTNETLINK << 8 | IPCTNL_MSG_CT_GET_STATS_CPU;
+	event = nfnl_msg_type(NFNL_SUBSYS_CTNETLINK,
+			      IPCTNL_MSG_CT_GET_STATS_CPU);
 	nlh = nlmsg_put(skb, portid, seq, event, sizeof(*nfmsg), flags);
 	if (nlh == NULL)
 		goto nlmsg_failure;
@@ -2066,7 +2067,7 @@ ctnetlink_stat_ct_fill_info(struct sk_buff *skb, u32 portid, u32 seq, u32 type,
 	unsigned int flags = portid ? NLM_F_MULTI : 0, event;
 	unsigned int nr_conntracks = atomic_read(&net->ct.count);
 
-	event = NFNL_SUBSYS_CTNETLINK << 8 | IPCTNL_MSG_CT_GET_STATS;
+	event = nfnl_msg_type(NFNL_SUBSYS_CTNETLINK, IPCTNL_MSG_CT_GET_STATS);
 	nlh = nlmsg_put(skb, portid, seq, event, sizeof(*nfmsg), flags);
 	if (nlh == NULL)
 		goto nlmsg_failure;
@@ -2576,7 +2577,7 @@ ctnetlink_exp_fill_info(struct sk_buff *skb, u32 portid, u32 seq,
 	struct nfgenmsg *nfmsg;
 	unsigned int flags = portid ? NLM_F_MULTI : 0;
 
-	event |= NFNL_SUBSYS_CTNETLINK_EXP << 8;
+	event = nfnl_msg_type(NFNL_SUBSYS_CTNETLINK_EXP, event);
 	nlh = nlmsg_put(skb, portid, seq, event, sizeof(*nfmsg), flags);
 	if (nlh == NULL)
 		goto nlmsg_failure;
@@ -3223,7 +3224,8 @@ ctnetlink_exp_stat_fill_info(struct sk_buff *skb, u32 portid, u32 seq, int cpu,
 	struct nfgenmsg *nfmsg;
 	unsigned int flags = portid ? NLM_F_MULTI : 0, event;
 
-	event = NFNL_SUBSYS_CTNETLINK << 8 | IPCTNL_MSG_EXP_GET_STATS_CPU;
+	event = nfnl_msg_type(NFNL_SUBSYS_CTNETLINK,
+			      IPCTNL_MSG_EXP_GET_STATS_CPU);
 	nlh = nlmsg_put(skb, portid, seq, event, sizeof(*nfmsg), flags);
 	if (nlh == NULL)
 		goto nlmsg_failure;
-- 
2.11.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Outreachy kernel] [PATCH] net: netfilter: Remove complexity
  2017-03-28 13:00 [PATCH] net: netfilter: Remove complexity Arushi Singhal
@ 2017-03-28 15:26 ` Pablo Neira Ayuso
  2017-03-28 16:10   ` Arushi Singhal
  0 siblings, 1 reply; 3+ messages in thread
From: Pablo Neira Ayuso @ 2017-03-28 15:26 UTC (permalink / raw)
  To: Arushi Singhal
  Cc: Jozsef Kadlecsik, davem, netfilter-devel, coreteam, linux-kernel,
	netdev, outreachy-kernel

On Tue, Mar 28, 2017 at 06:30:56PM +0530, Arushi Singhal wrote:
> To remove complexity of code the function is added in nfnetlink.h
> to make code more clear and readable.

Patch looks good, you can also use this new function from other
_fill_info() functions in the netfilter code, eg.

        nfnl_cthelper_fill_info()

Take the time to make a careful look at the netfilter tree to see if
we can have a good bunch of new clients of this function in one go.
Most likely many of the nfnetlink_*.c files can use this.

BTW, you can also indicate in your patch description that this is
opencoded in a way that makes it error prone for future netfilter
netlink subsystems.

Please search for a better patch title, this one is too generic. I
understand selecting a good patch title is something that exercise.

I'd suggest this:

        netfilter: add nfnl_msg_type() helper function

Never give up, revamp and resubmit, thanks!


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Outreachy kernel] [PATCH] net: netfilter: Remove complexity
  2017-03-28 15:26 ` [Outreachy kernel] " Pablo Neira Ayuso
@ 2017-03-28 16:10   ` Arushi Singhal
  0 siblings, 0 replies; 3+ messages in thread
From: Arushi Singhal @ 2017-03-28 16:10 UTC (permalink / raw)
  To: Pablo Neira Ayuso
  Cc: Jozsef Kadlecsik, David S. Miller, netfilter-devel, coreteam,
	LKML, netdev, outreachy-kernel

[-- Attachment #1: Type: text/plain, Size: 1134 bytes --]

On Tue, Mar 28, 2017 at 8:56 PM, Pablo Neira Ayuso <pablo@netfilter.org>
wrote:

> On Tue, Mar 28, 2017 at 06:30:56PM +0530, Arushi Singhal wrote:
> > To remove complexity of code the function is added in nfnetlink.h
> > to make code more clear and readable.
>
> Patch looks good, you can also use this new function from other
> _fill_info() functions in the netfilter code, eg.
>
>         nfnl_cthelper_fill_info()
>
> Take the time to make a careful look at the netfilter tree to see if
> we can have a good bunch of new clients of this function in one go.
> Most likely many of the nfnetlink_*.c files can use this.
>
> BTW, you can also indicate in your patch description that this is
> opencoded in a way that makes it error prone for future netfilter
> netlink subsystems.
>
> Please search for a better patch title, this one is too generic. I
> understand selecting a good patch title is something that exercise.
>
> I'd suggest this:
>
>         netfilter: add nfnl_msg_type() helper function
>
> Never give up, revamp and resubmit, thanks!
>
Thanks Pablo
I will try to make it more better and resubmit my patch again
Arushi

[-- Attachment #2: Type: text/html, Size: 1596 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-03-28 16:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-28 13:00 [PATCH] net: netfilter: Remove complexity Arushi Singhal
2017-03-28 15:26 ` [Outreachy kernel] " Pablo Neira Ayuso
2017-03-28 16:10   ` Arushi Singhal

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.