]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
rdma: Provide and reuse filter functions
authorLeon Romanovsky <leonro@mellanox.com>
Sat, 23 Feb 2019 09:15:28 +0000 (11:15 +0200)
committerDavid Ahern <dsahern@gmail.com>
Sun, 24 Feb 2019 15:09:24 +0000 (07:09 -0800)
Globally replace all filter function in safer variants of those
is_filtered functions, which take into account the availability/lack
of netlink attributes.

Such conversion allowed to fix a number of places in the code, where
the previous implementation didn't honor filter requests if netlink
attribute wasn't present.

Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
rdma/rdma.h
rdma/res-cmid.c
rdma/res-cq.c
rdma/res-mr.c
rdma/res-pd.c
rdma/res-qp.c
rdma/utils.c

index e86c7f2135bae0b0826d86ff6e4434f537a58f9a..1022e9a29291d49896ebf9d103e9c0345792e23b 100644 (file)
@@ -110,9 +110,10 @@ struct dev_map *dev_map_lookup(struct rd *rd, bool allow_port_index);
  */
 bool rd_doit_index(struct rd *rd, uint32_t *idx);
 int rd_build_filter(struct rd *rd, const struct filters valid_filters[]);
-bool rd_check_is_filtered(struct rd *rd, const char *key, uint32_t val);
-bool rd_check_is_string_filtered(struct rd *rd, const char *key, const char *val);
-bool rd_check_is_key_exist(struct rd *rd, const char *key);
+bool rd_is_filtered_attr(struct rd *rd, const char *key, uint32_t val,
+                        struct nlattr *attr);
+bool rd_is_string_filtered_attr(struct rd *rd, const char *key, const char *val,
+                               struct nlattr *attr);
 /*
  * Netlink
  */
index 0b61e43379f654a05b384c7feb1a5cca6077fb86..0b8300880a207d6d4a7a5a6dc2eb714fd7805f52 100644 (file)
@@ -132,57 +132,64 @@ static int res_cm_id_line(struct rd *rd, const char *name, int idx,
        if (port && port != rd->port_idx)
                goto out;
 
-       if (nla_line[RDMA_NLDEV_ATTR_RES_LQPN]) {
+       if (nla_line[RDMA_NLDEV_ATTR_RES_LQPN])
                lqpn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_LQPN]);
-               if (rd_check_is_filtered(rd, "lqpn", lqpn))
-                       goto out;
-       }
-       if (nla_line[RDMA_NLDEV_ATTR_RES_TYPE]) {
+
+       if (rd_is_filtered_attr(rd, "lqpn", lqpn,
+                               nla_line[RDMA_NLDEV_ATTR_RES_LQPN]))
+               goto out;
+
+       if (nla_line[RDMA_NLDEV_ATTR_RES_TYPE])
                type = mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_TYPE]);
-               if (rd_check_is_string_filtered(rd, "qp-type",
-                                               qp_types_to_str(type)))
-                       goto out;
-       }
+       if (rd_is_string_filtered_attr(rd, "qp-type", qp_types_to_str(type),
+                                      nla_line[RDMA_NLDEV_ATTR_RES_TYPE]))
+               goto out;
 
        ps = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PS]);
-       if (rd_check_is_string_filtered(rd, "ps", cm_id_ps_to_str(ps)))
+       if (rd_is_string_filtered_attr(rd, "ps", cm_id_ps_to_str(ps),
+                                      nla_line[RDMA_NLDEV_ATTR_RES_PS]))
                goto out;
 
        state = mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_STATE]);
-       if (rd_check_is_string_filtered(rd, "state", cm_id_state_to_str(state)))
+       if (rd_is_string_filtered_attr(rd, "state", cm_id_state_to_str(state),
+                                      nla_line[RDMA_NLDEV_ATTR_RES_STATE]))
                goto out;
 
-       if (nla_line[RDMA_NLDEV_ATTR_RES_SRC_ADDR]) {
+       if (nla_line[RDMA_NLDEV_ATTR_RES_SRC_ADDR])
                if (ss_ntop(nla_line[RDMA_NLDEV_ATTR_RES_SRC_ADDR],
                            src_addr_str, &src_port))
                        goto out;
-               if (rd_check_is_string_filtered(rd, "src-addr", src_addr_str))
-                       goto out;
-               if (rd_check_is_filtered(rd, "src-port", src_port))
-                       goto out;
-       }
+       if (rd_is_string_filtered_attr(rd, "src-addr", src_addr_str,
+                                      nla_line[RDMA_NLDEV_ATTR_RES_SRC_ADDR]))
+               goto out;
+       if (rd_is_filtered_attr(rd, "src-port", src_port,
+                               nla_line[RDMA_NLDEV_ATTR_RES_SRC_ADDR]))
+               goto out;
 
-       if (nla_line[RDMA_NLDEV_ATTR_RES_DST_ADDR]) {
+       if (nla_line[RDMA_NLDEV_ATTR_RES_DST_ADDR])
                if (ss_ntop(nla_line[RDMA_NLDEV_ATTR_RES_DST_ADDR],
                            dst_addr_str, &dst_port))
                        goto out;
-               if (rd_check_is_string_filtered(rd, "dst-addr", dst_addr_str))
-                       goto out;
-               if (rd_check_is_filtered(rd, "dst-port", dst_port))
-                       goto out;
-       }
+       if (rd_is_string_filtered_attr(rd, "dst-addr", dst_addr_str,
+                                      nla_line[RDMA_NLDEV_ATTR_RES_DST_ADDR]))
+               goto out;
+       if (rd_is_filtered_attr(rd, "dst-port", dst_port,
+                               nla_line[RDMA_NLDEV_ATTR_RES_DST_ADDR]))
+               goto out;
 
        if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
                pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
                comm = get_task_name(pid);
        }
 
-       if (rd_check_is_filtered(rd, "pid", pid))
+       if (rd_is_filtered_attr(rd, "pid", pid,
+                               nla_line[RDMA_NLDEV_ATTR_RES_PID]))
                goto out;
 
        if (nla_line[RDMA_NLDEV_ATTR_RES_CM_IDN])
                cm_idn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CM_IDN]);
-       if (rd_check_is_filtered(rd, "cm-idn", cm_idn))
+       if (rd_is_filtered_attr(rd, "cm-idn", cm_idn,
+                               nla_line[RDMA_NLDEV_ATTR_RES_CM_IDN]))
                goto out;
 
        if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) {
index c14637e6e9e0049b1a3c427700aaaae4a084ba4e..5afb97c5bbf458d35893f48de4d60ea0e56446bc 100644 (file)
@@ -51,32 +51,36 @@ static int res_cq_line(struct rd *rd, const char *name, int idx,
        cqe = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CQE]);
 
        users = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_USECNT]);
-       if (rd_check_is_filtered(rd, "users", users))
+       if (rd_is_filtered_attr(rd, "users", users,
+                               nla_line[RDMA_NLDEV_ATTR_RES_USECNT]))
                goto out;
 
-       if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]) {
+       if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX])
                poll_ctx =
                        mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]);
-               if (rd_check_is_string_filtered(rd, "poll-ctx",
-                                               poll_ctx_to_str(poll_ctx)))
-                       goto out;
-       }
+       if (rd_is_string_filtered_attr(rd, "poll-ctx",
+                                      poll_ctx_to_str(poll_ctx),
+                                      nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]))
+               goto out;
 
        if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
                pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
                comm = get_task_name(pid);
        }
 
-       if (rd_check_is_filtered(rd, "pid", pid))
+       if (rd_is_filtered_attr(rd, "pid", pid,
+                               nla_line[RDMA_NLDEV_ATTR_RES_PID]))
                goto out;
 
        if (nla_line[RDMA_NLDEV_ATTR_RES_CQN])
                cqn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CQN]);
-       if (rd_check_is_filtered(rd, "cqn", cqn))
+       if (rd_is_filtered_attr(rd, "cqn", cqn,
+                               nla_line[RDMA_NLDEV_ATTR_RES_CQN]))
                goto out;
        if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN])
                ctxn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CTXN]);
-       if (rd_check_is_filtered(rd, "ctxn", ctxn))
+       if (rd_is_filtered_attr(rd, "ctxn", ctxn,
+                               nla_line[RDMA_NLDEV_ATTR_RES_CTXN]))
                goto out;
 
        if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
index d42e8d812d93b6a7dae7eb38868a88cafe1a225a..f4a24dc1e7cf4e794d28e1af8365859b4afcfb49 100644 (file)
@@ -31,7 +31,8 @@ static int res_mr_line(struct rd *rd, const char *name, int idx,
                iova = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_IOVA]);
 
        mrlen = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_MRLEN]);
-       if (rd_check_is_filtered(rd, "mrlen", mrlen))
+       if (rd_is_filtered_attr(rd, "mrlen", mrlen,
+                               nla_line[RDMA_NLDEV_ATTR_RES_MRLEN]))
                goto out;
 
        if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
@@ -39,17 +40,20 @@ static int res_mr_line(struct rd *rd, const char *name, int idx,
                comm = get_task_name(pid);
        }
 
-       if (rd_check_is_filtered(rd, "pid", pid))
+       if (rd_is_filtered_attr(rd, "pid", pid,
+                               nla_line[RDMA_NLDEV_ATTR_RES_PID]))
                goto out;
 
        if (nla_line[RDMA_NLDEV_ATTR_RES_MRN])
                mrn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_MRN]);
-       if (rd_check_is_filtered(rd, "mrn", mrn))
+       if (rd_is_filtered_attr(rd, "mrn", mrn,
+                               nla_line[RDMA_NLDEV_ATTR_RES_MRN]))
                goto out;
 
        if (nla_line[RDMA_NLDEV_ATTR_RES_PDN])
                pdn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PDN]);
-       if (rd_check_is_filtered(rd, "pdn", pdn))
+       if (rd_is_filtered_attr(rd, "pdn", pdn,
+                               nla_line[RDMA_NLDEV_ATTR_RES_PDN]))
                goto out;
 
        if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
index 956d4d9fbf7e3f258bf83537be66e243a8397ebe..07c836e86d4ebac677b211460fe2e34f48c48bab 100644 (file)
@@ -28,7 +28,8 @@ static int res_pd_line(struct rd *rd, const char *name, int idx,
                        nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY]);
 
        users = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_USECNT]);
-       if (rd_check_is_filtered(rd, "users", users))
+       if (rd_is_filtered_attr(rd, "users", users,
+                               nla_line[RDMA_NLDEV_ATTR_RES_USECNT]))
                goto out;
 
        if (nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY])
@@ -40,18 +41,21 @@ static int res_pd_line(struct rd *rd, const char *name, int idx,
                comm = get_task_name(pid);
        }
 
-       if (rd_check_is_filtered(rd, "pid", pid))
+       if (rd_is_filtered_attr(rd, "pid", pid,
+                               nla_line[RDMA_NLDEV_ATTR_RES_PID]))
                goto out;
 
        if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN])
                ctxn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CTXN]);
 
-       if (rd_check_is_filtered(rd, "ctxn", ctxn))
+       if (rd_is_filtered_attr(rd, "ctxn", ctxn,
+                               nla_line[RDMA_NLDEV_ATTR_RES_CTXN]))
                goto out;
 
        if (nla_line[RDMA_NLDEV_ATTR_RES_PDN])
                pdn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PDN]);
-       if (rd_check_is_filtered(rd, "pdn", pdn))
+       if (rd_is_filtered_attr(rd, "pdn", pdn,
+                               nla_line[RDMA_NLDEV_ATTR_RES_PDN]))
                goto out;
 
        if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
index ac9976fc646996a5e1b015c93b4f7947555f6510..954e465de6fd6a5343c06698e093a38c51213e8d 100644 (file)
@@ -103,53 +103,49 @@ static int res_qp_line(struct rd *rd, const char *name, int idx,
                goto out;
 
        lqpn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_LQPN]);
-       if (rd_check_is_filtered(rd, "lqpn", lqpn))
+       if (rd_is_filtered_attr(rd, "lqpn", lqpn,
+                               nla_line[RDMA_NLDEV_ATTR_RES_LQPN]))
                goto out;
 
        if (nla_line[RDMA_NLDEV_ATTR_RES_PDN])
                pdn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PDN]);
-       if (rd_check_is_filtered(rd, "pdn", pdn))
+       if (rd_is_filtered_attr(rd, "pdn", pdn,
+                               nla_line[RDMA_NLDEV_ATTR_RES_PDN]))
                goto out;
 
-       if (nla_line[RDMA_NLDEV_ATTR_RES_RQPN]) {
+       if (nla_line[RDMA_NLDEV_ATTR_RES_RQPN])
                rqpn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_RQPN]);
-               if (rd_check_is_filtered(rd, "rqpn", rqpn))
-                       goto out;
-       } else {
-               if (rd_check_is_key_exist(rd, "rqpn"))
-                       goto out;
-       }
+       if (rd_is_filtered_attr(rd, "rqpn", rqpn,
+                               nla_line[RDMA_NLDEV_ATTR_RES_RQPN]))
+               goto out;
 
-       if (nla_line[RDMA_NLDEV_ATTR_RES_RQ_PSN]) {
+       if (nla_line[RDMA_NLDEV_ATTR_RES_RQ_PSN])
                rq_psn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_RQ_PSN]);
-               if (rd_check_is_filtered(rd, "rq-psn", rq_psn))
-                       goto out;
-       } else {
-               if (rd_check_is_key_exist(rd, "rq-psn"))
-                       goto out;
-       }
+       if (rd_is_filtered_attr(rd, "rq-psn", rq_psn,
+                               nla_line[RDMA_NLDEV_ATTR_RES_RQ_PSN]))
+               goto out;
 
        sq_psn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_SQ_PSN]);
-       if (rd_check_is_filtered(rd, "sq-psn", sq_psn))
+       if (rd_is_filtered_attr(rd, "sq-psn", sq_psn,
+                               nla_line[RDMA_NLDEV_ATTR_RES_SQ_PSN]))
                goto out;
 
-       if (nla_line[RDMA_NLDEV_ATTR_RES_PATH_MIG_STATE]) {
+       if (nla_line[RDMA_NLDEV_ATTR_RES_PATH_MIG_STATE])
                path_mig_state = mnl_attr_get_u8(
                        nla_line[RDMA_NLDEV_ATTR_RES_PATH_MIG_STATE]);
-               if (rd_check_is_string_filtered(rd, "path-mig-state",
-                                               path_mig_to_str(path_mig_state)))
-                       goto out;
-       } else {
-               if (rd_check_is_key_exist(rd, "path-mig-state"))
-                       goto out;
-       }
+       if (rd_is_string_filtered_attr(
+                   rd, "path-mig-state", path_mig_to_str(path_mig_state),
+                   nla_line[RDMA_NLDEV_ATTR_RES_PATH_MIG_STATE]))
+               goto out;
 
        type = mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_TYPE]);
-       if (rd_check_is_string_filtered(rd, "type", qp_types_to_str(type)))
+       if (rd_is_string_filtered_attr(rd, "type", qp_types_to_str(type),
+                                      nla_line[RDMA_NLDEV_ATTR_RES_TYPE]))
                goto out;
 
        state = mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_STATE]);
-       if (rd_check_is_string_filtered(rd, "state", qp_states_to_str(state)))
+       if (rd_is_string_filtered_attr(rd, "state", qp_states_to_str(state),
+                                      nla_line[RDMA_NLDEV_ATTR_RES_STATE]))
                goto out;
 
        if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
@@ -157,7 +153,8 @@ static int res_qp_line(struct rd *rd, const char *name, int idx,
                comm = get_task_name(pid);
        }
 
-       if (rd_check_is_filtered(rd, "pid", pid))
+       if (rd_is_filtered_attr(rd, "pid", pid,
+                               nla_line[RDMA_NLDEV_ATTR_RES_PID]))
                goto out;
 
        if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
index cff5297db93805ec7880c1e3c29684b88f9c9958..6bc14cd5c961b5cb7b0c965246389408f0cd3df8 100644 (file)
@@ -233,7 +233,7 @@ out:
        return ret;
 }
 
-bool rd_check_is_key_exist(struct rd *rd, const char *key)
+static bool rd_check_is_key_exist(struct rd *rd, const char *key)
 {
        struct filter_entry *fe;
 
@@ -249,8 +249,8 @@ bool rd_check_is_key_exist(struct rd *rd, const char *key)
  * Check if string entry is filtered:
  *  * key doesn't exist -> user didn't request -> not filtered
  */
-bool rd_check_is_string_filtered(struct rd *rd,
-                                const char *key, const char *val)
+static bool rd_check_is_string_filtered(struct rd *rd, const char *key,
+                                       const char *val)
 {
        bool key_is_filtered = false;
        struct filter_entry *fe;
@@ -300,7 +300,7 @@ out:
  * Check if key is filtered:
  * key doesn't exist -> user didn't request -> not filtered
  */
-bool rd_check_is_filtered(struct rd *rd, const char *key, uint32_t val)
+static bool rd_check_is_filtered(struct rd *rd, const char *key, uint32_t val)
 {
        bool key_is_filtered = false;
        struct filter_entry *fe;
@@ -349,6 +349,24 @@ out:
        return key_is_filtered;
 }
 
+bool rd_is_filtered_attr(struct rd *rd, const char *key, uint32_t val,
+                        struct nlattr *attr)
+{
+       if (!attr)
+               return rd_check_is_key_exist(rd, key);
+
+       return rd_check_is_filtered(rd, key, val);
+}
+
+bool rd_is_string_filtered_attr(struct rd *rd, const char *key, const char *val,
+                               struct nlattr *attr)
+{
+       if (!attr)
+               rd_check_is_key_exist(rd, key);
+
+       return rd_check_is_string_filtered(rd, key, val);
+}
+
 static void filters_cleanup(struct rd *rd)
 {
        struct filter_entry *fe, *tmp;