diff mbox series

inet: Add getsockopt support for IP_ROUTER_ALERT and IPV6_ROUTER_ALERT

Message ID AM6PR03MB5848BD89913195FF68DC625599232@AM6PR03MB5848.eurprd03.prod.outlook.com (mailing list archive)
State Accepted
Commit eeb78df4063c0b162324a9408ef573b24791871f
Delegated to: Netdev Maintainers
Headers show
Series inet: Add getsockopt support for IP_ROUTER_ALERT and IPV6_ROUTER_ALERT | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 2925 this patch: 2925
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 1007 this patch: 1007
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 3139 this patch: 3139
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 56 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-03-05--21-00 (tests: 892)

Commit Message

Juntong Deng March 4, 2024, 11:32 a.m. UTC
Currently getsockopt does not support IP_ROUTER_ALERT and
IPV6_ROUTER_ALERT, and we are unable to get the values of these two
socket options through getsockopt.

This patch adds getsockopt support for IP_ROUTER_ALERT and
IPV6_ROUTER_ALERT.

Signed-off-by: Juntong Deng <juntong.deng@outlook.com>
---
 include/net/inet_sock.h  |  1 +
 net/ipv4/ip_sockglue.c   | 13 ++++++++++---
 net/ipv6/ipv6_sockglue.c |  6 ++++++
 3 files changed, 17 insertions(+), 3 deletions(-)

Comments

Eric Dumazet March 4, 2024, 11:49 a.m. UTC | #1
On Mon, Mar 4, 2024 at 12:33 PM Juntong Deng <juntong.deng@outlook.com> wrote:
>
> Currently getsockopt does not support IP_ROUTER_ALERT and
> IPV6_ROUTER_ALERT, and we are unable to get the values of these two
> socket options through getsockopt.
>
> This patch adds getsockopt support for IP_ROUTER_ALERT and
> IPV6_ROUTER_ALERT.
>
> Signed-off-by: Juntong Deng <juntong.deng@outlook.com>
>

This looks good to me, thanks, assuming this is net-next material.

Make sure next time to include the target tree (net or net-next)

Reviewed-by: Eric Dumazet <edumazet@google.com>
Juntong Deng March 4, 2024, 12:08 p.m. UTC | #2
On 2024/3/4 19:49, Eric Dumazet wrote:
> On Mon, Mar 4, 2024 at 12:33 PM Juntong Deng <juntong.deng@outlook.com> wrote:
>>
>> Currently getsockopt does not support IP_ROUTER_ALERT and
>> IPV6_ROUTER_ALERT, and we are unable to get the values of these two
>> socket options through getsockopt.
>>
>> This patch adds getsockopt support for IP_ROUTER_ALERT and
>> IPV6_ROUTER_ALERT.
>>
>> Signed-off-by: Juntong Deng <juntong.deng@outlook.com>
>>
> 
> This looks good to me, thanks, assuming this is net-next material.
> 
> Make sure next time to include the target tree (net or net-next)
> 
> Reviewed-by: Eric Dumazet <edumazet@google.com>

Hi Eric Dumazet,

Thanks for the review.

Yes, I made this patch based on net-next.

Sorry for the oversight, I will add the target tree next time.
patchwork-bot+netdevbpf@kernel.org March 6, 2024, 12:40 p.m. UTC | #3
Hello:

This patch was applied to netdev/net-next.git (main)
by David S. Miller <davem@davemloft.net>:

On Mon,  4 Mar 2024 11:32:08 +0000 you wrote:
> Currently getsockopt does not support IP_ROUTER_ALERT and
> IPV6_ROUTER_ALERT, and we are unable to get the values of these two
> socket options through getsockopt.
> 
> This patch adds getsockopt support for IP_ROUTER_ALERT and
> IPV6_ROUTER_ALERT.
> 
> [...]

Here is the summary with links:
  - inet: Add getsockopt support for IP_ROUTER_ALERT and IPV6_ROUTER_ALERT
    https://git.kernel.org/netdev/net-next/c/eeb78df4063c

You are awesome, thank you!
diff mbox series

Patch

diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h
index d94c242eb3ed..f9ddd47dc4f8 100644
--- a/include/net/inet_sock.h
+++ b/include/net/inet_sock.h
@@ -274,6 +274,7 @@  enum {
 	INET_FLAGS_REPFLOW	= 27,
 	INET_FLAGS_RTALERT_ISOLATE = 28,
 	INET_FLAGS_SNDFLOW	= 29,
+	INET_FLAGS_RTALERT	= 30,
 };
 
 /* cmsg flags for inet */
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index 21d2ffa919e9..cf377377b52d 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -894,7 +894,7 @@  int do_ip_setsockopt(struct sock *sk, int level, int optname,
 {
 	struct inet_sock *inet = inet_sk(sk);
 	struct net *net = sock_net(sk);
-	int val = 0, err;
+	int val = 0, err, retv;
 	bool needs_rtnl = setsockopt_needs_rtnl(optname);
 
 	switch (optname) {
@@ -938,8 +938,12 @@  int do_ip_setsockopt(struct sock *sk, int level, int optname,
 
 	/* If optlen==0, it is equivalent to val == 0 */
 
-	if (optname == IP_ROUTER_ALERT)
-		return ip_ra_control(sk, val ? 1 : 0, NULL);
+	if (optname == IP_ROUTER_ALERT) {
+		retv = ip_ra_control(sk, val ? 1 : 0, NULL);
+		if (retv == 0)
+			inet_assign_bit(RTALERT, sk, val);
+		return retv;
+	}
 	if (ip_mroute_opt(optname))
 		return ip_mroute_setsockopt(sk, optname, optval, optlen);
 
@@ -1575,6 +1579,9 @@  int do_ip_getsockopt(struct sock *sk, int level, int optname,
 	case IP_BIND_ADDRESS_NO_PORT:
 		val = inet_test_bit(BIND_ADDRESS_NO_PORT, sk);
 		goto copyval;
+	case IP_ROUTER_ALERT:
+		val = inet_test_bit(RTALERT, sk);
+		goto copyval;
 	case IP_TTL:
 		val = READ_ONCE(inet->uc_ttl);
 		if (val < 0)
diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
index 56c3c467f9de..9f15664fa607 100644
--- a/net/ipv6/ipv6_sockglue.c
+++ b/net/ipv6/ipv6_sockglue.c
@@ -948,6 +948,8 @@  int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
 		if (optlen < sizeof(int))
 			goto e_inval;
 		retv = ip6_ra_control(sk, val);
+		if (retv == 0)
+			inet6_assign_bit(RTALERT, sk, valbool);
 		break;
 	case IPV6_FLOWLABEL_MGR:
 		retv = ipv6_flowlabel_opt(sk, optval, optlen);
@@ -1445,6 +1447,10 @@  int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
 		val = np->rxopt.bits.recvfragsize;
 		break;
 
+	case IPV6_ROUTER_ALERT:
+		val = inet6_test_bit(RTALERT, sk);
+		break;
+
 	case IPV6_ROUTER_ALERT_ISOLATE:
 		val = inet6_test_bit(RTALERT_ISOLATE, sk);
 		break;