Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Juntong Deng and committed by
David S. Miller
eeb78df4 edf7468d

+17 -3
+1
include/net/inet_sock.h
··· 274 274 INET_FLAGS_REPFLOW = 27, 275 275 INET_FLAGS_RTALERT_ISOLATE = 28, 276 276 INET_FLAGS_SNDFLOW = 29, 277 + INET_FLAGS_RTALERT = 30, 277 278 }; 278 279 279 280 /* cmsg flags for inet */
+10 -3
net/ipv4/ip_sockglue.c
··· 894 894 { 895 895 struct inet_sock *inet = inet_sk(sk); 896 896 struct net *net = sock_net(sk); 897 - int val = 0, err; 897 + int val = 0, err, retv; 898 898 bool needs_rtnl = setsockopt_needs_rtnl(optname); 899 899 900 900 switch (optname) { ··· 938 938 939 939 /* If optlen==0, it is equivalent to val == 0 */ 940 940 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 + } 943 947 if (ip_mroute_opt(optname)) 944 948 return ip_mroute_setsockopt(sk, optname, optval, optlen); 945 949 ··· 1578 1574 goto copyval; 1579 1575 case IP_BIND_ADDRESS_NO_PORT: 1580 1576 val = inet_test_bit(BIND_ADDRESS_NO_PORT, sk); 1577 + goto copyval; 1578 + case IP_ROUTER_ALERT: 1579 + val = inet_test_bit(RTALERT, sk); 1581 1580 goto copyval; 1582 1581 case IP_TTL: 1583 1582 val = READ_ONCE(inet->uc_ttl);
+6
net/ipv6/ipv6_sockglue.c
··· 948 948 if (optlen < sizeof(int)) 949 949 goto e_inval; 950 950 retv = ip6_ra_control(sk, val); 951 + if (retv == 0) 952 + inet6_assign_bit(RTALERT, sk, valbool); 951 953 break; 952 954 case IPV6_FLOWLABEL_MGR: 953 955 retv = ipv6_flowlabel_opt(sk, optval, optlen); ··· 1445 1443 1446 1444 case IPV6_RECVFRAGSIZE: 1447 1445 val = np->rxopt.bits.recvfragsize; 1446 + break; 1447 + 1448 + case IPV6_ROUTER_ALERT: 1449 + val = inet6_test_bit(RTALERT, sk); 1448 1450 break; 1449 1451 1450 1452 case IPV6_ROUTER_ALERT_ISOLATE: