[patch libnl] link: add support for IFLA_PHYS_PORT_ID

Jiri Pirko jiri at resnulli.us
Thu Aug 1 07:57:08 EDT 2013


Signed-off-by: Jiri Pirko <jiri at resnulli.us>
---
 include/linux/if_link.h         |  1 +
 include/netlink-private/types.h |  1 +
 include/netlink/route/link.h    |  2 ++
 lib/route/link.c                | 30 ++++++++++++++++++++++++++++++
 4 files changed, 34 insertions(+)

diff --git a/include/linux/if_link.h b/include/linux/if_link.h
index 73ee05c..565b7f6 100644
--- a/include/linux/if_link.h
+++ b/include/linux/if_link.h
@@ -143,6 +143,7 @@ enum {
 	IFLA_NUM_TX_QUEUES,
 	IFLA_NUM_RX_QUEUES,
 	IFLA_CARRIER,
+	IFLA_PHYS_PORT_ID,
 	__IFLA_MAX
 };
 
diff --git a/include/netlink-private/types.h b/include/netlink-private/types.h
index 60b880d..05a6a45 100644
--- a/include/netlink-private/types.h
+++ b/include/netlink-private/types.h
@@ -187,6 +187,7 @@ struct rtnl_link
 	uint8_t				l_carrier;
 	/* 3 byte hole */
 	struct rtnl_link_af_ops *	l_af_ops;
+	struct nl_data *		l_phys_port_id;
 };
 
 struct rtnl_ncacheinfo
diff --git a/include/netlink/route/link.h b/include/netlink/route/link.h
index 321a80d..e53f9b2 100644
--- a/include/netlink/route/link.h
+++ b/include/netlink/route/link.h
@@ -215,6 +215,8 @@ extern uint32_t	rtnl_link_get_num_tx_queues(struct rtnl_link *);
 extern void	rtnl_link_set_num_rx_queues(struct rtnl_link *, uint32_t);
 extern uint32_t	rtnl_link_get_num_rx_queues(struct rtnl_link *);
 
+extern struct nl_data *	rtnl_link_get_phys_port_id(struct rtnl_link *);
+
 extern int	rtnl_link_enslave_ifindex(struct nl_sock *, int, int);
 extern int	rtnl_link_enslave(struct nl_sock *, struct rtnl_link *,
 				  struct rtnl_link *);
diff --git a/lib/route/link.c b/lib/route/link.c
index 77dd7f1..a73e1db 100644
--- a/lib/route/link.c
+++ b/lib/route/link.c
@@ -24,6 +24,7 @@
 #include <netlink/utils.h>
 #include <netlink/object.h>
 #include <netlink/hashtable.h>
+#include <netlink/data.h>
 #include <netlink/route/rtnl.h>
 #include <netlink/route/link.h>
 #include <netlink-private/route/link/api.h>
@@ -57,6 +58,7 @@
 #define LINK_ATTR_CARRIER	(1 << 25)
 #define LINK_ATTR_PROTINFO	(1 << 26)
 #define LINK_ATTR_AF_SPEC	(1 << 27)
+#define LINK_ATTR_PHYS_PORT_ID	(1 << 28)
 
 static struct nl_cache_ops rtnl_link_ops;
 static struct nl_object_ops link_obj_ops;
@@ -215,6 +217,8 @@ static void link_free_data(struct nl_object *c)
 		free(link->l_info_kind);
 
 		do_foreach_af(link, af_free, NULL);
+
+		nl_data_free(link->l_phys_port_id);
 	}
 }
 
@@ -249,6 +253,10 @@ static int link_clone(struct nl_object *_dst, struct nl_object *_src)
 	if ((err = do_foreach_af(src, af_clone, dst)) < 0)
 		return err;
 
+	if (src->l_phys_port_id)
+		if (!(dst->l_phys_port_id = nl_data_clone(src->l_phys_port_id)))
+			return -NLE_NOMEM;
+
 	return 0;
 }
 
@@ -276,6 +284,7 @@ static struct nla_policy link_policy[IFLA_MAX+1] = {
 	[IFLA_NUM_RX_QUEUES]	= { .type = NLA_U32 },
 	[IFLA_GROUP]		= { .type = NLA_U32 },
 	[IFLA_CARRIER]		= { .type = NLA_U8 },
+	[IFLA_PHYS_PORT_ID]	= { .type = NLA_UNSPEC },
 };
 
 static struct nla_policy link_info_policy[IFLA_INFO_MAX+1] = {
@@ -587,6 +596,15 @@ static int link_msg_parser(struct nl_cache_ops *ops, struct sockaddr_nl *who,
 		link->ce_mask |= LINK_ATTR_GROUP;
 	}
 
+	if (tb[IFLA_PHYS_PORT_ID]) {
+		link->l_phys_port_id = nl_data_alloc_attr(tb[IFLA_PHYS_PORT_ID]);
+		if (link->l_phys_port_id == NULL) {
+			err = -NLE_NOMEM;
+			goto errout;
+		}
+		link->ce_mask |= LINK_ATTR_PHYS_PORT_ID;
+	}
+
 	err = pp->pp_cb((struct nl_object *) link, pp);
 errout:
 	rtnl_link_af_ops_put(af_ops);
@@ -917,6 +935,7 @@ static const struct trans_tbl link_attrs[] = {
 	__ADD(LINK_ATTR_NUM_RX_QUEUES, num_rx_queues)
 	__ADD(LINK_ATTR_GROUP, group)
 	__ADD(LINK_ATTR_CARRIER, carrier)
+	__ADD(LINK_ATTR_PHYS_PORT_ID, phys_port_id)
 };
 
 static char *link_attrs2str(int attrs, char *buf, size_t len)
@@ -2265,6 +2284,17 @@ uint32_t rtnl_link_get_num_rx_queues(struct rtnl_link *link)
 	return link->l_num_rx_queues;
 }
 
+/**
+ * Return physical port id of link object
+ * @arg link		Link object
+ *
+ * @return Physical port id or NULL if not set.
+ */
+struct nl_data *rtnl_link_get_phys_port_id(struct rtnl_link *link)
+{
+	return link->l_phys_port_id;
+}
+
 /** @} */
 
 /**
-- 
1.8.3.1




More information about the libnl mailing list