summaryrefslogtreecommitdiffstats
path: root/lib/route/link/api.c
diff options
context:
space:
mode:
authorThomas Graf <tgraf@suug.ch>2010-11-16 11:41:43 (GMT)
committerThomas Graf <tgraf@suug.ch>2010-11-16 11:41:43 (GMT)
commit53015f83811bd56d4b66331656633ad39051babf (patch)
tree9012ce9a769af8b977e98baa25b8b981cafbdba2 /lib/route/link/api.c
parent2e3ca4db0cbca7974888e7d3e7d84ba8fbbcf639 (diff)
downloadlibnl-53015f83811bd56d4b66331656633ad39051babf.zip
libnl-53015f83811bd56d4b66331656633ad39051babf.tar.gz
libnl-53015f83811bd56d4b66331656633ad39051babf.tar.bz2
link: AF_INET link module
Note: The code for this is not upstream yet. Extends the link api to allow address family modules to fill a link message and implements a AF_INET address family link module which uses the new interface.
Diffstat (limited to 'lib/route/link/api.c')
-rw-r--r--lib/route/link/api.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/route/link/api.c b/lib/route/link/api.c
index b1608e3..f7907a7 100644
--- a/lib/route/link/api.c
+++ b/lib/route/link/api.c
@@ -191,6 +191,64 @@ void rtnl_link_af_ops_put(struct rtnl_link_af_ops *ops)
}
/**
+ * Allocate and return data buffer for link address family modules
+ * @arg link Link object
+ * @arg ops Address family operations
+ *
+ * This function must be called by link address family modules in all
+ * cases where the API does not provide the data buffer as argument
+ * already. This typically includes set functions the module provides.
+ * Calling this function is strictly required to ensure proper allocation
+ * of the buffer upon first use. Link objects will NOT proactively
+ * allocate a data buffer for each registered link address family.
+ *
+ * @return Pointer to data buffer or NULL on error.
+ */
+void *rtnl_link_af_alloc(struct rtnl_link *link,
+ const struct rtnl_link_af_ops *ops)
+{
+ int family;
+
+ if (!link || !ops)
+ BUG();
+
+ family = ops->ao_family;
+
+ if (!link->l_af_data[family]) {
+ if (!ops->ao_alloc)
+ BUG();
+
+ link->l_af_data[family] = ops->ao_alloc(link);
+ if (!link->l_af_data[family])
+ return NULL;
+ }
+
+ return link->l_af_data[family];
+}
+
+/**
+ * Return data buffer for link address family modules
+ * @arg link Link object
+ * @arg ops Address family operations
+ *
+ * This function returns a pointer to the data buffer for the specified link
+ * address family module or NULL if the buffer was not allocated yet. This
+ * function is typically used by get functions of modules which are not
+ * interested in having the data buffer allocated if no values have been set
+ * yet.
+ *
+ * @return Pointer to data buffer or NULL on error.
+ */
+void *rtnl_link_af_data(const struct rtnl_link *link,
+ const struct rtnl_link_af_ops *ops)
+{
+ if (!link || !ops)
+ BUG();
+
+ return link->l_af_data[ops->ao_family];
+}
+
+/**
* Register operations for a link address family
* @arg ops Address family operations
*