]> granicus.if.org Git - libnl/commitdiff
factor out rtnl_link_fill_info()
authorCong Wang <xiyou.wangcong@gmail.com>
Fri, 1 Nov 2013 23:58:46 +0000 (16:58 -0700)
committerThomas Graf <tgraf@suug.ch>
Wed, 6 Nov 2013 08:55:01 +0000 (09:55 +0100)
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
include/netlink/route/link.h
lib/route/link.c

index e53f9b22599d45b0e9df87f1af789afdab2f45b5..fd7dda14b56d55628374c554ebcbd3afd8cbdcda 100644 (file)
@@ -222,6 +222,7 @@ extern int  rtnl_link_enslave(struct nl_sock *, struct rtnl_link *,
                                  struct rtnl_link *);
 extern int     rtnl_link_release_ifindex(struct nl_sock *, int);
 extern int     rtnl_link_release(struct nl_sock *, struct rtnl_link *);
+extern int     rtnl_link_fill_info(struct nl_msg *, struct rtnl_link *);
 
 /* deprecated */
 extern int     rtnl_link_set_info_type(struct rtnl_link *, const char *) __attribute__((deprecated));
index a016899527c7d32af1548761419c013f9c804822..37938aa9b75cfa933601862c57554f35db7c7846 100644 (file)
@@ -1213,19 +1213,8 @@ int rtnl_link_name2i(struct nl_cache *cache, const char *name)
 
 /** @} */
 
-static int build_link_msg(int cmd, struct ifinfomsg *hdr,
-                         struct rtnl_link *link, int flags, struct nl_msg **result)
+int rtnl_link_fill_info(struct nl_msg *msg, struct rtnl_link *link)
 {
-       struct nl_msg *msg;
-       struct nlattr *af_spec;
-
-       msg = nlmsg_alloc_simple(cmd, flags);
-       if (!msg)
-               return -NLE_NOMEM;
-
-       if (nlmsg_append(msg, hdr, sizeof(*hdr), NLMSG_ALIGNTO) < 0)
-               goto nla_put_failure;
-
        if (link->ce_mask & LINK_ATTR_ADDR)
                NLA_PUT_ADDR(msg, IFLA_ADDRESS, link->l_addr);
 
@@ -1271,6 +1260,28 @@ static int build_link_msg(int cmd, struct ifinfomsg *hdr,
        if (link->ce_mask & LINK_ATTR_GROUP)
                NLA_PUT_U32(msg, IFLA_GROUP, link->l_group);
 
+       return 0;
+
+nla_put_failure:
+       return -NLE_MSGSIZE;
+}
+
+static int build_link_msg(int cmd, struct ifinfomsg *hdr,
+                         struct rtnl_link *link, int flags, struct nl_msg **result)
+{
+       struct nl_msg *msg;
+       struct nlattr *af_spec;
+
+       msg = nlmsg_alloc_simple(cmd, flags);
+       if (!msg)
+               return -NLE_NOMEM;
+
+       if (nlmsg_append(msg, hdr, sizeof(*hdr), NLMSG_ALIGNTO) < 0)
+               goto nla_put_failure;
+
+       if (rtnl_link_fill_info(msg, link))
+               goto nla_put_failure;
+
        if (link->ce_mask & LINK_ATTR_LINKINFO) {
                struct nlattr *info;