diff mbox series

[iproute2] ip: IFLA_NEW_NETNSID/IFLA_NEW_IFINDEX support

Message ID 20180531142848.377-1-nicolas.dichtel@6wind.com
State Accepted, archived
Delegated to: stephen hemminger
Headers show
Series [iproute2] ip: IFLA_NEW_NETNSID/IFLA_NEW_IFINDEX support | expand

Commit Message

Nicolas Dichtel May 31, 2018, 2:28 p.m. UTC
Parse and display those attributes.
Example:
ip l a type dummy
ip netns add foo
ip monitor link&
ip l s dummy1 netns foo
Deleted 6: dummy1: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default
    link/ether 66:af:3a:3f:a0:89 brd ff:ff:ff:ff:ff:ff new-nsid 0 new-ifindex 6

Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
 ip/ipaddress.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

Nicolas Dichtel May 31, 2018, 2:31 p.m. UTC | #1
Oops, I use an old email for Stephen, sorry.


Regards,
Nicolas

Le 31/05/2018 à 16:28, Nicolas Dichtel a écrit :
> Parse and display those attributes.
> Example:
> ip l a type dummy
> ip netns add foo
> ip monitor link&
> ip l s dummy1 netns foo
> Deleted 6: dummy1: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default
>     link/ether 66:af:3a:3f:a0:89 brd ff:ff:ff:ff:ff:ff new-nsid 0 new-ifindex 6
> 
> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
> ---
>  ip/ipaddress.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/ip/ipaddress.c b/ip/ipaddress.c
> index 00da14c6f97c..c7c7e7df4e81 100644
> --- a/ip/ipaddress.c
> +++ b/ip/ipaddress.c
> @@ -964,6 +964,17 @@ int print_linkinfo(const struct sockaddr_nl *who,
>  		}
>  	}
>  
> +	if (tb[IFLA_NEW_NETNSID]) {
> +		int id = rta_getattr_u32(tb[IFLA_NEW_NETNSID]);
> +
> +		print_int(PRINT_FP, NULL, " new-nsid %d", id);
> +	}
> +	if (tb[IFLA_NEW_IFINDEX]) {
> +		int id = rta_getattr_u32(tb[IFLA_NEW_IFINDEX]);
> +
> +		print_int(PRINT_FP, NULL, " new-ifindex %d", id);
> +	}
> +
>  	if (tb[IFLA_PROTO_DOWN]) {
>  		if (rta_getattr_u8(tb[IFLA_PROTO_DOWN]))
>  			print_bool(PRINT_ANY,
>
Stephen Hemminger May 31, 2018, 3:46 p.m. UTC | #2
On Thu, 31 May 2018 16:28:48 +0200
Nicolas Dichtel <nicolas.dichtel@6wind.com> wrote:

> Parse and display those attributes.
> Example:
> ip l a type dummy
> ip netns add foo
> ip monitor link&
> ip l s dummy1 netns foo
> Deleted 6: dummy1: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default
>     link/ether 66:af:3a:3f:a0:89 brd ff:ff:ff:ff:ff:ff new-nsid 0 new-ifindex 6
> 
> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
> ---
>  ip/ipaddress.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/ip/ipaddress.c b/ip/ipaddress.c
> index 00da14c6f97c..c7c7e7df4e81 100644
> --- a/ip/ipaddress.c
> +++ b/ip/ipaddress.c
> @@ -964,6 +964,17 @@ int print_linkinfo(const struct sockaddr_nl *who,
>  		}
>  	}
>  
> +	if (tb[IFLA_NEW_NETNSID]) {
> +		int id = rta_getattr_u32(tb[IFLA_NEW_NETNSID]);
> +
> +		print_int(PRINT_FP, NULL, " new-nsid %d", id);
> +	}
> +	if (tb[IFLA_NEW_IFINDEX]) {
> +		int id = rta_getattr_u32(tb[IFLA_NEW_IFINDEX]);
> +
> +		print_int(PRINT_FP, NULL, " new-ifindex %d", id);
> +	}
> +
>  	if (tb[IFLA_PROTO_DOWN]) {
>  		if (rta_getattr_u8(tb[IFLA_PROTO_DOWN]))
>  			print_bool(PRINT_ANY,

This makes sense. All of linkinfo that is present should be displayed.

Both netns and ifindex are really unsigned values. Use __u32 and print_uint.
Also why not convert numeric values to names?
Nicolas Dichtel May 31, 2018, 3:51 p.m. UTC | #3
Le 31/05/2018 à 17:46, Stephen Hemminger a écrit :
> On Thu, 31 May 2018 16:28:48 +0200
[snip]
> This makes sense. All of linkinfo that is present should be displayed.
> 
> Both netns and ifindex are really unsigned values. Use __u32 and print_uint.
Ok.

> Also why not convert numeric values to names?
The only case where the ifname can change is when a netns is deleted and the
interface is put back in init_net. But at this stage, we don't know the new name.

For the nsid, you're right, it will be better to display the netns name. If you
agree, I will do this in a following patch, thus all places using nsid can be
converted at the same time.


Regards,
Nicolas
Nicolas Dichtel June 1, 2018, 3:02 p.m. UTC | #4
Le 31/05/2018 à 17:51, Nicolas Dichtel a écrit :
> Le 31/05/2018 à 17:46, Stephen Hemminger a écrit :
>> On Thu, 31 May 2018 16:28:48 +0200
> [snip]
>> This makes sense. All of linkinfo that is present should be displayed.
>>
>> Both netns and ifindex are really unsigned values. Use __u32 and print_uint.
> Ok.
I replied a bit quickly, both are signed values:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/core/rtnetlink.c#n1621


Regards,
Nicolas
Stephen Hemminger June 1, 2018, 8:02 p.m. UTC | #5
On Fri, 1 Jun 2018 17:02:18 +0200
Nicolas Dichtel <nicolas.dichtel@6wind.com> wrote:

> Le 31/05/2018 à 17:51, Nicolas Dichtel a écrit :
> > Le 31/05/2018 à 17:46, Stephen Hemminger a écrit :  
> >> On Thu, 31 May 2018 16:28:48 +0200  
> > [snip]  
> >> This makes sense. All of linkinfo that is present should be displayed.
> >>
> >> Both netns and ifindex are really unsigned values. Use __u32 and print_uint.  
> > Ok.  
> I replied a bit quickly, both are signed values:
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/core/rtnetlink.c#n1621
> 
> 
> Regards,
> Nicolas

Ok, Applied orignal patch
diff mbox series

Patch

diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index 00da14c6f97c..c7c7e7df4e81 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -964,6 +964,17 @@  int print_linkinfo(const struct sockaddr_nl *who,
 		}
 	}
 
+	if (tb[IFLA_NEW_NETNSID]) {
+		int id = rta_getattr_u32(tb[IFLA_NEW_NETNSID]);
+
+		print_int(PRINT_FP, NULL, " new-nsid %d", id);
+	}
+	if (tb[IFLA_NEW_IFINDEX]) {
+		int id = rta_getattr_u32(tb[IFLA_NEW_IFINDEX]);
+
+		print_int(PRINT_FP, NULL, " new-ifindex %d", id);
+	}
+
 	if (tb[IFLA_PROTO_DOWN]) {
 		if (rta_getattr_u8(tb[IFLA_PROTO_DOWN]))
 			print_bool(PRINT_ANY,