[PATCH 1/2] route/link: fix dump of parent link for some link types

Beniamino Galvani bgalvani at redhat.com
Fri Oct 16 02:21:25 PDT 2015


Some link types incorrectly dump their own interface name as parent
link; fix this.

Signed-off-by: Beniamino Galvani <bgalvani at redhat.com>
---
 include/netlink-private/netlink.h |  1 +
 lib/route/link.c                  | 21 +++++++++++++++++++++
 lib/route/link/ip6tnl.c           |  8 +++++++-
 lib/route/link/ipgre.c            |  8 +++++++-
 lib/route/link/ipip.c             |  8 +++++++-
 lib/route/link/ipvti.c            |  8 +++++++-
 lib/route/link/sit.c              |  8 +++++++-
 lib/route/link/vxlan.c            |  8 +++++++-
 8 files changed, 64 insertions(+), 6 deletions(-)

diff --git a/include/netlink-private/netlink.h b/include/netlink-private/netlink.h
index b06df8b..6d40ea5 100644
--- a/include/netlink-private/netlink.h
+++ b/include/netlink-private/netlink.h
@@ -136,6 +136,7 @@ extern char *__flags2str(int, char *, size_t, const struct trans_tbl *, size_t);
 extern int __str2flags(const char *, const struct trans_tbl *, size_t);
 
 extern void dump_from_ops(struct nl_object *, struct nl_dump_params *);
+extern struct rtnl_link *link_lookup(struct nl_cache *cache, int ifindex);
 
 static inline int nl_cb_call(struct nl_cb *cb, int type, struct nl_msg *msg)
 {
diff --git a/lib/route/link.c b/lib/route/link.c
index 5c32550..4b10a3a 100644
--- a/lib/route/link.c
+++ b/lib/route/link.c
@@ -67,6 +67,27 @@ static struct nl_cache_ops rtnl_link_ops;
 static struct nl_object_ops link_obj_ops;
 /** @endcond */
 
+struct rtnl_link *link_lookup(struct nl_cache *cache, int ifindex)
+{
+	struct rtnl_link *link = NULL;
+	int fetched_cache = 0;
+
+	if (!cache) {
+		cache = nl_cache_mngt_require_safe("route/link");
+		fetched_cache = 1;
+	}
+
+	if (!cache)
+		return NULL;
+
+	link = rtnl_link_get(cache, ifindex);
+
+	if (fetched_cache)
+		nl_cache_put(cache);
+
+	return link;
+}
+
 static struct rtnl_link_af_ops *af_lookup_and_alloc(struct rtnl_link *link,
 						    int family)
 {
diff --git a/lib/route/link/ip6tnl.c b/lib/route/link/ip6tnl.c
index 59b06b7..085bf66 100644
--- a/lib/route/link/ip6tnl.c
+++ b/lib/route/link/ip6tnl.c
@@ -218,10 +218,16 @@ static void ip6_tnl_dump_details(struct rtnl_link *link, struct nl_dump_params *
 {
 	struct ip6_tnl_info *ip6_tnl = link->l_info;
 	char *name, addr[INET6_ADDRSTRLEN];
+	struct rtnl_link *parent;
 
 	if (ip6_tnl->ip6_tnl_mask & IP6_TNL_ATTR_LINK) {
 		nl_dump(p, "      link ");
-		name = rtnl_link_get_name(link);
+
+		name = NULL;
+		parent = link_lookup(link->ce_cache, ip6_tnl->link);
+		if (parent)
+			name = rtnl_link_get_name(parent);
+
 		if (name)
 			nl_dump_line(p, "%s\n", name);
 		else
diff --git a/lib/route/link/ipgre.c b/lib/route/link/ipgre.c
index 2fda637..cfaefd1 100644
--- a/lib/route/link/ipgre.c
+++ b/lib/route/link/ipgre.c
@@ -226,10 +226,16 @@ static void ipgre_dump_details(struct rtnl_link *link, struct nl_dump_params *p)
 {
 	struct ipgre_info *ipgre = link->l_info;
 	char *name, addr[INET_ADDRSTRLEN];
+	struct rtnl_link *parent;
 
 	if (ipgre->ipgre_mask & IPGRE_ATTR_LINK) {
 		nl_dump(p, "      link ");
-		name = rtnl_link_get_name(link);
+
+		name = NULL;
+		parent = link_lookup(link->ce_cache, ipgre->link);
+		if (parent)
+			name = rtnl_link_get_name(parent);
+
 		if (name)
 			nl_dump_line(p, "%s\n", name);
 		else
diff --git a/lib/route/link/ipip.c b/lib/route/link/ipip.c
index 5ded380..593d409 100644
--- a/lib/route/link/ipip.c
+++ b/lib/route/link/ipip.c
@@ -180,10 +180,16 @@ static void ipip_dump_details(struct rtnl_link *link, struct nl_dump_params *p)
 {
 	struct ipip_info *ipip = link->l_info;
 	char *name, addr[INET_ADDRSTRLEN];
+	struct rtnl_link *parent;
 
 	if (ipip->ipip_mask & IPIP_ATTR_LINK) {
 		nl_dump(p, "      link ");
-		name = rtnl_link_get_name(link);
+
+		name = NULL;
+		parent = link_lookup(link->ce_cache, ipip->link);
+		if (parent)
+			name = rtnl_link_get_name(parent);
+
 		if (name)
 			nl_dump_line(p, "%s\n", name);
 		else
diff --git a/lib/route/link/ipvti.c b/lib/route/link/ipvti.c
index d627a8e..7021a94 100644
--- a/lib/route/link/ipvti.c
+++ b/lib/route/link/ipvti.c
@@ -170,10 +170,16 @@ static void ipvti_dump_details(struct rtnl_link *link, struct nl_dump_params *p)
 {
 	struct ipvti_info *ipvti = link->l_info;
 	char *name, addr[INET_ADDRSTRLEN];
+	struct rtnl_link *parent;
 
 	if (ipvti->ipvti_mask & IPVTI_ATTR_LINK) {
 		nl_dump(p, "      link ");
-		name = rtnl_link_get_name(link);
+
+		name = NULL;
+		parent = link_lookup(link->ce_cache, ipvti->link);
+		if (parent)
+			name = rtnl_link_get_name(parent);
+
 		if (name)
 			nl_dump_line(p, "%s\n", name);
 		else
diff --git a/lib/route/link/sit.c b/lib/route/link/sit.c
index 75987b9..6e6a09a 100644
--- a/lib/route/link/sit.c
+++ b/lib/route/link/sit.c
@@ -204,10 +204,16 @@ static void sit_dump_details(struct rtnl_link *link, struct nl_dump_params *p)
 {
 	struct sit_info *sit = link->l_info;
 	char *name, addr[INET_ADDRSTRLEN];
+	struct rtnl_link *parent;
 
 	if (sit->sit_mask & SIT_ATTR_LINK) {
 		nl_dump(p, "      link ");
-		name = rtnl_link_get_name(link);
+
+		name = NULL;
+		parent = link_lookup(link->ce_cache, sit->link);
+		if (parent)
+			name = rtnl_link_get_name(parent);
+
 		if (name)
 			nl_dump_line(p, "%s\n", name);
 		else
diff --git a/lib/route/link/vxlan.c b/lib/route/link/vxlan.c
index 127d2dd..8eb6db1 100644
--- a/lib/route/link/vxlan.c
+++ b/lib/route/link/vxlan.c
@@ -218,6 +218,7 @@ static void vxlan_dump_details(struct rtnl_link *link, struct nl_dump_params *p)
 {
 	struct vxlan_info *vxi = link->l_info;
 	char *name, addr[INET_ADDRSTRLEN];
+	struct rtnl_link *parent;
 
 	nl_dump_line(p, "    vxlan-id %u\n", vxi->vxi_id);
 
@@ -231,7 +232,12 @@ static void vxlan_dump_details(struct rtnl_link *link, struct nl_dump_params *p)
 
 	if (vxi->vxi_mask & VXLAN_HAS_LINK) {
 		nl_dump(p, "      link ");
-		name = rtnl_link_get_name(link);
+
+		name = NULL;
+		parent = link_lookup(link->ce_cache, vxi->vxi_link);
+		if (parent)
+			name = rtnl_link_get_name(parent);
+
 		if (name)
 			nl_dump_line(p, "%s\n", name);
 		else
-- 
2.4.3




More information about the libnl mailing list