Skip to contentSkip to conversation

net: inet_diag: export IPV6_V6ONLY sockopt

PATCH Applied Phil Sutter 2 participants 2 messages Jun 24, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: inet_diag: export IPV6_V6ONLY sockopt

For AF_INET6 sockets, the value of struct ipv6_pinfo.ipv6only is exported to userspace. It indicates whether a socket bound to in6addr_any listens on IPv4 as well as IPv6. Since the socket is natively IPv6, it is not listed by e.g. 'ss -l -4'.

This patch is accompanied by an appropriate one for iproute2 to enable the additional information in 'ss -e'.

---
Changes since v1:
- Commit message corrected.
- Patch based on current net-next.git.
- Eric's superior solution implemented.

---
 include/uapi/linux/inet_diag.h | 3 ++-
 net/ipv4/inet_diag.c           | 4 ++++
 2 files changed, 6 insertions(+), 1 deletion(-)
include/uapi/linux/inet_diag.h +2 -1
index b629fc5..68a1f71 100644
@@ -112,9 +112,10 @@ enum {
 	INET_DIAG_SHUTDOWN,
 	INET_DIAG_DCTCPINFO,
 	INET_DIAG_PROTOCOL,  /* response attribute only */
+	INET_DIAG_SKV6ONLY,
 };
 
-#define INET_DIAG_MAX INET_DIAG_PROTOCOL
+#define INET_DIAG_MAX INET_DIAG_SKV6ONLY
 
 /* INET_DIAG_MEM */
 
net/ipv4/inet_diag.c +4 -0
index 21985d8..653564d 100644
@@ -151,6 +151,10 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
 			if (nla_put_u8(skb, INET_DIAG_TCLASS,
 				       inet6_sk(sk)->tclass) < 0)
 				goto errout;
+
+		if (ipv6_only_sock(sk) &&
+		    nla_put_u8(skb, INET_DIAG_SKV6ONLY, 1))
+			goto errout;
 	}
 #endif
 
Signature · 1 line
2.1.2
maintainer Applied
#1 lore raw

From: Phil Sutter <[email protected]>
Date: Wed, 24 Jun 2015 11:02:51 +0200

Quoted 9 lines

For AF_INET6 sockets, the value of struct ipv6_pinfo.ipv6only is exported to userspace. It indicates whether a socket bound to in6addr_any listens on IPv4 as well as IPv6. Since the socket is natively IPv6, it is not listed by e.g. 'ss -l -4'.

This patch is accompanied by an appropriate one for iproute2 to enable the additional information in 'ss -e'.

Applied, thanks.