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>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1320716800-9151-1-git-send-email-zenczykowski@gmail.com>
Date:	Mon,  7 Nov 2011 17:46:40 -0800
From:	Maciej Żenczykowski <zenczykowski@...il.com>
To:	Maciej Żenczykowski <maze@...gle.com>
Cc:	netdev@...r.kernel.org,
	Maciej Żenczykowski <maze@...gle.com>
Subject: [PATCH] [RFC] net-netlink: fix tos/tclass for dual-stack ipv6 sockets

From: Maciej Żenczykowski <maze@...gle.com>

Something along the following lines would be needed.

Signed-off-by: Maciej Żenczykowski <maze@...gle.com>
---
 include/net/ipv6.h   |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++
 net/ipv4/inet_diag.c |   11 +++++----
 2 files changed, 58 insertions(+), 5 deletions(-)

diff --git a/include/net/ipv6.h b/include/net/ipv6.h
index 3b5ac1f..50c7a3b 100644
--- a/include/net/ipv6.h
+++ b/include/net/ipv6.h
@@ -465,6 +465,58 @@ static inline int ipv6_addr_diff(const struct in6_addr *a1, const struct in6_add
 
 extern void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt);
 
+/* Return true for:
+ *   - an IPv4 socket (listening or connected)
+ *   - an IPv4 connection on a dual-stack IPv6 socket
+ *   - an IPv6 dual-stack listening socket -> can later accept IPv4 connection
+ */
+static inline bool sk_might_be_ipv4(struct sock *sk) {
+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
+	const struct ipv6_pinfo *np;
+
+	if (!sk) return false;
+	if (sk->sk_family == AF_INET) return true;
+	if (sk->sk_family != AF_INET6) return false;
+	np = inet6_sk(sk);
+	if (np->ipv6only) return false;
+
+	if (ipv6_addr_v4mapped(&np->rcv_saddr)) return true;
+	if (!ipv6_addr_any(&np->rcv_saddr)) return false;
+
+	if (sk->sk_state == TCP_LISTEN) return true;
+
+	if (ipv6_addr_v4mapped(&np->saddr)) return true;
+	return false;
+#else
+	return sk && (sk->sk_family == AF_INET);
+#endif
+}
+
+/* Return true for:
+ *   - a native IPv6 connection
+ *   - a listening IPv6 socket
+ */
+static inline bool sk_might_be_ipv6(struct sock *sk) {
+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
+	const struct ipv6_pinfo *np;
+
+	if (!sk) return false;
+	if (sk->sk_family != AF_INET6) return false;
+	np = inet6_sk(sk);
+	if (np->ipv6only) return true;
+
+	if (ipv6_addr_v4mapped(&np->rcv_saddr)) return false;
+	if (!ipv6_addr_any(&np->rcv_saddr)) return true;
+
+	if (sk->sk_state == TCP_LISTEN) return true;
+
+	if (ipv6_addr_v4mapped(&np->saddr)) return false;
+	return true;
+#else
+	return false;
+#endif
+}
+
 /*
  *	Prototypes exported by ipv6
  */
diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
index 68e8ac5..39bc97c 100644
--- a/net/ipv4/inet_diag.c
+++ b/net/ipv4/inet_diag.c
@@ -108,9 +108,6 @@ static int inet_csk_diag_fill(struct sock *sk,
 		       icsk->icsk_ca_ops->name);
 	}
 
-	if ((ext & (1 << (INET_DIAG_TOS - 1))) && (sk->sk_family != AF_INET6))
-		RTA_PUT_U8(skb, INET_DIAG_TOS, inet->tos);
-
 	r->idiag_family = sk->sk_family;
 	r->idiag_state = sk->sk_state;
 	r->idiag_timer = 0;
@@ -125,7 +122,13 @@ static int inet_csk_diag_fill(struct sock *sk,
 	r->id.idiag_src[0] = inet->inet_rcv_saddr;
 	r->id.idiag_dst[0] = inet->inet_daddr;
 
+	if ((ext & (1 << (INET_DIAG_TOS - 1))) && sk_might_be_ipv4(sk))
+		RTA_PUT_U8(skb, INET_DIAG_TOS, inet->tos);
+
 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
+	if ((ext & (1 << (INET_DIAG_TCLASS - 1))) && sk_might_be_ipv6(sk))
+		RTA_PUT_U8(skb, INET_DIAG_TCLASS, inet6_sk(sk)->tclass);
+
 	if (r->idiag_family == AF_INET6) {
 		const struct ipv6_pinfo *np = inet6_sk(sk);
 
@@ -133,8 +136,6 @@ static int inet_csk_diag_fill(struct sock *sk,
 			       &np->rcv_saddr);
 		ipv6_addr_copy((struct in6_addr *)r->id.idiag_dst,
 			       &np->daddr);
-		if (ext & (1 << (INET_DIAG_TCLASS - 1)))
-			RTA_PUT_U8(skb, INET_DIAG_TCLASS, np->tclass);
 	}
 #endif
 
-- 
1.7.3.1

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ