IB/core: Add raw packet QP type
authorOr Gerlitz <ogerlitz@mellanox.com>
Thu, 1 Mar 2012 10:17:51 +0000 (12:17 +0200)
committerRoland Dreier <roland@purestorage.com>
Tue, 8 May 2012 18:18:09 +0000 (11:18 -0700)
IB_QPT_RAW_PACKET allows applications to build a complete packet,
including L2 headers, when sending; on the receive side, the HW will
not strip any headers.

This QP type is designed for userspace direct access to Ethernet; for
example by applications that do TCP/IP themselves.  Only processes
with the NET_RAW capability are allowed to create raw packet QPs (the
name "raw packet QP" is supposed to suggest an analogy to AF_PACKET /
SOL_RAW sockets).

Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
Reviewed-by: Sean Hefty <sean.hefty@intel.com>
Signed-off-by: Roland Dreier <roland@purestorage.com>
drivers/infiniband/core/uverbs_cmd.c
drivers/infiniband/core/verbs.c
include/rdma/ib_verbs.h

index 4d27e4c3fe34badbe941e735edaf9d8fb33b61f2..7d801e6252f10520304600a71bb1dfbb6a4dc0bd 100644 (file)
@@ -1399,6 +1399,9 @@ ssize_t ib_uverbs_create_qp(struct ib_uverbs_file *file,
        if (copy_from_user(&cmd, buf, sizeof cmd))
                return -EFAULT;
 
+       if (cmd.qp_type == IB_QPT_RAW_PACKET && !capable(CAP_NET_RAW))
+               return -EPERM;
+
        INIT_UDATA(&udata, buf + sizeof cmd,
                   (unsigned long) cmd.response + sizeof resp,
                   in_len - sizeof cmd, out_len - sizeof resp);
index 575b78045aafd1b5a861f9fad753f0108dd7e5d0..140f9a5d492fdfb371c8d50045e0d6642d0e3099 100644 (file)
@@ -479,6 +479,7 @@ static const struct {
                                [IB_QPT_UD]  = (IB_QP_PKEY_INDEX                |
                                                IB_QP_PORT                      |
                                                IB_QP_QKEY),
+                               [IB_QPT_RAW_PACKET] = IB_QP_PORT,
                                [IB_QPT_UC]  = (IB_QP_PKEY_INDEX                |
                                                IB_QP_PORT                      |
                                                IB_QP_ACCESS_FLAGS),
index c3cca5a4dacdb3bc9a0a04518db43b68664cc132..a3fa3232b8a08d47f2752cde9f74f728ae4d998c 100644 (file)
@@ -605,7 +605,7 @@ enum ib_qp_type {
        IB_QPT_UD,
        IB_QPT_RAW_IPV6,
        IB_QPT_RAW_ETHERTYPE,
-       /* Save 8 for RAW_PACKET */
+       IB_QPT_RAW_PACKET = 8,
        IB_QPT_XRC_INI = 9,
        IB_QPT_XRC_TGT,
        IB_QPT_MAX