diff mbox series

[iproute2,2/3] link_iptnl: Print tunnel mode

Message ID 1514906959-9719-3-git-send-email-serhe.popovych@gmail.com
State Changes Requested, archived
Delegated to: stephen hemminger
Headers show
Series iptnl/tunnel: Open JSON section, kill code duplication and print iptnl mode | expand

Commit Message

Serhey Popovych Jan. 2, 2018, 3:29 p.m. UTC
Tunnel mode does not appear in parameters print for iptnl
supported tunnels like ipip and sit, while printed for
ip6tnl.

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

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

Comments

Stephen Hemminger Jan. 2, 2018, 7:54 p.m. UTC | #1
On Tue,  2 Jan 2018 17:29:18 +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 with "proto" field for JSON and without
> any name when printing to cli to follow ip6tnl behaviour.
> 
> 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..afd1696 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 ", "ip4ip4");
> +			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]);
>  

In iproute2 utilities the output format must match the input format.
I don't see "proto ip4ip4" as a valid option.
diff mbox series

Patch

diff --git a/ip/link_iptnl.c b/ip/link_iptnl.c
index d4d935b..afd1696 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 ", "ip4ip4");
+			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]);