Skip to content

Commit

Permalink
inet: Add getsockopt support for IP_ROUTER_ALERT and IPV6_ROUTER_ALERT
Browse files Browse the repository at this point in the history
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>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Juntong Deng authored and David S. Miller committed Mar 6, 2024
1 parent edf7468 commit eeb78df
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/net/inet_sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
13 changes: 10 additions & 3 deletions net/ipv4/ip_sockglue.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions net/ipv6/ipv6_sockglue.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit eeb78df

Please sign in to comment.