summaryrefslogtreecommitdiff
path: root/lib/route/link.c
diff options
context:
space:
mode:
authorThomas Graf <tgraf@suug.ch>2010-11-16 12:41:43 +0100
committerThomas Graf <tgraf@suug.ch>2010-11-16 12:41:43 +0100
commit53015f83811bd56d4b66331656633ad39051babf (patch)
tree9012ce9a769af8b977e98baa25b8b981cafbdba2 /lib/route/link.c
parent2e3ca4db0cbca7974888e7d3e7d84ba8fbbcf639 (diff)
downloadlibnl-53015f83811bd56d4b66331656633ad39051babf.tar.gz
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.c')
-rw-r--r--lib/route/link.c34
1 files changed, 27 insertions, 7 deletions
diff --git a/lib/route/link.c b/lib/route/link.c
index 60e1600..868a89a 100644
--- a/lib/route/link.c
+++ b/lib/route/link.c
@@ -187,18 +187,14 @@ static struct rtnl_link_af_ops *af_lookup_and_alloc(struct rtnl_link *link,
int family)
{
struct rtnl_link_af_ops *af_ops;
+ void *data;
af_ops = rtnl_link_af_ops_lookup(family);
if (!af_ops)
return NULL;
- if (!link->l_af_data[family] && af_ops->ao_alloc) {
- link->l_af_data[family] = af_ops->ao_alloc(link);
- if (!link->l_af_data[family]) {
- rtnl_link_af_ops_put(af_ops);
- return NULL;
- }
- }
+ if (!(data = rtnl_link_af_data(link, af_ops)))
+ return NULL;
return af_ops;
}
@@ -226,6 +222,27 @@ static int af_clone(struct rtnl_link *link, struct rtnl_link_af_ops *ops,
return 0;
}
+static int af_fill(struct rtnl_link *link, struct rtnl_link_af_ops *ops,
+ void *data, void *arg)
+{
+ struct nl_msg *msg = arg;
+ struct nlattr *af_attr;
+ int err;
+
+ if (!ops->ao_fill_af)
+ return 0;
+
+ if (!(af_attr = nla_nest_start(msg, ops->ao_family)))
+ return -NLE_MSGSIZE;
+
+ if ((err = ops->ao_fill_af(link, arg, data)) < 0)
+ return err;
+
+ nla_nest_end(msg, af_attr);
+
+ return 0;
+}
+
static int af_dump_line(struct rtnl_link *link, struct rtnl_link_af_ops *ops,
void *data, void *arg)
{
@@ -1096,6 +1113,9 @@ int rtnl_link_build_change_request(struct rtnl_link *old,
nla_nest_end(msg, info);
}
+ if (do_foreach_af(tmpl, af_fill, msg) < 0)
+ goto nla_put_failure;
+
*result = msg;
return 0;