netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iproute2 v2 2/3] link_iptnl: Print tunnel mode
  2018-01-02 19:54 [PATCH iproute2 2/3] link_iptnl: Print tunnel mode Stephen Hemminger
@ 2018-01-02 21:02 ` Serhey Popovych
  2018-01-02 21:13   ` Stephen Hemminger
  0 siblings, 1 reply; 8+ messages in thread
From: Serhey Popovych @ 2018-01-02 21:02 UTC (permalink / raw)
  To: netdev

Tunnel mode does not appear in parameters print for iptnl
supported tunnels like ipip and sit, while printed for
ip6tnl.

Print tunnel mode as "proto" field name for JSON and
without any name when printing to cli to follow ip6tnl
behaviour.

For non JSON output we have:

   $ ip -d link show dev sit1

Before:
-------
17: sit1@NONE: <NOARP> mtu 1480 qdisc noop state DOWN ...
    link/sit X.X.X.X brd 0.0.0.0 promiscuity 0
    sit remote any local X.X.X.X ...
        ~~~

After:
------
17: sit1@NONE: <NOARP> mtu 1480 qdisc noop state DOWN ...
    link/sit X.X.X.X brd 0.0.0.0 promiscuity 0
    sit any remote any local X.X.X.X ...
        ^^^

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
---
v2: Addressed comments: "proto ipip" vs "proto ip4ip4" for
    IPPROTO_IPIP tunnel type. Add example to message.

 ip/link_iptnl.c |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/ip/link_iptnl.c b/ip/link_iptnl.c
index d4d935b..b6ef95d 100644
--- a/ip/link_iptnl.c
+++ b/ip/link_iptnl.c
@@ -372,6 +372,23 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
 	if (tb[IFLA_IPTUN_COLLECT_METADATA])
 		print_bool(PRINT_ANY, "external", "external ", true);
 
+	if (tb[IFLA_IPTUN_PROTO]) {
+		switch (rta_getattr_u8(tb[IFLA_IPTUN_PROTO])) {
+		case IPPROTO_IPIP:
+			print_string(PRINT_ANY, "proto", "%s ", "ipip");
+			break;
+		case IPPROTO_IPV6:
+			print_string(PRINT_ANY, "proto", "%s ", "ip6ip");
+			break;
+		case IPPROTO_MPLS:
+			print_string(PRINT_ANY, "proto", "%s ", "mplsip");
+			break;
+		case 0:
+			print_string(PRINT_ANY, "proto", "%s ", "any");
+			break;
+		}
+	}
+
 	if (tb[IFLA_IPTUN_REMOTE]) {
 		unsigned int addr = rta_getattr_u32(tb[IFLA_IPTUN_REMOTE]);
 
-- 
1.7.10.4

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

* Re: [PATCH iproute2 v2 2/3] link_iptnl: Print tunnel mode
  2018-01-02 21:02 ` [PATCH iproute2 v2 " Serhey Popovych
@ 2018-01-02 21:13   ` Stephen Hemminger
  2018-01-02 21:29     ` Serhey Popovych
  0 siblings, 1 reply; 8+ messages in thread
From: Stephen Hemminger @ 2018-01-02 21:13 UTC (permalink / raw)
  To: Serhey Popovych; +Cc: netdev

On Tue,  2 Jan 2018 23:02:45 +0200
Serhey Popovych <serhe.popovych@gmail.com> wrote:

> Tunnel mode does not appear in parameters print for iptnl
> supported tunnels like ipip and sit, while printed for
> ip6tnl.
> 
> Print tunnel mode as "proto" field name for JSON and
> without any name when printing to cli to follow ip6tnl
> behaviour.
> 
> For non JSON output we have:
> 
>    $ ip -d link show dev sit1
> 
> Before:
> -------
> 17: sit1@NONE: <NOARP> mtu 1480 qdisc noop state DOWN ...
>     link/sit X.X.X.X brd 0.0.0.0 promiscuity 0
>     sit remote any local X.X.X.X ...
>         ~~~
> 
> After:
> ------
> 17: sit1@NONE: <NOARP> mtu 1480 qdisc noop state DOWN ...
>     link/sit X.X.X.X brd 0.0.0.0 promiscuity 0
>     sit any remote any local X.X.X.X ...
>         ^^^
> 
> Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
> ---
> v2: Addressed comments: "proto ipip" vs "proto ip4ip4" for
>     IPPROTO_IPIP tunnel type. Add example to message.
> 
>  ip/link_iptnl.c |   17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/ip/link_iptnl.c b/ip/link_iptnl.c
> index d4d935b..b6ef95d 100644
> --- a/ip/link_iptnl.c
> +++ b/ip/link_iptnl.c
> @@ -372,6 +372,23 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
>  	if (tb[IFLA_IPTUN_COLLECT_METADATA])
>  		print_bool(PRINT_ANY, "external", "external ", true);
>  
> +	if (tb[IFLA_IPTUN_PROTO]) {
> +		switch (rta_getattr_u8(tb[IFLA_IPTUN_PROTO])) {
> +		case IPPROTO_IPIP:
> +			print_string(PRINT_ANY, "proto", "%s ", "ipip");
> +			break;
> +		case IPPROTO_IPV6:
> +			print_string(PRINT_ANY, "proto", "%s ", "ip6ip");
> +			break;
> +		case IPPROTO_MPLS:
> +			print_string(PRINT_ANY, "proto", "%s ", "mplsip");
> +			break;
> +		case 0:
> +			print_string(PRINT_ANY, "proto", "%s ", "any");
> +			break;
> +		}
> +	}
> +
>  	if (tb[IFLA_IPTUN_REMOTE]) {
>  		unsigned int addr = rta_getattr_u32(tb[IFLA_IPTUN_REMOTE]);

Thanks for fixing the ip4 value.

When you fix one thing, you need to resend whole patch series.

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

* [PATCH iproute2 v2 0/3] iptnl/tunnel: Open JSON section, kill code duplication and print iptnl mode
@ 2018-01-02 21:27 Serhey Popovych
  2018-01-02 21:27 ` [PATCH iproute2 v2 1/3] link_iptnl: Kill code duplication Serhey Popovych
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Serhey Popovych @ 2018-01-02 21:27 UTC (permalink / raw)
  To: netdev

In this series I present following improvements and fixes:

  1) Add missing open_json_context() to link_iptnl.c
     for "encap" options.

  2) Get rid of code duplication when parsing tunnel mode
     parameters in link_iptnl.c.

  3) Add code to link_iptnl.c to print tunnel mode to be
     inline with ip6tnl.

See individual patch description message for details.

This is v2. Fixed proto value for ipip tunnel mode:
"proto ipip" vs "proto ip4ip4" previously.

Thanks,
Serhii

Serhey Popovych (3):
  link_iptnl: Kill code duplication
  link_iptnl: Print tunnel mode
  link_iptnl: Open "encap" JSON object

 ip/link_iptnl.c |   45 +++++++++++++++++++++++----------------------
 1 file changed, 23 insertions(+), 22 deletions(-)

-- 
1.7.10.4

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

* [PATCH iproute2 v2 1/3] link_iptnl: Kill code duplication
  2018-01-02 21:27 [PATCH iproute2 v2 0/3] iptnl/tunnel: Open JSON section, kill code duplication and print iptnl mode Serhey Popovych
@ 2018-01-02 21:27 ` Serhey Popovych
  2018-01-02 21:27 ` [PATCH iproute2 v2 2/3] link_iptnl: Print tunnel mode Serhey Popovych
  2018-01-02 21:27 ` [PATCH iproute2 v2 3/3] link_iptnl: Open "encap" JSON object Serhey Popovych
  2 siblings, 0 replies; 8+ messages in thread
From: Serhey Popovych @ 2018-01-02 21:27 UTC (permalink / raw)
  To: netdev

Both sit and ipip "mode" parameter handling nearly the same.
Except for sit we have "ip6ip" mode: check it only when
configuring sit.

Note that there is no need strcmp(lu->id, "ipip"): if it is
not sit it is "ipip" because we have only these two link util
defined in module.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
---
 ip/link_iptnl.c |   27 +++++----------------------
 1 file changed, 5 insertions(+), 22 deletions(-)

diff --git a/ip/link_iptnl.c b/ip/link_iptnl.c
index 8a8f5dd..d4d935b 100644
--- a/ip/link_iptnl.c
+++ b/ip/link_iptnl.c
@@ -230,11 +230,11 @@ get_failed:
 		} else if (strcmp(lu->id, "sit") == 0 &&
 			   strcmp(*argv, "isatap") == 0) {
 			iflags |= SIT_ISATAP;
-		} else if (strcmp(lu->id, "sit") == 0 &&
-			   strcmp(*argv, "mode") == 0) {
+		} else if (strcmp(*argv, "mode") == 0) {
 			NEXT_ARG();
-			if (strcmp(*argv, "ipv6/ipv4") == 0 ||
-			    strcmp(*argv, "ip6ip") == 0)
+			if (strcmp(lu->id, "sit") == 0 &&
+			    (strcmp(*argv, "ipv6/ipv4") == 0 ||
+			     strcmp(*argv, "ip6ip") == 0))
 				proto = IPPROTO_IPV6;
 			else if (strcmp(*argv, "ipv4/ipv4") == 0 ||
 				 strcmp(*argv, "ipip") == 0 ||
@@ -248,21 +248,6 @@ get_failed:
 				proto = 0;
 			else
 				invarg("Cannot guess tunnel mode.", *argv);
-		} else if (strcmp(lu->id, "ipip") == 0 &&
-			   strcmp(*argv, "mode") == 0) {
-			NEXT_ARG();
-			if (strcmp(*argv, "ipv4/ipv4") == 0 ||
-				 strcmp(*argv, "ipip") == 0 ||
-				 strcmp(*argv, "ip4ip4") == 0)
-				proto = IPPROTO_IPIP;
-			else if (strcmp(*argv, "mpls/ipv4") == 0 ||
-				   strcmp(*argv, "mplsip") == 0)
-				proto = IPPROTO_MPLS;
-			else if (strcmp(*argv, "any/ipv4") == 0 ||
-				 strcmp(*argv, "any") == 0)
-				proto = 0;
-			else
-				invarg("Cannot guess tunnel mode.", *argv);
 		} else if (strcmp(*argv, "noencap") == 0) {
 			encaptype = TUNNEL_ENCAP_NONE;
 		} else if (strcmp(*argv, "encap") == 0) {
@@ -337,6 +322,7 @@ get_failed:
 		exit(-1);
 	}
 
+	addattr8(n, 1024, IFLA_IPTUN_PROTO, proto);
 	if (metadata) {
 		addattr_l(n, 1024, IFLA_IPTUN_COLLECT_METADATA, NULL, 0);
 		return 0;
@@ -355,9 +341,6 @@ get_failed:
 	addattr16(n, 1024, IFLA_IPTUN_ENCAP_SPORT, htons(encapsport));
 	addattr16(n, 1024, IFLA_IPTUN_ENCAP_DPORT, htons(encapdport));
 
-	if (strcmp(lu->id, "ipip") == 0 || strcmp(lu->id, "sit") == 0)
-		addattr8(n, 1024, IFLA_IPTUN_PROTO, proto);
-
 	if (strcmp(lu->id, "sit") == 0) {
 		addattr16(n, 1024, IFLA_IPTUN_FLAGS, iflags);
 		if (ip6rdprefixlen) {
-- 
1.7.10.4

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

* [PATCH iproute2 v2 2/3] link_iptnl: Print tunnel mode
  2018-01-02 21:27 [PATCH iproute2 v2 0/3] iptnl/tunnel: Open JSON section, kill code duplication and print iptnl mode Serhey Popovych
  2018-01-02 21:27 ` [PATCH iproute2 v2 1/3] link_iptnl: Kill code duplication Serhey Popovych
@ 2018-01-02 21:27 ` Serhey Popovych
  2018-01-06  0:36   ` Stephen Hemminger
  2018-01-02 21:27 ` [PATCH iproute2 v2 3/3] link_iptnl: Open "encap" JSON object Serhey Popovych
  2 siblings, 1 reply; 8+ messages in thread
From: Serhey Popovych @ 2018-01-02 21:27 UTC (permalink / raw)
  To: netdev

Tunnel mode does not appear in parameters print for iptnl
supported tunnels like ipip and sit, while printed for
ip6tnl.

Print tunnel mode as "proto" field name for JSON and
without any name when printing to cli to follow ip6tnl
behaviour.

For non JSON output we have:

   $ ip -d link show dev sit1

Before:
-------
17: sit1@NONE: <NOARP> mtu 1480 qdisc noop state DOWN ...
    link/sit X.X.X.X brd 0.0.0.0 promiscuity 0
    sit remote any local X.X.X.X ...
        ~~~

After:
------
17: sit1@NONE: <NOARP> mtu 1480 qdisc noop state DOWN ...
    link/sit X.X.X.X brd 0.0.0.0 promiscuity 0
    sit any remote any local X.X.X.X ...
        ^^^

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
---
 ip/link_iptnl.c |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/ip/link_iptnl.c b/ip/link_iptnl.c
index d4d935b..b6ef95d 100644
--- a/ip/link_iptnl.c
+++ b/ip/link_iptnl.c
@@ -372,6 +372,23 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
 	if (tb[IFLA_IPTUN_COLLECT_METADATA])
 		print_bool(PRINT_ANY, "external", "external ", true);
 
+	if (tb[IFLA_IPTUN_PROTO]) {
+		switch (rta_getattr_u8(tb[IFLA_IPTUN_PROTO])) {
+		case IPPROTO_IPIP:
+			print_string(PRINT_ANY, "proto", "%s ", "ipip");
+			break;
+		case IPPROTO_IPV6:
+			print_string(PRINT_ANY, "proto", "%s ", "ip6ip");
+			break;
+		case IPPROTO_MPLS:
+			print_string(PRINT_ANY, "proto", "%s ", "mplsip");
+			break;
+		case 0:
+			print_string(PRINT_ANY, "proto", "%s ", "any");
+			break;
+		}
+	}
+
 	if (tb[IFLA_IPTUN_REMOTE]) {
 		unsigned int addr = rta_getattr_u32(tb[IFLA_IPTUN_REMOTE]);
 
-- 
1.7.10.4

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

* [PATCH iproute2 v2 3/3] link_iptnl: Open "encap" JSON object
  2018-01-02 21:27 [PATCH iproute2 v2 0/3] iptnl/tunnel: Open JSON section, kill code duplication and print iptnl mode Serhey Popovych
  2018-01-02 21:27 ` [PATCH iproute2 v2 1/3] link_iptnl: Kill code duplication Serhey Popovych
  2018-01-02 21:27 ` [PATCH iproute2 v2 2/3] link_iptnl: Print tunnel mode Serhey Popovych
@ 2018-01-02 21:27 ` Serhey Popovych
  2 siblings, 0 replies; 8+ messages in thread
From: Serhey Popovych @ 2018-01-02 21:27 UTC (permalink / raw)
  To: netdev

It seems missing pair of open_json_object()/close_json_object()
in iptnl implementation.

Note that we open "encap" JSON object in ip6tnl.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
---
 ip/link_iptnl.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/ip/link_iptnl.c b/ip/link_iptnl.c
index b6ef95d..24a0f0c 100644
--- a/ip/link_iptnl.c
+++ b/ip/link_iptnl.c
@@ -498,6 +498,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
 		__u16 sport = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_SPORT]);
 		__u16 dport = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_DPORT]);
 
+		open_json_object("encap");
 		print_string(PRINT_FP, NULL, "encap ", NULL);
 		switch (type) {
 		case TUNNEL_ENCAP_FOU:
-- 
1.7.10.4

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

* Re: [PATCH iproute2 v2 2/3] link_iptnl: Print tunnel mode
  2018-01-02 21:13   ` Stephen Hemminger
@ 2018-01-02 21:29     ` Serhey Popovych
  0 siblings, 0 replies; 8+ messages in thread
From: Serhey Popovych @ 2018-01-02 21:29 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev


[-- Attachment #1.1: Type: text/plain, Size: 2268 bytes --]

Stephen Hemminger wrote:
> On Tue,  2 Jan 2018 23:02:45 +0200
> Serhey Popovych <serhe.popovych@gmail.com> wrote:
> 
>> Tunnel mode does not appear in parameters print for iptnl
>> supported tunnels like ipip and sit, while printed for
>> ip6tnl.
>>
>> Print tunnel mode as "proto" field name for JSON and
>> without any name when printing to cli to follow ip6tnl
>> behaviour.
>>
>> For non JSON output we have:
>>
>>    $ ip -d link show dev sit1
>>
>> Before:
>> -------
>> 17: sit1@NONE: <NOARP> mtu 1480 qdisc noop state DOWN ...
>>     link/sit X.X.X.X brd 0.0.0.0 promiscuity 0
>>     sit remote any local X.X.X.X ...
>>         ~~~
>>
>> After:
>> ------
>> 17: sit1@NONE: <NOARP> mtu 1480 qdisc noop state DOWN ...
>>     link/sit X.X.X.X brd 0.0.0.0 promiscuity 0
>>     sit any remote any local X.X.X.X ...
>>         ^^^
>>
>> Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
>> ---
>> v2: Addressed comments: "proto ipip" vs "proto ip4ip4" for
>>     IPPROTO_IPIP tunnel type. Add example to message.
>>
>>  ip/link_iptnl.c |   17 +++++++++++++++++
>>  1 file changed, 17 insertions(+)
>>
>> diff --git a/ip/link_iptnl.c b/ip/link_iptnl.c
>> index d4d935b..b6ef95d 100644
>> --- a/ip/link_iptnl.c
>> +++ b/ip/link_iptnl.c
>> @@ -372,6 +372,23 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
>>  	if (tb[IFLA_IPTUN_COLLECT_METADATA])
>>  		print_bool(PRINT_ANY, "external", "external ", true);
>>  
>> +	if (tb[IFLA_IPTUN_PROTO]) {
>> +		switch (rta_getattr_u8(tb[IFLA_IPTUN_PROTO])) {
>> +		case IPPROTO_IPIP:
>> +			print_string(PRINT_ANY, "proto", "%s ", "ipip");
>> +			break;
>> +		case IPPROTO_IPV6:
>> +			print_string(PRINT_ANY, "proto", "%s ", "ip6ip");
>> +			break;
>> +		case IPPROTO_MPLS:
>> +			print_string(PRINT_ANY, "proto", "%s ", "mplsip");
>> +			break;
>> +		case 0:
>> +			print_string(PRINT_ANY, "proto", "%s ", "any");
>> +			break;
>> +		}
>> +	}
>> +
>>  	if (tb[IFLA_IPTUN_REMOTE]) {
>>  		unsigned int addr = rta_getattr_u32(tb[IFLA_IPTUN_REMOTE]);
> 
> Thanks for fixing the ip4 value.
> 
> When you fix one thing, you need to resend whole patch series.

Submitted v2 series. Thank you for the tip!

> 
> 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 490 bytes --]

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

* Re: [PATCH iproute2 v2 2/3] link_iptnl: Print tunnel mode
  2018-01-02 21:27 ` [PATCH iproute2 v2 2/3] link_iptnl: Print tunnel mode Serhey Popovych
@ 2018-01-06  0:36   ` Stephen Hemminger
  0 siblings, 0 replies; 8+ messages in thread
From: Stephen Hemminger @ 2018-01-06  0:36 UTC (permalink / raw)
  To: Serhey Popovych; +Cc: netdev

On Tue,  2 Jan 2018 23:27:58 +0200
Serhey Popovych <serhe.popovych@gmail.com> wrote:

> Tunnel mode does not appear in parameters print for iptnl
> supported tunnels like ipip and sit, while printed for
> ip6tnl.
> 
> Print tunnel mode as "proto" field name for JSON and
> without any name when printing to cli to follow ip6tnl
> behaviour.
> 
> For non JSON output we have:
> 
>    $ ip -d link show dev sit1
> 
> Before:
> -------
> 17: sit1@NONE: <NOARP> mtu 1480 qdisc noop state DOWN ...
>     link/sit X.X.X.X brd 0.0.0.0 promiscuity 0
>     sit remote any local X.X.X.X ...
>         ~~~
> 
> After:
> ------
> 17: sit1@NONE: <NOARP> mtu 1480 qdisc noop state DOWN ...
>     link/sit X.X.X.X brd 0.0.0.0 promiscuity 0
>     sit any remote any local X.X.X.X ...
>         ^^^
> 
> Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>

Applied all three to master.
Thanks.

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

end of thread, other threads:[~2018-01-06  0:36 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-02 21:27 [PATCH iproute2 v2 0/3] iptnl/tunnel: Open JSON section, kill code duplication and print iptnl mode Serhey Popovych
2018-01-02 21:27 ` [PATCH iproute2 v2 1/3] link_iptnl: Kill code duplication Serhey Popovych
2018-01-02 21:27 ` [PATCH iproute2 v2 2/3] link_iptnl: Print tunnel mode Serhey Popovych
2018-01-06  0:36   ` Stephen Hemminger
2018-01-02 21:27 ` [PATCH iproute2 v2 3/3] link_iptnl: Open "encap" JSON object Serhey Popovych
  -- strict thread matches above, loose matches on Subject: below --
2018-01-02 19:54 [PATCH iproute2 2/3] link_iptnl: Print tunnel mode Stephen Hemminger
2018-01-02 21:02 ` [PATCH iproute2 v2 " Serhey Popovych
2018-01-02 21:13   ` Stephen Hemminger
2018-01-02 21:29     ` Serhey Popovych

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).