All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] netns: simple cleanups
@ 2020-01-14 22:25 Guillaume Nault
  2020-01-14 22:25 ` [PATCH net-next 1/2] netns: Parse NETNSA_FD and NETNSA_PID as signed integers Guillaume Nault
  2020-01-14 22:25 ` [PATCH net-next 2/2] netns: constify exported functions Guillaume Nault
  0 siblings, 2 replies; 6+ messages in thread
From: Guillaume Nault @ 2020-01-14 22:25 UTC (permalink / raw)
  To: David Miller, Jakub Kicinski; +Cc: netdev, Nicolas Dichtel

A few things to cleanup, found while working on net_namespace.c:
  * align netlink attribute parsing policy with their real usage,
  * some constification.

Guillaume Nault (2):
  netns: Parse NETNSA_FD and NETNSA_PID as signed integers
  netns: constify exported functions

 include/net/net_namespace.h | 10 +++++-----
 net/core/net_namespace.c    | 18 +++++++++---------
 2 files changed, 14 insertions(+), 14 deletions(-)

-- 
2.21.1


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

* [PATCH net-next 1/2] netns: Parse NETNSA_FD and NETNSA_PID as signed integers
  2020-01-14 22:25 [PATCH net-next 0/2] netns: simple cleanups Guillaume Nault
@ 2020-01-14 22:25 ` Guillaume Nault
  2020-01-15 13:30   ` Nicolas Dichtel
  2020-01-14 22:25 ` [PATCH net-next 2/2] netns: constify exported functions Guillaume Nault
  1 sibling, 1 reply; 6+ messages in thread
From: Guillaume Nault @ 2020-01-14 22:25 UTC (permalink / raw)
  To: David Miller, Jakub Kicinski; +Cc: netdev, Nicolas Dichtel

These attributes represent signed values (file descriptors and PIDs).
Make that clear in nla_policy.

Signed-off-by: Guillaume Nault <gnault@redhat.com>
---
 net/core/net_namespace.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 6412c1fbfcb5..85c565571c1c 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -706,8 +706,8 @@ static struct pernet_operations __net_initdata net_ns_ops = {
 static const struct nla_policy rtnl_net_policy[NETNSA_MAX + 1] = {
 	[NETNSA_NONE]		= { .type = NLA_UNSPEC },
 	[NETNSA_NSID]		= { .type = NLA_S32 },
-	[NETNSA_PID]		= { .type = NLA_U32 },
-	[NETNSA_FD]		= { .type = NLA_U32 },
+	[NETNSA_PID]		= { .type = NLA_S32 },
+	[NETNSA_FD]		= { .type = NLA_S32 },
 	[NETNSA_TARGET_NSID]	= { .type = NLA_S32 },
 };
 
@@ -731,10 +731,10 @@ static int rtnl_net_newid(struct sk_buff *skb, struct nlmsghdr *nlh,
 	nsid = nla_get_s32(tb[NETNSA_NSID]);
 
 	if (tb[NETNSA_PID]) {
-		peer = get_net_ns_by_pid(nla_get_u32(tb[NETNSA_PID]));
+		peer = get_net_ns_by_pid(nla_get_s32(tb[NETNSA_PID]));
 		nla = tb[NETNSA_PID];
 	} else if (tb[NETNSA_FD]) {
-		peer = get_net_ns_by_fd(nla_get_u32(tb[NETNSA_FD]));
+		peer = get_net_ns_by_fd(nla_get_s32(tb[NETNSA_FD]));
 		nla = tb[NETNSA_FD];
 	} else {
 		NL_SET_ERR_MSG(extack, "Peer netns reference is missing");
@@ -874,10 +874,10 @@ static int rtnl_net_getid(struct sk_buff *skb, struct nlmsghdr *nlh,
 	if (err < 0)
 		return err;
 	if (tb[NETNSA_PID]) {
-		peer = get_net_ns_by_pid(nla_get_u32(tb[NETNSA_PID]));
+		peer = get_net_ns_by_pid(nla_get_s32(tb[NETNSA_PID]));
 		nla = tb[NETNSA_PID];
 	} else if (tb[NETNSA_FD]) {
-		peer = get_net_ns_by_fd(nla_get_u32(tb[NETNSA_FD]));
+		peer = get_net_ns_by_fd(nla_get_s32(tb[NETNSA_FD]));
 		nla = tb[NETNSA_FD];
 	} else if (tb[NETNSA_NSID]) {
 		peer = get_net_ns_by_id(net, nla_get_s32(tb[NETNSA_NSID]));
-- 
2.21.1


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

* [PATCH net-next 2/2] netns: constify exported functions
  2020-01-14 22:25 [PATCH net-next 0/2] netns: simple cleanups Guillaume Nault
  2020-01-14 22:25 ` [PATCH net-next 1/2] netns: Parse NETNSA_FD and NETNSA_PID as signed integers Guillaume Nault
@ 2020-01-14 22:25 ` Guillaume Nault
  2020-01-15 13:43   ` Nicolas Dichtel
  1 sibling, 1 reply; 6+ messages in thread
From: Guillaume Nault @ 2020-01-14 22:25 UTC (permalink / raw)
  To: David Miller, Jakub Kicinski; +Cc: netdev, Nicolas Dichtel

Mark function parameters as 'const' where possible.

Signed-off-by: Guillaume Nault <gnault@redhat.com>
---
 include/net/net_namespace.h | 10 +++++-----
 net/core/net_namespace.c    |  6 +++---
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
index b8ceaf0cd997..854d39ef1ca3 100644
--- a/include/net/net_namespace.h
+++ b/include/net/net_namespace.h
@@ -347,9 +347,9 @@ static inline struct net *read_pnet(const possible_net_t *pnet)
 #endif
 
 int peernet2id_alloc(struct net *net, struct net *peer, gfp_t gfp);
-int peernet2id(struct net *net, struct net *peer);
-bool peernet_has_id(struct net *net, struct net *peer);
-struct net *get_net_ns_by_id(struct net *net, int id);
+int peernet2id(const struct net *net, struct net *peer);
+bool peernet_has_id(const struct net *net, struct net *peer);
+struct net *get_net_ns_by_id(const struct net *net, int id);
 
 struct pernet_operations {
 	struct list_head list;
@@ -427,7 +427,7 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
 }
 #endif
 
-static inline int rt_genid_ipv4(struct net *net)
+static inline int rt_genid_ipv4(const struct net *net)
 {
 	return atomic_read(&net->ipv4.rt_genid);
 }
@@ -459,7 +459,7 @@ static inline void rt_genid_bump_all(struct net *net)
 	rt_genid_bump_ipv6(net);
 }
 
-static inline int fnhe_genid(struct net *net)
+static inline int fnhe_genid(const struct net *net)
 {
 	return atomic_read(&net->fnhe_genid);
 }
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 85c565571c1c..fd0727670f34 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -268,7 +268,7 @@ int peernet2id_alloc(struct net *net, struct net *peer, gfp_t gfp)
 EXPORT_SYMBOL_GPL(peernet2id_alloc);
 
 /* This function returns, if assigned, the id of a peer netns. */
-int peernet2id(struct net *net, struct net *peer)
+int peernet2id(const struct net *net, struct net *peer)
 {
 	int id;
 
@@ -283,12 +283,12 @@ EXPORT_SYMBOL(peernet2id);
 /* This function returns true is the peer netns has an id assigned into the
  * current netns.
  */
-bool peernet_has_id(struct net *net, struct net *peer)
+bool peernet_has_id(const struct net *net, struct net *peer)
 {
 	return peernet2id(net, peer) >= 0;
 }
 
-struct net *get_net_ns_by_id(struct net *net, int id)
+struct net *get_net_ns_by_id(const struct net *net, int id)
 {
 	struct net *peer;
 
-- 
2.21.1


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

* Re: [PATCH net-next 1/2] netns: Parse NETNSA_FD and NETNSA_PID as signed integers
  2020-01-14 22:25 ` [PATCH net-next 1/2] netns: Parse NETNSA_FD and NETNSA_PID as signed integers Guillaume Nault
@ 2020-01-15 13:30   ` Nicolas Dichtel
  2020-01-15 14:55     ` Guillaume Nault
  0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Dichtel @ 2020-01-15 13:30 UTC (permalink / raw)
  To: Guillaume Nault, David Miller, Jakub Kicinski; +Cc: netdev

Le 14/01/2020 à 23:25, Guillaume Nault a écrit :
> These attributes represent signed values (file descriptors and PIDs).
> Make that clear in nla_policy.
> 
> Signed-off-by: Guillaume Nault <gnault@redhat.com>
> ---
>  net/core/net_namespace.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
> index 6412c1fbfcb5..85c565571c1c 100644
> --- a/net/core/net_namespace.c
> +++ b/net/core/net_namespace.c
> @@ -706,8 +706,8 @@ static struct pernet_operations __net_initdata net_ns_ops = {
>  static const struct nla_policy rtnl_net_policy[NETNSA_MAX + 1] = {
>  	[NETNSA_NONE]		= { .type = NLA_UNSPEC },
>  	[NETNSA_NSID]		= { .type = NLA_S32 },
> -	[NETNSA_PID]		= { .type = NLA_U32 },
> -	[NETNSA_FD]		= { .type = NLA_U32 },
> +	[NETNSA_PID]		= { .type = NLA_S32 },
> +	[NETNSA_FD]		= { .type = NLA_S32 },
Please, keep them consistent with IFLA_NET_NS_*:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/core/rtnetlink.c?h=v5.5-rc6#n1793

>  	[NETNSA_TARGET_NSID]	= { .type = NLA_S32 },
>  };
>  
> @@ -731,10 +731,10 @@ static int rtnl_net_newid(struct sk_buff *skb, struct nlmsghdr *nlh,
>  	nsid = nla_get_s32(tb[NETNSA_NSID]);
>  
>  	if (tb[NETNSA_PID]) {
> -		peer = get_net_ns_by_pid(nla_get_u32(tb[NETNSA_PID]));
> +		peer = get_net_ns_by_pid(nla_get_s32(tb[NETNSA_PID]));
Same here:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/core/rtnetlink.c?h=v5.5-rc6#n2115


Thank you,
Nicolas

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

* Re: [PATCH net-next 2/2] netns: constify exported functions
  2020-01-14 22:25 ` [PATCH net-next 2/2] netns: constify exported functions Guillaume Nault
@ 2020-01-15 13:43   ` Nicolas Dichtel
  0 siblings, 0 replies; 6+ messages in thread
From: Nicolas Dichtel @ 2020-01-15 13:43 UTC (permalink / raw)
  To: Guillaume Nault, David Miller, Jakub Kicinski; +Cc: netdev

Le 14/01/2020 à 23:25, Guillaume Nault a écrit :
> Mark function parameters as 'const' where possible.
> 
> Signed-off-by: Guillaume Nault <gnault@redhat.com>
Acked-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>

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

* Re: [PATCH net-next 1/2] netns: Parse NETNSA_FD and NETNSA_PID as signed integers
  2020-01-15 13:30   ` Nicolas Dichtel
@ 2020-01-15 14:55     ` Guillaume Nault
  0 siblings, 0 replies; 6+ messages in thread
From: Guillaume Nault @ 2020-01-15 14:55 UTC (permalink / raw)
  To: Nicolas Dichtel; +Cc: David Miller, Jakub Kicinski, netdev

On Wed, Jan 15, 2020 at 02:30:13PM +0100, Nicolas Dichtel wrote:
> Le 14/01/2020 à 23:25, Guillaume Nault a écrit :
> > These attributes represent signed values (file descriptors and PIDs).
> > Make that clear in nla_policy.
> > 
> > Signed-off-by: Guillaume Nault <gnault@redhat.com>
> > ---
> >  net/core/net_namespace.c | 12 ++++++------
> >  1 file changed, 6 insertions(+), 6 deletions(-)
> > 
> > diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
> > index 6412c1fbfcb5..85c565571c1c 100644
> > --- a/net/core/net_namespace.c
> > +++ b/net/core/net_namespace.c
> > @@ -706,8 +706,8 @@ static struct pernet_operations __net_initdata net_ns_ops = {
> >  static const struct nla_policy rtnl_net_policy[NETNSA_MAX + 1] = {
> >  	[NETNSA_NONE]		= { .type = NLA_UNSPEC },
> >  	[NETNSA_NSID]		= { .type = NLA_S32 },
> > -	[NETNSA_PID]		= { .type = NLA_U32 },
> > -	[NETNSA_FD]		= { .type = NLA_U32 },
> > +	[NETNSA_PID]		= { .type = NLA_S32 },
> > +	[NETNSA_FD]		= { .type = NLA_S32 },
> Please, keep them consistent with IFLA_NET_NS_*:
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/core/rtnetlink.c?h=v5.5-rc6#n1793
> 
Oh right! I'll also update rtnetlink.c in v2.
Thanks!


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

end of thread, other threads:[~2020-01-15 14:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-14 22:25 [PATCH net-next 0/2] netns: simple cleanups Guillaume Nault
2020-01-14 22:25 ` [PATCH net-next 1/2] netns: Parse NETNSA_FD and NETNSA_PID as signed integers Guillaume Nault
2020-01-15 13:30   ` Nicolas Dichtel
2020-01-15 14:55     ` Guillaume Nault
2020-01-14 22:25 ` [PATCH net-next 2/2] netns: constify exported functions Guillaume Nault
2020-01-15 13:43   ` Nicolas Dichtel

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.