lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:	Thu, 12 Nov 2015 23:10:08 +0200
From:	Konstantin Shemyak <konstantin@...myak.com>
To:	Stephen Hemminger <shemming@...cade.com>
Cc:	netdev@...r.kernel.org
Subject: [PATCH iproute2] ip_tunnel: determine tunnel address family from
 the tunnel type

When creating an IP tunnel over IPv6, the address family must be passed in
the option, e.g.

ip -6 tunnel add mode ip6gre local 1::1 remote 2::2

This makes it impossible to create both IPv4 and IPv6 tunnels in one batch.

In fact the address family option is redundant here, as each tunnel mode is
relevant for only one address family.
The patch determines whether the applicable address family is AF_INET6
instead of the default AF_INET and makes the "-6" option unnecessary for
"ip tunnel add".

Signed-off-by: Konstantin Shemyak <konstantin@...myak.com>
---
 ip/iptunnel.c                          | 26 ++++++++++++++++++++++++++
 testsuite/tests/ip/tunnel/add_tunnel.t | 14 ++++++++++++++
 2 files changed, 40 insertions(+)
 create mode 100755 testsuite/tests/ip/tunnel/add_tunnel.t

diff --git a/ip/iptunnel.c b/ip/iptunnel.c
index 78fa988..7826a37 100644
--- a/ip/iptunnel.c
+++ b/ip/iptunnel.c
@@ -629,8 +629,34 @@ static int do_6rd(int argc, char **argv)
        return tnl_6rd_ioctl(cmd, medium, &ip6rd);
 }
 
+static int tunnel_mode_is_ipv6(char *tunnel_mode) {
+       char *ipv6_modes[] = {
+               "ipv6/ipv6", "ip6ip6",
+               "vti6",
+               "ip/ipv6", "ipv4/ipv6", "ipip6", "ip4ip6",
+               "ip6gre", "gre/ipv6",
+               "any/ipv6", "any"
+       };
+       int i;
+
+       for (i = 0; i < sizeof(ipv6_modes) / sizeof(char *); i++) {
+               if (strcmp(ipv6_modes[i], tunnel_mode) == 0)
+                       return 1;
+       }
+       return 0;
+}
+
 int do_iptunnel(int argc, char **argv)
 {
+       int i;
+
+       for (i = 0; i < argc - 1; i++) {
+               if (strcmp(argv[i], "mode") == 0) {
+                       if (tunnel_mode_is_ipv6(argv[i + 1]))
+                               preferred_family = AF_INET6;
+                       break;
+               }
+       }
        switch (preferred_family) {
        case AF_UNSPEC:
                preferred_family = AF_INET;
diff --git a/testsuite/tests/ip/tunnel/add_tunnel.t b/testsuite/tests/ip/tunnel/add_tunnel.t
new file mode 100755
index 0000000..18f6e37
--- /dev/null
+++ b/testsuite/tests/ip/tunnel/add_tunnel.t
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+source lib/generic.sh
+
+TUNNEL_NAME="tunnel_test_ip"
+
+ts_log "[Testing add/del tunnels]"
+
+ts_ip "$0" "Add GRE tunnel over IPv4" tunnel add name $TUNNEL_NAME mode gre local 1.1.1.1 remote 2.2.2.2
+ts_ip "$0" "Del GRE tunnel over IPv4" tunnel del $TUNNEL_NAME
+
+ts_ip "$0" "Add GRE tunnel over IPv6" tunnel add name $TUNNEL_NAME mode ip6gre local dead:beef::1 remote dead:beef::2
+ts_ip "$0" "Del GRE tunnel over IPv6" tunnel del $TUNNEL_NAME
+
-- 
1.9.1

View attachment "0001-Tunnel-address-family-is-determined-from-the-tunnel-.patch" of type "text/x-diff" (2325 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ