net/rds Add getsockopt support for SO_RDS_TRANSPORT
authorSowmini Varadhan <sowmini.varadhan@oracle.com>
Fri, 29 May 2015 21:28:09 +0000 (17:28 -0400)
committerDavid S. Miller <davem@davemloft.net>
Mon, 1 Jun 2015 04:47:23 +0000 (21:47 -0700)
The currently attached transport for a PF_RDS socket may be obtained
from user space by invoking getsockopt(2) using the SO_RDS_TRANSPORT
option at the SOL_RDS level. The integer optval returned will be one
of the RDS_TRANS_* constants defined in linux/rds.h.

Signed-off-by: Sowmini Varadhan <sowmini.varadhan@oracle.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/rds/af_rds.c

index 04877441fb013042570948169334057757d5d6bf..2ad9032372b2d3a050137451f37dff32f790ba09 100644 (file)
@@ -339,6 +339,7 @@ static int rds_getsockopt(struct socket *sock, int level, int optname,
 {
        struct rds_sock *rs = rds_sk_to_rs(sock->sk);
        int ret = -ENOPROTOOPT, len;
+       int trans;
 
        if (level != SOL_RDS)
                goto out;
@@ -364,6 +365,19 @@ static int rds_getsockopt(struct socket *sock, int level, int optname,
                else
                        ret = 0;
                break;
+       case SO_RDS_TRANSPORT:
+               if (len < sizeof(int)) {
+                       ret = -EINVAL;
+                       break;
+               }
+               trans = (rs->rs_transport ? rs->rs_transport->t_type :
+                        RDS_TRANS_NONE); /* unbound */
+               if (put_user(trans, (int __user *)optval) ||
+                   put_user(sizeof(int), optlen))
+                       ret = -EFAULT;
+               else
+                       ret = 0;
+               break;
        default:
                break;
        }