]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - rdma/utils.c
Merge branch 'iproute2-master' into next
[mirror_iproute2.git] / rdma / utils.c
index cff5297db93805ec7880c1e3c29684b88f9c9958..1f6bf330bdbb553947c94752ea88ac49f30cb0ee 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;
@@ -811,27 +829,37 @@ static int print_driver_entry(struct rd *rd, struct nlattr *key_attr,
                                struct nlattr *val_attr,
                                enum rdma_nldev_print_type print_type)
 {
-       const char *key_str = mnl_attr_get_str(key_attr);
        int attr_type = nla_type(val_attr);
+       int ret = -EINVAL;
+       char *key_str;
+
+       if (asprintf(&key_str, "drv_%s", mnl_attr_get_str(key_attr)) == -1)
+               return -ENOMEM;
 
        switch (attr_type) {
        case RDMA_NLDEV_ATTR_DRIVER_STRING:
-               return print_driver_string(rd, key_str,
-                               mnl_attr_get_str(val_attr));
+               ret = print_driver_string(rd, key_str,
+                                         mnl_attr_get_str(val_attr));
+               break;
        case RDMA_NLDEV_ATTR_DRIVER_S32:
-               return print_driver_s32(rd, key_str,
-                               mnl_attr_get_u32(val_attr), print_type);
+               ret = print_driver_s32(rd, key_str, mnl_attr_get_u32(val_attr),
+                                      print_type);
+               break;
        case RDMA_NLDEV_ATTR_DRIVER_U32:
-               return print_driver_u32(rd, key_str,
-                               mnl_attr_get_u32(val_attr), print_type);
+               ret = print_driver_u32(rd, key_str, mnl_attr_get_u32(val_attr),
+                                      print_type);
+               break;
        case RDMA_NLDEV_ATTR_DRIVER_S64:
-               return print_driver_s64(rd, key_str,
-                               mnl_attr_get_u64(val_attr), print_type);
+               ret = print_driver_s64(rd, key_str, mnl_attr_get_u64(val_attr),
+                                      print_type);
+               break;
        case RDMA_NLDEV_ATTR_DRIVER_U64:
-               return print_driver_u64(rd, key_str,
-                               mnl_attr_get_u64(val_attr), print_type);
+               ret = print_driver_u64(rd, key_str, mnl_attr_get_u64(val_attr),
+                                      print_type);
+               break;
        }
-       return -EINVAL;
+       free(key_str);
+       return ret;
 }
 
 void print_driver_table(struct rd *rd, struct nlattr *tb)