netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Richard Gobert <richardbgobert@gmail.com>
To: davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org
Subject: [PATCH] net: error on unsupported IP setsockopts in IPv6
Date: Thu, 9 Jun 2022 17:26:10 +0200	[thread overview]
Message-ID: <20220609152525.GA6504@debian> (raw)

The IP_TTL and IP_TOS sockopts are unsupported for IPv6 sockets,
this bug was reported previously to the kernel bugzilla [1].
Make the IP_TTL and IP_TOS sockopts return an error for AF_INET6 sockets.

[1] https://bugzilla.kernel.org/show_bug.cgi?id=212585

Signed-off-by: Richard Gobert <richardbgobert@gmail.com>
---
 net/ipv6/ipv6_sockglue.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
index 222f6bf220ba..2cdaa8f3a8f2 100644
--- a/net/ipv6/ipv6_sockglue.c
+++ b/net/ipv6/ipv6_sockglue.c
@@ -1012,8 +1012,16 @@ int ipv6_setsockopt(struct sock *sk, int level, int optname, sockptr_t optval,
 {
 	int err;
 
-	if (level == SOL_IP && sk->sk_type != SOCK_RAW)
-		return udp_prot.setsockopt(sk, level, optname, optval, optlen);
+	if (level == SOL_IP && sk->sk_type != SOCK_RAW) {
+		switch (optname) {
+		/* Some IP opts are not supported for IPv6 sockets */
+		case IP_TTL:
+		case IP_TOS:
+			return -ENOPROTOOPT;
+		default:
+			return udp_prot.setsockopt(sk, level, optname, optval, optlen);
+		}
+	}
 
 	if (level != SOL_IPV6)
 		return -ENOPROTOOPT;
-- 
2.36.1


             reply	other threads:[~2022-06-09 15:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-09 15:26 Richard Gobert [this message]
2022-06-11  5:16 ` [PATCH] net: error on unsupported IP setsockopts in IPv6 Jakub Kicinski
2022-06-11 16:55   ` David Ahern

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220609152525.GA6504@debian \
    --to=richardbgobert@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=yoshfuji@linux-ipv6.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).