[PATCH 2/3] Set IFLA_PROTINFO attribute in request message

Jef Oliver jef.oliver at intel.com
Fri Aug 26 19:19:50 PDT 2016


This patch adds the functionality to set IFLA_PROTINFO in a
request. This allows for appending protocol specific information
to a request message.

This patch adds ao_fill_pi to the rtnl_link_af_ops structure. This
registers a function to fill the IFLA_PROTINFO attribute. This
function follows the makeup of ao_fill_af.

This patch adds ao_fill_pi_flags to the rtnl_link_af_ops
structure. This registers an extra flag that can be bitmasked
onto the IFLA_PROTINFO definition. This is useful for address
families that require NLA_F_NESTED.

This patch adds a function named af_fill_pi, which is called by
build_link_msg. This function calls the registered function
pointers for an address family to fill IFLA_PROTINFO and to
bitmask any extra flags.

Signed-off-by: Jef Oliver <jef.oliver at intel.com>
---
 include/netlink-private/route/link/api.h | 13 +++++++++++++
 lib/route/link.c                         | 27 +++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/include/netlink-private/route/link/api.h b/include/netlink-private/route/link/api.h
index 1cda72e..2767f63 100644
--- a/include/netlink-private/route/link/api.h
+++ b/include/netlink-private/route/link/api.h
@@ -154,6 +154,19 @@ struct rtnl_link_af_ops
 	 * RTM_SETLINK when rtnl_link_build_change_request() is called.
 	 */
 	const int ao_override_rtm;
+
+	/** Called if a link message is sent to the kernel. Must append the
+	 * link protocol specific attributes to the message. (IFLA_PROTINFO) */
+	int		      (*ao_fill_pi)(struct rtnl_link *,
+								struct nl_msg *msg, void *);
+
+	/** PROTINFO type
+	 *
+	 * Called if a link message is sent to the kernel. If this is set,
+	 * the default IFLA_PROTINFO is bitmasked with what is specified
+	 * here. (eg. NLA_F_NESTED)
+	 */
+	const int ao_fill_pi_flags;
 };
 
 extern struct rtnl_link_af_ops *rtnl_link_af_ops_lookup(unsigned int);
diff --git a/lib/route/link.c b/lib/route/link.c
index 7b687e9..c247603 100644
--- a/lib/route/link.c
+++ b/lib/route/link.c
@@ -152,6 +152,30 @@ static int af_fill(struct rtnl_link *link, struct rtnl_link_af_ops *ops,
 	return 0;
 }
 
+static int af_fill_pi(struct rtnl_link *link, struct rtnl_link_af_ops *ops,
+		   void *data, void *arg)
+{
+	struct nl_msg *msg = arg;
+	struct nlattr *pi_attr;
+	int err, pi_type = IFLA_PROTINFO;
+
+	if (!ops->ao_fill_pi)
+		return 0;
+
+	if (ops->ao_fill_pi_flags > 0)
+		pi_type |= ops->ao_fill_pi_flags;
+
+	if (!(pi_attr = nla_nest_start(msg, pi_type)))
+		return -NLE_MSGSIZE;
+
+	if ((err = ops->ao_fill_pi(link, arg, data)) < 0)
+		return err;
+
+	nla_nest_end(msg, pi_attr);
+
+	return 0;
+}
+
 static int af_dump_line(struct rtnl_link *link, struct rtnl_link_af_ops *ops,
 			 void *data, void *arg)
 {
@@ -1481,6 +1505,9 @@ static int build_link_msg(int cmd, struct ifinfomsg *hdr,
 		nla_nest_end(msg, info);
 	}
 
+	if (do_foreach_af(link, af_fill_pi, msg) < 0)
+		goto nla_put_failure;
+
 	if (!(af_spec = nla_nest_start(msg, IFLA_AF_SPEC)))
 		goto nla_put_failure;
 
-- 
2.9.3




More information about the libnl mailing list