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

Submitted by Kirill Gorkunov on Nov. 16, 2016, 9:37 a.m.

Details

Message ID 20161116093710.GL17655@uranus
State New
Headers show

Patch hide | download patch | download mbox

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,