Skip to content

Commit eeb78df

Browse files
juntongdengdavem330
authored andcommitted
inet: Add getsockopt support for IP_ROUTER_ALERT and IPV6_ROUTER_ALERT
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>
1 parent edf7468 commit eeb78df

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

include/net/inet_sock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ enum {
274274
INET_FLAGS_REPFLOW = 27,
275275
INET_FLAGS_RTALERT_ISOLATE = 28,
276276
INET_FLAGS_SNDFLOW = 29,
277+
INET_FLAGS_RTALERT = 30,
277278
};
278279

279280
/* cmsg flags for inet */

net/ipv4/ip_sockglue.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ int do_ip_setsockopt(struct sock *sk, int level, int optname,
894894
{
895895
struct inet_sock *inet = inet_sk(sk);
896896
struct net *net = sock_net(sk);
897-
int val = 0, err;
897+
int val = 0, err, retv;
898898
bool needs_rtnl = setsockopt_needs_rtnl(optname);
899899

900900
switch (optname) {
@@ -938,8 +938,12 @@ int do_ip_setsockopt(struct sock *sk, int level, int optname,
938938

939939
/* If optlen==0, it is equivalent to val == 0 */
940940

941-
if (optname == IP_ROUTER_ALERT)
942-
return ip_ra_control(sk, val ? 1 : 0, NULL);
941+
if (optname == IP_ROUTER_ALERT) {
942+
retv = ip_ra_control(sk, val ? 1 : 0, NULL);
943+
if (retv == 0)
944+
inet_assign_bit(RTALERT, sk, val);
945+
return retv;
946+
}
943947
if (ip_mroute_opt(optname))
944948
return ip_mroute_setsockopt(sk, optname, optval, optlen);
945949

@@ -1575,6 +1579,9 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname,
15751579
case IP_BIND_ADDRESS_NO_PORT:
15761580
val = inet_test_bit(BIND_ADDRESS_NO_PORT, sk);
15771581
goto copyval;
1582+
case IP_ROUTER_ALERT:
1583+
val = inet_test_bit(RTALERT, sk);
1584+
goto copyval;
15781585
case IP_TTL:
15791586
val = READ_ONCE(inet->uc_ttl);
15801587
if (val < 0)

net/ipv6/ipv6_sockglue.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,8 @@ int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
948948
if (optlen < sizeof(int))
949949
goto e_inval;
950950
retv = ip6_ra_control(sk, val);
951+
if (retv == 0)
952+
inet6_assign_bit(RTALERT, sk, valbool);
951953
break;
952954
case IPV6_FLOWLABEL_MGR:
953955
retv = ipv6_flowlabel_opt(sk, optval, optlen);
@@ -1445,6 +1447,10 @@ int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
14451447
val = np->rxopt.bits.recvfragsize;
14461448
break;
14471449

1450+
case IPV6_ROUTER_ALERT:
1451+
val = inet6_test_bit(RTALERT, sk);
1452+
break;
1453+
14481454
case IPV6_ROUTER_ALERT_ISOLATE:
14491455
val = inet6_test_bit(RTALERT_ISOLATE, sk);
14501456
break;

0 commit comments

Comments
 (0)