RDMA/netlink: Add flag to consolidate common handling
authorLeon Romanovsky <leonro@mellanox.com>
Mon, 12 Jun 2017 13:00:19 +0000 (16:00 +0300)
committerLeon Romanovsky <leon@kernel.org>
Thu, 10 Aug 2017 10:18:45 +0000 (13:18 +0300)
Add ability to provide flags to control RDMA netlink callbacks
and convert addr.c and sa_query.c to be first users of such
infrastructure. It allows to move their CAP_NET_ADMIN checks
into netlink core.

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
drivers/infiniband/core/addr.c
drivers/infiniband/core/device.c
drivers/infiniband/core/netlink.c
drivers/infiniband/core/sa_query.c
include/rdma/rdma_netlink.h

index 01236cef7bfb1affe07e4214cf6d8baf6ca2a2a1..9f3339861ec5bc3cec8c14f7349ed25028267536 100644 (file)
@@ -134,8 +134,7 @@ int ib_nl_handle_ip_res_resp(struct sk_buff *skb,
        const struct nlmsghdr *nlh = (struct nlmsghdr *)cb->nlh;
 
        if ((nlh->nlmsg_flags & NLM_F_REQUEST) ||
-           !(NETLINK_CB(skb).sk) ||
-           !netlink_capable(skb, CAP_NET_ADMIN))
+           !(NETLINK_CB(skb).sk))
                return -EPERM;
 
        if (ib_nl_is_good_ip_resp(nlh))
index d0994cd30eae4eca86215b3e227bd0611b1eb513..7ae29cc49a5e206314c311bfc7514e7af1b2fea1 100644 (file)
@@ -1088,11 +1088,17 @@ EXPORT_SYMBOL(ib_get_net_dev_by_params);
 
 static const struct ibnl_client_cbs ibnl_ls_cb_table[] = {
        [RDMA_NL_LS_OP_RESOLVE] = {
-               .dump = ib_nl_handle_resolve_resp},
+               .dump = ib_nl_handle_resolve_resp,
+               .flags = RDMA_NL_ADMIN_PERM,
+       },
        [RDMA_NL_LS_OP_SET_TIMEOUT] = {
-               .dump = ib_nl_handle_set_timeout},
+               .dump = ib_nl_handle_set_timeout,
+               .flags = RDMA_NL_ADMIN_PERM,
+       },
        [RDMA_NL_LS_OP_IP_RESOLVE] = {
-               .dump = ib_nl_handle_ip_res_resp},
+               .dump = ib_nl_handle_ip_res_resp,
+               .flags = RDMA_NL_ADMIN_PERM,
+       },
 };
 
 static int __init ib_core_init(void)
index 826fbd612c7de433d3f813aa2a72b69f8868fd38..c5ee62a249600138addd07104cf801b7dc97acb6 100644 (file)
@@ -171,6 +171,10 @@ static int rdma_nl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh,
        if (!is_nl_valid(index, op))
                return -EINVAL;
 
+       if ((rdma_nl_types[index].cb_table[op].flags & RDMA_NL_ADMIN_PERM) &&
+           !netlink_capable(skb, CAP_NET_ADMIN))
+               return -EPERM;
+
        /*
         * For response or local service set_timeout request,
         * there is no need to use netlink_dump_start.
index 70fa4cabe48e75813dfe6ef7804bff854c8c59c4..b499f4422f417410130d38ea2b95c73ccd8b9367 100644 (file)
@@ -1033,8 +1033,7 @@ int ib_nl_handle_set_timeout(struct sk_buff *skb,
        int ret;
 
        if (!(nlh->nlmsg_flags & NLM_F_REQUEST) ||
-           !(NETLINK_CB(skb).sk) ||
-           !netlink_capable(skb, CAP_NET_ADMIN))
+           !(NETLINK_CB(skb).sk))
                return -EPERM;
 
        ret = nla_parse(tb, LS_NLA_TYPE_MAX - 1, nlmsg_data(nlh),
@@ -1109,8 +1108,7 @@ int ib_nl_handle_resolve_resp(struct sk_buff *skb,
        int ret;
 
        if ((nlh->nlmsg_flags & NLM_F_REQUEST) ||
-           !(NETLINK_CB(skb).sk) ||
-           !netlink_capable(skb, CAP_NET_ADMIN))
+           !(NETLINK_CB(skb).sk))
                return -EPERM;
 
        spin_lock_irqsave(&ib_nl_request_lock, flags);
index c124d8e43fc86ab11e76c58c7f42072126fbdfc6..6ea36ec4540116c6be1604c5090c4be56a96b578 100644 (file)
@@ -7,6 +7,12 @@
 
 struct ibnl_client_cbs {
        int (*dump)(struct sk_buff *skb, struct netlink_callback *nlcb);
+       u8 flags;
+};
+
+enum rdma_nl_flags {
+       /* Require CAP_NET_ADMIN */
+       RDMA_NL_ADMIN_PERM      = 1 << 0,
 };
 
 /**