[Devel] [PATCH rh7] ipv6: add IPV6_HDRINCL option for raw sockets

Cyrill Gorcunov gorcunov at virtuozzo.com
Wed Nov 16 01:37:10 PST 2016


On top of this series.

---
From: Hannes Frederic Sowa <hannes at stressinduktion.org>

ML: 715f504b118998c41a2079a17e16bf5a8a114885

Same as in Windows, we miss IPV6_HDRINCL for SOL_IPV6 and SOL_RAW.
The SOL_IP/IP_HDRINCL is not available for IPv6 sockets.

Signed-off-by: Hannes Frederic Sowa <hannes at stressinduktion.org>
Signed-off-by: David S. Miller <davem at davemloft.net>
Signed-off-by: Cyrill Gorcunov <gorcunov at virtuozzo.com>
---
 include/uapi/linux/in6.h |    2 ++
 net/ipv6/raw.c           |   20 ++++++++++++++++----
 2 files changed, 18 insertions(+), 4 deletions(-)

Index: linux-pcs7.git/include/uapi/linux/in6.h
===================================================================
--- linux-pcs7.git.orig/include/uapi/linux/in6.h
+++ linux-pcs7.git/include/uapi/linux/in6.h
@@ -174,6 +174,8 @@ struct in6_flowlabel_req {
 #define IPV6_JOIN_ANYCAST	27
 #define IPV6_LEAVE_ANYCAST	28
 
+#define IPV6_HDRINCL		36
+
 /* IPV6_MTU_DISCOVER values */
 #define IPV6_PMTUDISC_DONT		0
 #define IPV6_PMTUDISC_WANT		1
Index: linux-pcs7.git/net/ipv6/raw.c
===================================================================
--- linux-pcs7.git.orig/net/ipv6/raw.c
+++ linux-pcs7.git/net/ipv6/raw.c
@@ -964,6 +964,11 @@ static int do_rawv6_setsockopt(struct so
 		return -EFAULT;
 
 	switch (optname) {
+	case IPV6_HDRINCL:
+		if (sk->sk_type != SOCK_RAW)
+			return -EINVAL;
+		inet_sk(sk)->hdrincl = !!val;
+		return 0;
 	case IPV6_CHECKSUM:
 		if (inet_sk(sk)->inet_num == IPPROTO_ICMPV6 &&
 		    level == IPPROTO_IPV6) {
@@ -1008,7 +1013,8 @@ static int rawv6_setsockopt(struct sock
 			return -EOPNOTSUPP;
 		return rawv6_seticmpfilter(sk, level, optname, optval, optlen);
 	case SOL_IPV6:
-		if (optname == IPV6_CHECKSUM)
+		if (optname == IPV6_CHECKSUM ||
+		    optname == IPV6_HDRINCL)
 			break;
 	default:
 		return ipv6_setsockopt(sk, level, optname, optval, optlen);
@@ -1029,7 +1035,8 @@ static int compat_rawv6_setsockopt(struc
 			return -EOPNOTSUPP;
 		return rawv6_seticmpfilter(sk, level, optname, optval, optlen);
 	case SOL_IPV6:
-		if (optname == IPV6_CHECKSUM)
+		if (optname == IPV6_CHECKSUM ||
+		    optname == IPV6_HDRINCL)
 			break;
 	default:
 		return compat_ipv6_setsockopt(sk, level, optname,
@@ -1049,6 +1056,9 @@ static int do_rawv6_getsockopt(struct so
 		return -EFAULT;
 
 	switch (optname) {
+	case IPV6_HDRINCL:
+		val = inet_sk(sk)->hdrincl;
+		break;
 	case IPV6_CHECKSUM:
 		/*
 		 * We allow getsockopt() for IPPROTO_IPV6-level
@@ -1086,7 +1096,8 @@ static int rawv6_getsockopt(struct sock
 			return -EOPNOTSUPP;
 		return rawv6_geticmpfilter(sk, level, optname, optval, optlen);
 	case SOL_IPV6:
-		if (optname == IPV6_CHECKSUM)
+		if (optname == IPV6_CHECKSUM ||
+		    optname == IPV6_HDRINCL)
 			break;
 	default:
 		return ipv6_getsockopt(sk, level, optname, optval, optlen);
@@ -1107,7 +1118,8 @@ static int compat_rawv6_getsockopt(struc
 			return -EOPNOTSUPP;
 		return rawv6_geticmpfilter(sk, level, optname, optval, optlen);
 	case SOL_IPV6:
-		if (optname == IPV6_CHECKSUM)
+		if (optname == IPV6_CHECKSUM ||
+		    optname == IPV6_HDRINCL)
 			break;
 	default:
 		return compat_ipv6_getsockopt(sk, level, optname,


More information about the Devel mailing list