]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - lib/utils.c
utils: Introduce and use get_ifname_rta()
[mirror_iproute2.git] / lib / utils.c
index cbe5d8de8f594f3ca60c066ec1aca847e3bcfab2..6a62c1edb7bf0598848c9203f2864317360e2b1c 100644 (file)
@@ -872,6 +872,25 @@ int get_ifname(char *buf, const char *name)
        return ret;
 }
 
+const char *get_ifname_rta(int ifindex, const struct rtattr *rta)
+{
+       const char *name;
+
+       if (rta) {
+               name = rta_getattr_str(rta);
+       } else {
+               fprintf(stderr,
+                       "BUG: device with ifindex %d has nil ifname\n",
+                       ifindex);
+               name = ll_idx_n2a(ifindex);
+       }
+
+       if (check_ifname(name))
+               return NULL;
+
+       return name;
+}
+
 int matches(const char *cmd, const char *pattern)
 {
        int len = strlen(cmd);